Merge "Move cluster delete method to driver"

This commit is contained in:
Jenkins 2016-11-01 20:46:49 +00:00 committed by Gerrit Code Review
commit 7fc0935a3e
3 changed files with 21 additions and 17 deletions

View File

@ -133,22 +133,18 @@ class Handler(object):
LOG.debug('cluster_heat cluster_delete') LOG.debug('cluster_heat cluster_delete')
osc = clients.OpenStackClients(context) osc = clients.OpenStackClients(context)
cluster = objects.Cluster.get_by_uuid(context, uuid) cluster = objects.Cluster.get_by_uuid(context, uuid)
ct = conductor_utils.retrieve_cluster_template(context, cluster)
cluster_driver = driver.Driver.get_driver(ct.server_type,
ct.cluster_distro,
ct.coe)
stack_id = cluster.stack_id
# NOTE(sdake): This will execute a stack_delete operation. This will
# Ignore HTTPNotFound exceptions (stack wasn't present). In the case
# that Heat couldn't find the stack representing the cluster, likely a
# user has deleted the stack outside the context of Magnum. Therefore
# the contents of the cluster are forever lost.
#
# If the exception is unhandled, the original exception will be raised.
try: try:
conductor_utils.notify_about_cluster_operation( conductor_utils.notify_about_cluster_operation(
context, taxonomy.ACTION_DELETE, taxonomy.OUTCOME_PENDING) context, taxonomy.ACTION_DELETE, taxonomy.OUTCOME_PENDING)
osc.heat().stacks.delete(stack_id) cluster_driver.delete_stack(context, osc, cluster)
except exc.HTTPNotFound: except exc.HTTPNotFound:
LOG.info(_LI('The stack %s was not found during cluster' LOG.info(_LI('The stack %s was not found during cluster'
' deletion.'), stack_id) ' deletion.'), cluster.stack_id)
try: try:
trust_manager.delete_trustee_and_trust(osc, context, cluster) trust_manager.delete_trustee_and_trust(osc, context, cluster)
cert_manager.delete_certificates_from_cluster(cluster, cert_manager.delete_certificates_from_cluster(cluster,
@ -172,11 +168,11 @@ class Handler(object):
cluster.status = fields.ClusterStatus.DELETE_IN_PROGRESS cluster.status = fields.ClusterStatus.DELETE_IN_PROGRESS
cluster.save() cluster.save()
self._poll_and_check(osc, cluster) self._poll_and_check(osc, cluster, cluster_driver)
return None return None
def _poll_and_check(self, osc, cluster, cluster_driver=None): def _poll_and_check(self, osc, cluster, cluster_driver):
poller = HeatPoller(osc, cluster, cluster_driver) poller = HeatPoller(osc, cluster, cluster_driver)
lc = loopingcall.FixedIntervalLoopingCall(f=poller.poll_and_check) lc = loopingcall.FixedIntervalLoopingCall(f=poller.poll_and_check)
lc.start(CONF.cluster_heat.wait_interval, True) lc.start(CONF.cluster_heat.wait_interval, True)
@ -184,15 +180,14 @@ class Handler(object):
class HeatPoller(object): class HeatPoller(object):
def __init__(self, openstack_client, cluster, cluster_driver=None): def __init__(self, openstack_client, cluster, cluster_driver):
self.openstack_client = openstack_client self.openstack_client = openstack_client
self.context = self.openstack_client.context self.context = self.openstack_client.context
self.cluster = cluster self.cluster = cluster
self.attempts = 0 self.attempts = 0
self.cluster_template = conductor_utils.retrieve_cluster_template( self.cluster_template = conductor_utils.retrieve_cluster_template(
self.context, cluster) self.context, cluster)
if cluster_driver: self.template_def = cluster_driver.get_template_definition()
self.template_def = cluster_driver.get_template_definition()
def poll_and_check(self): def poll_and_check(self):
# TODO(yuanying): temporary implementation to update api_address, # TODO(yuanying): temporary implementation to update api_address,

View File

@ -206,3 +206,6 @@ class Driver(object):
} }
return osc.heat().stacks.update(cluster.stack_id, **fields) return osc.heat().stacks.update(cluster.stack_id, **fields)
def delete_stack(self, context, osc, cluster):
osc.heat().stacks.delete(cluster.stack_id)

View File

@ -472,7 +472,10 @@ class TestHandler(db_base.DbTestCase):
@patch('magnum.conductor.handlers.cluster_conductor.cert_manager') @patch('magnum.conductor.handlers.cluster_conductor.cert_manager')
@patch('magnum.common.clients.OpenStackClients') @patch('magnum.common.clients.OpenStackClients')
def test_cluster_delete(self, mock_openstack_client_class, cert_manager): @patch('magnum.drivers.common.driver.Driver.get_driver')
def test_cluster_delete(self, mock_driver, mock_openstack_client_class,
cert_manager):
mock_driver.return_value = k8s_atomic_dr.Driver()
osc = mock.MagicMock() osc = mock.MagicMock()
mock_openstack_client_class.return_value = osc mock_openstack_client_class.return_value = osc
osc.heat.side_effect = exc.HTTPNotFound osc.heat.side_effect = exc.HTTPNotFound
@ -496,8 +499,11 @@ class TestHandler(db_base.DbTestCase):
@patch('magnum.conductor.handlers.cluster_conductor.cert_manager') @patch('magnum.conductor.handlers.cluster_conductor.cert_manager')
@patch('magnum.common.clients.OpenStackClients') @patch('magnum.common.clients.OpenStackClients')
def test_cluster_delete_conflict(self, mock_openstack_client_class, @patch('magnum.drivers.common.driver.Driver.get_driver')
def test_cluster_delete_conflict(self, mock_driver,
mock_openstack_client_class,
cert_manager): cert_manager):
mock_driver.return_value = k8s_atomic_dr.Driver()
osc = mock.MagicMock() osc = mock.MagicMock()
mock_openstack_client_class.return_value = osc mock_openstack_client_class.return_value = osc
osc.heat.side_effect = exc.HTTPConflict osc.heat.side_effect = exc.HTTPConflict