Skip to content

Commit

Permalink
fix: various fixes plus linting
Browse files Browse the repository at this point in the history
Change-Id: Iea104f33d934dd205bdbb66866eae1c0264657c0
  • Loading branch information
grafuls committed Feb 9, 2023
1 parent 6f6f29e commit 178bde4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
18 changes: 12 additions & 6 deletions quads/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,13 @@ def POST(self, **data):
time_left = lock_release - datetime.datetime.now()
hours = time_left.total_seconds() // 3600
minutes = (time_left.total_seconds() % 3600) // 60
cloud_string = "%s still has %dhr %dmin remaining on a pre-schedule reservation lock" % (
obj.name,
hours,
minutes,
cloud_string = (
"%s still has %dhr %dmin remaining on a pre-schedule reservation lock"
% (
obj.name,
hours,
minutes,
)
)
result.append(cloud_string)
cherrypy.response.status = "400 Bad Request"
Expand Down Expand Up @@ -384,7 +387,7 @@ def POST(self, **data):

broken_hosts = Host.objects(broken=True)
if _host_obj in broken_hosts:
result.append(f"Host {_host_obj.name} does not exist")
result.append(f"Host {_host_obj.name} is in broken state")

# Check if there were data validation errors
if result:
Expand Down Expand Up @@ -580,7 +583,10 @@ def DELETE(self, **data):
class VersionMethodHandler(object):
def GET(self):
return json.dumps(
{"result": "QUADS version %s %s" % (Config.QUADSVERSION, Config.QUADSCODENAME)}
{
"result": "QUADS version %s %s"
% (Config.QUADSVERSION, Config.QUADSCODENAME)
}
)


Expand Down
21 changes: 14 additions & 7 deletions quads/tools/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ async def get(self, endpoint):
async with session.get(
self.url + endpoint,
auth=BasicAuth(self.username, self.password),
verify_ssl=False,
ssl=False,
timeout=60,
) as response:
result = await response.json(content_type="application/json")
except Exception as ex:
Expand Down Expand Up @@ -75,7 +76,8 @@ async def put_host_parameter(self, host_id, parameter_id, value):
self.url + endpoint,
json=data,
auth=BasicAuth(self.username, self.password),
verify_ssl=False,
ssl=False,
timeout=60,
) as response:
await response.json(content_type="application/json")
except Exception as ex:
Expand All @@ -98,7 +100,8 @@ async def post_host_parameter(self, host_id, name, value):
self.url + endpoint,
json=data,
auth=BasicAuth(self.username, self.password),
verify_ssl=False,
ssl=False,
timeout=60,
) as response:
await response.json(content_type="application/json")
except Exception as ex:
Expand All @@ -122,7 +125,8 @@ async def update_user_password(self, login, password):
self.url + endpoint,
json=data,
auth=BasicAuth(self.username, self.password),
verify_ssl=False,
ssl=False,
timeout=60,
) as response:
await response.json(content_type="application/json")
except Exception as ex:
Expand Down Expand Up @@ -150,7 +154,8 @@ async def put_elements(self, element_name, element_id, params):
self.url + endpoint,
json=data,
auth=BasicAuth(self.username, self.password),
verify_ssl=False,
ssl=False,
timeout=60,
) as response:
await response.json(content_type="application/json")
except Exception as ex:
Expand Down Expand Up @@ -231,7 +236,8 @@ async def verify_credentials(self):
async with session.get(
self.url + endpoint,
auth=BasicAuth(self.username, self.password),
verify_ssl=False,
ssl=False,
timeout=60,
) as response:
await response.json(content_type="application/json")
except Exception as ex:
Expand Down Expand Up @@ -350,7 +356,8 @@ async def remove_extraneous_interfaces(self, host):
async with session.delete(
endpoint,
auth=BasicAuth(self.username, self.password),
verify_ssl=False,
ssl=False,
timeout=60,
) as response:
await response.json(content_type="application/json")
except Exception as ex:
Expand Down
9 changes: 6 additions & 3 deletions quads/tools/ssh_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def __init__(self, _host, _user=None, _password=None):
self.host = _host
self.user = _user
self.password = _password
self.ssh = self.connect()
try:
self.ssh = self.connect()
except SSHHelperException as ex:
raise SSHHelperException(f"{self.host}: {ex}")

def __exit__(self, exc_type, exc_val, exc_tb):
self.disconnect()
Expand All @@ -41,8 +44,8 @@ def connect(self):
allow_agent=False,
timeout=30,
)
except SSHException:
raise SSHHelperException
except SSHException as ex:
raise SSHHelperException(ex)

transport = ssh.get_transport()
channel = transport.open_session()
Expand Down
5 changes: 1 addition & 4 deletions quads/tools/validate_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,7 @@ def main(_args, _loop):
help="Show debugging information.",
)
parser.add_argument(
"--cloud",
nargs=1,
default="",
help="Run validation only on specified cloud."
"--cloud", default="", help="Run validation only on specified cloud."
)
args = parser.parse_args()

Expand Down

0 comments on commit 178bde4

Please sign in to comment.