Skip to content

Commit c906f01

Browse files
committed
Rip out the testsuite and replace it with a much better one
- No more hpilo_cli _test, but python -munittest discover - Tests the xml generating/parsing without needing an iLO - Can test parsing XML generated by many iLOs - Can still test its actions on iLOs if you want it to - Can test many ilos in one run - Can actually be maintained...
1 parent 7fcb381 commit c906f01

File tree

371 files changed

+9530
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

371 files changed

+9530
-384
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ firmware
88
*.bin
99
*.scexe
1010
.*.sw?
11+
*.request.tmp
12+
hpilo_test_debug_output
13+
.firmware_version_cache

hpilo.py

Lines changed: 16 additions & 375 deletions
Large diffs are not rendered by default.

hpilo_cli

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def main():
6363
p.add_option('-v', '--version', action="callback", callback=hpilo_version)
6464

6565
opts, args = p.parse_args()
66-
opts.do_write_tests = False
6766

6867
if opts.format == 'json':
6968
import json
@@ -74,10 +73,7 @@ def main():
7473
if len(args) < 2:
7574
p.error("Not enough arguments")
7675

77-
if args[1] == '_test_writes':
78-
args[1] = '_test'
79-
opts.do_write_tests = True
80-
if args[1] not in ilo_methods and args[1] != '_test' and args[0] != 'download_rib_firmware':
76+
if args[1] not in ilo_methods and args[0] != 'download_rib_firmware':
8177
p.error("Unknown method: %s" % args[1])
8278

8379
config = ConfigParser.ConfigParser()
@@ -97,10 +93,6 @@ def main():
9793
for args in args_:
9894
method = args.pop(0)
9995

100-
if method == '_test':
101-
calls.append(('_test', {'opts': opts, 'tests': args}))
102-
continue
103-
10496
# Arguments must be passed as param=value pairs that are valid arguments to the methods
10597
if sys.version_info[0] >= 3:
10698
func = getattr(hpilo.Ilo, method)#.__func__

tests/README

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Testsuite for python-hpilo
2+
--------------------------
3+
4+
This testsuite consists of two parts:
5+
- Tests for the XML generator and parser
6+
- Tests that actually contact iLO's
7+
8+
The former use a corpus of known data, they're safe to run and run pretty
9+
quickly. The latter will change data on iLO's (and do their best to restore
10+
the data to previous values), will reset iLO's and take a long time to run.
11+
12+
Test contributions wanted!
13+
--------------------------
14+
For the corpus of test data, we need more people to submit data from their
15+
machines. This process is safe (no iLO data is changed at all), though can
16+
leak information about your systems if you are not careful. If you want to
17+
contribute, please do the following:
18+
19+
$ cd tests/xml
20+
$ ./fetch_responses hostname-of-your-ilo-here
21+
22+
This creates a new directory named after the hardware model, ilo model and ilo
23+
firmware of your machine. In it, you find raw and parsed responses of all
24+
python-hpilo queries. You should inspect this data and see if it's correct.
25+
You should also redact information you do not wish to share, but please don't
26+
go overboard.
27+
28+
- Redacting iLO license keys makes perfect sense.
29+
- Redacting hostnames and IP addresses is acceptable, but please do not redact
30+
anything else
31+
- When redacting, replace each letter of the redacted string with an x. Don't
32+
add or remove characters
33+
- The .raw files may contain http chunked data, be very careful when editing
34+
this and don't break the format. Preferably use a hex editor, or an editor
35+
that does not mess with newlines (vim will do)
36+
37+
You can either send me your datafiles via e-mail, or send a pull request on
38+
GitHub. If you do not know how to redact the data, or want me to do it for
39+
you, please send the data by e-mail and I will redact hostnames and iLO
40+
license keys.
41+
42+
Running the tests
43+
-----------------
44+
Running the safe tests is as simple as running:
45+
46+
$ python -munittest tests.test_requests
47+
$ python -munittest tests.test_responses
48+
49+
You can run any of the tests this way, just replace test_requests with the
50+
name of the test. To run all tests, you can use:
51+
52+
$ python -munittest discover
53+
54+
However, if you run this without configuring the tests, you'll notice that
55+
nothing actually attempts to contact an iLO. You will need to tell it which
56+
iLOs to test. You do this in ~/.ilo.conf by adding test sections like the
57+
following:
58+
59+
[test test-server]
60+
hostname = test-server.ilo.example.com
61+
62+
Please don't run these tests on mission-critical servers. While they try very
63+
hard to restore the settings it changes, bugs and errors happen.

