Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ascenderkit/api/pages/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test(self, data):
"""Test the credential type endpoint."""
response = self.connection.post(urljoin(str(self.url), 'test/'), data)
exception = exception_from_status_code(response.status_code)
exc_str = "%s (%s) received" % (http.responses[response.status_code], response.status_code)
exc_str = f"{http.responses[response.status_code]} ({response.status_code}) received"
if exception:
raise exception(exc_str, response.json())
elif response.status_code == http.FORBIDDEN:
Expand Down Expand Up @@ -266,7 +266,7 @@ def test(self, data):
"""Test the credential endpoint."""
response = self.connection.post(urljoin(str(self.url), 'test/'), data)
exception = exception_from_status_code(response.status_code)
exc_str = "%s (%s) received" % (http.responses[response.status_code], response.status_code)
exc_str = f"{http.responses[response.status_code]} ({response.status_code}) received"
if exception:
raise exception(exc_str, response.json())
elif response.status_code == http.FORBIDDEN:
Expand Down
19 changes: 9 additions & 10 deletions ascenderkit/api/pages/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ def print_ini(self):
continue

# output host groups
output.append('[%s]' % group)
output.append(f'[{group}]')
for host in inv_dict[group].get('hosts', []):
# FIXME ... include hostvars
output.append(host)
output.append('') # newline

# output child groups
if inv_dict[group].get('children', []):
output.append('[%s:children]' % group)
output.append(f'[{group}:children]')
for child in inv_dict[group].get('children', []):
output.append(child)
output.append('') # newline

# output group vars
if inv_dict[group].get('vars', {}).items():
output.append('[%s:vars]' % group)
output.append(f'[{group}:vars]')
for k, v in inv_dict[group].get('vars', {}).items():
output.append('%s=%s' % (k, v))
output.append(f'{k}={v}')
output.append('') # newline

print('\n'.join(output))
Expand Down Expand Up @@ -371,20 +371,19 @@ def update(self):
update_pg = self.get_related('update')

# assert can_update == True
assert update_pg.can_update, "The specified inventory_source (id:%s) is not able to update (can_update:%s)" % (self.id, update_pg.can_update)
assert update_pg.can_update, f"The specified inventory_source (id:{self.id}) is not able to update (can_update:{update_pg.can_update})"

# start the inventory_update
result = update_pg.post()

# assert JSON response
assert 'inventory_update' in result.json, "Unexpected JSON response when starting an inventory_update.\n%s" % json.dumps(result.json, indent=2)
assert 'inventory_update' in result.json, f"Unexpected JSON response when starting an inventory_update.\n{json.dumps(result.json, indent=2)}"

# locate and return the inventory_update
jobs_pg = self.related.inventory_updates.get(id=result.json['inventory_update'])
assert jobs_pg.count == 1, "An inventory_update started (id:%s) but job not found in response at %s/inventory_updates/" % (
result.json['inventory_update'],
self.url,
)
assert (
jobs_pg.count == 1
), f"An inventory_update started (id:{result.json['inventory_update']}) but job not found in response at {self.url}/inventory_updates/"
return jobs_pg.results[0]

@property
Expand Down
9 changes: 4 additions & 5 deletions ascenderkit/api/pages/job_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ def launch(self, payload=None):
# return job
if result.json['type'] == 'job':
jobs_pg = self.get_related('jobs', id=result.json['job'])
assert jobs_pg.count == 1, "job_template launched (id:%s) but job not found in response at %s/jobs/" % (result.json['job'], self.url)
assert jobs_pg.count == 1, f"job_template launched (id:{result.json['job']}) but job not found in response at {self.url}/jobs/"
return jobs_pg.results[0]
elif result.json['type'] == 'workflow_job':
slice_workflow_jobs = self.get_related('slice_workflow_jobs', id=result.json['id'])
assert slice_workflow_jobs.count == 1, "job_template launched sliced job (id:%s) but not found in related %s/slice_workflow_jobs/" % (
result.json['id'],
self.url,
)
assert (
slice_workflow_jobs.count == 1
), f"job_template launched sliced job (id:{result.json['id']}) but not found in related {self.url}/slice_workflow_jobs/"
return slice_workflow_jobs.results[0]
else:
raise RuntimeError('Unexpected type of job template spawned job.')
Expand Down
7 changes: 3 additions & 4 deletions ascenderkit/api/pages/notification_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ def test(self):

# return notification page
notifications_pg = self.get_related('notifications', id=notification_id).wait_until_count(1)
assert notifications_pg.count == 1, "test notification triggered (id:%s) but notification not found in response at %s/notifications/" % (
notification_id,
self.url,
)
assert (
notifications_pg.count == 1
), f"test notification triggered (id:{notification_id}) but notification not found in response at {self.url}/notifications/"
return notifications_pg.results[0]

def silent_delete(self):
Expand Down
2 changes: 1 addition & 1 deletion ascenderkit/api/pages/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def page_identity(self, response, request_json=None):
ds = None

