From fdb2e2976a0c733170f9edb80f19c7ff98868190 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 8 Feb 2017 17:13:51 -0700 Subject: [PATCH] cloud: Volume creation fails node creation Signed-off-by: Zack Cerza --- teuthology/provision/cloud/openstack.py | 5 ++- .../provision/cloud/test/test_openstack.py | 39 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/teuthology/provision/cloud/openstack.py b/teuthology/provision/cloud/openstack.py index 36d4188e3b..71e3962ebe 100644 --- a/teuthology/provision/cloud/openstack.py +++ b/teuthology/provision/cloud/openstack.py @@ -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 diff --git a/teuthology/provision/cloud/test/test_openstack.py b/teuthology/provision/cloud/test/test_openstack.py index 1b0f50f2f3..ac07fdf896 100644 --- a/teuthology/provision/cloud/test/test_openstack.py +++ b/teuthology/provision/cloud/test/test_openstack.py @@ -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): -- 2.39.5