Beispiel #1
0
def get_smf_repo_info():
        """Return a list of repo_info from the online instances of pkg/server
        which are marked as pkg/standalone = False and pkg/readonly = True."""

        smf_instances = smf.check_fmris(None, "{0}:*".format(PKG_SERVER_SVC))
        repo_info = []
        for fmri in smf_instances:
                repo_prefix = fmri.split(":")[-1]
                repo_root = smf.get_prop(fmri, "pkg/inst_root")
                writable_root = smf.get_prop(fmri, "pkg/writable_root")
                if not writable_root or writable_root == '""':
                        writable_root = None
                state = smf.get_prop(fmri, "restarter/state")
                readonly = smf.get_prop(fmri, "pkg/readonly")
                standalone = smf.get_prop(fmri, "pkg/standalone")

                if (state == "online" and
                    readonly == "true" and
                    standalone == "false"):
                        repo_info.append((repo_root,
                            _affix_slash(repo_prefix), writable_root))
        if not repo_info:
                raise DepotException(_(
                    "No online, readonly, non-standalone instances of "
                    "{0} found.").format(PKG_SERVER_SVC))
        return repo_info
Beispiel #2
0
    def exec_pre_actuators(self, image):
        """do pre execution actuator processing..."""

        if self.do_nothing:
            return

        suspend_fmris = self.update.get("suspend_fmri", set())
        tmp_suspend_fmris = set()

        disable_fmris = self.removal.get("disable_fmri", set())

        suspend_fmris = smf.check_fmris("suspend_fmri",
                                        suspend_fmris,
                                        zone=self.zone)
        disable_fmris = smf.check_fmris("disable_fmri",
                                        disable_fmris,
                                        zone=self.zone)
        # eliminate services not loaded or not running
        # remember those services enabled only temporarily

        for fmri in suspend_fmris.copy():
            state = smf.get_state(fmri, zone=self.zone)
            if state <= smf.SMF_SVC_TMP_ENABLED:
                suspend_fmris.remove(fmri)
            if state == smf.SMF_SVC_TMP_ENABLED:
                tmp_suspend_fmris.add(fmri)

        for fmri in disable_fmris.copy():
            if smf.is_disabled(fmri, zone=self.zone):
                disable_fmris.remove(fmri)

        self.suspend_fmris = suspend_fmris
        self.tmp_suspend_fmris = tmp_suspend_fmris

        params = tuple(suspend_fmris | tmp_suspend_fmris)

        if params:
            self.__invoke(smf.disable, params, temporary=True)

        params = tuple(disable_fmris)

        if params:
            self.__invoke(smf.disable, params)
Beispiel #3
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)
Beispiel #4
0
        def exec_pre_actuators(self, image):
                """do pre execution actuator processing..."""

                if self.do_nothing:
                        return

                suspend_fmris = self.update.get("suspend_fmri", set())
                tmp_suspend_fmris = set()

                disable_fmris = self.removal.get("disable_fmri", set())

                suspend_fmris = smf.check_fmris("suspend_fmri", suspend_fmris)
                disable_fmris = smf.check_fmris("disable_fmri", disable_fmris)
                # eliminate services not loaded or not running
                # remember those services enabled only temporarily

                for fmri in suspend_fmris.copy():
                        state = smf.get_state(fmri)
                        if state <= smf.SMF_SVC_TMP_ENABLED:
                                suspend_fmris.remove(fmri)
                        if state == smf.SMF_SVC_TMP_ENABLED:
                                tmp_suspend_fmris.add(fmri)

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

                self.suspend_fmris = suspend_fmris
                self.tmp_suspend_fmris = tmp_suspend_fmris

                params = tuple(suspend_fmris | tmp_suspend_fmris)

                if params:
                        smf.disable(params, temporary=True)

                params = tuple(disable_fmris)

                if params:
                        smf.disable(params)
Beispiel #5
0
def get_smf_repo_info():
        """Return a list of repo_info from the online instances of pkg/server
        which are marked as pkg/standalone = False and pkg/readonly = True."""

        smf_instances = smf.check_fmris(None, "%s:*" % PKG_SERVER_SVC)
        repo_info = []
        for fmri in smf_instances:
                repo_prefix = fmri.split(":")[-1]
                repo_root = smf.get_prop(fmri, "pkg/inst_root")
                state = smf.get_prop(fmri, "restarter/state")
                readonly = smf.get_prop(fmri, "pkg/readonly")
                standalone = smf.get_prop(fmri, "pkg/standalone")

                if (state == "online" and
                    readonly == "true" and
                    standalone == "false"):
                        repo_info.append((repo_root,
                            _affix_slash(repo_prefix)))
        if not repo_info:
                raise DepotException(_(
                    "No online, readonly, non-standalone instances of "
                    "%s found.") % PKG_SERVER_SVC)
        return repo_info
Beispiel #6
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 #7
0
    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 hasattr(act, "__call__"):
                act()

        for act in self.install.itervalues():
            if hasattr(act, "__call__"):
                act()

        for act in self.update.itervalues():
            if hasattr(act, "__call__"):
                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,
                                        zone=self.zone)
        restart_fmris = smf.check_fmris("restart_fmri",
                                        restart_fmris,
                                        zone=self.zone)

        # ignore services not present or not
        # enabled

        for fmri in refresh_fmris.copy():
            if smf.is_disabled(fmri, zone=self.zone):
                refresh_fmris.remove(fmri)

        params = tuple(refresh_fmris)

        if params:
            self.__invoke(smf.refresh, params, sync_timeout=self.sync_timeout)

        for fmri in restart_fmris.copy():
            if smf.is_disabled(fmri, zone=self.zone):
                restart_fmris.remove(fmri)

        params = tuple(restart_fmris)
        if params:
            self.__invoke(smf.restart, params, sync_timeout=self.sync_timeout)

        # 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:
            self.__invoke(smf.enable, params, sync_timeout=self.sync_timeout)

        params = tuple(self.tmp_suspend_fmris)
        if params:
            self.__invoke(smf.enable,
                          params,
                          temporary=True,
                          sync_timeout=self.sync_timeout)
Beispiel #8
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"))
Beispiel #9
0
        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)