def test_install_arg_matrix(volttron_instance: PlatformWrapper, args: List, use_config: bool): listener_config_file = get_examples("ListenerAgent/config") with with_os_environ(volttron_instance.env): # Don't change the parametrized args that have mutable values. Make copy if changing within test. # parameterized args when used with more than 1 .parametrize() or with another parameterized fixture # fails to rest values correctly # @pytest.mark.parametrize("x,y", (([1, 2], 1), ([3, 4], 1))) - will work fine even if x is changed in test # But # @pytest.mark.parametrize("x,y", (([1,2],1), ([3,4],1))) # @pytest.mark.parametrize("z", [8, 9]) # will fail to reset value of x correctly if x is changed within test vctl_args = copy.copy(args) vctl_args.insert(0, "--json") vctl_args.insert(0, "volttron-ctl") if use_config: vctl_args.extend(["--agent-config", listener_config_file]) response = execute_command(vctl_args, volttron_instance.env) json_response = jsonapi.loads(response) agent_uuid = json_response["agent_uuid"] gevent.sleep(1) response = execute_command(["vctl", "--json", "status", agent_uuid], volttron_instance.env) json_response = jsonapi.loads(response) identity = list(json_response.keys())[0] agent_status_dict = json_response[identity] if "--start" in vctl_args: assert agent_status_dict["status"] if "--tag" in vctl_args: assert agent_status_dict["agent_tag"] tag_name = vctl_args[vctl_args.index("--tag") + 1] assert tag_name == agent_status_dict["agent_tag"] if "--vip-identity" in vctl_args: assert agent_status_dict["identity"] expected_identity = vctl_args[vctl_args.index("--vip-identity") + 1] assert expected_identity == agent_status_dict["identity"] if use_config: with open(listener_config_file) as fp: expected_config = yaml.safe_load(fp.read()) config_path = Path(volttron_instance.volttron_home).joinpath( f"agents/{agent_uuid}/listeneragent-3.3/listeneragent-3.3.dist-info/config" ) with open(config_path) as fp: config_data = yaml.safe_load(fp.read()) assert expected_config == config_data volttron_instance.remove_all_agents()
def test_install_with_wheel(volttron_instance: PlatformWrapper): with with_os_environ(volttron_instance.env): global listener_agent_dir args = ["volttron-pkg", "package", listener_agent_dir] response = execute_command(args, volttron_instance.env) assert response.startswith("Package created at: ") path = response[len("Package created at: "):] assert os.path.exists(path.strip()) args = ["volttron-ctl", "--json", "install", path.strip()] response = execute_command(args, volttron_instance.env) response_dict = jsonapi.loads(response) assert response_dict.get("agent_uuid") volttron_instance.remove_all_agents()
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()