def vc_vcp_platforms(): """ This method returns two distinct platforms one vc and one vcp. When they are returned they should be registered together. This method will yield the two platforms as a tuple and then after the module is finished executing the cleanup of both will happen. """ vc = PlatformWrapper() vcp = PlatformWrapper() # VC is setup to allow all connections vc.allow_all_connections() start_wrapper_platform(vc, with_http=True) start_wrapper_platform(vcp, volttron_central_address=vc.vip_address, volttron_central_serverkey=vc.serverkey) vc_uuid = add_volttron_central(vc) vcp_uuid = add_volttron_central_platform(vcp) # Sleep so we know we are registered gevent.sleep(15) yield vc, vcp vc.shutdown_platform() vcp.shutdown_platform()
def both_with_vc_vcp(request): """ Adds the volttron-central-address and volttron-central-serverkey to the main instance configuration file before starting the platform """ p = PlatformWrapper() if request.param[1] == 'local': start_wrapper_platform(p, with_http=True, add_local_vc_address=True) else: start_wrapper_platform(p, with_http=True) if request.param[0] == 'vcp-first': vcp_uuid = add_volttron_central_platform(p) vc_uuid = add_volttron_central(p) else: vc_uuid = add_volttron_central(p) vcp_uuid = add_volttron_central_platform(p) # Give the agents a chance to do stuff. note might take up to 10 sec # if the vcp is started first. gevent.sleep(10) yield p p.shutdown_platform()
def both_with_vc_vcp(request): """ Adds the volttron-central-address and volttron-central-serverkey to the main instance configuration file before starting the platform """ p = PlatformWrapper() if request.param[1] == 'local': start_wrapper_platform(p, with_http=True, add_local_vc_address=True) else: start_wrapper_platform(p, with_http=True) if request.param[0] == 'vcp-first': vcp_uuid = add_volttron_central_platform(p) vc_uuid = add_volttron_central(p) else: vc_uuid = add_volttron_central(p) vcp_uuid = add_volttron_central_platform(p) # Give the agents a chance to do stuff. note might take up to 10 sec # if the vcp is started first. gevent.sleep(10) yield p p.shutdown_platform()
def test_can_start_webserver(get_volttron_instances): wrapper = get_volttron_instances(1, False) start_wrapper_platform(wrapper, with_http=True, with_tcp=True) gevent.sleep(0.5) assert requests.get(wrapper.discovery_address).ok
def test_can_start_webserver(get_volttron_instances): wrapper = get_volttron_instances(1, False) skip_if_not_encrypted(get_volttron_instances.param == 'encrypted') start_wrapper_platform(wrapper, with_http=True, with_tcp=True) gevent.sleep(0.5) assert requests.get(wrapper.discovery_address).ok
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 setup_instances(request): inst1 = PlatformWrapper() inst2 = PlatformWrapper() start_wrapper_platform(inst1) start_wrapper_platform(inst2) yield inst1, inst2 inst1.shutdown_platform() inst2.shutdown_platform()
def setup_instances(): inst1 = PlatformWrapper() inst2 = PlatformWrapper() start_wrapper_platform(inst1) start_wrapper_platform(inst2) yield inst1, inst2 inst1.shutdown_platform() inst2.shutdown_platform()
def web_instance(request, get_volttron_instances): instance = get_volttron_instances(1, should_start=False) start_wrapper_platform(instance, with_http=True) # Create a web enabled agent to test with. Cleanup will happen in the # shutdown_platform method of the instance. web_agent = _build_web_agent(instance.volttron_home) gevent.sleep(1) instance.install_agent(agent_dir=web_agent) yield instance
def web_instance(request, get_volttron_instances): instance = get_volttron_instances(1, should_start=False) start_wrapper_platform(instance, with_http=True) # Create a web enabled agent to test with. Cleanup will happen in the # shutdown_platform method of the instance. web_agent = _build_web_agent(instance.volttron_home) gevent.sleep(1) instance.install_agent(agent_dir=web_agent) yield instance instance.shutdown_platform()
def test_agent(request, get_volttron_instances): """Create test fixtures: a test agent plus a Volttron instance running a web agent, VEN agent, and ControlAgent.""" instance = get_volttron_instances(1, should_start=False) start_wrapper_platform(instance, with_http=True) # Delete $VOLTTRON_HOME/data/test_openadr.sqlite so that old db data won't interfere with new testing. db_path = os.path.expandvars(DB_PATH) if os.path.exists(db_path): os.remove(db_path) # Install and start a WebAgent. web_agent = _build_web_agent(instance.volttron_home) gevent.sleep(1) web_agent_id = instance.install_agent(agent_dir=web_agent) global web_server_address web_server_address = instance.bind_web_address # Install and start an OpenADRVenAgent. agent_dir = 'services/core/OpenADRVenAgent' ven_agent_id = instance.install_agent(agent_dir=agent_dir, config_file=VEN_AGENT_CONFIG, vip_identity=VEN_AGENT_ID, start=True) # Install and start a ControlAgentSim. agent_dir = 'services/core/OpenADRVenAgent/test/ControlAgentSim' control_agent_id = instance.install_agent(agent_dir=agent_dir, config_file=CONTROL_AGENT_CONFIG, vip_identity=CONTROL_AGENT_ID, start=True) test_agt = instance.build_agent() def stop(): instance.stop_agent(control_agent_id) instance.stop_agent(ven_agent_id) instance.stop_agent(web_agent_id) test_agt.core.stop() instance.shutdown_platform() request.addfinalizer(stop) yield test_agt
def setup_platform(request): """ Creates a single instance of VOLTTRON with a VOLTTRON Central Platform, a listener agent, and a sqlite historian that is a platform.historian. The VOLTTRON Central Platform agent is not registered with a VOLTTRON Central Platform. """ vcp = PlatformWrapper(messagebus=request.param[0], ssl_auth=request.param[1]) start_wrapper_platform(vcp, with_http=True, add_local_vc_address=True) assert vcp assert vcp.is_running() vcp_uuid = add_volttron_central_platform(vcp) print("VCP uuid: {}".format(vcp_uuid)) # historian_config = SQLITE_HISTORIAN_CONFIG.copy() # historian_config['connection']['params']['database'] = \ # vcp.volttron_home + "/data/platform.historian.sqlite" # # historian_uuid = add_sqlhistorian(vcp, config=historian_config, # vip_identity='platform.historian') # listeneer_uuid = add_listener(vcp, vip_identity="platform.listener") assert vcp_uuid, "Invalid vcp uuid returned" assert vcp.is_agent_running(vcp_uuid), "vcp wasn't running!" # assert historian_uuid, "Invalid historian uuid returned" # assert vcp.is_agent_running(historian_uuid), "historian wasn't running!" # # assert listeneer_uuid, "Invalid listener uuid returned" # assert vcp.is_agent_running(listeneer_uuid), "listener wasn't running!" yield vcp print('Shutting down instance: {}'.format(vcp.volttron_home)) if vcp.is_running(): vcp.remove_all_agents() # Shutdown handles case where the platform hasn't started. vcp.shutdown_platform()
def vc_vcp_platforms(request): vc = PlatformWrapper() vcp = PlatformWrapper() # VC is setup to allow all connections vc.allow_all_connections() start_wrapper_platform(vc, with_http=True) if request.param == 'use-http': start_wrapper_platform(vcp, volttron_central_address=vc.bind_web_address) else: start_wrapper_platform(vcp, volttron_central_address=vc.vip_address, volttron_central_serverkey=vc.serverkey) vcp_uuid = add_volttron_central_platform(vcp) vc_uuid = add_volttron_central(vc) # Give the agents a chance to do stuff. Can take up to 10 seconds to # reconnect with vc. gevent.sleep(10) yield vc, vcp vc.shutdown_platform() vcp.shutdown_platform()
def vc_vcp_platforms(request): vc = PlatformWrapper() vcp = PlatformWrapper() # VC is setup to allow all connections vc.allow_all_connections() start_wrapper_platform(vc, with_http=True) if request.param == 'use-http': start_wrapper_platform(vcp, volttron_central_address=vc.bind_web_address) else: start_wrapper_platform(vcp, volttron_central_address=vc.vip_address, volttron_central_serverkey=vc.serverkey) vcp_uuid = add_volttron_central_platform(vcp) vc_uuid = add_volttron_central(vc) # Give the agents a chance to do stuff. Can take up to 10 seconds to # reconnect with vc. gevent.sleep(10) yield vc, vcp vc.shutdown_platform() vcp.shutdown_platform()
def setup_first(request, get_volttron_instances): wrapper = get_volttron_instances(1, False) request.addfinalizer(wrapper.shutdown_platform) if get_volttron_instances.param != 'encrypted': pytest.skip("Only encrypted available for this test") start_wrapper_platform(wrapper, with_http=True) if request.param == 'vc_first': vc_uuid = add_volttron_central(wrapper) vcp_uuid = add_volttron_central_platform(wrapper) else: vcp_uuid = add_volttron_central_platform(wrapper) vc_uuid = add_volttron_central(wrapper) # Sleep to guarantee that the registration has happened and all the # agent startup is complete. gevent.sleep(5) assert vcp_uuid and vc_uuid return wrapper
def setup_first(request, get_volttron_instances): wrapper = get_volttron_instances(1, False) request.addfinalizer(wrapper.shutdown_platform) if get_volttron_instances.param != 'encrypted': pytest.skip("Only encrypted available for this test") start_wrapper_platform(wrapper, with_http=True) if request.param == 'vc_first': vc_uuid = add_volttron_central(wrapper) vcp_uuid = add_volttron_central_platform(wrapper) else: vcp_uuid = add_volttron_central_platform(wrapper) vc_uuid = add_volttron_central(wrapper) # Sleep to guarantee that the registration has happened and all the # agent startup is complete. gevent.sleep(5) assert vcp_uuid and vc_uuid return wrapper
def vcp_simulated_vc(request): """ This method yields a platform wrapper with a vcp installed and an agent connected to it with manager capabilities. The parameters are for each of the different identities we want to test with. """ p = PlatformWrapper() start_wrapper_platform(p, with_tcp=True) vcp_uuid = add_volttron_central_platform(p) # Build a connection to the just installed vcp agent. vc_simulated_agent = p.build_connection("platform.agent", identity="volttron.central") p.add_capabilities(vc_simulated_agent.server.core.publickey, "manager") yield p, vc_simulated_agent vc_simulated_agent.kill() p.shutdown_platform()
def vcp_simulated_vc(request): """ This method yields a platform wrapper with a vcp installed and an agent connected to it with manager capabilities. The parameters are for each of the different identities we want to test with. """ p = PlatformWrapper() start_wrapper_platform(p, with_tcp=True) vcp_uuid = add_volttron_central_platform(p) # Build a connection to the just installed vcp agent. vc_simulated_agent = p.build_connection("platform.agent", identity="volttron.central") p.add_capabilities(vc_simulated_agent.server.core.publickey, "manager") yield p, vc_simulated_agent vc_simulated_agent.kill() p.shutdown_platform()
def setup_platform(request, get_volttron_instances): """ Creates a single instance of VOLTTRON with a VOLTTRON Central Platform The VOLTTRON Central Platform agent is not registered with a VOLTTRON Central Platform. """ global vcp vcp = get_volttron_instances(1, False) if get_volttron_instances.param == "encrypted": start_wrapper_platform(vcp, with_http=True) else: pytest.skip("Only testing encrypted") start_wrapper_platform(vcp, with_http=False, with_tcp=False) assert vcp assert vcp.is_running() vcp_uuid = add_volttron_central_platform(vcp) assert vcp_uuid, "Invalid vcp uuid returned" assert vcp.is_agent_running(vcp_uuid), "vcp wasn't running!" return vcp
def setup_platform(): """ Creates a single instance of VOLTTRON with a VOLTTRON Central Platform, a listener agent, and a sqlite historian that is a platform.historian. The VOLTTRON Central Platform agent is not registered with a VOLTTRON Central Platform. """ vcp = PlatformWrapper() start_wrapper_platform(vcp, with_http=True) assert vcp assert vcp.is_running() vcp_uuid = add_volttron_central_platform(vcp) historian_config = SQLITE_HISTORIAN_CONFIG.copy() historian_config['connection']['params']['database'] = \ vcp.volttron_home + "/data/platform.historian.sqlite" historian_uuid = add_sqlhistorian(vcp, config=historian_config, vip_identity='platform.historian') listeneer_uuid = add_listener(vcp, vip_identity="platform.listener") assert vcp_uuid, "Invalid vcp uuid returned" assert vcp.is_agent_running(vcp_uuid), "vcp wasn't running!" assert historian_uuid, "Invalid historian uuid returned" assert vcp.is_agent_running(historian_uuid), "historian wasn't running!" assert listeneer_uuid, "Invalid listener uuid returned" assert vcp.is_agent_running(listeneer_uuid), "listener wasn't running!" yield vcp vcp.shutdown_platform() vcp = None
def setup_platform(): """ Creates a single instance of VOLTTRON with a VOLTTRON Central Platform, a listener agent, and a sqlite historian that is a platform.historian. The VOLTTRON Central Platform agent is not registered with a VOLTTRON Central Platform. """ vcp = PlatformWrapper() start_wrapper_platform(vcp, with_http=True) assert vcp assert vcp.is_running() vcp_uuid = add_volttron_central_platform(vcp) historian_config = SQLITE_HISTORIAN_CONFIG.copy() historian_config['connection']['params']['database'] = \ vcp.volttron_home + "/data/platform.historian.sqlite" historian_uuid = add_sqlhistorian(vcp, config=historian_config, vip_identity='platform.historian') listeneer_uuid = add_listener(vcp, vip_identity="platform.listener") assert vcp_uuid, "Invalid vcp uuid returned" assert vcp.is_agent_running(vcp_uuid), "vcp wasn't running!" assert historian_uuid, "Invalid historian uuid returned" assert vcp.is_agent_running(historian_uuid), "historian wasn't running!" assert listeneer_uuid, "Invalid listener uuid returned" assert vcp.is_agent_running(listeneer_uuid), "listener wasn't running!" yield vcp vcp.shutdown_platform() vcp = None
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 volttron_instance_web_enabled(request, get_volttron_instances): instance = get_volttron_instances(1, should_start=False) start_wrapper_platform(instance, with_http=True) return instance