~psivaa/uci-engine/lander-jenkins-sub-charm-with-plugin

« back to all changes in this revision

Viewing changes to test_runner/tstrun/testbed.py

  • Committer: Andy Doan
  • Date: 2014-04-04 16:00:36 UTC
  • mfrom: (422 uci-engine)
  • mto: This revision was merged to the branch mainline in revision 423.
  • Revision ID: andy.doan@canonical.com-20140404160036-cve1123qiu8o7dvf
merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
log = logging.getLogger(__name__)
32
32
 
33
33
 
34
 
class NovaClientException(Exception):
 
34
class TestBedException(Exception):
35
35
    pass
36
36
 
37
37
 
179
179
                pass
180
180
        # MISSINGTEST: some cloud doesn't provide one of our expected flavors
181
181
        # -- vila 2014-01-06
182
 
        raise NovaClientException(
 
182
        raise TestBedException(
183
183
            'None of {} can be found'.format(self.flavors))
184
184
 
185
185
    def setup(self):
235
235
            time.sleep(5)
236
236
        # MISSINGTEST: What if the instance doesn't come up after max_tries ?
237
237
        if status == 'BUILD':
238
 
            raise NovaClientException('Instance never came up')
 
238
            raise TestBedException('Instance never came up')
239
239
        else:
240
 
            raise NovaClientException('Instance never provided an IP')
 
240
            raise TestBedException('Instance never provided an IP')
241
241
 
242
242
    def get_cloud_init_console(self, length=None):
243
243
        return self.instance.get_console_output(length)
252
252
            # the console for the specific message we specified in user-data).
253
253
            try:
254
254
                console = self.get_cloud_init_console(10)
 
255
            except exceptions.OverLimit:
 
256
                # This happens rarely but breaks badly if not caught. elmo
 
257
                # recommended a 30 seconds nap in that case.
 
258
                nap_time = 30
 
259
                msg = ('Rate limit while acquiring nova console for {},'
 
260
                       ' will sleep for {} seconds')
 
261
                log.exception(msg.format(self.instance.id, nap_time))
 
262
                time.sleep(nap_time)
 
263
                continue
255
264
            except requests.ConnectionError:
256
265
                # The reported status is the one known before the last attempt.
257
266
                log.warn('Received connection error for {},'
264
273
                    'cloud-init completed for {}'.format(self.instance.id))
265
274
                return
266
275
            time.sleep(5)
267
 
        raise NovaClientException('Instance never completed cloud-init')
 
276
        raise TestBedException('Instance never completed cloud-init')
268
277
 
269
278
    def teardown(self):
270
279
        self.nova.servers.delete(self.instance.id)
294
303
        return proc, out, err
295
304
 
296
305
    def get_remote_content(self, path):
297
 
        _, content, _ = self.ssh('cat', path, out=subprocess.PIPE)
 
306
        proc, content, err = self.ssh('cat', path, out=subprocess.PIPE,
 
307
                                      err=subprocess.PIPE)
 
308
        if proc.returncode:
 
309
            # We didn't get a proper content, report it instead
 
310
            content = ("{} couldn't be copied from testbed {}:\n"
 
311
                       "error: {}\n".format(path, self.ip, err))
298
312
        return content
299
313
 
300
314
    def run_test(self, package):