~ubuntu-branches/ubuntu/utopic/pacemaker/utopic-proposed

« back to all changes in this revision

Viewing changes to lrmd/regression.py.in

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-08-15 11:27:07 UTC
  • mfrom: (1.1.12) (2.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20130815112707-5r864ink7jme3zl5
Tags: 1.1.10+git20130802-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/control: Build-Depends on libqb-dev; Depends on libheartbeat2.
* Corosync's pacemaker plugin is disabled, hence not built:
  - debian/licrmcluster4-dev.install: Do not install plugin.h.
  - debian/pacemaker.install: Do not install pacemaker.lcrso.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
                self.name = name
37
37
                self.description = description
38
38
                self.cmds = []
39
 
                self.daemon_location = "@CRM_DAEMON_DIR@/lrmd"
 
39
 
 
40
                if tls:
 
41
                        self.daemon_location = "/usr/sbin/pacemaker_remoted"
 
42
                else:
 
43
                        self.daemon_location = "@CRM_DAEMON_DIR@/lrmd"
 
44
 
40
45
                self.test_tool_location = "@CRM_DAEMON_DIR@/lrmd_test"
41
46
                self.verbose = verbose
42
47
                self.tls = tls
72
77
 
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)
77
82
                test.wait()
78
83
 
79
84
                additional_args = ""
80
85
 
81
 
                self.stonith_process = subprocess.Popen(shlex.split("@CRM_DAEMON_DIR@/stonithd -s"))
82
 
                if self.tls:
83
 
                        additional_args = additional_args + " -t "
 
86
                if self.tls == 0:
 
87
                        self.stonith_process = subprocess.Popen(shlex.split("@CRM_DAEMON_DIR@/stonithd -s"))
 
88
 
84
89
                if self.verbose:
85
 
                        additional_args = additional_args + " -VVV "
 
90
                        additional_args = additional_args + " -VV "
86
91
 
87
92
                self.lrmd_process = subprocess.Popen(shlex.split("%s %s -l /tmp/lrmd-regression.log" % (self.daemon_location, additional_args)))
88
93
 
123
128
                self.__new_cmd(self.test_tool_location, args, 0, "", kill=killProc)
124
129
 
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, "")
127
132
 
128
133
        def get_exitcode(self):
129
134
                return self.result_exitcode
170
175
        def run(self):
171
176
                res = 0
172
177
                i = 1
 
178
 
 
179
                if self.tls and self.name.count("stonith") != 0:
 
180
                        self.result_txt = "SKIPPED - '%s' - disabled when testing pacemaker_remote" % (self.name)
 
181
                        print self.result_txt
 
182
                        return res
 
183
 
173
184
                self.start_environment()
174
185
 
175
186
                if self.verbose:
204
215
                self.tests = []
205
216
                self.verbose = verbose
206
217
                self.tls = tls;
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
 
221
                if self.tls:
 
222
                        self.rsc_classes.remove("stonith")
 
223
 
209
224
                print "Testing "+repr(self.rsc_classes)
210
225
 
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")
214
 
 
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\" ",
254
265
 
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\" ",
267
278
 
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\"",
298
309
                return test
299
310
 
300
311
        def setup_test_environment(self):
 
312
                os.system("service pacemaker_remote stop")
301
313
                self.cleanup_test_environment()
302
314
 
 
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")
 
319
 
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")
372
389
 
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")
375
392
 
376
393
                os.system("systemctl daemon-reload")
377
394
 
378
395
        def cleanup_test_environment(self):
 
396
                if self.need_authkey:
 
397
                    os.system("rm -f /etc/pacemaker/authkey")
 
398
 
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")
651
671
 
652
672
        ### These are tests that target specific cases ###
653
673
        def build_custom_tests(self):
 
674
 
 
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\" ")
 
686
 
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 "
731
764
 
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'")
736
769
 
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
769
802
 
770
803
                test.add_cmd_check_stdout("-c list_agents -C ocf", "", "lrmd_dummy_daemon")               ### should not exist
774
807
 
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
781
814
 
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
788
821
 
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
859
892
 
860
893
        def build_options(self, argv):
861
894
                args = argv[1:]
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]
877
910
                                skip = 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)
901
934
 
902
 
        tests = Tests(o.options['verbose'], o.options['tls-backend'])
 
935
        tests = Tests(o.options['verbose'], o.options['pacemaker-remote'])
903
936
 
904
937
        tests.build_generic_tests()
905
938
        tests.build_multi_rsc_tests()