コード例 #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
ファイル: test_utils.py プロジェクト: nebril/fuel-web
 def test_all_rules(self):
     pin = get_apt_preferences_line(self._deb_release)
     self.assertItemsEqual(pin.split(','), [
         'o=TestOrigin',
         'l=TestLabel',
         'a=test-archive',
         'v=42.42',
         'n=testcodename',
     ])
コード例 #4
0
ファイル: test_utils.py プロジェクト: nebril/fuel-web
    def test_suite_is_synonym_for_archive(self):
        deb_release = self._deb_release.copy()
        deb_release['Suite'] = 'test-suite'
        del deb_release['Archive']

        pin = get_apt_preferences_line(deb_release)
        conditions = pin.split(',')

        self.assertIn('a=test-suite', conditions)
コード例 #5
0
    def test_suite_is_synonym_for_archive(self):
        deb_release = self._deb_release.copy()
        deb_release['Suite'] = 'test-suite'
        del deb_release['Archive']

        pin = get_apt_preferences_line(deb_release)
        conditions = pin.split(',')

        self.assertIn('a=test-suite', conditions)
コード例 #6
0
 def test_all_rules(self):
     pin = get_apt_preferences_line(self._deb_release)
     self.assertItemsEqual(pin.split(','), [
         'o=TestOrigin',
         'l=TestLabel',
         'a=test-archive',
         'v=42.42',
         'n=testcodename',
     ])
コード例 #7
0
ファイル: test_utils.py プロジェクト: nebril/fuel-web
    def test_not_all_rules(self):
        deb_release = self._deb_release.copy()

        del deb_release['Codename']
        del deb_release['Label']
        del deb_release['Version']

        pin = get_apt_preferences_line(deb_release)
        self.assertItemsEqual(pin.split(','), [
            'o=TestOrigin',
            'a=test-archive',
        ])
コード例 #8
0
    def test_not_all_rules(self):
        deb_release = self._deb_release.copy()

        del deb_release['Codename']
        del deb_release['Label']
        del deb_release['Version']

        pin = get_apt_preferences_line(deb_release)
        self.assertItemsEqual(pin.split(','), [
            'o=TestOrigin',
            'a=test-archive',
        ])
コード例 #9
0
ファイル: tasks_templates.py プロジェクト: thefuyang/fuel-web
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)
コード例 #10
0
ファイル: tasks_templates.py プロジェクト: yxh1990/deployfuel
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)