Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ret = utils.get_task_from_instance(
"cluster1", "my-service", "main", slave_hostname="test"
)
mock_api.service.tasks_instance.side_effect = HTTPError(
response=mock.Mock(status_code=500)
)
with raises(utils.PaastaTaskNotFound):
ret = utils.get_task_from_instance(
"cluster1", "my-service", "main", slave_hostname="test"
)
mock_api.service.tasks_instance.assert_called_with(
service="my-service", instance="main", verbose=True, slave_hostname="test"
)
mock_api.service.tasks_instance.side_effect = HTTPNotFound(
response=mock.Mock(status_code=404)
)
with raises(utils.PaastaTaskNotFound):
ret = utils.get_task_from_instance(
"cluster1", "my-service", "main", slave_hostname="test"
)
def get_state(job_id):
"""Returns a tuple of whether the job exists, and if so the state."""
try:
test_job, response = service.jobs.get_job_by_id(jobId=job_id).result()
assert response.status_code == 200
except HTTPNotFound:
return False, None
return True, test_job
ret = utils.get_task_from_instance(
"cluster1", "my-service", "main", slave_hostname="test"
)
mock_api.service.tasks_instance.side_effect = HTTPError(
response=mock.Mock(status_code=500)
)
with raises(utils.PaastaTaskNotFound):
ret = utils.get_task_from_instance(
"cluster1", "my-service", "main", slave_hostname="test"
)
mock_api.service.tasks_instance.assert_called_with(
service="my-service", instance="main", verbose=True, slave_hostname="test"
)
mock_api.service.tasks_instance.side_effect = HTTPNotFound(
response=mock.Mock(status_code=404)
)
with raises(utils.PaastaTaskNotFound):
ret = utils.get_task_from_instance(
"cluster1", "my-service", "main", slave_hostname="test"
)
filtered by whether a topic's most recent schema has a primary_key
Args:
topics (list[str]): List of topic names
Returns:
Newly created list of topic names filtered by if the corresponding
topics have primary_keys in their most recent schemas
"""
pkey_topics = []
for topic in topics:
try:
schema = self.get_latest_schema_by_topic_name(topic)
if schema.primary_keys:
pkey_topics.append(topic)
except HTTPNotFound:
# List of topics may include topics not in schematizer
pass
return pkey_topics
try:
if entry_types is None:
entry_types = ['experiment', 'notebook']
def get_portion(limit, offset):
return self.leaderboard_swagger_client.api.getLeaderboard(
projectIdentifier=project.full_id,
entryType=entry_types,
shortId=ids, groupShortId=None, state=states, owner=owners, tags=tags,
tagsMode='and', minRunningTimeSeconds=min_running_time,
sortBy=['shortId'], sortFieldType=['native'], sortDirection=['ascending'],
limit=limit, offset=offset
).response().result.entries
return [LeaderboardEntry(e) for e in self._get_all_items(get_portion, step=100)]
except HTTPNotFound:
raise ProjectNotFound(project_identifier=project.full_id)
def get(self):
try:
return self.result()
except (HTTPInternalServerError,
HTTPBadRequest) as ex: # pragma: no cover
raise ESIError(str(ex))
except HTTPNotFound as ex: # pragma: no cover
try:
error_msg = json.loads(ex.response.text)
raise ESINotFound(error_msg.get('error', 'Not found'))
except Exception as ex:
raise ESINotFound(str(ex))
except HTTPForbidden: # pragma: no cover
raise ESIForbidden('Access denied')
def download_component(request, oid):
client = Client(**client_kwargs(request))
try:
resp = client.structures.get_entry(pk=oid, _fields=["cif"]).result()
content = resp["cif"]
ext = "cif"
except HTTPNotFound:
try:
resp = client.get_table(oid)
content = resp.to_csv()
ext = "csv"
except HTTPNotFound:
return HttpResponse(status=404)
if content:
content = gzip.compress(bytes(content, "utf-8"))
response = HttpResponse(content, content_type="application/gzip")
response["Content-Disposition"] = f"attachment; filename={oid}.{ext}.gz"
return response
return HttpResponse(status=404)
def get_itemtype(self, type_id):
try:
data = self.client.Universe.get_universe_types_type_id(type_id=type_id).result()
return ItemType(id=type_id, name=data['name'])
except (HTTPNotFound, HTTPUnprocessableEntity):
raise ObjectNotFound(type_id, 'type')
def _topic_to_range_map_to_topics_list(self, topic_to_range_map):
output = []
for topic, range_map in topic_to_range_map.iteritems():
try:
topic_result = self.schematizer.get_topic_by_name(topic)._asdict()
topic_result['range_map'] = range_map
output.append(topic_result)
except HTTPNotFound:
pass
return output
if task_id:
log.warning("Specifying a task_id, so ignoring hostname if specified")
task = api.service.task_instance(
service=service,
instance=instance,
verbose=True,
task_id=task_id,
).result()
return task
tasks = api.service.tasks_instance(
service=service,
instance=instance,
verbose=True,
slave_hostname=slave_hostname,
).result()
except HTTPNotFound:
log.error("Cannot find instance {}, for service {}, in cluster {}".format(
instance,
service,
cluster,
))
raise PaastaTaskNotFound
except HTTPError as e:
log.error("Problem with API call to find task details")
log.error(e.response.text)
raise PaastaTaskNotFound
if not tasks:
log.error("Cannot find any tasks on host: {} or with task_id: {}".format(
slave_hostname,
task_id,
))
raise PaastaTaskNotFound