Browse Source

Merge "Update status to active when locations replaced"

Zuul 8 months ago
parent
commit
1312e25d9f
2 changed files with 32 additions and 8 deletions
  1. 2
    0
      glance/api/v2/images.py
  2. 30
    8
      glance/tests/unit/v2/test_images_resource.py

+ 2
- 0
glance/api/v2/images.py View File

@@ -391,6 +391,8 @@ class ImagesController(object):
391 391
             # NOTE(flwang): _locations_proxy's setattr method will check if
392 392
             # the update is acceptable.
393 393
             image.locations = value
394
+            if image.status == 'queued':
395
+                image.status = 'active'
394 396
         except (exception.BadStoreUri, exception.DuplicateLocation) as e:
395 397
             raise webob.exc.HTTPBadRequest(explanation=e.msg)
396 398
         except ValueError as ve:    # update image status failed.

+ 30
- 8
glance/tests/unit/v2/test_images_resource.py View File

@@ -1720,14 +1720,24 @@ class TestImagesController(base.IsolatedUnitTest):
1720 1720
         self.assertEqual(2, len(output.locations))
1721 1721
         self.assertEqual(new_location, output.locations[1])
1722 1722
 
1723
-    def test_replace_location_possible_on_queued(self):
1724
-        self.skipTest('This test is intermittently failing at the gate. '
1725
-                      'See bug #1649300')
1723
+    @mock.patch.object(glance.quota, '_calc_required_size')
1724
+    @mock.patch.object(glance.location, '_check_image_location')
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 1737
         self.config(show_multiple_locations=True)
1727 1738
         self.images = [
1728 1739
             _db_fixture('1', owner=TENANT1, checksum=CHKSUM,
1729 1740
                         name='1',
1730
-                        is_public=True,
1731 1741
                         disk_format='raw',
1732 1742
                         container_format='bare',
1733 1743
                         status='queued'),
@@ -1741,15 +1751,26 @@ class TestImagesController(base.IsolatedUnitTest):
1741 1751
         self.assertEqual('1', output.image_id)
1742 1752
         self.assertEqual(1, len(output.locations))
1743 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):
1746
-        self.skipTest('This test is intermittently failing at the gate. '
1747
-                      'See bug #1649300')
1756
+    @mock.patch.object(glance.quota, '_calc_required_size')
1757
+    @mock.patch.object(glance.location, '_check_image_location')
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 1770
         self.config(show_multiple_locations=True)
1749 1771
         self.images = [
1750 1772
             _db_fixture('1', owner=TENANT1, checksum=CHKSUM,
1751 1773
                         name='1',
1752
-                        is_public=True,
1753 1774
                         disk_format='raw',
1754 1775
                         container_format='bare',
1755 1776
                         status='queued'),
@@ -1763,6 +1784,7 @@ class TestImagesController(base.IsolatedUnitTest):
1763 1784
         self.assertEqual('1', output.image_id)
1764 1785
         self.assertEqual(1, len(output.locations))
1765 1786
         self.assertEqual(new_location, output.locations[0])
1787
+        self.assertEqual('active', output.status)
1766 1788
 
1767 1789
     def _test_update_locations_status(self, image_status, update):
1768 1790
         self.config(show_multiple_locations=True)

Loading…
Cancel
Save