示例#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
示例#2
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
示例#3
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)
示例#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
文件: 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"))