Пример #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="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)
Пример #2
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)
Пример #3
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
    def get_n_volttron_instances(n, should_start=True, address_file=True):
        get_n_volttron_instances.count = n
        instances = []
        vip_addresses = []
        web_addresses = []
        instances = []
        addr_config = dict()
        names = []

        for i in range(0, n):
            address = get_rand_vip()
            web_address = "http://{}".format(get_rand_ip_and_port())
            vip_addresses.append(address)
            web_addresses.append(web_address)
            nm = 'platform{}'.format(i + 1)
            names.append(nm)

        for i in range(0, n):
            address = vip_addresses[i]
            web_address = web_addresses[i]
            wrapper = PlatformWrapper()

            addr_file = os.path.join(wrapper.volttron_home,
                                     'external_address.json')
            if address_file:
                with open(addr_file, 'w') as f:
                    json.dump(web_addresses, f)
                    gevent.sleep(.1)
            wrapper.startup_platform(address,
                                     bind_web_address=web_address,
                                     instance_name=names[i],
                                     setupmode=True)
            wrapper.skip_cleanup = True
            instances.append(wrapper)

        gevent.sleep(11)
        for i in range(0, n):
            instances[i].shutdown_platform()

        gevent.sleep(1)
        # del instances[:]
        for i in range(0, n):
            address = vip_addresses.pop(0)
            web_address = web_addresses.pop(0)
            print address, web_address
            instances[i].startup_platform(address,
                                          bind_web_address=web_address,
                                          instance_name=names[i])
            instances[i].allow_all_connections()
        gevent.sleep(11)
        instances = instances if n > 1 else instances[0]

        get_n_volttron_instances.instances = instances
        return instances
    def build_n_volttron_instances(n, bad_config=False, add_my_address=True):
        build_n_volttron_instances.count = n
        instances = []
        vip_addresses = []
        instances = []
        addr_config = dict()
        names = []

        for i in range(0, n):
            address = get_rand_vip()
            vip_addresses.append(address)
            nm = 'platform{}'.format(i + 1)
            names.append(nm)

        for i in range(0, n):
            address = vip_addresses[i]
            wrapper = PlatformWrapper()
            wrapper.startup_platform(address, instance_name=names[i])
            wrapper.skip_cleanup = True
            instances.append(wrapper)

        gevent.sleep(1)
        for i in range(0, n):
            instances[i].shutdown_platform()

        for i in range(0, n):
            addr_config.clear()
            for j in range(0, n):
                if j != i or (j == i and add_my_address):
                    name = names[j]
                    addr_config[name] = dict()
                    addr_config[name]['instance-name'] = names[j]
                    if bad_config:
                        addr_config[name]['vip-address123'] = vip_addresses[j]
                    else:
                        addr_config[name]['vip-address'] = vip_addresses[j]
                    addr_config[name]['serverkey'] = instances[j].serverkey

            address_file = os.path.join(instances[i].volttron_home,
                                        'external_platform_discovery.json')
            if address_file:
                with open(address_file, 'w') as f:
                    json.dump(addr_config, f)

        gevent.sleep(1)
        for i in range(0, n):
            address = vip_addresses.pop(0)
            instances[i].startup_platform(address, instance_name=names[i])
            instances[i].allow_all_connections()
        gevent.sleep(11)
        instances = instances if n > 1 else instances[0]

        build_n_volttron_instances.instances = instances
        return instances
Пример #6
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()
Пример #7
0
def build_wrapper(vip_address,
                  should_start=True,
                  messagebus='zmq',
                  remote_platform_ca=None,
                  instance_name=None,
                  **kwargs):

    wrapper = PlatformWrapper(ssl_auth=kwargs.pop('ssl_auth', False),
                              messagebus=messagebus,
                              instance_name=instance_name,
                              remote_platform_ca=remote_platform_ca)
    if should_start:
        wrapper.startup_platform(vip_address=vip_address, **kwargs)
    return wrapper
def build_wrapper(vip_address: str,
                  should_start: bool = True,
                  messagebus: str = 'zmq',
                  remote_platform_ca: Optional[str] = None,
                  instance_name: Optional[str] = None,
                  secure_agent_users: bool = False,
                  **kwargs):
    wrapper = PlatformWrapper(ssl_auth=kwargs.pop('ssl_auth', False),
                              messagebus=messagebus,
                              instance_name=instance_name,
                              secure_agent_users=secure_agent_users,
                              remote_platform_ca=remote_platform_ca)
    if should_start:
        wrapper.startup_platform(vip_address=vip_address, **kwargs)
    return wrapper
Пример #9
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()
Пример #10
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
Пример #11
0
def build_wrapper(vip_address, **kwargs):
    wrapper = PlatformWrapper()
    print('BUILD_WRAPPER: {}'.format(vip_address))
    wrapper.startup_platform(vip_address=vip_address, **kwargs)
    return wrapper
def build_wrapper(vip_address, **kwargs):
    wrapper = PlatformWrapper()
    print('BUILD_WRAPPER: {}'.format(vip_address))
    wrapper.startup_platform(vip_address=vip_address, **kwargs)
    return wrapper