Project

General

Profile

0001-commands-cook-add-prechecks-on-recipe-16599.patch

Christophe Siraut, 03 Oct 2018 06:20 PM

Download (2.91 KB)

View differences:

Subject: [PATCH] commands/cook: add prechecks on recipe (#16599)

 hobo/environment/management/commands/cook.py | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
hobo/environment/management/commands/cook.py
35 35
from hobo.multitenant.middleware import TenantMiddleware
36 36
from hobo.environment.models import (AVAILABLE_SERVICES, Authentic, Wcs, Hobo,
37 37
        Passerelle, Combo, Fargo, Welco, MandayeJS, Chrono, Corbo, BiJoe,
38
        Variable)
38
        Variable, ServiceBase)
39 39
from hobo.deploy.signals import notify_agents
40 40
from hobo.theme.utils import set_theme
41 41
from hobo.profile.models import AttributeDefinition
......
53 53
        parser.add_argument(
54 54
                '--timeout', type=int, action='store', default=120,
55 55
                 help='set the timeout for the wait_operationals method')
56
        parser.add_argument('--permissive', action='store_true', help='ignore integrity checks')
56 57

  
57 58
    def handle(self, recipe, *args, **kwargs):
58 59
        self.verbosity = kwargs.get('verbosity')
59 60
        self.timeout = kwargs.get('timeout')
61
        self.permissive = kwargs.get('permissive')
60 62
        self.run_cook(recipe)
61 63
        if self.verbosity:
62 64
            print 'All steps executed successfully.  Your environment should now be ready.'
......
75 77
                    continue
76 78
                action_args[arg] = string.Template(
77 79
                        action_args[arg]).substitute(variables)
80
            if not self.permissive:
81
                self.check_action(action, action_args)
82

  
83
        for step in recipe.get('steps', []):
78 84
            getattr(self, action.replace('-', '_'))(**action_args)
79 85
            if self.must_notify:
80 86
                notify_agents(None)
......
281 287
        current_tenant = connection.get_tenant()
282 288
        self.run_cook(filename)
283 289
        connection.set_tenant(current_tenant)
290

  
291
    def check_action(self, action, action_args):
292
        if not hasattr(self, action.replace('-', '_')):
293
            raise CommandError('Error: Unknown action %s' % action)
294
        if 'url' in action_args.keys():
295
            url = action_args['url']
296
            service = ServiceBase(title='dummy', base_url=url)
297
            if not service.is_resolvable():
298
                raise CommandError('Error: %s is not resolvable' % url)
299
            if not service.has_valid_certificate():
300
                raise CommandError('Error: %s has no valid certificate' % url)
284
-