|
1 #!/usr/bin/python2.4 |
|
2 # |
|
3 # CDDL HEADER START |
|
4 # |
|
5 # The contents of this file are subject to the terms of the |
|
6 # Common Development and Distribution License (the "License"). |
|
7 # You may not use this file except in compliance with the License. |
|
8 # |
|
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
10 # or http://www.opensolaris.org/os/licensing. |
|
11 # See the License for the specific language governing permissions |
|
12 # and limitations under the License. |
|
13 # |
|
14 # When distributing Covered Code, include this CDDL HEADER in each |
|
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
16 # If applicable, add the following below this CDDL HEADER, with the |
|
17 # fields enclosed by brackets "[]" replaced with your own identifying |
|
18 # information: Portions Copyright [yyyy] [name of copyright owner] |
|
19 # |
|
20 # CDDL HEADER END |
|
21 # |
|
22 |
|
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
|
24 # Use is subject to license terms. |
|
25 |
|
26 import testutils |
|
27 if __name__ == "__main__": |
|
28 testutils.setup_environment("../../../proto") |
|
29 |
|
30 import os |
|
31 import unittest |
|
32 import shutil |
|
33 |
|
34 class TestPkgActuators(testutils.SingleDepotTestCase): |
|
35 # Only start/stop the depot once (instead of for every test) |
|
36 persistent_depot = True |
|
37 |
|
38 svcprop_enabled_data = \ |
|
39 """general/enabled boolean true |
|
40 general/entity_stability astring Unstable |
|
41 general/single_instance boolean true |
|
42 restarter/start_pid count 4172 |
|
43 restarter/start_method_timestamp time 1222382991.639687000 |
|
44 restarter/start_method_waitstatus integer 0 |
|
45 restarter/transient_contract count |
|
46 restarter/auxiliary_state astring none |
|
47 restarter/next_state astring none |
|
48 restarter/state astring online |
|
49 restarter/state_timestamp time 1222382991.644413000 |
|
50 restarter_actions/refresh integer |
|
51 restarter_actions/maint_on integer |
|
52 restarter_actions/maint_off integer |
|
53 restarter_actions/restart integer |
|
54 local-filesystems/entities fmri svc:/system/filesystem/local |
|
55 local-filesystems/grouping astring require_all |
|
56 local-filesystems/restart_on astring none |
|
57 local-filesystems/type astring service |
|
58 remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs |
|
59 remote-filesystems/grouping astring optional_all |
|
60 remote-filesystems/restart_on astring none |
|
61 remote-filesystems/type astring service |
|
62 startd/duration astring transient |
|
63 start/timeout_seconds count 0 |
|
64 start/type astring method |
|
65 stop/exec astring :true |
|
66 stop/timeout_seconds count 0 |
|
67 stop/type astring method |
|
68 """ |
|
69 svcprop_disabled_data = \ |
|
70 """general/enabled boolean false |
|
71 general/entity_stability astring Unstable |
|
72 general/single_instance boolean true |
|
73 restarter/start_pid count 4172 |
|
74 restarter/start_method_timestamp time 1222382991.639687000 |
|
75 restarter/start_method_waitstatus integer 0 |
|
76 restarter/transient_contract count |
|
77 restarter/auxiliary_state astring none |
|
78 restarter/next_state astring none |
|
79 restarter/state astring disabled |
|
80 restarter/state_timestamp time 1222992132.445811000 |
|
81 restarter_actions/refresh integer |
|
82 restarter_actions/maint_on integer |
|
83 restarter_actions/maint_off integer |
|
84 restarter_actions/restart integer |
|
85 local-filesystems/entities fmri svc:/system/filesystem/local |
|
86 local-filesystems/grouping astring require_all |
|
87 local-filesystems/restart_on astring none |
|
88 local-filesystems/type astring service |
|
89 remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs |
|
90 remote-filesystems/grouping astring optional_all |
|
91 remote-filesystems/restart_on astring none |
|
92 remote-filesystems/type astring service |
|
93 startd/duration astring transient |
|
94 start/timeout_seconds count 0 |
|
95 start/type astring method |
|
96 stop/exec astring :true |
|
97 stop/timeout_seconds count 0 |
|
98 stop/type astring method |
|
99 """ |
|
100 svcprop_temp_enabled_data = \ |
|
101 """general/enabled boolean false |
|
102 general/entity_stability astring Unstable |
|
103 general/single_instance boolean true |
|
104 restarter/start_pid count 7816 |
|
105 restarter/start_method_timestamp time 1222992237.506096000 |
|
106 restarter/start_method_waitstatus integer 0 |
|
107 restarter/transient_contract count |
|
108 restarter/auxiliary_state astring none |
|
109 restarter/next_state astring none |
|
110 restarter/state astring online |
|
111 restarter/state_timestamp time 1222992237.527408000 |
|
112 restarter_actions/refresh integer |
|
113 restarter_actions/maint_on integer |
|
114 restarter_actions/maint_off integer |
|
115 restarter_actions/restart integer |
|
116 general_ovr/enabled boolean true |
|
117 local-filesystems/entities fmri svc:/system/filesystem/local |
|
118 local-filesystems/grouping astring require_all |
|
119 local-filesystems/restart_on astring none |
|
120 local-filesystems/type astring service |
|
121 remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs |
|
122 remote-filesystems/grouping astring optional_all |
|
123 remote-filesystems/restart_on astring none |
|
124 remote-filesystems/type astring service |
|
125 startd/duration astring transient |
|
126 start/timeout_seconds count 0 |
|
127 start/type astring method |
|
128 stop/exec astring :true |
|
129 stop/timeout_seconds count 0 |
|
130 stop/type astring method |
|
131 """ |
|
132 svcprop_temp_disabled_data = \ |
|
133 """general/enabled boolean true |
|
134 general/entity_stability astring Unstable |
|
135 general/single_instance boolean true |
|
136 restarter/start_pid count 7816 |
|
137 restarter/start_method_timestamp time 1222992237.506096000 |
|
138 restarter/start_method_waitstatus integer 0 |
|
139 restarter/transient_contract count |
|
140 restarter/auxiliary_state astring none |
|
141 restarter/next_state astring none |
|
142 restarter/state astring disabled |
|
143 restarter/state_timestamp time 1222992278.822335000 |
|
144 restarter_actions/refresh integer |
|
145 restarter_actions/maint_on integer |
|
146 restarter_actions/maint_off integer |
|
147 restarter_actions/restart integer |
|
148 general_ovr/enabled boolean false |
|
149 local-filesystems/entities fmri svc:/system/filesystem/local |
|
150 local-filesystems/grouping astring require_all |
|
151 local-filesystems/restart_on astring none |
|
152 local-filesystems/type astring service |
|
153 remote-filesystems/entities fmri svc:/network/nfs/client svc:/system/filesystem/autofs |
|
154 remote-filesystems/grouping astring optional_all |
|
155 remote-filesystems/restart_on astring none |
|
156 remote-filesystems/type astring service |
|
157 startd/duration astring transient |
|
158 start/timeout_seconds count 0 |
|
159 start/type astring method |
|
160 stop/exec astring :true |
|
161 stop/timeout_seconds count 0 |
|
162 stop/type astring method |
|
163 """ |
|
164 empty_data = "" |
|
165 |
|
166 svcprop_data = \ |
|
167 """#!/usr/bin/sh |
|
168 cat $PKG_TEST_DIR/$PKG_SVCPROP_OUTPUT |
|
169 exit $PKG_SVCPROP_EXIT_CODE |
|
170 """ |
|
171 svcadm_data = \ |
|
172 """#!/usr/bin/sh |
|
173 echo $0 "$@" >> $PKG_TEST_DIR/svcadm_arguments |
|
174 exit $(PKG_SVCADM_EXIT_CODE) |
|
175 """ |
|
176 |
|
177 |
|
178 misc_files = [ "svcprop_enabled", "svcprop_disabled", "svcprop_temp_enabled", "empty", |
|
179 "svcprop_temp_enabled", "usr/bin/svcprop", "usr/sbin/svcadm"] |
|
180 |
|
181 testdata_dir = None |
|
182 |
|
183 def setUp(self): |
|
184 |
|
185 testutils.SingleDepotTestCase.setUp(self) |
|
186 tp = self.get_test_prefix() |
|
187 self.testdata_dir = os.path.join(tp, "testdata") |
|
188 os.mkdir(self.testdata_dir) |
|
189 self.pkg_list = [] |
|
190 |
|
191 self.pkg_list+= [""" |
|
192 open [email protected],5.11-0 |
|
193 add file """ + self.testdata_dir + """/empty mode=0644 owner=root group=sys path=/test_restart restart_fmri=svc:system/test_restart_svc |
|
194 close """] |
|
195 |
|
196 self.pkg_list+= [""" |
|
197 open [email protected],5.11-0 |
|
198 add file """ + self.testdata_dir + """/empty mode=0655 owner=root group=sys path=/test_restart restart_fmri=svc:system/test_restart_svc |
|
199 close """] |
|
200 |
|
201 self.pkg_list+= [""" |
|
202 open [email protected],5.11-0 |
|
203 add file """ + self.testdata_dir + """/empty mode=0646 owner=root group=sys path=/test_restart restart_fmri=svc:system/test_restart_svc |
|
204 close """] |
|
205 |
|
206 self.pkg_list+= [""" |
|
207 open [email protected],5.11-0 |
|
208 add file """ + self.testdata_dir + """/empty mode=0657 owner=root group=sys path=/test_restart refresh_fmri=svc:system/test_refresh_svc |
|
209 close """] |
|
210 |
|
211 self.pkg_list+= [""" |
|
212 open [email protected],5.11-0 |
|
213 add file """ + self.testdata_dir + """/empty mode=0667 owner=root group=sys path=/test_restart suspend_fmri=svc:system/test_suspend_svc |
|
214 close """] |
|
215 |
|
216 self.pkg_list+= [""" |
|
217 open [email protected],5.11-0 |
|
218 add file """ + self.testdata_dir + """/empty mode=0677 owner=root group=sys path=/test_restart suspend_fmri=svc:system/test_suspend_svc disable_fmri=svc:system/test_disable_svc |
|
219 close """] |
|
220 |
|
221 for f in self.misc_files: |
|
222 filename = os.path.join(self.testdata_dir, f) |
|
223 if not os.path.exists(os.path.dirname(filename)): |
|
224 os.makedirs(os.path.dirname(filename)) |
|
225 file_handle = open(filename, 'wb') |
|
226 data = "self.%s_data" % os.path.basename(f) |
|
227 file_handle.write(eval(data)) |
|
228 file_handle.close() |
|
229 os.chmod(filename, 0755) |
|
230 |
|
231 def tearDown(self): |
|
232 testutils.SingleDepotTestCase.tearDown(self) |
|
233 if self.testdata_dir: |
|
234 shutil.rmtree(self.testdata_dir) |
|
235 |
|
236 def test_actuators(self): |
|
237 """test actuators""" |
|
238 |
|
239 durl = self.dc.get_depot_url() |
|
240 for pkg in self.pkg_list: |
|
241 self.pkgsend_bulk(durl, pkg) |
|
242 self.image_create(durl) |
|
243 os.environ["PKG_TEST_DIR"] = self.testdata_dir |
|
244 os.environ["PKG_SVCADM_EXIT_CODE"] = "0" |
|
245 os.environ["PKG_SVCPROP_EXIT_CODE"] = "0" |
|
246 |
|
247 svcadm_output = os.path.join(self.testdata_dir, |
|
248 "svcadm_arguments") |
|
249 |
|
250 # make it look like our test service is enabled |
|
251 os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_enabled" |
|
252 |
|
253 # test to see if our test service is restarted on install |
|
254 cmdstr = "--debug actuator_cmds_dir=%s" % self.testdata_dir |
|
255 self.pkg(cmdstr + " install [email protected]") |
|
256 self.pkg("verify") |
|
257 |
|
258 self.file_contains(svcadm_output, "svcadm restart svc:system/test_restart_svc") |
|
259 os.unlink(svcadm_output) |
|
260 |
|
261 # test to see if our test service is restarted on upgrade |
|
262 cmdstr = "--debug actuator_cmds_dir=%s" % self.testdata_dir |
|
263 self.pkg(cmdstr + " install [email protected]") |
|
264 self.pkg("verify") |
|
265 self.file_contains(svcadm_output, "svcadm restart svc:system/test_restart_svc") |
|
266 os.unlink(svcadm_output) |
|
267 |
|
268 # test to see if our test service is restarted on uninstall |
|
269 self.pkg(cmdstr + " uninstall basics") |
|
270 self.pkg("verify") |
|
271 self.file_contains(svcadm_output, "svcadm restart svc:system/test_restart_svc") |
|
272 os.unlink(svcadm_output) |
|
273 |
|
274 # make it look like our test service is not enabled |
|
275 os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_disabled" |
|
276 |
|
277 # test to see to make sure we don't restart disabled service |
|
278 cmdstr = "--debug actuator_cmds_dir=%s" % self.testdata_dir |
|
279 self.pkg(cmdstr + " install [email protected]") |
|
280 self.pkg("verify") |
|
281 self.file_does_not_exist(svcadm_output) |
|
282 |
|
283 # make it look like our test service(s) is/are enabled |
|
284 os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_enabled" |
|
285 |
|
286 # test to see if refresh works as designed, along w/ restart |
|
287 cmdstr = "--debug actuator_cmds_dir=%s" % self.testdata_dir |
|
288 self.pkg(cmdstr + " install [email protected]") |
|
289 self.pkg("verify") |
|
290 self.file_contains(svcadm_output, "svcadm restart svc:system/test_restart_svc") |
|
291 self.file_contains(svcadm_output, "svcadm refresh svc:system/test_refresh_svc") |
|
292 os.unlink(svcadm_output) |
|
293 |
|
294 # test if suspend works |
|
295 cmdstr = "--debug actuator_cmds_dir=%s" % self.testdata_dir |
|
296 self.pkg(cmdstr + " install [email protected]") |
|
297 self.pkg("verify") |
|
298 self.file_contains(svcadm_output, "svcadm disable -t svc:system/test_suspend_svc") |
|
299 self.file_contains(svcadm_output, "svcadm enable svc:system/test_suspend_svc") |
|
300 os.unlink(svcadm_output) |
|
301 |
|
302 # test if suspend works properly w/ temp. enabled service |
|
303 # make it look like our test service(s) is/are temp enabled |
|
304 os.environ["PKG_SVCPROP_OUTPUT"] = "svcprop_temp_enabled" |
|
305 cmdstr = "--debug actuator_cmds_dir=%s" % self.testdata_dir |
|
306 self.pkg(cmdstr + " install [email protected]") |
|
307 self.pkg("verify") |
|
308 self.file_contains(svcadm_output, "svcadm disable -t svc:system/test_suspend_svc") |
|
309 self.file_contains(svcadm_output, "svcadm enable -t svc:system/test_suspend_svc") |
|
310 os.unlink(svcadm_output) |
|
311 |
|
312 # test if service is disabled on uninstall |
|
313 cmdstr = "--debug actuator_cmds_dir=%s" % self.testdata_dir |
|
314 self.pkg(cmdstr + " uninstall basics") |
|
315 self.pkg("verify") |
|
316 self.file_contains(svcadm_output, "svcadm disable svc:system/test_disable_svc") |
|
317 |
|
318 def file_does_not_exist(self, path): |
|
319 file_path = os.path.join(self.get_img_path(), path) |
|
320 if os.path.exists(file_path): |
|
321 self.assert_(False, "File %s exists" % path) |
|
322 |
|
323 def file_contains(self, path, string): |
|
324 file_path = os.path.join(self.get_img_path(), path) |
|
325 try: |
|
326 f = file(file_path) |
|
327 except: |
|
328 self.assert_(False, "File %s does not exist or contain %s" % (path, string)) |
|
329 |
|
330 for line in f: |
|
331 if string in line: |
|
332 f.close() |
|
333 break |
|
334 else: |
|
335 f.close() |
|
336 self.assert_(False, "File %s does not contain %s" % (path, string)) |
|
337 |
|
338 if __name__ == "__main__": |
|
339 unittest.main() |