From 222bf33552e9db3a0af487ccc63c58391a2f7a71 Mon Sep 17 00:00:00 2001 From: Christophe Siraut Date: Wed, 3 Oct 2018 18:13:08 +0200 Subject: [PATCH] commands/cook: add prechecks on recipe (#16599) --- hobo/environment/management/commands/cook.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/hobo/environment/management/commands/cook.py b/hobo/environment/management/commands/cook.py index 913e39f..40deb42 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,10 +53,12 @@ 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') 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.' @@ -75,6 +77,10 @@ class Command(BaseCommand): continue action_args[arg] = string.Template( action_args[arg]).substitute(variables) + if not self.permissive: + self.check_action(action, action_args) + + for step in recipe.get('steps', []): getattr(self, action.replace('-', '_'))(**action_args) if self.must_notify: notify_agents(None) @@ -281,3 +287,14 @@ class Command(BaseCommand): current_tenant = connection.get_tenant() self.run_cook(filename) connection.set_tenant(current_tenant) + + def check_action(self, action, action_args): + if not hasattr(self, action.replace('-', '_')): + raise CommandError('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(): + raise CommandError('Error: %s is not resolvable' % url) + if not service.has_valid_certificate(): + raise CommandError('Error: %s has no valid certificate' % url) -- 2.19.0