Browse Source

Merge "Move cluster delete method to driver"

changes/56/392356/2
Jenkins 5 years ago
committed by Gerrit Code Review
parent
commit
7fc0935a3e
3 changed files with 21 additions and 17 deletions
  1. +10
    -15
      magnum/conductor/handlers/cluster_conductor.py
  2. +3
    -0
      magnum/drivers/common/driver.py
  3. +8
    -2
      magnum/tests/unit/conductor/handlers/test_cluster_conductor.py

+ 10
- 15
magnum/conductor/handlers/cluster_conductor.py View File

@ -133,22 +133,18 @@ class Handler(object):
LOG.debug('cluster_heat cluster_delete')
osc = clients.OpenStackClients(context)
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:
conductor_utils.notify_about_cluster_operation(
context, taxonomy.ACTION_DELETE, taxonomy.OUTCOME_PENDING)
osc.heat().stacks.delete(stack_id)
cluster_driver.delete_stack(context, osc, cluster)
except exc.HTTPNotFound:
LOG.info(_LI('The stack %s was not found during cluster'
' deletion.'), stack_id)
' deletion.'), cluster.stack_id)
try:
trust_manager.delete_trustee_and_trust(osc, context, cluster)
cert_manager.delete_certificates_from_cluster(cluster,
@ -172,11 +168,11 @@ class Handler(object):
cluster.status = fields.ClusterStatus.DELETE_IN_PROGRESS
cluster.save()
self._poll_and_check(osc, cluster)
self._poll_and_check(osc, cluster, cluster_driver)
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)
lc = loopingcall.FixedIntervalLoopingCall(f=poller.poll_and_check)
lc.start(CONF.cluster_heat.wait_interval, True)
@ -184,15 +180,14 @@ class Handler(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.context = self.openstack_client.context
self.cluster = cluster
self.attempts = 0
self.cluster_template = conductor_utils.retrieve_cluster_template(
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):
# TODO(yuanying): temporary implementation to update api_address,


+ 3
- 0
magnum/drivers/common/driver.py View File

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

+ 8
- 2
magnum/tests/unit/conductor/handlers/test_cluster_conductor.py View File

@ -472,7 +472,10 @@ class TestHandler(db_base.DbTestCase):
@patch('magnum.conductor.handlers.cluster_conductor.cert_manager')
@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()
mock_openstack_client_class.return_value = osc
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.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):
mock_driver.return_value = k8s_atomic_dr.Driver()
osc = mock.MagicMock()
mock_openstack_client_class.return_value = osc
osc.heat.side_effect = exc.HTTPConflict


Loading…
Cancel
Save