Port from python2: Remove circular dependency on delete resource
python2: https://review.opendev.org/#/c/693399 Change-Id: I0f68235685f03fc73fb848997d5eba5e8915b477
This commit is contained in:
parent
bf8b33b372
commit
6f3fb47049
@ -42,12 +42,12 @@ class RegionController(rest.RestController):
|
|||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
status_code=409,
|
status_code=409,
|
||||||
message='Region already exists',
|
message='Region already exists',
|
||||||
error_details=exception.message)
|
error_details=str(exception))
|
||||||
|
|
||||||
except ErrorStatus as exception:
|
except ErrorStatus as exception:
|
||||||
LOG.log_exception("CustomerController - Failed to update regions", exception)
|
LOG.log_exception("CustomerController - Failed to update regions", exception)
|
||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
message=exception.message,
|
message=str(exception),
|
||||||
status_code=exception.status_code)
|
status_code=exception.status_code)
|
||||||
|
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
@ -77,7 +77,7 @@ class RegionController(rest.RestController):
|
|||||||
except ErrorStatus as exception:
|
except ErrorStatus as exception:
|
||||||
LOG.log_exception("CustomerController - Failed to Replace regions", exception)
|
LOG.log_exception("CustomerController - Failed to Replace regions", exception)
|
||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
message=exception.message,
|
message=str(exception),
|
||||||
status_code=exception.status_code)
|
status_code=exception.status_code)
|
||||||
|
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
@ -95,14 +95,11 @@ class RegionController(rest.RestController):
|
|||||||
force_delete = True
|
force_delete = True
|
||||||
else:
|
else:
|
||||||
force_delete = False
|
force_delete = False
|
||||||
requester = request.headers.get('X-RANGER-Requester')
|
|
||||||
is_rds_client_request = requester == 'rds_resource_service_proxy'
|
|
||||||
LOG.info("Delete Region (delete) customer id {0} region_id: {1} by RDS Proxy: {2} ".format(customer_id, region_id, is_rds_client_request))
|
|
||||||
authentication.authorize(request, 'customers:delete_region')
|
authentication.authorize(request, 'customers:delete_region')
|
||||||
try:
|
try:
|
||||||
customer_logic = CustomerLogic()
|
customer_logic = CustomerLogic()
|
||||||
customer_logic.delete_region(customer_id, region_id, request.transaction_id,
|
customer_logic.delete_region(customer_id, region_id, request.transaction_id,
|
||||||
is_rds_client_request, force_delete)
|
force_delete)
|
||||||
LOG.info("RegionController - Delete Region (delete) finished well")
|
LOG.info("RegionController - Delete Region (delete) finished well")
|
||||||
|
|
||||||
event_details = 'Customer {} region: {} deleted'.format(
|
event_details = 'Customer {} region: {} deleted'.format(
|
||||||
@ -118,7 +115,7 @@ class RegionController(rest.RestController):
|
|||||||
except ErrorStatus as exception:
|
except ErrorStatus as exception:
|
||||||
LOG.log_exception("CustomerController - Failed to delete region", exception)
|
LOG.log_exception("CustomerController - Failed to delete region", exception)
|
||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
message=exception.message,
|
message=str(exception),
|
||||||
status_code=exception.status_code)
|
status_code=exception.status_code)
|
||||||
|
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
|
@ -54,13 +54,13 @@ class RegionController(rest.RestController):
|
|||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
status_code=409,
|
status_code=409,
|
||||||
message='Region already exists',
|
message='Region already exists',
|
||||||
error_details=exception.message)
|
error_details=str(exception))
|
||||||
|
|
||||||
except ErrorStatus as exception:
|
except ErrorStatus as exception:
|
||||||
LOG.log_exception(
|
LOG.log_exception(
|
||||||
"RegionController - Failed to add regions", exception)
|
"RegionController - Failed to add regions", exception)
|
||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
message=exception.message,
|
message=str(exception),
|
||||||
status_code=exception.status_code)
|
status_code=exception.status_code)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
LOG.log_exception(
|
LOG.log_exception(
|
||||||
@ -79,17 +79,12 @@ class RegionController(rest.RestController):
|
|||||||
else:
|
else:
|
||||||
force_delete = False
|
force_delete = False
|
||||||
|
|
||||||
requester = request.headers.get('X-RANGER-Requester')
|
|
||||||
is_rds_client_request = requester == 'rds_resource_service_proxy'
|
|
||||||
LOG.info("Delete Region group id {0} region_id: {1} by RDS Proxy: "
|
|
||||||
" {2} ".format(group_id, region_id, is_rds_client_request))
|
|
||||||
authentication.authorize(request, 'groups:delete_region')
|
authentication.authorize(request, 'groups:delete_region')
|
||||||
try:
|
try:
|
||||||
group_logic = GroupLogic()
|
group_logic = GroupLogic()
|
||||||
group_logic.delete_region(group_id,
|
group_logic.delete_region(group_id,
|
||||||
region_id,
|
region_id,
|
||||||
request.transaction_id,
|
request.transaction_id,
|
||||||
is_rds_client_request,
|
|
||||||
force_delete)
|
force_delete)
|
||||||
LOG.info("RegionController - Delete Region finished")
|
LOG.info("RegionController - Delete Region finished")
|
||||||
|
|
||||||
@ -109,7 +104,7 @@ class RegionController(rest.RestController):
|
|||||||
LOG.log_exception("RegionController - Failed to delete region",
|
LOG.log_exception("RegionController - Failed to delete region",
|
||||||
exception)
|
exception)
|
||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
message=exception.message,
|
message=str(exception),
|
||||||
status_code=exception.status_code)
|
status_code=exception.status_code)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
LOG.log_exception("RegionController - Failed in delete Region",
|
LOG.log_exception("RegionController - Failed in delete Region",
|
||||||
|
@ -588,15 +588,12 @@ class CustomerLogic(object):
|
|||||||
datamanager.rollback()
|
datamanager.rollback()
|
||||||
raise exp
|
raise exp
|
||||||
|
|
||||||
def delete_region(self, customer_id, region_id, transaction_id, on_success_by_rds,
|
def delete_region(self, customer_id, region_id, transaction_id, force_delete):
|
||||||
force_delete):
|
|
||||||
datamanager = DataManager()
|
datamanager = DataManager()
|
||||||
try:
|
try:
|
||||||
customer_region = datamanager.get_record('customer_region')
|
customer_region = datamanager.get_record('customer_region')
|
||||||
|
|
||||||
sql_customer = datamanager.get_customer_by_uuid(customer_id)
|
sql_customer = datamanager.get_customer_by_uuid(customer_id)
|
||||||
if on_success_by_rds and sql_customer is None:
|
|
||||||
return
|
|
||||||
if sql_customer is None:
|
if sql_customer is None:
|
||||||
raise ErrorStatus(404,
|
raise ErrorStatus(404,
|
||||||
"customer with id {} does not exist".format(
|
"customer with id {} does not exist".format(
|
||||||
@ -606,11 +603,6 @@ class CustomerLogic(object):
|
|||||||
customer_region.delete_region_for_customer(customer_id, region_id)
|
customer_region.delete_region_for_customer(customer_id, region_id)
|
||||||
datamanager.flush() # Get any exception created by this insert
|
datamanager.flush() # Get any exception created by this insert
|
||||||
|
|
||||||
if on_success_by_rds:
|
|
||||||
datamanager.commit()
|
|
||||||
LOG.debug("Region {0} in customer {1} deleted".format(region_id,
|
|
||||||
customer_id))
|
|
||||||
else:
|
|
||||||
region = next((r.region for r in sql_customer.customer_customer_regions if r.region.name == region_id), None)
|
region = next((r.region for r in sql_customer.customer_customer_regions if r.region.name == region_id), None)
|
||||||
if region:
|
if region:
|
||||||
if region.type == 'group':
|
if region.type == 'group':
|
||||||
|
@ -57,7 +57,8 @@ class GroupLogic(object):
|
|||||||
# add group default users
|
# add group default users
|
||||||
self.add_default_user_db(datamanager, group.users, [], sql_group.uuid)
|
self.add_default_user_db(datamanager, group.users, [], sql_group.uuid)
|
||||||
# add default user(s) to all regions where group is assigned to
|
# add default user(s) to all regions where group is assigned to
|
||||||
self.add_default_users_to_regions_db(datamanager, sql_group, group.users)
|
self.add_default_users_to_regions_db(
|
||||||
|
datamanager, sql_group, group.users)
|
||||||
|
|
||||||
self.add_roles_to_db(group.roles, sql_group.uuid, datamanager)
|
self.add_roles_to_db(group.roles, sql_group.uuid, datamanager)
|
||||||
|
|
||||||
@ -669,14 +670,11 @@ class GroupLogic(object):
|
|||||||
finally:
|
finally:
|
||||||
datamanager.close()
|
datamanager.close()
|
||||||
|
|
||||||
def delete_region(self, group_id, region_id, transaction_id,
|
def delete_region(self, group_id, region_id, transaction_id, force_delete):
|
||||||
on_success_by_rds, force_delete):
|
|
||||||
datamanager = DataManager()
|
datamanager = DataManager()
|
||||||
try:
|
try:
|
||||||
group_region = datamanager.get_record('groups_region')
|
group_region = datamanager.get_record('groups_region')
|
||||||
sql_group = datamanager.get_group_by_uuid_or_name(group_id)
|
sql_group = datamanager.get_group_by_uuid_or_name(group_id)
|
||||||
if on_success_by_rds and sql_group is None:
|
|
||||||
return
|
|
||||||
if sql_group is None:
|
if sql_group is None:
|
||||||
raise ErrorStatus(
|
raise ErrorStatus(
|
||||||
404,
|
404,
|
||||||
@ -686,11 +684,6 @@ class GroupLogic(object):
|
|||||||
group_region.delete_region_for_group(group_id, region_id)
|
group_region.delete_region_for_group(group_id, region_id)
|
||||||
datamanager.flush()
|
datamanager.flush()
|
||||||
|
|
||||||
if on_success_by_rds:
|
|
||||||
datamanager.commit()
|
|
||||||
LOG.debug("Region {0} in group {1} deleted".format(region_id,
|
|
||||||
group_id))
|
|
||||||
else:
|
|
||||||
region = next((r.region for r in sql_group.group_regions
|
region = next((r.region for r in sql_group.group_regions
|
||||||
if r.region.name == region_id), None)
|
if r.region.name == region_id), None)
|
||||||
if region:
|
if region:
|
||||||
|
@ -16,7 +16,8 @@ di = injector.get_di()
|
|||||||
@di.dependsOn('flavor_logic')
|
@di.dependsOn('flavor_logic')
|
||||||
@di.dependsOn('utils')
|
@di.dependsOn('utils')
|
||||||
class RegionController(rest.RestController):
|
class RegionController(rest.RestController):
|
||||||
@wsexpose(RegionWrapper, str, body=RegionWrapper, rest_content_types='json', status_code=201)
|
@wsexpose(RegionWrapper, str, body=RegionWrapper,
|
||||||
|
rest_content_types='json', status_code=201)
|
||||||
def post(self, flavor_id, region_wrapper):
|
def post(self, flavor_id, region_wrapper):
|
||||||
flavor_logic, utils = di.resolver.unpack(RegionController)
|
flavor_logic, utils = di.resolver.unpack(RegionController)
|
||||||
|
|
||||||
@ -24,7 +25,8 @@ class RegionController(rest.RestController):
|
|||||||
authentication.authorize(request, 'flavor:add_flavor_regions')
|
authentication.authorize(request, 'flavor:add_flavor_regions')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = flavor_logic.add_regions(flavor_id, region_wrapper, request.transaction_id)
|
result = flavor_logic.add_regions(
|
||||||
|
flavor_id, region_wrapper, request.transaction_id)
|
||||||
|
|
||||||
LOG.info("RegionController - regions added: " + str(result))
|
LOG.info("RegionController - regions added: " + str(result))
|
||||||
|
|
||||||
@ -36,13 +38,15 @@ class RegionController(rest.RestController):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
except ErrorStatus as exception:
|
except ErrorStatus as exception:
|
||||||
LOG.log_exception("RegionController - Failed to add region", exception)
|
LOG.log_exception("RegionController - Failed to add region",
|
||||||
|
exception)
|
||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
message=exception.message,
|
message=str(exception),
|
||||||
status_code=exception.status_code)
|
status_code=exception.status_code)
|
||||||
|
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
LOG.log_exception("RegionController - Failed to add region", exception)
|
LOG.log_exception("RegionController - Failed to add region",
|
||||||
|
exception)
|
||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
status_code=500,
|
status_code=500,
|
||||||
error_details=str(exception))
|
error_details=str(exception))
|
||||||
@ -54,16 +58,12 @@ class RegionController(rest.RestController):
|
|||||||
else:
|
else:
|
||||||
force_delete = False
|
force_delete = False
|
||||||
flavor_logic, utils = di.resolver.unpack(RegionController)
|
flavor_logic, utils = di.resolver.unpack(RegionController)
|
||||||
requester = request.headers.get('X-RANGER-Requester')
|
|
||||||
is_rds_client_request = requester == 'rds_resource_service_proxy'
|
|
||||||
LOG.info("RegionController - Delete region:{0} by RDS Proxy: {1} ".format(region_name, is_rds_client_request))
|
|
||||||
|
|
||||||
authentication.authorize(request, 'flavor:delete_flavor_region')
|
authentication.authorize(request, 'flavor:delete_flavor_region')
|
||||||
try:
|
try:
|
||||||
result = flavor_logic.delete_region(flavor_id, region_name, request.transaction_id,
|
result = flavor_logic.delete_region(
|
||||||
is_rds_client_request, force_delete)
|
flavor_id, region_name, request.transaction_id, force_delete)
|
||||||
|
|
||||||
if is_rds_client_request:
|
|
||||||
LOG.info("RegionController - region deleted: " + str(result))
|
LOG.info("RegionController - region deleted: " + str(result))
|
||||||
|
|
||||||
event_details = 'Flavor {} region {} deleted'.format(flavor_id,
|
event_details = 'Flavor {} region {} deleted'.format(flavor_id,
|
||||||
@ -73,13 +73,15 @@ class RegionController(rest.RestController):
|
|||||||
event_details=event_details)
|
event_details=event_details)
|
||||||
|
|
||||||
except ErrorStatus as exception:
|
except ErrorStatus as exception:
|
||||||
LOG.log_exception("RegionController - Failed to delete region", exception)
|
LOG.log_exception("RegionController - Failed to delete region",
|
||||||
|
exception)
|
||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
message=exception.message,
|
message=str(exception),
|
||||||
status_code=exception.status_code)
|
status_code=exception.status_code)
|
||||||
|
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
LOG.log_exception("RegionController - Failed to delete region", exception)
|
LOG.log_exception("RegionController - Failed to delete region",
|
||||||
|
exception)
|
||||||
raise err_utils.get_error(request.transaction_id,
|
raise err_utils.get_error(request.transaction_id,
|
||||||
status_code=500,
|
status_code=500,
|
||||||
error_details=str(exception))
|
error_details=str(exception))
|
||||||
|
@ -256,16 +256,13 @@ def add_regions(flavor_uuid, regions, transaction_id):
|
|||||||
|
|
||||||
|
|
||||||
@di.dependsOn('data_manager')
|
@di.dependsOn('data_manager')
|
||||||
def delete_region(flavor_uuid, region_name, transaction_id, on_success_by_rds,
|
def delete_region(flavor_uuid, region_name, transaction_id, force_delete):
|
||||||
force_delete):
|
|
||||||
DataManager = di.resolver.unpack(delete_region)
|
DataManager = di.resolver.unpack(delete_region)
|
||||||
datamanager = DataManager()
|
datamanager = DataManager()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
flavor_rec = datamanager.get_record('flavor')
|
flavor_rec = datamanager.get_record('flavor')
|
||||||
sql_flavor = flavor_rec.get_flavor_by_id(flavor_uuid)
|
sql_flavor = flavor_rec.get_flavor_by_id(flavor_uuid)
|
||||||
if not sql_flavor and on_success_by_rds:
|
|
||||||
return
|
|
||||||
if not sql_flavor:
|
if not sql_flavor:
|
||||||
raise ErrorStatus(404,
|
raise ErrorStatus(404,
|
||||||
'flavor id {0} not found'.format(flavor_uuid))
|
'flavor id {0} not found'.format(flavor_uuid))
|
||||||
@ -275,9 +272,6 @@ def delete_region(flavor_uuid, region_name, transaction_id, on_success_by_rds,
|
|||||||
|
|
||||||
# get any exception created by previous actions against the database
|
# get any exception created by previous actions against the database
|
||||||
datamanager.flush()
|
datamanager.flush()
|
||||||
if on_success_by_rds:
|
|
||||||
datamanager.commit()
|
|
||||||
else:
|
|
||||||
send_to_rds_if_needed(sql_flavor, existing_region_names, "put",
|
send_to_rds_if_needed(sql_flavor, existing_region_names, "put",
|
||||||
transaction_id)
|
transaction_id)
|
||||||
if force_delete:
|
if force_delete:
|
||||||
|
@ -99,12 +99,9 @@ class RegionController(rest.RestController):
|
|||||||
image_logic, utils = di.resolver.unpack(RegionController)
|
image_logic, utils = di.resolver.unpack(RegionController)
|
||||||
auth.authorize(request, "region:delete")
|
auth.authorize(request, "region:delete")
|
||||||
try:
|
try:
|
||||||
requester = request.headers.get('X-RANGER-Requester')
|
result = image_logic.delete_region(
|
||||||
is_rds_client_request = requester == 'rds_resource_service_proxy'
|
image_id, region_name, request.transaction_id, force_delete)
|
||||||
LOG.info("RegionController - Delete region:{0} by RDS Proxy: {1} ".format(region_name, is_rds_client_request))
|
|
||||||
result = image_logic.delete_region(image_id, region_name, request.transaction_id, is_rds_client_request,
|
|
||||||
force_delete)
|
|
||||||
if is_rds_client_request:
|
|
||||||
LOG.info("RegionController - region deleted: " + str(result))
|
LOG.info("RegionController - region deleted: " + str(result))
|
||||||
|
|
||||||
event_details = 'Image {} region {} deleted'.format(image_id,
|
event_details = 'Image {} region {} deleted'.format(image_id,
|
||||||
|
@ -261,16 +261,13 @@ def replace_regions(image_uuid, regions, transaction_id):
|
|||||||
|
|
||||||
|
|
||||||
@di.dependsOn('data_manager')
|
@di.dependsOn('data_manager')
|
||||||
def delete_region(image_uuid, region_name, transaction_id, on_success_by_rds,
|
def delete_region(image_uuid, region_name, transaction_id, force_delete):
|
||||||
force_delete):
|
|
||||||
DataManager = di.resolver.unpack(delete_region)
|
DataManager = di.resolver.unpack(delete_region)
|
||||||
datamanager = DataManager()
|
datamanager = DataManager()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
image_rec = datamanager.get_record('image')
|
image_rec = datamanager.get_record('image')
|
||||||
sql_image = image_rec.get_image_by_id(image_uuid)
|
sql_image = image_rec.get_image_by_id(image_uuid)
|
||||||
if on_success_by_rds and not sql_image:
|
|
||||||
return
|
|
||||||
if not sql_image:
|
if not sql_image:
|
||||||
raise ErrorStatus(404, 'image with id: {0} not found'.format(
|
raise ErrorStatus(404, 'image with id: {0} not found'.format(
|
||||||
image_uuid))
|
image_uuid))
|
||||||
@ -283,11 +280,9 @@ def delete_region(image_uuid, region_name, transaction_id, on_success_by_rds,
|
|||||||
existing_region_names = sql_image.get_existing_region_names()
|
existing_region_names = sql_image.get_existing_region_names()
|
||||||
sql_image.remove_region(region_name)
|
sql_image.remove_region(region_name)
|
||||||
|
|
||||||
datamanager.flush() # Get any exception created by
|
# Get any exception created by previous actions against the database
|
||||||
# previous actions against the database
|
datamanager.flush()
|
||||||
if on_success_by_rds:
|
|
||||||
datamanager.commit()
|
|
||||||
else:
|
|
||||||
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
send_to_rds_if_needed(sql_image, existing_region_names, "put",
|
||||||
transaction_id)
|
transaction_id)
|
||||||
if force_delete:
|
if force_delete:
|
||||||
|
@ -14,7 +14,8 @@ server = {
|
|||||||
|
|
||||||
# DB configurations
|
# DB configurations
|
||||||
database = {
|
database = {
|
||||||
'url': config.db_connect
|
'url': config.db_connect,
|
||||||
|
'connection_string': config.db_connect
|
||||||
}
|
}
|
||||||
|
|
||||||
sot = {
|
sot = {
|
||||||
|
@ -3,6 +3,12 @@ import logging
|
|||||||
from pecan import conf
|
from pecan import conf
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from orm.services.customer_manager.cms_rest.data.data_manager \
|
||||||
|
import DataManager as CmsDataManager
|
||||||
|
from orm.services.flavor_manager.fms_rest.data.sql_alchemy.data_manager \
|
||||||
|
import DataManager as FmsDataManager
|
||||||
|
from orm.services.image_manager.ims.persistency.sql_alchemy.data_manager \
|
||||||
|
import DataManager as ImsDataManager
|
||||||
from orm.services.resource_distributor.rds.services.base import ErrorMessage
|
from orm.services.resource_distributor.rds.services.base import ErrorMessage
|
||||||
from orm.services.resource_distributor.rds.utils import \
|
from orm.services.resource_distributor.rds.utils import \
|
||||||
authentication as AuthService
|
authentication as AuthService
|
||||||
@ -10,7 +16,6 @@ from orm.services.resource_distributor.rds.utils import \
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
headers = {'content-type': 'application/json'}
|
headers = {'content-type': 'application/json'}
|
||||||
|
|
||||||
|
|
||||||
@ -22,61 +27,106 @@ def _set_headers(region):
|
|||||||
headers['X-Auth-Region'] = region
|
headers['X-Auth-Region'] = region
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("no token")
|
logger.error("no token")
|
||||||
headers['X-RANGER-Requester'] = 'rds_resource_service_proxy'
|
|
||||||
|
|
||||||
|
|
||||||
def invoke_resources_region_delete(resource_type, region, resource_id):
|
def invoke_resources_region_delete(resource_type, region, resource_id):
|
||||||
logger.debug("REGION STATUS PROXY - send delete status to {} service for "
|
logger.debug("REGION STATUS PROXY - delete {} resource with ID:{} for "
|
||||||
"region {}".format(resource_type, region))
|
"region {}".format(resource_type, resource_id, region))
|
||||||
|
|
||||||
_set_headers(region)
|
_set_headers(region)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if resource_type == "customer":
|
if resource_type == "customer":
|
||||||
logger.debug("sending the data to {} server delete "
|
delete_customer_region(resource_id, region)
|
||||||
"method ".format(resource_type))
|
|
||||||
response = requests.delete(
|
|
||||||
conf.cms.base_url + (conf.cms.delete_region).format(
|
|
||||||
resource_id, region),
|
|
||||||
headers=headers, verify=conf.verify)
|
|
||||||
elif resource_type == "group":
|
elif resource_type == "group":
|
||||||
logger.debug("sending the data to {} server delete "
|
delete_group_region(resource_id, region)
|
||||||
"method ".format(resource_type))
|
|
||||||
response = requests.delete(
|
|
||||||
conf.cms.base_url + (conf.cms.delete_groups_region).format(
|
|
||||||
resource_id, region),
|
|
||||||
headers=headers, verify=conf.verify)
|
|
||||||
elif resource_type == "flavor":
|
elif resource_type == "flavor":
|
||||||
logger.debug("sending the data to {} server delete "
|
delete_flavor_region(resource_id, region)
|
||||||
"method ".format(resource_type))
|
|
||||||
response = requests.delete(
|
|
||||||
conf.fms.base_url + (conf.fms.delete_region).format(
|
|
||||||
resource_id, region),
|
|
||||||
headers=headers, verify=conf.verify)
|
|
||||||
elif resource_type == "image":
|
elif resource_type == "image":
|
||||||
logger.debug("sending the data to {} server delete "
|
delete_image_region(resource_id, region)
|
||||||
"method ".format(resource_type))
|
|
||||||
response = requests.delete(
|
|
||||||
conf.ims.base_url + (conf.ims.delete_region).format(
|
|
||||||
resource_id, region),
|
|
||||||
headers=headers, verify=conf.verify)
|
|
||||||
else:
|
|
||||||
response = None
|
|
||||||
|
|
||||||
logger.debug("got response {} from send delete status to {} service.".
|
except Exception as exp:
|
||||||
format(response, resource_type))
|
|
||||||
except requests.ConnectionError as exp:
|
|
||||||
logger.error(exp)
|
logger.error(exp)
|
||||||
logger.exception(exp)
|
logger.exception(exp)
|
||||||
raise ErrorMessage("fail to connect to server {}".format(exp.message))
|
|
||||||
|
|
||||||
if response.status_code != 200:
|
|
||||||
raise ErrorMessage(
|
raise ErrorMessage(
|
||||||
"Got error from rds server, code: {0} message: {1}".format(
|
"Fail to delete {} resource {}".format(resource_type, str(exp)))
|
||||||
response.status_code, response.content))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def delete_customer_region(customer_id, region_id):
|
||||||
|
datamanager = CmsDataManager()
|
||||||
|
try:
|
||||||
|
customer_region = datamanager.get_record('customer_region')
|
||||||
|
customer_region.delete_region_for_customer(customer_id, region_id)
|
||||||
|
datamanager.flush()
|
||||||
|
datamanager.commit()
|
||||||
|
except Exception as exp:
|
||||||
|
logger.error("RDS CMS resource - Failed to delete region")
|
||||||
|
logger.exception(exp)
|
||||||
|
datamanager.rollback()
|
||||||
|
raise exp
|
||||||
|
finally:
|
||||||
|
datamanager.close()
|
||||||
|
|
||||||
|
|
||||||
|
def delete_group_region(group_uuid, region_name):
|
||||||
|
datamanager = CmsDataManager()
|
||||||
|
try:
|
||||||
|
group_region = datamanager.get_record('groups_region')
|
||||||
|
group_region.delete_region_for_group(group_uuid, region_name)
|
||||||
|
datamanager.flush()
|
||||||
|
datamanager.commit()
|
||||||
|
except Exception as exp:
|
||||||
|
logger.error("RDS Group resource - Failed to delete region")
|
||||||
|
logger.exception(exp)
|
||||||
|
datamanager.rollback()
|
||||||
|
raise exp
|
||||||
|
finally:
|
||||||
|
datamanager.close()
|
||||||
|
|
||||||
|
|
||||||
|
def delete_flavor_region(flavor_uuid, region_name):
|
||||||
|
datamanager = FmsDataManager()
|
||||||
|
try:
|
||||||
|
flavor_rec = datamanager.get_record('flavor')
|
||||||
|
sql_flavor = flavor_rec.get_flavor_by_id(flavor_uuid)
|
||||||
|
|
||||||
|
if sql_flavor is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
sql_flavor.remove_region(region_name)
|
||||||
|
datamanager.flush()
|
||||||
|
datamanager.commit()
|
||||||
|
except Exception as exp:
|
||||||
|
logger.error("RDS FMS resource - Failed to delete region")
|
||||||
|
logger.exception(exp)
|
||||||
|
datamanager.rollback()
|
||||||
|
raise exp
|
||||||
|
finally:
|
||||||
|
datamanager.close()
|
||||||
|
|
||||||
|
|
||||||
|
def delete_image_region(image_uuid, region_name):
|
||||||
|
datamanager = ImsDataManager()
|
||||||
|
try:
|
||||||
|
image_rec = datamanager.get_record('image')
|
||||||
|
sql_image = image_rec.get_image_by_id(image_uuid)
|
||||||
|
|
||||||
|
if sql_image is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
sql_image.remove_region(region_name)
|
||||||
|
datamanager.flush()
|
||||||
|
datamanager.commit()
|
||||||
|
except Exception as exp:
|
||||||
|
logger.error("RDS IMS resource - Failed to delete region")
|
||||||
|
logger.exception(exp)
|
||||||
|
datamanager.rollback()
|
||||||
|
raise exp
|
||||||
|
finally:
|
||||||
|
datamanager.close()
|
||||||
|
|
||||||
|
|
||||||
def send_image_metadata(meta_data, region, resource_id, action='post'):
|
def send_image_metadata(meta_data, region, resource_id, action='post'):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"IMS PROXY - send metadata to ims {} for region {}".format(meta_data,
|
"IMS PROXY - send metadata to ims {} for region {}".format(meta_data,
|
||||||
|
@ -356,14 +356,14 @@ class TestCustomerLogic(FunctionalTest):
|
|||||||
|
|
||||||
def test_delete_regions_success(self):
|
def test_delete_regions_success(self):
|
||||||
logic = customer_logic.CustomerLogic()
|
logic = customer_logic.CustomerLogic()
|
||||||
logic.delete_region('customer_id', 'region_id', 'transaction_is', True, False)
|
logic.delete_region('customer_id', 'region_id', 'transaction_is', False)
|
||||||
|
|
||||||
assert record_mock.delete_region_for_customer.called
|
assert record_mock.delete_region_for_customer.called
|
||||||
assert data_manager_mock.commit.called
|
assert data_manager_mock.rollback.called
|
||||||
|
|
||||||
def test_delete_regions_success_force_delete(self):
|
def test_delete_regions_success_force_delete(self):
|
||||||
logic = customer_logic.CustomerLogic()
|
logic = customer_logic.CustomerLogic()
|
||||||
logic.delete_region('customer_id', 'region_id', 'transaction_is', True, True)
|
logic.delete_region('customer_id', 'region_id', 'transaction_is', True)
|
||||||
|
|
||||||
assert record_mock.delete_region_for_customer.called
|
assert record_mock.delete_region_for_customer.called
|
||||||
assert data_manager_mock.commit.called
|
assert data_manager_mock.commit.called
|
||||||
@ -375,7 +375,7 @@ class TestCustomerLogic(FunctionalTest):
|
|||||||
logic = customer_logic.CustomerLogic()
|
logic = customer_logic.CustomerLogic()
|
||||||
|
|
||||||
self.assertRaises(SystemError, logic.delete_region, 'customer_id',
|
self.assertRaises(SystemError, logic.delete_region, 'customer_id',
|
||||||
'region_id', 'transaction_is', True, False)
|
'region_id', 'transaction_is', False)
|
||||||
assert data_manager_mock.rollback.called
|
assert data_manager_mock.rollback.called
|
||||||
|
|
||||||
def test_get_customer_list_by_criteria(self):
|
def test_get_customer_list_by_criteria(self):
|
||||||
|
@ -82,16 +82,14 @@ class TestGroupLogic(FunctionalTest):
|
|||||||
|
|
||||||
def test_delete_region_success(self):
|
def test_delete_region_success(self):
|
||||||
logic = group_logic.GroupLogic()
|
logic = group_logic.GroupLogic()
|
||||||
logic.delete_region('group_id', 'region_id', 'transaction_is', True,
|
logic.delete_region('group_id', 'region_id', 'transaction_is', False)
|
||||||
False)
|
|
||||||
|
|
||||||
assert record_mock.delete_region_for_group.called
|
assert record_mock.delete_region_for_group.called
|
||||||
assert data_manager_mock.commit.called
|
assert data_manager_mock.rollback.called
|
||||||
|
|
||||||
def test_delete_region_success_force_delete(self):
|
def test_delete_region_success_force_delete(self):
|
||||||
logic = group_logic.GroupLogic()
|
logic = group_logic.GroupLogic()
|
||||||
logic.delete_region('group_id', 'region_id', 'transaction_is', True,
|
logic.delete_region('group_id', 'region_id', 'transaction_is', True)
|
||||||
True)
|
|
||||||
|
|
||||||
assert record_mock.delete_region_for_group.called
|
assert record_mock.delete_region_for_group.called
|
||||||
assert data_manager_mock.commit.called
|
assert data_manager_mock.commit.called
|
||||||
@ -103,7 +101,7 @@ class TestGroupLogic(FunctionalTest):
|
|||||||
logic = group_logic.GroupLogic()
|
logic = group_logic.GroupLogic()
|
||||||
|
|
||||||
self.assertRaises(SystemError, logic.delete_region, 'group_id',
|
self.assertRaises(SystemError, logic.delete_region, 'group_id',
|
||||||
'region_id', 'transaction_is', True, False)
|
'region_id', 'transaction_is', False)
|
||||||
assert data_manager_mock.rollback.called
|
assert data_manager_mock.rollback.called
|
||||||
|
|
||||||
def test_get_group_list_by_criteria(self):
|
def test_get_group_list_by_criteria(self):
|
||||||
|
@ -464,7 +464,7 @@ class TestFlavorLogic(FunctionalTest):
|
|||||||
('rds_proxy', get_rds_proxy_mock()))
|
('rds_proxy', get_rds_proxy_mock()))
|
||||||
|
|
||||||
res_regions = flavor_logic.delete_region('uuid', RegionWrapper(
|
res_regions = flavor_logic.delete_region('uuid', RegionWrapper(
|
||||||
[Region(name='test_region')]), 'transaction', True, False)
|
[Region(name='test_region')]), 'transaction', False)
|
||||||
|
|
||||||
@patch.object(flavor_logic, 'send_to_rds_if_needed')
|
@patch.object(flavor_logic, 'send_to_rds_if_needed')
|
||||||
@patch.object(flavor_logic, 'get_flavor_by_uuid')
|
@patch.object(flavor_logic, 'get_flavor_by_uuid')
|
||||||
@ -478,13 +478,13 @@ class TestFlavorLogic(FunctionalTest):
|
|||||||
injector.override_injected_dependency(
|
injector.override_injected_dependency(
|
||||||
('data_manager', get_datamanager_mock))
|
('data_manager', get_datamanager_mock))
|
||||||
self.assertRaises(flavor_logic.ErrorStatus, flavor_logic.delete_region,
|
self.assertRaises(flavor_logic.ErrorStatus, flavor_logic.delete_region,
|
||||||
'uuid', 'test_region', 'transaction', False, False)
|
'uuid', 'test_region', 'transaction', False)
|
||||||
|
|
||||||
error = 2
|
error = 2
|
||||||
injector.override_injected_dependency(
|
injector.override_injected_dependency(
|
||||||
('data_manager', get_datamanager_mock))
|
('data_manager', get_datamanager_mock))
|
||||||
self.assertRaises(SystemError, flavor_logic.delete_region,
|
self.assertRaises(SystemError, flavor_logic.delete_region,
|
||||||
'uuid', 'test_region', 'transaction', False, False)
|
'uuid', 'test_region', 'transaction', False)
|
||||||
|
|
||||||
@patch.object(flavor_logic, 'send_to_rds_if_needed')
|
@patch.object(flavor_logic, 'send_to_rds_if_needed')
|
||||||
@patch.object(flavor_logic, 'get_flavor_by_uuid')
|
@patch.object(flavor_logic, 'get_flavor_by_uuid')
|
||||||
|
@ -484,7 +484,7 @@ class TestDeleteRegion(FunctionalTest):
|
|||||||
rds_proxy, mock_data_manager = get_data_manager_mock()
|
rds_proxy, mock_data_manager = get_data_manager_mock()
|
||||||
mock_di.resolver.unpack.return_value = mock_data_manager
|
mock_di.resolver.unpack.return_value = mock_data_manager
|
||||||
result = image_logic.delete_region('uuid', mock.MagicMock(),
|
result = image_logic.delete_region('uuid', mock.MagicMock(),
|
||||||
'transaction', True, False)
|
'transaction', False)
|
||||||
|
|
||||||
@mock.patch.object(image_logic, 'send_to_rds_if_needed', return_value=True)
|
@mock.patch.object(image_logic, 'send_to_rds_if_needed', return_value=True)
|
||||||
@mock.patch.object(image_logic, 'di')
|
@mock.patch.object(image_logic, 'di')
|
||||||
@ -492,7 +492,7 @@ class TestDeleteRegion(FunctionalTest):
|
|||||||
rds_proxy, mock_data_manager = get_data_manager_mock()
|
rds_proxy, mock_data_manager = get_data_manager_mock()
|
||||||
mock_di.resolver.unpack.return_value = mock_data_manager
|
mock_di.resolver.unpack.return_value = mock_data_manager
|
||||||
result = image_logic.delete_region('uuid', mock.MagicMock(),
|
result = image_logic.delete_region('uuid', mock.MagicMock(),
|
||||||
'transaction', False, True)
|
'transaction', True)
|
||||||
|
|
||||||
@mock.patch.object(image_logic, 'send_to_rds_if_needed', return_value=True)
|
@mock.patch.object(image_logic, 'send_to_rds_if_needed', return_value=True)
|
||||||
@mock.patch.object(image_logic, 'di')
|
@mock.patch.object(image_logic, 'di')
|
||||||
@ -502,7 +502,7 @@ class TestDeleteRegion(FunctionalTest):
|
|||||||
mock_sql_image=None)
|
mock_sql_image=None)
|
||||||
mock_di.resolver.unpack.return_value = mock_data_manager
|
mock_di.resolver.unpack.return_value = mock_data_manager
|
||||||
self.assertRaises(image_logic.ErrorStatus, image_logic.delete_region,
|
self.assertRaises(image_logic.ErrorStatus, image_logic.delete_region,
|
||||||
'uuid', mock.MagicMock(), 'transaction', False, False)
|
'uuid', mock.MagicMock(), 'transaction', False)
|
||||||
|
|
||||||
@mock.patch.object(image_logic, 'send_to_rds_if_needed', return_value=True)
|
@mock.patch.object(image_logic, 'send_to_rds_if_needed', return_value=True)
|
||||||
@mock.patch.object(image_logic, 'di')
|
@mock.patch.object(image_logic, 'di')
|
||||||
@ -511,7 +511,7 @@ class TestDeleteRegion(FunctionalTest):
|
|||||||
rds_proxy, mock_data_manager = get_data_manager_mock(protected=True)
|
rds_proxy, mock_data_manager = get_data_manager_mock(protected=True)
|
||||||
mock_di.resolver.unpack.return_value = mock_data_manager
|
mock_di.resolver.unpack.return_value = mock_data_manager
|
||||||
self.assertRaises(image_logic.ErrorStatus, image_logic.delete_region,
|
self.assertRaises(image_logic.ErrorStatus, image_logic.delete_region,
|
||||||
'uuid', mock.MagicMock(), 'transaction', False, False)
|
'uuid', mock.MagicMock(), 'transaction', False)
|
||||||
|
|
||||||
@mock.patch.object(image_logic, 'get_image_by_uuid',
|
@mock.patch.object(image_logic, 'get_image_by_uuid',
|
||||||
side_effect=ValueError('test'))
|
side_effect=ValueError('test'))
|
||||||
@ -524,7 +524,7 @@ class TestDeleteRegion(FunctionalTest):
|
|||||||
rds_proxy, mock_data_manager = get_data_manager_mock()
|
rds_proxy, mock_data_manager = get_data_manager_mock()
|
||||||
mock_di.resolver.unpack.return_value = mock_data_manager
|
mock_di.resolver.unpack.return_value = mock_data_manager
|
||||||
self.assertRaises(ValueError, image_logic.delete_region,
|
self.assertRaises(ValueError, image_logic.delete_region,
|
||||||
'uuid', mock.MagicMock(), 'transaction', False, False)
|
'uuid', mock.MagicMock(), 'transaction', False)
|
||||||
|
|
||||||
|
|
||||||
class TestAddCustomers(FunctionalTest):
|
class TestAddCustomers(FunctionalTest):
|
||||||
|
Loading…
Reference in New Issue
Block a user