示例#1
0
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)
示例#2
0
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 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)
示例#4
0
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()
示例#5
0
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()
示例#6
0
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()
示例#7
0
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()
示例#8
0
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)
示例#9
0
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
示例#10
0
def setup_instances():

    inst1 = PlatformWrapper()
    inst2 = PlatformWrapper()

    start_wrapper_platform(inst1)
    start_wrapper_platform(inst2)

    yield inst1, inst2

    inst1.shutdown_platform()
    inst2.shutdown_platform()
示例#11
0
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()
示例#12
0
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()
示例#13
0
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()
示例#14
0
def test_encryption():
    addr = 'tcp://127.0.0.1:55055'
    pub, sec = curve_keypair()
    publickey, secretkey = encode_key(pub), encode_key(sec)
    auth = {'allow': [{'credentials': 'CURVE:{}'.format(publickey)}]}

    plat = PlatformWrapper()
    plat.startup_platform(vip_address=addr, auth_dict=auth, encrypt=True)

    agent_addr = '{}?serverkey={}&publickey={}&secretkey=' \
                 '{}'.format(addr, plat.publickey, publickey, secretkey)

    agent1 = plat.build_agent(agent_addr, identity='agent1')
    peers = agent1.vip.peerlist.list().get(timeout=2)
    plat.shutdown_platform()
    print('PEERS: ', peers)
    assert len(peers) > 0
示例#15
0
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()
示例#16
0
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()
示例#17
0
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()
示例#18
0
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