data = self.extract_data(response)
exc_str = "%s (%s) received" % (http.responses[response.status_code], response.status_code)
exc_str = f"{http.responses[response.status_code]} ({response.status_code}) received"

exception = exception_from_status_code(response.status_code)
if exception:
Expand Down
11 changes: 5 additions & 6 deletions ascenderkit/api/pages/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,19 @@ def update(self):
update_pg = self.get_related('update')

# assert can_update == True
assert update_pg.can_update, "The specified project (id:%s) is not able to update (can_update:%s)" % (self.id, update_pg.can_update)
assert update_pg.can_update, f"The specified project (id:{self.id}) is not able to update (can_update:{update_pg.can_update})"

# start the update
result = update_pg.post()

# assert JSON response
assert 'project_update' in result.json, "Unexpected JSON response when starting an project_update.\n%s" % json.dumps(result.json, indent=2)
assert 'project_update' in result.json, f"Unexpected JSON response when starting an project_update.\n{json.dumps(result.json, indent=2)}"

# locate and return the specific update
jobs_pg = self.get_related('project_updates', id=result.json['project_update'])
assert jobs_pg.count == 1, "An project_update started (id:%s) but job not found in response at %s/inventory_updates/" % (
result.json['project_update'],
self.url,
)
assert (
jobs_pg.count == 1
), f"An project_update started (id:{result.json['project_update']}) but job not found in response at {self.url}/inventory_updates/"
return jobs_pg.results[0]

@property
Expand Down
5 changes: 1 addition & 4 deletions ascenderkit/api/pages/system_job_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def launch(self, payload=None):

# return job
jobs_pg = self.get_related('jobs', id=result.json['system_job'])
assert jobs_pg.count == 1, "system_job_template launched (id:%s) but unable to find matching job at %s/jobs/" % (
result.json['system_job'],
self.url,
)
assert jobs_pg.count == 1, f"system_job_template launched (id:{result.json['system_job']}) but unable to find matching job at {self.url}/jobs/"
return jobs_pg.results[0]


Expand Down
14 changes: 7 additions & 7 deletions ascenderkit/ascender/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def upload_inventory(ansible_runner, nhosts=10, ini=False):
copy_dest = '/tmp/inventory{}.sh'.format(random_title(non_ascii=False))
copy_content = '''#!/bin/bash
cat <<EOF
%s
EOF''' % json_inventory(nhosts)
{json_inventory(nhosts)}
EOF'''

# Copy script to test system
contacted = ansible_runner.copy(dest=copy_dest, force=True, mode=copy_mode, content=copy_content)
for result in contacted.values():
assert not result.get('failed', False), "Failed to create inventory file: %s" % result
assert not result.get('failed', False), f"Failed to create inventory file: {result}"
return copy_dest


Expand Down Expand Up @@ -88,21 +88,21 @@ def ini_inventory(nhosts=10):
continue

# output host groups
output.append('[%s]' % group)
output.append(f'[{group}]')
for host in inv_list[group].get('hosts', []):
output.append(host)
output.append('') # newline

# output child groups
output.append('[%s:children]' % group)
output.append(f'[{group}:children]')
for child in inv_list[group].get('children', []):
output.append(child)
output.append('') # newline

# output group vars
output.append('[%s:vars]' % group)
output.append(f'[{group}:vars]')
for k, v in inv_list[group].get('vars', {}).items():
output.append('%s=%s' % (k, v))
output.append(f'{k}={v}')
output.append('') # newline

return '\n'.join(output)
Expand Down
2 changes: 1 addition & 1 deletion ascenderkit/cli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,4 @@ def parse_args(self, argv, env=None):
disable_color()
fmt = self.get_config('format')
if fmt not in FORMATTERS.keys():
self.parser.error('No formatter %s available.' % (fmt))
self.parser.error(f'No formatter {fmt} available.')
2 changes: 1 addition & 1 deletion ascenderkit/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def error(self, message): # pragma: nocover
"""
self.print_help(sys.stderr)
self._print_message('\n')
self.exit(2, '%s: %s\n' % (self.prog, message))
self.exit(2, f'{self.prog}: {message}\n')


def color_enabled():
Expand Down
4 changes: 2 additions & 2 deletions ascenderkit/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def load_credentials(filename=None):
credentials_dict = yaml.safe_load(credentials_fh)
return credentials_dict
else:
msg = 'Unable to load credentials file at %s' % path
msg = f'Unable to load credentials file at {path}'
raise Exception(msg)


Expand All @@ -184,7 +184,7 @@ def load_projects(filename=None):
projects_dict = yaml.safe_load(projects_fh)
return projects_dict
else:
msg = 'Unable to load projects file at %s' % path
msg = f'Unable to load projects file at {path}'
raise Exception(msg)


Expand Down
2 changes: 1 addition & 1 deletion ascenderkit/yaml_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ def load_file(filename):
# FIXME - support load_all()
return yaml.load(fp, Loader=Loader)
else:
msg = 'Unable to load data file at %s' % path
msg = f'Unable to load data file at {path}'
raise Exception(msg)