Revision 4fdd25ab

b/snf-tools/test_suite.py
225 225

  
226 226
    def _verify_server_status(self, current_status, new_status):
227 227
        """Verify a server has switched to a specified status"""
228
        log.info("Getting status for server %d, Image %s",
229
                 self.serverid, self.imagename)
230 228
        server = self.client.get_server_details(self.serverid)
231 229
        self.assertIn(server["status"], (current_status, new_status))
232 230
        self.assertEquals(server["status"], new_status)
......
254 252

  
255 253
    def _ping_once(self, ipv6, ip):
256 254
        """Test server responds to a single IPv4 or IPv6 ping"""
257
        log.info("PING IPv%s to %s", "6" if ipv6 else "4", ip)
258 255
        cmd = "ping%s -c 2 -w 3 %s" % ("6" if ipv6 else "", ip)
259 256
        ping = subprocess.Popen(cmd, shell=True,
260 257
                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
......
272 269
        stdin, stdout, stderr = ssh.exec_command("hostname")
273 270
        lines = stdout.readlines()
274 271
        self.assertEqual(len(lines), 1)
275
        return lines
272
        return lines[0]
276 273

  
277 274
    def _try_until_timeout_expires(self, warn_timeout, fail_timeout,
278 275
                                   opmsg, callable, *args, **kwargs):
......
281 278
        warn_tmout = time.time() + warn_timeout
282 279
        fail_tmout = time.time() + fail_timeout
283 280
        while True:
281
            self.assertLess(time.time(), fail_tmout,
282
                            "operation '%s' timed out" % opmsg)
284 283
            if time.time() > warn_tmout:
285
                log.warning("Server %d: %s operation '%s' not done yet",
286
                            opmsg, self.serverid, self.servername)
284
                log.warning("Server %d: `%s' operation `%s' not done yet",
285
                            self.serverid, self.servername, opmsg)
287 286
            try:
287
                log.info("%s... " % opmsg)
288 288
                return callable(*args, **kwargs)
289 289
            except AssertionError:
290 290
                pass
291

  
292
            self.assertLess(time.time(), fail_tmout,
293
                            "operation '%s' timed out" % opmsg)
294 291
            time.sleep(self.query_interval)
295 292

  
296 293
    def _insist_on_tcp_connection(self, family, host, port):
......
305 302

  
306 303
    def _insist_on_status_transition(self, current_status, new_status,
307 304
                                    fail_timeout, warn_timeout=None):
308
        msg = "status transition %s -> %s" % (current_status, new_status)
305
        msg = "Server %d: `%s', waiting for %s -> %s" % \
306
              (self.serverid, self.servername, current_status, new_status)
309 307
        if warn_timeout is None:
310 308
            warn_timeout = fail_timeout
311 309
        self._try_until_timeout_expires(warn_timeout, fail_timeout,
......
313 311
                                        current_status, new_status)
314 312

  
315 313
    def _insist_on_ssh_hostname(self, hostip, username, password):
316
        msg = "ssh to %s, as %s/%s" % (hostip, username, password)
314
        msg = "SSH to %s, as %s/%s" % (hostip, username, password)
317 315
        hostname = self._try_until_timeout_expires(
318 316
                self.action_timeout, self.action_timeout,
319 317
                msg, self._get_hostname_over_ssh,
......
441 439
        ip = self._get_ipv4(server)
442 440
        self._try_until_timeout_expires(self.action_timeout,
443 441
                                        self.action_timeout,
444
                                        "PING IPv4", self._ping_once,
442
                                        "PING IPv4 to %s" % ip,
443
                                        self._ping_once,
445 444
                                        False, ip)
446 445

  
447 446
    def test_007_server_responds_to_ping_IPv6(self):
......
450 449
        ip = self._get_ipv6(server)
451 450
        self._try_until_timeout_expires(self.action_timeout,
452 451
                                        self.action_timeout,
453
                                        "PING IPv6", self._ping_once,
452
                                        "PING IPv6 to %s" % ip,
453
                                        self._ping_once,
454 454
                                        True, ip)
455 455

  
456 456
    def test_008_submit_shutdown_request(self):
......
518 518
        self._skipIf(self.is_windows, "only implemented for Linux servers")
519 519
        self.assertTrue(False, "test not implemented, will fail")
520 520

  
521
    def test_017_submit_delete_request(self):
522
        """Test submit request to delete server"""
523
        self.client.delete_server(self.serverid)
524

  
525
    def test_018_server_becomes_deleted(self):
526
        """Test server becomes DELETED"""
527
        self._insist_on_status_transition("ACTIVE", "DELETED",
528
                                         self.action_timeout,
529
                                         self.action_timeout)
530

  
531
    def test_019_server_no_longer_in_server_list(self):
532
        """Test server is no longer in server list"""
533
        servers = self.client.list_servers()
534
        self.assertNotIn(self.serverid, [s['id'] for s in servers])
535

  
521 536

  
522 537
def _spawn_server_test_case(**kwargs):
523 538
    """Construct a new unit test case class from SpawnServerTestCase"""
......
539 554
    servers = c.list_servers()
540 555
    stale = [s for s in servers if s["name"].startswith(SNF_TEST_PREFIX)]
541 556

  
557
    if len(stale) == 0:
558
        return
559

  
542 560
    print >> sys.stderr, "Found these stale servers from previous runs:"
543 561
    print "    " + \
544 562
          "\n    ".join(["%d: %s" % (s['id'], s['name']) for s in stale])

Also available in: Unified diff