Ejemplo n.º 1
0
 def test__leaves_other_variables_intact(self):
     untouched_var, untouched_value = self.make_variable()
     var, value = self.make_variable()
     with env.environment_variables({untouched_var: untouched_value}):
         with env.environment_variables({var: value}):
             environment = os.environ.copy()
     self.assertEqual(untouched_value, environment[untouched_var])
Ejemplo n.º 2
0
 def test__overrides_prior_values(self):
     var, prior_value = self.make_variable()
     temp_value = factory.make_name("temp-value")
     with env.environment_variables({var: prior_value}):
         with env.environment_variables({var: temp_value}):
             environment = os.environ.copy()
     self.assertEqual(temp_value, environment[var])
Ejemplo n.º 3
0
 def test__restores_variables_to_previous_values(self):
     var, prior_value = self.make_variable()
     temp_value = factory.make_name("temp-value")
     with env.environment_variables({var: prior_value}):
         with env.environment_variables({var: temp_value}):
             pass
         environment = os.environ.copy()
     self.assertEqual(prior_value, environment[var])
Ejemplo n.º 4
0
def _run_import(sources, maas_url, http_proxy=None, https_proxy=None):
    """Run the import.

    This is function is synchronous so it must be called with deferToThread.
    """
    # Fix the sources to download from the IP address defined in the cluster
    # configuration, instead of the URL that the region asked it to use.
    sources = fix_sources_for_cluster(sources, maas_url)
    variables = {"GNUPGHOME": get_maas_user_gpghome()}
    if http_proxy is not None:
        variables["http_proxy"] = http_proxy
    if https_proxy is not None:
        variables["https_proxy"] = https_proxy
    # Communication to the sources and loopback should not go through proxy.
    no_proxy_hosts = [
        "localhost",
        "::ffff:127.0.0.1",
        "127.0.0.1",
        "::1",
        "[::ffff:127.0.0.1]",
        "[::1]",
    ]
    no_proxy_hosts += list(get_hosts_from_sources(sources))
    variables["no_proxy"] = ",".join(no_proxy_hosts)
    with environment_variables(variables):
        imported = boot_resources.import_images(sources)

    # Update the boot images cache so `list_boot_images` returns the
    # correct information.
    reload_boot_images()

    # Tell callers if anything happened.
    return imported
Ejemplo n.º 5
0
def is_filesystem_file(path):
    """Does the file at `path` look like a filesystem-in-a-file?"""
    # Identify filesystems using the "file" utility.  We'll be parsing the
    # output, so suppress any translation.
    with environment_variables({'LANG': 'C'}):
        output = check_output(['file', path])
    return b"filesystem data" in output
Ejemplo n.º 6
0
    def test__restores_even_after_exception(self):
        var, value = self.make_variable()
        self.assertNotIn(var, os.environ)

        class DeliberateException(Exception):
            pass

        with ExpectedException(DeliberateException):
            with env.environment_variables({var: value}):
                raise DeliberateException()

        self.assertNotIn(var, os.environ)
Ejemplo n.º 7
0
 def test__restores_previously_unset_variables_to_being_unset(self):
     var, value = self.make_variable()
     self.assertNotIn(var, os.environ)
     with env.environment_variables({var: value}):
         pass
     self.assertNotIn(var, os.environ)
Ejemplo n.º 8
0
 def test__sets_variables(self):
     var, value = self.make_variable()
     with env.environment_variables({var: value}):
         environment = os.environ.copy()
     self.assertEqual(value, environment[var])