Ejemplo n.º 1
0
    def test_vars_set_by_api_takes_precedence(self):
        """ Setting a varaible through the D-Bus API should mean that value
            takes precedence over a variable previously set by the environment
            gateway.
        """
        sc = Container()
        try:
            sc.start(DATA)
            # Set variable through gateway
            sc.set_capabilities(["environment.test.cap.4"])
            # Set the same variable with LaunchCommand
            env_var = {"MY_ENV_VAR": "new-value"}
            sc.launch_command(
                "python " + sc.get_bind_dir() + "/testhelper.py --test-dir " +
                sc.get_bind_dir() + "/testoutput" + " --do-get-env-vars",
                env=env_var)

            # The D-Bus LaunchCommand is asynch so let it take effect before assert
            time.sleep(0.5)
            helper = EnvironmentHelper(TESTOUTPUT_DIR)
            my_env_var = helper.env_var("MY_ENV_VAR")
            # Assert value is the one set with LaunchCommand
            assert my_env_var == "new-value"
        finally:
            sc.terminate()
    def test_env_var_is_prepended(self):
        """ Set a config and then an prepending config, assert the prepended
            variable looks as expected.
        """
        sc = Container()
        try:
            sc.start(DATA)
            sc.set_capabilities(["environment.test.cap.5"])
            sc.launch_command("python " +
                              sc.get_bind_dir() +
                              "/testhelper.py --test-dir " +
                              sc.get_bind_dir() + "/testoutput" +
                              " --do-get-env-vars")

            # The D-Bus LaunchCommand is asynch so let it take effect before assert
            time.sleep(0.5)
            helper = EnvironmentHelper(TESTOUTPUT_DIR)
            ld_library_path = helper.env_var("LD_LIBRARY_PATH")
            # Assert the append was applied
            assert ld_library_path == "/another/path:/some/non/relevant/path"
            my_env_var = helper.env_var("MY_ENV_VAR")
            # Assert other variables were not affected
            assert my_env_var == "1234"
        finally:
            sc.terminate()
    def test_caps_for_one_container_does_not_affect_another_container(self):
        """ Test that setting caps for one containers does not have an impact
            on another container.

            Test steps:
                * Create two containers, sc1 and sc2
                * Set cap A and B on sc1
                * Assert the two expected variables are set, one from cap A and one from B
                * Set cap A on sc2
                * Assert ony the one expected variable is set, the one from cap A, and
                  that the one from cap B is not set.
        """
        sc1 = Container()
        sc2 = Container()

        try:
            sc1.start(DATA)
            sc2.start(DATA)

            # These caps should set two different env vars in the container
            sc1.set_capabilities(["environment.test.cap.7", "environment.test.cap.8"])

            sc1.launch_command("python " +
                               sc1.get_bind_dir() +
                               "/testhelper.py --test-dir " +
                               sc1.get_bind_dir() + "/testoutput" +
                               " --do-get-env-vars")

            # The D-Bus LaunchCommand is asynch so let it take effect before assert
            time.sleep(0.5)

            helper = EnvironmentHelper(TESTOUTPUT_DIR)

            my_env_var_1 = helper.env_var("MY_ENV_VAR_1")
            my_env_var_2 = helper.env_var("MY_ENV_VAR_2")

            assert my_env_var_1 == "1" and my_env_var_2 == "2"

            # This cap should set only one env var in the container
            sc2.set_capabilities(["environment.test.cap.7"])

            sc2.launch_command("python " +
                               sc2.get_bind_dir() +
                               "/testhelper.py --test-dir " +
                               sc2.get_bind_dir() + "/testoutput" +
                               " --do-get-env-vars")

            # The D-Bus LaunchCommand is asynch so let it take effect before assert
            time.sleep(0.5)

            my_env_var_1 = helper.env_var("MY_ENV_VAR_1")
            my_env_var_2 = helper.env_var("MY_ENV_VAR_2")

            assert my_env_var_1 == "1" and my_env_var_2 == None

        finally:
            sc1.terminate()
            sc2.terminate()
Ejemplo n.º 4
0
    def test_env_var_is_set(self):
        """ Set an Environment gateway config that sets a variable inside
            the container. Use helper to get the inside environment and
            assert the expected result.
        """
        sc = Container()
        try:
            sc.start(DATA)
            sc.set_capabilities(["environment.test.cap.4"])
            sc.launch_command("python " + sc.get_bind_dir() +
                              "/testhelper.py --test-dir " +
                              sc.get_bind_dir() + "/testoutput" +
                              " --do-get-env-vars")

            # The D-Bus LaunchCommand is asynch so let it take effect before assert
            time.sleep(0.5)
            helper = EnvironmentHelper(TESTOUTPUT_DIR)
            assert helper.env_var("MY_ENV_VAR") == "1234"
        finally:
            sc.terminate()
Ejemplo n.º 5
0
    def test_appending_non_existent_var_creates_it(self):
        """ Append to a non existing env var and assert that the variable is created
            as a result.
        """
        sc = Container()
        try:
            sc.start(DATA)
            sc.set_capabilities(["environment.test.cap.2"])
            sc.launch_command("python " + sc.get_bind_dir() +
                              "/testhelper.py --test-dir " +
                              sc.get_bind_dir() + "/testoutput" +
                              " --do-get-env-vars")

            # The D-Bus LaunchCommand is asynch so let it take effect before assert
            time.sleep(0.5)
            helper = EnvironmentHelper(TESTOUTPUT_DIR)
            variable = helper.env_var("LD_LIBRARY_PATH")
            # Assert the append resulted in the creation of the variable
            assert variable == "/another/path"
        finally:
            sc.terminate()
Ejemplo n.º 6
0
    def test_defaults_are_applied(self):
        """ Test that running without first setting capabilities results in
            the default capabilities being set.
        """
        sc = Container()
        try:
            sc.start(DATA)

            # Start without setting any capabilities
            sc.launch_command("python " + sc.get_bind_dir() +
                              "/testhelper.py --test-dir " +
                              sc.get_bind_dir() + "/testoutput" +
                              " --do-get-env-vars")

            # Give the helper some time to run
            time.sleep(0.25)

            # Verify that the default caps were set.
            helper = EnvironmentHelper(TESTOUTPUT_DIR)
            my_env_var = helper.env_var("TEST_ENV_VAR")
            assert my_env_var == "TEST_ENV_VALUE"
        finally:
            sc.terminate()