def do_delete(self, obj, **params): """Delete the physical resource associated with the specified node. :param obj: The node object to operate on. :param kwargs params: Optional keyword arguments for the delete operation. :returns: This operation always return True unless exception is caught. :raises: `EResourceDeletion` if interaction with compute service fails. """ if not obj.physical_id: return True server_id = obj.physical_id ignore_missing = params.get('ignore_missing', True) force = params.get('force', False) try: driver = self.compute(obj) if force: driver.server_force_delete(server_id, ignore_missing) else: driver.server_delete(server_id, ignore_missing) driver.wait_for_server_delete(server_id) return True except exc.InternalError as ex: raise exc.EResourceDeletion(type='server', id=server_id, message=six.text_type(ex))
def release_channel(self, context): queue_name = self.channel['queue_name'] subscription = self.channel['subscription'] # Delete subscription on zaqar queue try: self.zaqar().subscription_delete(queue_name, subscription) except exc.InternalError as ex: raise exc.EResourceDeletion(type='subscription', id='subscription', message=ex.message) # Delete zaqar queue try: self.zaqar().queue_delete(queue_name) except exc.InternalError as ex: raise exc.EResourceDeletion(type='queue', id='queue_name', message=ex.message)
def do_cluster_delete(self, obj): if obj.dependents and 'kube-node' in obj.dependents: msg = ("Cluster %s delete failed, " "Node clusters %s must be deleted first." % (obj.id, obj.dependents['kube-node'])) raise exc.EResourceDeletion(type='kubernetes.master', id=obj.id, message=msg) self._delete_network(obj) self._delete_security_group(obj)
def _delete_security_group(self, obj): sgid = obj.data.get(self.SECURITY_GROUP) if sgid: try: self.network(obj).security_group_delete(sgid, ignore_missing=True) except exc.InternalError as ex: raise exc.EResourceDeletion(type='kubernetes', id=sgid, message=str(ex))
def _delete_network(self, obj): client = self.network(obj) fip_id = obj.data.get(self.KUBE_MASTER_FLOATINGIP_ID) if fip_id: try: # delete floating ip client.floatingip_delete(fip_id) except exc.InternalError as ex: raise exc.EResourceDeletion(type='kubernetes', id=fip_id, message=str(ex)) router = obj.data.get(self.PRIVATE_ROUTER) subnet = obj.data.get(self.PRIVATE_SUBNET) if router and subnet: try: client.remove_interface_from_router(router, subnet_id=subnet) except exc.InternalError as ex: raise exc.EResourceDeletion(type='kubernetes', id=subnet, message=str(ex)) if router: try: # delete router client.router_delete(router, ignore_missing=True) except exc.InternalError as ex: raise exc.EResourceDeletion(type='kubernetes', id=router, message=str(ex)) net = obj.data.get(self.PRIVATE_NETWORK) if net: try: # delete network client.network_delete(net, ignore_missing=True) except exc.InternalError as ex: raise exc.EResourceDeletion(type='kubernetes', id=net, message=str(ex))
def test_do_recover_with_recreate_failed_delete(self): profile = self._create_profile('test-profile') err = exception.EResourceDeletion(type='STACK', id='ID', message='BANG') self.patchobject(profile, 'do_delete', side_effect=err) operation = "RECREATE" ex = self.assertRaises(exception.EResourceOperation, profile.do_recover, mock.Mock(id='NODE_ID'), operation=operation) self.assertEqual("Failed in recovering node 'NODE_ID': " "Failed in deleting STACK 'ID': BANG.", six.text_type(ex))
def test_do_recover_with_force_recreate_failed_delete(self): profile = self._create_profile('test-profile') self.patchobject(profile, 'do_create', return_value=True) err = exception.EResourceDeletion(type='STACK', id='ID', message='BANG') self.patchobject(profile, 'do_delete', side_effect=err) obj = mock.Mock() res = profile.do_recover(obj, ignore_missing=True, force_recreate=True, operation=consts.RECOVER_RECREATE) self.assertTrue(res) profile.do_delete.assert_called_once_with(obj, force=False, timeout=None) profile.do_create.assert_called_once_with(obj)
def test_node_delete_EResourceDeletion(self, mock_delete, mock_status): ex = exception.EResourceDeletion(type='PROFILE', id='NODE_ID', message='Too Bad') mock_delete.side_effect = ex node = nodem.Node('node1', PROFILE_ID, CLUSTER_ID, self.context) node.physical_id = uuidutils.generate_uuid() res = node.do_delete(self.context) self.assertFalse(res) mock_delete.assert_called_once_with(self.context, node) mock_status.assert_has_calls([ mock.call(self.context, consts.NS_DELETING, 'Deletion in progress'), mock.call(self.context, consts.NS_ERROR, 'Failed in deleting PROFILE NODE_ID: Too Bad.') ])
def do_delete(self, obj): """Delete a container node. :param obj: The node object representing the container. :returns: `None` """ if not obj.physical_id: return try: self.docker(obj).container_delete(obj.physical_id) except exc.InternalError as ex: raise exc.EResourceDeletion(type='container', id=obj.physical_id, message=six.text_type(ex)) ctx = context.get_admin_context() db_api.node_remove_dependents(ctx, self.host.id, obj.id) return
def do_delete(self, obj, **params): """Delete the physical stack behind the node object. :param obj: The node object to operate on. :param kwargs params: Optional keyword arguments for the delete operation. :returns: This operation always return True unless exception is caught. :raises: `EResourceDeletion` if interaction with heat fails. """ stack_id = obj.physical_id ignore_missing = params.get('ignore_missing', True) try: self.orchestration(obj).stack_delete(stack_id, ignore_missing) self.orchestration(obj).wait_for_stack_delete(stack_id) except exc.InternalError as ex: raise exc.EResourceDeletion(type='stack', id=stack_id, message=six.text_type(ex)) return True