~caio1982/mojo/local_repo_keys

« back to all changes in this revision

Viewing changes to mojo/phase.py

  • Committer: Tom Haddon
  • Date: 2016-01-15 14:29:03 UTC
  • mfrom: (241.2.2 mojo-code-cleanup2)
  • Revision ID: tom.haddon@canonical.com-20160115142903-9tk9e023tq0omyva
[timkuhlman,r=mthaddon] Series is part of the project and shouldn't be dealt with independent of it

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
        return "<{} {} {} {}>".format(self.__class__.__name__, self.name,
86
86
                                      self.config_base, self.options)
87
87
 
88
 
    def run(self, project, workspace, series, stage=None):
 
88
    def run(self, project, workspace, stage=None):
89
89
        raise NotImplementedError
90
90
 
91
91
 
97
97
    """
98
98
    name = "sleep"
99
99
 
100
 
    def run(self, project, workspace, series, stage=None):
 
100
    def run(self, project, workspace, stage=None):
101
101
        "Sleep for time in seconds"
102
102
        logging.debug("### Running phase {} with options {} ###"
103
103
                      "".format(self.name, self.options))
145
145
    """
146
146
    name = "secrets"
147
147
 
148
 
    def run(self, project, workspace, series, stage=None):
 
148
    def run(self, project, workspace, stage=None):
149
149
        "Pull Secrets into workspace local"
150
150
 
