Projet

Général

Profil

0002-cook-add-prechecks-on-recipe-16599.patch

Christophe Siraut, 14 septembre 2018 14:39

Télécharger (3,08 ko)

Voir les différences:

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

 hobo/environment/management/commands/cook.py | 29 ++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
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 result')
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
            print 'All steps executed successfully.  Your environment should now be ready.'
64
            print('All steps executed successfully.  Your environment should now be ready.')
63 65

  
64 66
    def run_cook(self, filename):
65 67
        recipe = json.load(open(filename))
68
        self.perform_checks(recipe)
66 69
        variables = {}
67 70
        if 'load-variables-from' in recipe:
68 71
            variables.update(json.load(open(
......
281 284
        current_tenant = connection.get_tenant()
282 285
        self.run_cook(filename)
283 286
        connection.set_tenant(current_tenant)
287

  
288
    def perform_checks(self, recipe):
289
        errors = []
290
        for step in recipe.get('steps', []):
291
            act, action_args = step.items()[0]
292
            action = act.replace('-', '_')
293
            if not hasattr(self, action):
294
                errors.append('Error: Unknown action %s' % action)
295
            if 'url' in action_args.keys():
296
                url = action_args['url']
297
                service = ServiceBase(title='dummy', base_url=url)
298
                if not service.is_resolvable():
299
                    errors.append('Error: %s is not resovable' % url)
300
                if not service.has_valid_certificate():
301
                    errors.append('Error: %s has no valid certificate' % url)
302

  
303
        if not self.permissive:
304
            if len(errors) > 0:
305
                for e in errors:
306
                    print(e)
307
                sys.exit(1)
308

  
284
-