def test_pid_file(): try: import psutil except: warnings.warn('No psutil module present for this test') return wrapper = PlatformWrapper() address = "tcp://127.0.0.1:{}".format(get_rand_port()) wrapper.startup_platform(address) assert wrapper is not None assert wrapper.is_running() pid_file = os.path.join(wrapper.volttron_home, "VOLTTRON_PID") assert os.path.exists(pid_file) with open(pid_file, 'r') as pf: assert psutil.pid_exists(int(pf.read().strip())) wrapper.skip_cleanup = True wrapper.shutdown_platform() # give operating system enough time to update pids. gevent.sleep(0.1) assert not os.path.exists(pid_file) # Check overwrite of pid file. In case last shutdown was not clean with open(pid_file, 'w') as pf: pf.write('abcd') wrapper = PlatformWrapper() address = "tcp://127.0.0.1:{}".format(get_rand_port()) wrapper.startup_platform(address) assert wrapper is not None assert wrapper.is_running() pid_file = os.path.join(wrapper.volttron_home, "VOLTTRON_PID") assert os.path.exists(pid_file) with open(pid_file, 'r') as pf: pid_str = pf.read().strip() assert psutil.pid_exists(int(pid_str)) # test start-volttron script we don't start a second volttron process if one # is already running env = os.environ.copy() env["VOLTTRON_HOME"] = wrapper.volttron_home vsource_home = os.path.dirname( os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) process = Popen(["./start-volttron"], cwd=vsource_home, env=env, stderr=subprocess.PIPE, stdout=subprocess.PIPE) (output, error) = process.communicate() assert process.returncode == 1 assert "VOLTTRON with process id " + pid_str + " is already running" in \ output
def test_can_create(messagebus, ssl_auth): p = PlatformWrapper(messagebus=messagebus, ssl_auth=ssl_auth) try: assert not p.is_running() assert p.volttron_home.startswith("/tmp/tmp") p.startup_platform(vip_address=get_rand_tcp_address()) assert p.is_running() finally: if p: p.shutdown_platform() assert not p.is_running()
def test_can_cleanup_installed_listener(): try: import psutil except: warnings.warn('No psutil module present for this test') return wrapper = PlatformWrapper() address="tcp://127.0.0.1:{}".format(get_rand_port()) wrapper.startup_platform(address) assert wrapper is not None assert wrapper.is_running() auuid = wrapper.install_agent(agent_dir="examples/ListenerAgent", start=False) assert auuid is not None started = wrapper.start_agent(auuid) assert isinstance(started, int) assert psutil.pid_exists(started) wrapper.shutdown_platform() # give operating system enough time to update pids. gevent.sleep(0.1) assert not psutil.pid_exists(started)
def test_can_cleanup_installed_listener(): try: import psutil except: warnings.warn('No psutil module present for this test') return wrapper = PlatformWrapper() address="tcp://127.0.0.1:{}".format(get_rand_port()) wrapper.startup_platform(address) assert wrapper is not None assert wrapper.is_running() auuid = wrapper.install_agent(agent_dir=get_examples("ListenerAgent"), vip_identity="listener", start=False) assert auuid is not None started = wrapper.start_agent(auuid) assert isinstance(started, int) assert psutil.pid_exists(started) wrapper.shutdown_platform() # give operating system enough time to update pids. gevent.sleep(0.1) assert not psutil.pid_exists(started)
def test_can_create_web_enabled(messagebus: str, https_enabled: bool): p = PlatformWrapper(messagebus=messagebus) try: assert not p.is_running() assert p.volttron_home.startswith("/tmp/tmp") http_address = get_rand_http_address(https=https_enabled) p.startup_platform(vip_address=get_rand_tcp_address(), bind_web_address=http_address) assert p.is_running() response = requests.get(http_address, verify=False) assert response.ok finally: if p: p.shutdown_platform() assert not p.is_running()
def instance(request): instance = PlatformWrapper(messagebus='rmq', ssl_auth=True) yield instance if instance.is_running(): instance.shutdown_platform() # In case platform was just killed stop_rabbit(rmq_home=instance.rabbitmq_config_obj.rmq_home, env=instance.env, quite=True)
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 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