Destroy deployment in spite of exception

At current moment it is impossible to delete deployment
if for some reason deployment engine plugin
cannot be found, because exeption will be thrown.
This patch eliminates that issue.

Closes-Bug: #1536172

Change-Id: I043afd2a6751cca726fcc21caf46477762323e9a
This commit is contained in:
Dmitry Ratushnyy 2016-03-15 11:48:03 +03:00
parent d4daeafb34
commit adb13f54c7
2 changed files with 33 additions and 6 deletions

View File

@ -80,13 +80,17 @@ class Deployment(object):
# TODO(akscram): Check that the deployment have got a status that
# is equal to "*->finished" or "deploy->inconsistent".
deployment = objects.Deployment.get(deployment)
deployer = deploy_engine.Engine.get_engine(
deployment["config"]["type"], deployment)
tempest.Tempest(deployment["uuid"]).uninstall()
with deployer:
deployer.make_cleanup()
deployment.delete()
try:
deployer = deploy_engine.Engine.get_engine(
deployment["config"]["type"], deployment)
with deployer:
deployer.make_cleanup()
except exceptions.PluginNotFound:
LOG.info(_("Deployment %s will be deleted despite"
" exception") % deployment["uuid"])
deployment.delete()
@classmethod
def recreate(cls, deployment):

View File

@ -25,6 +25,7 @@ import mock
from rally import api
from rally.common import objects
from rally import consts
from rally.deployment import engine
from rally import exceptions
from tests.unit import fakes
from tests.unit import test
@ -592,3 +593,25 @@ class VerificationAPITestCase(BaseDeploymentTestCase):
retval = api.Verification.get("fake_id")
self.assertEqual(mock_verification_get.return_value, retval)
mock_verification_get.assert_called_once_with("fake_id")
@mock.patch("rally.common.objects.deploy.db.deployment_delete")
@mock.patch("rally.common.objects.deploy.db.deployment_update")
@mock.patch("rally.common.objects.deploy.db.deployment_get")
def test_destroy_invalid_deployment_type(self, mock_deployment_get,
mock_deployment_update,
mock_deployment_delete):
with mock.patch.dict(self.deployment["config"],
{"type": "InvalidDeploymentType"}):
deployment = mock.Mock()
deployment.update_status = lambda x: x
deployment.__getitem__ = lambda _self, key: self.deployment[key]
self.assertRaises(exceptions.PluginNotFound,
engine.Engine.get_engine,
self.deployment["config"]["type"],
deployment)
mock_deployment_get.return_value = self.deployment
mock_deployment_update.return_value = self.deployment
api.Deployment.destroy(self.deployment_uuid)
mock_deployment_get.assert_called_once_with(self.deployment_uuid)
mock_deployment_delete.assert_called_once_with(
self.deployment_uuid)