t_smf.py revision 2310
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# CDDL HEADER START
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# The contents of this file are subject to the terms of the
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# Common Development and Distribution License (the "License").
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# You may not use this file except in compliance with the License.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# See the License for the specific language governing permissions
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# and limitations under the License.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# When distributing Covered Code, include this CDDL HEADER in each
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# If applicable, add the following below this CDDL HEADER, with the
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# fields enclosed by brackets "[]" replaced with your own identifying
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# information: Portions Copyright [yyyy] [name of copyright owner]
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# CDDL HEADER END
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschclass TestSMF(pkg5unittest.SingleDepotTestCase):
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch # Only start/stop the depot once (instead of for every test)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschif __name__ == "__main__":
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch opts, pargs = getopt.getopt(sys.argv[1:], "cp:")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch except getopt.GetoptError, e:
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch usage(_("illegal global option -- %s") % e.opt)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch found_c = False
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch for opt, arg in opts:
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if opt == "-c":
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch found_c = True
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch elif opt == "-p":
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch with open(os.path.join(os.environ["PKG_TEST_DIR"],
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch os.environ["PKG_SVCPROP_OUTPUT"]), "rb") as fh:
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch s = fh.read()
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch prop_dict = {}
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch for l in s.splitlines():
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch t = l.split(None, 2)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if len(t) == 3:
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch prop_dict[t[0]] = t[2]
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch prop = prop_dict.get(prop, None)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if not found_c or not prop:
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschexit $PKG_SVCADM_EXIT_CODE
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# called from pkg.client.actuator using 'svcs -H -o fmri <string>'
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch# so $4 is the FMRI pattern that we're interested in resolving
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch # the following are too relaxed, eg.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch # would match, but is sufficient for this test case as we only
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch # ever resolve services that truely exist here.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch *sy*t?st_suspend_svc:def*)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch FMRI=svc:/system/test_suspend_svc:default
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch *test_disable_svc*)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch FMRI=svc:/system/test_disable_svc:default
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch *test_restart_svc*)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch FMRI=svc:/system/test_restart_svc:default
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch FMRI="ERROR - t_actuators.py svcs wrapper failed to match $4"
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcprop_enabled" :
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch"""general/enabled boolean true
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/start_method_timestamp time 1222382991.639687000
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/state_timestamp time 1222382991.644413000
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschlocal-filesystems/entities fmri svc:/system/filesystem/local
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschlocal-filesystems/grouping astring require_all
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschremote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschremote-filesystems/grouping astring optional_all
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstartd/duration astring transient
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstart/type astring method
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstop/type astring method""",
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcprop_disabled" :
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch"""general/enabled boolean false
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/start_method_timestamp time 1222382991.639687000
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/state astring disabled
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/state_timestamp time 1222992132.445811000
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschlocal-filesystems/entities fmri svc:/system/filesystem/local
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschlocal-filesystems/grouping astring require_all
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschremote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschremote-filesystems/grouping astring optional_all
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstartd/duration astring transient
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstart/type astring method
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstop/type astring method""",
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcprop_temp_enabled" :
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch"""general/enabled boolean false
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/start_method_timestamp time 1222992237.506096000
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/state_timestamp time 1222992237.527408000
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschlocal-filesystems/entities fmri svc:/system/filesystem/local
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschlocal-filesystems/grouping astring require_all
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschremote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschremote-filesystems/grouping astring optional_all
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstartd/duration astring transient
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstart/type astring method
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstop/type astring method""",
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcprop_temp_disabled" :
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch"""general/enabled boolean true
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/start_method_timestamp time 1222992237.506096000
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/state astring disabled
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/state_timestamp time 1222992278.822335000
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschlocal-filesystems/entities fmri svc:/system/filesystem/local
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschlocal-filesystems/grouping astring require_all
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschremote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschremote-filesystems/grouping astring optional_all
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstartd/duration astring transient
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstart/type astring method
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstop/type astring method""",
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcprop_maintenance":
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch"""general/enabled boolean true
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/start_method_timestamp time 1222382991.639687000
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/state astring maintenance
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschrestarter/state_timestamp time 1222382991.644413000
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschlocal-filesystems/entities fmri svc:/system/filesystem/local
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschlocal-filesystems/grouping astring require_all
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschremote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschremote-filesystems/grouping astring optional_all
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstartd/duration astring transient
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstart/type astring method
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstop/type astring method""",
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch self.make_misc_files(self.misc_files, prefix="testdata")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch """Test that the smf interface performs as expected."""
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch testdata_dir = os.path.join(self.test_root, "testdata")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcadm_arguments")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch smf.restart("svc:/system/test_restart_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcadm restart svc:/system/test_restart_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch smf.refresh("svc:/system/test_refresh_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcadm refresh svc:/system/test_refresh_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch smf.mark("maintenance", "svc:/system/test_mark_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcadm mark maintenance svc:/system/test_mark_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch smf.mark("degraded", "svc:/system/test_mark_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcadm mark degraded svc:/system/test_mark_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch smf.disable("svc:/system/test_disable_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcadm disable -s svc:/system/test_disable_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch smf.disable("svc:/system/test_disable_svc:default",
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcadm disable -s -t svc:/system/test_disable_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch smf.enable("svc:/system/test_enable_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcadm enable svc:/system/test_enable_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch smf.enable("svc:/system/test_enable_svc:default",
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "svcadm enable -t svc:/system/test_enable_svc:default")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_enabled"
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch self.assertEqual(smf.get_prop("foo", "start/timeout_seconds"),
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch self.assertEqual(smf.get_prop("foo", "stop/exec"), ":true")
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch self.assert_("0" in p["start/timeout_seconds"])
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch # "a" should be removed from the list of fmris since it's not
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch # an instance.
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch self.assertEqual(fmris, set(["test_disable_svc:default"]))
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch fmris = smf.check_fmris("foo", set(["test_disable_svc*"]))
5b2062e40f54535b212e800ffc79de0e405d4560Timo Sirainen set(["svc:/system/test_disable_svc:default"]))
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_ENABLED)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_disabled"
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_DISABLED)
5b2062e40f54535b212e800ffc79de0e405d4560Timo Sirainen os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_enabled"
5b2062e40f54535b212e800ffc79de0e405d4560Timo Sirainen self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_TMP_ENABLED)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_disabled"
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch self.assertEqual(smf.get_state("foo"), smf.SMF_SVC_TMP_DISABLED)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_maintenance"