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

« back to all changes in this revision

Viewing changes to tests/test_assess_container_networking.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:
17
17
    LXD_MACHINE,
18
18
    SimpleEnvironment,
19
19
    )
 
20
from jujupy.client import CommandTime
20
21
 
21
22
import assess_container_networking as jcnet
22
23
from tests import (
78
79
        if cmd != 'bootstrap':
79
80
            self.commands.append((cmd, args))
80
81
        if cmd == 'ssh':
 
82
            ct = CommandTime(cmd, args)
 
83
            if len(self._ssh_output) == 0:
 
84
                return "", ct
 
85
 
 
86
            try:
 
87
                ct = CommandTime(cmd, args)
 
88
                return self._ssh_output[self._call_number()], ct
 
89
            except IndexError:
 
90
                # If we ran out of values, just return the last one
 
91
                return self._ssh_output[-1], ct
 
92
        else:
 
93
            return super(JujuMock, self).juju(cmd, *rargs, **kwargs)
 
94
 
 
95
    def get_juju_output(self, cmd, *rargs, **kwargs):
 
96
        # Almost exactly like juju() except get_juju_output doesn't return
 
97
        # a CommandTime
 
98
        if len(rargs) == 1:
 
99
            args = rargs[0]
 
100
        else:
 
101
            args = rargs
 
102
        if cmd != 'bootstrap':
 
103
            self.commands.append((cmd, args))
 
104
        if cmd == 'ssh':
81
105
            if len(self._ssh_output) == 0:
82
106
                return ""
83
107
 
87
111
                # If we ran out of values, just return the last one
88
112
                return self._ssh_output[-1]
89
113
        else:
90
 
            return super(JujuMock, self).juju(cmd, *rargs, **kwargs)
 
114
            return super(JujuMock, self).get_juju_output(cmd, *rargs, **kwargs)
91
115
 
92
116
    def _call_number(self):
93
117
        call_number = self._call_n
117
141
            patch.object(self.client, 'wait_for', lambda *args, **kw: None),
118
142
            patch.object(self.client, 'wait_for_started',
119
143
                         self.juju_mock.get_status),
120
 
            patch.object(self.client, 'get_juju_output', self.juju_mock.juju),
 
144
            patch.object(
 
145
                self.client, 'get_juju_output',
 
146
                self.juju_mock.get_juju_output),
121
147
        ]
122
148
 
123
149
        for patcher in patches: