~gz/juju-ci-tools/measure_coverage

« back to all changes in this revision

Viewing changes to remote.py

  • Committer: Martin Packman
  • Date: 2015-08-28 13:58:59 UTC
  • mfrom: (1074.1.3 remote_timeout)
  • Revision ID: martin.packman@canonical.com-20150828135859-0id6veia2a96t8cz
Update remote to use new timeout script and also use timeout for juju ssh

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import logging
7
7
import os
8
8
import subprocess
9
 
import sys
10
9
import zlib
11
10
 
12
11
import winrm
13
12
 
 
13
import jujupy
14
14
import utility
15
15
 
16
16
 
114
114
        "-o", "StrictHostKeyChecking no",
115
115
    ]
116
116
 
117
 
    timeout = "5m"
 
117
    # Limit each operation over SSH to 2 minutes by default
 
118
    timeout = 120
118
119
 
119
120
    def run(self, command):
120
121
        """Run a command on the remote machine."""
121
122
        if self.use_juju_ssh:
122
123
            try:
123
 
                return self.client.get_juju_output("ssh", self.unit, command)
 
124
                return self.client.get_juju_output("ssh", self.unit, command,
 
125
                                                   timeout=self.timeout)
124
126
            except subprocess.CalledProcessError as e:
125
127
                logging.warning("juju ssh to %r failed: %s", self.unit, e)
126
128
                self.use_juju_ssh = False
148
150
        return self.run("cat " + utility.quote(filename))
149
151
 
150
152
    def _run_subprocess(self, command):
151
 
        # XXX implement this in a Windows-compatible way
152
 
        if self.timeout and sys.platform != 'win32':
153
 
            command = ["timeout", self.timeout] + command
 
153
        if self.timeout:
 
154
            command = jujupy.get_timeout_prefix(self.timeout) + tuple(command)
154
155
        return subprocess.check_output(command)
155
156
 
156
157