author | Edward Pilatowicz <edward.pilatowicz@oracle.com> |
Sat, 07 May 2011 00:25:10 -0700 | |
changeset 2339 | aa5954c06b9d |
parent 2158 | 5a688b5b92a3 |
child 2488 | 010931d9cabe |
permissions | -rw-r--r-- |
1516
8c950a3b4171
10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents:
1505
diff
changeset
|
1 |
#!/usr/bin/python |
581 | 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 |
||
2339
aa5954c06b9d
16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents:
2158
diff
changeset
|
23 |
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. |
581 | 24 |
|
25 |
import testutils |
|
26 |
if __name__ == "__main__": |
|
27 |
testutils.setup_environment("../../../proto") |
|
1715
8f305f0a6864
8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents:
1516
diff
changeset
|
28 |
import pkg5unittest |
581 | 29 |
|
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
30 |
import os |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
31 |
import pkg.portable as portable |
581 | 32 |
import unittest |
33 |
||
1895
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1715
diff
changeset
|
34 |
|
1715
8f305f0a6864
8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents:
1516
diff
changeset
|
35 |
class TestROption(pkg5unittest.SingleDepotTestCase): |
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
36 |
# Cleanup after every test. |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
37 |
persistent_setup = False |
581 | 38 |
|
39 |
foo10 = """ |
|
40 |
open [email protected],5.11-0 |
|
41 |
close """ |
|
42 |
||
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
43 |
def setUp(self): |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
44 |
pkg5unittest.SingleDepotTestCase.setUp(self) |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
45 |
self.pkgsend_bulk(self.rurl, self.foo10) |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
46 |
self.image_create(self.rurl) |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
884
diff
changeset
|
47 |
|
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
48 |
def test_bad_cli_options(self): |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
49 |
"""Verify that pkg rejects invalid -R combos and values.""" |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
50 |
|
581 | 51 |
self.pkg("-@", exit=2) |
52 |
self.pkg("-s status", exit=2) |
|
53 |
self.pkg("-R status", exit=2) |
|
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
54 |
self.pkg("-R / version", exit=2) |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
884
diff
changeset
|
55 |
|
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
56 |
def test_1_explicit(self): |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
57 |
"""Ensure that pkg explicit image specification works as |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
58 |
expected.""" |
581 | 59 |
|
2339
aa5954c06b9d
16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents:
2158
diff
changeset
|
60 |
imgpath = self.img_path() |
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
61 |
badpath = self.test_root |
581 | 62 |
|
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
63 |
# Verify that bad paths cause exit and good paths succeed. |
581 | 64 |
self.pkg("-R %s list" % badpath, exit=1) |
65 |
self.pkg("-R %s list" % imgpath, exit=1) |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
884
diff
changeset
|
66 |
|
581 | 67 |
self.pkg("-R %s install foo" % badpath, exit=1) |
68 |
self.pkg("-R %s install foo" % imgpath) |
|
69 |
||
70 |
self.pkg("-R %s list" % badpath, exit=1) |
|
71 |
self.pkg("-R %s list" % imgpath) |
|
72 |
||
1895
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1715
diff
changeset
|
73 |
self.pkgsend_bulk(self.rurl, self.foo10) |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
884
diff
changeset
|
74 |
self.pkg("-R %s refresh" % imgpath) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
884
diff
changeset
|
75 |
|
2089
c8b9d6341530
2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents:
1895
diff
changeset
|
76 |
self.pkg("-R %s update" % badpath, exit=1) |
c8b9d6341530
2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents:
1895
diff
changeset
|
77 |
self.pkg("-R %s update --be-name NEWBENAME" % imgpath, exit=1) |
c8b9d6341530
2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents:
1895
diff
changeset
|
78 |
self.pkg("-R %s update" % imgpath) |
581 | 79 |
|
80 |
self.pkg("-R %s uninstall foo" % badpath, exit=1) |
|
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
996
diff
changeset
|
81 |
self.pkg("-R %s install foo" % imgpath, exit=4) |
581 | 82 |
|
83 |
self.pkg("-R %s info foo" % badpath, exit=1) |
|
84 |
self.pkg("-R %s info foo" % imgpath) |
|
85 |
||
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
86 |
def test_2_implicit(self): |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
87 |
"""Ensure that pkg implicit image finding works as expected.""" |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
88 |
|
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
89 |
# Should fail because $PKG_IMAGE is set to test root by default, |
2339
aa5954c06b9d
16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents:
2158
diff
changeset
|
90 |
# and default test behaviour to use -R self.img_path() was |
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
91 |
# disabled. |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
92 |
self.pkg("install foo", exit=1, use_img_root=False) |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
93 |
|
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
94 |
# Unset unit testing default bogus image dir. |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
95 |
del os.environ["PKG_IMAGE"] |
2339
aa5954c06b9d
16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents:
2158
diff
changeset
|
96 |
os.chdir(self.img_path()) |
aa5954c06b9d
16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents:
2158
diff
changeset
|
97 |
self.assertEqual(os.getcwd(), self.img_path()) |
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
98 |
|
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
99 |
if portable.osname != "sunos": |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
100 |
# For other platforms, first install a package uses an |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
101 |
# explicit root, and then verify that an implicit find |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
102 |
# of the image results in the right image being found. |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
103 |
self.pkg("install foo") |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
104 |
self.pkg("info foo", use_img_root=False) |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
105 |
|
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
106 |
# Remaining tests are not valid on other platforms. |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
107 |
return |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
108 |
|
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
109 |
# Should fail because image found is not at '/', but at cwd(). |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
110 |
self.pkg("install foo", exit=1, use_img_root=False) |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
111 |
|
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
112 |
# Should succeed because image is found at simulated live root. |
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
113 |
self.pkg("-D simulate_live_root=%s install foo" % |
2339
aa5954c06b9d
16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents:
2158
diff
changeset
|
114 |
self.img_path(), use_img_root=False) |
2158
5a688b5b92a3
15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents:
2089
diff
changeset
|
115 |
|
1895
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1715
diff
changeset
|
116 |
|
581 | 117 |
if __name__ == "__main__": |
118 |
unittest.main() |