Пример #1
0
 def test_normal_ubuntu_repo(self, m_get):
     get_release_file({
         'name': 'myrepo',
         'uri': 'http://some-uri.com/path',
         'suite': 'mysuite',
         'section': 'main university',
     })
     m_get.assert_called_with(
         'http://some-uri.com/path/dists/mysuite/Release')
 def test_normal_ubuntu_repo(self, m_get):
     get_release_file({
         'name': 'myrepo',
         'uri': 'http://some-uri.com/path',
         'suite': 'mysuite',
         'section': 'main university',
     })
     m_get.assert_called_with(
         'http://some-uri.com/path/dists/mysuite/Release')
Пример #3
0
    def test_flat_ubuntu_repo(self, m_get):
        testcases = [
            # (suite, uri)
            ('/', 'http://some-uri.com/deb/Release'),
            ('/path', 'http://some-uri.com/deb/path/Release'),
            ('path', 'http://some-uri.com/deb/path/Release'),
        ]

        for suite, uri in testcases:
            get_release_file({
                'name': 'myrepo',
                'uri': 'http://some-uri.com/deb',
                'suite': suite,
                'section': '',
            })
            m_get.assert_called_with(uri)
    def test_flat_ubuntu_repo(self, m_get):
        testcases = [
            # (suite, uri)
            ('/', 'http://some-uri.com/deb/Release'),
            ('/path', 'http://some-uri.com/deb/path/Release'),
            ('path', 'http://some-uri.com/deb/path/Release'),
        ]

        for suite, uri in testcases:
            get_release_file({
                'name': 'myrepo',
                'uri': 'http://some-uri.com/deb',
                'suite': suite,
                'section': '',
            })
            m_get.assert_called_with(uri)
Пример #5
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)
Пример #6
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)
Пример #7
0
    def test_returns_content_if_http_ok(self, m_get):
        r = requests.Response()
        r._content = 'content'
        r.status_code = 200
        m_get.return_value = r

        content = get_release_file({
            'name': 'myrepo',
            'uri': 'http://some-uri.com/path',
            'suite': 'mysuite',
            'section': 'main university',
        })
        self.assertEqual(content, 'content')
    def test_returns_content_if_http_ok(self, m_get):
        r = requests.Response()
        r._content = 'content'
        r.status_code = 200
        m_get.return_value = r

        content = get_release_file({
            'name': 'myrepo',
            'uri': 'http://some-uri.com/path',
            'suite': 'mysuite',
            'section': 'main university',
        })
        self.assertEqual(content, 'content')
Пример #9
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)
Пример #10
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)