author | Danek Duvall <danek.duvall@oracle.com> |
Mon, 19 Oct 2015 13:13:17 -0700 | |
changeset 4990 | ce7a7efc042b |
permissions | -rw-r--r-- |
4990
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
1 |
From 5447e8419d92f0cbb14de53b207e772ce9067933 Mon Sep 17 00:00:00 2001 |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
2 |
From: Mike Fedosin <[email protected]> |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
3 |
Date: Sun, 20 Sep 2015 17:01:22 +0300 |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
4 |
Subject: [PATCH] Cleanup chunks for deleted image if token expired |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
5 |
|
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
6 |
In patch I47229b366c25367ec1bd48aec684e0880f3dfe60 it was |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
7 |
introduced the logic that if image was deleted during file |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
8 |
upload when we want to update image status from 'saving' |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
9 |
to 'active' it's expected to get Duplicate error and delete |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
10 |
stale chunks after that. But if user's token is expired |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
11 |
there will be Unathorized exception and chunks will stay |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
12 |
in store and clog it. |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
13 |
And when, the upload operation for such an image is |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
14 |
completed the operator configured quota can be exceeded. |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
15 |
|
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
16 |
This patch fixes the issue of left over chunks for an image |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
17 |
which was deleted from saving status, by correcly handle |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
18 |
auth exceptions from registry server. |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
19 |
|
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
20 |
This patch fixes the issue of left over chunks for an image |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
21 |
which was deleted from saving status, by correctly handle |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
22 |
auth exceptions from registry server. |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
23 |
|
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
24 |
Partial-bug: #1498163 |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
25 |
|
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
26 |
Conflicts: |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
27 |
glance/api/v1/upload_utils.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
28 |
(Kilo catches NotFound instead of ImagenotFound) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
29 |
|
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
30 |
Change-Id: I17a66eca55bfb83107046910e69c4da01415deec |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
31 |
(cherry picked from commit 50e3a7c58a9862206d92fef577540c5b144ecbf0) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
32 |
--- |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
33 |
glance/api/v1/upload_utils.py | 8 ++++++++ |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
34 |
glance/api/v2/image_data.py | 14 ++++++++++++- |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
35 |
glance/tests/unit/v1/test_upload_utils.py | 26 ++++++++++++++++++++++++ |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
36 |
glance/tests/unit/v2/test_image_data_resource.py | 17 ++++++++++++++++ |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
37 |
4 files changed, 64 insertions(+), 1 deletion(-) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
38 |
|
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
39 |
diff --git a/glance/api/v1/upload_utils.py b/glance/api/v1/upload_utils.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
40 |
index e587319..f9bdc29 100644 |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
41 |
--- a/glance/api/v1/upload_utils.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
42 |
+++ b/glance/api/v1/upload_utils.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
43 |
@@ -171,6 +171,14 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier): |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
44 |
raise exception.NotFound() |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
45 |
else: |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
46 |
raise |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
47 |
+ |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
48 |
+ except exception.NotAuthenticated as e: |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
49 |
+ # Delete image data due to possible token expiration. |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
50 |
+ LOG.debug("Authentication error - the token may have " |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
51 |
+ "expired during file upload. Deleting image data for " |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
52 |
+ " %s " % image_id) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
53 |
+ initiate_deletion(req, location_data, image_id) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
54 |
+ raise webob.exc.HTTPUnauthorized(explanation=e.msg, request=req) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
55 |
except exception.NotFound: |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
56 |
msg = _LI("Image %s could not be found after upload. The image may" |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
57 |
" have been deleted during the upload.") % image_id |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
58 |
diff --git a/glance/api/v2/image_data.py b/glance/api/v2/image_data.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
59 |
index cdfa34b..ee9d0ba 100644 |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
60 |
--- a/glance/api/v2/image_data.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
61 |
+++ b/glance/api/v2/image_data.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
62 |
@@ -90,7 +90,19 @@ class ImageDataController(object): |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
63 |
raise webob.exc.HTTPGone(explanation=msg, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
64 |
request=req, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
65 |
content_type='text/plain') |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
66 |
- |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
67 |
+ except exception.NotAuthenticated: |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
68 |
+ msg = (_("Authentication error - the token may have " |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
69 |
+ "expired during file upload. Deleting image data for " |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
70 |
+ "%s.") % image_id) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
71 |
+ LOG.debug(msg) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
72 |
+ try: |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
73 |
+ image.delete() |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
74 |
+ except exception.NotAuthenticated: |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
75 |
+ # NOTE: Ignore this exception |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
76 |
+ pass |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
77 |
+ raise webob.exc.HTTPUnauthorized(explanation=msg, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
78 |
+ request=req, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
79 |
+ content_type='text/plain') |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
80 |
except ValueError as e: |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
81 |
LOG.debug("Cannot save data for image %(id)s: %(e)s", |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
82 |
{'id': image_id, 'e': utils.exception_to_str(e)}) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
83 |
diff --git a/glance/tests/unit/v1/test_upload_utils.py b/glance/tests/unit/v1/test_upload_utils.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
84 |
index 083cda3..f561dbe 100644 |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
85 |
--- a/glance/tests/unit/v1/test_upload_utils.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
86 |
+++ b/glance/tests/unit/v1/test_upload_utils.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
87 |
@@ -323,3 +323,29 @@ class TestUploadUtils(base.StoreClearingUnitTest): |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
88 |
'metadata': {}}, image_meta['id']) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
89 |
mock_safe_kill.assert_called_once_with( |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
90 |
req, image_meta['id'], 'saving') |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
91 |
+ |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
92 |
+ @mock.patch.object(registry, 'update_image_metadata', |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
93 |
+ side_effect=exception.NotAuthenticated) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
94 |
+ @mock.patch.object(upload_utils, 'initiate_deletion') |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
95 |
+ def test_activate_image_with_expired_token( |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
96 |
+ self, mocked_delete, mocked_update): |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
97 |
+ """Test token expiration during image upload. |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
98 |
+ |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
99 |
+ If users token expired before image was uploaded then if auth error |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
100 |
+ was caught from registry during changing image status from 'saving' |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
101 |
+ to 'active' then it's required to delete all image data. |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
102 |
+ """ |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
103 |
+ context = mock.Mock() |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
104 |
+ req = mock.Mock() |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
105 |
+ req.context = context |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
106 |
+ with self._get_store_and_notifier() as (location, checksum, image_meta, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
107 |
+ image_data, store, notifier, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
108 |
+ update_data): |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
109 |
+ self.assertRaises(webob.exc.HTTPUnauthorized, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
110 |
+ upload_utils.upload_data_to_store, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
111 |
+ req, image_meta, image_data, store, notifier) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
112 |
+ self.assertEqual(2, mocked_update.call_count) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
113 |
+ mocked_delete.assert_called_once_with( |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
114 |
+ req, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
115 |
+ {'url': 'file://foo/bar', 'status': 'active', 'metadata': {}}, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
116 |
+ 'c80a1a6c-bd1f-41c5-90ee-81afedb1d58d') |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
117 |
diff --git a/glance/tests/unit/v2/test_image_data_resource.py b/glance/tests/unit/v2/test_image_data_resource.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
118 |
index a121e82..b7bacab 100644 |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
119 |
--- a/glance/tests/unit/v2/test_image_data_resource.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
120 |
+++ b/glance/tests/unit/v2/test_image_data_resource.py |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
121 |
@@ -183,6 +183,23 @@ class TestImagesController(base.StoreClearingUnitTest): |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
122 |
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.upload, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
123 |
request, unit_test_utils.UUID1, 'YYYY', 4) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
124 |
|
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
125 |
+ def test_upload_with_expired_token(self): |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
126 |
+ def side_effect(image, from_state=None): |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
127 |
+ if from_state == 'saving': |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
128 |
+ raise exception.NotAuthenticated() |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
129 |
+ |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
130 |
+ mocked_save = mock.Mock(side_effect=side_effect) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
131 |
+ mocked_delete = mock.Mock() |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
132 |
+ request = unit_test_utils.get_fake_request() |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
133 |
+ image = FakeImage('abcd') |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
134 |
+ image.delete = mocked_delete |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
135 |
+ self.image_repo.result = image |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
136 |
+ self.image_repo.save = mocked_save |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
137 |
+ self.assertRaises(webob.exc.HTTPUnauthorized, self.controller.upload, |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
138 |
+ request, unit_test_utils.UUID1, 'YYYY', 4) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
139 |
+ self.assertEqual(3, mocked_save.call_count) |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
140 |
+ mocked_delete.assert_called_once_with() |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
141 |
+ |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
142 |
def test_upload_non_existent_image_during_save_initiates_deletion(self): |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
143 |
def fake_save_not_found(self): |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
144 |
raise exception.NotFound() |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
145 |
-- |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
146 |
1.9.1 |
ce7a7efc042b
21936036 problem in SERVICE/GLANCE
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
147 |