Merge lp:~rackspace-titan/glance/glance-clear-lp766295 into lp:~hudson-openstack/glance/trunk

Proposed by Brian Waldon
Status: Merged
Approved by: Jay Pipes
Approved revision: 120
Merged at revision: 122
Proposed branch: lp:~rackspace-titan/glance/glance-clear-lp766295
Merge into: lp:~hudson-openstack/glance/trunk
Diff against target: 83 lines (+25/-3)
2 files modified
bin/glance (+23/-1)
tests/functional/test_bin_glance.py (+2/-2)
To merge this branch: bzr merge lp:~rackspace-titan/glance/glance-clear-lp766295
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Dan Prince (community) Approve
Review via email: mp+58377@code.launchpad.net

Description of the change

- Require user confirmation for "bin/glance clear" and "bin/glance delete <id>"
- Allow for override with -f/--force command-line option

To post a comment you must log in.
Revision history for this message
Brian Waldon (bcwaldon) wrote :

I didn't add any testing, just because I wasn't quite sure how to do it correctly. If anybody has any ideas I am all ears.

Revision history for this message
Jay Pipes (jaypipes) wrote :

nice work, Brian :)

review: Approve
Revision history for this message
Dan Prince (dan-prince) wrote :

Looks great.

We don't appear to have a glance bin test on clear all. Probably some overlap with existing tests but we could create a test named 'test_add_list_clear_list' test case or something? I approve w/ or without this test case however.

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

> Looks great.
>
> We don't appear to have a glance bin test on clear all. Probably some overlap
> with existing tests but we could create a test named
> 'test_add_list_clear_list' test case or something? I approve w/ or without
> this test case however.

Sure, but keep in mind clear only deletes *public* images, since it uses a call to index() and then delete()s each one in the index (which is only public images)

-jay

Revision history for this message
Dan Prince (dan-prince) wrote :

Sure. Also I'm adding this missing test in my branch to fix the image_properties clearing issue. ;) Wouldn't want to have a conflict.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (10.9 KiB)

The attempt to merge lp:~rackspace-titan/glance/glance-clear-lp766295 into lp:glance failed. Below is the output from the failed tests.

running test
running egg_info
creating glance.egg-info
writing glance.egg-info/PKG-INFO
writing top-level names to glance.egg-info/top_level.txt
writing dependency_links to glance.egg-info/dependency_links.txt
writing manifest file 'glance.egg-info/SOURCES.txt'
reading manifest file 'glance.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'ChangeLog'
writing manifest file 'glance.egg-info/SOURCES.txt'
running build_ext

We test the following: ... ERROR
We test the following: ... ok
Test for LP Bugs #736295, #767203 ... ok
We test the following sequential series of actions: ... ok
A test against the actual datastore backend for the registry ... ok
A test that errors coming from the POST API do not ... ok
Test logging output proper when verbose and debug ... ok
Test logging output proper when verbose and debug ... ok
A test for LP bug #704854 -- Exception thrown by registry ... ok
Tests raises BadRequest for invalid store header ... ok
Tests to add a basic image in the file store ... ok
Tests creates a queued image for no body and no loc header ... ok
Test that the image contents are checksummed properly ... ok
test_bad_container_format (tests.unit.test_api.TestGlanceAPI) ... ok
test_bad_disk_format (tests.unit.test_api.TestGlanceAPI) ... ok
test_delete_image (tests.unit.test_api.TestGlanceAPI) ... ok
test_delete_non_exists_image (tests.unit.test_api.TestGlanceAPI) ... ok
Here, we try to delete an image that is in the queued state. ... ok
Test that the ETag header matches the x-image-meta-checksum ... ok
Test that the image contents are checksummed properly ... ok
Test for HEAD /images/<ID> ... ok
test_show_image_basic (tests.unit.test_api.TestGlanceAPI) ... ok
test_show_non_exists_image (tests.unit.test_api.TestGlanceAPI) ... ok
Tests that the /images POST registry API creates the image ... ok
Tests proper exception is raised if a bad disk_format is set ... ok
Tests proper exception is raised if a bad disk_format is set ... ok
Tests proper exception is raised if a bad status is set ... ok
Tests that exception raised for bad matching disk and container ... ok
Tests that the /images DELETE registry API deletes the image ... ok
Tests proper exception is raised if attempt to delete non-existing ... ok
Tests that the /images/detail registry API returns ... ok
Tests that the /images registry API returns list of ... ok
Tests that the root registry API returns "index", ... ok
Tests that the /images PUT registry API updates the image ... ok
Tests proper exception is raised if attempt to update non-existing ... ok
Tests that exception raised trying to set a bad container_format ... ok
Tests that exception raised trying to set a bad disk_format ... ok
Tests that exception raised trying to set a bad status ... ok
Tests that exception raised for bad matching disk and container ... ok
Test ClientConnectionError raised ... ok
Tests proper exception is raised if image with ID already exists ... ok
Tests that we can add image metadata and returns the new id ... ok
Tests a bad stat...

