Beispiel #1
0
def test_get_requests_proxy_dict_without_proxy(monkeypatch):
    with_gsettings(monkeypatch)
    intercept_proxy_environment(monkeypatch, 'manual',
                                '', '', '', '')

    with clear_proxy_setup_cache():
        proxy_dict = ProxySetup().get_requests_dict()
        assert proxy_dict.get('http') is None
        assert proxy_dict.get('https') is None
        assert proxy_dict.get('no_proxy') is None
Beispiel #2
0
def get_base_dictionary():
    base_dict = {}
    current_user_name = get_user()
    base_dict["edi_current_user_name"] = current_user_name
    base_dict["edi_current_user_group_name"] = get_user_group()
    base_dict["edi_current_user_ssh_pub_keys"] = get_user_ssh_pub_keys()
    base_dict["edi_current_user_uid"] = get_user_uid()
    base_dict["edi_current_user_gid"] = get_user_gid()
    base_dict[
        "edi_current_user_host_home_directory"] = get_user_home_directory(
            current_user_name)
    base_dict["edi_current_user_target_home_directory"] = "/home/{}".format(
        current_user_name)
    base_dict["edi_host_hostname"] = get_hostname()
    base_dict["edi_edi_plugin_directory"] = get_edi_plugin_directory()
    proxy_setup = ProxySetup()
    base_dict["edi_host_http_proxy"] = proxy_setup.get('http_proxy',
                                                       default='')
    base_dict["edi_host_https_proxy"] = proxy_setup.get('https_proxy',
                                                        default='')
    base_dict["edi_host_ftp_proxy"] = proxy_setup.get('ftp_proxy', default='')
    base_dict["edi_host_socks_proxy"] = proxy_setup.get('all_proxy',
                                                        default='')
    base_dict["edi_host_no_proxy"] = proxy_setup.get('no_proxy', default='')
    base_dict["edi_edi_version"] = get_edi_version()
    base_dict["edi_lxd_version"] = get_lxd_version()
    base_dict["edi_current_display"] = get_current_display()
    return base_dict
Beispiel #3
0
def fetch_repository_key(key_url):
    if key_url:
        key_req = requests.get(key_url, proxies=ProxySetup().get_requests_dict())
        if key_req.status_code != 200:
            raise FatalError(("Unable to fetch repository key '{0}'"
                              ).format(key_url))

        return key_req.text
    else:
        return None
Beispiel #4
0
    def _fetch_archive_element_impl(url, check=True):
        req = requests.get(url, proxies=ProxySetup().get_requests_dict())
        if req.status_code != 200:
            if check:
                raise FatalError(
                    ("Unable to fetch archive element '{0}'.").format(url))
            else:
                return None

        return req.content
Beispiel #5
0
def test_get_requests_proxy_dict_with_proxy(monkeypatch):
    with_gsettings(monkeypatch)
    intercept_proxy_environment(monkeypatch, 'manual',
                                '''['localhost', '127.0.0.0/8', '::1']''', '3128',
                                '', '')
    with clear_proxy_setup_cache():
        proxy_dict = ProxySetup().get_requests_dict()
        assert proxy_dict.get('http') == 'http://*****:*****@example.com:3128/'
        assert proxy_dict.get('https') == 'http://*****:*****@example.com:3128/'
        assert proxy_dict.get('no_proxy') == 'localhost,127.0.0.0/8,::1'

        # test cache
        proxy_dict = ProxySetup().get_requests_dict()
        assert proxy_dict.get('http') == 'http://*****:*****@example.com:3128/'
Beispiel #6
0
def test_proxy_setup_no_gsettings_no_env(monkeypatch):
    without_gsettings(monkeypatch)
    intercept_proxy_environment(monkeypatch, 'manual',
                                '''['localhost', '127.0.0.0/8', '::1']''', '3128',
                                '', '')
    with clear_proxy_setup_cache():
        proxy_setup = ProxySetup()
        assert proxy_setup.get('no_proxy', default='') == ''
        assert proxy_setup.get('http_proxy', default='') == ''
        assert proxy_setup.get('https_proxy', default='') == ''
        assert proxy_setup.get('ftp_proxy', default='') == ''
        assert proxy_setup.get('all_proxy', default='') == ''
