Exemple #1
0
    def test_build_sorting(self):
        """Ensure we can sort a list of builds"""
        b1 = brew.Build(nvr='abcd-1.0.0')
        b2 = brew.Build(nvr='zyxw-1.0.0')
        # Same one as before for equality
        b3 = brew.Build(nvr='zyxw-1.0.0')

        self.assertGreater(b2, b1)
        self.assertLess(b1, b2)
        self.assertEqual(b2, b3)
Exemple #2
0
    def test_build_equality(self):
        """Ensure brew Builds are unique and can be tested for equality"""
        b1 = brew.Build(nvr='megafrobber-1.3.3-7')
        b2 = brew.Build(nvr='tuxracer-42')

        builds = set([])
        builds.add(str(b1))
        builds.add(str(b1))

        self.assertEqual(1, len(builds))
        self.assertTrue(b1 != b2)
Exemple #3
0
def get_brew_build(nvr, product_version='', session=None):
    """5.2.2.1. GET /api/v1/build/{id_or_nvr}

    Get Brew build details.

    https://errata.devel.redhat.com/developer-guide/api-http-api.html#api-get-apiv1buildid_or_nvr

    :param str nvr: A name-version-release string of a brew rpm/image build
    :param str product_version: The product version tag as given to ET
    when attaching a build
    :param requests.Session session: A python-requests Session object,
    used for for connection pooling. Providing `session` object can
    yield a significant reduction in total query time when looking up
    many builds.

    http://docs.python-requests.org/en/master/user/advanced/#session-objects

    :return: An initialized Build object with the build details
    :raises exceptions.BrewBuildException: When build not found

    """
    if session is None:
        session = requests.session()

    res = session.get(constants.errata_get_build_url.format(id=nvr),
                      verify=ssl.get_default_verify_paths().openssl_cafile,
                      auth=HTTPKerberosAuth())

    if res.status_code == 200:
        return brew.Build(nvr=nvr,
                          body=res.json(),
                          product_version=product_version)
    else:
        raise exceptions.BrewBuildException("{build}: {msg}".format(
            build=nvr, msg=res.text))
Exemple #4
0
def get_brew_builds(errata_id, session=None):
    """5.2.2.1. GET /api/v1/erratum/{id}/builds

    Get Errata list of builds.

    https://errata.devel.redhat.com/developer-guide/api-http-api.html#api-get-apiv1erratumidbuilds
    :param str errata_id: the errata id
    :param requests.Session session: A python-requests Session object,
    used for for connection pooling. Providing `session` object can
    yield a significant reduction in total query time when looking up
    many builds.

    http://docs.python-requests.org/en/master/user/advanced/#session-objects

    :return: A List of initialized Build object with the build details
    :raises exceptions.BrewBuildException: When erratum return errors

    """
    if session is None:
        session = requests.session()

    res = session.get(constants.errata_get_builds_url.format(id=errata_id),
                      verify=ssl.get_default_verify_paths().openssl_cafile,
                      auth=HTTPKerberosAuth())
    brew_list = []
    if res.status_code == 200:
        jlist = res.json()
        for key in jlist.keys():
            for obj in jlist[key]['builds']:
                brew_list.append(
                    brew.Build(nvr=list(obj.keys())[0], product_version=key))
        return brew_list
    else:
        raise exceptions.BrewBuildException(
            "fetch builds from {id}: {msg}".format(id=errata_id, msg=res.text))
Exemple #5
0
 def test_build_attached_to_closed_erratum(self):
     """We can tell if a build is attached to any closed erratum"""
     # Use filter #1991: (Active; Product: RHOSE; sorted by newest)
     b = brew.Build(nvr='template-service-broker-docker-v3.7.36-2',
                    body=test_structures.image_build_attached_closed_json,
                    product_version='rhaos-test-7')
     self.assertTrue(b.attached_to_closed_erratum)
Exemple #6
0
 def test_build_attached_to_open_erratum(self):
     """We can tell if a build is attached to any open erratum"""
     # Create Erratum(), create Build() using dict with all_errata
     # containing an object with 'id' matching Erratum.advisory_id
     b = brew.Build(nvr='template-service-broker-docker-v3.7.36-2',
                    body=test_structures.image_build_attached_open_json,
                    product_version='rhaos-test-7')
     self.assertTrue(b.attached_to_open_erratum)
Exemple #7
0
    def test_good_unattached_brew_rpm_build(self):
        """We can create and process an unattached rpm Build object"""
        b = brew.Build(nvr='ansible-service-broker-1.0.21-1.el7',
                       body=test_structures.rpm_build_unattached_json,
                       product_version='rhaos-test-7')

        self.assertEqual('ansible-service-broker-1.0.21-1.el7', b.nvr)
        self.assertEqual('rpm', b.kind)
        self.assertEqual('rpm', b.file_type)
        self.assertFalse(b.attached)
Exemple #8
0
    def test_good_attached_brew_rpm_build(self):
        """We can create and process an attached rpm Build object"""
        b = brew.Build(nvr='coreutils-8.22-21.el7',
                       body=test_structures.rpm_build_attached_json,
                       product_version='rhaos-test-7')

        self.assertEqual('coreutils-8.22-21.el7', b.nvr)
        self.assertEqual('rpm', b.kind)
        self.assertEqual('rpm', b.file_type)
        self.assertTrue(b.attached)
Exemple #9
0
    def test_good_unattached_brew_image_build(self):
        """We can create and process an unattached image Build object"""
        b = brew.Build(nvr='cri-o-docker-v3.7.37-1',
                       body=test_structures.image_build_unattached_json,
                       product_version='rhaos-test-7')

        self.assertEqual('cri-o-docker-v3.7.37-1', b.nvr)
        self.assertEqual('image', b.kind)
        self.assertEqual('tar', b.file_type)
        self.assertFalse(b.attached)
Exemple #10
0
    def test_good_attached_brew_image_build(self):
        """We can create and process an attached image Build object"""
        b = brew.Build(nvr='template-service-broker-docker-v3.7.36-2',
                       body=test_structures.image_build_attached_json,
                       product_version='rhaos-test-7')

        self.assertEqual('template-service-broker-docker-v3.7.36-2', b.nvr)
        self.assertEqual('image', b.kind)
        self.assertEqual('tar', b.file_type)
        self.assertTrue(b.attached)
Exemple #11
0
    def test_image_build_json_formatting(self):
        """Ensure a brew Build returns proper JSON for API posting"""
        nvr = 'template-service-broker-docker-v3.7.36-2'
        pv = 'rhaos-test-7'

        b = brew.Build(nvr=nvr,
                       body=test_structures.image_build_attached_json,
                       product_version=pv)

        expected_json = {
            'product_version': pv,
            'build': nvr,
            'file_types': ['tar']
        }

        self.assertEqual(expected_json, b.to_json())
Exemple #12
0
    def test_rpm_build_json_formatting(self):
        """Ensure a brew Build returns proper JSON for API posting"""
        nvr = 'coreutils-8.22-21.el7'
        pv = 'rhaos-test-7'

        b = brew.Build(nvr=nvr,
                       body=test_structures.rpm_build_attached_json,
                       product_version=pv)

        expected_json = {
            'product_version': pv,
            'build': nvr,
            'file_types': ['rpm']
        }

        self.assertEqual(expected_json, b.to_json())
Exemple #13
0
 def test_build_display(self):
     """Verify brew Builds display correctly"""
     nvr = 'megafrobber-1.3.3-7'
     b = brew.Build(nvr=nvr)
     self.assertEqual(nvr, str(b))
     self.assertEqual("Build({nvr})".format(nvr=nvr), repr(b))