Skip to content
Snippets Groups Projects
Commit 4890620f authored by Francisco-Javier Moreno-Muro's avatar Francisco-Javier Moreno-Muro
Browse files

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

See merge request teraflow-h2020/controller!44
parents 8f83279b 6ece7c73
No related branches found
No related tags found
1 merge request!54Release 2.0.0
Showing
with 378 additions and 415 deletions
......@@ -8,18 +8,16 @@ stages:
- deploy
- funct_test
# include the individual .gitlab-ci.yml of each micro-service
include:
- local: '/manifests/.gitlab-ci.yml'
# - local: '/manifests/.gitlab-ci.yml'
- local: '/src/monitoring/.gitlab-ci.yml'
- local: '/src/centralizedattackdetector/.gitlab-ci.yml'
- local: '/src/context/.gitlab-ci.yml'
- local: '/src/device/.gitlab-ci.yml'
- local: '/src/service/.gitlab-ci.yml'
- local: '/src/tester_integration/.gitlab-ci.yml'
- local: '/src/tester_functional/.gitlab-ci.yml'
- local: '/src/automation/.gitlab-ci.yml'
- local: '/src/policy/.gitlab-ci.yml'
- local: '/src/l3_distributedattackdetector/.gitlab-ci.yml'
- local: '/src/l3_centralizedattackdetector/.gitlab-ci.yml'
- local: '/src/l3_attackmitigator/.gitlab-ci.yml'
# - local: '/src/centralizedattackdetector/.gitlab-ci.yml'
# - local: '/src/context/.gitlab-ci.yml'
# - local: '/src/device/.gitlab-ci.yml'
# - local: '/src/service/.gitlab-ci.yml'
# - local: '/src/tester_integration/.gitlab-ci.yml'
# - local: '/src/tester_functional/.gitlab-ci.yml'
# - local: '/src/automation/.gitlab-ci.yml'
syntax = "proto3";
package context;
//import "kpi_sample_types.proto";
import "kpi_sample_types.proto";
service ContextService {
rpc ListContextIds (Empty ) returns ( ContextIdList ) {}
......@@ -243,7 +243,6 @@ message EndPointId {
message EndPoint {
EndPointId endpoint_id = 1;
string endpoint_type = 2;
//repeated kpi_sample_types.KpiSampleType kpi_sample_types = 3;
}
......@@ -258,6 +257,7 @@ message ConfigRule {
ConfigActionEnum action = 1;
string resource_key = 2;
string resource_value = 3;
kpi_sample_types.KpiSampleType kpi_sample_type = 4;
}
......
......@@ -2,19 +2,19 @@ syntax = "proto3";
package device;
import "context.proto";
//import "monitoring.proto";
import "monitoring.proto";
service DeviceService {
rpc AddDevice (context.Device ) returns (context.DeviceId ) {}
rpc ConfigureDevice (context.Device ) returns (context.DeviceId ) {}
rpc DeleteDevice (context.DeviceId ) returns (context.Empty ) {}
rpc GetInitialConfig(context.DeviceId ) returns (context.DeviceConfig) {}
//rpc MonitorDeviceKpi(MonitoringSettings) returns (context.Empty ) {}
rpc MonitorDeviceKpi(MonitoringSettings) returns (context.Empty ) {}
}
//message MonitoringSettings {
// monitoring.KpiId kpi_id = 1;
// monitoring.KpiDescriptor kpi_descriptor = 2;
// float sampling_duration_s = 3;
// float sampling_interval_s = 4;
//}
message MonitoringSettings {
monitoring.KpiId kpi_id = 1;
monitoring.KpiDescriptor kpi_descriptor = 2;
float sampling_duration_s = 3;
float sampling_interval_s = 4;
}
syntax = "proto3";
//package kpi_sample_types;
package kpi_sample_types;
//enum KpiSampleType {
// UNKNOWN = 0;
// PACKETS_TRANSMITTED = 101;
// PACKETS_RECEIVED = 102;
// BYTES_TRANSMITTED = 201;
// BYTES_RECEIVED = 202;
//}
enum KpiSampleType {
UNKNOWN = 0;
PACKETS_TRANSMITTED = 101;
PACKETS_RECEIVED = 102;
BYTES_TRANSMITTED = 201;
BYTES_RECEIVED = 202;
}
......@@ -2,68 +2,30 @@ syntax = "proto3";
package monitoring;
import "context.proto";
//import "kpi_sample_types.proto";
import "kpi_sample_types.proto";
service MonitoringService {
// Old RPCs:
rpc CreateKpi (CreateKpiRequest) returns (KpiId) {}
rpc IncludeKpi (IncludeKpiRequest) returns (context.Empty) {}
rpc MonitorKpi (MonitorKpiRequest) returns (context.Empty) {}
rpc MonitorDeviceKpi (MonitorDeviceKpiRequest) returns (context.Empty) {}
rpc GetStreamKpi ( KpiId ) returns (stream Kpi) {}
rpc GetInstantKpi ( KpiId ) returns (Kpi) {}
// New RPCs:
//rpc CreateKpi (KpiDescriptor ) returns (KpiId ) {}
//rpc GetKpiDescriptor(KpiId ) returns (KpiDescriptor) {}
//rpc IncludeKpi (Kpi ) returns (context.Empty) {}
//rpc MonitorKpi (MonitorKpiRequest) returns (context.Empty) {}
//rpc GetStreamKpi (KpiId ) returns (stream Kpi ) {}
//rpc GetInstantKpi (KpiId ) returns (Kpi ) {}
rpc CreateKpi (KpiDescriptor ) returns (KpiId ) {}
rpc GetKpiDescriptor(KpiId ) returns (KpiDescriptor) {}
rpc IncludeKpi (Kpi ) returns (context.Empty) {}
rpc MonitorKpi (MonitorKpiRequest) returns (context.Empty) {}
rpc GetStreamKpi (KpiId ) returns (stream Kpi ) {}
rpc GetInstantKpi (KpiId ) returns (Kpi ) {}
}
message CreateKpiRequest /*New name: KpiDescriptor*/ {
// Old fields:
string kpiDescription = 1;
context.DeviceId device_id = 2;
KpiSampleType kpi_sample_type = 3;
// context.EndpointId endpoint_id = 4; // others might be added
// context.ServiceId service_id = 5; // for monitoring other
// context.SliceId slice_id = 6; // entities
// New fields:
//string kpi_description = 1;
//kpi_sample_types.KpiSampleType kpi_sample_type = 2;
//context.DeviceId device_id = 3;
//context.EndPointId endpoint_id = 4;
//context.ServiceId service_id = 5;
////context.SliceId slice_id = 6; // to be used in future features
message KpiDescriptor {
string kpi_description = 1;
kpi_sample_types.KpiSampleType kpi_sample_type = 2;
context.DeviceId device_id = 3;
context.EndPointId endpoint_id = 4;
context.ServiceId service_id = 5;
// context.SliceId slice_id = 6;
}
message MonitorKpiRequest{
KpiId kpi_id = 1;
// Old fields:
uint32 connexion_time_s = 2;
uint32 sample_rate_ms = 3;
// New fields:
//float sampling_duration_s = 2;
//float sampling_interval_s = 3;
}
// Message to be removed:
message MonitorDeviceKpiRequest{
Kpi kpi = 1;
uint32 connexion_time_s = 2;
uint32 sample_rate_ms = 3;
}
// Message to be removed:
message IncludeKpiRequest{
KpiId kpi_id = 1;
string time_stamp = 2;
KpiValue kpi_value= 3;
float sampling_duration_s = 2;
float sampling_interval_s = 3;
}
message KpiId {
......@@ -73,32 +35,18 @@ message KpiId {
message Kpi {
KpiId kpi_id = 1;
string timestamp = 2;
string kpiDescription = 3; // field to be removed
KpiValue kpi_value = 4; // field to be renumbered to 3
KpiSampleType kpi_sample_type = 5; // field to be removed
context.DeviceId device_id = 6; // field to be removed
// context.EndpointId endpoint_id = 7; // others might be added // field to be removed
// context.ServiceId service_id = 8; // for monitoring other // field to be removed
// context.SliceId slice_id = 9; // entities // field to be removed
KpiValue kpi_value = 4;
}
message KpiValue {
oneof value {
uint32 intVal = 1; // field to be renamed to int_val
float floatVal = 2; // field to be renamed to float_val
string stringVal = 3; // field to be renamed to str_val
bool boolVal = 4; // field to be renamed to bool_val
uint32 intVal = 1;
float floatVal = 2;
string stringVal = 3;
bool boolVal = 4;
}
}
message KpiList {
repeated Kpi kpiList = 1; // to be renamed to kpi_list
}
enum KpiSampleType { // to be moved to file "kpi_sample_types.proto"
UNKNOWN = 0;
PACKETS_TRANSMITTED = 101; // others might be added for
PACKETS_RECEIVED = 102; // packet, optical, radio,...
BYTES_TRANSMITTED = 201;
BYTES_RECEIVED = 202;
repeated Kpi kpi_list = 1;
}
......@@ -3,13 +3,13 @@ from typing import Optional, Union
from .backend._Backend import _Backend
from .backend.BackendEnum import BackendEnum
from .backend.inmemory.InMemoryBackend import InMemoryBackend
from .backend.redis.RedisBackend import RedisBackend
# from .backend.redis.RedisBackend import RedisBackend
LOGGER = logging.getLogger(__name__)
BACKENDS = {
BackendEnum.INMEMORY.value: InMemoryBackend,
BackendEnum.REDIS.value: RedisBackend,
# BackendEnum.REDIS.value: RedisBackend,
#BackendEnum.KAFKA.value: KafkaBackend,
#BackendEnum.RABBITMQ.value: RabbitMQBackend,
#BackendEnum.ZEROMQ.value: ZeroMQBackend,
......
......@@ -3,13 +3,13 @@ from typing import Optional, Union
from .backend._Backend import _Backend
from .backend.BackendEnum import BackendEnum
from .backend.inmemory.InMemoryBackend import InMemoryBackend
from .backend.redis.RedisBackend import RedisBackend
# from .backend.redis.RedisBackend import RedisBackend
LOGGER = logging.getLogger(__name__)
BACKENDS = {
BackendEnum.INMEMORY.value: InMemoryBackend,
BackendEnum.REDIS.value: RedisBackend,
# BackendEnum.REDIS.value: RedisBackend,
#BackendEnum.MONGODB.value: MongoDBBackend,
#BackendEnum.RETHINKDB.value: RethinkDBBackend,
#BackendEnum.ETCD.value: EtcdBackend,
......
This diff is collapsed.
......@@ -6,9 +6,7 @@ from . import context_pb2 as context__pb2
class ContextServiceStub(object):
"""import "kpi_sample_types.proto";
"""
"""Missing associated documentation comment in .proto file."""
def __init__(self, channel):
"""Constructor.
......@@ -169,9 +167,7 @@ class ContextServiceStub(object):
class ContextServiceServicer(object):
"""import "kpi_sample_types.proto";
"""
"""Missing associated documentation comment in .proto file."""
def ListContextIds(self, request, context):
"""Missing associated documentation comment in .proto file."""
......@@ -514,9 +510,7 @@ def add_ContextServiceServicer_to_server(servicer, server):
# This class is part of an EXPERIMENTAL API.
class ContextService(object):
"""import "kpi_sample_types.proto";
"""
"""Missing associated documentation comment in .proto file."""
@staticmethod
def ListContextIds(request,
......
......@@ -2,6 +2,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: kpi_sample_types.proto
"""Generated protocol buffer code."""
from google.protobuf.internal import enum_type_wrapper
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
......@@ -15,15 +16,62 @@ _sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor(
name='kpi_sample_types.proto',
package='',
package='kpi_sample_types',
syntax='proto3',
serialized_options=None,
create_key=_descriptor._internal_create_key,
serialized_pb=b'\n\x16kpi_sample_types.protob\x06proto3'
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'
)
_KPISAMPLETYPE = _descriptor.EnumDescriptor(
name='KpiSampleType',
full_name='kpi_sample_types.KpiSampleType',
filename=None,
file=DESCRIPTOR,
create_key=_descriptor._internal_create_key,
values=[
_descriptor.EnumValueDescriptor(
name='UNKNOWN', index=0, number=0,
serialized_options=None,
type=None,
create_key=_descriptor._internal_create_key),
_descriptor.EnumValueDescriptor(
name='PACKETS_TRANSMITTED', index=1, number=101,
serialized_options=None,
type=None,
create_key=_descriptor._internal_create_key),
_descriptor.EnumValueDescriptor(
name='PACKETS_RECEIVED', index=2, number=102,
serialized_options=None,
type=None,
create_key=_descriptor._internal_create_key),
_descriptor.EnumValueDescriptor(
name='BYTES_TRANSMITTED', index=3, number=201,
serialized_options=None,
type=None,
create_key=_descriptor._internal_create_key),
_descriptor.EnumValueDescriptor(
name='BYTES_RECEIVED', index=4, number=202,
serialized_options=None,
type=None,
create_key=_descriptor._internal_create_key),
],
containing_type=None,
serialized_options=None,
serialized_start=44,
serialized_end=164,
)
_sym_db.RegisterEnumDescriptor(_KPISAMPLETYPE)
KpiSampleType = enum_type_wrapper.EnumTypeWrapper(_KPISAMPLETYPE)
UNKNOWN = 0
PACKETS_TRANSMITTED = 101
PACKETS_RECEIVED = 102
BYTES_TRANSMITTED = 201
BYTES_RECEIVED = 202
DESCRIPTOR.enum_types_by_name['KpiSampleType'] = _KPISAMPLETYPE
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
......
import functools, logging, operator
from enum import Enum
from typing import Dict, List, Optional, Tuple, Union
from typing import Dict, List, Tuple, Union
from common.orm.Database import Database
from common.orm.HighLevel import get_object, get_or_create_object, update_or_create_object
from common.orm.HighLevel import get_or_create_object, update_or_create_object
from common.orm.backend.Tools import key_to_str
from common.orm.fields.EnumeratedField import EnumeratedField
from common.orm.fields.ForeignKeyField import ForeignKeyField
......@@ -11,7 +11,7 @@ from common.orm.fields.PrimaryKeyField import PrimaryKeyField
from common.orm.fields.StringField import StringField
from common.orm.model.Model import Model
from context.proto.context_pb2 import ConfigActionEnum
from .Tools import fast_hasher, grpc_to_enum, remove_dict_key
from context.service.database.Tools import fast_hasher, grpc_to_enum, remove_dict_key
LOGGER = logging.getLogger(__name__)
......@@ -50,62 +50,35 @@ class ConfigRuleModel(Model): # pylint: disable=abstract-method
return result
def set_config_rule(
database : Database, db_config : ConfigModel, position : int, resource_key : str, resource_value : str
database : Database, db_config : ConfigModel, grpc_config_rule, position : int
) -> Tuple[ConfigRuleModel, bool]:
str_rule_key_hash = fast_hasher(resource_key)
str_rule_key_hash = fast_hasher(grpc_config_rule.resource_key)
str_config_rule_key = key_to_str([db_config.pk, str_rule_key_hash], separator=':')
result : Tuple[ConfigRuleModel, bool] = update_or_create_object(database, ConfigRuleModel, str_config_rule_key, {
'config_fk': db_config, 'position': position, 'action': ORM_ConfigActionEnum.SET,
'key': resource_key, 'value': resource_value})
'config_fk': db_config,
'position' : position,
'action' : grpc_to_enum__config_action(grpc_config_rule.action),
'key' : grpc_config_rule.resource_key,
'value' : grpc_config_rule.resource_value,
})
db_config_rule, updated = result
return db_config_rule, updated
def delete_config_rule(
database : Database, db_config : ConfigModel, resource_key : str
) -> None:
str_rule_key_hash = fast_hasher(resource_key)
str_config_rule_key = key_to_str([db_config.pk, str_rule_key_hash], separator=':')
db_config_rule : Optional[ConfigRuleModel] = get_object(
database, ConfigRuleModel, str_config_rule_key, raise_if_not_found=False)
if db_config_rule is None: return
db_config_rule.delete()
def delete_all_config_rules(
database : Database, db_config : ConfigModel
) -> None:
db_config_rule_pks = db_config.references(ConfigRuleModel)
for pk,_ in db_config_rule_pks: ConfigRuleModel(database, pk).delete()
def grpc_config_rules_to_raw(grpc_config_rules) -> List[Tuple[ORM_ConfigActionEnum, str, str]]:
def translate(grpc_config_rule):
action = grpc_to_enum__config_action(grpc_config_rule.action)
return action, grpc_config_rule.resource_key, grpc_config_rule.resource_value
return [translate(grpc_config_rule) for grpc_config_rule in grpc_config_rules]
def update_config(
database : Database, db_parent_pk : str, config_name : str,
raw_config_rules : List[Tuple[ORM_ConfigActionEnum, str, str]]
def set_config(
database : Database, db_parent_pk : str, config_name : str, grpc_config_rules
) -> List[Tuple[Union[ConfigModel, ConfigRuleModel], bool]]:
str_config_key = key_to_str([db_parent_pk, config_name], separator=':')
result : Tuple[ConfigModel, bool] = get_or_create_object(database, ConfigModel, str_config_key)
db_config, created = result
db_objects : List[Tuple[Union[ConfigModel, ConfigRuleModel], bool]] = [(db_config, created)]
db_objects = [(db_config, created)]
for position,(action, resource_key, resource_value) in enumerate(raw_config_rules):
if action == ORM_ConfigActionEnum.SET:
result : Tuple[ConfigRuleModel, bool] = set_config_rule(
database, db_config, position, resource_key, resource_value)
db_config_rule, updated = result
db_objects.append((db_config_rule, updated))
elif action == ORM_ConfigActionEnum.DELETE:
delete_config_rule(database, db_config, resource_key)
else:
msg = 'Unsupported action({:s}) for resource_key({:s})/resource_value({:s})'
raise AttributeError(msg.format(str(ConfigActionEnum.Name(action)), str(resource_key), str(resource_value)))
for position,grpc_config_rule in enumerate(grpc_config_rules):
result : Tuple[ConfigRuleModel, bool] = set_config_rule(database, db_config, grpc_config_rule, position)
db_config_rule, updated = result
db_objects.append((db_config_rule, updated))
return db_objects
......@@ -4,8 +4,8 @@ from common.orm.fields.ForeignKeyField import ForeignKeyField
from common.orm.fields.PrimaryKeyField import PrimaryKeyField
from common.orm.fields.StringField import StringField
from common.orm.model.Model import Model
from .DeviceModel import DeviceModel
from .TopologyModel import TopologyModel
from context.service.database.DeviceModel import DeviceModel
from context.service.database.TopologyModel import TopologyModel
LOGGER = logging.getLogger(__name__)
......
......@@ -12,7 +12,7 @@ from context.proto.context_pb2 import (
DeviceList, Empty, EventTypeEnum, Link, LinkEvent, LinkId, LinkIdList, LinkList, Service, ServiceEvent, ServiceId,
ServiceIdList, ServiceList, Topology, TopologyEvent, TopologyId, TopologyIdList, TopologyList)
from context.proto.context_pb2_grpc import ContextServiceServicer
from context.service.database.ConfigModel import ConfigModel, ConfigRuleModel, grpc_config_rules_to_raw, update_config
from context.service.database.ConfigModel import ConfigModel, ConfigRuleModel, set_config
from context.service.database.ConstraintModel import ConstraintModel, ConstraintsModel, set_constraints
from context.service.database.ContextModel import ContextModel
from context.service.database.DeviceModel import (
......@@ -236,8 +236,7 @@ class ContextServiceServicerImpl(ContextServiceServicer):
'request.device_endpoints[{:d}].device_id.device_uuid.uuid'.format(i), endpoint_device_uuid,
['should be == {:s}({:s})'.format('request.device_id.device_uuid.uuid', device_uuid)])
config_rules = grpc_config_rules_to_raw(request.device_config.config_rules)
running_config_result = update_config(self.database, device_uuid, 'running', config_rules)
running_config_result = set_config(self.database, device_uuid, 'running', request.device_config.config_rules)
db_running_config = running_config_result[0][0]
result : Tuple[DeviceModel, bool] = update_or_create_object(self.database, DeviceModel, device_uuid, {
......@@ -453,8 +452,8 @@ class ContextServiceServicerImpl(ContextServiceServicer):
self.database, str_service_key, 'constraints', request.service_constraints)
db_constraints = constraints_result[0][0]
config_rules = grpc_config_rules_to_raw(request.service_config.config_rules)
running_config_result = update_config(self.database, str_service_key, 'running', config_rules)
running_config_result = set_config(
self.database, str_service_key, 'running', request.service_config.config_rules)
db_running_config = running_config_result[0][0]
result : Tuple[ServiceModel, bool] = update_or_create_object(self.database, ServiceModel, str_service_key, {
......
......@@ -2,12 +2,13 @@ from copy import deepcopy
from common.Constants import DEFAULT_CONTEXT_UUID, DEFAULT_TOPOLOGY_UUID
from context.proto.context_pb2 import (
ConfigActionEnum, DeviceDriverEnum, DeviceOperationalStatusEnum, ServiceStatusEnum, ServiceTypeEnum)
from context.proto.kpi_sample_types_pb2 import KpiSampleType
# 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 config_rule(action, resource_key, resource_value, kpi_sample_type):
return {'action': action, 'resource_key': resource_key, 'resource_value': resource_value, 'kpi_sample_type': kpi_sample_type}
def endpoint_id(topology_id, device_id, endpoint_uuid):
return {'topology_id': deepcopy(topology_id), 'device_id': deepcopy(device_id),
......@@ -40,9 +41,10 @@ DEVICE1 = {
'device_id': deepcopy(DEVICE1_ID),
'device_type': 'packet-router',
'device_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value1'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value2'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value3'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value1', KpiSampleType.PACKETS_TRANSMITTED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value2', KpiSampleType.PACKETS_RECEIVED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value3', KpiSampleType.BYTES_TRANSMITTED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc4/value', 'value4', KpiSampleType.BYTES_RECEIVED),
]},
'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED,
'device_drivers': [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG, DeviceDriverEnum.DEVICEDRIVER_P4],
......@@ -59,9 +61,9 @@ DEVICE2 = {
'device_id': deepcopy(DEVICE2_ID),
'device_type': 'packet-router',
'device_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value4'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value5'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value6'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value4', KpiSampleType.PACKETS_TRANSMITTED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value5', KpiSampleType.PACKETS_RECEIVED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value6', KpiSampleType.BYTES_TRANSMITTED),
]},
'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED,
'device_drivers': [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG, DeviceDriverEnum.DEVICEDRIVER_P4],
......@@ -78,9 +80,9 @@ DEVICE3 = {
'device_id': deepcopy(DEVICE3_ID),
'device_type': 'packet-router',
'device_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value4'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value5'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value6'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value4', KpiSampleType.PACKETS_TRANSMITTED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value5', KpiSampleType.PACKETS_RECEIVED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value6', KpiSampleType.BYTES_TRANSMITTED),
]},
'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED,
'device_drivers': [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG, DeviceDriverEnum.DEVICEDRIVER_P4],
......@@ -139,9 +141,9 @@ SERVICE_DEV1_DEV2 = {
],
'service_status': {'service_status': ServiceStatusEnum.SERVICESTATUS_ACTIVE},
'service_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc1/value', 'value7'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc2/value', 'value8'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc3/value', 'value9'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc1/value', 'value7', KpiSampleType.PACKETS_TRANSMITTED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc2/value', 'value8', KpiSampleType.PACKETS_TRANSMITTED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc3/value', 'value9', KpiSampleType.PACKETS_TRANSMITTED),
]},
}
......@@ -163,9 +165,9 @@ SERVICE_DEV1_DEV3 = {
],
'service_status': {'service_status': ServiceStatusEnum.SERVICESTATUS_ACTIVE},
'service_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc1/value', 'value7'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc2/value', 'value8'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc3/value', 'value9'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc1/value', 'value7', KpiSampleType.PACKETS_TRANSMITTED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc2/value', 'value8', KpiSampleType.PACKETS_TRANSMITTED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc3/value', 'value9', KpiSampleType.PACKETS_TRANSMITTED),
]},
}
......@@ -187,8 +189,8 @@ SERVICE_DEV2_DEV3 = {
],
'service_status': {'service_status': ServiceStatusEnum.SERVICESTATUS_ACTIVE},
'service_config': {'config_rules': [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc1/value', 'value7'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc2/value', 'value8'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc3/value', 'value9'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc1/value', 'value7', KpiSampleType.PACKETS_TRANSMITTED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc2/value', 'value8', KpiSampleType.PACKETS_TRANSMITTED),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'svc/rsrc3/value', 'value9', KpiSampleType.PACKETS_TRANSMITTED),
]},
}
......@@ -35,7 +35,7 @@ unit_test device:
- sleep 5
- docker ps -a
- docker logs $IMAGE_NAME
- 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_service.py $IMAGE_NAME/tests/test_unitary_driverapi.py"
after_script:
- docker stop $IMAGE_NAME
- docker rm $IMAGE_NAME
......
......@@ -10,9 +10,3 @@ GRPC_GRACE_PERIOD = 60
# Prometheus settings
METRICS_PORT = 9192
# Dependency micro-service connection settings
CONTEXT_SERVICE_HOST = '127.0.0.1'
CONTEXT_SERVICE_PORT = 1010
MONITORING_SERVICE_HOST = '127.0.0.1'
MONITORING_SERVICE_PORT = 7070
......@@ -29,9 +29,7 @@ RUN python3 -m pip install -r device/requirements.in
# Add files into working directory
COPY common/. common
COPY context/. context
COPY device/. device
COPY monitoring/. monitoring
# Start device service
ENTRYPOINT ["python", "-m", "device.service"]
import grpc, logging
from common.tools.client.RetryDecorator import retry, delay_exponential
from device.proto.context_pb2 import Device, DeviceConfig, DeviceId, Empty
#from device.proto.device_pb2 import MonitoringSettings
from device.proto.context_pb2 import Device, DeviceId, Empty
from device.proto.device_pb2 import MonitoringSettings
from device.proto.device_pb2_grpc import DeviceServiceStub
LOGGER = logging.getLogger(__name__)
......@@ -22,7 +22,7 @@ class DeviceClient:
self.stub = DeviceServiceStub(self.channel)
def close(self):
if self.channel is not None: self.channel.close()
if(self.channel is not None): self.channel.close()
self.channel = None
self.stub = None
......@@ -48,15 +48,8 @@ class DeviceClient:
return response
@retry(exceptions=set(), max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')
def GetInitialConfig(self, request : DeviceId) -> DeviceConfig:
LOGGER.debug('GetInitialConfig request: {:s}'.format(str(request)))
response = self.stub.GetInitialConfig(request)
LOGGER.debug('GetInitialConfig result: {:s}'.format(str(response)))
def MonitorDeviceKpi(self, request: MonitoringSettings) -> Empty:
LOGGER.debug('MonitorDeviceKpi request: {:s}'.format(str(request)))
response = self.stub.MonitorDeviceKpi(request)
LOGGER.debug('MonitorDeviceKpi result: {:s}'.format(str(response)))
return response
#@retry(exceptions=set(), max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')
#def MonitorDeviceKpi(self, request : MonitoringSettings) -> Empty:
# LOGGER.debug('MonitorDeviceKpi request: {:s}'.format(str(request)))
# response = self.stub.MonitorDeviceKpi(request)
# LOGGER.debug('MonitorDeviceKpi result: {:s}'.format(str(response)))
# return response
......@@ -26,14 +26,10 @@ touch proto/__init__.py
python -m grpc_tools.protoc -I../../proto --python_out=proto --grpc_python_out=proto context.proto
python -m grpc_tools.protoc -I../../proto --python_out=proto --grpc_python_out=proto device.proto
python -m grpc_tools.protoc -I../../proto --python_out=proto --grpc_python_out=proto kpi_sample_types.proto
python -m grpc_tools.protoc -I../../proto --python_out=proto --grpc_python_out=proto monitoring.proto
rm proto/context_pb2_grpc.py
rm proto/kpi_sample_types_pb2_grpc.py
rm proto/monitoring_pb2_grpc.py
sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/context_pb2.py
sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/device_pb2.py
sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/device_pb2_grpc.py
sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/kpi_sample_types_pb2.py
sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/monitoring_pb2.py
This diff is collapsed.
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