diff options
| author | Jenkins <jenkins@review.openstack.org> | 2011-10-12 01:19:16 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2011-10-12 01:19:16 +0000 |
| commit | e95e923f2bee1fa3e5005bb99ec0d41e4931cec8 (patch) | |
| tree | 92632cc0ddc54e2f0de2a6bc8ed73ffcc2b4c4eb | |
| parent | 5ac67d89eb0f3484f78c61f471e72a42972fe4ff (diff) | |
| parent | b84d71c6bcca04a47407ea8491911b8584e395bb (diff) | |
| download | nova-e95e923f2bee1fa3e5005bb99ec0d41e4931cec8.tar.gz nova-e95e923f2bee1fa3e5005bb99ec0d41e4931cec8.tar.xz nova-e95e923f2bee1fa3e5005bb99ec0d41e4931cec8.zip | |
Merge "Updating image progress to be more granular. Before, the image progress had only 2 states, 0 and 100. Now it can be 0, 25, 50 or 100."
| -rw-r--r-- | nova/api/openstack/views/images.py | 22 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_images.py | 12 |
2 files changed, 21 insertions, 13 deletions
diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index 67364b115..8eaf0ca6a 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -37,6 +37,10 @@ class ViewBuilder(object): def _format_status(self, image): """Update the status field to standardize format.""" + + if 'status' not in image: + return + status_mapping = { 'active': 'ACTIVE', 'queued': 'SAVING', @@ -51,6 +55,14 @@ class ViewBuilder(object): except KeyError: image['status'] = 'UNKNOWN' + def _get_progress_for_status(self, status): + progress_map = { + 'queued': 25, + 'saving': 50, + 'active': 100, + } + return progress_map.get(status, 0) + def _build_server(self, image, image_obj): """Indicates that you must use a ViewBuilder subclass.""" raise NotImplementedError() @@ -72,8 +84,8 @@ class ViewBuilder(object): """Return a standardized image structure for display by the API.""" self._format_dates(image_obj) - if "status" in image_obj: - self._format_status(image_obj) + orig_status = image_obj.get('status', '').lower() + self._format_status(image_obj) image = { "id": image_obj.get("id"), @@ -89,11 +101,7 @@ class ViewBuilder(object): "updated": image_obj.get("updated_at"), "status": image_obj.get("status"), }) - - if image["status"].upper() == "ACTIVE": - image["progress"] = 100 - else: - image["progress"] = 0 + image["progress"] = self._get_progress_for_status(orig_status) return image diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 05d398478..5e32ccf42 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -133,7 +133,7 @@ class ImagesTest(test.TestCase): "updated": NOW_API_FORMAT, "created": NOW_API_FORMAT, "status": "SAVING", - "progress": 0, + "progress": 25, "minDisk": 0, "minRam": 0, 'server': { @@ -587,7 +587,7 @@ class ImagesTest(test.TestCase): 'updated': NOW_API_FORMAT, 'created': NOW_API_FORMAT, 'status': 'SAVING', - 'progress': 0, + 'progress': 25, }, { 'id': 125, @@ -595,7 +595,7 @@ class ImagesTest(test.TestCase): 'updated': NOW_API_FORMAT, 'created': NOW_API_FORMAT, 'status': 'SAVING', - 'progress': 0, + 'progress': 50, }, { 'id': 126, @@ -685,7 +685,7 @@ class ImagesTest(test.TestCase): 'updated': NOW_API_FORMAT, 'created': NOW_API_FORMAT, 'status': 'SAVING', - 'progress': 0, + 'progress': 25, 'minDisk': 0, 'minRam': 0, 'server': { @@ -723,7 +723,7 @@ class ImagesTest(test.TestCase): 'updated': NOW_API_FORMAT, 'created': NOW_API_FORMAT, 'status': 'SAVING', - 'progress': 0, + 'progress': 50, 'minDisk': 0, 'minRam': 0, 'server': { @@ -978,7 +978,7 @@ class ImagesTest(test.TestCase): 'created': NOW_API_FORMAT, 'status': 'SAVING', 'minDisk': 0, - 'progress': 0, + 'progress': 25, 'minRam': 0, 'server': { 'id': '42', |