Beispiel #7
0
def test_get_environment_without_proxy(monkeypatch):
    with_gsettings(monkeypatch)
    intercept_proxy_environment(monkeypatch, 'manual',
                                '', '', '', '')

    with clear_proxy_setup_cache():
        env = ProxySetup().get_environment()
        assert env.get('http_proxy') == ''
        assert env.get('https_proxy') == ''
        assert env.get('ftp_proxy') == ''
        assert env.get('all_proxy') == ''
        assert env.get('no_proxy') == ''
Beispiel #8
0
def test_proxy_setup_gsettings_no_env(monkeypatch):
    with_gsettings(monkeypatch)
    intercept_proxy_environment(monkeypatch, 'manual',
                                '''['localhost', '127.0.0.0/8', '::1']''', '3128',
                                '', '')
    with clear_proxy_setup_cache():
        proxy_setup = ProxySetup()
        assert proxy_setup.get('no_proxy', default='') == 'localhost,127.0.0.0/8,::1'
        assert proxy_setup.get('http_proxy', default='') == 'http://*****:*****@example.com:3128/'
        assert proxy_setup.get('https_proxy', default='') == 'http://*****:*****@example.com:3128/'
        assert proxy_setup.get('ftp_proxy', default='') == 'http://*****:*****@example.com:3128/'
        assert proxy_setup.get('all_proxy', default='') == 'socks://*****:*****@example.com:3128/'
Beispiel #9
0
def test_proxy_setup_gsettings_env(monkeypatch):
    with_gsettings(monkeypatch)
    intercept_proxy_environment(monkeypatch, 'manual',
                                '''['localhost', '127.0.0.0/8', '::1']''', '3128',
                                'protocol://proxy-xy', '1.2.3.4,5.6.7.8,example.com')
    with clear_proxy_setup_cache():
        proxy_setup = ProxySetup()
        assert proxy_setup.get('no_proxy', default='') == '1.2.3.4,5.6.7.8,example.com'
        assert proxy_setup.get('http_proxy', default='') == 'protocol://proxy-xy'
        assert proxy_setup.get('https_proxy', default='') == 'protocol://proxy-xy'
        assert proxy_setup.get('ftp_proxy', default='') == 'protocol://proxy-xy'
        assert proxy_setup.get('all_proxy', default='') == 'protocol://proxy-xy'
Beispiel #10
0
def test_proxy_setup_gsettings_manual_edge_case_no_env(monkeypatch):
    with_gsettings(monkeypatch)
    intercept_proxy_environment(monkeypatch, 'manual',
                                '@as []', '0',
                                '', '')

    with clear_proxy_setup_cache():
        proxy_setup = ProxySetup()
        assert proxy_setup.get('no_proxy') is None
        assert proxy_setup.get('http_proxy') is None
        assert proxy_setup.get('https_proxy') is None
        assert proxy_setup.get('ftp_proxy') is None
        assert proxy_setup.get('all_proxy') is None
Beispiel #11
0
    def _run_debootstrap(self, tempdir, keyring_file, qemu_executable):
        additional_packages = ','.join(
            self.config.get_bootstrap_additional_packages())
        rootfs = os.path.join(tempdir, "rootfs")
        bootstrap_source = SourceEntry(self.config.get_bootstrap_repository())
        components = ",".join(bootstrap_source.comps)

        cmd = list()
        cmd.append("debootstrap")
        cmd.append("--arch={0}".format(
            self.config.get_bootstrap_architecture()))
        if qemu_executable:
            cmd.append("--foreign")
        cmd.append("--variant=minbase")
        cmd.append("--include={0}".format(additional_packages))
        cmd.append("--components={0}".format(components))
        if keyring_file:
            cmd.append("--force-check-gpg")
            cmd.append("--keyring={0}".format(keyring_file))
        cmd.append(bootstrap_source.dist)
        cmd.append(rootfs)
        cmd.append(bootstrap_source.uri)
        run(cmd,
            sudo=True,
            log_threshold=logging.INFO,
            env=ProxySetup().get_environment())

        if qemu_executable:
            qemu_target_path = os.path.join(rootfs, "usr", "bin")
            shutil.copy(qemu_executable, qemu_target_path)
            second_stage_cmd = get_chroot_cmd(rootfs)
            second_stage_cmd.append("/debootstrap/debootstrap")
            second_stage_cmd.append("--second-stage")
            run(second_stage_cmd, sudo=True, log_threshold=logging.INFO)

        return rootfs
Beispiel #12
0
def clear_proxy_setup_cache():
    try:
        ProxySetup(clear_cache=True)
        yield
    finally:
        ProxySetup(clear_cache=True)