t_smf.py revision 3339
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
from __future__ import print_function
from . import testutils
if __name__ == "__main__":
import os
import pkg5unittest
import unittest
smf_cmds = { \
import getopt
import os
import sys
if __name__ == "__main__":
try:
opts, pargs = getopt.getopt(sys.argv[1:], "cp:")
except getopt.GetoptError as e:
usage(_("illegal global option -- {0}").format(e.opt))
found_c = False
prop = None
for opt, arg in opts:
if opt == "-c":
found_c = True
elif opt == "-p":
prop = arg
with open(os.path.join(os.environ["PKG_TEST_DIR"],
os.environ["PKG_SVCPROP_OUTPUT"]), "r") as fh:
s = fh.read()
if prop:
prop_dict = {}
for l in s.splitlines():
t = l.split(None, 2)
if len(t) == 3:
prop_dict[t[0]] = t[2]
prop = prop_dict.get(prop, None)
if not found_c or not prop:
sys.exit(1)
print(prop)
sys.exit(0)
print(s)
sys.exit(0)
""",
echo $0 "$@" >> $PKG_TEST_DIR/svcadm_arguments
exit $PKG_SVCADM_EXIT_CODE
""",
# called from pkg.client.actuator using 'svcs -H -o fmri <string>'
# so $4 is the FMRI pattern that we're interested in resolving
RETURN=0
case $4 in
svc:/system/test_refresh_svc:default)
FMRI=$4
;;
svc:/system/test_multi_svc?:default)
FMRI=$4
;;
# the following are too relaxed, eg.
# "svcs sys/foo/tZst_suspend_svc:defXX"
# would match, but is sufficient for this test case as we only
# ever resolve services that truely exist here.
*sy*t?st_suspend_svc:def*)
FMRI=svc:/system/test_suspend_svc:default
;;
*test_disable_svc*)
FMRI=svc:/system/test_disable_svc:default
;;
*test_restart_svc*)
FMRI=svc:/system/test_restart_svc:default
;;
*)
FMRI="ERROR - t_actuators.py svcs wrapper failed to match $4"
RETURN=1
;;
esac
echo $FMRI
exit $RETURN
""",
"bin_zlogin" : \
zone_name=$1
shift
echo "zlogin $zone_name" >> $PKG_TEST_DIR/zlogin_arguments
($*)""",
}
misc_files = { \
"svcprop_enabled" :
general/entity_stability astring Unstable
general/single_instance boolean true
restarter/start_method_timestamp time 1222382991.639687000
restarter/start_method_waitstatus integer 0
restarter/transient_contract count
restarter/auxiliary_state astring none
restarter/next_state astring none
restarter/state_timestamp time 1222382991.644413000
restarter_actions/refresh integer
restarter_actions/maint_on integer
restarter_actions/maint_off integer
restarter_actions/restart integer
local-filesystems/entities fmri svc:/system/filesystem/local
local-filesystems/grouping astring require_all
local-filesystems/restart_on astring none
local-filesystems/type astring service
remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
remote-filesystems/grouping astring optional_all
remote-filesystems/restart_on astring none
remote-filesystems/type astring service
start/timeout_seconds count 0
stop/timeout_seconds count 0
"svcprop_disabled" :
general/entity_stability astring Unstable
general/single_instance boolean true
restarter/start_method_timestamp time 1222382991.639687000
restarter/start_method_waitstatus integer 0
restarter/transient_contract count
restarter/auxiliary_state astring none
restarter/next_state astring none
restarter/state_timestamp time 1222992132.445811000
restarter_actions/refresh integer
restarter_actions/maint_on integer
restarter_actions/maint_off integer
restarter_actions/restart integer
local-filesystems/entities fmri svc:/system/filesystem/local
local-filesystems/grouping astring require_all
local-filesystems/restart_on astring none
local-filesystems/type astring service
remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
remote-filesystems/grouping astring optional_all
remote-filesystems/restart_on astring none
remote-filesystems/type astring service
start/timeout_seconds count 0
stop/timeout_seconds count 0
"svcprop_temp_enabled" :
general/entity_stability astring Unstable
general/single_instance boolean true
restarter/start_method_timestamp time 1222992237.506096000
restarter/start_method_waitstatus integer 0
restarter/transient_contract count
restarter/auxiliary_state astring none
restarter/next_state astring none
restarter/state_timestamp time 1222992237.527408000
restarter_actions/refresh integer
restarter_actions/maint_on integer
restarter_actions/maint_off integer
restarter_actions/restart integer
general_ovr/enabled boolean true
local-filesystems/entities fmri svc:/system/filesystem/local
local-filesystems/grouping astring require_all
local-filesystems/restart_on astring none
local-filesystems/type astring service
remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
remote-filesystems/grouping astring optional_all
remote-filesystems/restart_on astring none
remote-filesystems/type astring service
start/timeout_seconds count 0
stop/timeout_seconds count 0
"svcprop_temp_enabled2" :
general/entity_stability astring Unstable
general/single_instance boolean true
restarter/start_method_timestamp time 1222992237.506096000
restarter/start_method_waitstatus integer 0
restarter/transient_contract count
restarter/auxiliary_state astring none
restarter/next_state astring none
restarter/state_timestamp time 1222992237.527408000
restarter_actions/refresh integer
restarter_actions/maint_on integer
restarter_actions/maint_off integer
restarter_actions/restart integer
general_ovr/enabled boolean true
local-filesystems/entities fmri svc:/system/filesystem/local
local-filesystems/grouping astring require_all
local-filesystems/restart_on astring none
local-filesystems/type astring service
remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
remote-filesystems/grouping astring optional_all
remote-filesystems/restart_on astring none
remote-filesystems/type astring service
start/timeout_seconds count 0
stop/timeout_seconds count 0
"svcprop_temp_disabled" :
general/entity_stability astring Unstable
general/single_instance boolean true
restarter/start_method_timestamp time 1222992237.506096000
restarter/start_method_waitstatus integer 0
restarter/transient_contract count
restarter/auxiliary_state astring none
restarter/next_state astring none
restarter/state_timestamp time 1222992278.822335000
restarter_actions/refresh integer
restarter_actions/maint_on integer
restarter_actions/maint_off integer
restarter_actions/restart integer
general_ovr/enabled boolean false
local-filesystems/entities fmri svc:/system/filesystem/local
local-filesystems/grouping astring require_all
local-filesystems/restart_on astring none
local-filesystems/type astring service
remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
remote-filesystems/grouping astring optional_all
remote-filesystems/restart_on astring none
remote-filesystems/type astring service
start/timeout_seconds count 0
stop/timeout_seconds count 0
"svcprop_temp_disabled2" :
general/entity_stability astring Unstable
general/single_instance boolean true
restarter/start_method_timestamp time 1222992237.506096000
restarter/start_method_waitstatus integer 0
restarter/transient_contract count
restarter/auxiliary_state astring none
restarter/next_state astring none
restarter/state_timestamp time 1222992278.822335000
restarter_actions/refresh integer
restarter_actions/maint_on integer
restarter_actions/maint_off integer
restarter_actions/restart integer
general_ovr/enabled boolean false
local-filesystems/entities fmri svc:/system/filesystem/local
local-filesystems/grouping astring require_all
local-filesystems/restart_on astring none
local-filesystems/type astring service
remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
remote-filesystems/grouping astring optional_all
remote-filesystems/restart_on astring none
remote-filesystems/type astring service
start/timeout_seconds count 0
stop/timeout_seconds count 0
"svcprop_maintenance":
general/entity_stability astring Unstable
general/single_instance boolean true
restarter/start_method_timestamp time 1222382991.639687000
restarter/start_method_waitstatus integer 0
restarter/transient_contract count
restarter/auxiliary_state astring none
restarter/next_state astring none
restarter/state_timestamp time 1222382991.644413000
restarter_actions/refresh integer
restarter_actions/maint_on integer
restarter_actions/maint_off integer
restarter_actions/restart integer
local-filesystems/entities fmri svc:/system/filesystem/local
local-filesystems/grouping astring require_all
local-filesystems/restart_on astring none
local-filesystems/type astring service
remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs
remote-filesystems/grouping astring optional_all
remote-filesystems/restart_on astring none
remote-filesystems/type astring service
start/timeout_seconds count 0
stop/timeout_seconds count 0
"empty": "",
}
"""Test that the smf interface performs as expected."""
"svcadm_arguments")
"svcadm restart svc:/system/test_restart_svc:default")
sync_timeout=0)
"svcadm restart svc:/system/test_restart_svc:default")
sync_timeout=-1)
"svcadm restart -s svc:/system/test_restart_svc:default")
sync_timeout=10)
"svcadm restart -s -T 10 svc:/system/test_restart_svc:default")
"svcadm refresh svc:/system/test_refresh_svc:default")
sync_timeout=0)
"svcadm refresh svc:/system/test_refresh_svc:default")
sync_timeout=-1)
"svcadm refresh -s svc:/system/test_refresh_svc:default")
sync_timeout=10)
"svcadm refresh -s -T 10 svc:/system/test_refresh_svc:default")
"svcadm mark maintenance svc:/system/test_mark_svc:default")
"svcadm mark degraded svc:/system/test_mark_svc:default")
"svcadm disable -s svc:/system/test_disable_svc:default")
"svcadm disable -s -t svc:/system/test_disable_svc:default")
"svcadm enable svc:/system/test_enable_svc:default")
"svcadm enable -t svc:/system/test_enable_svc:default")
sync_timeout=-1)
"svcadm enable -s svc:/system/test_enable_svc:default")
sync_timeout=0)
"svcadm enable svc:/system/test_enable_svc:default")
sync_timeout=10)
"svcadm enable -s -T 10 svc:/system/test_enable_svc:default")
"0")
# "a" should be removed from the list of fmris since it's not
# an instance.
set(["test_disable_svc:default"]))
set(["svc:/system/test_disable_svc:default"]))
# test if supplying tuples and lists as arguments works
"svcadm enable svc:/system/test_enable_svc:default foo")
"svcadm enable svc:/system/test_enable_svc:default foo")
"svcadm disable -s svc:/system/test_enable_svc:default foo")
"svcadm disable -s svc:/system/test_enable_svc:default foo")
"svcadm refresh svc:/system/test_enable_svc:default foo")
"svcadm refresh svc:/system/test_enable_svc:default foo")
"svcadm restart svc:/system/test_enable_svc:default foo")
"svcadm restart svc:/system/test_enable_svc:default foo")
"svcadm mark degraded svc:/system/test_enable_svc:default foo")
"svcadm mark degraded svc:/system/test_enable_svc:default foo")
def test_zone_actuators(self):
"""Test that the smf interface for zones performs as
expected."""
"svcadm_arguments")
"zlogin_arguments")
"smf_cmds", "bin_zlogin")
zone = "z1"
"zlogin "+zone)
"svcadm restart svc:/system/test_restart_svc:default")
"zlogin "+zone)
"svcadm refresh svc:/system/test_refresh_svc:default")
"zlogin "+zone)
"svcadm mark maintenance svc:/system/test_mark_svc:default")
"zlogin "+zone)
"svcadm enable svc:/system/test_enable_svc:default")
"zlogin "+zone)
"svcadm disable -s svc:/system/test_disable_svc:default")
"zlogin "+zone)
"zlogin "+zone)
"zlogin "+zone)