示例#1
0
def make_ubuntu_preferences_task(uids, repo):
    # NOTE(ikalnitsky): In order to implement the proper pinning,
    # we have to download and parse the repo's "Release" file.
    # Generally, that's not a good idea to make some HTTP request
    # from Nailgun, but taking into account that this task
    # will be executed in uWSGI's mule worker we can skip this
    # rule, because proper pinning is more valuable thing right now.

    template = '\n'.join([
        'Package: *',
        'Pin: release {conditions}',
        'Pin-Priority: {priority}'])
    preferences_content = []

    try:
        release = debian.get_release_file(repo, retries=3)
        release = debian.parse_release_file(release)
        pin = debian.get_apt_preferences_line(release)

    except requests.exceptions.HTTPError as exc:
        logger.error("Failed to fetch 'Release' file due to '%s'. "
                     "The apt preferences won't be applied for repo '%s'.",
                     six.text_type(exc), repo['name'])
        return None

    except Exception:
        logger.exception("Failed to parse 'Release' file.")
        return None

    # NOTE(kozhukalov): When a package is available both in:
    # 1) http://archive.ubuntu.com/ubuntu trusty universe
    # 2) http://mirror.fuel-infra.org/mos-repos/ubuntu/7.0 mos7.0 main
    # And if the content of the preferences file is (i.e. by section priority):
    #    Package: *
    #    Pin: release o=Mirantis, a=mos7.0, n=mos7.0, l=mos7.0, c=main
    #    Pin-Priority: 1050
    # then the package available in MOS won't match the pin because for
    # some reason apt still thinks this package is in universe section.
    # As a result:
    # # apt-cache policy ohai
    # ohai:
    # Installed: (none)
    # Candidate: 6.14.0-2
    # Version table:
    # 6.14.0-2 0
    #    500 http://10.20.0.1/mirror/ubuntu/ trusty/universe amd64 Packages
    # 6.14.0-2~u14.04+mos1 0
    #    500 http://10.20.0.2:8080/2015.1.0-7.0/ubuntu/x86_64/ mos7.0/main
    # amd64 Packages

    preferences_content.append(template.format(
        conditions=pin,
        priority=repo['priority']))

    preferences_content = '\n\n'.join(preferences_content)
    preferences_path = '/etc/apt/preferences.d/{0}.pref'.format(repo['name'])
    return make_upload_task(uids, preferences_content, preferences_path)
示例#2
0
def make_ubuntu_preferences_task(uids, repo):
    # NOTE(ikalnitsky): In order to implement the proper pinning,
    # we have to download and parse the repo's "Release" file.
    # Generally, that's not a good idea to make some HTTP request
    # from Nailgun, but taking into account that this task
    # will be executed in uWSGI's mule worker we can skip this
    # rule, because proper pinning is more valuable thing right now.

    template = '\n'.join([
        'Package: *',
        'Pin: release {conditions}',
        'Pin-Priority: {priority}'])
    preferences_content = []

    try:
        release = debian.get_release_file(repo, retries=3)
        release = debian.parse_release_file(release)
        pin = debian.get_apt_preferences_line(release)

    except requests.exceptions.HTTPError as exc:
        logger.error("Failed to fetch 'Release' file due to '%s'. "
                     "The apt preferences won't be applied for repo '%s'.",
                     six.text_type(exc), repo['name'])
        return None

    except Exception:
        logger.exception("Failed to parse 'Release' file.")
        return None

    # NOTE(kozhukalov): When a package is available both in:
    # 1) http://archive.ubuntu.com/ubuntu trusty universe
    # 2) http://mirror.fuel-infra.org/mos-repos/ubuntu/7.0 mos7.0 main
    # And if the content of the preferences file is (i.e. by section priority):
    #    Package: *
    #    Pin: release o=Mirantis, a=mos7.0, n=mos7.0, l=mos7.0, c=main
    #    Pin-Priority: 1050
    # then the package available in MOS won't match the pin because for
    # some reason apt still thinks this package is in universe section.
    # As a result:
    # # apt-cache policy ohai
    # ohai:
    # Installed: (none)
    # Candidate: 6.14.0-2
    # Version table:
    # 6.14.0-2 0
    #    500 http://10.20.0.1/mirror/ubuntu/ trusty/universe amd64 Packages
    # 6.14.0-2~u14.04+mos1 0
    #    500 http://10.20.0.2:8080/2015.1.0-7.0/ubuntu/x86_64/ mos7.0/main
    # amd64 Packages

    preferences_content.append(template.format(
        conditions=pin,
        priority=repo['priority']))

    preferences_content = '\n\n'.join(preferences_content)
    preferences_path = '/etc/apt/preferences.d/{0}.pref'.format(repo['name'])
    return make_upload_task(uids, preferences_content, preferences_path)
