Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-luna-valero committed Feb 5, 2025
1 parent c58ea5f commit f7e2d64
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 35 deletions.
22 changes: 12 additions & 10 deletions fedcloud_monitoring_tools/accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,24 @@ def all_vos(self):
self._get_accounting_data()
for col in self._data:
if col["id"] == "ylegend":
return [vo for vo in col.values() if vo != 'ylegend' and vo != 'id']
return [vo for vo in col.values() if vo != "ylegend" and vo != "id"]

def accounting_all_vos(self):
active_VOs = {}
for vo in self.all_vos():
active_VOs[vo] = {}
for i in self._data:
if i["id"] != 'Total' and \
i["id"] != 'Percent' and \
i["id"] != 'var' and \
i["id"] != 'xlegend' and \
i["id"] != 'ylegend' and \
vo in i and \
i[vo] is not None and \
float(i[vo]) > 0.0:
# loop over all sites having > 0 CPUh for this VO
if (
i["id"] != "Total"
and i["id"] != "Percent"
and i["id"] != "var"
and i["id"] != "xlegend"
and i["id"] != "ylegend"
and vo in i
and i[vo] is not None
and float(i[vo]) > 0.0
):
# loop over all sites having > 0 CPUh for this VO
site = i["id"]
cpuh = float(i[vo])
active_VOs[vo][site] = cpuh
Expand Down
4 changes: 2 additions & 2 deletions fedcloud_monitoring_tools/appdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ def all_vos(self):
r = requests.get(restful_url + "vos/")
r.raise_for_status()
result = []
for vo in xmltodict.parse(r.text)['appdb:appdb']['vo:vo']:
result.append(vo['@name'])
for vo in xmltodict.parse(r.text)["appdb:appdb"]["vo:vo"]:
result.append(vo["@name"])
return result
2 changes: 1 addition & 1 deletion fedcloud_monitoring_tools/goc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_sites_vo(self, cert_file, vo_map):
# All nova endpoints in the service group do not support all VOs.
# Therefore, a special value is added to be treated accordingly.
for vo in vos:
sites_per_vo[vo] = ['sla-group-with-multiple-vos']
sites_per_vo[vo] = ["sla-group-with-multiple-vos"]
continue
elif vos is None:
# This SLA service group does not have a VO associated, skipping
Expand Down
51 changes: 29 additions & 22 deletions fedcloud_monitoring_tools/sla_monitor_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,55 @@ def check_site_slas(site, acct, appdb, goc, gocdb_sites):
click.echo(f"[W] {site} has no configuration for ops")
click.echo()


def vo_in_map(vo, vo_map):
flat_list = []
for i in vo_map.values():
if i is not None:
flat_list += i
return vo in flat_list


def check_vo_sla(acct, appdb, goc, user_cert, vo_map, vo):
if not vo_in_map(vo, vo_map):
click.secho("[ERR] VO {} not found in the map file provided".format(vo),
fg="red", bold=True
)
click.secho(
"[ERR] VO {} not found in the map file provided".format(vo),
fg="red",
bold=True,
)
return
all_vos_acct = acct.accounting_all_vos()
all_vos_acct = acct.accounting_all_vos()
if vo not in all_vos_acct:
click.secho("[ERR] VO {} not found in Accounting Portal".format(vo),
fg="red", bold=True
)
click.secho(
"[ERR] VO {} not found in Accounting Portal".format(vo), fg="red", bold=True
)
return
all_vos_gocdb = goc.get_sites_vo(user_cert, vo_map)
if vo not in all_vos_gocdb:
click.secho("[ERR] VO {} not found in GOCDB".format(vo),
fg="red", bold=True
)
click.secho("[ERR] VO {} not found in GOCDB".format(vo), fg="red", bold=True)
return
sites_gocdb = sorted(all_vos_gocdb[vo])
sites_acct = sorted([provider for provider in all_vos_acct[vo]])
sites_acct = sorted([provider for provider in all_vos_acct[vo]])
sites_appdb = sorted(appdb.get_sites_for_vo(vo))
if sites_gocdb == sites_appdb == sites_acct:
click.secho("[OK] VO {}. The sites supporting the VO are: {}".format(vo, sites_gocdb),
fg="green", bold=True
)
elif 'sla-group-with-multiple-vos' in sites_gocdb and \
sites_appdb == sites_acct:
click.secho("[OK] VO {}. The sites supporting the VO are: {}".format(vo, sites_appdb),
fg="green", bold=True
)
click.secho(
"[OK] VO {}. The sites supporting the VO are: {}".format(vo, sites_gocdb),
fg="green",
bold=True,
)
elif "sla-group-with-multiple-vos" in sites_gocdb and sites_appdb == sites_acct:
click.secho(
"[OK] VO {}. The sites supporting the VO are: {}".format(vo, sites_appdb),
fg="green",
bold=True,
)

else:
click.secho("[W] VO {}. Uncertain list of sites supporting the VO!".format(vo),
fg="yellow", bold=True
)
click.secho(
"[W] VO {}. Uncertain list of sites supporting the VO!".format(vo),
fg="yellow",
bold=True,
)
click.echo("Sites in GOCDB: {}".format(sites_gocdb))
click.echo("Sites in AppDB: {}".format(sites_appdb))
click.echo("Sites in Accounting Portal: {}".format(sites_acct))
Expand Down

0 comments on commit f7e2d64

Please sign in to comment.