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

Intermediate Device component backup:

- reorganized some files and modules
- implemented discovery of device endpoints for OpenConfig driver
- implemented retrieval of current configuration for OpenConfig driver
- updated test units and separated in emulated and openconfig test sets
parent dfa0d98d
No related branches found
No related tags found
1 merge request!54Release 2.0.0
Showing
with 361 additions and 346 deletions
drx30-01.xml *.xml
import grpc, json, logging
from typing import Any, List, Tuple from typing import Any, List, Tuple
import grpc, logging from google.protobuf.json_format import MessageToDict
from common.orm.Database import Database from common.orm.Database import Database
from common.orm.Factory import get_database_backend from common.orm.Factory import get_database_backend
from common.orm.HighLevel import get_object, update_or_create_object from common.orm.HighLevel import get_object, update_or_create_object
...@@ -12,6 +13,7 @@ from context.client.ContextClient import ContextClient ...@@ -12,6 +13,7 @@ from context.client.ContextClient import ContextClient
from device.proto.context_pb2 import ConfigActionEnum, Device, DeviceConfig, DeviceId, Empty from device.proto.context_pb2 import ConfigActionEnum, Device, DeviceConfig, DeviceId, Empty
from device.proto.device_pb2 import MonitoringSettings from device.proto.device_pb2 import MonitoringSettings
from device.proto.device_pb2_grpc import DeviceServiceServicer from device.proto.device_pb2_grpc import DeviceServiceServicer
from device.service.drivers.openconfig.OpenConfigDriver import OpenConfigDriver
from .MonitoringLoops import MonitoringLoops from .MonitoringLoops import MonitoringLoops
from .database.ConfigModel import ( from .database.ConfigModel import (
ConfigModel, ConfigRuleModel, ORM_ConfigActionEnum, get_config_rules, grpc_config_rules_to_raw, update_config) ConfigModel, ConfigRuleModel, ORM_ConfigActionEnum, get_config_rules, grpc_config_rules_to_raw, update_config)
...@@ -22,7 +24,7 @@ from .database.DeviceModel import DeviceModel, DriverModel ...@@ -22,7 +24,7 @@ from .database.DeviceModel import DeviceModel, DriverModel
from .database.EndPointModel import EndPointModel from .database.EndPointModel import EndPointModel
from .database.KpiModel import KpiModel from .database.KpiModel import KpiModel
from .database.KpiSampleType import grpc_to_enum__kpi_sample_type from .database.KpiSampleType import grpc_to_enum__kpi_sample_type
from .driver_api._Driver import _Driver 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 (
check_delete_errors, check_set_errors, check_subscribe_errors, check_unsubscribe_errors) check_delete_errors, check_set_errors, check_subscribe_errors, check_unsubscribe_errors)
...@@ -59,11 +61,36 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): ...@@ -59,11 +61,36 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
else: else:
unexpected_config_rules.append(config_rule) unexpected_config_rules.append(config_rule)
if len(unexpected_config_rules) > 0: if len(unexpected_config_rules) > 0:
unexpected_config_rules = MessageToDict(
request.device_config, including_default_value_fields=True,
preserving_proto_field_name=True, use_integers_for_enums=True)
unexpected_config_rules = unexpected_config_rules['config_rules']
unexpected_config_rules = list(filter(
lambda cr: cr['resource_key'].replace('_connect/', '') not in connection_config_rules,
unexpected_config_rules))
str_unexpected_config_rules = json.dumps(unexpected_config_rules, sort_keys=True)
raise InvalidArgumentException( raise InvalidArgumentException(
'device.device_config.config_rules', str(unexpected_config_rules), 'device.device_config.config_rules', str_unexpected_config_rules,
extra_details='RPC method AddDevice only accepts connection Config Rules that should start '\ extra_details='RPC method AddDevice only accepts connection Config Rules that should start '\
'with "_connect/" tag. Others should be configured after adding the device.') 'with "_connect/" tag. Others should be configured after adding the device.')
if len(request.device_endpoints) > 0:
unexpected_endpoints = MessageToDict(
request.device_endpoints, including_default_value_fields=True, preserving_proto_field_name=True,
use_integers_for_enums=True)
str_unexpected_endpoints = json.dumps(unexpected_endpoints, sort_keys=True)
raise InvalidArgumentException(
'device.device_endpoints', str_unexpected_endpoints,
extra_details='RPC method AddDevice does not accept endpoints. Endpoints are discovered through '\
'interrogation of the physical device.')
# Remove device configuration
json_request = MessageToDict(
request, including_default_value_fields=True, preserving_proto_field_name=True,
use_integers_for_enums=True)
json_request['device_config'] = {}
request = Device(**json_request)
sync_device_from_context(device_uuid, self.context_client, self.database) sync_device_from_context(device_uuid, self.context_client, self.database)
db_device,_ = update_device_in_local_database(self.database, request) db_device,_ = update_device_in_local_database(self.database, request)
...@@ -76,12 +103,25 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): ...@@ -76,12 +103,25 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
settings=connection_config_rules) settings=connection_config_rules)
driver.Connect() driver.Connect()
running_config_rules = driver.GetConfig() endpoints = driver.GetConfig([RESOURCE_ENDPOINTS])
running_config_rules = [(ORM_ConfigActionEnum.SET, rule[0], rule[1]) for rule in running_config_rules] for _, resource_value in endpoints:
LOGGER.info('[AddDevice] running_config_rules = {:s}'.format(str(running_config_rules))) endpoint_uuid = resource_value.get('name')
endpoint_type = resource_value.get('type')
context_config_rules = get_config_rules(self.database, device_uuid, 'running') str_endpoint_key = key_to_str([device_uuid, endpoint_uuid])
LOGGER.info('[AddDevice] context_config_rules = {:s}'.format(str(context_config_rules))) update_or_create_object(
self.database, EndPointModel, str_endpoint_key, {
'device_fk' : db_device,
'endpoint_uuid': endpoint_uuid,
'endpoint_type': endpoint_type,
})
running_config_rules = driver.GetConfig([RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES])
running_config_rules = [(ORM_ConfigActionEnum.SET, cr[0], json.dumps(cr[1])) for cr in running_config_rules]
#for running_config_rule in running_config_rules:
# LOGGER.info('[AddDevice] running_config_rule: {:s}'.format(str(running_config_rule)))
#context_config_rules = get_config_rules(self.database, device_uuid, 'running')
#LOGGER.info('[AddDevice] context_config_rules = {:s}'.format(str(context_config_rules)))
# TODO: Compute diff between current context config and device config. The one in device is of higher priority # TODO: Compute diff between current context config and device config. The one in device is of higher priority
# (might happen another instance is updating config and context was not already updated) # (might happen another instance is updating config and context was not already updated)
......
import anytree import anytree
from typing import Any, List, Optional from typing import Any, List, Optional
from anytree.render import Row
class TreeNode(anytree.node.Node): class TreeNode(anytree.node.Node):
def __init__(self, name, parent=None, children=None, **kwargs) -> None: def __init__(self, name, parent=None, children=None, **kwargs) -> None:
super().__init__(name, parent=parent, children=children, **kwargs) super().__init__(name, parent=parent, children=children, **kwargs)
......
from typing import Any, Iterator, List, Optional, Tuple, Union from typing import Any, Iterator, List, Optional, Tuple, Union
# Special resource names
RESOURCE_ENDPOINTS = '__endpoints__'
RESOURCE_INTERFACES = '__interfaces__'
RESOURCE_NETWORK_INSTANCES = '__network_instances__'
class _Driver: class _Driver:
def __init__(self, address : str, port : int, **settings) -> None: def __init__(self, address : str, port : int, **settings) -> None:
""" Initialize Driver. """ Initialize Driver.
......
...@@ -7,7 +7,7 @@ DRIVERS = [ ...@@ -7,7 +7,7 @@ DRIVERS = [
(EmulatedDriver, [ (EmulatedDriver, [
{ {
FilterFieldEnum.DEVICE_TYPE: DeviceTypeFilterFieldEnum.EMULATED, FilterFieldEnum.DEVICE_TYPE: DeviceTypeFilterFieldEnum.EMULATED,
FilterFieldEnum.DRIVER : ORM_DeviceDriverEnum.OPENCONFIG, FilterFieldEnum.DRIVER : ORM_DeviceDriverEnum.UNDEFINED,
} }
]), ]),
(OpenConfigDriver, [ (OpenConfigDriver, [
......
...@@ -7,7 +7,7 @@ from apscheduler.jobstores.memory import MemoryJobStore ...@@ -7,7 +7,7 @@ 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.driver_api._Driver import _Driver from device.service.driver_api._Driver import _Driver
from .AnyTreeTools import TreeNode, dump_subtree, get_subnode, set_subnode_value from device.service.driver_api.AnyTreeTools import TreeNode, dump_subtree, get_subnode, set_subnode_value
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
......
import logging, ncclient.manager, pytz, queue, threading import anytree, logging, pytz, queue, threading
import xml.dom.minidom from anytree.importer import DictImporter
from typing import Any, Iterator, List, Optional, Tuple, Union
#import anytree, random
#from datetime import datetime, timedelta #from datetime import datetime, timedelta
import lxml.etree as ET
from typing import Any, Iterator, List, Optional, Tuple, Union
#from apscheduler.executors.pool import ThreadPoolExecutor #from apscheduler.executors.pool import ThreadPoolExecutor
#from apscheduler.job import Job #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 netconf_client.connect import connect_ssh
from netconf_client.ncclient import Manager
from common.type_checkers.Checkers import chk_float, chk_integer, chk_length, chk_string, chk_type
from device.service.driver_api._Driver import _Driver from device.service.driver_api._Driver import _Driver
from device.service.drivers.openconfig.handlers import DEFAULT_HANDLER, HANDLERS from device.service.driver_api.AnyTreeTools import TreeNode, dump_subtree, get_subnode, set_subnode_value
#from .AnyTreeTools import TreeNode, dump_subtree, get_subnode, set_subnode_value from device.service.drivers.openconfig.Tools import xml_pretty_print, xml_to_dict, xml_to_file
from device.service.drivers.openconfig.templates import ALL_RESOURCES, get_filter, extract_data
logging.getLogger('ncclient.transport.ssh').setLevel(logging.WARNING) logging.getLogger('ncclient.transport.ssh').setLevel(logging.WARNING)
...@@ -22,14 +25,14 @@ LOGGER = logging.getLogger(__name__) ...@@ -22,14 +25,14 @@ LOGGER = logging.getLogger(__name__)
class OpenConfigDriver(_Driver): class OpenConfigDriver(_Driver):
def __init__(self, address : str, port : int, **settings) -> None: # pylint: disable=super-init-not-called def __init__(self, address : str, port : int, **settings) -> None: # pylint: disable=super-init-not-called
self.__address = address self.__address = address
self.__port = port self.__port = int(port)
self.__settings = settings self.__settings = settings
self.__lock = threading.Lock() self.__lock = threading.Lock()
#self.__initial = TreeNode('.') #self.__initial = TreeNode('.')
#self.__running = TreeNode('.') #self.__running = TreeNode('.')
self.__started = threading.Event() self.__started = threading.Event()
self.__terminate = threading.Event() self.__terminate = threading.Event()
self.__netconf_manager : ncclient.manager.Manager = None self.__netconf_manager : Manager = None
#self.__scheduler = BackgroundScheduler(daemon=True) # scheduler used to emulate sampling events #self.__scheduler = BackgroundScheduler(daemon=True) # scheduler used to emulate sampling events
#self.__scheduler.configure( #self.__scheduler.configure(
# jobstores = {'default': MemoryJobStore()}, # jobstores = {'default': MemoryJobStore()},
...@@ -43,11 +46,10 @@ class OpenConfigDriver(_Driver): ...@@ -43,11 +46,10 @@ class OpenConfigDriver(_Driver):
if self.__started.is_set(): return True if self.__started.is_set(): return True
username = self.__settings.get('username') username = self.__settings.get('username')
password = self.__settings.get('password') password = self.__settings.get('password')
handler_name = self.__settings.get('handler') timeout = int(self.__settings.get('timeout', 120))
handler = HANDLERS.get(handler_name, DEFAULT_HANDLER) session = connect_ssh(
self.__netconf_manager = ncclient.manager.connect_ssh( host=self.__address, port=self.__port, username=username, password=password)
host=self.__address, port=self.__port, username=username, password=password, hostkey_verify=False, self.__netconf_manager = Manager(session, timeout=timeout)
device_params=handler)
# Connect triggers activation of sampling events that will be scheduled based on subscriptions # Connect triggers activation of sampling events that will be scheduled based on subscriptions
#self.__scheduler.start() #self.__scheduler.start()
self.__started.set() self.__started.set()
...@@ -75,29 +77,21 @@ class OpenConfigDriver(_Driver): ...@@ -75,29 +77,21 @@ class OpenConfigDriver(_Driver):
results = [] results = []
with self.__lock: with self.__lock:
if len(resource_keys) == 0: if len(resource_keys) == 0: resource_keys = ALL_RESOURCES
config = self.__netconf_manager.get_config(source='running').data_xml for i,resource_key in enumerate(resource_keys):
with open('../data/drx30-01.xml', mode='w', encoding='UTF-8') as f: str_resource_name = 'resource_key[#{:d}]'.format(i)
dom = xml.dom.minidom.parseString(config) try:
f.write(dom.toprettyxml()) str_filter = get_filter(resource_key)
if str_filter is None: str_filter = resource_key
xml_data = self.__netconf_manager.get(filter=str_filter).data_ele
if isinstance(xml_data, Exception): raise xml_data
results.extend(extract_data(resource_key, xml_data))
except Exception as e: # pylint: disable=broad-except
LOGGER.exception('Exception retrieving {:s}: {:s}'.format(str_resource_name, str(resource_key)))
results.append((resource_key, e)) # if validation fails, store the exception
continue
return results return results
# resolver = anytree.Resolver(pathattr='name')
# for i,resource_key in enumerate(resource_keys):
# str_resource_name = 'resource_key[#{:d}]'.format(i)
# try:
# resource_path = resource_key.split('/')
# except Exception as e: # pylint: disable=broad-except
# LOGGER.exception('Exception validating {:s}: {:s}'.format(str_resource_name, str(resource_key)))
# results.append((resource_key, e)) # if validation fails, store the exception
# continue
#
# resource_node = get_subnode(resolver, self.__running, resource_path, default=None)
# # if not found, resource_node is None
# if resource_node is None: continue
# results.extend(dump_subtree(resource_node))
# return results
#
# def GetResource(self, endpoint_uuid : str) -> Optional[str]: # def GetResource(self, endpoint_uuid : str) -> Optional[str]:
# chk_string('endpoint_uuid', endpoint_uuid) # chk_string('endpoint_uuid', endpoint_uuid)
# return { # return {
......
import xml.dom.minidom, xmltodict
def xml_pretty_print(data : str):
return xml.dom.minidom.parseString(data).toprettyxml()
def xml_to_file(data : str, file_path : str) -> None:
with open(file_path, mode='w', encoding='UTF-8') as f:
f.write(xml_pretty_print(data))
def xml_to_dict(data : str):
return xmltodict.parse(data)
# Handler for Infinera device specific information through YANG.
from ncclient.xml_ import BASE_NS_1_0
from ncclient.devices.default import DefaultDeviceHandler
class InfineraDeviceHandler(DefaultDeviceHandler):
_EXEMPT_ERRORS = []
def get_capabilities(self):
return [
'urn:ietf:params:netconf:base:1.0',
'urn:ietf:params:netconf:base:1.1',
]
def get_xml_base_namespace_dict(self):
return {None: BASE_NS_1_0}
def get_xml_extra_prefix_kwargs(self):
return {'nsmap': self.get_xml_base_namespace_dict()}
from .InfineraDeviceHandler import InfineraDeviceHandler
HANDLERS = {
'infinera': {'handler': InfineraDeviceHandler},
}
DEFAULT_HANDLER = {'name': 'default'}
NAMESPACE_NETCONF = 'urn:ietf:params:xml:ns:netconf:base:1.0'
NAMESPACE_INTERFACES = 'http://openconfig.net/yang/interfaces'
NAMESPACE_INTERFACES_IP = 'http://openconfig.net/yang/interfaces/ip'
NAMESPACE_NETWORK_INSTANCE = 'http://openconfig.net/yang/network-instance'
NAMESPACE_NETWORK_INSTANCE_TYPES = 'http://openconfig.net/yang/network-instance-types'
NAMESPACE_OPENCONFIG_TYPES = 'http://openconfig.net/yang/openconfig-types'
NAMESPACE_PLATFORM = 'http://openconfig.net/yang/platform'
NAMESPACE_PLATFORM_PORT = 'http://openconfig.net/yang/platform/port'
NAMESPACE_VLAN = 'http://openconfig.net/yang/vlan'
NAMESPACES = {
'nc' : NAMESPACE_NETCONF,
'oci' : NAMESPACE_INTERFACES,
'ociip': NAMESPACE_INTERFACES_IP,
'ocni' : NAMESPACE_NETWORK_INSTANCE,
'ocnit': NAMESPACE_NETWORK_INSTANCE_TYPES,
'ococt': NAMESPACE_OPENCONFIG_TYPES,
'ocp' : NAMESPACE_PLATFORM,
'ocpp' : NAMESPACE_PLATFORM_PORT,
'ocv' : NAMESPACE_VLAN,
}
import lxml.etree as ET
from typing import Collection, Dict
def add_value_from_tag(container : Dict, name: str, value : ET.Element, cast=None) -> None:
if value is None or value.text is None: return
value = value.text
if cast is not None: value = cast(value)
container[name] = value
def add_value_from_collection(container : Dict, name: str, value : Collection) -> None:
if value is None or len(value) == 0: return
container[name] = value
import lxml.etree as ET
from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES
from .Components import get_filter_components, extract_port_data
from .Interfaces import get_filter_interfaces, extract_interface_data
from .NetworkInstance import get_filter_network_instances, extract_network_instance_data
RESOURCE_FUNCTIONS = {
RESOURCE_ENDPOINTS : (get_filter_components, extract_port_data),
RESOURCE_INTERFACES : (get_filter_interfaces, extract_interface_data),
RESOURCE_NETWORK_INSTANCES : (get_filter_network_instances, extract_network_instance_data),
}
ALL_RESOURCES = [
RESOURCE_ENDPOINTS,
RESOURCE_INTERFACES,
RESOURCE_NETWORK_INSTANCES,
]
def get_filter(resource_key : str, *args, **kwargs):
filter_function = RESOURCE_FUNCTIONS.get(resource_key)
return None if filter_function is None else filter_function[0](*args, **kwargs)
def extract_data(resource_key : str, xml_data : ET.Element, *args, **kwargs):
extract_function = RESOURCE_FUNCTIONS.get(resource_key)
return [(resource_key, xml_data)] if extract_function is None else extract_function[1](xml_data, *args, **kwargs)
from copy import deepcopy
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}
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 ConfigActionEnum, DeviceDriverEnum, DeviceOperationalStatusEnum from context.proto.context_pb2 import ConfigActionEnum, DeviceDriverEnum, DeviceOperationalStatusEnum
from .Tools import config_rule
DEVICE_EMU_UUID = 'EMULARED'
DEVICE_EMU_TYPE = 'emulated'
DEVICE_EMU_ADDRESS = '127.0.0.1'
DEVICE_EMU_PORT = '0'
DEVICE_EMU_DRIVERS = [DeviceDriverEnum.DEVICEDRIVER_UNDEFINED]
try: try:
from ._device_credentials import ( from ._device_credentials import (
DEVICE1_UUID, DEVICE1_TYPE, DEVICE1_ADDRESS, DEVICE1_PORT, DEVICE1_USERNAME, DEVICE1_PASSWORD, DEVICE1_HANDLER, DEVICE_INF_UUID, DEVICE_INF_TYPE, DEVICE_INF_ADDRESS, DEVICE_INF_PORT, DEVICE_INF_USERNAME,
DEVICE1_DRIVERS) DEVICE_INF_PASSWORD, DEVICE_INF_DRIVERS, DEVICE_INF_CONFIG_RULES)
except ImportError: except ImportError:
DEVICE1_UUID = 'DEV1' DEVICE_INF_UUID = 'DEV2'
DEVICE1_TYPE = 'packet-router' DEVICE_INF_TYPE = 'packet-router'
DEVICE1_ADDRESS = '127.0.0.1' DEVICE_INF_ADDRESS = '127.0.0.1'
DEVICE1_PORT = '830' DEVICE_INF_PORT = '830'
DEVICE1_USERNAME = 'username' DEVICE_INF_USERNAME = 'username'
DEVICE1_PASSWORD = 'password' DEVICE_INF_PASSWORD = 'password'
DEVICE1_HANDLER = 'default' DEVICE_INF_DRIVERS = [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG]
DEVICE1_DRIVERS = [DeviceDriverEnum.DEVICEDRIVER_OPENCONFIG] DEVICE_INF_CONFIG_RULES = []
# 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}}
...@@ -47,26 +41,41 @@ TOPOLOGY = { ...@@ -47,26 +41,41 @@ TOPOLOGY = {
'link_ids': [], 'link_ids': [],
} }
DEVICE1_ID = {'device_uuid': {'uuid': DEVICE1_UUID}} DEVICE_EMU_ID = {'device_uuid': {'uuid': DEVICE_EMU_UUID}}
DEVICE1 = { DEVICE_EMU = {
'device_id': deepcopy(DEVICE1_ID), 'device_id': deepcopy(DEVICE_EMU_ID),
'device_type': DEVICE1_TYPE, 'device_type': DEVICE_EMU_TYPE,
'device_config': {'config_rules': []}, 'device_config': {'config_rules': []},
'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED, 'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED,
'device_drivers': DEVICE1_DRIVERS, 'device_drivers': DEVICE_EMU_DRIVERS,
'device_endpoints': [], 'device_endpoints': [],
} }
DEVICE1_CONNECT_RULES = [ DEVICE_EMU_CONNECT_RULES = [
config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/address', DEVICE1_ADDRESS ), config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/address', DEVICE_EMU_ADDRESS ),
config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/port', DEVICE1_PORT ), config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/port', DEVICE_EMU_PORT ),
config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/username', DEVICE1_USERNAME),
config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/password', DEVICE1_PASSWORD),
config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/handler', DEVICE1_HANDLER ),
] ]
DEVICE1_CONFIG_RULES = [ DEVICE_EMU_CONFIG_RULES = [
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value1'), config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc1/value', 'value1'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value2'), config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc2/value', 'value2'),
config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value3'), config_rule(ConfigActionEnum.CONFIGACTION_SET, 'dev/rsrc3/value', 'value3'),
] ]
DEVICE_INF_ID = {'device_uuid': {'uuid': DEVICE_INF_UUID}}
DEVICE_INF = {
'device_id': deepcopy(DEVICE_INF_ID),
'device_type': DEVICE_INF_TYPE,
'device_config': {'config_rules': []},
'device_operational_status': DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED,
'device_drivers': DEVICE_INF_DRIVERS,
'device_endpoints': [],
}
DEVICE_INF_CONNECT_RULES = [
config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/address', DEVICE_INF_ADDRESS ),
config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/port', DEVICE_INF_PORT ),
config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/username', DEVICE_INF_USERNAME),
config_rule(ConfigActionEnum.CONFIGACTION_SET, '_connect/password', DEVICE_INF_PASSWORD),
]
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