From 30593074b618811b4847e0af254c83dd3c2ce271 Mon Sep 17 00:00:00 2001 From: Christophe Siraut Date: Thu, 13 Sep 2018 11:17:56 +0200 Subject: [PATCH 2/2] cook: add prechecks on recipe (#16599) --- hobo/environment/management/commands/cook.py | 34 ++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/hobo/environment/management/commands/cook.py b/hobo/environment/management/commands/cook.py index 913e39f..a9bc889 100644 --- a/hobo/environment/management/commands/cook.py +++ b/hobo/environment/management/commands/cook.py @@ -35,7 +35,7 @@ from hobo.agent.common.management.commands.hobo_deploy import ( from hobo.multitenant.middleware import TenantMiddleware from hobo.environment.models import (AVAILABLE_SERVICES, Authentic, Wcs, Hobo, Passerelle, Combo, Fargo, Welco, MandayeJS, Chrono, Corbo, BiJoe, - Variable) + Variable, ServiceBase) from hobo.deploy.signals import notify_agents from hobo.theme.utils import set_theme from hobo.profile.models import AttributeDefinition @@ -53,16 +53,19 @@ class Command(BaseCommand): parser.add_argument( '--timeout', type=int, action='store', default=120, help='set the timeout for the wait_operationals method') + parser.add_argument('--permissive', action='store_true', help='ignore integrity checks result') def handle(self, recipe, *args, **kwargs): self.verbosity = kwargs.get('verbosity') self.timeout = kwargs.get('timeout') + self.permissive = kwargs.get('permissive') self.run_cook(recipe) if self.verbosity: - print 'All steps executed successfully. Your environment should now be ready.' + print('All steps executed successfully. Your environment should now be ready.') def run_cook(self, filename): recipe = json.load(open(filename)) + self.perform_checks(recipe) variables = {} if 'load-variables-from' in recipe: variables.update(json.load(open( @@ -281,3 +284,30 @@ class Command(BaseCommand): current_tenant = connection.get_tenant() self.run_cook(filename) connection.set_tenant(current_tenant) + + def perform_checks(self, recipe): + class Counter(): + def __init__(self): + self.count = 0 + def add(self, msg): + print(msg) + self.count += 1 + + errors = Counter() + for step in recipe.get('steps', []): + act, action_args = step.items()[0] + action = act.replace('-', '_') + if not hasattr(self, action): + errors.add('Error: Unknown action %s' % action) + if 'url' in action_args.keys(): + url = action_args['url'] + service = ServiceBase(title='dummy', base_url=url) + if not service.is_resolvable(): + errors.add('Error: %s is not resovable' % url) + if not service.has_valid_certificate(): + errors.add('Error: %s has no valid certificate' % url) + + if not self.permissive: + if errors.count > 0: + raise(Exception('%s errors have been reported' % errors)) + -- 2.11.0