Ejemplo n.º 1
0
def test_repackage_invalid_agent_dir():
    """
    Test if we can create a wheel file given an installed agent temp_dir.
    Test with invalid agent temp_dir. Expected result - AgentPackageError

    """
    try:
        repackage("/tmp/abcdefghijklmnopqrstuvwxyz")
        pytest.fail("Expecting AgentPackageError but code completed "
                    "successfully")
    except AgentPackageError as a:
        assert a.message == "Agent directory " \
                            "/tmp/abcdefghijklmnopqrstuvwxyz " \
                            "does not exist"
    temp_dir = ""
    try:
        temp_dir = tempfile.mkdtemp()
        repackage(temp_dir)
        pytest.fail("Expecting AgentPackageError but code completed "
                    "successfully")
    except AgentPackageError as a:
        assert a.message == 'directory does not contain a valid agent ' \
                            'package: {}'.format(temp_dir)
    finally:
        if temp_dir:
            os.rmdir(temp_dir)
Ejemplo n.º 2
0
def test_repackage_invalid_agent_dir():
    """
    Test if we can create a wheel file given an installed agent temp_dir.
    Test with invalid agent temp_dir. Expected result - AgentPackageError

    """
    try:
        repackage("/tmp/abcdefghijklmnopqrstuvwxyz")
        pytest.fail("Expecting AgentPackageError but code completed "
                    "successfully")
    except AgentPackageError as a:
        assert a.message == "Agent directory " \
                            "/tmp/abcdefghijklmnopqrstuvwxyz " \
                            "does not exist"
    temp_dir = ""
    try:
        temp_dir = tempfile.mkdtemp()
        repackage(temp_dir)
        pytest.fail("Expecting AgentPackageError but code completed "
                    "successfully")
    except AgentPackageError as a:
        assert a.message == 'directory does not contain a valid agent ' \
                            'package: {}'.format(temp_dir)
    finally:
        if temp_dir:
            os.rmdir(temp_dir)
Ejemplo n.º 3
0
def test_repackage_new_dest_dir(volttron_instance):
    """
    Test if we can create a wheel file given an installed agent directory.
    Test with valid destination directory

    :param volttron_instance: platform wrapper used to install a test
                              agent and test installation of wheel file
                              generated by repackage

    """
    dest_dir = None
    try:
        dest_dir = tempfile.mkdtemp()
        dest_dir = os.path.join(dest_dir, "subdir")
        print("cwd {}".format(os.getcwd()))

        agent_uuid = volttron_instance.install_agent(
            agent_dir=os.path.join(get_examples("ListenerAgent")))
        agent_dir = os.path.join(volttron_instance.volttron_home, 'agents',
                                 agent_uuid, 'listeneragent-3.2')
        print agent_dir
        wheel_path = repackage(agent_dir, dest=dest_dir)
        expeceted_wheel = os.path.join(dest_dir,
                                       'listeneragent-3.2-py2-none-any.whl')
        assert wheel_path == expeceted_wheel
        # Check wheel exists and it can be used to install the agent again
        assert os.path.isfile(wheel_path)
        volttron_instance.install_agent(agent_wheel=wheel_path)
    finally:
        if dest_dir:
            shutil.rmtree(dest_dir)
Ejemplo n.º 4
0
def test_repackage_output_to_cwd(volttron_instance):
    """
    Test if we can create a wheel file given an installed agent directory.
    Test without any explicit destination directory for the wheel file.
    Wheel file should be created in current working directory

    :param volttron_instance: platform wrapper used to install a test
                              agent and test installation of wheel file
                              generated by repackage

    """
    dest_dir = None
    cwd = os.getcwd()
    try:
        dest_dir = tempfile.mkdtemp()
        os.chdir(dest_dir)
        agent_uuid = volttron_instance.install_agent(
            agent_dir=os.path.join(cwd, get_examples("ListenerAgent")))
        agent_dir = os.path.join(volttron_instance.volttron_home, 'agents',
                                 agent_uuid, 'listeneragent-3.2')
        print agent_dir
        wheel_name = repackage(agent_dir)
        assert wheel_name == 'listeneragent-3.2-py2-none-any.whl'

        wheel = os.path.join(dest_dir, wheel_name)
        # Check wheel exists and it can be used to install the agent again
        assert os.path.isfile(wheel)
        volttron_instance.install_agent(agent_wheel=wheel)
    finally:
        os.chdir(cwd)
        if dest_dir:
            shutil.rmtree(dest_dir)
