Exemplo n.º 1
0
def load_os_config(platform_name, os_name, require_enabled=False,
                   feature_overrides=None):
    """Load configuration for os.

    @param platform_name: platform name to load os config for
    @param os_name: name of os to retrieve config for
    @param require_enabled: if true, raise error if 'enabled' not True
    @param feature_overrides: feature flag overrides to merge with features
    @return_value: config dict
    """
    if feature_overrides is None:
        feature_overrides = {}
    main_conf = c_util.read_conf(RELEASES_CONF)
    default = main_conf['default_release_config']
    image = main_conf['releases'][os_name]
    conf = merge_config(merge_config(get(default, 'default'),
                                     get(default, platform_name)),
                        merge_config(get(image, 'default'),
                                     get(image, platform_name)))

    feature_conf = main_conf['features']
    feature_groups = conf.get('feature_groups', [])
    overrides = merge_config(get(conf, 'features'), feature_overrides)
    conf['arch'] = c_util.get_dpkg_architecture()
    conf['features'] = merge_feature_groups(
        feature_conf, feature_groups, overrides)

    if require_enabled and not enabled(conf):
        raise ValueError('OS is not enabled')
    return conf
Exemplo n.º 2
0
def get_default_mirrors(arch=None, target=None):
    """returns the default mirrors for the target. These depend on the
       architecture, for more see:
       https://wiki.ubuntu.com/UbuntuDevelopment/PackageArchive#Ports"""
    if arch is None:
        arch = util.get_dpkg_architecture(target)
    if arch in PRIMARY_ARCHES:
        return PRIMARY_ARCH_MIRRORS.copy()
    if arch in PORTS_ARCHES:
        return PORTS_MIRRORS.copy()
    raise ValueError("No default mirror known for arch %s" % arch)
Exemplo n.º 3
0
    def get_image(self, img_conf):
        """Get image using specified image configuration.

        @param img_conf: configuration for image
        @return_value: cloud_tests.images instance
        """
        (url, path) = s_util.path_from_mirror_url(img_conf['mirror_url'], None)

        filter = filters.get_filters([
            'arch=%s' % c_util.get_dpkg_architecture(),
            'release=%s' % img_conf['release'],
            'ftype=disk1.img',
        ])
        mirror_config = {
            'filters': filter,
            'keep_items': False,
            'max_items': 1,
            'checksumming_reader': True,
            'item_download': True
        }

        def policy(content, path):
            return s_util.read_signed(content, keyring=img_conf['keyring'])

        smirror = mirrors.UrlMirrorReader(url, policy=policy)
        tstore = objectstores.FileStore(img_conf['mirror_dir'])
        tmirror = mirrors.ObjectFilterMirror(config=mirror_config,
                                             objectstore=tstore)
        tmirror.sync(smirror, path)

        search_d = os.path.join(img_conf['mirror_dir'], '**',
                                img_conf['release'], '**', '*.img')

        images = []
        for fname in glob.iglob(search_d, recursive=True):
            images.append(fname)

        if len(images) < 1:
            raise RuntimeError("No images found under '%s'" % search_d)
        if len(images) > 1:
            raise RuntimeError("Multiple images found in '%s': %s" %
                               (search_d, ' '.join(images)))

        image = NoCloudKVMImage(self, img_conf, images[0])
        return image
Exemplo n.º 4
0
def apply_apt(cfg, cloud, target):
    # cfg is the 'apt' top level dictionary already in 'v3' format.
    if not cfg:
        should_config, msg = _should_configure_on_empty_apt()
        if not should_config:
            LOG.debug("Nothing to do: No apt config and %s", msg)
            return

    LOG.debug("handling apt config: %s", cfg)

    release = util.lsb_release(target=target)["codename"]
    arch = util.get_dpkg_architecture(target)
    mirrors = find_apt_mirror_info(cfg, cloud, arch=arch)
    LOG.debug("Apt Mirror info: %s", mirrors)

    if util.is_false(cfg.get("preserve_sources_list", False)):
        add_mirror_keys(cfg, target)
        generate_sources_list(cfg, release, mirrors, cloud)
        rename_apt_lists(mirrors, target, arch)

    try:
        apply_apt_config(cfg, APT_PROXY_FN, APT_CONFIG_FN)
    except (IOError, OSError):
        LOG.exception("Failed to apply proxy or apt config info:")

    # Process 'apt_source -> sources {dict}'
    if "sources" in cfg:
        params = mirrors
        params["RELEASE"] = release
        params["MIRROR"] = mirrors["MIRROR"]

        matcher = None
        matchcfg = cfg.get("add_apt_repo_match", ADD_APT_REPO_MATCH)
        if matchcfg:
            matcher = re.compile(matchcfg).search

        add_apt_sources(
            cfg["sources"],
            cloud,
            target=target,
            template_params=params,
            aa_repo_match=matcher,
        )
Exemplo n.º 5
0
def find_apt_mirror_info(cfg, cloud, arch=None):
    """find_apt_mirror_info
       find an apt_mirror given the cfg provided.
       It can check for separate config of primary and security mirrors
       If only primary is given security is assumed to be equal to primary
       If the generic apt_mirror is given that is defining for both
    """

    if arch is None:
        arch = util.get_dpkg_architecture()
        LOG.debug("got arch for mirror selection: %s", arch)
    pmirror = get_mirror(cfg, "primary", arch, cloud)
    LOG.debug("got primary mirror: %s", pmirror)
    smirror = get_mirror(cfg, "security", arch, cloud)
    LOG.debug("got security mirror: %s", smirror)

    mirror_info = update_mirror_info(pmirror, smirror, arch, cloud)

    # less complex replacements use only MIRROR, derive from primary
    mirror_info["MIRROR"] = mirror_info["PRIMARY"]

    return mirror_info
Exemplo n.º 6
0
 def get_primary_arch(self):
     return util.get_dpkg_architecture()