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)
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)
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)
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)
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"))