151
151
        mojo_local_dir = os.path.join(project.mojo_root, 'LOCAL',
188
188
    """
189
189
    name = "collect"
190
190
 
191
 
    def run(self, project, workspace, series, stage=None, auto_repo=True):
 
191
    def run(self, project, workspace, stage=None, auto_repo=True):
192
192
        "Collect build resources using config-manager"
193
193
        logging.debug("### Running phase {} with options {} ###"
194
194
                      "".format(self.name, self.options))
195
195
        logging.info("Building resource tree")
196
196
        env = os.environ.copy()
197
 
        env['MOJO_SERIES'] = series
 
197
        env['MOJO_SERIES'] = project.series
198
198
        env['MOJO_STAGE'] = stage or 'devel'
199
199
        expand_config_base = string.Template(self.config_base).substitute(env)
200
200
        config = workspace.spec.get_config(expand_config_base, stage)
212
212
        if auto_repo:
213
213
            # Run Repo phase automatically
214
214
            repo = CharmRepoPhase(auto_repo=True)
215
 
            repo.run(project, workspace, series, stage)
 
215
            repo.run(project, workspace, stage)
216
216
 
217
217
 
218
218
class InstallBuildDepsPhase(Phase):
225
225
    """
226
226
    name = "builddeps"
227
227
 
228
 
    def run(self, project, workspace, series, stage=None):
 
228
    def run(self, project, workspace, stage=None):
229
229
        "Install packages"
230
230
        logging.debug("### Running phase {} with options {}"
231
231
                      "".format(self.name, self.options))
254
254
    """
255
255
    name = "volumes"
256
256
 
257
 
    def run(self, project, workspace, series, stage=None):
 
257
    def run(self, project, workspace, stage=None):
258
258
        "Attach volumes to services"
259
259
        logging.debug("### Running phase {} with options {}".format(self.name,
260
260
                      self.options))
278
278
    """
279
279
    name = "script"
280
280
 
281
 
    def run(self, project, workspace, series, stage=None, lxc=False,
 
281
    def run(self, project, workspace, stage=None, lxc=False,
282
282
            network=True, auto_secrets=True, gather_debug_logs=True):
283
283
        if auto_secrets:
284
284
            # Run secrets phase automatically first
285
285
            secrets = mojo.phase.build('secrets', **{'auto_secrets': True})
286
 
            secrets.run(project, workspace, series, stage)
 
286
            secrets.run(project, workspace, stage)
287
287
        logging.debug("### Running phase {} with options {}".format(self.name,
288
288
                      self.options))
289
289
        logging.info("Running script {}".format(self.config_base))
299
299
            env[key] = self.options[key]
300
300
        env['MOJO_PROJECT'] = project.name
301
301
        env['MOJO_WORKSPACE'] = workspace.name
302
 
        env['MOJO_SERIES'] = series
 
302
        env['MOJO_SERIES'] = project.series
303
303
        env['MOJO_WORKSPACE_DIR'] = workspace.path
304
304
        env['MOJO_BUILD_DIR'] = workspace.build_dir
305
305
        env['MOJO_REPO_DIR'] = workspace.repo_dir
338
338
    """
339
339
    name = "build"
340
340
 
341
 
    def run(self, project, workspace, series, stage, auto_secrets=True):
 
341
    def run(self, project, workspace, stage, auto_secrets=True):
342
342
        "Run a build script"
343
343
        # XXX: Remove network access during build phase
344
 
        super(BuildPhase, self).run(project, workspace, series, stage,
 
344
        super(BuildPhase, self).run(project, workspace, stage,
345
345
                                    lxc=True, network=False,
346
346
                                    auto_secrets=auto_secrets,
347
347
                                    gather_debug_logs=False)
354
354
    """
355
355
    name = "repo"
356
356
 
357
 
    def run(self, project, workspace, series, stage):
 
357
    def run(self, project, workspace, stage):
358
358
        "Build a charm repository"
359
359
        logging.debug("### Running phase {} with options {}"
360
360
                      "".format(self.name, self.options))
363
363
        if self.options.get('auto_repo'):
364
364
            logging.info("Creating charm repo automatically from all charms "
365
365
                         "in the build directory.")
366
 
            repo.build_all(workspace.build_dir, series)
 
366
            repo.build_all(workspace.build_dir, project.series)
367
367
        else:
368
368
            logging.warn("It is no longer necessary to specify a repo phase "
369
369
                         "in the manifest nor have a repo config file in the "
371
371
                         "each collect phase and will copy over all charms "
372
372
                         "from the build directory to the charms directory.")
373
373
            config = workspace.spec.get_config(self.config_base, stage)
374
 
            repo.build_from_config(config, workspace.build_dir, series)
 
374
            repo.build_from_config(config, workspace.build_dir, project.series)
375
375
 
376
376
 
377
377
class DeployerPhase(Phase):
433
433
                                           "juju-deployer configuration file "
434
434
                                           "{}:\n{}".format(config, e))
435
435
 
436
 
    def _deployer_configs(self, project, workspace, series, stage,
 
436
    def _deployer_configs(self, project, workspace, stage,
437
437
                          auto_secrets=True, cli=True):
438
438
        """
439
439
        Return list of juju deployer rendered configuration files
445
445
        if auto_secrets:
446
446
            # Run secrets phase automatically first
447
447
            secrets = SecretsPhase(auto_secrets=True)
448
 
            secrets.run(project, workspace, series, stage)
 
448
            secrets.run(project, workspace, stage)
449
449
 
450
450
        # Process the deployment configs as a Jinja2 template
451
451
        tmpl_vars = {
452
452
            'project': project.name,
453
453
            'workspace': workspace.name,
454
 
            'series': series,
 
454
            'series': project.series,
455
455
            'spec_dir': workspace.spec_dir,
456
456
            'local_dir': workspace.local_dir,
457
457
            'build_dir': workspace.build_dir,
499
499
        else:
500
500
            return configs
501
501
 
502
 
    def show(self, project, workspace, series, stage):
 
502
    def show(self, project, workspace, stage):
503
503
        """
504
504
        Display rendered juju-deployer configuration files
505
505
        """
506
506
        # Quiet logging to get clean display of YAML
507
507
        logger = logging.getLogger()
508
508
        logger.setLevel(level='WARNING')
509
 
        configs = self._deployer_configs(project, workspace, series, stage,
510
 
                                         cli=False)
 
509
        configs = self._deployer_configs(project, workspace, stage, cli=False)
511
510
        deploy_name = self._get_target(configs)
512
511
        deployer_config = ConfigStack(configs)
513
512
        deployer_config.load()
518
517
        deployment.resolve_config()
519
518
        print(yaml.dump(deployment.data))
520
519
 
521
 
    def diff(self, project, workspace, series, stage):
 
520
    def diff(self, project, workspace, stage):
522
521
        """
523
522
        Display juju-deployer --diff comparing running environment
524
523
        to the juju-deployer configuration
525
524
        """
526
525
        deployer = get_dep_prog("juju-deployer")
527
 
        configs = self._deployer_configs(project, workspace, series, stage)
 
526
        configs = self._deployer_configs(project, workspace, stage)
528
527
        deploy_name = self._get_target(configs)
529
528
        cmd = ('python', deployer)
530
529
        cmd += configs
532
531
        with chdir(workspace.repo_dir):
533
532
            subprocess.call(cmd)
534
533
 
535
 
    def run(self, project, workspace, series, stage, auto_secrets=True):
 
534
    def run(self, project, workspace, stage, auto_secrets=True):
536
535
        logging.debug("### Running phase {} with options {}"
537
536
                      "".format(self.name, self.options))
538
537
        logging.info("Running juju-deployer")
539
538
        deployer = get_dep_prog("juju-deployer")
540
539
 
541
 
        configs = self._deployer_configs(project, workspace, series, stage,
542
 
                                         auto_secrets=auto_secrets)
 
540
        configs = self._deployer_configs(project, workspace, stage, auto_secrets=auto_secrets)
543
541
 
544
542
        juju_env = None
545
543
        if "juju" in self.options:
580
578
 
581
579
        # run the deploy
582
580
        env = os.environ.copy()
583
 
        env['MOJO_SERIES'] = series
 
581
        env['MOJO_SERIES'] = project.series
584
582
        env['MOJO_STAGE'] = stage or 'devel'
585
583
        cmd = ('python', deployer)
586
584
        cmd += configs
688
686
    """
689
687
    name = "verify"
690
688
 
691
 
    def run(self, project, workspace, series, stage, auto_secrets=True):
 
689
    def run(self, project, workspace, stage, auto_secrets=True):
692
690
        retry = int_from_dict(self.options, 'retry', 1)
693
691
        sleep = int_from_dict(self.options, 'sleep', 5)
694
692
 
701
699
                        i, retry))