tests/__init__.py

Whitespace-only changes.

tests/test_boot.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/python
2+
3+
from utils import *
4+
import random
5+
6+
class BootTests(IloTestCase):
7+
def test_persistent_boot(self, ilo):
8+
old = ilo.get_persistent_boot()
9+
new = old[:]
10+
random.shuffle(new)
11+
try:
12+
ilo.set_persistent_boot(new)
13+
self.assertEqual(new, ilo.get_persistent_boot())
14+
finally:
15+
ilo.set_persistent_boot(old)
16+
17+
def test_one_time_boot(self, ilo):
18+
old = ilo.get_one_time_boot()
19+
all = ilo.get_persistent_boot()
20+
if old in all:
21+
all.remove(old)
22+
new = random.choice(all)
23+
try:
24+
ilo.set_one_time_boot(new)
25+
self.assertEqual(new, ilo.get_one_time_boot())
26+
finally:
27+
ilo.set_one_time_boot(old)
28+
29+
if __name__ == '__main__':
30+
unittest.main()

tests/test_delayed.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/python
2+
3+
from utils import *
4+
5+
class DelayedTests(IloTestCase):
6+
def test_delayed_calls(self, ilo):
7+
uid = {'ON': 'Yes', 'OFF': 'No'}[ilo.get_uid_status()]
8+
non_delayed = [
9+
ilo.get_all_users(),
10+
ilo.get_global_settings(),
11+
]
12+
try:
13+
ilo.delayed = True
14+
ilo.get_all_users()
15+
ilo.uid_control(uid=uid)
16+
ilo.get_global_settings()
17+
delayed = ilo.call_delayed()
18+
finally:
19+
ilo.delayed = False
20+
self.assertEquals(non_delayed, delayed)
21+
22+
if __name__ == '__main__':
23+
unittest.main()

tests/test_global_settings.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/python
2+
3+
from utils import *
4+
5+
class GlobalSettingsTests(IloTestCase):
6+
def test_mod_global_settings(self, ilo):
7+
old = ilo.get_global_settings()
8+
try:
9+
ilo.mod_global_settings(
10+
f8_login_required=True,
11+
min_password=3
12+
)
13+
new = ilo.get_global_settings()
14+
self.assertEqual(new['f8_login_required'], True)
15+
self.assertEqual(new['min_password'], 3)
16+
finally:
17+
ilo.mod_global_settings(
18+
f8_login_required=old['f8_login_required'],
19+
min_password=old['min_password']
20+
)
21+
22+
if __name__ == '__main__':
23+
unittest.main()

tests/test_languages.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/python
2+
3+
from utils import *
4+
5+
class LanguageTests(IloTestCase):
6+
def test_languages(self, ilo):
7+
ilo.set_language(ilo.get_language()['lang_id'])
8+
9+
if __name__ == '__main__':
10+
unittest.main()

tests/test_logs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/python
2+
3+
from utils import *
4+
import time
5+
6+
class LogTests(IloTestCase):
7+
def test_ilo_event_log(self, ilo):
8+
ilo.clear_ilo_event_log()
9+
time.sleep(2)
10+
log = ilo.get_ilo_event_log()
11+
self.assertTrue(type(log) != dict)
12+
self.assertTrue(len(log) <= 3)
13+
14+
if __name__ == '__main__':
15+
unittest.main()

0 commit comments

Comments
 (0)