]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
cloud: Volume creation fails node creation
authorZack Cerza <zack@redhat.com>
Thu, 9 Feb 2017 00:13:51 +0000 (17:13 -0700)
committerZack Cerza <zack@redhat.com>
Fri, 24 Feb 2017 16:03:33 +0000 (09:03 -0700)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/provision/cloud/openstack.py
teuthology/provision/cloud/test/test_openstack.py

index 36d4188e3b708bcff883db030e7c6753f3a44058..71e3962ebe6bf1901e03a0c2ab9c6cc7ec11067f 100644 (file)
@@ -173,7 +173,9 @@ class OpenStackProvisioner(base.Provisioner):
         )
         self._node, self.ips = results[0]
         log.debug("Node started: %s", self.node)
-        self._create_volumes()
+        if not self._create_volumes():
+            self._destroy_volumes()
+            return False
         self._update_dns()
         # Give cloud-init a few seconds to bring up the network, start sshd,
         # and install the public key
@@ -203,7 +205,6 @@ class OpenStackProvisioner(base.Provisioner):
                 )
         except Exception:
             log.exception("Failed to create or attach volume!")
-            self._destroy_volumes()
             return False
         return True
 
index 1b0f50f2f3809f2c3ecaa5cf73f489884d8dacc6..ac07fdf8968d9000fe2dfdf2d447c3674ad6d03d 100644 (file)
@@ -496,6 +496,16 @@ class TestOpenStackProvisioner(TestOpenStackBase):
         with p_wait_for_ready:
             res = obj.create()
         assert res is obj.node
+        # Test once again to ensure that if volume creation/attachment fails,
+        # we destroy any remaining volumes and consider the node creation to
+        # have failed as well.
+        del obj._node
+        with p_wait_for_ready:
+            obj.conf['volumes']['count'] = 1
+            obj.provider.driver.create_volume.side_effect = Exception
+            with patch.object(obj, '_destroy_volumes'):
+                assert obj.create() is False
+                assert obj._destroy_volumes.called_once_with()
 
     def test_update_dns(self):
         config.nsupdate_url = 'nsupdate_url'
@@ -542,22 +552,19 @@ class TestOpenStackProvisioner(TestOpenStackBase):
         if not should_succeed:
             obj.provider.driver.create_volume.side_effect = Exception
         obj._node = node
-        with patch.object(obj, '_destroy_volumes'):
-            result = obj._create_volumes()
-            assert result is should_succeed
-            if should_succeed:
-                create_calls = obj.provider.driver.create_volume.call_args_list
-                attach_calls = obj.provider.driver.attach_volume.call_args_list
-                assert len(create_calls) == count
-                assert len(attach_calls) == count
-                for i in range(count):
-                    vol_size, vol_name = create_calls[i][0]
-                    assert vol_size == size
-                    assert vol_name == '%s_%s' % (obj.name, i)
-                    assert attach_calls[i][0][0] is obj._node
-                    assert attach_calls[i][1]['device'] is None
-            else:
-                assert obj._destroy_volumes.called_once_with()
+        result = obj._create_volumes()
+        assert result is should_succeed
+        if should_succeed:
+            create_calls = obj.provider.driver.create_volume.call_args_list
+            attach_calls = obj.provider.driver.attach_volume.call_args_list
+            assert len(create_calls) == count
+            assert len(attach_calls) == count
+            for i in range(count):
+                vol_size, vol_name = create_calls[i][0]
+                assert vol_size == size
+                assert vol_name == '%s_%s' % (obj.name, i)
+                assert attach_calls[i][0][0] is obj._node
+                assert attach_calls[i][1]['device'] is None
 
     @mark.parametrize(*_volume_matrix)
     def test_destroy_volumes(self, count, size, should_succeed):