summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorimacdonn <iain.macdonnell@oracle.com>2018-08-17 00:55:08 +0000
committerimacdonn <iain.macdonnell@oracle.com>2018-08-21 21:48:35 +0000
commite2c54d58b33c7350c78629cc7726b5fa4509637b (patch)
tree7f9733c240c4f80afb03107b7247f0a75b783215
parentd8221bf16fc0f5adabe4d3751c19aeed90d84f30 (diff)
Update status to active when locations replaced
Image status should be changed from 'queued' to 'active' when 'locations' has been successfully replaced. Change-Id: I966688e67475e00a1eeb0cbe1632d5c811e41e4f Closes-Bug: 1750892
Notes
Notes (review): Code-Review+2: Brian Rosmaita <rosmaita.fossdev@gmail.com> Code-Review+1: Piotr Bielak <piotr.bielak@corp.ovh.com> Code-Review+2: Sean McGinnis <sean.mcginnis@gmail.com> Workflow+1: Sean McGinnis <sean.mcginnis@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Sat, 25 Aug 2018 11:14:48 +0000 Reviewed-on: https://review.openstack.org/592775 Project: openstack/glance Branch: refs/heads/master
-rw-r--r--glance/api/v2/images.py2
-rw-r--r--glance/tests/unit/v2/test_images_resource.py38
2 files changed, 32 insertions, 8 deletions
diff --git a/glance/api/v2/images.py b/glance/api/v2/images.py
index f551bb1..c005546 100644
--- a/glance/api/v2/images.py
+++ b/glance/api/v2/images.py
@@ -391,6 +391,8 @@ class ImagesController(object):
391 # NOTE(flwang): _locations_proxy's setattr method will check if 391 # NOTE(flwang): _locations_proxy's setattr method will check if
392 # the update is acceptable. 392 # the update is acceptable.
393 image.locations = value 393 image.locations = value
394 if image.status == 'queued':
395 image.status = 'active'
394 except (exception.BadStoreUri, exception.DuplicateLocation) as e: 396 except (exception.BadStoreUri, exception.DuplicateLocation) as e:
395 raise webob.exc.HTTPBadRequest(explanation=e.msg) 397 raise webob.exc.HTTPBadRequest(explanation=e.msg)
396 except ValueError as ve: # update image status failed. 398 except ValueError as ve: # update image status failed.
diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py
index 83e2caf..91c0db9 100644
--- a/glance/tests/unit/v2/test_images_resource.py
+++ b/glance/tests/unit/v2/test_images_resource.py
@@ -1720,14 +1720,24 @@ class TestImagesController(base.IsolatedUnitTest):
1720 self.assertEqual(2, len(output.locations)) 1720 self.assertEqual(2, len(output.locations))
1721 self.assertEqual(new_location, output.locations[1]) 1721 self.assertEqual(new_location, output.locations[1])
1722 1722
1723 def test_replace_location_possible_on_queued(self): 1723 @mock.patch.object(glance.quota, '_calc_required_size')
1724 self.skipTest('This test is intermittently failing at the gate. ' 1724 @mock.patch.object(glance.location, '_check_image_location')
1725 'See bug #1649300') 1725 @mock.patch.object(glance.location.ImageRepoProxy, '_set_acls')
1726 @mock.patch.object(store, 'get_size_from_uri_and_backend')
1727 @mock.patch.object(store, 'get_size_from_backend')
1728 def test_replace_location_on_queued(self,
1729 mock_get_size,
1730 mock_get_size_uri,
1731 mock_set_acls,
1732 mock_check_loc,
1733 mock_calc):
1734 mock_calc.return_value = 1
1735 mock_get_size.return_value = 1
1736 mock_get_size_uri.return_value = 1
1726 self.config(show_multiple_locations=True) 1737 self.config(show_multiple_locations=True)
1727 self.images = [ 1738 self.images = [
1728 _db_fixture('1', owner=TENANT1, checksum=CHKSUM, 1739 _db_fixture('1', owner=TENANT1, checksum=CHKSUM,
1729 name='1', 1740 name='1',
1730 is_public=True,
1731 disk_format='raw', 1741 disk_format='raw',
1732 container_format='bare', 1742 container_format='bare',
1733 status='queued'), 1743 status='queued'),
@@ -1741,15 +1751,26 @@ class TestImagesController(base.IsolatedUnitTest):
1741 self.assertEqual('1', output.image_id) 1751 self.assertEqual('1', output.image_id)
1742 self.assertEqual(1, len(output.locations)) 1752 self.assertEqual(1, len(output.locations))
1743 self.assertEqual(new_location, output.locations[0]) 1753 self.assertEqual(new_location, output.locations[0])
1754 self.assertEqual('active', output.status)
1744 1755
1745 def test_add_location_possible_on_queued(self): 1756 @mock.patch.object(glance.quota, '_calc_required_size')
1746 self.skipTest('This test is intermittently failing at the gate. ' 1757 @mock.patch.object(glance.location, '_check_image_location')
1747 'See bug #1649300') 1758 @mock.patch.object(glance.location.ImageRepoProxy, '_set_acls')
1759 @mock.patch.object(store, 'get_size_from_uri_and_backend')
1760 @mock.patch.object(store, 'get_size_from_backend')
1761 def test_add_location_on_queued(self,
1762 mock_get_size,
1763 mock_get_size_uri,
1764 mock_set_acls,
1765 mock_check_loc,
1766 mock_calc):
1767 mock_calc.return_value = 1
1768 mock_get_size.return_value = 1
1769 mock_get_size_uri.return_value = 1
1748 self.config(show_multiple_locations=True) 1770 self.config(show_multiple_locations=True)
1749 self.images = [ 1771 self.images = [
1750 _db_fixture('1', owner=TENANT1, checksum=CHKSUM, 1772 _db_fixture('1', owner=TENANT1, checksum=CHKSUM,
1751 name='1', 1773 name='1',
1752 is_public=True,
1753 disk_format='raw', 1774 disk_format='raw',
1754 container_format='bare', 1775 container_format='bare',
1755 status='queued'), 1776 status='queued'),
@@ -1763,6 +1784,7 @@ class TestImagesController(base.IsolatedUnitTest):
1763 self.assertEqual('1', output.image_id) 1784 self.assertEqual('1', output.image_id)
1764 self.assertEqual(1, len(output.locations)) 1785 self.assertEqual(1, len(output.locations))
1765 self.assertEqual(new_location, output.locations[0]) 1786 self.assertEqual(new_location, output.locations[0])
1787 self.assertEqual('active', output.status)
1766 1788
1767 def _test_update_locations_status(self, image_status, update): 1789 def _test_update_locations_status(self, image_status, update):
1768 self.config(show_multiple_locations=True) 1790 self.config(show_multiple_locations=True)