Ejemplo n.º 5
0
def test_repackage_new_dest_dir(volttron_instance):
    """
    Test if we can create a wheel file given an installed agent directory.
    Test with valid destination directory

    :param volttron_instance: platform wrapper used to install a test
                              agent and test installation of wheel file
                              generated by repackage

    """
    dest_dir = None
    try:
        dest_dir = tempfile.mkdtemp()
        dest_dir = os.path.join(dest_dir, "subdir")
        print ("cwd {}".format(os.getcwd()))

        agent_uuid = volttron_instance.install_agent(
            agent_dir=os.path.join(get_examples("ListenerAgent")))
        agent_dir = os.path.join(volttron_instance.volttron_home, 'agents',
            agent_uuid, 'listeneragent-3.2')
        print agent_dir
        wheel_path = repackage(agent_dir, dest=dest_dir)
        expeceted_wheel = os.path.join(
            dest_dir, 'listeneragent-3.2-py2-none-any.whl')
        assert wheel_path == expeceted_wheel
        # Check wheel exists and it can be used to install the agent again
        assert os.path.isfile(wheel_path)
        volttron_instance.install_agent(agent_wheel=wheel_path)
    finally:
        if dest_dir:
            shutil.rmtree(dest_dir)
Ejemplo n.º 6
0
def test_repackage_output_to_cwd(volttron_instance):
    """
    Test if we can create a wheel file given an installed agent directory.
    Test without any explicit destination directory for the wheel file.
    Wheel file should be created in current working directory

    :param volttron_instance: platform wrapper used to install a test
                              agent and test installation of wheel file
                              generated by repackage

    """
    dest_dir = None
    cwd = os.getcwd()
    try:
        dest_dir = tempfile.mkdtemp()
        os.chdir(dest_dir)
        agent_uuid = volttron_instance.install_agent(
            agent_dir=os.path.join(cwd, get_examples("ListenerAgent")))
        agent_dir = os.path.join(volttron_instance.volttron_home, 'agents',
            agent_uuid, 'listeneragent-3.2')
        print agent_dir
        wheel_name = repackage(agent_dir)
        assert wheel_name == 'listeneragent-3.2-py2-none-any.whl'

        wheel = os.path.join(dest_dir, wheel_name)
        # Check wheel exists and it can be used to install the agent again
        assert os.path.isfile(wheel)
        volttron_instance.install_agent(agent_wheel=wheel)
    finally:
        os.chdir(cwd)
        if dest_dir:
            shutil.rmtree(dest_dir)
Ejemplo n.º 7
0
def test_repackage_invalid_dest_dir(volttron_instance):
    """
    Test if we can create a wheel file given an installed agent agent_dir.
    Test with invalid destination agent_dir.
    Expected result - AgentPackageError

    :param volttron_instance: platform wrapper used to install a test
                              agent and test installation of wheel file
                              generated by repackage

    """
    dest_dir = "/abcdef/ghijkl"
    try:
        agent_uuid = volttron_instance.install_agent(
            agent_dir=get_examples("ListenerAgent"))
        agent_dir = os.path.join(volttron_instance.volttron_home, 'agents',
                                 agent_uuid, 'listeneragent-3.2')
        repackage(agent_dir, dest=dest_dir)
        pytest.fail("Expecting AgentPackageError but code completed "
                    "successfully")
    except AgentPackageError as a:
        assert a.message.find("Unable to create destination directory "
                              "{}".format(dest_dir)) != -1
    try:

        dest_dir = tempfile.mkdtemp()
        os.chmod(dest_dir, stat.S_IREAD)
        agent_uuid = volttron_instance.install_agent(
            agent_dir=get_examples("ListenerAgent"))
        agent_dir = os.path.join(volttron_instance.volttron_home, 'agents',
                                 agent_uuid, 'listeneragent-3.2')
        repackage(agent_dir, dest=dest_dir)
        pytest.fail("Expecting AgentPackageError but code completed "
                    "successfully")
    except Exception as a:
        assert str(a).find("Permission denied") != -1
Ejemplo n.º 8
0
def test_repackage_invalid_dest_dir(volttron_instance):
    """
    Test if we can create a wheel file given an installed agent agent_dir.
    Test with invalid destination agent_dir.
    Expected result - AgentPackageError

    :param volttron_instance: platform wrapper used to install a test
                              agent and test installation of wheel file
                              generated by repackage

    """
    dest_dir = "/abcdef/ghijkl"
    try:
        agent_uuid = volttron_instance.install_agent(
            agent_dir=get_examples("ListenerAgent"))
        agent_dir = os.path.join(volttron_instance.volttron_home, 'agents',
                                 agent_uuid, 'listeneragent-3.2')
        repackage(agent_dir, dest=dest_dir)
        pytest.fail("Expecting AgentPackageError but code completed "
                    "successfully")
    except AgentPackageError as a:
        assert a.message.find("Unable to create destination directory "
                              "{}".format(dest_dir)) != -1
    try:

        dest_dir = tempfile.mkdtemp()
        os.chmod(dest_dir, stat.S_IREAD)
        agent_uuid = volttron_instance.install_agent(
            agent_dir=get_examples("ListenerAgent"))
        agent_dir = os.path.join(volttron_instance.volttron_home, 'agents',
                                 agent_uuid, 'listeneragent-3.2')
        repackage(agent_dir, dest=dest_dir)
        pytest.fail("Expecting AgentPackageError but code completed "
                    "successfully")
    except Exception as a:
        assert str(a).find("Permission denied") != -1