def volttron_instance_module_web(request): print("building module instance (using web)") address = get_rand_vip() web_address = "http://{}".format(get_rand_ip_and_port()) wrapper = build_wrapper(address, bind_web_address=web_address, messagebus='zmq', ssl_auth=False) yield wrapper cleanup_wrapper(wrapper)
def get_volttron_multi_msgbus_instances(instance_name1=None, instance_name2=None): print("volttron_multi_messagebus source: {} sink: {}".format( request.param['source'], request.param['sink'])) sink_address = get_rand_vip() if request.param['sink'] == 'rmq_web': hostname, port = get_hostname_and_random_port() web_address = 'https://{hostname}:{port}'.format(hostname=hostname, port=port) messagebus = 'rmq' ssl_auth = True else: web_address = "http://{}".format(get_rand_ip_and_port()) messagebus = 'zmq' ssl_auth = False sink = build_wrapper(sink_address, ssl_auth=ssl_auth, messagebus=messagebus, bind_web_address=web_address, volttron_central_address=web_address, instance_name="volttron1") source_address = get_rand_vip() messagebus = 'zmq' ssl_auth = False if request.param['source'] == 'rmq': messagebus = 'rmq' ssl_auth = True if sink.messagebus == 'rmq': # sink_ca_file = sink.certsobj.cert_file(sink.certsobj.root_ca_name) source = build_wrapper( source_address, ssl_auth=ssl_auth, messagebus=messagebus, volttron_central_address=sink.bind_web_address, remote_platform_ca=sink.certsobj.cert_file( sink.certsobj.root_ca_name), instance_name='volttron2') else: source = build_wrapper( source_address, ssl_auth=ssl_auth, messagebus=messagebus, volttron_central_address=sink.bind_web_address, instance_name='volttron2') get_volttron_multi_msgbus_instances.source = source get_volttron_multi_msgbus_instances.sink = sink return source, sink
def volttron_instance_web(request): print( "volttron_instance_web (messagebus {messagebus} ssl_auth {ssl_auth})". format(**request.param)) address = get_rand_vip() if request.param['ssl_auth']: hostname, port = get_hostname_and_random_port() web_address = 'https://{hostname}:{port}'.format(hostname=hostname, port=port) else: web_address = "http://{}".format(get_rand_ip_and_port()) wrapper = build_wrapper(address, ssl_auth=request.param['ssl_auth'], messagebus=request.param['messagebus'], bind_web_address=web_address, volttron_central_address=web_address) yield wrapper cleanup_wrapper(wrapper)
import pytest import gevent import logging import time from struct import pack, unpack from volttron.platform import get_services_core, jsonapi from platform_driver.interfaces.modbus_tk.server import Server from platform_driver.interfaces.modbus_tk.client import Client, Field from platform_driver.interfaces.modbus_tk import helpers from volttrontesting.utils.utils import get_rand_ip_and_port from volttron.platform.agent.known_identities import PLATFORM_DRIVER logger = logging.getLogger(__name__) IP, _port = get_rand_ip_and_port().split(":") PORT = int(_port) DRIVER_CONFIG = { "driver_config": { "device_address": IP, "port": PORT, "slave_id": 1 }, "driver_type": "modbus", "registry_config": "config://modbus.csv", "interval": 120, "timezone": "UTC" } # This registry configuration contains only required fields
def volttron_multi_messagebus(request): """ This fixture allows multiple two message bus types to be configured to work together This case will create a source (where data comes from) and a sink (where data goes to) to allow connections from source to sink to be tested for the different cases. In particular, the case of VolttronCentralPlatform, Forwarder and DataMover agents should use this case. :param request: :return: """ print("volttron_multi_messagebus source: {} sink: {}".format( request.param['source'], request.param['sink'])) sink_address = get_rand_vip() if request.param['sink'] == 'rmq_web': hostname, port = get_hostname_and_random_port() web_address = 'https://{hostname}:{port}'.format(hostname=hostname, port=port) messagebus = 'rmq' ssl_auth = True else: web_address = "http://{}".format(get_rand_ip_and_port()) messagebus = 'zmq' ssl_auth = False sink = build_wrapper(sink_address, ssl_auth=ssl_auth, messagebus=messagebus, bind_web_address=web_address, volttron_central_address=web_address) source_address = get_rand_vip() messagebus = 'zmq' ssl_auth = False if request.param['source'] == 'rmq': messagebus = 'rmq' ssl_auth = True if sink.messagebus == 'rmq': # sink_ca_file = sink.certsobj.cert_file(sink.certsobj.root_ca_name) source = build_wrapper(source_address, ssl_auth=ssl_auth, messagebus=messagebus, volttron_central_address=sink.bind_web_address, remote_platform_ca=sink.certsobj.cert_file( sink.certsobj.root_ca_name)) if source.messagebus == 'rmq': # The _ca is how the auth subsystem saves the remote cert from discovery. We # are effectively doing that here instead of making the discovery call. source.certsobj.save_remote_cert( sink.certsobj.root_ca_name + "_ca", sink.certsobj.ca_cert(public_bytes=True)) else: source = build_wrapper(source_address, ssl_auth=ssl_auth, messagebus=messagebus, volttron_central_address=sink.bind_web_address) yield source, sink cleanup_wrapper(source) cleanup_wrapper(sink)
def get_test_volttron_home(messagebus: str, web_https=False, web_http=False, has_vip=True, volttron_home: str = None, config_params: dict = None, env_options: dict = None): """ Create a full volttronn_home test environment with all of the options available in the environment (os.environ) and configuration file (volttron_home/config) in order to test from. @param messagebus: Currently supports rmq and zmq strings @param web_https: Determines if https should be used and enabled. If this is specified then the cert_fixtures.certs_profile_1 function will be used to generate certificates for the server and signed ca. Either web_https or web_http may be specified not both. @param has_vip: Allows the rmq message bus to not specify a vip address if backward compatibility is not needed. @param config_params: Configuration parameters that should go into the volttron configuration file, note if the basic ones are set via the previous arguments (i.e. web_https) then it is an error to specify bind-web-address (or other) duplicate. @param env_options: Other options that should be specified in the os.environ during the setup of this environment. """ # Make these not None so that we can use set operations on them to see if we have any overlap between # common configuration params and environment. if config_params is None: config_params = {} if env_options is None: env_options = {} # make a copy so we can restore in cleanup env_cpy = os.environ.copy() # start validating input assert messagebus in ( 'rmq', 'zmq'), 'Invalid messagebus specified, must be rmq or zmq.' if web_http and web_https: raise ValueError( "Incompatabile tyeps web_https and web_Http cannot both be specified as True" ) default_env_options = ('VOLTTRON_HOME', 'MESSAGEBUS') for v in default_env_options: if v in env_options: raise ValueError( f"Cannot specify {v} in env_options as it is set already.") # All is well.Create vhome if volttron_home: os.makedirs(volttron_home, exist_ok=True) else: volttron_home = create_volttron_home() # Create env envs = dict(VOLTTRON_HOME=volttron_home, MESSAGEBUS=messagebus) os.environ.update(envs) os.environ.update(env_options) # make the top level dirs os.mkdir(os.path.join(volttron_home, "agents")) os.mkdir(os.path.join(volttron_home, "configuration_store")) os.mkdir(os.path.join(volttron_home, "keystores")) os.mkdir(os.path.join(volttron_home, "run")) # create the certs. This will create the certs dirs web_certs_dir = os.path.join(volttron_home, "web_certs") web_certs = None if web_https: web_certs = certs_profile_1(web_certs_dir) vip_address = None bind_web_address = None web_ssl_cert = None web_ssl_key = None web_secret_key = None config_file = {} if messagebus == 'rmq': if has_vip: ip, port = get_rand_ip_and_port() vip_address = f"tcp://{ip}:{port}" web_https = True elif messagebus == 'zmq': if web_http or web_https: ip, port = get_rand_ip_and_port() vip_address = f"tcp://{ip}:{port}" if web_https: hostname, port = get_hostname_and_random_port() bind_web_address = f"https://{hostname}:{port}" web_ssl_cert = web_certs.server_certs[0].cert_file web_ssl_key = web_certs.server_certs[0].key_file elif web_http: hostname, port = get_hostname_and_random_port() bind_web_address = f"http://{hostname}:{port}" web_secret_key = get_random_key() if vip_address: config_file['vip-address'] = vip_address if bind_web_address: config_file['bind-web-address'] = bind_web_address if web_ssl_cert: config_file['web-ssl-cert'] = web_ssl_cert if web_ssl_key: config_file['web-ssl-key'] = web_ssl_key if web_secret_key: config_file['web-secret-key'] = web_secret_key config_intersect = set(config_file).intersection(set(config_params)) if len(config_intersect) > 0: raise ValueError( f"passed configuration params {list(config_intersect)} are built internally" ) config_file.update(config_params) update_platform_config(config_file) try: yield volttron_home finally: os.environ.clear() os.environ.update(env_cpy) if not os.environ.get("DEBUG", 0) != 1 and not os.environ.get( "DEBUG_MODE", 0): shutil.rmtree(volttron_home, ignore_errors=True)