Browse Source

Merge "Improve handle_delete/check_delete_complete for resources"

changes/86/700886/10
Zuul 6 days ago
parent
commit
94bdcd8c9f
6 changed files with 36 additions and 35 deletions
  1. +2
    -1
      heat/engine/resources/openstack/designate/recordset.py
  2. +7
    -8
      heat/engine/resources/openstack/heat/remote_stack.py
  3. +7
    -10
      heat/engine/resources/openstack/senlin/cluster.py
  4. +7
    -10
      heat/engine/resources/openstack/senlin/node.py
  5. +4
    -1
      heat/engine/resources/openstack/senlin/policy.py
  6. +9
    -5
      heat/tests/openstack/designate/test_recordset.py

+ 2
- 1
heat/engine/resources/openstack/designate/recordset.py View File

@@ -150,9 +150,10 @@ class DesignateRecordSet(resource.Resource):
recordset=self.resource_id,
zone=self.properties[self.ZONE]
)
return self.resource_id

def check_delete_complete(self, handler_data=None):
if self.resource_id is not None:
if handler_data:
with self.client_plugin().ignore_not_found:
return self._check_status_complete()


+ 7
- 8
heat/engine/resources/openstack/heat/remote_stack.py View File

@@ -314,6 +314,8 @@ class RemoteStack(resource.Resource):
with TempCACertFile(self.cacert) as cacert_path:
self.heat(
cacert_path).stacks.delete(stack_id=self.resource_id)
return self.resource_id
return None

def handle_resume(self):
if self.resource_id is None:
@@ -414,15 +416,12 @@ class RemoteStack(resource.Resource):
def check_create_complete(self, *args):
return self._check_action_complete(action=self.CREATE)

def check_delete_complete(self, *args):
if self.resource_id is None:
return True
def check_delete_complete(self, deleting_resource_id=None):
if deleting_resource_id is not None:
with self.client_plugin().ignore_not_found:
return self._check_action_complete(action=self.DELETE)

try:
return self._check_action_complete(action=self.DELETE)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
return True
return True

def check_resume_complete(self, *args):
return self._check_action_complete(action=self.RESUME)

+ 7
- 10
heat/engine/resources/openstack/senlin/cluster.py View File

@@ -249,18 +249,15 @@ class Cluster(res_base.BaseSenlinResource):
if self.resource_id is not None:
with self.client_plugin().ignore_not_found:
self.client().delete_cluster(self.resource_id)
return self.resource_id
return self.resource_id

def check_delete_complete(self, resource_id):
if not resource_id:
return True

try:
self.client().get_cluster(self.resource_id)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
return True
return False
if resource_id:
with self.client_plugin().ignore_not_found:
self.client().get_cluster(self.resource_id)
return False

return True

def handle_update(self, json_snippet, tmpl_diff, prop_diff):
UPDATE_PROPS = (self.NAME, self.METADATA, self.TIMEOUT, self.PROFILE)

+ 7
- 10
heat/engine/resources/openstack/senlin/node.py View File

@@ -130,18 +130,15 @@ class Node(res_base.BaseSenlinResource):
if self.resource_id is not None:
with self.client_plugin().ignore_not_found:
self.client().delete_node(self.resource_id)
return self.resource_id
return self.resource_id

def check_delete_complete(self, res_id):
if not res_id:
return True

try:
self.client().get_node(self.resource_id)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
return True
return False
if res_id:
with self.client_plugin().ignore_not_found:
self.client().get_node(self.resource_id)
return False

return True

def handle_update(self, json_snippet, tmpl_diff, prop_diff):
actions = []

+ 4
- 1
heat/engine/resources/openstack/senlin/policy.py View File

@@ -169,10 +169,13 @@ class Policy(res_base.BaseSenlinResource):
return self.check_action_done(bindings)

def handle_delete(self):
if not self.resource_id:
return

return copy.deepcopy(self.properties[self.BINDINGS])

def check_delete_complete(self, bindings):
if not self.resource_id:
if not bindings:
return True
self.remove_bindings(bindings)
if self.check_action_done(bindings):

+ 9
- 5
heat/tests/openstack/designate/test_recordset.py View File

@@ -165,7 +165,7 @@ class DesignateRecordSetTest(common.HeatTestCase):
self.assertFalse(self.test_resource.check_update_complete())
self.assertTrue(self.test_resource.check_update_complete())
ex = self.assertRaises(exception.ResourceInError,
self.test_resource.check_create_complete)
self.test_resource.check_update_complete)
self.assertIn('Error in RecordSet',
ex.message)

@@ -174,7 +174,8 @@ class DesignateRecordSetTest(common.HeatTestCase):
self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
mock_record_delete.return_value = None

self.assertIsNone(self.test_resource.handle_delete())
self.assertEqual(self.test_resource.resource_id,
self.test_resource.handle_delete())
mock_record_delete.assert_called_once_with(
zone='1234567',
recordset=self.test_resource.resource_id
@@ -192,10 +193,13 @@ class DesignateRecordSetTest(common.HeatTestCase):
def test_check_delete_complete(self):
self.test_resource.resource_id = self._get_mock_resource()['id']
self._mock_check_status_active()
self.assertFalse(self.test_resource.check_delete_complete())
self.assertTrue(self.test_resource.check_delete_complete())
self.assertFalse(self.test_resource.check_delete_complete(
self.test_resource.resource_id))
self.assertTrue(self.test_resource.check_delete_complete(
self.test_resource.resource_id))
ex = self.assertRaises(exception.ResourceInError,
self.test_resource.check_create_complete)
self.test_resource.check_delete_complete,
self.test_resource.resource_id)
self.assertIn('Error in RecordSet',
ex.message)


Loading…
Cancel
Save