Skip to content

Commit

Permalink
feat: added debug option to validate_env
Browse files Browse the repository at this point in the history
Change-Id: Ib0f5ad4f5daff8049bf1693d2582744799e037ba
  • Loading branch information
grafuls committed Dec 2, 2019
1 parent 2f5c19b commit 96807b4
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions quads/tools/validate_env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python3
import argparse
import asyncio
import logging
import os
Expand All @@ -7,6 +8,7 @@
from datetime import datetime
from jinja2 import Template
from paramiko import SSHException
from paramiko.ssh_exception import NoValidConnectionsError

from quads.config import conf, TEMPLATES_PATH, INTERFACES
from quads.model import Cloud, Schedule, Host, Notification
Expand All @@ -16,7 +18,6 @@
from quads.tools.ssh_helper import SSHHelper

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format="%(message)s")


class Validator(object):
Expand Down Expand Up @@ -123,8 +124,9 @@ def post_network_test(self):
test_host = host
try:
ssh_helper = SSHHelper(test_host.name)
except SSHException:
logger.exception("Could not establish connection with host: %s." % test_host.name)
except (SSHException, NoValidConnectionsError, socket.timeout) as ex:
logger.debug(ex)
logger.error("Could not establish connection with host: %s." % test_host.name)
self.report = self.report + "Could not establish connection with host: %s.\n" % test_host.name
return False
host_list = " ".join([host.name for host in self.hosts])
Expand Down Expand Up @@ -161,6 +163,7 @@ def post_network_test(self):
return True

def validate_env(self):
logger.info(f"Validating {self.cloud.name}")
notification_obj = Notification.objects(
cloud=self.cloud,
ticket=self.cloud.ticket
Expand Down Expand Up @@ -192,12 +195,23 @@ def validate_env(self):


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Validate Quads assignments')
parser.add_argument('--debug', action='store_true', default=False, help='Show debugging information.')
args = parser.parse_args()

level = logging.INFO
if args.debug:
level = logging.DEBUG

logging.basicConfig(level=level, format="%(message)s")

clouds = Cloud.objects(validated=False, name__ne="cloud01")
for _cloud in clouds:
_schedule_count = Schedule.current_schedule(cloud=_cloud).count()
if _schedule_count and _cloud.wipe:
validator = Validator(_cloud)
try:
validator.validate_env()
except Exception:
logger.exception("Failed validation for %s" % _cloud.name)
except Exception as ex:
logger.debug(ex)
logger.info("Failed validation for %s" % _cloud.name)

0 comments on commit 96807b4

Please sign in to comment.