diff --git a/src/common/exceptions/ServiceException.py b/src/common/exceptions/ServiceException.py index 476650b039b90c9cef318015664cf72509df4b58..864e44e2345dcc53ae54fb9dcc35ea1efd5cdd52 100644 --- a/src/common/exceptions/ServiceException.py +++ b/src/common/exceptions/ServiceException.py @@ -4,4 +4,4 @@ class ServiceException(Exception): def __init__(self, code : grpc.StatusCode, details : str) -> None: self.code = code self.details = details - super().__init__() + super().__init__(self.details) diff --git a/src/common/tests/Assertions.py b/src/common/tests/Assertions.py index 8417a42345c8b9acf9a7e76e4ea9c2e7add03a89..c7b87a671f88ab65768525c73dcf2b34361b579f 100644 --- a/src/common/tests/Assertions.py +++ b/src/common/tests/Assertions.py @@ -113,6 +113,14 @@ def validate_topology_has_links(message): validate_topology(message) assert len(message['link']) > 0 +def validate_constraint(message): + assert type(message) is dict + assert len(message.keys()) == 2 + assert 'constraint_type' in message + assert type(message['constraint_type']) is str + assert 'constraint_value' in message + assert type(message['constraint_value']) is str + def validate_service_id(message): assert type(message) is dict assert len(message.keys()) == 2 @@ -121,10 +129,43 @@ def validate_service_id(message): assert 'cs_id' in message validate_uuid(message['cs_id']) +def validate_service_config(message): + assert type(message) is dict + assert len(message.keys()) == 1 + assert 'serviceConfig' in message + assert type(message['serviceConfig']) is str + +def validate_service_type(message): + assert type(message) is str + assert message in ['UNKNOWN', 'L3NM', 'L2NM', 'TAPI_CONNECTIVITY_SERVICE'] + +def validate_service_state_enum(message): + assert type(message) is str + assert message in ['PLANNED', 'ACTIVE', 'PENDING_REMOVAL'] + +def validate_service_state(message): + assert type(message) is dict + assert len(message.keys()) == 1 + assert 'serviceState' in message + validate_service_state_enum(message['serviceState']) + def validate_service(message): assert type(message) is dict - assert len(message.keys()) > 1 + assert len(message.keys()) == 6 assert 'cs_id' in message + validate_service_id(message['cs_id']) + assert 'serviceType' in message + validate_service_type(message['serviceType']) + assert 'endpointList' in message + assert type(message['endpointList']) is list + for endpoint_id in message['endpointList']: validate_endpoint_id(endpoint_id) + assert 'constraint' in message + assert type(message['constraint']) is list + for constraint in message['constraint']: validate_constraint(constraint) + assert 'serviceState' in message + validate_service_state(message['serviceState']) + assert 'serviceConfig' in message + validate_service_config(message['serviceConfig']) def validate_service_list(message): assert type(message) is dict diff --git a/src/common/tools/service/EndpointIdCheckers.py b/src/common/tools/service/EndpointIdCheckers.py index e36082c33abc2014e0f24eba1db7a8aaae72dddc..5ac0fe92dd458f38778d9a62011c4279b42ed918 100644 --- a/src/common/tools/service/EndpointIdCheckers.py +++ b/src/common/tools/service/EndpointIdCheckers.py @@ -7,10 +7,10 @@ from common.database.api.context.Constants import DEFAULT_CONTEXT_ID, DEFAULT_TO def check_endpoint_id( logger : logging.Logger, endpoint_number : int, parent_name : str, endpoint_id : 'EndpointId', add_topology_devices_endpoints : Dict[str, Dict[str, Set[str]]], - default_device_if_empty : Union[str, None] = None, predefined_context_id : str = DEFAULT_CONTEXT_ID, acceptable_context_ids : Set[str] = set([DEFAULT_CONTEXT_ID]), - predefined_topology_id : str = DEFAULT_TOPOLOGY_ID, acceptable_topology_ids : Set[str] = set([DEFAULT_TOPOLOGY_ID]) - ) -> Tuple[str, str, str]: + predefined_topology_id : str = DEFAULT_TOPOLOGY_ID, acceptable_topology_ids : Set[str] = set([DEFAULT_TOPOLOGY_ID]), + predefined_device_id : Union[str, None] = None, acceptable_device_ids : Set[str] = set(), + prevent_same_device_multiple_times : bool = True) -> Tuple[str, str, str]: try: ep_context_id = chk_string('endpoint_id[#{}].topoId.contextId.contextUuid.uuid'.format(endpoint_number), @@ -21,7 +21,7 @@ def check_endpoint_id( allow_empty=True) ep_device_id = chk_string('endpoint_id[#{}].dev_id.device_id.uuid'.format(endpoint_number), endpoint_id.dev_id.device_id.uuid, - allow_empty=(default_device_if_empty is not None)) + allow_empty=(predefined_device_id is not None)) ep_port_id = chk_string('endpoint_id[#{}].port_id.uuid'.format(endpoint_number), endpoint_id.port_id.uuid, allow_empty=False) @@ -30,33 +30,44 @@ def check_endpoint_id( raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, str(e)) if len(ep_context_id) == 0: - # Assumption: if no context is specified for an endpoint_id, use parent context + # Assumption: if no context is specified for an endpoint_id, use predefined context ep_context_id = predefined_context_id - elif ep_context_id not in acceptable_context_ids: + elif (len(acceptable_context_ids) > 0) and (ep_context_id not in acceptable_context_ids): # Assumption: parent and endpoints should belong to the same context msg = ' '.join([ 'Context({}) in {} mismatches acceptable Contexts({}).', 'Optionally, leave field empty to use predefined Context({}).', ]) - msg = msg.format(ep_context_id, parent_name, str(acceptable_context_ids), predefined_context_id) + msg = msg.format( + ep_context_id, parent_name, str(acceptable_context_ids), predefined_context_id) raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, msg) if len(ep_topology_id) == 0: - # Assumption: if no topology is specified for an endpoint_id, use parent topology + # Assumption: if no topology is specified for an endpoint_id, use predefined topology ep_topology_id = predefined_topology_id - elif ep_topology_id not in acceptable_topology_ids: + elif (len(acceptable_topology_ids) > 0) and (ep_topology_id not in acceptable_topology_ids): msg = ' '.join([ - 'Topology({}) in {} mismatches acceptable Topologies({}).', + 'Context({})/Topology({}) in {} mismatches acceptable Topologies({}).', 'Optionally, leave field empty to use predefined Topology({}).', ]) - msg = msg.format(ep_topology_id, parent_name, str(acceptable_topology_ids), predefined_topology_id) + msg = msg.format( + ep_context_id, ep_topology_id, parent_name, str(acceptable_topology_ids), predefined_topology_id) raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, msg) - if (len(ep_device_id) == 0) and (default_device_if_empty is not None): - ep_device_id = default_device_if_empty + if (predefined_device_id is not None) and (len(ep_device_id) == 0): + # Assumption: if no device is specified for an endpoint_id, use predefined device, if available + ep_device_id = predefined_device_id + elif (len(acceptable_device_ids) > 0) and (ep_device_id not in acceptable_device_ids): + msg = ' '.join([ + 'Context({})/Topology({})/Device({}) in {} mismatches acceptable Devices({}).', + 'Optionally, leave field empty to use predefined Device({}).', + ]) + msg = msg.format( + ep_context_id, ep_topology_id, ep_device_id, parent_name, str(acceptable_device_ids), predefined_device_id) + raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, msg) add_devices = add_topology_devices_endpoints.setdefault(ep_topology_id, dict()) - if ep_device_id in add_devices: + if prevent_same_device_multiple_times and (ep_device_id in add_devices): msg = 'Duplicated Context({})/Topology({})/Device({}) in {}.' msg = msg.format(ep_context_id, ep_topology_id, ep_device_id, parent_name) raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, msg) diff --git a/src/context/tests/test_unitary.py b/src/context/tests/test_unitary.py index 2ba65f3a0ef8090b7035b4fd3934b55fe2ac73a3..c82f62d202b96bcf9ec787e7124a6825bfbc33e1 100644 --- a/src/context/tests/test_unitary.py +++ b/src/context/tests/test_unitary.py @@ -140,7 +140,8 @@ def test_add_link_wrong_endpoint(context_client : ContextClient): context_client.AddLink(Link(**copy_link)) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT msg = ' '.join([ - 'Topology(wrong-topo) in Endpoint(#0) of Context(admin)/Topology(admin)/Link(DEV1/EP2 ==> DEV2/EP1)', + 'Context(admin)/Topology(wrong-topo)', + 'in Endpoint(#0) of Context(admin)/Topology(admin)/Link(DEV1/EP2 ==> DEV2/EP1)', 'mismatches acceptable Topologies({\'admin\'}).', 'Optionally, leave field empty to use predefined Topology(admin).', ]) diff --git a/src/device/service/DeviceServiceServicerImpl.py b/src/device/service/DeviceServiceServicerImpl.py index 19c5ef87de661b9d2265927b839895350b376b1e..84ff22b3cad32252160596a457ea8358bcad953b 100644 --- a/src/device/service/DeviceServiceServicerImpl.py +++ b/src/device/service/DeviceServiceServicerImpl.py @@ -84,39 +84,14 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): LOGGER.debug('ConfigureDevice request: {}'.format(str(request))) # ----- Validate request data and pre-conditions ----------------------------------------------------------- - try: - device_id = chk_string ('device.device_id.device_id.uuid', - request.device_id.device_id.uuid, - allow_empty=False) - device_type = chk_string ('device.device_type', - request.device_type, - allow_empty=True) - device_config = chk_string ('device.device_config.device_config', - request.device_config.device_config, - allow_empty=True) - device_opstat = chk_options('device.devOperationalStatus', - request.devOperationalStatus, - operationalstatus_enum_values()) - except Exception as e: - LOGGER.exception('Invalid arguments:') - raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, str(e)) - - device_opstat = to_operationalstatus_enum(device_opstat) - # should not happen because gRPC limits accepted values in enums - if device_opstat is None: # pragma: no cover - msg = 'Unsupported OperationalStatus({}).' # pragma: no cover - msg = msg.format(request.devOperationalStatus) # pragma: no cover - raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, msg) # pragma: no cover + device_id, device_type, device_config, device_opstat, db_endpoints_ports = \ + check_device_request('UpdateDevice', request, self.database, LOGGER) + # ----- Implement changes in the database ------------------------------------------------------------------ db_context = self.database.context(DEFAULT_CONTEXT_ID).create() db_topology = db_context.topology(DEFAULT_TOPOLOGY_ID).create() - - if not db_topology.devices.contains(device_id): - msg = 'Device({}) does not exist in the database.' - msg = msg.format(device_id) - raise ServiceException(grpc.StatusCode.NOT_FOUND, msg) - db_device = db_topology.device(device_id) + db_device_attributes = db_device.attributes.get(attributes=['device_type']) # should not happen, device creation through Database API ensures all fields are always present if len(db_device_attributes) == 0: # pragma: no cover @@ -136,7 +111,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): msg = msg.format(device_id, db_device_type, device_type) raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, msg) - if len(request.endpointList) > 0: + if len(db_endpoints_ports) > 0: msg = 'Endpoints belonging to Device({}) cannot be modified.' msg = msg.format(device_id) raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, msg) @@ -157,7 +132,6 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): msg = msg.format(device_id) raise ServiceException(grpc.StatusCode.ABORTED, msg) - # ----- Implement changes in the database ------------------------------------------------------------------ db_device.update(update_attributes=update_attributes) # ----- Compose reply -------------------------------------------------------------------------------------- diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py index c4837082a8c76826aad524b7aa6a9efa22691e6f..72751da82430dd6f94ba6bc2741a70e1dec25d43 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -15,12 +15,12 @@ from context.proto.context_pb2 import Device, DeviceId # For each method name, define acceptable device operational statuses. Empty set means accept all. ACCEPTED_DEVICE_OPERATIONAL_STATUSES : Dict[str, Set[OperationalStatus]] = { - 'CreateService': set([OperationalStatus.ENABLED, OperationalStatus.DISABLED]), - 'UpdateService': set([OperationalStatus.KEEP_STATE, OperationalStatus.ENABLED, OperationalStatus.DISABLED]), + 'AddDevice': set([OperationalStatus.ENABLED, OperationalStatus.DISABLED]), + 'UpdateDevice': set([OperationalStatus.KEEP_STATE, OperationalStatus.ENABLED, OperationalStatus.DISABLED]), } def _check_device_exists(method_name : str, database : Database, device_id : str): - if method_name in ['CreateDevice']: + if method_name in ['AddDevice']: check_device_not_exists(database, DEFAULT_CONTEXT_ID, DEFAULT_TOPOLOGY_ID, device_id) elif method_name in ['UpdateDevice', 'DeleteDevice']: check_device_exists(database, DEFAULT_CONTEXT_ID, DEFAULT_TOPOLOGY_ID, device_id) @@ -29,6 +29,22 @@ def _check_device_exists(method_name : str, database : Database, device_id : str msg = msg.format(str(method_name), str(device_id)) raise ServiceException(grpc.StatusCode.UNIMPLEMENTED, msg) +def _check_device_endpoint_exists_or_get_pointer( + method_name : str, database : Database, parent_name : str, device_id : str, endpoint_id : str): + + if method_name in ['AddDevice']: + db_context = database.context(DEFAULT_CONTEXT_ID) + db_topology = db_context.topology(DEFAULT_TOPOLOGY_ID) + db_device = db_topology.device(device_id) + return db_device.endpoint(endpoint_id) + elif method_name in ['UpdateDevice', 'DeleteDevice']: + return check_device_endpoint_exists( + database, parent_name, DEFAULT_CONTEXT_ID, DEFAULT_TOPOLOGY_ID, device_id, endpoint_id) + else: # pragma: no cover (test requires malforming the code) + msg = 'Unexpected condition [_check_device_exists(method_name={}, device_id={})]' + msg = msg.format(str(method_name), str(device_id)) + raise ServiceException(grpc.StatusCode.UNIMPLEMENTED, msg) + def check_device_operational_status(method_name : str, value : str) -> OperationalStatus: return check_enum( 'OperationalStatus', method_name, value, to_operationalstatus_enum, ACCEPTED_DEVICE_OPERATIONAL_STATUSES) @@ -69,7 +85,8 @@ def check_device_request( _, ep_device_id, ep_port_id = check_endpoint_id( logger, endpoint_number, parent_name, endpoint.port_id, add_topology_devices_endpoints, - default_device_if_empty=device_id) + predefined_device_id=device_id, acceptable_device_ids=set([device_id]), + prevent_same_device_multiple_times=False) try: ep_port_type = chk_string('endpoint[#{}].port_type'.format(endpoint_number), @@ -79,8 +96,8 @@ def check_device_request( logger.exception('Invalid arguments:') raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, str(e)) - db_endpoint = check_device_endpoint_exists( - database, parent_name, DEFAULT_CONTEXT_ID, DEFAULT_TOPOLOGY_ID, ep_device_id, ep_port_id) + db_endpoint = _check_device_endpoint_exists_or_get_pointer( + method_name, database, parent_name, ep_device_id, ep_port_id) db_endpoints__port_types.append((db_endpoint, ep_port_type)) return device_id, device_type, device_config, device_opstat, db_endpoints__port_types diff --git a/src/device/tests/test_unitary.py b/src/device/tests/test_unitary.py index fcabea92850b41e08d83b5e660c256ec1d1c30b5..773da58bcbb18b2c6a91416a365fa5bf18a98c04 100644 --- a/src/device/tests/test_unitary.py +++ b/src/device/tests/test_unitary.py @@ -73,7 +73,7 @@ def device_client(device_service): yield _client _client.close() -def test_add_device_empty_device_uuid(device_client : DeviceClient): +def test_add_device_wrong_attributes(device_client : DeviceClient): # should fail with device uuid is empty with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) @@ -82,7 +82,6 @@ def test_add_device_empty_device_uuid(device_client : DeviceClient): assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == 'device.device_id.device_id.uuid() string is empty.' -def test_add_device_empty_device_type(device_client : DeviceClient): # should fail with device type is empty with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) @@ -91,7 +90,6 @@ def test_add_device_empty_device_type(device_client : DeviceClient): assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == 'device.device_type() string is empty.' -def test_add_device_wrong_device_operational_status(device_client : DeviceClient): # should fail with wrong device operational status with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) @@ -99,13 +97,13 @@ def test_add_device_wrong_device_operational_status(device_client : DeviceClient device_client.AddDevice(Device(**copy_device)) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT msg = ' '.join([ - 'Device has to be created with either ENABLED/DISABLED Operational State.', - 'Use KEEP_STATE only in configure Device methods.', + 'Method(AddDevice) does not accept OperationalStatus(KEEP_STATE).', + 'Permitted values for Method(AddDevice) are OperationalStatus([\'DISABLED\', \'ENABLED\']).', ]) assert e.value.details() == msg -def test_add_device_endpoint_wrong_context(device_client : DeviceClient): - # should fail with unsupported context +def test_add_device_wrong_endpoint(device_client : DeviceClient): + # should fail with unsupported endpoint context with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) copy_device['endpointList'][0]['port_id']['topoId']['contextId']['contextUuid']['uuid'] = 'wrong-context' @@ -113,27 +111,25 @@ def test_add_device_endpoint_wrong_context(device_client : DeviceClient): device_client.AddDevice(request) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT msg = ' '.join([ - 'Unsupported Context(wrong-context) in Endpoint(#0) of Device(DEV1).', - 'Only default Context(admin) is currently supported.', - 'Optionally, leave field empty to use default Context.', + 'Context(wrong-context)', + 'in Endpoint(#0) of Context(admin)/Topology(admin)/Device(DEV1) mismatches acceptable Contexts({\'admin\'}).', + 'Optionally, leave field empty to use predefined Context(admin).', ]) assert e.value.details() == msg -def test_add_device_endpoint_wrong_topology(device_client : DeviceClient): - # should fail with unsupported topology + # should fail with unsupported endpoint topology with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) copy_device['endpointList'][0]['port_id']['topoId']['topoId']['uuid'] = 'wrong-topo' device_client.AddDevice(Device(**copy_device)) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT msg = ' '.join([ - 'Unsupported Topology(wrong-topo) in Endpoint(#0) of Device(DEV1).', - 'Only default Topology(admin) is currently supported.', - 'Optionally, leave field empty to use default Topology.', + 'Context(admin)/Topology(wrong-topo)', + 'in Endpoint(#0) of Context(admin)/Topology(admin)/Device(DEV1) mismatches acceptable Topologies({\'admin\'}).', + 'Optionally, leave field empty to use predefined Topology(admin).', ]) assert e.value.details() == msg -def test_add_device_endpoint_wrong_device(device_client : DeviceClient): # should fail with wrong endpoint device with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) @@ -141,23 +137,21 @@ def test_add_device_endpoint_wrong_device(device_client : DeviceClient): device_client.AddDevice(Device(**copy_device)) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT msg = ' '.join([ - 'Wrong Device(wrong-device) in Endpoint(#0).', - 'Parent specified in message is Device(DEV1).', - 'Optionally, leave field empty to use parent Device.', + 'Context(admin)/Topology(admin)/Device(wrong-device)', + 'in Endpoint(#0) of Context(admin)/Topology(admin)/Device(DEV1) mismatches acceptable Devices({\'DEV1\'}).', + 'Optionally, leave field empty to use predefined Device(DEV1).', ]) assert e.value.details() == msg -def test_add_device_empty_port_uuid(device_client : DeviceClient): - # should fail with port uuid is empty + # should fail with endpoint port uuid is empty with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) copy_device['endpointList'][0]['port_id']['port_id']['uuid'] = '' device_client.AddDevice(Device(**copy_device)) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT - assert e.value.details() == 'endpoint[#0].port_id.port_id.uuid() string is empty.' + assert e.value.details() == 'endpoint_id[#0].port_id.uuid() string is empty.' -def test_add_device_empty_port_type(device_client : DeviceClient): - # should fail with port type is empty + # should fail with endpoint port type is empty with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) copy_device['endpointList'][0]['port_type'] = '' @@ -165,14 +159,17 @@ def test_add_device_empty_port_type(device_client : DeviceClient): assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == 'endpoint[#0].port_type() string is empty.' -def test_add_device_duplicate_port(device_client : DeviceClient): - # should fail with uplicate port in device + # should fail with duplicate port in device with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) copy_device['endpointList'][1]['port_id']['port_id']['uuid'] = 'EP2' device_client.AddDevice(Device(**copy_device)) - assert e.value.code() == grpc.StatusCode.ALREADY_EXISTS - assert e.value.details() == 'Duplicated Port(EP2) in Endpoint(#1) of Device(DEV1).' + assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT + msg = ' '.join([ + 'Duplicated Context(admin)/Topology(admin)/Device(DEV1)/Port(EP2)', + 'in Endpoint(#1) of Context(admin)/Topology(admin)/Device(DEV1).', + ]) + assert e.value.details() == msg def test_add_device(device_client : DeviceClient): # should work @@ -186,7 +183,7 @@ def test_add_device_duplicate(device_client : DeviceClient): with pytest.raises(grpc._channel._InactiveRpcError) as e: device_client.AddDevice(Device(**DEVICE)) assert e.value.code() == grpc.StatusCode.ALREADY_EXISTS - assert e.value.details() == 'Device(DEV1) already exists in the database.' + assert e.value.details() == 'Context(admin)/Topology(admin)/Device(DEV1) already exists in the database.' def test_delete_device_empty_uuid(device_client : DeviceClient): # should fail with device uuid is empty @@ -204,7 +201,7 @@ def test_delete_device_not_found(device_client : DeviceClient): copy_device_id['device_id']['uuid'] = 'wrong-device-id' device_client.DeleteDevice(DeviceId(**copy_device_id)) assert e.value.code() == grpc.StatusCode.NOT_FOUND - assert e.value.details() == 'Device(wrong-device-id) does not exist in the database.' + assert e.value.details() == 'Context(admin)/Topology(admin)/Device(wrong-device-id) does not exist in the database.' def test_delete_device(device_client : DeviceClient): # should work @@ -229,7 +226,7 @@ def test_configure_device_not_found(device_client : DeviceClient): copy_device['device_id']['device_id']['uuid'] = 'wrong-device-id' device_client.ConfigureDevice(Device(**copy_device)) assert e.value.code() == grpc.StatusCode.NOT_FOUND - assert e.value.details() == 'Device(wrong-device-id) does not exist in the database.' + assert e.value.details() == 'Context(admin)/Topology(admin)/Device(wrong-device-id) does not exist in the database.' def test_add_device_default_endpoint_context_topology_device(device_client : DeviceClient): # should work @@ -242,7 +239,7 @@ def test_add_device_default_endpoint_context_topology_device(device_client : Dev including_default_value_fields=True, preserving_proto_field_name=True, use_integers_for_enums=False)) -def test_configure_device_wrong_device_type(device_client : DeviceClient): +def test_configure_device_wrong_attributes(device_client : DeviceClient): # should fail with device type is wrong with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) @@ -251,7 +248,6 @@ def test_configure_device_wrong_device_type(device_client : DeviceClient): assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == 'Device(DEV1) has Type(ROADM) in the database. Cannot be changed to Type(wrong-type).' -def test_configure_device_with_endpoints(device_client : DeviceClient): # should fail with endpoints cannot be modified with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) @@ -259,7 +255,6 @@ def test_configure_device_with_endpoints(device_client : DeviceClient): assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == 'Endpoints belonging to Device(DEV1) cannot be modified.' -def test_configure_device_no_change(device_client : DeviceClient): # should fail with any change detected with pytest.raises(grpc._channel._InactiveRpcError) as e: copy_device = copy.deepcopy(DEVICE) diff --git a/src/service/tests/test_unitary.py b/src/service/tests/test_unitary.py index 50c2653c2ac3ba5162d566dd4ea46d0f73206578..800de71dac6e6ad9072d081c849095361ed1ffb1 100644 --- a/src/service/tests/test_unitary.py +++ b/src/service/tests/test_unitary.py @@ -176,7 +176,7 @@ def test_create_service_wrong_endpoint(service_client : ServiceClient): service_client.CreateService(Service(**copy_service)) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT msg = ' '.join([ - 'Topology(wrong-topo) in Endpoint(#0) of Context(admin)/Service(DEV1)', + 'Context(admin)/Topology(wrong-topo) in Endpoint(#0) of Context(admin)/Service(DEV1)', 'mismatches acceptable Topologies({\'admin\'}).', 'Optionally, leave field empty to use predefined Topology(admin).', ])