702
700
 
703
701
            try:
704
 
                _run(project, workspace, series, stage,
 
702
                _run(project, workspace, stage,
705
703
                     auto_secrets=auto_secrets, gather_debug_logs=False)
706
704
            except ScriptPhaseException as e:
707
705
                if i < retry:
733
731
    """
734
732
    name = "stop-on"
735
733
 
736
 
    def run(self, project, workspace, series, stage):
 
734
    def run(self, project, workspace, stage):
737
735
 
738
736
        if "return-code" in self.options:
739
737
            return_code = int(self.options['return-code'])
745
743
        _run = super(StopOnPhase, self).run
746
744
 
747
745
        try:
748
 
            _run(project, workspace, series, stage, gather_debug_logs=False)
 
746
            _run(project, workspace, stage, gather_debug_logs=False)
749
747
        except ScriptPhaseException as e:
750
748
            if e.returncode == return_code:
751
749
                # Exit silently
767
765
    """
768
766
    name = "juju-check-wait"
769
767
 
770
 
    def run(self, project, workspace, series, stage=None):
 
768
    def run(self, project, workspace, stage=None):
771
769
        status_timeout = str(self.options.get("status-timeout", "1800"))
772
770
        logging.info("Checking Juju status")
773
771
        juju_status = mojo.juju.status.Status()