47 # repository that is different than the actual test1 |
46 # repository that is different than the actual test1 |
48 # repository can be used. |
47 # repository can be used. |
49 pkg5unittest.ManyDepotTestCase.setUp(self, ["test1", "test2", |
48 pkg5unittest.ManyDepotTestCase.setUp(self, ["test1", "test2", |
50 "test1", "test1", "nopubconfig"]) |
49 "test1", "test1", "nopubconfig"]) |
51 |
50 |
52 self.durl1 = self.dcs[1].get_depot_url() |
51 self.rurl1 = self.dcs[1].get_repo_url() |
53 self.durl2 = self.dcs[2].get_depot_url() |
52 self.rurl2 = self.dcs[2].get_repo_url() |
54 self.durl3 = self.dcs[3].get_depot_url() |
53 self.rurl3 = self.dcs[3].get_repo_url() |
55 self.durl4 = self.dcs[4].get_depot_url() |
54 self.rurl4 = self.dcs[4].get_repo_url() |
56 self.durl5 = self.dcs[5].get_depot_url() |
55 self.durl5 = self.dcs[5].get_depot_url() |
57 |
56 |
58 # The fifth depot is purposefully one with the publisher |
57 # The fifth depot is purposefully one with the publisher |
59 # operation disabled. |
58 # operation disabled. |
60 self.dcs[5].stop() |
|
61 self.dcs[5].set_disable_ops(["publisher/0"]) |
59 self.dcs[5].set_disable_ops(["publisher/0"]) |
62 self.dcs[5].start() |
60 self.dcs[5].start() |
63 |
61 |
64 def test_basic(self): |
62 def test_basic(self): |
65 """ Create an image, verify it. """ |
63 """ Create an image, verify it. """ |
66 |
64 |
67 self.pkg_image_create(self.durl1, prefix="test1") |
65 self.pkg_image_create(self.rurl1, prefix="test1") |
68 self.pkg("verify") |
66 self.pkg("verify") |
69 |
67 |
70 def test_image_create_bad_opts(self): |
68 def test_image_create_bad_opts(self): |
71 """Test some bad cli options.""" |
69 """Test some bad cli options.""" |
72 |
70 |
117 # These tests are interdependent. |
115 # These tests are interdependent. |
118 # |
116 # |
119 # Bug 3588: Make sure we can't create an image where one |
117 # Bug 3588: Make sure we can't create an image where one |
120 # already exists |
118 # already exists |
121 self.pkg("image-create -p test1=%s %s/3588_image" % ( |
119 self.pkg("image-create -p test1=%s %s/3588_image" % ( |
122 self.durl1, self.get_img_path())) |
120 self.rurl1, self.get_img_path())) |
123 self.pkg("image-create -p test1=%s %s/3588_image" % ( |
121 self.pkg("image-create -p test1=%s %s/3588_image" % ( |
124 self.durl1, self.get_img_path()), exit=1) |
122 self.rurl1, self.get_img_path()), exit=1) |
125 |
123 |
126 # Make sure we can create an image where one |
124 # Make sure we can create an image where one |
127 # already exists with the -f (force) flag |
125 # already exists with the -f (force) flag |
128 self.pkg("image-create -p test1=%s %s/3588_image_1" % ( |
126 self.pkg("image-create -p test1=%s %s/3588_image_1" % ( |
129 self.durl1, self.get_img_path())) |
127 self.rurl1, self.get_img_path())) |
130 self.pkg("image-create -f -p test1=%s %s/3588_image_1" % |
128 self.pkg("image-create -f -p test1=%s %s/3588_image_1" % |
131 (self.durl1, self.get_img_path())) |
129 (self.rurl1, self.get_img_path())) |
132 |
130 |
133 # Bug 3588: Make sure we can't create an image where a |
131 # Bug 3588: Make sure we can't create an image where a |
134 # non-empty directory exists |
132 # non-empty directory exists |
135 p = os.path.join(self.get_img_path(), "3588_2_image") |
133 p = os.path.join(self.get_img_path(), "3588_2_image") |
136 os.mkdir(p) |
134 os.mkdir(p) |
137 self.cmdline_run("touch %s/%s" % (p, "somefile")) |
135 self.cmdline_run("touch %s/%s" % (p, "somefile")) |
138 self.pkg("image-create -p test1=%s %s" % (self.durl1, p), |
136 self.pkg("image-create -p test1=%s %s" % (self.rurl1, p), |
139 exit=1) |
137 exit=1) |
140 self.pkg("image-create -f -p test1=%s %s" % (self.durl1, p)) |
138 self.pkg("image-create -f -p test1=%s %s" % (self.rurl1, p)) |
141 |
139 |
142 def __verify_pub_cfg(self, img_path, prefix, pub_cfg): |
140 def __verify_pub_cfg(self, img_path, prefix, pub_cfg): |
143 """Private helper method to verify publisher configuration.""" |
141 """Private helper method to verify publisher configuration.""" |
144 |
142 |
145 img = image.Image(img_path, should_exist=True) |
143 img = image.Image(img_path, should_exist=True) |
180 information work as expected for image-create.""" |
178 information work as expected for image-create.""" |
181 |
179 |
182 img_path = os.path.join(self.test_root, "test_4_img") |
180 img_path = os.path.join(self.test_root, "test_4_img") |
183 for opt in ("-a", "-p", "--publisher"): |
181 for opt in ("-a", "-p", "--publisher"): |
184 self.pkg("image-create %s test1=%s %s" % (opt, |
182 self.pkg("image-create %s test1=%s %s" % (opt, |
185 self.durl1, img_path)) |
183 self.rurl1, img_path)) |
186 shutil.rmtree(img_path) |
184 shutil.rmtree(img_path) |
187 |
185 |
188 # Verify that specifying additional mirrors and origins works. |
186 # Verify that specifying additional mirrors and origins works. |
189 mirrors = " ".join( |
187 mirrors = " ".join( |
190 "-m %s" % u |
188 "-m %s" % u |
191 for u in (self.durl3, self.durl4) |
189 for u in (self.rurl3, self.rurl4) |
192 ) |
190 ) |
193 origins = " ".join( |
191 origins = " ".join( |
194 "-g %s" % u |
192 "-g %s" % u |
195 for u in (self.durl3, self.durl4) |
193 for u in (self.rurl3, self.rurl4) |
196 ) |
194 ) |
197 |
195 |
198 self.pkg("image-create -p test1=%s %s %s %s" % (self.durl1, |
196 self.pkg("image-create -p test1=%s %s %s %s" % (self.rurl1, |
199 mirrors, origins, img_path)) |
197 mirrors, origins, img_path)) |
200 |
198 |
201 self.pkg("-R %s publisher | grep origin.*%s" % (img_path, |
199 self.pkg("-R %s publisher | grep origin.*%s" % (img_path, |
202 self.durl1)) |
200 self.rurl1)) |
203 for u in (self.durl3, self.durl4): |
201 for u in (self.rurl3, self.rurl4): |
204 self.pkg("-R %s publisher | grep mirror.*%s" % ( |
202 self.pkg("-R %s publisher | grep mirror.*%s" % ( |
205 img_path, u)) |
203 img_path, u)) |
206 self.pkg("-R %s publisher | grep origin.*%s" % ( |
204 self.pkg("-R %s publisher | grep origin.*%s" % ( |
207 img_path, u)) |
205 img_path, u)) |
208 shutil.rmtree(img_path, True) |
206 shutil.rmtree(img_path, True) |
218 self.__verify_pub_cfg(img_path, "test5", pub_cfg) |
216 self.__verify_pub_cfg(img_path, "test5", pub_cfg) |
219 shutil.rmtree(img_path) |
217 shutil.rmtree(img_path) |
220 |
218 |
221 # Verify that -p auto-configuration works as expected for a |
219 # Verify that -p auto-configuration works as expected for a |
222 # a v1 repository when no prefix is provided. |
220 # a v1 repository when no prefix is provided. |
223 self.pkg("image-create -p %s %s" % (self.durl1, img_path)) |
221 self.pkg("image-create -p %s %s" % (self.rurl1, img_path)) |
224 pub_cfg = { |
222 pub_cfg = { |
225 "publisher": { "prefix": "test1" }, |
223 "publisher": { "prefix": "test1" }, |
226 "repository": { "origins": self.durl1 } |
224 "repository": { "origins": self.rurl1 } |
227 } |
225 } |
228 self.__verify_pub_cfg(img_path, "test1", pub_cfg) |
226 self.__verify_pub_cfg(img_path, "test1", pub_cfg) |
229 shutil.rmtree(img_path) |
227 shutil.rmtree(img_path) |
230 |
228 |
231 # Verify that -p auto-configuration works as expected for a |
229 # Verify that -p auto-configuration works as expected for a |
232 # a v1 repository when a prefix is provided. |
230 # a v1 repository when a prefix is provided. |
233 self.pkg("image-create -p test1=%s %s" % (self.durl1, img_path)) |
231 self.pkg("image-create -p test1=%s %s" % (self.rurl1, img_path)) |
234 pub_cfg = { |
232 pub_cfg = { |
235 "publisher": { "prefix": "test1" }, |
233 "publisher": { "prefix": "test1" }, |
236 "repository": { "origins": self.durl1 } |
234 "repository": { "origins": self.rurl1 } |
237 } |
235 } |
238 self.__verify_pub_cfg(img_path, "test1", pub_cfg) |
236 self.__verify_pub_cfg(img_path, "test1", pub_cfg) |
239 shutil.rmtree(img_path) |
237 shutil.rmtree(img_path) |
240 |
238 |
241 # Verify that -p auto-configuration works as expected for a |
239 # Verify that -p auto-configuration works as expected for a |
242 # a v1 repository with additional origins and mirrors. |
240 # a v1 repository with additional origins and mirrors. |
243 self.pkg("image-create -p test1=%s -g %s -m %s %s" % ( |
241 self.pkg("image-create -p test1=%s -g %s -m %s %s" % ( |
244 self.durl1, self.durl3, self.durl5, img_path)) |
242 self.rurl1, self.rurl3, self.durl5, img_path)) |
245 pub_cfg = { |
243 pub_cfg = { |
246 "publisher": { "prefix": "test1" }, |
244 "publisher": { "prefix": "test1" }, |
247 "repository": { |
245 "repository": { |
248 "origins": "%s,%s" % (self.durl1,self.durl3), |
246 "origins": "%s,%s" % (self.rurl1,self.rurl3), |
249 "mirrors": self.durl5, |
247 "mirrors": self.durl5, |
250 }, |
248 }, |
251 } |
249 } |
252 self.__verify_pub_cfg(img_path, "test1", pub_cfg) |
250 self.__verify_pub_cfg(img_path, "test1", pub_cfg) |
253 shutil.rmtree(img_path) |
251 shutil.rmtree(img_path) |
269 self.assertFalse(os.path.exists(p)) |
267 self.assertFalse(os.path.exists(p)) |
270 |
268 |
271 # Valid URI but without prefix and with --no-refresh; auto- |
269 # Valid URI but without prefix and with --no-refresh; auto- |
272 # configuration isn't possible in this scenario and so |
270 # configuration isn't possible in this scenario and so |
273 # an image should not be created. |
271 # an image should not be created. |
274 self.pkg("image-create --no-refresh -p %s %s" % (self.durl1, p), |
272 self.pkg("image-create --no-refresh -p %s %s" % (self.rurl1, p), |
275 exit=2) |
273 exit=2) |
276 self.assertFalse(os.path.exists(p)) |
274 self.assertFalse(os.path.exists(p)) |
277 |
275 |
278 # Valid URI but with the wrong publisher prefix should |
276 # Valid URI but with the wrong publisher prefix should |
279 # not create an image. |
277 # not create an image. |
280 self.pkg("image-create -p nosuchpub=%s %s" % (self.durl1, p), |
278 self.pkg("image-create -p nosuchpub=%s %s" % (self.rurl1, p), |
281 exit=1) |
279 exit=1) |
282 self.assertFalse(os.path.exists(p)) |
280 self.assertFalse(os.path.exists(p)) |
283 |
281 |
284 # Valid URI, without a publisher prefix, but for a repository |
282 # Valid URI, without a publisher prefix, but for a repository |
285 # that doesn't provide publisher configuration should not |
283 # that doesn't provide publisher configuration should not |
298 |
296 |
299 # Now verify that the image root isn't duplicated within the |
297 # Now verify that the image root isn't duplicated within the |
300 # specified image root if the specified root doesn't already |
298 # specified image root if the specified root doesn't already |
301 # exist. |
299 # exist. |
302 os.chdir(self.test_root) |
300 os.chdir(self.test_root) |
303 self.pkg("image-create -p test1=%s %s" % (self.durl1, |
301 self.pkg("image-create -p test1=%s %s" % (self.rurl1, |
304 img_path)) |
302 img_path)) |
305 os.chdir(pwd) |
303 os.chdir(pwd) |
306 self.assertFalse(os.path.exists(os.path.join(abs_img_path, |
304 self.assertFalse(os.path.exists(os.path.join(abs_img_path, |
307 img_path))) |
305 img_path))) |
308 shutil.rmtree(abs_img_path) |
306 shutil.rmtree(abs_img_path) |
309 |
307 |
310 # Now verify that the image root isn't duplicated within the |
308 # Now verify that the image root isn't duplicated within the |
311 # specified image root if the specified root already exists. |
309 # specified image root if the specified root already exists. |
312 os.chdir(self.test_root) |
310 os.chdir(self.test_root) |
313 os.mkdir(img_path) |
311 os.mkdir(img_path) |
314 self.pkg("image-create -p test1=%s %s" % (self.durl1, |
312 self.pkg("image-create -p test1=%s %s" % (self.rurl1, |
315 img_path)) |
313 img_path)) |
316 os.chdir(pwd) |
314 os.chdir(pwd) |
317 self.assertFalse(os.path.exists(os.path.join(abs_img_path, |
315 self.assertFalse(os.path.exists(os.path.join(abs_img_path, |
318 img_path))) |
316 img_path))) |
319 shutil.rmtree(abs_img_path) |
317 shutil.rmtree(abs_img_path) |
324 |
322 |
325 pkgsend_data = """ |
323 pkgsend_data = """ |
326 open [email protected] |
324 open [email protected] |
327 close |
325 close |
328 """ |
326 """ |
329 self.pkgsend_bulk(self.durl1, pkgsend_data) |
327 self.pkgsend_bulk(self.rurl1, pkgsend_data) |
330 |
328 |
331 # First, check to be certain that an image-create --no-refresh |
329 # First, check to be certain that an image-create --no-refresh |
332 # will succeed. |
330 # will succeed. |
333 self.pkg_image_create(self.durl2, prefix="test1", |
331 self.pkg_image_create(self.rurl2, prefix="test1", |
334 additional_args="--no-refresh") |
332 additional_args="--no-refresh") |
335 self.pkg("list --no-refresh -a | grep baz", exit=1) |
333 self.pkg("list --no-refresh -a | grep baz", exit=1) |
336 |
334 |
337 # Finally, verify that using set-publisher will cause a refresh |
335 # Finally, verify that using set-publisher will cause a refresh |
338 # which in turn should cause 'baz' to be listed *if* the origin |
336 # which in turn should cause 'baz' to be listed *if* the origin |
339 # has changed (setting it to the same value again won't work). |
337 # has changed (setting it to the same value again won't work). |
340 self.pkg("set-publisher -O %s test1" % self.durl1) |
338 self.pkg("set-publisher -O %s test1" % self.rurl1) |
341 self.pkg("list --no-refresh -a | grep baz") |
339 self.pkg("list --no-refresh -a | grep baz") |
342 |
340 |
343 def test_8_image_upgrade(self): |
341 def test_8_image_upgrade(self): |
344 """Verify that a version 0 image can be used by a client that |
342 """Verify that a version 0 image can be used by a client that |
345 normally creates version 1 images, and that it will be upgraded |
343 normally creates version 1 images, and that it will be upgraded |
346 correctly when a privileged user uses it.""" |
344 correctly when a privileged user uses it.""" |
347 |
345 |
348 # Publish some sample packages (to separate repositories). |
346 # Publish some sample packages (to separate repositories). |
349 self.pkgsend_bulk(self.durl1, "open [email protected]\nclose") |
347 self.pkgsend_bulk(self.rurl1, "open [email protected]\nclose") |
350 self.pkgsend_bulk(self.durl2, "open [email protected]\nclose") |
348 self.pkgsend_bulk(self.rurl2, "open [email protected]\nclose") |
351 |
349 |
352 # First, create a new image. |
350 # First, create a new image. |
353 self.pkg_image_create(self.durl1, prefix="test1") |
351 self.pkg_image_create(self.rurl1, prefix="test1") |
354 |
352 |
355 # Add the second repository. |
353 # Add the second repository. |
356 self.pkg("set-publisher -O %s test2" % self.durl2) |
354 self.pkg("set-publisher -O %s test2" % self.rurl2) |
357 |
355 |
358 # Next, install the packages. |
356 # Next, install the packages. |
359 self.pkg("install quux") |
357 self.pkg("install quux") |
360 self.pkg("set-publisher -P test2") |
358 self.pkg("set-publisher -P test2") |
361 |
359 |
426 def test_9_bad_image_state(self): |
424 def test_9_bad_image_state(self): |
427 """Verify that the pkg(1) command handles invalid image state |
425 """Verify that the pkg(1) command handles invalid image state |
428 gracefully.""" |
426 gracefully.""" |
429 |
427 |
430 # Publish a package. |
428 # Publish a package. |
431 self.pkgsend_bulk(self.durl1, """ |
429 self.pkgsend_bulk(self.rurl1, """ |
432 open [email protected] |
430 open [email protected] |
433 close |
431 close |
434 """) |
432 """) |
435 |
433 |
436 # First, create a new image. |
434 # First, create a new image. |
437 self.pkg_image_create(self.durl1, prefix="test1") |
435 self.pkg_image_create(self.rurl1, prefix="test1") |
438 |
436 |
439 # Verify pkg info works as expected. |
437 # Verify pkg info works as expected. |
440 self.pkg("info -r foo") |
438 self.pkg("info -r foo") |
441 |
439 |
442 # Now invalidate the existing image data. |
440 # Now invalidate the existing image data. |
477 |
475 |
478 p = os.path.join(self.test_root, "unpriv_test_10") |
476 p = os.path.join(self.test_root, "unpriv_test_10") |
479 os.mkdir(p) |
477 os.mkdir(p) |
480 |
478 |
481 self.pkg("image-create -p test1=%s %s/image" % ( |
479 self.pkg("image-create -p test1=%s %s/image" % ( |
482 self.durl1, p), su_wrap=True, exit=1) |
480 self.rurl1, p), su_wrap=True, exit=1) |
483 |
481 |
484 |
482 |
485 class TestImageCreateNoDepot(pkg5unittest.CliTestCase): |
483 class TestImageCreateNoDepot(pkg5unittest.CliTestCase): |
486 persistent_setup = True |
484 persistent_setup = True |
487 def test_bad_image_create(self): |
485 def test_bad_image_create(self): |