~juju-qa/juju-ci-tools/trunk

« back to all changes in this revision

Viewing changes to jujupy/version_client.py

  • Committer: Christopher Lee
  • Date: 2017-04-05 23:07:51 UTC
  • mfrom: (1938.3.28 timing_bootstrap)
  • Revision ID: chris.lee@canonical.com-20170405230751-pj0l3y2anyczvcb5
Merge the CommandTiming and CommandComplete work for timing commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import yaml
26
26
 
27
27
from jujupy.client import (
 
28
    CommandComplete,
28
29
    Controller,
29
30
    _DEFAULT_BUNDLE_TIMEOUT,
30
31
    get_cache_path,
38
39
    LXC_MACHINE,
39
40
    make_safe_config,
40
41
    ModelClient,
 
42
    NoopCondition,
41
43
    SimpleEnvironment,
42
44
    Status,
43
45
    StatusItem,
373
375
 
374
376
    def set_model_constraints(self, constraints):
375
377
        constraint_strings = self._dict_as_option_strings(constraints)
376
 
        return self.juju('set-constraints', constraint_strings)
 
378
        retvar, ct = self.juju('set-constraints', constraint_strings)
 
379
        return retvar, CommandComplete(NoopCondition(), ct)
377
380
 
378
381
    def set_config(self, service, options):
379
382
        option_strings = ['{}={}'.format(*item) for item in options.items()]
394
397
    def set_env_option(self, option, value):
395
398
        """Set the value of the option in the environment."""
396
399
        option_value = "%s=%s" % (option, value)
397
 
        return self.juju('set-env', (option_value,))
 
400
        retvar, ct = self.juju('set-env', (option_value,))
 
401
        return retvar, CommandComplete(NoopCondition(), ct)
398
402
 
399
403
    def unset_env_option(self, option):
400
404
        """Unset the value of the option in the environment."""
401
 
        return self.juju('set-env', ('{}='.format(option),))
 
405
        retvar, ct = self.juju('set-env', ('{}='.format(option),))
 
406
        return retvar, CommandComplete(NoopCondition(), ct)
402
407
 
403
408
    def get_model_defaults(self, model_key, cloud=None, region=None):
404
409
        log.info('No model-defaults stored for client (attempted get).')
449
454
        """Bootstrap a controller."""
450
455
        self._check_bootstrap()
451
456
        args = self.get_bootstrap_args(upload_tools, bootstrap_series)
452
 
        self.juju('bootstrap', args)
 
457
        retvar, ct = self.juju('bootstrap', args)
 
458
        ct.actual_completion()
453
459
 
454
460
    @contextmanager
455
461
    def bootstrap_async(self, upload_tools=False):
497
503
        """Destroy the environment, with force. Hard kill option.
498
504
 
499
505
        :return: Subprocess's exit code."""
500
 
        return self.juju(
 
506
        retvar, ct = self.juju(
501
507
            'destroy-environment', (self.env.environment, '--force', '-y'),
502
508
            check=check, include_e=False, timeout=get_teardown_timeout(self))
 
509
        return retvar, CommandComplete(NoopCondition(), ct)
503
510
 
504
511
    def destroy_controller(self, all_models=False):
505
512
        """Destroy the environment, with force. Soft kill option.
506
513
 
507
514
        :param all_models: Ignored.
508
515
        :raises: subprocess.CalledProcessError if the operation fails."""
509
 
        return self.juju(
 
516
        retvar, ct = self.juju(
510
517
            'destroy-environment', (self.env.environment, '-y'),
511
518
            include_e=False, timeout=get_teardown_timeout(self))
 
519
        return retvar, CommandComplete(NoopCondition(), ct)
512
520
 
513
521
    def destroy_environment(self, force=True, delete_jenv=False):
514
522
        if force:
515
523
            force_arg = ('--force',)
516
524
        else:
517
525
            force_arg = ()
518
 
        exit_status = self.juju(
 
526
        exit_status, _ = self.juju(
519
527
            'destroy-environment',
520
528
            (self.env.environment,) + force_arg + ('-y',),
521
529
            check=False, include_e=False,
572
580
            args.extend(['--storage', storage])
573
581
        if constraints is not None:
574
582
            args.extend(['--constraints', constraints])
575
 
        return self.juju('deploy', tuple(args))
 
583
        retvar, ct = self.juju('deploy', tuple(args))
 
584
        return retvar, CommandComplete(NoopCondition(), ct)
576
585
 
577
586
    def upgrade_charm(self, service, charm_path=None):
578
587
        args = (service,)
661
670
 
662
671
    def disable_command(self, command_set, message=''):
663
672
        """Disable a command-set."""
664
 
        return self.juju('block {}'.format(command_set), (message, ))
 
673
        retvar, ct = self.juju('block {}'.format(command_set), (message, ))
 
674
        return retvar, CommandComplete(NoopCondition(), ct)
665
675
 
666
676
    def enable_command(self, args):
667
677
        """Enable a command-set."""
668
 
        return self.juju('unblock', args)
 
678
        retvar, ct = self.juju('unblock', args)
 
679
        return retvar, CommandComplete(NoopCondition(), ct)
669
680
 
670
681
 
671
682
class EnvJujuClient22(EnvJujuClient1X):