~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to jujupy.py

  • Committer: Aaron Bentley
  • Date: 2014-04-15 19:35:13 UTC
  • mto: This revision was merged to the branch mainline in revision 378.
  • Revision ID: aaron.bentley@canonical.com-20140415193513-ujvvannlax2fel9w
Support supplying timeout to calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
        version = cls.get_version()
88
88
        full_path = cls.get_full_path()
89
89
        if version.startswith('1.16'):
90
 
            return JujuClient16(version, full_path)
 
90
            raise Exception('Unsupported juju: %s' % version)
91
91
        else:
92
92
            return JujuClientDevel(version, full_path)
93
93
 
94
 
    def _full_args(self, environment, command, sudo, args):
 
94
    def _full_args(self, environment, command, sudo, args, timeout=None):
95
95
        # sudo is not needed for devel releases.
96
96
        e_arg = () if environment is None else ('-e', environment.environment)
97
 
        return ('juju', '--show-log', command,) + e_arg + args
 
97
        if timeout is None:
 
98
            prefix = ()
 
99
        else:
 
100
            prefix = ('timeout', '%.2fs' % timeout)
 
101
        return prefix + ('juju', '--show-log', command,) + e_arg + args
98
102
 
99
103
    def bootstrap(self, environment):
100
104
        """Bootstrap, using sudo if necessary."""
111
115
            (environment.environment, '--force', '-y'),
112
116
            environment.needs_sudo(), check=False)
113
117
 
114
 
    def get_juju_output(self, environment, command, *args):
115
 
        args = self._full_args(environment, command, False, args)
 
118
    def get_juju_output(self, environment, command, *args, **kwargs):
 
119
        args = self._full_args(environment, command, False, args,
 
120
                               timeout=kwargs.get('timeout'))
116
121
        with tempfile.TemporaryFile() as stderr:
117
122
            try:
118
123
                return subprocess.check_output(args, stderr=stderr)
156
161
        return subprocess.call(args)
157
162
 
158
163
 
159
 
class JujuClient16(JujuClientDevel):
160
 
 
161
 
    def destroy_environment(self, environment):
162
 
        self.juju(environment, 'destroy-environment', ('-y',),
163
 
                  environment.needs_sudo(), check=False)
164
 
 
165
 
    def _full_args(self, environment, command, sudo, args):
166
 
        # juju 1.16.x required sudo, so replace the juju command with it, as
167
 
        # appropriate.
168
 
        full = super(JujuClient16, self)._full_args(
169
 
            environment, command, sudo, args)
170
 
        sudo_args = ('sudo', '-E', self.full_path) if sudo else ('juju',)
171
 
        return sudo_args + full[1:]
172
 
 
173
 
 
174
164
class Status:
175
165
 
176
166
    def __init__(self, status):