Beispiel #1
0
        def exec_fail_actuators(self, image):
                """handle a failed install"""

                if self.do_nothing:
                        return

                params = tuple(self.suspend_fmris |
                    self.tmp_suspend_fmris)

                if params:
                        smf.mark("maintenance", params)
Beispiel #2
0
        def test_zone_actuators(self):
                """Test that the smf interface for zones performs as
                expected."""

                testdata_dir = os.path.join(self.test_root, "testdata")
                svcadm_output = os.path.join(testdata_dir,
                    "svcadm_arguments")
                zlogin_output = os.path.join(testdata_dir,
                    "zlogin_arguments")
                os.environ["PKG_TEST_DIR"] = testdata_dir
                DebugValues["bin_zlogin"] = os.path.join(self.test_root,
                    "smf_cmds", "bin_zlogin")

                zone = "z1"

                smf.restart("svc:/system/test_restart_svc:default", zone=zone)
                self.file_contains(zlogin_output,
                    "zlogin "+zone)
                os.unlink(zlogin_output)
                self.file_contains(svcadm_output,
                    "svcadm restart svc:/system/test_restart_svc:default")
                os.unlink(svcadm_output)

                smf.refresh("svc:/system/test_refresh_svc:default", zone=zone)
                self.file_contains(zlogin_output,
                    "zlogin "+zone)
                os.unlink(zlogin_output)
                self.file_contains(svcadm_output,
                    "svcadm refresh svc:/system/test_refresh_svc:default")
                os.unlink(svcadm_output)

                smf.mark("maintenance", "svc:/system/test_mark_svc:default", zone=zone)
                self.file_contains(zlogin_output,
                    "zlogin "+zone)
                os.unlink(zlogin_output)
                self.file_contains(svcadm_output,
                    "svcadm mark maintenance svc:/system/test_mark_svc:default")
                os.unlink(svcadm_output)

                smf.enable("svc:/system/test_enable_svc:default", zone=zone)
                self.file_contains(zlogin_output,
                    "zlogin "+zone)
                os.unlink(zlogin_output)
                self.file_contains(svcadm_output,
                    "svcadm enable svc:/system/test_enable_svc:default")
                os.unlink(svcadm_output)

                smf.disable("svc:/system/test_disable_svc:default", zone=zone)
                self.file_contains(zlogin_output,
                    "zlogin "+zone)
                os.unlink(zlogin_output)
                self.file_contains(svcadm_output,
                    "svcadm disable -s svc:/system/test_disable_svc:default")
                os.unlink(svcadm_output)

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_enabled"
                smf.get_prop("foo", "start/timeout_seconds", zone=zone)
                self.file_contains(zlogin_output,
                    "zlogin "+zone)
                os.unlink(zlogin_output)

                smf.is_disabled("foo", zone=zone)
                self.file_contains(zlogin_output,
                    "zlogin "+zone)
                os.unlink(zlogin_output)

                smf.get_state("foo", zone=zone)
                self.file_contains(zlogin_output,
                    "zlogin "+zone)
                os.unlink(zlogin_output)
