SatelliteQE / robottelo

Robottelo is a test suite that exercises The Foreman.
GNU General Public License v3.0
61 stars 112 forks source link

KeyError: 'status' if bz['status'] in OPEN_STATUSES: #7486

Closed vijay8451 closed 4 years ago

vijay8451 commented 4 years ago

KeyError: 'status' if bz['status'] in OPEN_STATUSES:

2019-11-15 13:07:52 - robottelo.helpers - DEBUG - Generated file bz_cache.json with BZ collect data

tests/foreman/cli/test_repository.py::RepositoryTestCase::test_negative_synchronize_docker_repo_with_mix_valid_invalid_tags FAILED                                    [100%]

================================================================================= FAILURES ==================================================================================
___________________________________________ RepositoryTestCase.test_negative_synchronize_docker_repo_with_mix_valid_invalid_tags ____________________________________________

self = <tests.foreman.cli.test_repository.RepositoryTestCase testMethod=test_negative_synchronize_docker_repo_with_mix_valid_invalid_tags>

    @tier2
    def test_negative_synchronize_docker_repo_with_mix_valid_invalid_tags(self):
        """Set tags whitelist to contain both valid and invalid (non-existing)
        tags. Check if only whitelisted tags are synchronized

        :id: 75668da8-cc94-4d39-ade1-d3ef91edc812

        :expectedresults: Only whitelisted tag is synchronized
        """
        tags = ['latest', gen_string('alpha')]
        repo = self._make_repository({
            'content-type': 'docker',
            'docker-upstream-name': 'alpine',
            'url': DOCKER_REGISTRY_HUB,
            'docker-tags-whitelist': ",".join(tags),
        })
        Repository.synchronize({'id': repo['id']})
>       repo = self._validated_image_tags_count(repo=repo)

tests/foreman/cli/test_repository.py:1064: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/foreman/cli/test_repository.py:132: in _validated_image_tags_count
    if is_open('BZ:1664631'):
robottelo/helpers.py:779: in is_open
    return handlers[handler_code.strip()](issue.strip(), data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

issue = 'BZ:1664631', data = None

    def is_open_bz(issue, data=None):
        """Check if specific BZ is open consulting a cached `data` dict or
        calling Bugzilla REST API.

        Arguments:
            issue {str} -- The BZ reference e.g: BZ:123456
            data {dict} -- Issue data indexed by <handler>:<number> or None
        """

        bz = try_from_cache(issue, data)
        if bz.get("is_open") is not None:  # bug has been already processed
            return bz["is_open"]

        bz = follow_duplicates(bz)

        # BZ is explicitly in OPEN status
>       if bz['status'] in OPEN_STATUSES:
E       KeyError: 'status'

robottelo/issue_handlers/bugzilla.py:41: KeyError
vijay8451 commented 4 years ago

@rochacbruno to me more looks a bug ..

rochacbruno commented 4 years ago

@vijay8451 I am not able to reproduce the problem, this is expected that it fails if was not possible to talk to BZ api, we need to improve the error message.

I would like to reproduce it, do you have more info? do you have api_key set?

vijay8451 commented 4 years ago

@rochacbruno yes api_key exists and correct as well...

tests/foreman/cli/test_repository.py::RepositoryTestCase::test_negative_synchronize_docker_repo_with_mix_valid_invalid_tags
lhellebr commented 4 years ago

This happens when is_open function is used outside of test, for example in setUpClass. It happens because the BZ status is only cached when:

f364bd912 robottelo/helpers.py        (Bruno Rocha            2019-10-29 17:06:15 -0300 899)         if 'is_open(' in source:
rochacbruno commented 4 years ago

@lhellebr thanks now I got it.

This was supposed to force an API call to bugzilla on deman, for example if I call is_open('BZ:123') but BZ is not yet fetched, then an API call is fired on-demand.

I am taking a look on why this is not happening.

rochacbruno commented 4 years ago

7465 includes a possible fix for this problem

https://github.com/SatelliteQE/robottelo/pull/7465/commits/c49bf915c2f24d7cf215d6d5068ff1d7a4ac0fe4#diff-7317a8934342592454d26e6d8c3ea341R296-R307

vijay8451 commented 4 years ago

@rochacbruno thanks , same fix also requires to be cherry-pick for 6.6.z branch as well.