Skip to content

Commit

Permalink
WIP: add helper functions to errata connector
Browse files Browse the repository at this point in the history
- add helper to get list of releases by product either id or name
- add helper option 1 to retrieve advisories by release id (using
- add helper option 2 to retrieve advisories by release id (using _filter)

Related: red-hat-storage#132
  • Loading branch information
yazug committed May 7, 2019
1 parent 81ebb0d commit 3a2a74e
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion errata_tool/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _processResponse(self, r):
str(r.status_code))


def filter(self, endpoint, filter_arg, **kwargs):
def _filter(self, endpoint, filter_arg, **kwargs):
"""format and generate filter request
expose a general filter helper method to format kwargs up
as parameters for ET filter request. Then return generated
Expand All @@ -280,3 +280,44 @@ def filter(self, endpoint, filter_arg, **kwargs):
url = url + '&format=json'
print(url)
return self._get(url)

def get_releases_for_product(self, product_name_or_id, return_ids_only=True):

This comment has been minimized.

Copy link
@yazug

yazug May 8, 2019

Author Owner

not actually product ... it's name of release

This comment has been minimized.

Copy link
@yazug

yazug May 8, 2019

Author Owner

done

"""search for and return list of releases by name or id of product"""
args = {'is_active':'true', 'enabled':'true'}

try:
args['id'] = int(product_name_or_id)
except ValueError:
args['name'] = product_name_or_id

data = self._filter('/api/v1/releases', 'filter', **args)
if return_ids_only:
return [i['id'] for i in data['data']]

return data

def get_open_advisories_for_release(self, release_id):
data = self._get('/errata/errata_for_release/{0}.json'.format(release_id))

ADVISORY_STATES = ('NEW_FILES', 'QE', 'REL_PREP', 'PUSH_READY')
advisory_ids = set()

for advisory_result in data:
if advisory_result['status'] in ADVISORY_STATES:
advisory_ids.add(advisory_result['id'])
return list(advisory_ids)

def get_open_advisories_for_release_filter(self, release_id, return_ids_only=True):
"""Return list of open advisories for a release either id's or json summary"""

data = self._filter(
'/errata', 'errata_filter[filter_params]',
show_type_RHBA=1, show_type_RHEA=1, show_type_RHSA=1,
show_state_NEW_FILES=1, show_state_QE=1, show_state_REL_PREP=1,
show_state_PUSH_READY=1, open_closed_option='exclude',
release=release_id)

if return_ids_only:
return [i['id'] for i in data]

return data

1 comment on commit 3a2a74e

@yazug
Copy link
Owner Author

@yazug yazug commented on 3a2a74e May 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to move this whole thing over to new file, filter.py
and Need to get unittests included to cover these methods

Please sign in to comment.