comment out temporarily broken ensure_vms_and_db_are_synced

This commit is contained in:
forest 2021-12-09 11:21:53 -06:00
parent b3f62018ea
commit 099b90081f

View File

@ -268,45 +268,46 @@ def notify_users_about_account_balance():
def ensure_vms_and_db_are_synced():
db_vms = get_model().all_vm_ids_with_desired_state()
# TODO replaced
#virt_vms = current_app.config["HUB_MODEL"].virsh_list()
pass
# db_vms = get_model().all_vm_ids_with_desired_state()
# # TODO replaced
# #virt_vms = current_app.config["HUB_MODEL"].virsh_list()
db_ids_dict = dict()
virt_ids_dict = dict()
# db_ids_dict = dict()
# virt_ids_dict = dict()
for vm in db_vms:
db_ids_dict[vm['id']] = vm['desired_state']
# for vm in db_vms:
# db_ids_dict[vm['id']] = vm['desired_state']
for vm in virt_vms:
virt_ids_dict[vm['id']] = vm['desired_state']
# for vm in virt_vms:
# virt_ids_dict[vm['id']] = vm['desired_state']
errors = list()
# errors = list()
for id in db_ids_dict:
if id not in virt_ids_dict:
errors.append(f"{id} is in the database but not in the virtualization model")
elif db_ids_dict[id] != virt_ids_dict[id]:
errors.append(f"{id} has the desired state {db_ids_dict[id]} in the database but current state {virt_ids_dict[id]} in the virtualization model")
# for id in db_ids_dict:
# if id not in virt_ids_dict:
# errors.append(f"{id} is in the database but not in the virtualization model")
# elif db_ids_dict[id] != virt_ids_dict[id]:
# errors.append(f"{id} has the desired state {db_ids_dict[id]} in the database but current state {virt_ids_dict[id]} in the virtualization model")
for id in virt_ids_dict:
if id not in db_ids_dict:
errors.append(f"{id} is in the virtualization model but not in the database")
# for id in virt_ids_dict:
# if id not in db_ids_dict:
# errors.append(f"{id} is in the virtualization model but not in the database")
if len(errors) > 0:
email_addresses_raw = current_app.config['ADMIN_EMAIL_ADDRESSES'].split(",")
email_addresses = list(filter(lambda x: len(x) > 6, map(lambda x: x.strip(), email_addresses_raw ) ))
# if len(errors) > 0:
# email_addresses_raw = current_app.config['ADMIN_EMAIL_ADDRESSES'].split(",")
# email_addresses = list(filter(lambda x: len(x) > 6, map(lambda x: x.strip(), email_addresses_raw ) ))
current_app.logger.info(f"cron_task: sending inconsistency warning email to {','.join(email_addresses)}:")
for error in errors:
current_app.logger.info(f"cron_task: {error}.")
# current_app.logger.info(f"cron_task: sending inconsistency warning email to {','.join(email_addresses)}:")
# for error in errors:
# current_app.logger.info(f"cron_task: {error}.")
current_app.config["FLASK_MAIL_INSTANCE"].send(
Message(
"Capsul Consistency Check Failed",
sender=current_app.config["MAIL_DEFAULT_SENDER"],
body="\n".join(errors),
recipients=email_addresses
)
)
# current_app.config["FLASK_MAIL_INSTANCE"].send(
# Message(
# "Capsul Consistency Check Failed",
# sender=current_app.config["MAIL_DEFAULT_SENDER"],
# body="\n".join(errors),
# recipients=email_addresses
# )
# )