Projet

Général

Profil

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

Christophe Siraut, 13 septembre 2018 15:20

Télécharger (3,25 ko)

Voir les différences:

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

 hobo/environment/management/commands/cook.py | 34 ++++++++++++++++++++++++++--
 1 file changed, 32 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
        class Counter():
290
            def __init__(self):
291
                self.count = 0
292
            def add(self, msg):
293
                print(msg)
294
                self.count += 1
295

  
296
        errors = Counter()
297
        for step in recipe.get('steps', []):
298
            act, action_args = step.items()[0]
299
            action = act.replace('-', '_')
300
            if not hasattr(self, action):
301
                errors.add('Error: Unknown action %s' % action)
302
            if 'url' in action_args.keys():
303
                url = action_args['url']
304
                service = ServiceBase(title='dummy', base_url=url)
305
                if not service.is_resolvable():
306
                    errors.add('Error: %s is not resovable' % url)
307
                if not service.has_valid_certificate():
308
                    errors.add('Error: %s has no valid certificate' % url)
309

  
310
        if not self.permissive:
311
            if errors.count > 0:
312
                raise(Exception('%s errors have been reported' % errors))
313

  
284
-