To delete the keypair preparing for update replacement

If the keypair resource is in *_FAILED, to update it will
enter UpdateReplacement, but maybe the keypair exists still
in nova, then we can't recreate the new one, so try to delete
the old one preparing for update replacement.

Change-Id: Ic5a4e1eb4625dcefe5accc484b2c8db7fbb2940d
Closes-Bug: #1597602
This commit is contained in:
huangtianhua 2016-07-07 13:36:38 +08:00
parent 150a013597
commit bc782538d6
2 changed files with 19 additions and 0 deletions

View File

@ -135,6 +135,13 @@ class KeyPair(resource.Resource):
def get_reference_id(self):
return self.resource_id
def prepare_for_replace(self):
if self.resource_id is None:
return
with self.client_plugin().ignore_not_found:
self.client().keypairs.delete(self.resource_id)
def resource_mapping():
return {'OS::Nova::KeyPair': KeyPair}

View File

@ -145,6 +145,18 @@ class NovaKeyPairTest(common.HeatTestCase):
self.assertIn("boom", six.text_type(exc))
self.assertEqual((res.CHECK, res.FAILED), res.state)
def test_update_replace(self):
res = self._get_test_resource(self.kp_template)
res.state_set(res.CHECK, res.FAILED, 'for test')
res.resource_id = 'my_key'
# to delete the keypair preparing for replace
self.fake_keypairs.delete('my_key')
self.m.ReplayAll()
updater = scheduler.TaskRunner(res.update, res.t)
self.assertRaises(exception.UpdateReplace, updater)
self.m.ReplayAll()
def test_delete_key_not_found(self):
"""Test delete non-existent key."""
test_res = self._get_test_resource(self.kp_template)