def test_default_config(volttron_instance, cleanup_cache, query_agent): """ Test the default configuration file included with the agent """ locations = [{"station": "KLAX"}] publish_agent = volttron_instance.build_agent(identity="test_agent") gevent.sleep(1) config_path = os.path.join(get_services_core("WeatherDotGov"), "config") with open(config_path, "r") as config_file: config_json = json.load(config_file) assert isinstance(config_json, dict) volttron_instance.install_agent( agent_dir=get_services_core("WeatherDotGov"), config_file=config_json, start=True, vip_identity="health_test") assert publish_agent.vip.rpc.call("health_test", "health.get_status").get(timeout=10).get('status') == STATUS_GOOD query_data = query_agent.vip.rpc.call("health_test", 'get_current_weather', locations).get(timeout=30) print(query_data) assert len(query_data) == len(locations) for record in query_data: # check format here assert record.get("observation_time") assert record.get("station") # check weather error message results = record.get("weather_results")
def test_reinstall_agent(volttron_instance): sqlite_config = { "connection": { "type": "sqlite", "params": { "database": "data/historian.sqlite" } } } auuid = volttron_instance.install_agent( agent_dir=get_services_core("SQLHistorian"), config_file=sqlite_config, start=True, vip_identity='test_historian') assert volttron_instance.is_agent_running(auuid) newuuid = volttron_instance.install_agent( agent_dir=get_services_core("SQLHistorian"), config_file=sqlite_config, start=True, force=True, vip_identity='test_historian') assert volttron_instance.is_agent_running(newuuid) assert auuid != newuuid and auuid is not None volttron_instance.remove_agent(newuuid)
def test_default_config(volttron_instance): """ Test the default configuration file included with the agent """ publish_agent = volttron_instance.build_agent(identity="test_agent") gevent.sleep(1) config_path = os.path.join(get_services_core("MarketServiceAgent"), "config") with open(config_path, "r") as config_file: config_json = json.load(config_file) assert isinstance(config_json, dict) volttron_instance.install_agent( agent_dir=get_services_core("MarketServiceAgent"), config_file=config_json, start=True, vip_identity="health_test") assert publish_agent.vip.rpc.call( "health_test", "health.get_status").get(timeout=10).get('status') == STATUS_GOOD # perform basic sanity check market_name = 'test_market' buyer_participant = MarketParticipant(BUYER, 'agent_id1') publish_agent.vip.rpc.call("health_test", "make_reservation", market_name, buyer_participant.buyer_seller)
def agent(request, volttron_instance): """Build MasterDriverAgent and add DNP3 driver config to it.""" def update_config(agent_id, name, value, cfg_type): test_agent.vip.rpc.call('config.store', 'manage_store', agent_id, name, value, config_type=cfg_type) test_agent = volttron_instance.build_agent() # Build and start DNP3Agent dnp3_agent_uuid = volttron_instance.install_agent(agent_dir=get_services_core("DNP3Agent"), config_file=DNP3_AGENT_CONFIG, vip_identity=DNP3_AGENT_ID, start=True) # Build and start MasterDriverAgent test_agent.vip.rpc.call('config.store', 'manage_delete_store', MASTER_DRIVER_AGENT_ID) update_config(MASTER_DRIVER_AGENT_ID, 'devices/dnp3', DRIVER_CONFIG_STRING, 'json') update_config(MASTER_DRIVER_AGENT_ID, 'dnp3.csv', REGISTRY_CONFIG_STRING, 'csv') master_uuid = volttron_instance.install_agent(agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) gevent.sleep(3) # Wait for the agent to start and start the devices def stop(): volttron_instance.stop_agent(master_uuid) volttron_instance.stop_agent(dnp3_agent_uuid) test_agent.core.stop() request.addfinalizer(stop) return test_agent
def vc_and_vcp_together(volttron_instance_web): if volttron_instance_web.ssl_auth is True: os.environ[ 'REQUESTS_CA_BUNDLE'] = volttron_instance_web.requests_ca_bundle vc_uuid = volttron_instance_web.install_agent( agent_dir=get_services_core("VolttronCentral"), config_file=VC_CONFIG, start=True) # Allow all incoming zmq based connections. volttron_instance_web.allow_all_connections() # Allow all rmq based csr connections. if volttron_instance_web.messagebus == 'rmq': volttron_instance_web.enable_auto_csr() gevent.sleep(7) # vcp_config = PLATFORM_AGENT_CONFIG.copy() # vcp_config['volttron-central-address'] = volttron_instance_web.bind_web_address vcp_uuid = volttron_instance_web.install_agent( agent_dir=get_services_core("VolttronCentralPlatform"), config_file=PLATFORM_AGENT_CONFIG, start=True) gevent.sleep(7) yield volttron_instance_web volttron_instance_web.remove_agent(vc_uuid) volttron_instance_web.remove_agent(vcp_uuid)
def agent(request, volttron_instance_module_web): test_agent = volttron_instance_module_web.build_agent( identity="test_agent") capabilities = {'edit_config_store': {'identity': PLATFORM_DRIVER}} volttron_instance_module_web.add_capabilities(test_agent.core.publickey, capabilities) # Configure a IEEE 2030.5 device in the Master Driver test_agent.vip.rpc.call('config.store', 'manage_delete_store', PLATFORM_DRIVER).get(timeout=10) test_agent.vip.rpc.call( 'config.store', 'manage_store', PLATFORM_DRIVER, 'devices/{}'.format(DRIVER_NAME), """{ "driver_config": { "sfdi": "097935300833", "IEEE2030_5_agent_id": "test_IEEE2030_5agent" }, "campus": "campus", "building": "building", "unit": "IEEE2030_5", "driver_type": "IEEE2030_5", "registry_config": "config://IEEE2030_5.csv", "interval": 15, "timezone": "US/Pacific", "heart_beat_point": "Heartbeat" }""", 'json').get(timeout=10) test_agent.vip.rpc.call('config.store', 'manage_store', PLATFORM_DRIVER, 'IEEE2030_5.csv', REGISTRY_CONFIG_STRING, 'csv').get(timeout=10) # Install and start a IEEE2030_5Agent IEEE2030_5_id = volttron_instance_module_web.install_agent( agent_dir=get_services_core("IEEE2030_5Agent"), config_file=TEST_IEEE2030_5_CONFIG, vip_identity='test_IEEE2030_5agent', start=True) print('IEEE2030_5 agent id: ', IEEE2030_5_id) # Install and start a MasterDriverAgent md_id = volttron_instance_module_web.install_agent( agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) print('master driver agent id: ', md_id) global web_address web_address = volttron_instance_module_web.bind_web_address def stop(): volttron_instance_module_web.stop_agent(md_id) volttron_instance_module_web.stop_agent(IEEE2030_5_id) test_agent.core.stop() gevent.sleep(3) # wait for agents and devices to start request.addfinalizer(stop) return test_agent
def test_agent(request, get_volttron_instances): """ Fixture that initializes VOLTTRON agents for ReferenceAppAgent test cases. Start a VOLTTRON instance running a web agent, then install and start an OpenADRVenAgent, a ReferenceAppAgent, a SimulationDriverAgent, an ActuatorAgent, and a test agent. """ instance = get_volttron_instances(1, should_start=False) start_wrapper_platform(instance, with_http=True) # Install and start a WebAgent. web_agent = _build_web_agent(instance.volttron_home) gevent.sleep(1) web_agent_uuid = instance.install_agent(agent_dir=web_agent) global web_server_address web_server_address = instance.bind_web_address global volttron_home volttron_home = instance.volttron_home def issue_config_rpc(test_agt, config_request, *args): return test_agt.vip.rpc.call('config.store', config_request, SIMULATION_DRIVER_ID, *args).get(timeout=10) def start_agent(id, dir, config): return instance.install_agent(vip_identity=id, agent_dir=dir, config_file=config, start=True) test_agt = instance.build_agent(identity=TEST_AGENT_ID) issue_config_rpc(test_agt, 'manage_delete_store') for param_dict in DRIVER_PARAMS: device_id = param_dict['id'] issue_config_rpc(test_agt, 'manage_store', 'devices/campus1/building1/{}'.format(device_id), param_dict['config'], 'json') issue_config_rpc(test_agt, 'manage_store', '{}.csv'.format(device_id), param_dict['points'], 'csv') clock_uuid = start_agent(SIMULATION_CLOCK_ID, 'applications/kisensum/Simulation/SimulationClockAgent', SIMULATION_CLOCK_CONFIG) sim_driver_uuid = start_agent(SIMULATION_DRIVER_ID, 'applications/kisensum/Simulation/SimulationDriverAgent', {}) actuator_uuid = start_agent(ACTUATOR_ID, get_services_core('ActuatorAgent'), ACTUATOR_CONFIG) ven_uuid = start_agent(VEN_AGENT_ID, get_services_core('OpenADRVenAgent'), VEN_AGENT_CONFIG) ref_app_uuid = start_agent(REFERENCE_APP_ID, 'applications/kisensum/ReferenceAppAgent', REFERENCE_APP_CONFIG) def stop(): instance.stop_agent(actuator_uuid) instance.stop_agent(ref_app_uuid) instance.stop_agent(sim_driver_uuid) instance.stop_agent(ven_uuid) instance.stop_agent(clock_uuid) instance.stop_agent(web_agent_uuid) test_agt.core.stop() instance.shutdown_platform() gevent.sleep(10) request.addfinalizer(stop) yield test_agt
def failover(request, get_volttron_instances): global primary_config global secondary_config global primary_failover global secondary_failover global vc_uuid primary, secondary, vc = get_volttron_instances(3) primary.allow_all_connections() secondary.allow_all_connections() vc.allow_all_connections() # configure vc vc_uuid = vc.install_agent( agent_dir=get_services_core("VolttronCentralPlatform")) # configure primary primary_platform = primary.install_agent( agent_dir=get_services_core("VolttronCentralPlatform")) # register with vc primary_listener = primary.install_agent(agent_dir=get_examples("ListenerAgent"), vip_identity="listener", start=False) primary_config["remote_vip"] = tcp_to(secondary) primary_failover = primary.install_agent(agent_dir=get_services_core("FailoverAgent"), config_file=primary_config) # configure secondary secondary_platform = secondary.install_agent(agent_dir=get_services_core("VolttronCentralPlatform")) # register with vc secondary_listener = secondary.install_agent(agent_dir=get_examples("ListenerAgent"), vip_identity="listener", start=False) secondary_config["remote_vip"] = tcp_to(primary) secondary_failover = secondary.install_agent(agent_dir=get_services_core("FailoverAgent"), config_file=secondary_config) def stop(): vc.stop_agent(vc_uuid) vc.shutdown_platform() primary.stop_agent(primary_failover) primary.stop_agent(primary_platform) primary.stop_agent(primary_listener) primary.shutdown_platform() secondary.stop_agent(secondary_failover) secondary.stop_agent(secondary_platform) secondary.stop_agent(secondary_listener) secondary.shutdown_platform() request.addfinalizer(stop) return primary, secondary, vc
def agent(request, volttron_instance_module_web): test_agent = volttron_instance_module_web.build_agent() # Configure a SEP2 device in the Master Driver test_agent.vip.rpc.call('config.store', 'manage_delete_store', 'platform.driver').get(timeout=10) test_agent.vip.rpc.call( 'config.store', 'manage_store', 'platform.driver', 'devices/{}'.format(DRIVER_NAME), """{ "driver_config": { "sfdi": "097935300833", "sep2_agent_id": "test_sep2agent" }, "campus": "campus", "building": "building", "unit": "sep2", "driver_type": "sep2", "registry_config": "config://sep2.csv", "interval": 15, "timezone": "US/Pacific", "heart_beat_point": "Heartbeat" }""", 'json').get(timeout=10) test_agent.vip.rpc.call('config.store', 'manage_store', 'platform.driver', 'sep2.csv', REGISTRY_CONFIG_STRING, 'csv').get(timeout=10) # Install and start a MasterDriverAgent md_id = volttron_instance_module_web.install_agent( agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) print('master driver agent id: ', md_id) # Install and start a SEP2Agent sep2_id = volttron_instance_module_web.install_agent( agent_dir=get_services_core("SEP2Agent"), config_file=TEST_CONFIG, vip_identity='test_sep2agent', start=True) print('sep2 agent id: ', sep2_id) global web_address web_address = volttron_instance_module_web.bind_web_address def stop(): volttron_instance_module_web.stop_agent(md_id) volttron_instance_module_web.stop_agent(sep2_id) test_agent.core.stop() gevent.sleep(10) # wait for agents and devices to start request.addfinalizer(stop) return test_agent
def agent(request, volttron_instance_module_web): test_agent = volttron_instance_module_web.build_agent() # Configure a SEP2 device in the Master Driver test_agent.vip.rpc.call('config.store', 'manage_delete_store', 'platform.driver').get(timeout=10) test_agent.vip.rpc.call('config.store', 'manage_store', 'platform.driver', 'devices/{}'.format(DRIVER_NAME), """{ "driver_config": { "sfdi": "097935300833", "sep2_agent_id": "test_sep2agent" }, "campus": "campus", "building": "building", "unit": "sep2", "driver_type": "sep2", "registry_config": "config://sep2.csv", "interval": 15, "timezone": "US/Pacific", "heart_beat_point": "Heartbeat" }""", 'json').get(timeout=10) test_agent.vip.rpc.call('config.store', 'manage_store', 'platform.driver', 'sep2.csv', REGISTRY_CONFIG_STRING, 'csv').get(timeout=10) # Install and start a SEP2Agent sep2_id = volttron_instance_module_web.install_agent(agent_dir=get_services_core("SEP2Agent"), config_file=TEST_SEP2_CONFIG, vip_identity='test_sep2agent', start=True) print('sep2 agent id: ', sep2_id) # Install and start a MasterDriverAgent md_id = volttron_instance_module_web.install_agent(agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) print('master driver agent id: ', md_id) global web_address web_address = volttron_instance_module_web.bind_web_address def stop(): volttron_instance_module_web.stop_agent(md_id) volttron_instance_module_web.stop_agent(sep2_id) test_agent.core.stop() gevent.sleep(3) # wait for agents and devices to start request.addfinalizer(stop) return test_agent
def test_default_config(volttron_instances, query_agent): """ Test the default configuration file included with the agent """ global volttron_instance1 publish_agent = volttron_instance1.build_agent(identity="test_agent") gevent.sleep(1) config_path = os.path.join(get_services_core("ForwardHistorian"), "config") with open(config_path, "r") as config_file: config_json = json.load(config_file) assert isinstance(config_json, dict) volttron_instance1.install_agent( agent_dir=get_services_core("ForwardHistorian"), config_file=config_json, start=True, vip_identity="health_test") assert publish_agent.vip.rpc.call( "health_test", "health.get_status").get(timeout=10).get('status') == STATUS_GOOD # do basic sanity check oat_reading = random.uniform(30, 100) float_meta = {'units': 'F', 'tz': 'UTC', 'type': 'float'} all_message = [{ 'OutsideAirTemperature': oat_reading }, { 'OutsideAirTemperature': float_meta }] time1 = utils.format_timestamp(datetime.utcnow()) headers = {headers_mod.DATE: time1} publish(publish_agent, 'devices/PNNL/BUILDING_1/Device/all', headers, all_message) gevent.sleep(1) result = query_agent.vip.rpc.call( 'platform.historian', 'query', topic='PNNL/BUILDING1_ANON/Device/OutsideAirTemperature', start=time1, count=20, order="LAST_TO_FIRST").get(timeout=10) assert (len(result['values']) == 1) (time1_date, time1_time) = time1.split("T") assert (result['values'][0][0] == time1_date + 'T' + time1_time + '+00:00') assert (result['values'][0][1] == approx(oat_reading)) assert set(result['metadata'].items()) == set(float_meta.items())
def simple_failover(request, get_volttron_instances): global simple_primary_config global simple_secondary_config global uuid_primary global uuid_secondary global listener_primary primary, secondary = get_volttron_instances(2) primary.allow_all_connections() secondary.allow_all_connections() # configure primary listener_primary = primary.install_agent( agent_dir=get_examples("ListenerAgent"), vip_identity="listener", start=False) simple_primary_config["remote_vip"] = secondary.vip_address simple_primary_config["remote_serverkey"] = secondary.serverkey uuid_primary = primary.install_agent( agent_dir=get_services_core("FailoverAgent"), config_file=simple_primary_config) # configure secondary listener_secondary = secondary.install_agent( agent_dir=get_examples("ListenerAgent"), vip_identity="listener", start=False) simple_secondary_config["remote_vip"] = primary.vip_address simple_secondary_config["remote_serverkey"] = primary.serverkey uuid_secondary = secondary.install_agent( agent_dir=get_services_core("FailoverAgent"), config_file=simple_secondary_config) gevent.sleep(SLEEP_TIME) assert all_agents_running(primary) assert not all_agents_running(secondary) def cleanup(): primary.stop_agent(uuid_primary) primary.stop_agent(listener_primary) primary.shutdown_platform() secondary.stop_agent(uuid_secondary) secondary.stop_agent(listener_secondary) secondary.shutdown_platform() request.addfinalizer(cleanup) return primary, secondary
def test_default_config(volttron_instance, query_agent, cleanup_cache): """ Test the default configuration file included with the agent """ locations = [{"lat": 39.7555, "long": -105.2211}] publish_agent = volttron_instance.build_agent(identity="test_agent") gevent.sleep(1) config_path = os.path.join(get_services_core("Darksky"), "config") with open(config_path, "r") as config_file: config_json = json.load(config_file) assert isinstance(config_json, dict) config_json["api_key"] = API_KEY volttron_instance.install_agent( agent_dir=get_services_core("Darksky"), config_file=config_json, start=True, vip_identity="health_test") assert publish_agent.vip.rpc.call("health_test", "health.get_status").get(timeout=10).get('status') == STATUS_GOOD query_data = query_agent.vip.rpc.call("health_test", 'get_current_weather', locations).get(timeout=30) if query_data[0].get("weather_error"): error = query_data[0].get("weather_error") if error.endswith("Remote API returned Code 403"): pytest.skip("API key has exceeded daily call limit") print(query_data) assert len(query_data) == len(locations) for record in query_data: # check format here assert record.get("observation_time") assert (record.get("lat") and record.get("long")) results = record.get("weather_results") if results: assert isinstance(results, dict) assert "data" not in results assert results["attribution"] == "Powered by Dark Sky" else: results = record.get("weather_error") if results.startswith("Remote API returned no data") or \ results.startswith("Remote API redirected request, but redirect failed") \ or results.startswith("Remote API returned invalid response") \ or results.startswith("API request failed with unexpected response"): assert True else: assert False
def agent(request, volttron_instance): """Build PlatformDriverAgent and add DNP3 driver config to it.""" test_agent = volttron_instance.build_agent() def update_config(agent_id, name, value, cfg_type): test_agent.vip.rpc.call('config.store', 'manage_store', agent_id, name, value, config_type=cfg_type) capabilities = {'edit_config_store': {'identity': PLATFORM_DRIVER}} volttron_instance.add_capabilities(test_agent.core.publickey, capabilities) gevent.sleep(1) # Build and start DNP3Agent dnp3_agent_uuid = volttron_instance.install_agent( agent_dir=get_services_core("DNP3Agent"), config_file=DNP3_AGENT_CONFIG, vip_identity=DNP3_AGENT_ID, start=True) # Build and start PlatformDriverAgent test_agent.vip.rpc.call('config.store', 'manage_delete_store', PLATFORM_DRIVER) platform_uuid = volttron_instance.install_agent( agent_dir=get_services_core("PlatformDriverAgent"), config_file={}, start=True) update_config(PLATFORM_DRIVER, 'devices/dnp3', DRIVER_CONFIG_STRING, 'json') update_config(PLATFORM_DRIVER, 'dnp3.csv', REGISTRY_CONFIG_STRING, 'csv') # Wait for the agent to start and start the devices gevent.sleep(3) def stop(): volttron_instance.stop_agent(platform_uuid) volttron_instance.stop_agent(dnp3_agent_uuid) test_agent.core.stop() request.addfinalizer(stop) return test_agent
def vc_instance(request, volttron_instance1_web): """ Creates an instance of volttron with a `VolttronCentral` agent already installed and started. :returns tuple: - the PlatformWrapper - the uuid of the `VolttronCentral` agent. - the jsonrpc address to be used for communicating with the `VolttronCentral` agent. """ agent_uuid = volttron_instance1_web.install_agent( agent_dir=get_services_core("VolttronCentral"), config_file=VC_CONFIG, start=True) rpc_addr = volttron_instance1_web.jsonrpc_endpoint # Allow all incoming connections that are encrypted. volttron_instance1_web.allow_all_connections() def cleanup(): print('Cleanup vc_instance') volttron_instance1_web.remove_agent(agent_uuid) print_log(volttron_instance1_web.volttron_home) request.addfinalizer(cleanup) return volttron_instance1_web, agent_uuid, rpc_addr
def vc_instance(request, volttron_instance1_web): """ Creates an instance of volttron with a `VolttronCentral` agent already installed and started. :returns tuple: - the PlatformWrapper - the uuid of the `VolttronCentral` agent. - the jsonrpc address to be used for communicating with the `VolttronCentral` agent. """ agent_uuid = volttron_instance1_web.install_agent( agent_dir=get_services_core("VolttronCentral"), config_file=VC_CONFIG, start=True ) rpc_addr = volttron_instance1_web.jsonrpc_endpoint # Allow all incoming connections that are encrypted. volttron_instance1_web.allow_all_connections() def cleanup(): print('Cleanup vc_instance') volttron_instance1_web.remove_agent(agent_uuid) print_log(volttron_instance1_web.volttron_home) request.addfinalizer(cleanup) return volttron_instance1_web, agent_uuid, rpc_addr
def test_poll_valid(volttron_instance, publish_agent, locations, result_topics): global publish_agent_v2, API_KEY uuid = None try: config = { "operation_mode": 2, "wu_api_key": API_KEY, "locations": locations, "poll_time": 20 } uuid = volttron_instance.install_agent( vip_identity='weather_agent', agent_dir=get_services_core("WeatherAgent"), config_file=config, start=False) # reset mock to ignore any previous callback publish_agent.process_poll_result.reset_mock() publish_agent.process_error.reset_mock() volttron_instance.start_agent(uuid) gevent.sleep(10) assert publish_agent.process_poll_result.call_count == len(locations) assert publish_agent.process_error.call_count == 0 call_args_list = publish_agent.process_poll_result.call_args_list i = 0 for args in call_args_list: assert args[0][3] == result_topics[i] assert_weather_response(args[0]) i += 1 finally: if uuid: volttron_instance.remove_agent(uuid)
def agent(request, volttron_instance): """Build the test agent for rpc call.""" test_agent = volttron_instance.build_agent(identity="test_agent") capabilities = {'edit_config_store': {'identity': 'dnp3agent'}} volttron_instance.add_capabilities(test_agent.core.publickey, capabilities) add_definitions_to_config_store(test_agent) print('Installing DNP3Agent') os.environ['AGENT_MODULE'] = 'dnp3.agent' agent_id = volttron_instance.install_agent(agent_dir=get_services_core("DNP3Agent"), config_file=AGENT_CONFIG, vip_identity=DNP3_AGENT_ID, start=True) # Subscribe to DNP3 point publication test_agent.vip.pubsub.subscribe(peer='pubsub', prefix=POINT_TOPIC, callback=onmessage) def stop(): """Stop test agent.""" if volttron_instance.is_running(): volttron_instance.stop_agent(agent_id) volttron_instance.remove_agent(agent_id) test_agent.core.stop() gevent.sleep(12) # wait for agents and devices to start request.addfinalizer(stop) return test_agent
def agent(request, volttron_instance): agent = volttron_instance.build_agent() # Clean out master driver configurations. agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_delete_store', PLATFORM_DRIVER).get(timeout=10) #Add test configurations. agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_store', PLATFORM_DRIVER, "devices/campus/building/unit", driver_config_dict_string, "json").get(timeout=10) agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_store', PLATFORM_DRIVER, "restful.csv", restful_csv_string, "csv").get(timeout=10) master_uuid = volttron_instance.install_agent( agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) print("agent id: ", master_uuid) gevent.sleep(2) # wait for the agent to start and start the devices server = pywsgi.WSGIServer((ip, int(port)), handle) server.start() def stop(): volttron_instance.stop_agent(master_uuid) agent.core.stop() server.stop() request.addfinalizer(stop) return agent
def test_reconnect_forwarder(get_volttron_instances): from_instance, to_instance = get_volttron_instances(2, True) to_instance.allow_all_connections() publisher = from_instance.build_agent() receiver = to_instance.build_agent() forwarder_config = deepcopy(BASE_FORWARD_CONFIG) #forwardtoaddr = build_vip_address(to_instance, receiver) #print("FORWARD ADDR: {}".format(forwardtoaddr)) forwarder_config['destination-vip'] = to_instance.vip_address forwarder_config['destination-serverkey'] = to_instance.keystore.public fuuid = from_instance.install_agent( agent_dir=get_services_core("ForwardHistorian"),start=True, config_file=forwarder_config) assert from_instance.is_agent_running(fuuid) print('Before Subscribing') receiver.vip.pubsub.subscribe('pubsub', '', callback=onmessage) publisher.vip.pubsub.publish('pubsub', 'stuff', message='Fuzzy') gevent.sleep(.2) num_messages = 5 for i in range(num_messages): do_publish(publisher) for i in range(len(publishedmessages)): assert allforwardedmessage[i] == publishedmessages[i]
def agent(volttron_instance): agent = volttron_instance.build_agent(identity="test_agent") capabilities = {'edit_config_store': {'identity': PLATFORM_DRIVER}} volttron_instance.add_capabilities(agent.core.publickey, capabilities) # Clean out platform driver configurations. agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_delete_store', PLATFORM_DRIVER).get(timeout=10) # Add test configurations. agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_store', PLATFORM_DRIVER, "devices/campus/building/unit", driver_config_string, "json").get(timeout=10) agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_store', PLATFORM_DRIVER, "eagle.json", register_config_string, "json").get(timeout=10) platform_uuid = volttron_instance.install_agent( agent_dir=get_services_core("PlatformDriverAgent"), config_file={}, start=True) print("agent id: ", platform_uuid) gevent.sleep(2) # wait for the agent to start and start the devices server = pywsgi.WSGIServer((ip, int(port)), handle) server.start() yield agent volttron_instance.stop_agent(platform_uuid) agent.core.stop() server.stop()
def test_reconnect_forwarder(get_volttron_instances): from_instance, to_instance = get_volttron_instances(2, True) to_instance.allow_all_connections() publisher = from_instance.build_agent() receiver = to_instance.build_agent() forwarder_config = deepcopy(BASE_FORWARD_CONFIG) #forwardtoaddr = build_vip_address(to_instance, receiver) #print("FORWARD ADDR: {}".format(forwardtoaddr)) forwarder_config['destination-vip'] = to_instance.vip_address forwarder_config['destination-serverkey'] = to_instance.keystore.public fuuid = from_instance.install_agent( agent_dir=get_services_core("ForwardHistorian"), start=True, config_file=forwarder_config) assert from_instance.is_agent_running(fuuid) print('Before Subscribing') receiver.vip.pubsub.subscribe('pubsub', '', callback=onmessage) publisher.vip.pubsub.publish('pubsub', 'stuff', message='Fuzzy') gevent.sleep(3) num_messages = 5 for i in range(num_messages): do_publish(publisher) for i in range(len(publishedmessages)): assert allforwardedmessage[i] == approx(publishedmessages[i])
def vtn_request(service_name, xml_filename, event_id=None, event_start_time=None, event_duration=None): """ Push a VTN request to the VEN, sending the contents of the indicated XML file. @param service_name: The service name as it appears in the URL. @param xml_filename: The distinguishing part of the sample data file name. @param event_id: The event ID. @param event_start_time: The time that the test event should become active. Modifies the XML string. @param event_duration: The test event's duration. Modifies the XML string. """ global web_server_address xml_filename = get_services_core( "OpenADRVenAgent/test/xml/{}.xml".format(xml_filename)) with open(xml_filename, 'r') as xml_file: xml_string = xml_file.read() if event_id: # Modify the XML, substituting in a custom event ID, start_time and duration. xml_string = xml_string.format( event_id=event_id, event_start_time=event_start_time, event_duration=event_duration) requests.post('{}/OpenADR2/Simple/2.0b/{}'.format( web_server_address, service_name), data=xml_string, headers={'content-type': 'application/xml'}) time.sleep(POLL_INTERVAL_SECS + 1) # Wait for the request to be dequeued and handled.
def agent(volttron_instance1): agent = volttron_instance1.build_agent() # Clean out master driver configurations. agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_delete_store', PLATFORM_DRIVER).get(timeout=10) #Add test configurations. agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_store', PLATFORM_DRIVER, "devices/campus/building/unit", driver_config_string, "json").get(timeout=10) agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_store', PLATFORM_DRIVER, "eagle.json", register_config_string, "json").get(timeout=10) master_uuid = volttron_instance1.install_agent( agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) print("agent id: ", master_uuid) gevent.sleep(2) # wait for the agent to start and start the devices server = pywsgi.WSGIServer((ip, int(port)), handle) server.start() yield agent volttron_instance1.stop_agent(master_uuid) agent.core.stop() server.stop()
def multi_messagebus_forwarder(volttron_multi_messagebus): from_instance, to_instance = volttron_multi_messagebus to_instance.allow_all_connections() forwarder_config = {"custom_topic_list": ["foo"]} if to_instance.messagebus == 'rmq': remote_address = to_instance.bind_web_address to_instance.enable_auto_csr() print("REQUEST CA: {}".format(os.environ.get('REQUESTS_CA_BUNDLE'))) os.environ['REQUESTS_CA_BUNDLE'] = to_instance.requests_ca_bundle forwarder_config['destination-address'] = remote_address else: remote_address = to_instance.vip_address forwarder_config['destination-vip'] = remote_address forwarder_config['destination-serverkey'] = to_instance.serverkey forwarder_uuid = from_instance.install_agent( agent_dir=get_services_core("ForwardHistorian"), config_file=forwarder_config, start=True) gevent.sleep(1) assert from_instance.is_agent_running(forwarder_uuid) yield from_instance, to_instance from_instance.stop_agent(forwarder_uuid)
def agent(request, volttron_instance): """Build the test agent for rpc call.""" test_agent = volttron_instance.build_agent() add_definitions_to_config_store(test_agent) print('Installing Mesa Agent') os.environ['AGENT_MODULE'] = 'dnp3.mesa.agent' agent_id = volttron_instance.install_agent(agent_dir=get_services_core("DNP3Agent"), config_file=MESA_AGENT_CONFIG, vip_identity=MESA_AGENT_ID, start=True) # Subscribe to MESA functions test_agent.vip.pubsub.subscribe(peer='pubsub', prefix='mesa/function', callback=onmessage) def stop(): """Stop test agent.""" if volttron_instance.is_running(): volttron_instance.stop_agent(agent_id) volttron_instance.remove_agent(agent_id) test_agent.core.stop() gevent.sleep(3) # wait for agents and devices to start request.addfinalizer(stop) return test_agent
def test_poll_valid(volttron_instance, publish_agent, locations, result_topics): global publish_agent_v2, API_KEY uuid = None try: config = { "operation_mode": 2, "wu_api_key": API_KEY, "locations": locations, "poll_time": 20 } uuid = volttron_instance.install_agent( vip_identity='weather_agent', agent_dir=get_services_core("WeatherUndergroundAgent"), config_file=config, start=False) # reset mock to ignore any previous callback publish_agent.process_poll_result.reset_mock() publish_agent.process_error.reset_mock() volttron_instance.start_agent(uuid) gevent.sleep(10) assert publish_agent.process_poll_result.call_count == len(locations) assert publish_agent.process_error.call_count == 0 call_args_list = publish_agent.process_poll_result.call_args_list i = 0 for args in call_args_list: assert args[0][3] == result_topics[i] assert_weather_response(args[0]) i += 1 finally: if uuid: volttron_instance.remove_agent(uuid)
def add_forward_historian(wrapper, config={}, **kwargs): agent_uuid = wrapper.install_agent( config_file=config, agent_dir=get_services_core("ForwardHistorian"), **kwargs ) return agent_uuid
def forwarder(request, volttron_instances): global volttron_instance1, volttron_instance2 global datamover_uuid, datamover_config # 1. Update destination address in forwarder configuration volttron_instance1.allow_all_connections() volttron_instance2.allow_all_connections() datamover_config["destination-vip"] = volttron_instance2.vip_address known_hosts_file = os.path.join(volttron_instance1.volttron_home, 'known_hosts') known_hosts = KnownHostsStore(known_hosts_file) known_hosts.add(volttron_instance2.vip_address, volttron_instance2.serverkey) # setup destination address to include keys datamover_config["destination-serverkey"] = volttron_instance2.serverkey # 1: Install historian agent # Install and start sqlhistorian agent in instance2 datamover_uuid = volttron_instance1.install_agent( agent_dir=get_services_core("DataMover"), config_file=datamover_config, start=True) print("forwarder agent id: ", datamover_uuid)
def forwarder(request, volttron_instances): #print "Fixture forwarder" global volttron_instance1, volttron_instance2 global forwarder_uuid, forwarder_config # 1. Update destination address in forwarder configuration volttron_instance1.allow_all_connections() volttron_instance2.allow_all_connections() # setup destination address to include keys known_hosts_file = os.path.join(volttron_instance1.volttron_home, 'known_hosts') known_hosts = KnownHostsStore(known_hosts_file) known_hosts.add(volttron_instance2.vip_address, volttron_instance2.serverkey) forwarder_config["destination-vip"] = volttron_instance2.vip_address forwarder_config["destination-serverkey"] = volttron_instance2.serverkey # 1: Install historian agent # Install and start sqlhistorian agent in instance2 forwarder_uuid = volttron_instance1.install_agent( agent_dir=get_services_core("ForwardHistorian"), config_file=forwarder_config, start=True) print("forwarder agent id: ", forwarder_uuid)
def config_store_connection(request, volttron_instance): capabilities = [{'edit_config_store': {'identity': PLATFORM_DRIVER}}] connection = volttron_instance.build_connection(peer=CONFIGURATION_STORE, capabilities=capabilities) gevent.sleep(1) # Reset platform driver config store connection.call("manage_delete_store", PLATFORM_DRIVER) # Start the platform driver agent which would in turn start the fake driver # using the configs created above platform_uuid = volttron_instance.install_agent( agent_dir=get_services_core("PlatformDriverAgent"), config_file={}, start=True) print("agent id: ", platform_uuid) gevent.sleep(2) # wait for the agent to start and start the devices def stop_agent(): volttron_instance.stop_agent(platform_uuid) volttron_instance.remove_agent(platform_uuid) connection.kill() request.addfinalizer(stop_agent) return connection
def test_resinstall_agent(volttron_instance): mysql_config = { "connection": { "type": "mysql", "params": { "host": "localhost", "port": 3306, "database": "test_historian", "user": "******", "passwd": "historian" } } } for i in range(0,50): print("Counter: {}".format(i)) # auuid = volttron_instance.install_agent( # agent_dir=get_examples("ListenerAgent", # vip_identity='test_listener', # start=True) auuid = volttron_instance.install_agent( agent_dir=get_services_core("SQLHistorian"), config_file=mysql_config, start=True, vip_identity='test_historian') assert volttron_instance.is_agent_running(auuid) volttron_instance.remove_agent(auuid)
def vc_instance(volttron_instance_web): """ Creates an instance of volttron with a `VolttronCentral` agent already installed and started. :returns tuple: - the PlatformWrapper - the uuid of the `VolttronCentral` agent. - the jsonrpc address to be used for communicating with the `VolttronCentral` agent. """ if not volttron_instance_web.get_agent_identity(VOLTTRON_CENTRAL): agent_uuid = volttron_instance_web.install_agent( agent_dir=get_services_core("VolttronCentral"), config_file=VC_CONFIG, vip_identity=VOLTTRON_CENTRAL, start=True) rpc_addr = volttron_instance_web.jsonrpc_endpoint # Allow all incoming zmq based connections. volttron_instance_web.allow_all_connections() # Allow all rmq based csr connections. if volttron_instance_web.messagebus == 'rmq': volttron_instance_web.enable_auto_csr() # volttron_instance_web.web_admin_api.create_web_admin('admin', 'admin') yield volttron_instance_web, agent_uuid, rpc_addr volttron_instance_web.remove_agent(agent_uuid)
def add_volttron_central_platform(wrapper, config={}, **kwargs): print('Adding vcp to {}'.format(wrapper.vip_address)) agent_uuid = wrapper.install_agent( config_file=config, agent_dir=get_services_core("VolttronCentralPlatform"), vip_identity=VOLTTRON_CENTRAL_PLATFORM) return agent_uuid
def test_base_historian(volttron_instance): global foundtopic v1 = volttron_instance assert v1.is_running() master_config = prep_config(v1.volttron_home) master_uuid = v1.install_agent( agent_dir=get_services_core("MasterDriverAgent"), config_file=master_config) gevent.sleep(2) db = Historian({}, address=v1.vip_address[0], backup_storage_limit_gb=0.00002) gevent.spawn(db.core.run).join(0) agent = v1.build_agent() gevent.sleep(2) agent.vip.pubsub.subscribe('pubsub', 'backupdb/nomore', callback=listener) for _ in range(0, 60): gevent.sleep(1) if foundtopic: break assert foundtopic
def simple_failover(request, get_volttron_instances): global simple_primary_config global simple_secondary_config global uuid_primary global uuid_secondary global listener_primary primary, secondary = get_volttron_instances(2) primary.allow_all_connections() secondary.allow_all_connections() # configure primary listener_primary = primary.install_agent(agent_dir=get_examples("ListenerAgent"), vip_identity="listener", start=False) simple_primary_config["remote_vip"] = secondary.vip_address simple_primary_config["remote_serverkey"] = secondary.serverkey uuid_primary = primary.install_agent(agent_dir=get_services_core("FailoverAgent"), config_file=simple_primary_config) # configure secondary listener_secondary = secondary.install_agent(agent_dir=get_examples("ListenerAgent"), vip_identity="listener", start=False) simple_secondary_config["remote_vip"] = primary.vip_address simple_secondary_config["remote_serverkey"] = primary.serverkey uuid_secondary = secondary.install_agent(agent_dir=get_services_core("FailoverAgent"), config_file=simple_secondary_config) gevent.sleep(SLEEP_TIME) assert all_agents_running(primary) assert not all_agents_running(secondary) def cleanup(): primary.stop_agent(uuid_primary) primary.stop_agent(listener_primary) primary.shutdown_platform() secondary.stop_agent(uuid_secondary) secondary.stop_agent(listener_secondary) secondary.shutdown_platform() request.addfinalizer(cleanup) return primary, secondary
def add_volttron_central_platform(wrapper, config={}, **kwargs): print('Adding vcp to {}'.format(wrapper.vip_address)) agent_uuid = wrapper.install_agent( config_file=config, agent_dir=get_services_core("VolttronCentralPlatform"), vip_identity=VOLTTRON_CENTRAL_PLATFORM ) return agent_uuid
def add_listener(wrapper, config={}, vip_identity=None, **kwargs): print("Adding to {wrapper} a listener agent".format(wrapper=wrapper)) agent_uuid = wrapper.install_agent( config_file=config, vip_identity=vip_identity, agent_dir=get_services_core("ListenerAgent"), **kwargs) return agent_uuid
def add_mongohistorian(wrapper, config, vip_identity='platform.historian', **kwargs): agent_uuid = wrapper.install_agent( config_file=config, agent_dir=get_services_core("MongodbHistorian"), vip_identity=vip_identity, **kwargs ) return agent_uuid
def add_listener(wrapper, config={}, vip_identity=None, **kwargs): print("Adding to {wrapper} a listener agent".format(wrapper=wrapper)) agent_uuid = wrapper.install_agent( config_file=config, vip_identity=vip_identity, agent_dir=get_services_core("ListenerAgent"), **kwargs ) return agent_uuid
def test_default_config(volttron_instances): """ Test the default configuration file included with the agent """ publish_agent = volttron_instance1.build_agent(identity="test_agent") gevent.sleep(1) config_path = os.path.join(get_services_core("DataMover"), "config") with open(config_path, "r") as config_file: config_json = json.load(config_file) assert isinstance(config_json, dict) volttron_instance1.install_agent(agent_dir=get_services_core("DataMover"), config_file=config_json, start=True, vip_identity="health_test") assert publish_agent.vip.rpc.call( "health_test", "health.get_status").get(timeout=10).get('status') == STATUS_GOOD
def add_mongohistorian(wrapper, config, vip_identity='platform.historian', **kwargs): agent_uuid = wrapper.install_agent( config_file=config, agent_dir=get_services_core("MongodbHistorian"), vip_identity=vip_identity, **kwargs) return agent_uuid
def agent(request, volttron_instance): """ Build MasterDriverAgent, add modbus driver & csv configurations """ # Build master driver agent md_agent = volttron_instance.build_agent(identity="test_md_agent") capabilities = {'edit_config_store': {'identity': PLATFORM_DRIVER}} volttron_instance.add_capabilities(md_agent.core.publickey, capabilities) # Clean out master driver configurations # wait for it to return before adding new config md_agent.vip.rpc.call('config.store', 'manage_delete_store', PLATFORM_DRIVER).get() # Add driver configurations md_agent.vip.rpc.call('config.store', 'manage_store', PLATFORM_DRIVER, 'devices/modbus_tk', jsonapi.dumps(DRIVER_CONFIG), config_type='json') # Add csv configurations md_agent.vip.rpc.call('config.store', 'manage_store', PLATFORM_DRIVER, 'modbus_tk.csv', REGISTRY_CONFIG_STRING, config_type='csv') md_agent.vip.rpc.call('config.store', 'manage_store', PLATFORM_DRIVER, 'modbus_tk_map.csv', REGISTER_MAP, config_type='csv') master_uuid = volttron_instance.install_agent( agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) gevent.sleep(10) # wait for the agent to start and start the devices def stop(): """ Stop master driver agent """ volttron_instance.stop_agent(master_uuid) md_agent.core.stop() request.addfinalizer(stop) return md_agent
def test_openadr(self, agent): # Test that a GET of the "oadr_request_event" XML succeeds, returning a response with a 200 status code url = '{}/OpenADR2/Simple/2.0b/EIEvent'.format(web_address) xml_filename = get_services_core('OpenADRVenAgent/tests/oadr_request_event.xml') xml_file = open(xml_filename, 'rb') headers = {'content-type': 'application/sep+xml'} response = requests.get(url, data=xml_file, headers=headers) assert response.status_code == 200 # Test that the PUT caused an update to the agent's list of events assert agent.vip.rpc.call('test_ven_agent', 'get_events').get(timeout=10) is None
def sep2_http_put(sep2_resource_name, sep2_filename): """ Issue a web request to PUT data for a SEP2 resource, using the contents of an XML file. @param sep2_resource_name: The distinguishing part of the name of the SEP2 resource as it appears in the URL. @param sep2_filename: The distinguishing part of the SEP2 sample data file name. """ url = '{}/dcap/{}'.format(web_address, sep2_resource_name) headers = {'content-type': 'application/sep+xml'} return requests.post(url, data=open(get_services_core("SEP2Agent/tests/{}.PUT.xml").format(sep2_filename), 'rb'), headers=headers)
def sqlhistorian(request, volttron_instances): # print "Fixture sqlhistorian" global volttron_instance1, volttron_instance2 global sqlite_config # 1: Install historian agent # Install and start sqlhistorian agent in instance2 agent_uuid = volttron_instance2.install_agent( agent_dir=get_services_core("SQLHistorian"), config_file=sqlite_config, start=True, vip_identity='platform.historian') print("sqlite historian agent id: ", agent_uuid)
def test_cov_update_published(volttron_instance, test_agent): """Tests the functionality of BACnet change of value forwarding in the Master Driver and driver.py""" # Reset master driver config store cmd = ['volttron-ctl', 'config', 'delete', PLATFORM_DRIVER, '--all'] process = Popen(cmd, env=volttron_instance.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) result = process.wait() assert result == 0 # Add fake device configuration cmd = ['volttron-ctl', 'config', 'store', PLATFORM_DRIVER, 'fake.csv', 'examples/configurations/drivers/fake.csv', '--csv'] process = Popen(cmd, env=volttron_instance.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) result = process.wait() assert result == 0 cmd = ['volttron-ctl', 'config', 'store', PLATFORM_DRIVER, "devices/fakedriver", 'examples/configurations/drivers/fake.config', '--json'] process = Popen(cmd, env=volttron_instance.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) result = process.wait() assert result == 0 # install master driver, start the master driver, which starts the device master_uuid = volttron_instance.install_agent( agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) print("agent id: ", master_uuid) # tell the master driver to forward the value point_name = "PowerState" device_path = "fakedriver" result_dict = {"fake1": "test", "fake2": "test", "fake3": "test"} test_agent.vip.rpc.call(PLATFORM_DRIVER, 'forward_bacnet_cov_value', device_path, point_name, result_dict) # wait for the publishes to make it to the bus gevent.sleep(2) # Mock checks # Should have one "PowerState" publish for each item in the result dict # Total all publishes likely will include regular scrapes assert test_agent.cov_callback.call_count >= 3 test_count = 0 for call_arg in test_agent.cov_callback.call_args_list: if call_arg[0][5][0].get("PowerState", False): test_count += 1 assert test_count == 3
def test_indefinite_override_after_restart(config_store, test_agent, volttron_instance1): for i in xrange(4): config_name = "devices/fakedriver{}".format(i) setup_config(config_store, config_name, fake_device_config) device_path = 'fakedriver2' # Set override feature on device test_agent.vip.rpc.call( PLATFORM_DRIVER, # Target agent 'set_override_on', # Method device_path, # Override Pattern 0.0, # Indefinite override False, # revert flag to True False ).get(timeout=10) # Give it enough time to set indefinite override. gevent.sleep(0.5) global master_uuid volttron_instance1.stop_agent(master_uuid) volttron_instance1.remove_agent(master_uuid) gevent.sleep(1) # Start the master driver agent which would in turn start the fake driver # using the configs created above master_uuid = volttron_instance1.install_agent( agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) gevent.sleep(1) # wait for the agent to start and start the devices point = 'SampleWritableFloat1' new_value = 65.5 try: #Try to set a point on fakedriver1 result = test_agent.vip.rpc.call( PLATFORM_DRIVER, # Target agent 'set_point', # Method device_path, #device path point, new_value ).get(timeout=10) pytest.fail("Expecting Override Error. Code returned : {}".format(result)) except RemoteError as e: assert e.exc_info['exc_type'] == 'master_driver.agent.OverrideError' assert e.message == 'Cannot set point on device {} since global override is set'.format( device_path) result = test_agent.vip.rpc.call( PLATFORM_DRIVER, # Target agent 'clear_overrides' # Method ).get(timeout=10)
def agent(request, volttron_instance): """Build MasterDriverAgent, add modbus driver & csv configurations """ # Build master driver agent md_agent = volttron_instance.build_agent() # Clean out master driver configurations md_agent.vip.rpc.call('config.store', 'manage_delete_store', 'platform.driver') # Add driver configurations md_agent.vip.rpc.call('config.store', 'manage_store', 'platform.driver', 'devices/modbus_tk', DRIVER_CONFIG_STRING, config_type='json') # Add csv configurations md_agent.vip.rpc.call('config.store', 'manage_store', 'platform.driver', 'modbus_tk.csv', REGISTRY_CONFIG_STRING, config_type='csv') md_agent.vip.rpc.call('config.store', 'manage_store', 'platform.driver', 'modbus_tk_map.csv', REGISTER_MAP, config_type='csv') master_uuid = volttron_instance.install_agent(agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) gevent.sleep(10) # wait for the agent to start and start the devices def stop(): """Stop master driver agent """ volttron_instance.stop_agent(master_uuid) md_agent.core.stop() request.addfinalizer(stop) return md_agent
def add_volttron_central(wrapper, config=None, **kwargs): config_dict = { # The agentid is used during display on the VOLTTRON central platform # it does not need to be unique. "agentid": "Volttron Central", # By default the webroot will be relative to the installation directory # of the agent when it is installed. One can override this by specifying # the root directory here. # "webroot": "path/to/webroot", # Authentication for users is handled through a naive password algorithm # import hashlib # hashlib.sha512(password).hexdigest() where password is the plain text password. "users": { "reader": { "password": "******", "groups": [ "reader" ] }, "admin": { "password": "******", "groups": [ "admin" ] }, "dorothy": { "password": "******", "groups": [ "reader, writer" ] } } } if config is not None: config_dict = config print('Adding vc to {}'.format(wrapper.vip_address)) agent_uuid = wrapper.install_agent( config_file=config_dict, agent_dir=get_services_core("VolttronCentral"), vip_identity=VOLTTRON_CENTRAL, **kwargs ) return agent_uuid
def test_creates_schema_prefix_tables(volttron_instance, crate_connection2): try: vi = volttron_instance assert not retrieve_tables_from_schema(crate_connection2, "testing") agent_uuid = vi.install_agent(agent_dir=get_services_core("CrateHistorian"), config_file=crate_config) tables = retrieve_tables_from_schema(crate_connection2, "testing") assert len(expected_table_list) == len(tables) assert set(expected_table_list) == set(tables) finally: vi.remove_agent(agent_uuid)
def test_creates_default_table_prefixes(volttron_instance, crate_connection1): try: vi = volttron_instance assert not retrieve_tables_from_schema(crate_connection1, "historian") agent_uuid = vi.install_agent(agent_dir=get_services_core("CrateHistorian"), config_file=crate_config_no_schema) gevent.sleep(0.5) tables = retrieve_tables_from_schema(crate_connection1, "historian") assert len(expected_table_list) == len(tables) assert set(expected_table_list) == set(tables) finally: vi.remove_agent(agent_uuid)
def agent(request, volttron_instance1): md_agent = volttron_instance1.build_agent() # Clean out master driver configurations. md_agent.vip.rpc.call('config.store', 'manage_delete_store', 'platform.driver').get(timeout=10) driver1_config = DRIVER1_CONFIG_STRING % os.environ.get('CHARGEPOINT_PASSWORD', 'Must set a password') driver2_config = DRIVER2_CONFIG_STRING % os.environ.get('CHARGEPOINT_PASSWORD', 'Must set a password') print('Driver1 config: %s' % driver1_config) # Add test configurations. md_agent.vip.rpc.call('config.store', 'manage_store', 'platform.driver', 'devices/chargepoint1', driver1_config, 'json').get(timeout=10) md_agent.vip.rpc.call('config.store', 'manage_store', 'platform.driver', 'devices/chargepoint2', driver2_config, 'json').get(timeout=10) md_agent.vip.rpc.call('config.store', 'manage_store', 'platform.driver', 'chargepoint.csv', REGISTRY_CONFIG_STRING, 'csv').get(timeout=10) master_uuid = volttron_instance1.install_agent(agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) print('agent id: ', master_uuid) gevent.sleep(10) # wait for the agent to start and start the devices def stop(): volttron_instance1.stop_agent(master_uuid) md_agent.core.stop() request.addfinalizer(stop) return md_agent
def database_client(request, volttron_instance): print('connecting to mongo database') client = pymongo.MongoClient( mongo_connection_string(request.param['connection']['params'])) print (request.param) agent_uuid = volttron_instance.install_agent( agent_dir=get_services_core("MongodbHistorian"), config_file=request.param, start=True, vip_identity="platform.historian") def cleanup(): if client is not None: client.close() volttron_instance.remove_agent(agent_uuid) request.addfinalizer(cleanup) return client
def config_store_connection(request, volttron_instance1): connection = volttron_instance1.build_connection(peer=CONFIGURATION_STORE) # Reset master driver config store connection.call("manage_delete_store", PLATFORM_DRIVER) # Start the master driver agent which would in turn start the fake driver # using the configs created above master_uuid = volttron_instance1.install_agent( agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) print("agent id: ", master_uuid) gevent.sleep(2) # wait for the agent to start and start the devices yield connection volttron_instance1.stop_agent(master_uuid) volttron_instance1.remove_agent(master_uuid) connection.kill()
def weather_agent(request, volttron_instance): global API_KEY config = { "operation_mode": 1, "wu_api_key": API_KEY } weather_uuid = volttron_instance.install_agent( vip_identity='weather_agent', agent_dir=get_services_core("WeatherAgent"), config_file=config, start=False) volttron_instance.start_agent(weather_uuid) def stop_agent(): if volttron_instance.is_running(): volttron_instance.stop_agent(weather_uuid) volttron_instance.remove_agent(weather_uuid) request.addfinalizer(stop_agent)
def test_old_config(volttron_instances, forwarder): """ Test adding 'agentid' and 'identity' to config. identity should be supported with "deprecated warning" and "agentid" should get ignored with a warning message """ print("\n** test_old_config **") global forwarder_config forwarder_config['agentid'] = "test_forwarder_agent_id" forwarder_config['identity'] = "second forwarder" # 1: Install historian agent # Install and start sqlhistorian agent in instance2 forwarder_uuid = volttron_instance1.install_agent( agent_dir=get_services_core("ForwardHistorian"), config_file=forwarder_config, start=True) print("forwarder agent id: ", forwarder_uuid)
def agent(request, volttron_instance1): agent = volttron_instance1.build_agent() # Clean out master driver configurations. agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_delete_store', PLATFORM_DRIVER).get(timeout=10) #Add test configurations. agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_store', PLATFORM_DRIVER, "devices/campus/building/unit", driver_config_dict_string, "json").get(timeout=10) agent.vip.rpc.call(CONFIGURATION_STORE, 'manage_store', PLATFORM_DRIVER, "restful.csv", restful_csv_string, "csv").get(timeout=10) master_uuid = volttron_instance1.install_agent( agent_dir=get_services_core("MasterDriverAgent"), config_file={}, start=True) print("agent id: ", master_uuid) gevent.sleep(2) # wait for the agent to start and start the devices server = pywsgi.WSGIServer((ip, int(port)), handle) server.start() def stop(): volttron_instance1.stop_agent(master_uuid) agent.core.stop() server.stop() request.addfinalizer(stop) return agent