示例#3
0
def make_ubuntu_preferences_task(uids, repo):
    # NOTE(ikalnitsky): In order to implement the proper pinning,
    # we have to download and parse the repo's "Release" file.
    # Generally, that's not a good idea to make some HTTP request
    # from Nailgun, but taking into account that this task
    # will be executed in uWSGI's mule worker we can skip this
    # rule, because proper pinning is more valuable thing right now.

    template = '\n'.join([
        'Package: *',
        'Pin: release {conditions}',
        'Pin-Priority: {priority}'])
    preferences_content = []

    try:
        release = debian.get_release_file(repo, retries=3)
        release = debian.parse_release_file(release)
        pin = debian.get_apt_preferences_line(release)

    except requests.exceptions.HTTPError as exc:
        logger.error("Failed to fetch 'Release' file due to '%s'. "
                     "The apt preferences won't be applied for repo '%s'.",
                     six.text_type(exc), repo['name'])
        return None

    except Exception:
        logger.exception("Failed to parse 'Release' file.")
        return None

    # if sections are detected (non-flat repo) create pinning per
    # sections; otherwise - create just one pin for the entire repo
    if repo['section']:
        for section in repo['section'].split():
            preferences_content.append(template.format(
                conditions='{0},c={1}'.format(pin, section),
                priority=repo['priority']))
    else:
        preferences_content.append(template.format(
            conditions=pin,
            priority=repo['priority']))

    preferences_content = '\n\n'.join(preferences_content)
    preferences_path = '/etc/apt/preferences.d/{0}.pref'.format(repo['name'])
    return make_upload_task(uids, preferences_content, preferences_path)
示例#4
0
def make_ubuntu_preferences_task(uids, repo):
    # NOTE(ikalnitsky): In order to implement the proper pinning,
    # we have to download and parse the repo's "Release" file.
    # Generally, that's not a good idea to make some HTTP request
    # from Nailgun, but taking into account that this task
    # will be executed in uWSGI's mule worker we can skip this
    # rule, because proper pinning is more valuable thing right now.

    template = '\n'.join([
        'Package: *',
        'Pin: release {conditions}',
        'Pin-Priority: {priority}'])
    preferences_content = []

    try:
        release = debian.get_release_file(repo, retries=3)
        release = debian.parse_release_file(release)
        pin = debian.get_apt_preferences_line(release)

    except requests.exceptions.HTTPError as exc:
        logger.error("Failed to fetch 'Release' file due to '%s'. "
                     "The apt preferences won't be applied for repo '%s'.",
                     six.text_type(exc), repo['name'])
        return None

    except Exception:
        logger.exception("Failed to parse 'Release' file.")
        return None

    # if sections are detected (non-flat repo) create pinning per
    # sections; otherwise - create just one pin for the entire repo
    if repo['section']:
        for section in repo['section'].split():
            preferences_content.append(template.format(
                conditions='{0},c={1}'.format(pin, section),
                priority=repo['priority']))
    else:
        preferences_content.append(template.format(
            conditions=pin,
            priority=repo['priority']))

    preferences_content = '\n\n'.join(preferences_content)
    preferences_path = '/etc/apt/preferences.d/{0}.pref'.format(repo['name'])
    return make_upload_task(uids, preferences_content, preferences_path)
示例#5
0
    def test_parse(self):
        deb_release = parse_release_file(self._deb_release_info)

        self.assertEqual(
            deb_release, {
                'Origin':
                'TestOrigin',
                'Label':
                'TestLabel',
                'Archive':
                'test-archive',
                'Codename':
                'testcodename',
                'Date':
                'Thu, 08 May 2014 14:19:09 UTC',
                'Architectures':
                'amd64 i386',
                'Components':
                'main restricted universe multiverse',
                'Description':
                'Test Description',
                'MD5Sum': [{
                    'md5sum': 'ead1cbf42ed119c50bf3aab28b5b6351',
                    'size': '934',
                    'name': 'main/binary-amd64/Packages',
                }, {
                    'md5sum': '52d605b4217be64f461751f233dd9a8f',
                    'size': '96',
                    'name': 'main/binary-amd64/Release',
                }],
                'SHA1': [{
                    'sha1': '28c4460e3aaf1b93f11911fdc4ff23c28809af89',
                    'size': '934',
                    'name': 'main/binary-amd64/Packages',
                }, {
                    'sha1': 'd03d716bceaba35f91726c096e2a9a8c23ccc766',
                    'size': '96',
                    'name': 'main/binary-amd64/Release',
                }],
            })
    def test_parse(self):
        deb_release = parse_release_file(self._deb_release_info)

        self.assertEqual(deb_release, {
            'Origin': 'TestOrigin',
            'Label': 'TestLabel',
            'Archive': 'test-archive',
            'Codename': 'testcodename',
            'Date': 'Thu, 08 May 2014 14:19:09 UTC',
            'Architectures': 'amd64 i386',
            'Components': 'main restricted universe multiverse',
            'Description': 'Test Description',
            'MD5Sum': [
                {
                    'md5sum': 'ead1cbf42ed119c50bf3aab28b5b6351',
                    'size': '934',
                    'name': 'main/binary-amd64/Packages',
                },
                {
                    'md5sum': '52d605b4217be64f461751f233dd9a8f',
                    'size': '96',
                    'name': 'main/binary-amd64/Release',
                }
            ],
            'SHA1': [
                {
                    'sha1': '28c4460e3aaf1b93f11911fdc4ff23c28809af89',
                    'size': '934',
                    'name': 'main/binary-amd64/Packages',
                },
                {
                    'sha1': 'd03d716bceaba35f91726c096e2a9a8c23ccc766',
                    'size': '96',
                    'name': 'main/binary-amd64/Release',
                }
            ],
        })