예제 #1
0
def _update_smf_props(smf_fmri, prop_list, orig, dest):
    """Update the smf props after the new prop values are generated."""

    smf_instances = smf.check_fmris(None, smf_fmri)
    for fmri in smf_instances:
        refresh = False
        for i in range(len(prop_list)):
            if orig[i] != dest[i]:
                smf.set_prop(fmri, prop_list[i], dest[i])
                refresh = True
        if refresh:
            smf.refresh(fmri)
예제 #2
0
파일: t_smf.py 프로젝트: ripudamank2/pkg5
        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)
예제 #3
0
파일: t_smf.py 프로젝트: aszeszo/test
        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"))
예제 #4
0
파일: t_smf.py 프로젝트: ripudamank2/pkg5
        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)
예제 #5
0
파일: actuator.py 프로젝트: aszeszo/test
        def exec_post_actuators(self, image):
                """do post execution actuator processing"""

                if self.do_nothing:
                        return

                # handle callables first

                for act in self.removal.itervalues():
                        if callable(act):
                                act()

                for act in self.install.itervalues():
                        if callable(act):
                                act()

                for act in self.update.itervalues():
                        if callable(act):
                                act()


                refresh_fmris = self.removal.get("refresh_fmri", set()) | \
                    self.update.get("refresh_fmri", set()) | \
                    self.install.get("refresh_fmri", set())

                restart_fmris = self.removal.get("restart_fmri", set()) | \
                    self.update.get("restart_fmri", set()) | \
                    self.install.get("restart_fmri", set())

                refresh_fmris = smf.check_fmris("refresh_fmri", refresh_fmris)
                restart_fmris = smf.check_fmris("restart_fmri", restart_fmris)

                # ignore services not present or not
                # enabled

                for fmri in refresh_fmris.copy():
                        if smf.is_disabled(fmri):
                                refresh_fmris.remove(fmri)

                params = tuple(refresh_fmris)

                if params:
                        smf.refresh(params)

                for fmri in restart_fmris.copy():
                        if smf.is_disabled(fmri):
                                restart_fmris.remove(fmri)

                params = tuple(restart_fmris)
                if params:
                        smf.restart(params)

                # reenable suspended services that were running
                # be sure to not enable services that weren't running
                # and temp. enable those services that were in that
                # state.

                params = tuple(self.suspend_fmris)
                if params:
                        smf.enable(params)

                params = tuple(self.tmp_suspend_fmris)
                if params:
                        smf.enable(params, temporary=True)