def test_plan_create_InvalidProvider(self, mock_provider): plan = self._plan_in_request_body() body = {"plan": plan} req = fakes.HTTPRequest.blank('/v1/plans') mock_provider.side_effect = exception.NotFound() self.assertRaises(exc.HTTPBadRequest, self.controller.create, req, body=body)
def test_report_state_disconnected_DBError(self): service_ref = { 'host': self.host, 'binary': self.binary, 'topic': self.topic, 'report_count': 0, 'id': 1 } with mock.patch.object(service, 'db') as mock_db: mock_db.service_get_by_args.side_effect = exception.NotFound() mock_db.service_create.return_value = service_ref mock_db.service_get.side_effect = db_exc.DBError() serv = service.Service( self.host, self.binary, self.topic, 'karbor.tests.unit.test_service.FakeManager') serv.start() serv.report_state() self.assertTrue(serv.model_disconnected) self.assertFalse(mock_db.service_update.called)
def on_main(self, checkpoint, resource, context, parameters, **kwargs): resource_id = resource.id bank_section = checkpoint.get_resource_bank_section(resource_id) backup_id = None try: bank_section.update_object('status', constants.RESOURCE_STATUS_DELETING) resource_metadata = bank_section.get_object('metadata') backup_id = resource_metadata['backup_id'] trove_client = ClientFactory.create_client('trove', context) try: backup = trove_client.backups.get(backup_id) trove_client.backups.delete(backup) except trove_exc.NotFound: LOG.info('Backup id: %s not found. Assuming deleted', backup_id) is_success = utils.status_poll( partial(get_backup_status, trove_client, backup_id), interval=self._interval, success_statuses={'not-found'}, failure_statuses={'FAILED', 'DELETE_FAILED'}, ignore_statuses={'COMPLETED'}, ignore_unexpected=True ) if not is_success: raise exception.NotFound() bank_section.delete_object('metadata') bank_section.update_object('status', constants.RESOURCE_STATUS_DELETED) except Exception as e: LOG.error('Delete Database instance Backup failed, backup_id: %s', backup_id) bank_section.update_object('status', constants.RESOURCE_STATUS_ERROR) raise exception.DeleteResourceFailed( name="Database instance Backup", reason=six.text_type(e), resource_id=resource_id, resource_type=constants.DATABASE_RESOURCE_TYPE )
def on_main(self, checkpoint, resource, context, parameters, **kwargs): resource_id = resource.id bank_section = checkpoint.get_resource_bank_section(resource_id) snapshot_id = None try: bank_section.update_object('status', constants.RESOURCE_STATUS_DELETING) resource_metadata = bank_section.get_object('metadata') snapshot_id = resource_metadata['snapshot_id'] cinder_client = ClientFactory.create_client('cinder', context) try: snapshot = cinder_client.volume_snapshots.get(snapshot_id) cinder_client.volume_snapshots.delete(snapshot) except cinder_exc.NotFound: LOG.info('Snapshot id: %s not found. Assuming deleted', snapshot_id) is_success = utils.status_poll( partial(get_snapshot_status, cinder_client, snapshot_id), interval=self._interval, success_statuses={'deleted', 'not-found'}, failure_statuses={'error', 'error_deleting'}, ignore_statuses={'deleting'}, ignore_unexpected=True ) if not is_success: raise exception.NotFound() bank_section.delete_object('metadata') bank_section.update_object('status', constants.RESOURCE_STATUS_DELETED) except Exception as e: LOG.error('Delete volume snapshot failed, snapshot_id: %s', snapshot_id) bank_section.update_object('status', constants.RESOURCE_STATUS_ERROR) raise exception.DeleteResourceFailed( name="Volume Snapshot", reason=six.text_type(e), resource_id=resource_id, resource_type=constants.VOLUME_RESOURCE_TYPE )
def on_main(self, checkpoint, resource, context, parameters, **kwargs): resource_id = resource.id bank_section = checkpoint.get_resource_bank_section(resource_id) backup_id = None try: bank_section.update_object('status', constants.RESOURCE_STATUS_DELETING) resource_metadata = bank_section.get_object('metadata') backup_id = resource_metadata['backup_id'] cinder_client = ClientFactory.create_client('cinder', context) try: backup = cinder_client.backups.get(backup_id) cinder_client.backups.delete(backup) except cinder_exc.NotFound: LOG.info('Backup id: %s not found. Assuming deleted', backup_id) is_success = status_poll( partial(get_backup_status, cinder_client, backup_id), interval=self._interval, success_statuses={'deleted', 'not-found'}, failure_statuses={'error', 'error_deleting'}, ignore_statuses={'deleting'}, ) if not is_success: raise exception.NotFound() bank_section.delete_object('metadata') bank_section.update_object('status', constants.RESOURCE_STATUS_DELETED) except Exception as e: LOG.error('delete volume backup failed, backup_id: %s', backup_id) bank_section.update_object('status', constants.RESOURCE_STATUS_ERROR) raise exception.DeleteBackupFailed( reason=six.text_type(e), resource_id=resource_id, resource_type=constants.VOLUME_RESOURCE_TYPE)
def test_service_list_with_invalid_services(self, mock_get_all_by_args): req = fakes.HTTPRequest.blank('/v1/os-services', use_admin_context=True) mock_get_all_by_args.side_effect = exception.NotFound() self.assertRaises(exc.HTTPBadRequest, self.controller.index, req)