120. By Brian Waldon

adding --force option to test_add_clear

Revision history for this message
Brian Waldon (bcwaldon) wrote :

Should have merged trunk after Dan's branch went in today. Sorry, guys! We're good to go now.

Revision history for this message
Jay Pipes (jaypipes) wrote :

Cool, looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/glance'
2--- bin/glance 2011-04-20 19:12:18 +0000
3+++ bin/glance 2011-04-21 00:03:23 +0000
4@@ -309,7 +309,6 @@
5 %(prog)s delete [options] <ID>
6
7 Deletes an image from Glance"""
8- c = get_client(options)
9 try:
10 image_id = args.pop()
11 except IndexError:
12@@ -317,6 +316,13 @@
13 print "as the first argument"
14 return FAILURE
15
16+ if not options.force and \
17+ not user_confirm("Delete image %s?" % (image_id,)):
18+ print 'Not deleting image %s' % (image_id,)
19+ return FAILURE
20+
21+ c = get_client(options)
22+
23 try:
24 c.delete_image(image_id)
25 print "Deleted image %s" % image_id
26@@ -428,6 +434,10 @@
27 %(prog)s clear [options]
28
29 Deletes all images from a Glance server"""
30+ if not options.force and not user_confirm("Delete all images?"):
31+ print 'Not deleting any images'
32+ return FAILURE
33+
34 c = get_client(options)
35 images = c.get_images()
36 for image in images:
37@@ -470,6 +480,10 @@
38 type=int, default=9292,
39 help="Port the Glance API host listens on. "
40 "Default: %default")
41+ parser.add_option('-f', '--force', dest="force", metavar="FORCE",
42+ default=False, action="store_true",
43+ help="Prevent select actions from requesting "
44+ "user confirmation")
45 parser.add_option('--dry-run', default=False, action="store_true",
46 help="Don't actually execute the command, just print "
47 "output showing what WOULD happen.")
48@@ -532,6 +546,14 @@
49 print COMMANDS[command].__doc__ % {'prog': os.path.basename(sys.argv[0])}
50
51
52+def user_confirm(prompt):
53+ try:
54+ answer = raw_input("%s [Y/n] " % (prompt,))
55+ return answer.lower() in ("yes", "y")
56+ except Exception:
57+ return False
58+
59+
60 if __name__ == '__main__':
61 usage = """
62 %prog <command> [options] [args]
63
64=== modified file 'tests/functional/test_bin_glance.py'
65--- tests/functional/test_bin_glance.py 2011-04-20 19:12:18 +0000
66+++ tests/functional/test_bin_glance.py 2011-04-21 00:03:23 +0000
67@@ -72,7 +72,7 @@
68 self.assertTrue('MyImage' in image_data_line)
69
70 # 3. Delete the image
71- cmd = "bin/glance --port=%d delete 1" % api_port
72+ cmd = "bin/glance --port=%d --force delete 1" % api_port
73
74 exitcode, out, err = execute(cmd)
75
76@@ -195,7 +195,7 @@
77 self.assertEqual('Added new image with ID: %i' % i, out.strip())
78
79 # 2. Clear all images
80- cmd = "bin/glance --port=%d clear" % api_port
81+ cmd = "bin/glance --port=%d --force clear" % api_port
82 exitcode, out, err = execute(cmd)
83 self.assertEqual(0, exitcode)
84

Subscribers

People subscribed via source and target branches