Skip to content
Snippets Groups Projects
Commit 5cc92a6f authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'feat/device-monitoring' into 'develop'

Final arrangements in Device monitoring

See merge request teraflow-h2020/controller!49
parents 492e852b f3e8ac33
No related branches found
No related tags found
1 merge request!54Release 2.0.0
Showing
with 255 additions and 267 deletions
import logging import logging
from typing import Dict from typing import Dict, List
from common.orm.Database import Database
from common.orm.backend.Tools import key_to_str
from common.orm.fields.EnumeratedField import EnumeratedField
from common.orm.fields.ForeignKeyField import ForeignKeyField from common.orm.fields.ForeignKeyField import ForeignKeyField
from common.orm.fields.PrimaryKeyField import PrimaryKeyField from common.orm.fields.PrimaryKeyField import PrimaryKeyField
from common.orm.fields.StringField import StringField from common.orm.fields.StringField import StringField
from common.orm.model.Model import Model from common.orm.model.Model import Model
from .DeviceModel import DeviceModel from .DeviceModel import DeviceModel
from .KpiSampleType import ORM_KpiSampleTypeEnum, grpc_to_enum__kpi_sample_type
from .TopologyModel import TopologyModel from .TopologyModel import TopologyModel
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
...@@ -26,8 +30,34 @@ class EndPointModel(Model): ...@@ -26,8 +30,34 @@ class EndPointModel(Model):
result['topology_id'] = TopologyModel(self.database, self.topology_fk).dump_id() result['topology_id'] = TopologyModel(self.database, self.topology_fk).dump_id()
return result return result
def dump(self) -> Dict: def dump_kpi_sample_types(self) -> List[int]:
return { db_kpi_sample_type_pks = self.references(KpiSampleTypeModel)
return [KpiSampleTypeModel(self.database, pk).dump() for pk,_ in db_kpi_sample_type_pks]
def dump( # pylint: disable=arguments-differ
self, include_kpi_sample_types=True
) -> Dict:
result = {
'endpoint_id': self.dump_id(), 'endpoint_id': self.dump_id(),
'endpoint_type': self.endpoint_type, 'endpoint_type': self.endpoint_type,
} }
if include_kpi_sample_types: result['kpi_sample_types'] = self.dump_kpi_sample_types()
return result
class KpiSampleTypeModel(Model): # pylint: disable=abstract-method
pk = PrimaryKeyField()
endpoint_fk = ForeignKeyField(EndPointModel)
kpi_sample_type = EnumeratedField(ORM_KpiSampleTypeEnum, required=True)
def dump(self) -> Dict:
return self.kpi_sample_type.value
def set_kpi_sample_types(database : Database, db_endpoint : EndPointModel, grpc_endpoint_kpi_sample_types):
db_endpoint_pk = db_endpoint.pk
for kpi_sample_type in grpc_endpoint_kpi_sample_types:
orm_kpi_sample_type = grpc_to_enum__kpi_sample_type(kpi_sample_type)
str_endpoint_kpi_sample_type_key = key_to_str([db_endpoint_pk, orm_kpi_sample_type.name])
db_endpoint_kpi_sample_type = KpiSampleTypeModel(database, str_endpoint_kpi_sample_type_key)
db_endpoint_kpi_sample_type.endpoint_fk = db_endpoint
db_endpoint_kpi_sample_type.kpi_sample_type = orm_kpi_sample_type
db_endpoint_kpi_sample_type.save()
import functools
from enum import Enum
from context.proto.kpi_sample_types_pb2 import KpiSampleType
from .Tools import grpc_to_enum
class ORM_KpiSampleTypeEnum(Enum):
UNKNOWN = KpiSampleType.KPISAMPLETYPE_UNKNOWN
PACKETS_TRANSMITTED = KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED
PACKETS_RECEIVED = KpiSampleType.KPISAMPLETYPE_PACKETS_RECEIVED
BYTES_TRANSMITTED = KpiSampleType.KPISAMPLETYPE_BYTES_TRANSMITTED
BYTES_RECEIVED = KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED
grpc_to_enum__kpi_sample_type = functools.partial(
grpc_to_enum, KpiSampleType, ORM_KpiSampleTypeEnum)
...@@ -17,7 +17,7 @@ from context.service.database.ConstraintModel import ConstraintModel, Constraint ...@@ -17,7 +17,7 @@ from context.service.database.ConstraintModel import ConstraintModel, Constraint
from context.service.database.ContextModel import ContextModel from context.service.database.ContextModel import ContextModel
from context.service.database.DeviceModel import ( from context.service.database.DeviceModel import (
DeviceModel, DriverModel, grpc_to_enum__device_operational_status, set_drivers) DeviceModel, DriverModel, grpc_to_enum__device_operational_status, set_drivers)
from context.service.database.EndPointModel import EndPointModel from context.service.database.EndPointModel import EndPointModel, KpiSampleTypeModel, set_kpi_sample_types
from context.service.database.Events import notify_event from context.service.database.Events import notify_event
from context.service.database.LinkModel import LinkModel from context.service.database.LinkModel import LinkModel
from context.service.database.RelationModels import ( from context.service.database.RelationModels import (
...@@ -279,7 +279,9 @@ class ContextServiceServicerImpl(ContextServiceServicer): ...@@ -279,7 +279,9 @@ class ContextServiceServicerImpl(ContextServiceServicer):
result : Tuple[EndPointModel, bool] = update_or_create_object( result : Tuple[EndPointModel, bool] = update_or_create_object(
self.database, EndPointModel, str_endpoint_key, endpoint_attributes) self.database, EndPointModel, str_endpoint_key, endpoint_attributes)
#db_endpoint, updated = result db_endpoint, endpoint_updated = result
set_kpi_sample_types(self.database, db_endpoint, endpoint.kpi_sample_types)
event_type = EventTypeEnum.EVENTTYPE_UPDATE if updated else EventTypeEnum.EVENTTYPE_CREATE event_type = EventTypeEnum.EVENTTYPE_UPDATE if updated else EventTypeEnum.EVENTTYPE_CREATE
dict_device_id = db_device.dump_id() dict_device_id = db_device.dump_id()
...@@ -296,7 +298,10 @@ class ContextServiceServicerImpl(ContextServiceServicer): ...@@ -296,7 +298,10 @@ class ContextServiceServicerImpl(ContextServiceServicer):
dict_device_id = db_device.dump_id() dict_device_id = db_device.dump_id()
for db_endpoint_pk,_ in db_device.references(EndPointModel): for db_endpoint_pk,_ in db_device.references(EndPointModel):
EndPointModel(self.database, db_endpoint_pk).delete() db_endpoint = EndPointModel(self.database, db_endpoint_pk)
for db_kpi_sample_type_pk,_ in db_endpoint.references(KpiSampleTypeModel):
KpiSampleTypeModel(self.database, db_kpi_sample_type_pk).delete()
db_endpoint.delete()
for db_topology_device_pk,_ in db_device.references(TopologyDeviceModel): for db_topology_device_pk,_ in db_device.references(TopologyDeviceModel):
TopologyDeviceModel(self.database, db_topology_device_pk).delete() TopologyDeviceModel(self.database, db_topology_device_pk).delete()
......
import json
from copy import deepcopy
from typing import Any, Dict, Union
from context.proto.context_pb2 import ConfigActionEnum
def config_rule(action : ConfigActionEnum, resource_key : str, resource_value : Union[str, Dict[str, Any]]):
if not isinstance(resource_value, str): resource_value = json.dumps(resource_value, sort_keys=True)
return {'action': action, 'resource_key': resource_key, 'resource_value': resource_value}
def config_rule_set(resource_key : str, resource_value : Union[str, Dict[str, Any]]):
return config_rule(ConfigActionEnum.CONFIGACTION_SET, resource_key, resource_value)
def config_rule_delete(resource_key : str, resource_value : Union[str, Dict[str, Any]]):
return config_rule(ConfigActionEnum.CONFIGACTION_DELETE, resource_key, resource_value)
def endpoint_id(device_id, endpoint_uuid, topology_id=None):
result = {'device_id': deepcopy(device_id), 'endpoint_uuid': {'uuid': endpoint_uuid}}
if topology_id is not None: result['topology_id'] = deepcopy(topology_id)
return result
def endpoint(device_id, endpoint_uuid, endpoint_type, topology_id=None, kpi_sample_types=[]):
result = {
'endpoint_id': endpoint_id(device_id, endpoint_uuid, topology_id=topology_id),
'endpoint_type': endpoint_type,
}
if len(kpi_sample_types) > 0: result['kpi_sample_types'] = deepcopy(kpi_sample_types)
return result
from copy import deepcopy from copy import deepcopy
from common.Constants import DEFAULT_CONTEXT_UUID, DEFAULT_TOPOLOGY_UUID from common.Constants import DEFAULT_CONTEXT_UUID, DEFAULT_TOPOLOGY_UUID
from context.proto.context_pb2 import ( from context.proto.context_pb2 import (
ConfigActionEnum, DeviceDriverEnum, DeviceOperationalStatusEnum, ServiceStatusEnum, ServiceTypeEnum) DeviceDriverEnum, DeviceOperationalStatusEnum, ServiceStatusEnum, ServiceTypeEnum)
from context.proto.kpi_sample_types_pb2 import KpiSampleType
from .Tools import config_rule_set, endpoint, endpoint_id
# Some example objects to be used by the tests # Some example objects to be used by the tests
# Helper methods
def config_rule(action, resource_key, resource_value):
return {'action': action, 'resource_key': resource_key, 'resource_value': resource_value}
def endpoint_id(topology_id, device_id, endpoint_uuid):
return {'topology_id': deepcopy(topology_id), 'device_id': deepcopy(device_id),
'endpoint_uuid': {'uuid': endpoint_uuid}}
def endpoint(topology_id, device_id, endpoint_uuid, endpoint_type):
return {'endpoint_id': endpoint_id(topology_id, device_id, endpoint_uuid), 'endpoint_type': endpoint_type}
## use "deepcopy" to prevent propagating forced changes during tests ## use "deepcopy" to prevent propagating forced changes during tests
CONTEXT_ID = {'context_uuid': {'uuid': DEFAULT_CONTEXT_UUID}} CONTEXT_ID = {'context_uuid': {'uuid': DEFAULT_CONTEXT_UUID}}
CONTEXT = { CONTEXT = {
...@@ -34,22 +25,36 @@ TOPOLOGY = { ...@@ -34,22 +25,36 @@ TOPOLOGY = {
'link_ids': [], 'link_ids': [],
} }
PACKET_PORT_SAMPLE_TYPES = [
KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED,
KpiSampleType.KPISAMPLETYPE_PACKETS_RECEIVED,
KpiSampleType.KPISAMPLETYPE_BYTES_TRANSMITTED,
KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED,
]
def _endpoint_id(device_id, endpoint_uuid):
return endpoint_id(device_id, endpoint_uuid, topology_id=TOPOLOGY_ID)
def _endpoint(device_id, endpoint_uuid, endpoint_type):
return endpoint(
device_id, endpoint_uuid, endpoint_type, topology_id=TOPOLOGY_ID, kpi_sample_types=PACKET_PORT_SAMPLE_TYPES)
DEVICE1_UUID = 'DEV1' DEVICE1_UUID = 'DEV1'
DEVICE1_ID = {'device_uuid': {'uuid': DEVICE1_UUID}} DEVICE1_ID = {'device_uuid': {'uuid': DEVICE1_UUID}}
DEVICE1 = { DEVICE1 = {
'device_id': deepcopy(DEVICE1_ID), 'device_id': deepcopy(DEVICE1_ID),
'device_type': 'packet-router', 'device_type': 'packet-router',
'device_config': {'config_rules': [ 'device_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value1'), config_rule_set('dev/rsrc1/value', 'value1'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value2'), config_rule_set('dev/rsrc2/value', 'value2'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value3'), config_rule_set('dev/rsrc3/value', 'value3'),
]}, ]},
'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED, 'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED,
'device_drivers': [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG, DeviceDriverEnum.DEVICEDRIVER_P4], 'device_drivers': [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG, DeviceDriverEnum.DEVICEDRIVER_P4],
'device_endpoints': [ 'device_endpoints': [
endpoint(TOPOLOGY_ID, DEVICE1_ID, 'EP2', 'port-packet-100G'), _endpoint(DEVICE1_ID, 'EP2', 'port-packet-100G'),
endpoint(TOPOLOGY_ID, DEVICE1_ID, 'EP3', 'port-packet-100G'), _endpoint(DEVICE1_ID, 'EP3', 'port-packet-100G'),
endpoint(TOPOLOGY_ID, DEVICE1_ID, 'EP100', 'port-packet-10G'), _endpoint(DEVICE1_ID, 'EP100', 'port-packet-10G' ),
], ],
} }
...@@ -59,16 +64,16 @@ DEVICE2 = { ...@@ -59,16 +64,16 @@ DEVICE2 = {
'device_id': deepcopy(DEVICE2_ID), 'device_id': deepcopy(DEVICE2_ID),
'device_type': 'packet-router', 'device_type': 'packet-router',
'device_config': {'config_rules': [ 'device_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value4'), config_rule_set('dev/rsrc1/value', 'value4'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value5'), config_rule_set('dev/rsrc2/value', 'value5'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value6'), config_rule_set('dev/rsrc3/value', 'value6'),
]}, ]},
'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED, 'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED,
'device_drivers': [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG, DeviceDriverEnum.DEVICEDRIVER_P4], 'device_drivers': [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG, DeviceDriverEnum.DEVICEDRIVER_P4],
'device_endpoints': [ 'device_endpoints': [
endpoint(TOPOLOGY_ID, DEVICE2_ID, 'EP1', 'port-packet-100G'), _endpoint(DEVICE2_ID, 'EP1', 'port-packet-100G'),
endpoint(TOPOLOGY_ID, DEVICE2_ID, 'EP3', 'port-packet-100G'), _endpoint(DEVICE2_ID, 'EP3', 'port-packet-100G'),
endpoint(TOPOLOGY_ID, DEVICE2_ID, 'EP100', 'port-packet-10G'), _endpoint(DEVICE2_ID, 'EP100', 'port-packet-10G' ),
], ],
} }
...@@ -78,16 +83,16 @@ DEVICE3 = { ...@@ -78,16 +83,16 @@ DEVICE3 = {
'device_id': deepcopy(DEVICE3_ID), 'device_id': deepcopy(DEVICE3_ID),
'device_type': 'packet-router', 'device_type': 'packet-router',
'device_config': {'config_rules': [ 'device_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value4'), config_rule_set('dev/rsrc1/value', 'value4'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value5'), config_rule_set('dev/rsrc2/value', 'value5'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value6'), config_rule_set('dev/rsrc3/value', 'value6'),
]}, ]},
'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED, 'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED,
'device_drivers': [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG, DeviceDriverEnum.DEVICEDRIVER_P4], 'device_drivers': [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG, DeviceDriverEnum.DEVICEDRIVER_P4],
'device_endpoints': [ 'device_endpoints': [
endpoint(TOPOLOGY_ID, DEVICE3_ID, 'EP1', 'port-packet-100G'), _endpoint(DEVICE3_ID, 'EP1', 'port-packet-100G'),
endpoint(TOPOLOGY_ID, DEVICE3_ID, 'EP2', 'port-packet-100G'), _endpoint(DEVICE3_ID, 'EP2', 'port-packet-100G'),
endpoint(TOPOLOGY_ID, DEVICE3_ID, 'EP100', 'port-packet-10G'), _endpoint(DEVICE3_ID, 'EP100', 'port-packet-10G' ),
], ],
} }
...@@ -96,8 +101,8 @@ LINK_DEV1_DEV2_ID = {'link_uuid': {'uuid': LINK_DEV1_DEV2_UUID}} ...@@ -96,8 +101,8 @@ LINK_DEV1_DEV2_ID = {'link_uuid': {'uuid': LINK_DEV1_DEV2_UUID}}
LINK_DEV1_DEV2 = { LINK_DEV1_DEV2 = {
'link_id': deepcopy(LINK_DEV1_DEV2_ID), 'link_id': deepcopy(LINK_DEV1_DEV2_ID),
'link_endpoint_ids' : [ 'link_endpoint_ids' : [
endpoint_id(TOPOLOGY_ID, DEVICE1_ID, 'EP2'), _endpoint_id(DEVICE1_ID, 'EP2'),
endpoint_id(TOPOLOGY_ID, DEVICE2_ID, 'EP1'), _endpoint_id(DEVICE2_ID, 'EP1'),
] ]
} }
...@@ -106,8 +111,8 @@ LINK_DEV2_DEV3_ID = {'link_uuid': {'uuid': LINK_DEV2_DEV3_UUID}} ...@@ -106,8 +111,8 @@ LINK_DEV2_DEV3_ID = {'link_uuid': {'uuid': LINK_DEV2_DEV3_UUID}}
LINK_DEV2_DEV3 = { LINK_DEV2_DEV3 = {
'link_id': deepcopy(LINK_DEV2_DEV3_ID), 'link_id': deepcopy(LINK_DEV2_DEV3_ID),
'link_endpoint_ids' : [ 'link_endpoint_ids' : [
endpoint_id(TOPOLOGY_ID, DEVICE2_ID, 'EP3'), _endpoint_id(DEVICE2_ID, 'EP3'),
endpoint_id(TOPOLOGY_ID, DEVICE3_ID, 'EP2'), _endpoint_id(DEVICE3_ID, 'EP2'),
] ]
} }
...@@ -116,8 +121,8 @@ LINK_DEV1_DEV3_ID = {'link_uuid': {'uuid': LINK_DEV1_DEV3_UUID}} ...@@ -116,8 +121,8 @@ LINK_DEV1_DEV3_ID = {'link_uuid': {'uuid': LINK_DEV1_DEV3_UUID}}
LINK_DEV1_DEV3 = { LINK_DEV1_DEV3 = {
'link_id': deepcopy(LINK_DEV1_DEV3_ID), 'link_id': deepcopy(LINK_DEV1_DEV3_ID),
'link_endpoint_ids' : [ 'link_endpoint_ids' : [
endpoint_id(TOPOLOGY_ID, DEVICE1_ID, 'EP3'), _endpoint_id(DEVICE1_ID, 'EP3'),
endpoint_id(TOPOLOGY_ID, DEVICE3_ID, 'EP1'), _endpoint_id(DEVICE3_ID, 'EP1'),
] ]
} }
...@@ -130,8 +135,8 @@ SERVICE_DEV1_DEV2 = { ...@@ -130,8 +135,8 @@ SERVICE_DEV1_DEV2 = {
'service_id': deepcopy(SERVICE_DEV1_DEV2_ID), 'service_id': deepcopy(SERVICE_DEV1_DEV2_ID),
'service_type': ServiceTypeEnum.SERVICETYPE_L3NM, 'service_type': ServiceTypeEnum.SERVICETYPE_L3NM,
'service_endpoint_ids' : [ 'service_endpoint_ids' : [
endpoint_id(TOPOLOGY_ID, DEVICE1_ID, 'EP100'), _endpoint_id(DEVICE1_ID, 'EP100'),
endpoint_id(TOPOLOGY_ID, DEVICE2_ID, 'EP100'), _endpoint_id(DEVICE2_ID, 'EP100'),
], ],
'service_constraints': [ 'service_constraints': [
{'constraint_type': 'latency_ms', 'constraint_value': '15.2'}, {'constraint_type': 'latency_ms', 'constraint_value': '15.2'},
...@@ -139,9 +144,9 @@ SERVICE_DEV1_DEV2 = { ...@@ -139,9 +144,9 @@ SERVICE_DEV1_DEV2 = {
], ],
'service_status': {'service_status': ServiceStatusEnum.SERVICESTATUS_ACTIVE}, 'service_status': {'service_status': ServiceStatusEnum.SERVICESTATUS_ACTIVE},
'service_config': {'config_rules': [ 'service_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc1/value', 'value7'), config_rule_set('svc/rsrc1/value', 'value7'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc2/value', 'value8'), config_rule_set('svc/rsrc2/value', 'value8'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc3/value', 'value9'), config_rule_set('svc/rsrc3/value', 'value9'),
]}, ]},
} }
...@@ -154,8 +159,8 @@ SERVICE_DEV1_DEV3 = { ...@@ -154,8 +159,8 @@ SERVICE_DEV1_DEV3 = {
'service_id': deepcopy(SERVICE_DEV1_DEV3_ID), 'service_id': deepcopy(SERVICE_DEV1_DEV3_ID),
'service_type': ServiceTypeEnum.SERVICETYPE_L3NM, 'service_type': ServiceTypeEnum.SERVICETYPE_L3NM,
'service_endpoint_ids' : [ 'service_endpoint_ids' : [
endpoint_id(TOPOLOGY_ID, DEVICE1_ID, 'EP100'), _endpoint_id(DEVICE1_ID, 'EP100'),
endpoint_id(TOPOLOGY_ID, DEVICE3_ID, 'EP100'), _endpoint_id(DEVICE3_ID, 'EP100'),
], ],
'service_constraints': [ 'service_constraints': [
{'constraint_type': 'latency_ms', 'constraint_value': '5.8'}, {'constraint_type': 'latency_ms', 'constraint_value': '5.8'},
...@@ -163,9 +168,9 @@ SERVICE_DEV1_DEV3 = { ...@@ -163,9 +168,9 @@ SERVICE_DEV1_DEV3 = {
], ],
'service_status': {'service_status': ServiceStatusEnum.SERVICESTATUS_ACTIVE}, 'service_status': {'service_status': ServiceStatusEnum.SERVICESTATUS_ACTIVE},
'service_config': {'config_rules': [ 'service_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc1/value', 'value7'), config_rule_set('svc/rsrc1/value', 'value7'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc2/value', 'value8'), config_rule_set('svc/rsrc2/value', 'value8'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc3/value', 'value9'), config_rule_set('svc/rsrc3/value', 'value9'),
]}, ]},
} }
...@@ -178,8 +183,8 @@ SERVICE_DEV2_DEV3 = { ...@@ -178,8 +183,8 @@ SERVICE_DEV2_DEV3 = {
'service_id': deepcopy(SERVICE_DEV2_DEV3_ID), 'service_id': deepcopy(SERVICE_DEV2_DEV3_ID),
'service_type': ServiceTypeEnum.SERVICETYPE_L3NM, 'service_type': ServiceTypeEnum.SERVICETYPE_L3NM,
'service_endpoint_ids' : [ 'service_endpoint_ids' : [
endpoint_id(TOPOLOGY_ID, DEVICE2_ID, 'EP100'), _endpoint_id(DEVICE2_ID, 'EP100'),
endpoint_id(TOPOLOGY_ID, DEVICE3_ID, 'EP100'), _endpoint_id(DEVICE3_ID, 'EP100'),
], ],
'service_constraints': [ 'service_constraints': [
{'constraint_type': 'latency_ms', 'constraint_value': '23.1'}, {'constraint_type': 'latency_ms', 'constraint_value': '23.1'},
...@@ -187,8 +192,8 @@ SERVICE_DEV2_DEV3 = { ...@@ -187,8 +192,8 @@ SERVICE_DEV2_DEV3 = {
], ],
'service_status': {'service_status': ServiceStatusEnum.SERVICESTATUS_ACTIVE}, 'service_status': {'service_status': ServiceStatusEnum.SERVICESTATUS_ACTIVE},
'service_config': {'config_rules': [ 'service_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc1/value', 'value7'), config_rule_set('svc/rsrc1/value', 'value7'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc2/value', 'value8'), config_rule_set('svc/rsrc2/value', 'value8'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc3/value', 'value9'), config_rule_set('svc/rsrc3/value', 'value9'),
]}, ]},
} }
...@@ -484,7 +484,7 @@ def test_grpc_device( ...@@ -484,7 +484,7 @@ def test_grpc_device(
for db_entry in db_entries: for db_entry in db_entries:
LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover
LOGGER.info('-----------------------------------------------------------') LOGGER.info('-----------------------------------------------------------')
assert len(db_entries) == 25 assert len(db_entries) == 41
# ----- Get when the object exists --------------------------------------------------------------------------------- # ----- Get when the object exists ---------------------------------------------------------------------------------
response = context_client_grpc.GetDevice(DeviceId(**DEVICE1_ID)) response = context_client_grpc.GetDevice(DeviceId(**DEVICE1_ID))
...@@ -537,7 +537,7 @@ def test_grpc_device( ...@@ -537,7 +537,7 @@ def test_grpc_device(
for db_entry in db_entries: for db_entry in db_entries:
LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover
LOGGER.info('-----------------------------------------------------------') LOGGER.info('-----------------------------------------------------------')
assert len(db_entries) == 25 assert len(db_entries) == 41
# ----- Remove the object ------------------------------------------------------------------------------------------ # ----- Remove the object ------------------------------------------------------------------------------------------
context_client_grpc.RemoveDevice(DeviceId(**DEVICE1_ID)) context_client_grpc.RemoveDevice(DeviceId(**DEVICE1_ID))
...@@ -639,7 +639,7 @@ def test_grpc_link( ...@@ -639,7 +639,7 @@ def test_grpc_link(
for db_entry in db_entries: for db_entry in db_entries:
LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover
LOGGER.info('-----------------------------------------------------------') LOGGER.info('-----------------------------------------------------------')
assert len(db_entries) == 38 assert len(db_entries) == 69
# ----- Create the object ------------------------------------------------------------------------------------------ # ----- Create the object ------------------------------------------------------------------------------------------
response = context_client_grpc.SetLink(Link(**LINK_DEV1_DEV2)) response = context_client_grpc.SetLink(Link(**LINK_DEV1_DEV2))
...@@ -667,7 +667,7 @@ def test_grpc_link( ...@@ -667,7 +667,7 @@ def test_grpc_link(
for db_entry in db_entries: for db_entry in db_entries:
LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover
LOGGER.info('-----------------------------------------------------------') LOGGER.info('-----------------------------------------------------------')
assert len(db_entries) == 48 assert len(db_entries) == 77
# ----- Get when the object exists --------------------------------------------------------------------------------- # ----- Get when the object exists ---------------------------------------------------------------------------------
response = context_client_grpc.GetLink(LinkId(**LINK_DEV1_DEV2_ID)) response = context_client_grpc.GetLink(LinkId(**LINK_DEV1_DEV2_ID))
...@@ -713,7 +713,7 @@ def test_grpc_link( ...@@ -713,7 +713,7 @@ def test_grpc_link(
for db_entry in db_entries: for db_entry in db_entries:
LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover
LOGGER.info('-----------------------------------------------------------') LOGGER.info('-----------------------------------------------------------')
assert len(db_entries) == 48 assert len(db_entries) == 77
# ----- Remove the object ------------------------------------------------------------------------------------------ # ----- Remove the object ------------------------------------------------------------------------------------------
context_client_grpc.RemoveLink(LinkId(**LINK_DEV1_DEV2_ID)) context_client_grpc.RemoveLink(LinkId(**LINK_DEV1_DEV2_ID))
...@@ -827,7 +827,7 @@ def test_grpc_service( ...@@ -827,7 +827,7 @@ def test_grpc_service(
for db_entry in db_entries: for db_entry in db_entries:
LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover
LOGGER.info('-----------------------------------------------------------') LOGGER.info('-----------------------------------------------------------')
assert len(db_entries) == 38 assert len(db_entries) == 69
# ----- Create the object ------------------------------------------------------------------------------------------ # ----- Create the object ------------------------------------------------------------------------------------------
with pytest.raises(grpc.RpcError) as e: with pytest.raises(grpc.RpcError) as e:
...@@ -879,7 +879,7 @@ def test_grpc_service( ...@@ -879,7 +879,7 @@ def test_grpc_service(
for db_entry in db_entries: for db_entry in db_entries:
LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover LOGGER.info(' [{:>4s}] {:40s} :: {:s}'.format(*db_entry)) # pragma: no cover
LOGGER.info('-----------------------------------------------------------') LOGGER.info('-----------------------------------------------------------')
assert len(db_entries) == 57 assert len(db_entries) == 86
# ----- Get when the object exists --------------------------------------------------------------------------------- # ----- Get when the object exists ---------------------------------------------------------------------------------
response = context_client_grpc.GetService(ServiceId(**SERVICE_DEV1_DEV2_ID)) response = context_client_grpc.GetService(ServiceId(**SERVICE_DEV1_DEV2_ID))
......
...@@ -39,7 +39,7 @@ unit test device: ...@@ -39,7 +39,7 @@ unit test device:
- docker run --name $IMAGE_NAME -d -p 2020:2020 --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - docker run --name $IMAGE_NAME -d -p 2020:2020 --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG
- sleep 5 - sleep 5
- docker ps -a - docker ps -a
- docker exec -i $IMAGE_NAME bash -c "pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary_driverapi.py $IMAGE_NAME/tests/test_unitary.py" - docker exec -i $IMAGE_NAME bash -c "pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py"
after_script: after_script:
- docker rm -f $IMAGE_NAME - docker rm -f $IMAGE_NAME
- docker network rm teraflowbridge - docker network rm teraflowbridge
......
...@@ -21,7 +21,7 @@ from .database.DatabaseTools import ( ...@@ -21,7 +21,7 @@ from .database.DatabaseTools import (
from .database.DeviceModel import DeviceModel, DriverModel from .database.DeviceModel import DeviceModel, DriverModel
from .database.EndPointModel import EndPointModel, EndPointMonitorModel from .database.EndPointModel import EndPointModel, EndPointMonitorModel
from .database.KpiModel import KpiModel from .database.KpiModel import KpiModel
from .database.KpiSampleType import ORM_KpiSampleType, grpc_to_enum__kpi_sample_type from .database.KpiSampleType import ORM_KpiSampleTypeEnum, grpc_to_enum__kpi_sample_type
from .driver_api._Driver import _Driver, RESOURCE_ENDPOINTS #, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES from .driver_api._Driver import _Driver, RESOURCE_ENDPOINTS #, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES
from .driver_api.DriverInstanceCache import DriverInstanceCache from .driver_api.DriverInstanceCache import DriverInstanceCache
from .driver_api.Tools import ( from .driver_api.Tools import (
...@@ -352,7 +352,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): ...@@ -352,7 +352,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
endpoint_uuid = db_endpoint.endpoint_uuid endpoint_uuid = db_endpoint.endpoint_uuid
str_endpoint_key = db_endpoint.pk str_endpoint_key = db_endpoint.pk
kpi_sample_type : ORM_KpiSampleType = db_kpi.kpi_sample_type kpi_sample_type : ORM_KpiSampleTypeEnum = db_kpi.kpi_sample_type
sample_type = kpi_sample_type.value sample_type = kpi_sample_type.value
str_endpoint_monitor_key = key_to_str([str_endpoint_key, str(sample_type)]) str_endpoint_monitor_key = key_to_str([str_endpoint_key, str(sample_type)])
db_endpoint_monitor : EndPointMonitorModel = get_object( db_endpoint_monitor : EndPointMonitorModel = get_object(
......
import grpc, logging
from typing import Dict, List, Set, Tuple
from common.Checkers import chk_options, chk_string
from common.database.api.Database import Database
from common.database.api.context.Constants import DEFAULT_CONTEXT_ID, DEFAULT_TOPOLOGY_ID
from common.database.api.context.topology.device.Endpoint import Endpoint
from common.database.api.context.topology.device.OperationalStatus import OperationalStatus, \
operationalstatus_enum_values, to_operationalstatus_enum
from common.exceptions.ServiceException import ServiceException
from common.tools.service.DeviceCheckers import check_device_endpoint_exists
from common.tools.service.EndpointIdCheckers import check_endpoint_id
from common.tools.service.EnumCheckers import check_enum
from common.tools.service.DeviceCheckers import check_device_exists, check_device_not_exists
from device.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]] = {
'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 ['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)
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_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)
def check_device_request(
method_name : str, request : Device, database : Database, logger : logging.Logger
) -> Tuple[str, str, str, OperationalStatus, List[Tuple[Endpoint, str]]]:
# ----- Parse attributes -------------------------------------------------------------------------------------------
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=False)
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 = check_device_operational_status(method_name, device_opstat)
# ----- Check if device exists in database -------------------------------------------------------------------------
_check_device_exists(method_name, database, device_id)
# ----- Parse endpoints and check if they exist in the database as device endpoints --------------------------------
add_topology_devices_endpoints : Dict[str, Dict[str, Set[str]]] = {}
db_endpoints__port_types : List[Tuple[Endpoint, str]] = []
for endpoint_number,endpoint in enumerate(request.endpointList):
parent_name = 'Endpoint(#{}) of Context({})/Topology({})/Device({})'
parent_name = parent_name.format(endpoint_number, DEFAULT_CONTEXT_ID, DEFAULT_TOPOLOGY_ID, device_id)
_, ep_device_id, ep_port_id = check_endpoint_id(
logger, endpoint_number, parent_name, endpoint.port_id, add_topology_devices_endpoints,
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),
endpoint.port_type,
allow_empty=False)
except Exception as e:
logger.exception('Invalid arguments:')
raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, str(e))
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
def check_device_id_request(
method_name : str, request : DeviceId, database : Database, logger : logging.Logger) -> str:
# ----- Parse attributes -------------------------------------------------------------------------------------------
try:
device_id = chk_string('device_id.device_id.uuid',
request.device_id.uuid,
allow_empty=False)
except Exception as e:
logger.exception('Invalid arguments:')
raise ServiceException(grpc.StatusCode.INVALID_ARGUMENT, str(e))
# ----- Check if device exists in database ---------------------------------------------------------------------------
_check_device_exists(method_name, database, device_id)
return device_id
...@@ -10,7 +10,7 @@ from device.service.driver_api.FilterFields import FilterFieldEnum ...@@ -10,7 +10,7 @@ from device.service.driver_api.FilterFields import FilterFieldEnum
from .ConfigModel import delete_all_config_rules, grpc_config_rules_to_raw, update_config from .ConfigModel import delete_all_config_rules, grpc_config_rules_to_raw, update_config
from .ContextModel import ContextModel from .ContextModel import ContextModel
from .DeviceModel import DeviceModel, DriverModel, grpc_to_enum__device_operational_status, set_drivers from .DeviceModel import DeviceModel, DriverModel, grpc_to_enum__device_operational_status, set_drivers
from .EndPointModel import EndPointModel from .EndPointModel import EndPointModel, set_endpoint_monitors
from .TopologyModel import TopologyModel from .TopologyModel import TopologyModel
def update_device_in_local_database(database : Database, device : Device) -> Tuple[DeviceModel, bool]: def update_device_in_local_database(database : Database, device : Device) -> Tuple[DeviceModel, bool]:
...@@ -74,7 +74,10 @@ def update_device_in_local_database(database : Database, device : Device) -> Tup ...@@ -74,7 +74,10 @@ def update_device_in_local_database(database : Database, device : Device) -> Tup
result : Tuple[EndPointModel, bool] = update_or_create_object( result : Tuple[EndPointModel, bool] = update_or_create_object(
database, EndPointModel, str_endpoint_key, endpoint_attributes) database, EndPointModel, str_endpoint_key, endpoint_attributes)
_, db_endpoint_updated = result db_endpoint, db_endpoint_updated = result
set_endpoint_monitors(database, db_endpoint, endpoint.kpi_sample_types)
updated = updated or db_endpoint_updated updated = updated or db_endpoint_updated
return db_device, updated return db_device, updated
......
import logging import logging
from typing import Dict from typing import Dict, List
from common.orm.Database import Database
from common.orm.backend.Tools import key_to_str
from common.orm.fields.EnumeratedField import EnumeratedField from common.orm.fields.EnumeratedField import EnumeratedField
from common.orm.fields.ForeignKeyField import ForeignKeyField from common.orm.fields.ForeignKeyField import ForeignKeyField
from common.orm.fields.PrimaryKeyField import PrimaryKeyField from common.orm.fields.PrimaryKeyField import PrimaryKeyField
from common.orm.fields.StringField import StringField from common.orm.fields.StringField import StringField
from common.orm.model.Model import Model from common.orm.model.Model import Model
from .DeviceModel import DeviceModel from .DeviceModel import DeviceModel
from .KpiSampleType import ORM_KpiSampleType from .KpiSampleType import ORM_KpiSampleTypeEnum, grpc_to_enum__kpi_sample_type
from .TopologyModel import TopologyModel from .TopologyModel import TopologyModel
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
...@@ -29,14 +31,36 @@ class EndPointModel(Model): ...@@ -29,14 +31,36 @@ class EndPointModel(Model):
result['topology_id'] = TopologyModel(self.database, self.topology_fk).dump_id() result['topology_id'] = TopologyModel(self.database, self.topology_fk).dump_id()
return result return result
def dump(self) -> Dict: def dump_kpi_sample_types(self) -> List[int]:
return { db_kpi_sample_type_pks = self.references(EndPointMonitorModel)
return [EndPointMonitorModel(self.database, pk).dump() for pk,_ in db_kpi_sample_type_pks]
def dump( # pylint: disable=arguments-differ
self, include_kpi_sample_types=True
) -> Dict:
result = {
'endpoint_id': self.dump_id(), 'endpoint_id': self.dump_id(),
'endpoint_type': self.endpoint_type, 'endpoint_type': self.endpoint_type,
} }
if include_kpi_sample_types: result['kpi_sample_types'] = self.dump_kpi_sample_types()
return result
class EndPointMonitorModel(Model): class EndPointMonitorModel(Model): # pylint: disable=abstract-method
pk = PrimaryKeyField() pk = PrimaryKeyField()
endpoint_fk = ForeignKeyField(EndPointModel) endpoint_fk = ForeignKeyField(EndPointModel)
resource_key = StringField(required=True, allow_empty=False) resource_key = StringField(required=True, allow_empty=True)
kpi_sample_type = EnumeratedField(ORM_KpiSampleType, required=True) kpi_sample_type = EnumeratedField(ORM_KpiSampleTypeEnum, required=True)
def dump(self) -> Dict:
return self.kpi_sample_type.value
def set_endpoint_monitors(database : Database, db_endpoint : EndPointModel, grpc_endpoint_kpi_sample_types):
db_endpoint_pk = db_endpoint.pk
for kpi_sample_type in grpc_endpoint_kpi_sample_types:
orm_kpi_sample_type = grpc_to_enum__kpi_sample_type(kpi_sample_type)
str_endpoint_kpi_sample_type_key = key_to_str([db_endpoint_pk, orm_kpi_sample_type.name])
db_endpoint_kpi_sample_type = EndPointMonitorModel(database, str_endpoint_kpi_sample_type_key)
db_endpoint_kpi_sample_type.endpoint_fk = db_endpoint
db_endpoint_kpi_sample_type.resource_key = '' # during initialization, allow empty value
db_endpoint_kpi_sample_type.kpi_sample_type = orm_kpi_sample_type
db_endpoint_kpi_sample_type.save()
...@@ -8,7 +8,7 @@ from common.orm.fields.StringField import StringField ...@@ -8,7 +8,7 @@ from common.orm.fields.StringField import StringField
from common.orm.model.Model import Model from common.orm.model.Model import Model
from .DeviceModel import DeviceModel from .DeviceModel import DeviceModel
from .EndPointModel import EndPointModel from .EndPointModel import EndPointModel
from .KpiSampleType import ORM_KpiSampleType from .KpiSampleType import ORM_KpiSampleTypeEnum
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
...@@ -16,7 +16,7 @@ class KpiModel(Model): ...@@ -16,7 +16,7 @@ class KpiModel(Model):
pk = PrimaryKeyField() pk = PrimaryKeyField()
kpi_uuid = StringField(required=True, allow_empty=False) kpi_uuid = StringField(required=True, allow_empty=False)
kpi_description = StringField(required=False, allow_empty=True) kpi_description = StringField(required=False, allow_empty=True)
kpi_sample_type = EnumeratedField(ORM_KpiSampleType, required=True) kpi_sample_type = EnumeratedField(ORM_KpiSampleTypeEnum, required=True)
device_fk = ForeignKeyField(DeviceModel) device_fk = ForeignKeyField(DeviceModel)
endpoint_fk = ForeignKeyField(EndPointModel) endpoint_fk = ForeignKeyField(EndPointModel)
sampling_duration = FloatField(min_value=0, required=True) sampling_duration = FloatField(min_value=0, required=True)
......
...@@ -3,7 +3,7 @@ from enum import Enum ...@@ -3,7 +3,7 @@ from enum import Enum
from device.proto.kpi_sample_types_pb2 import KpiSampleType from device.proto.kpi_sample_types_pb2 import KpiSampleType
from .Tools import grpc_to_enum from .Tools import grpc_to_enum
class ORM_KpiSampleType(Enum): class ORM_KpiSampleTypeEnum(Enum):
UNKNOWN = KpiSampleType.KPISAMPLETYPE_UNKNOWN UNKNOWN = KpiSampleType.KPISAMPLETYPE_UNKNOWN
PACKETS_TRANSMITTED = KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED PACKETS_TRANSMITTED = KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED
PACKETS_RECEIVED = KpiSampleType.KPISAMPLETYPE_PACKETS_RECEIVED PACKETS_RECEIVED = KpiSampleType.KPISAMPLETYPE_PACKETS_RECEIVED
...@@ -11,4 +11,4 @@ class ORM_KpiSampleType(Enum): ...@@ -11,4 +11,4 @@ class ORM_KpiSampleType(Enum):
BYTES_RECEIVED = KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED BYTES_RECEIVED = KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED
grpc_to_enum__kpi_sample_type = functools.partial( grpc_to_enum__kpi_sample_type = functools.partial(
grpc_to_enum, KpiSampleType, ORM_KpiSampleType) grpc_to_enum, KpiSampleType, ORM_KpiSampleTypeEnum)
...@@ -7,7 +7,7 @@ from apscheduler.job import Job ...@@ -7,7 +7,7 @@ from apscheduler.job import Job
from apscheduler.jobstores.memory import MemoryJobStore from apscheduler.jobstores.memory import MemoryJobStore
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from common.type_checkers.Checkers import chk_float, chk_length, chk_string, chk_type from common.type_checkers.Checkers import chk_float, chk_length, chk_string, chk_type
from device.service.database.KpiSampleType import ORM_KpiSampleType, grpc_to_enum__kpi_sample_type from device.service.database.KpiSampleType import ORM_KpiSampleTypeEnum, grpc_to_enum__kpi_sample_type
from device.service.driver_api._Driver import ( from device.service.driver_api._Driver import (
RESOURCE_ENDPOINTS, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES, RESOURCE_ENDPOINTS, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES,
_Driver) _Driver)
...@@ -35,7 +35,7 @@ def compose_resource_endpoint(endpoint_data : Dict[str, Any]) -> Tuple[str, Any] ...@@ -35,7 +35,7 @@ def compose_resource_endpoint(endpoint_data : Dict[str, Any]) -> Tuple[str, Any]
sample_types = {} sample_types = {}
for endpoint_sample_type in endpoint_sample_types: for endpoint_sample_type in endpoint_sample_types:
try: try:
kpi_sample_type : ORM_KpiSampleType = grpc_to_enum__kpi_sample_type(endpoint_sample_type) kpi_sample_type : ORM_KpiSampleTypeEnum = grpc_to_enum__kpi_sample_type(endpoint_sample_type)
except: # pylint: disable=bare-except except: # pylint: disable=bare-except
LOGGER.warning('Unknown EndpointSampleType({:s}) for Endpoint({:s}). Ignoring and continuing...'.format( LOGGER.warning('Unknown EndpointSampleType({:s}) for Endpoint({:s}). Ignoring and continuing...'.format(
str(endpoint_sample_type), str(endpoint_data))) str(endpoint_sample_type), str(endpoint_data)))
......
import logging, lxml.etree as ET import logging, lxml.etree as ET
from typing import Any, Dict, List, Tuple from typing import Any, Dict, List, Tuple
from device.service.database.KpiSampleType import ORM_KpiSampleType from device.service.database.KpiSampleType import ORM_KpiSampleTypeEnum
from .Namespace import NAMESPACES from .Namespace import NAMESPACES
from .Tools import add_value_from_collection, add_value_from_tag from .Tools import add_value_from_collection, add_value_from_tag
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
XPATH_PORTS = "//ocp:components/ocp:component/ocp:state[ocp:type='PORT']/.." XPATH_PORTS = "//ocp:components/ocp:component/ocp:state[ocp:type='PORT']/.."
XPATH_INTERFACE_COUNTER = "//oci:interfaces/oci:interface[oci:name='{:s}']/state/counters/{:s}" XPATH_IFACE_COUNTER = "//oci:interfaces/oci:interface[oci:name='{:s}']/state/counters/{:s}"
def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
response = [] response = []
...@@ -25,10 +25,10 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: ...@@ -25,10 +25,10 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
add_value_from_tag(endpoint, 'type', component_type) add_value_from_tag(endpoint, 'type', component_type)
sample_types = { sample_types = {
ORM_KpiSampleType.BYTES_RECEIVED.value : XPATH_INTERFACE_COUNTER.format(endpoint['uuid'], 'in-octets' ), ORM_KpiSampleTypeEnum.BYTES_RECEIVED.value : XPATH_IFACE_COUNTER.format(endpoint['uuid'], 'in-octets' ),
ORM_KpiSampleType.BYTES_TRANSMITTED.value : XPATH_INTERFACE_COUNTER.format(endpoint['uuid'], 'out-octets'), ORM_KpiSampleTypeEnum.BYTES_TRANSMITTED.value : XPATH_IFACE_COUNTER.format(endpoint['uuid'], 'out-octets'),
ORM_KpiSampleType.PACKETS_RECEIVED.value : XPATH_INTERFACE_COUNTER.format(endpoint['uuid'], 'in-pkts' ), ORM_KpiSampleTypeEnum.PACKETS_RECEIVED.value : XPATH_IFACE_COUNTER.format(endpoint['uuid'], 'in-pkts' ),
ORM_KpiSampleType.PACKETS_TRANSMITTED.value: XPATH_INTERFACE_COUNTER.format(endpoint['uuid'], 'out-pkts' ), ORM_KpiSampleTypeEnum.PACKETS_TRANSMITTED.value: XPATH_IFACE_COUNTER.format(endpoint['uuid'], 'out-pkts' ),
} }
add_value_from_collection(endpoint, 'sample_types', sample_types) add_value_from_collection(endpoint, 'sample_types', sample_types)
......
import operator import operator
from copy import deepcopy from copy import deepcopy
from device.proto.context_pb2 import DeviceDriverEnum, DeviceOperationalStatusEnum from device.proto.context_pb2 import DeviceDriverEnum, DeviceOperationalStatusEnum
from device.service.database.KpiSampleType import ORM_KpiSampleType from device.service.database.KpiSampleType import ORM_KpiSampleTypeEnum
from .Tools import config_rule_set, config_rule_delete from .Tools import config_rule_set, config_rule_delete
# use "deepcopy" to prevent propagating forced changes during tests # use "deepcopy" to prevent propagating forced changes during tests
...@@ -23,10 +23,10 @@ DEVICE_EMU = { ...@@ -23,10 +23,10 @@ DEVICE_EMU = {
} }
PACKET_PORT_SAMPLE_TYPES = [ PACKET_PORT_SAMPLE_TYPES = [
ORM_KpiSampleType.PACKETS_TRANSMITTED, ORM_KpiSampleTypeEnum.PACKETS_TRANSMITTED,
ORM_KpiSampleType.PACKETS_RECEIVED, ORM_KpiSampleTypeEnum.PACKETS_RECEIVED,
ORM_KpiSampleType.BYTES_TRANSMITTED, ORM_KpiSampleTypeEnum.BYTES_TRANSMITTED,
ORM_KpiSampleType.BYTES_RECEIVED, ORM_KpiSampleTypeEnum.BYTES_RECEIVED,
] ]
ENDPOINT_UUIDS = ['EP1', 'EP2', 'EP3', 'EP4'] ENDPOINT_UUIDS = ['EP1', 'EP2', 'EP3', 'EP4']
......
...@@ -20,7 +20,7 @@ DESCRIPTOR = _descriptor.FileDescriptor( ...@@ -20,7 +20,7 @@ DESCRIPTOR = _descriptor.FileDescriptor(
syntax='proto3', syntax='proto3',
serialized_options=None, serialized_options=None,
create_key=_descriptor._internal_create_key, create_key=_descriptor._internal_create_key,
serialized_pb=b'\n\x16kpi_sample_types.proto\x12\x10kpi_sample_types*x\n\rKpiSampleType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x17\n\x13PACKETS_TRANSMITTED\x10\x65\x12\x14\n\x10PACKETS_RECEIVED\x10\x66\x12\x16\n\x11\x42YTES_TRANSMITTED\x10\xc9\x01\x12\x13\n\x0e\x42YTES_RECEIVED\x10\xca\x01\x62\x06proto3' serialized_pb=b'\n\x16kpi_sample_types.proto\x12\x10kpi_sample_types*\xbe\x01\n\rKpiSampleType\x12\x19\n\x15KPISAMPLETYPE_UNKNOWN\x10\x00\x12%\n!KPISAMPLETYPE_PACKETS_TRANSMITTED\x10\x65\x12\"\n\x1eKPISAMPLETYPE_PACKETS_RECEIVED\x10\x66\x12$\n\x1fKPISAMPLETYPE_BYTES_TRANSMITTED\x10\xc9\x01\x12!\n\x1cKPISAMPLETYPE_BYTES_RECEIVED\x10\xca\x01\x62\x06proto3'
) )
_KPISAMPLETYPE = _descriptor.EnumDescriptor( _KPISAMPLETYPE = _descriptor.EnumDescriptor(
...@@ -31,44 +31,44 @@ _KPISAMPLETYPE = _descriptor.EnumDescriptor( ...@@ -31,44 +31,44 @@ _KPISAMPLETYPE = _descriptor.EnumDescriptor(
create_key=_descriptor._internal_create_key, create_key=_descriptor._internal_create_key,
values=[ values=[
_descriptor.EnumValueDescriptor( _descriptor.EnumValueDescriptor(
name='UNKNOWN', index=0, number=0, name='KPISAMPLETYPE_UNKNOWN', index=0, number=0,
serialized_options=None, serialized_options=None,
type=None, type=None,
create_key=_descriptor._internal_create_key), create_key=_descriptor._internal_create_key),
_descriptor.EnumValueDescriptor( _descriptor.EnumValueDescriptor(
name='PACKETS_TRANSMITTED', index=1, number=101, name='KPISAMPLETYPE_PACKETS_TRANSMITTED', index=1, number=101,
serialized_options=None, serialized_options=None,
type=None, type=None,
create_key=_descriptor._internal_create_key), create_key=_descriptor._internal_create_key),
_descriptor.EnumValueDescriptor( _descriptor.EnumValueDescriptor(
name='PACKETS_RECEIVED', index=2, number=102, name='KPISAMPLETYPE_PACKETS_RECEIVED', index=2, number=102,
serialized_options=None, serialized_options=None,
type=None, type=None,
create_key=_descriptor._internal_create_key), create_key=_descriptor._internal_create_key),
_descriptor.EnumValueDescriptor( _descriptor.EnumValueDescriptor(
name='BYTES_TRANSMITTED', index=3, number=201, name='KPISAMPLETYPE_BYTES_TRANSMITTED', index=3, number=201,
serialized_options=None, serialized_options=None,
type=None, type=None,
create_key=_descriptor._internal_create_key), create_key=_descriptor._internal_create_key),
_descriptor.EnumValueDescriptor( _descriptor.EnumValueDescriptor(
name='BYTES_RECEIVED', index=4, number=202, name='KPISAMPLETYPE_BYTES_RECEIVED', index=4, number=202,
serialized_options=None, serialized_options=None,
type=None, type=None,
create_key=_descriptor._internal_create_key), create_key=_descriptor._internal_create_key),
], ],
containing_type=None, containing_type=None,
serialized_options=None, serialized_options=None,
serialized_start=44, serialized_start=45,
serialized_end=164, serialized_end=235,
) )
_sym_db.RegisterEnumDescriptor(_KPISAMPLETYPE) _sym_db.RegisterEnumDescriptor(_KPISAMPLETYPE)
KpiSampleType = enum_type_wrapper.EnumTypeWrapper(_KPISAMPLETYPE) KpiSampleType = enum_type_wrapper.EnumTypeWrapper(_KPISAMPLETYPE)
UNKNOWN = 0 KPISAMPLETYPE_UNKNOWN = 0
PACKETS_TRANSMITTED = 101 KPISAMPLETYPE_PACKETS_TRANSMITTED = 101
PACKETS_RECEIVED = 102 KPISAMPLETYPE_PACKETS_RECEIVED = 102
BYTES_TRANSMITTED = 201 KPISAMPLETYPE_BYTES_TRANSMITTED = 201
BYTES_RECEIVED = 202 KPISAMPLETYPE_BYTES_RECEIVED = 202
DESCRIPTOR.enum_types_by_name['KpiSampleType'] = _KPISAMPLETYPE DESCRIPTOR.enum_types_by_name['KpiSampleType'] = _KPISAMPLETYPE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment