def wait_for_report(cls, pulp, response, timeout=300): # now every asyncronous call returns a call report object # call report has 'spawned_tasks' that contains list of tasks # meanwhile every tasks can have its own spawned tasks ret = cls.from_report(response)['spawned_tasks'] if isinstance(ret, list): for task in ret: task_resp = pulp.send(Request('GET', strip_url(task['_href']))) Task.wait_for_response(pulp, task_resp, timeout=timeout) task_resp = pulp.send(Request('GET', strip_url(task['_href']))) if 'spawned_tasks' in Task.from_response(task_resp).data: Task.wait_for_report(pulp, task_resp, timeout=timeout)
def create(cls, pulp, data={}): '''create an upload in pulp; upload.data is based on pulp response''' upload = cls.from_response( pulp.send(Request('POST', cls.path, data=data))) # data returned from the 201 response lacks original metadata upload |= data return upload
def delete_by_type_id( cls, pulp, data, path='/content/actions/delete_orphans/' ): return pulp.send(Request('POST', path=path, data=data))
def list(cls, pulp): ''' Uploads have custom list API @return: list of upload ids ''' with pulp.asserting(True): data = pulp.send(Request('GET', cls.path)).json() assert 'upload_ids' in data, "invalid data received: %s" % data return data['upload_ids']
def test_03_applicabilty_non_existing_consumer(self): #Generate Content Applicability for a single Consumer #if a consumer with given consumer_id does not exist self.pulp.send( Request( 'POST', path_join( Consumer.path, '/NonExistingConsumerID/actions/content/regenerate_applicability/' ))) self.assertPulp(code=404)
def from_report(cls, pulp, report): # report-based constructor # now every asyncronous call returns a call report object # call report has 'spawned_tasks' that contains list of tasks # meanwhile every tasks can have its own spawned tasks data = report.json() assert 'spawned_tasks' in data, 'invalid report data: %s' % data reported_tasks = data['spawned_tasks'] if not reported_tasks: return [] ret = [] for reported_task in reported_tasks: response = pulp.send( Request('GET', strip_url(reported_task['_href']))) assert pulp.is_ok, response.reason task = Task.from_response(response) ret.append(task) if 'spawned_tasks' in task.data: # recurse ret += cls.from_report(pulp, response) return ret
def test_01_view_orphaned_content_invalid_type_1092450(self): # https://bugzilla.redhat.com/show_bug.cgi?id=1092450 self.pulp.send(Request('GET', path_join(Orphans.path, 'invalid_type'))) self.assertPulp(code=404)
def get(cls, pulp, id): '''no GET method allowed (405)''' assert pulp.send(Request('GET', path_join(cls.path, id))) == ResponseLike(405) raise TypeError('Uploads do not support GET method')
def delete(cls, pulp): '''delete all orphans no matter the orphan type''' return pulp.send(Request('DELETE', cls.path))
def info(cls, pulp): return pulp.send(Request('GET', cls.path)).json()
def delete_all(cls, pulp): '''delete all orphans of particular type in pulp instance''' return pulp.send(Request('DELETE', cls.path))