37
37
self.description = description
39
self.daemon_location = "@CRM_DAEMON_DIR@/lrmd"
41
self.daemon_location = "/usr/sbin/pacemaker_remoted"
43
self.daemon_location = "@CRM_DAEMON_DIR@/lrmd"
40
45
self.test_tool_location = "@CRM_DAEMON_DIR@/lrmd_test"
41
46
self.verbose = verbose
73
78
def start_environment(self):
74
79
### make sure we are in full control here ###
75
cmd = shlex.split("killall -q -9 stonithd lrmd lt-lrmd lrmd_test lt-lrmd_test")
80
cmd = shlex.split("killall -q -9 stonithd lrmd lt-lrmd lrmd_test lt-lrmd_test pacemaker_remoted")
76
81
test = subprocess.Popen(cmd, stdout=subprocess.PIPE)
79
84
additional_args = ""
81
self.stonith_process = subprocess.Popen(shlex.split("@CRM_DAEMON_DIR@/stonithd -s"))
83
additional_args = additional_args + " -t "
87
self.stonith_process = subprocess.Popen(shlex.split("@CRM_DAEMON_DIR@/stonithd -s"))
85
additional_args = additional_args + " -VVV "
90
additional_args = additional_args + " -VV "
87
92
self.lrmd_process = subprocess.Popen(shlex.split("%s %s -l /tmp/lrmd-regression.log" % (self.daemon_location, additional_args)))
123
128
self.__new_cmd(self.test_tool_location, args, 0, "", kill=killProc)
125
130
def add_expected_fail_cmd(self, args):
126
self.__new_cmd(self.test_tool_location, args, 255, "")
131
self.__new_cmd(self.test_tool_location, args, 1, "")
128
133
def get_exitcode(self):
129
134
return self.result_exitcode
205
216
self.verbose = verbose
207
self.rsc_classes = output_from_command("crm_resource --list-standards")
218
self.rsc_classes = output_from_command("crm_resource --list-standards")
208
219
self.rsc_classes = self.rsc_classes[:-1] # Strip trailing empty line
220
self.need_authkey = 0
222
self.rsc_classes.remove("stonith")
209
224
print "Testing "+repr(self.rsc_classes)
211
if not os.path.isfile("/etc/pacemaker/authkey"):
212
os.system("mkdir -p /etc/pacemaker")
213
os.system("dd if=/dev/urandom of=/etc/pacemaker/authkey bs=4096 count=1")
215
226
self.common_cmds = {
216
227
"ocf_reg_line" : "-c register_rsc -r ocf_test_rsc -t 3000 -C ocf -P pacemaker -T Dummy",
217
228
"ocf_reg_event" : "-l \"NEW_EVENT event_type:register rsc_id:ocf_test_rsc action:none rc:ok op_status:complete\"",
252
263
"upstart_cancel_line" : "-c cancel -r \"upstart_test_rsc\" -a \"monitor\" -i \"2000\" -t \"3000\" ",
253
264
"upstart_cancel_event" : "-l \"NEW_EVENT event_type:exec_complete rsc_id:upstart_test_rsc action:monitor rc:ok op_status:Cancelled\" ",
255
"service_reg_line" : "-c register_rsc -r service_test_rsc -t 3000 -C service -T lrmd_dummy_daemon",
266
"service_reg_line" : "-c register_rsc -r service_test_rsc -t 3000 -C service -T LSBDummy",
256
267
"service_reg_event" : "-l \"NEW_EVENT event_type:register rsc_id:service_test_rsc action:none rc:ok op_status:complete\"",
257
268
"service_unreg_line" : "-c unregister_rsc -r \"service_test_rsc\" -t 3000",
258
269
"service_unreg_event" : "-l \"NEW_EVENT event_type:unregister rsc_id:service_test_rsc action:none rc:ok op_status:complete\"",
265
276
"service_cancel_line" : "-c cancel -r \"service_test_rsc\" -a \"monitor\" -i \"2000\" -t \"3000\" ",
266
277
"service_cancel_event" : "-l \"NEW_EVENT event_type:exec_complete rsc_id:service_test_rsc action:monitor rc:ok op_status:Cancelled\" ",
268
"lsb_reg_line" : "-c register_rsc -r lsb_test_rsc -t 3000 -C lsb -T lrmd_dummy_daemon",
279
"lsb_reg_line" : "-c register_rsc -r lsb_test_rsc -t 3000 -C lsb -T LSBDummy",
269
280
"lsb_reg_event" : "-l \"NEW_EVENT event_type:register rsc_id:lsb_test_rsc action:none rc:ok op_status:complete\" ",
270
281
"lsb_unreg_line" : "-c unregister_rsc -r \"lsb_test_rsc\" -t 3000",
271
282
"lsb_unreg_event" : "-l \"NEW_EVENT event_type:unregister rsc_id:lsb_test_rsc action:none rc:ok op_status:complete\"",
300
311
def setup_test_environment(self):
312
os.system("service pacemaker_remote stop")
301
313
self.cleanup_test_environment()
315
if self.tls and not os.path.isfile("/etc/pacemaker/authkey"):
316
self.need_authkey = 1
317
os.system("mkdir -p /etc/pacemaker")
318
os.system("dd if=/dev/urandom of=/etc/pacemaker/authkey bs=4096 count=1")
303
320
### Make fake systemd daemon and unit file ###
304
321
dummy_daemon = "#!/bin/bash\nwhile true\ndo\nsleep 5\ndone"
305
322
dummy_service_file = ("[Unit]\n"
370
387
os.system("cat <<-END >>/usr/sbin/fence_dummy_monitor\n%s\nEND" % (dummy_fence_agent))
371
388
os.system("chmod 711 /usr/sbin/fence_dummy_monitor")
373
os.system("cp /usr/share/pacemaker/tests/cts/LSBDummy /etc/init.d/lrmd_dummy_daemon")
390
os.system("cp /usr/share/pacemaker/tests/cts/LSBDummy /etc/init.d/LSBDummy")
374
391
os.system("mkdir -p @CRM_CORE_DIR@/root")
376
393
os.system("systemctl daemon-reload")
378
395
def cleanup_test_environment(self):
396
if self.need_authkey:
397
os.system("rm -f /etc/pacemaker/authkey")
379
399
os.system("rm -f /lib/systemd/system/lrmd_dummy_daemon.service")
380
os.system("rm -f /etc/init.d/lrmd_dummy_daemon")
400
os.system("rm -f /etc/init.d/LSBDummy")
381
401
os.system("rm -f /usr/sbin/lrmd_dummy_daemon")
382
402
os.system("rm -f /usr/sbin/fence_dummy_monitor")
383
403
os.system("rm -f /usr/sbin/fence_dummy_sleep")
505
525
"-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:ok op_status:complete\" ")
506
526
test.add_cmd("-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:ok op_status:complete\" -t 3000")
507
527
test.add_cmd("-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:ok op_status:complete\" -t 3000")
508
test.add_cmd_and_kill("rm -f /var/run/Dummy-test_rsc.state", "-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:not running op_status:complete\" -t 6000")
528
test.add_cmd_and_kill("rm -f @localstatedir@/run/Dummy-test_rsc.state", "-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:not running op_status:complete\" -t 6000")
509
529
test.add_cmd("-c cancel -r \"test_rsc\" -a \"monitor\" -i \"100\" -t \"3000\" "
510
530
"-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:not running op_status:Cancelled\" ")
511
531
test.add_expected_fail_cmd("-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:not running op_status:complete\" -t 3000")
522
542
test.add_cmd("-c exec -r \"test_rsc\" -a \"monitor\" -i \"100\" -t 3000 -o "
523
543
"-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:ok op_status:complete\" ")
524
544
test.add_expected_fail_cmd("-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:ok op_status:complete\" -t 3000")
525
test.add_cmd_and_kill("rm -f /var/run/Dummy-test_rsc.state", "-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:not running op_status:complete\" -t 6000")
545
test.add_cmd_and_kill("rm -f @localstatedir@/run/Dummy-test_rsc.state", "-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:not running op_status:complete\" -t 6000")
526
546
test.add_cmd("-c cancel -r \"test_rsc\" -a \"monitor\" -i \"100\" -t \"3000\" "
527
547
"-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:not running op_status:Cancelled\" ")
528
548
test.add_expected_fail_cmd("-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:not running op_status:complete\" -t 3000")
652
672
### These are tests that target specific cases ###
653
673
def build_custom_tests(self):
675
### verify resource temporary folder is created and used by heartbeat agents. ###
676
test = self.new_test("rsc_tmp_dir", "Verify creation and use of rsc temporary state directory")
677
test.add_sys_cmd("ls", "-al @CRM_RSCTMP_DIR@")
678
test.add_cmd("-c register_rsc -r test_rsc -P heartbeat -C ocf -T Dummy "
679
"-l \"NEW_EVENT event_type:register rsc_id:test_rsc action:none rc:ok op_status:complete\" -t 3000")
680
test.add_cmd("-c exec -r test_rsc -a start -t 4000")
681
test.add_sys_cmd("ls", "-al @CRM_RSCTMP_DIR@")
682
test.add_sys_cmd("ls", "@CRM_RSCTMP_DIR@/Dummy-test_rsc.state")
683
test.add_cmd("-c exec -r test_rsc -a stop -t 4000")
684
test.add_cmd("-c unregister_rsc -r test_rsc -t 3000 "
685
"-l \"NEW_EVENT event_type:unregister rsc_id:test_rsc action:none rc:ok op_status:complete\" ")
654
687
### start delay then stop test ###
655
688
test = self.new_test("start_delay", "Verify start delay works as expected.")
656
689
test.add_cmd("-c register_rsc -r test_rsc -P pacemaker -C ocf -T Dummy "
715
748
"-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:start rc:ok op_status:complete\" ")
716
749
test.add_cmd("-c exec -r \"test_rsc\" -a \"monitor\" -i \"100\" -t 3000 -n "
717
750
"-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:ok op_status:complete\" ")
718
# this will fail because the monitor notifications should only go to the original caller, which no longer exists.
751
# this will fail because the monitor notifications should only go to the original caller, which no longer exists.
719
752
test.add_expected_fail_cmd("-l \"NEW_EVENT event_type:exec_complete rsc_id:test_rsc action:monitor rc:ok op_status:complete\" -t 3000")
720
753
test.add_cmd("-c cancel -r \"test_rsc\" -a \"monitor\" -i \"100\" -t \"3000\" ")
721
754
test.add_cmd("-c unregister_rsc -r \"test_rsc\" -t 3000 "
732
765
### get metadata ###
733
766
test = self.new_test("get_lsb_metadata", "Retrieve metadata for a resource")
734
test.add_cmd_check_stdout("-c metadata -C \"lsb\" -T \"lrmd_dummy_daemon\""
735
,"resource-agent name=\"lrmd_dummy_daemon\"")
767
test.add_cmd_check_stdout("-c metadata -C \"lsb\" -T \"LSBDummy\""
768
,"resource-agent name='LSBDummy'")
737
770
### get stonith metadata ###
738
771
test = self.new_test("get_stonith_metadata", "Retrieve stonith metadata for a resource")
762
795
test.add_cmd_check_stdout("-c list_agents -C ocf", "Stateful")
763
796
test.add_cmd_check_stdout("-c list_agents -C lsb", "", "Stateful") ### should not exist
764
797
test.add_cmd_check_stdout("-c list_agents -C service", "", "Stateful") ### should not exist
765
test.add_cmd_check_stdout("-c list_agents ", "lrmd_dummy_daemon") ### init.d ###
766
test.add_cmd_check_stdout("-c list_agents -C lsb", "lrmd_dummy_daemon")
767
test.add_cmd_check_stdout("-c list_agents -C service", "lrmd_dummy_daemon")
798
test.add_cmd_check_stdout("-c list_agents ", "LSBDummy") ### init.d ###
799
test.add_cmd_check_stdout("-c list_agents -C lsb", "LSBDummy")
800
test.add_cmd_check_stdout("-c list_agents -C service", "LSBDummy")
768
801
test.add_cmd_check_stdout("-c list_agents -C ocf", "", "lrmd_dummy_daemon") ### should not exist
770
803
test.add_cmd_check_stdout("-c list_agents -C ocf", "", "lrmd_dummy_daemon") ### should not exist
775
808
if "systemd" in self.rsc_classes:
776
809
test.add_cmd_check_stdout("-c list_agents ", "lrmd_dummy_daemon") ### systemd ###
777
test.add_cmd_check_stdout("-c list_agents -C service", "lrmd_dummy_daemon")
778
test.add_cmd_check_stdout("-c list_agents -C systemd", "", "Stateful") ### should not exist
810
test.add_cmd_check_stdout("-c list_agents -C service", "LSBDummy")
811
test.add_cmd_check_stdout("-c list_agents -C systemd", "", "Stateful") ### should not exist
779
812
test.add_cmd_check_stdout("-c list_agents -C systemd", "lrmd_dummy_daemon")
780
813
test.add_cmd_check_stdout("-c list_agents -C systemd", "", "fence_dummy_monitor") ### should not exist
782
815
if "upstart" in self.rsc_classes:
783
816
test.add_cmd_check_stdout("-c list_agents ", "lrmd_dummy_daemon") ### upstart ###
784
test.add_cmd_check_stdout("-c list_agents -C service", "lrmd_dummy_daemon")
785
test.add_cmd_check_stdout("-c list_agents -C upstart", "", "Stateful") ### should not exist
817
test.add_cmd_check_stdout("-c list_agents -C service", "LSBDummy")
818
test.add_cmd_check_stdout("-c list_agents -C upstart", "", "Stateful") ### should not exist
786
819
test.add_cmd_check_stdout("-c list_agents -C upstart", "lrmd_dummy_daemon")
787
820
test.add_cmd_check_stdout("-c list_agents -C upstart", "", "fence_dummy_monitor") ### should not exist
855
888
self.options['verbose'] = 0
856
889
self.options['invalid-arg'] = ""
857
890
self.options['show-usage'] = 0
858
self.options['tls-backend'] = 0
891
self.options['pacemaker-remote'] = 0
860
893
def build_options(self, argv):
870
903
self.options['list-tests'] = 1
871
904
elif args[i] == "-V" or args[i] == "--verbose":
872
905
self.options['verbose'] = 1
873
elif args[i] == "-S" or args[i] == "--tls-backend":
874
self.options['tls-backend'] = 1
906
elif args[i] == "-R" or args[i] == "--pacemaker-remote":
907
self.options['pacemaker-remote'] = 1
875
908
elif args[i] == "-r" or args[i] == "--run-only":
876
909
self.options['run-only'] = args[i+1]
887
920
print "\t [--list-tests | -l] Print out all registered tests."
888
921
print "\t [--run-only | -r 'testname'] Run a specific test"
889
922
print "\t [--verbose | -V] Verbose output"
890
print "\t [--tls-backend | -S Use tls backend"
923
print "\t [--pacemaker-remote | -R Test pacemaker-remote binary instead of lrmd."
891
924
print "\t [--run-only-pattern | -p 'string'] Run only tests containing the string value"
892
925
print "\n\tExample: Run only the test 'start_top'"
893
926
print "\t\t python ./regression.py --run-only start_stop"
899
932
o = TestOptions()
900
933
o.build_options(argv)
902
tests = Tests(o.options['verbose'], o.options['tls-backend'])
935
tests = Tests(o.options['verbose'], o.options['pacemaker-remote'])
904
937
tests.build_generic_tests()
905
938
tests.build_multi_rsc_tests()