Beispiel #3
0
        def test_smf(self):
                """Test that the smf interface performs as expected."""

                testdata_dir = os.path.join(self.test_root, "testdata")
                svcadm_output = os.path.join(testdata_dir,
                    "svcadm_arguments")
                os.environ["PKG_TEST_DIR"] = testdata_dir
                os.environ["PKG_SVCADM_EXIT_CODE"] = "0"
                os.environ["PKG_SVCPROP_EXIT_CODE"] = "0"

                smf.restart("svc:/system/test_restart_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm restart svc:/system/test_restart_svc:default")
                os.unlink(svcadm_output)

                smf.restart("svc:/system/test_restart_svc:default",
                    sync_timeout=0)
                self.file_contains(svcadm_output,
                    "svcadm restart svc:/system/test_restart_svc:default")
                os.unlink(svcadm_output)

                smf.restart("svc:/system/test_restart_svc:default",
                    sync_timeout=-1)
                self.file_contains(svcadm_output,
                    "svcadm restart -s svc:/system/test_restart_svc:default")
                os.unlink(svcadm_output)

                smf.restart("svc:/system/test_restart_svc:default",
                    sync_timeout=10)
                self.file_contains(svcadm_output,
                    "svcadm restart -s svc:/system/test_restart_svc:default")
                os.unlink(svcadm_output)

                smf.refresh("svc:/system/test_refresh_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm refresh svc:/system/test_refresh_svc:default")
                os.unlink(svcadm_output)

                smf.refresh("svc:/system/test_refresh_svc:default",
                    sync_timeout=0)
                self.file_contains(svcadm_output,
                    "svcadm refresh svc:/system/test_refresh_svc:default")
                os.unlink(svcadm_output)

                smf.refresh("svc:/system/test_refresh_svc:default",
                    sync_timeout=-1)
                self.file_contains(svcadm_output,
                    "svcadm refresh -s svc:/system/test_refresh_svc:default")
                os.unlink(svcadm_output)

                smf.refresh("svc:/system/test_refresh_svc:default",
                    sync_timeout=10)
                self.file_contains(svcadm_output,
                    "svcadm refresh -s svc:/system/test_refresh_svc:default")
                os.unlink(svcadm_output)

                smf.mark("maintenance", "svc:/system/test_mark_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm mark maintenance svc:/system/test_mark_svc:default")
                os.unlink(svcadm_output)

                smf.mark("degraded", "svc:/system/test_mark_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm mark degraded svc:/system/test_mark_svc:default")
                os.unlink(svcadm_output)

                smf.disable("svc:/system/test_disable_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm disable -s svc:/system/test_disable_svc:default")
                os.unlink(svcadm_output)

                smf.disable("svc:/system/test_disable_svc:default",
                    temporary=True)
                self.file_contains(svcadm_output,
                    "svcadm disable -s -t svc:/system/test_disable_svc:default")
                os.unlink(svcadm_output)

                smf.enable("svc:/system/test_enable_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm enable svc:/system/test_enable_svc:default")
                os.unlink(svcadm_output)

                smf.enable("svc:/system/test_enable_svc:default",
                    temporary=True)
                self.file_contains(svcadm_output,
                    "svcadm enable -t svc:/system/test_enable_svc:default")
                os.unlink(svcadm_output)

                smf.enable("svc:/system/test_enable_svc:default",
                    sync_timeout=-1)
                self.file_contains(svcadm_output,
                    "svcadm enable -s svc:/system/test_enable_svc:default")
                os.unlink(svcadm_output)

                smf.enable("svc:/system/test_enable_svc:default",
                    sync_timeout=0)
                self.file_contains(svcadm_output,
                    "svcadm enable svc:/system/test_enable_svc:default")
                os.unlink(svcadm_output)

                smf.enable("svc:/system/test_enable_svc:default",
                    sync_timeout=10)
                self.file_contains(svcadm_output,
                    "svcadm enable -s svc:/system/test_enable_svc:default")
                os.unlink(svcadm_output)

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_enabled"
                self.assertEqual(smf.get_prop("foo", "start/timeout_seconds"),
                    "0")
                self.assertEqual(smf.get_prop("foo", "stop/exec"), ":true")

                p = smf.get_props("foo")
                self.assertTrue("start/timeout_seconds" in p)
                self.assertTrue("0" in p["start/timeout_seconds"])
                self.assertTrue("stop/exec" in p)
                self.assertTrue("true" in p["stop/exec"])

                # "a" should be removed from the list of fmris since it's not
                # an instance.
                fmris = smf.check_fmris("foo", set(["a"]))
                self.assertEqual(fmris, set([]))

                fmris = smf.check_fmris("foo",
                    set(["test_disable_svc:default"]))
                self.assertEqual(fmris, set(["test_disable_svc:default"]))

                fmris = smf.check_fmris("foo", set(["test_disable_svc*"]))
                self.assertEqual(fmris,
                    set(["svc:/system/test_disable_svc:default"]))

                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_ENABLED)
                self.assertTrue(not smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_disabled"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_DISABLED)
                self.assertTrue(smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_enabled"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_TMP_ENABLED)
                self.assertTrue(not smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_enabled2"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_TMP_ENABLED)
                self.assertTrue(not smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_disabled"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_TMP_DISABLED)
                self.assertTrue(smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_disabled2"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_TMP_DISABLED)
                self.assertTrue(smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_maintenance"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_MAINTENANCE)
                self.assertTrue(smf.is_disabled("foo"))

                # test if supplying tuples and lists as arguments works
                smf.enable(["svc:/system/test_enable_svc:default", "foo"])
                self.file_contains(svcadm_output,
                    "svcadm enable svc:/system/test_enable_svc:default foo")
                os.unlink(svcadm_output)
                smf.enable(("svc:/system/test_enable_svc:default", "foo"))
                self.file_contains(svcadm_output,
                    "svcadm enable svc:/system/test_enable_svc:default foo")
                os.unlink(svcadm_output)

                smf.disable(["svc:/system/test_enable_svc:default", "foo"])
                self.file_contains(svcadm_output,
                    "svcadm disable -s svc:/system/test_enable_svc:default foo")
                os.unlink(svcadm_output)
                smf.disable(("svc:/system/test_enable_svc:default", "foo"))
                self.file_contains(svcadm_output,
                    "svcadm disable -s svc:/system/test_enable_svc:default foo")
                os.unlink(svcadm_output)

                smf.refresh(["svc:/system/test_enable_svc:default", "foo"])
                self.file_contains(svcadm_output,
                    "svcadm refresh svc:/system/test_enable_svc:default foo")
                os.unlink(svcadm_output)
                smf.refresh(("svc:/system/test_enable_svc:default", "foo"))
                self.file_contains(svcadm_output,
                    "svcadm refresh svc:/system/test_enable_svc:default foo")
                os.unlink(svcadm_output)

                smf.restart(["svc:/system/test_enable_svc:default", "foo"])
                self.file_contains(svcadm_output,
                    "svcadm restart svc:/system/test_enable_svc:default foo")
                os.unlink(svcadm_output)
                smf.restart(("svc:/system/test_enable_svc:default", "foo"))
                self.file_contains(svcadm_output,
                    "svcadm restart svc:/system/test_enable_svc:default foo")
                os.unlink(svcadm_output)

                smf.mark("degraded", ["svc:/system/test_enable_svc:default", "foo"])
                self.file_contains(svcadm_output,
                    "svcadm mark degraded svc:/system/test_enable_svc:default foo")
                os.unlink(svcadm_output)
                smf.mark("degraded", ("svc:/system/test_enable_svc:default", "foo"))
                self.file_contains(svcadm_output,
                    "svcadm mark degraded svc:/system/test_enable_svc:default foo")
                os.unlink(svcadm_output)
Beispiel #4
0
        def test_smf(self):
                """Test that the smf interface performs as expected."""

                testdata_dir = os.path.join(self.test_root, "testdata")
                svcadm_output = os.path.join(testdata_dir,
                    "svcadm_arguments")
                os.environ["PKG_TEST_DIR"] = testdata_dir
                os.environ["PKG_SVCADM_EXIT_CODE"] = "0"
                os.environ["PKG_SVCPROP_EXIT_CODE"] = "0"

                smf.restart("svc:/system/test_restart_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm restart svc:/system/test_restart_svc:default")
                os.unlink(svcadm_output)

                smf.refresh("svc:/system/test_refresh_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm refresh svc:/system/test_refresh_svc:default")
                os.unlink(svcadm_output)

                smf.mark("maintenance", "svc:/system/test_mark_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm mark maintenance svc:/system/test_mark_svc:default")
                os.unlink(svcadm_output)

                smf.mark("degraded", "svc:/system/test_mark_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm mark degraded svc:/system/test_mark_svc:default")
                os.unlink(svcadm_output)

                smf.disable("svc:/system/test_disable_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm disable -s svc:/system/test_disable_svc:default")
                os.unlink(svcadm_output)

                smf.disable("svc:/system/test_disable_svc:default",
                    temporary=True)
                self.file_contains(svcadm_output,
                    "svcadm disable -s -t svc:/system/test_disable_svc:default")
                os.unlink(svcadm_output)

                smf.enable("svc:/system/test_enable_svc:default")
                self.file_contains(svcadm_output,
                    "svcadm enable svc:/system/test_enable_svc:default")
                os.unlink(svcadm_output)

                smf.enable("svc:/system/test_enable_svc:default",
                    temporary=True)
                self.file_contains(svcadm_output,
                    "svcadm enable -t svc:/system/test_enable_svc:default")
                os.unlink(svcadm_output)

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_enabled"
                self.assertEqual(smf.get_prop("foo", "start/timeout_seconds"),
                    "0")
                self.assertEqual(smf.get_prop("foo", "stop/exec"), ":true")

                p = smf.get_props("foo")
                self.assert_("start/timeout_seconds" in p)
                self.assert_("0" in p["start/timeout_seconds"])
                self.assert_("stop/exec" in p)
                self.assert_("true" in p["stop/exec"])

                # "a" should be removed from the list of fmris since it's not
                # an instance.
                fmris = smf.check_fmris("foo", set(["a"]))
                self.assertEqual(fmris, set([]))

                fmris = smf.check_fmris("foo",
                    set(["test_disable_svc:default"]))
                self.assertEqual(fmris, set(["test_disable_svc:default"]))

                fmris = smf.check_fmris("foo", set(["test_disable_svc*"]))
                self.assertEqual(fmris,
                    set(["svc:/system/test_disable_svc:default"]))

                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_ENABLED)
                self.assert_(not smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_disabled"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_DISABLED)
                self.assert_(smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_enabled"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_TMP_ENABLED)
                self.assert_(not smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_enabled2"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_TMP_ENABLED)
                self.assert_(not smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_disabled"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_TMP_DISABLED)
                self.assert_(smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_disabled2"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_TMP_DISABLED)
                self.assert_(smf.is_disabled("foo"))

                os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_maintenance"
                self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_MAINTENANCE)
                self.assert_(smf.is_disabled("foo"))