Revision 16abfbc2 test/ganeti.utils_unittest.py
b/test/ganeti.utils_unittest.py | ||
---|---|---|
31 | 31 |
import shutil |
32 | 32 |
|
33 | 33 |
import ganeti |
34 |
from ganeti import constants |
|
34 | 35 |
from ganeti.utils import IsProcessAlive, Lock, Unlock, RunCmd, \ |
35 | 36 |
RemoveFile, CheckDict, MatchNameComponent, FormatUnit, \ |
36 | 37 |
ParseUnit, AddAuthorizedKey, RemoveAuthorizedKey, \ |
37 |
ShellQuote, ShellQuoteArgs, _ParseIpOutput, TcpPing, \ |
|
38 |
ListVisibleFiles |
|
38 |
ShellQuote, ShellQuoteArgs, TcpPing, ListVisibleFiles |
|
39 | 39 |
from ganeti.errors import LockError, UnitParseError |
40 | 40 |
|
41 | 41 |
|
... | ... | |
445 | 445 |
self.assertEqual(ShellQuoteArgs(['a', 'b\'', 'c']), "a 'b'\\\''' c") |
446 | 446 |
|
447 | 447 |
|
448 |
class TestIpAdressList(unittest.TestCase): |
|
449 |
"""Test case for local IP addresses""" |
|
450 |
|
|
451 |
def _test(self, output, required): |
|
452 |
ips = _ParseIpOutput(output) |
|
453 |
|
|
454 |
# Sort the output, so our check below works in all cases |
|
455 |
ips.sort() |
|
456 |
required.sort() |
|
457 |
|
|
458 |
self.assertEqual(required, ips) |
|
459 |
|
|
460 |
def testSingleIpAddress(self): |
|
461 |
output = \ |
|
462 |
("3: lo inet 127.0.0.1/8 brd 127.255.255.255 scope host lo\n" |
|
463 |
"5: eth0 inet 10.0.0.1/24 brd 172.30.15.127 scope global eth0\n") |
|
464 |
self._test(output, ['127.0.0.1', '10.0.0.1']) |
|
465 |
|
|
466 |
def testMultipleIpAddresses(self): |
|
467 |
output = \ |
|
468 |
("3: lo inet 127.0.0.1/8 brd 127.255.255.255 scope host lo\n" |
|
469 |
"5: eth0 inet 10.0.0.1/24 brd 172.30.15.127 scope global eth0\n" |
|
470 |
"5: eth0 inet 1.2.3.4/8 brd 1.255.255.255 scope global eth0:test\n") |
|
471 |
self._test(output, ['127.0.0.1', '10.0.0.1', '1.2.3.4']) |
|
472 |
|
|
473 |
|
|
474 | 448 |
class TestTcpPing(unittest.TestCase): |
475 | 449 |
"""Testcase for TCP version of ping - against listen(2)ing port""" |
476 | 450 |
|
477 | 451 |
def setUp(self): |
478 | 452 |
self.listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
479 |
self.listener.bind(("127.0.0.1", 0))
|
|
453 |
self.listener.bind((constants.LOCALHOST_IP_ADDRESS, 0))
|
|
480 | 454 |
self.listenerport = self.listener.getsockname()[1] |
481 | 455 |
self.listener.listen(1) |
482 | 456 |
|
... | ... | |
486 | 460 |
del self.listenerport |
487 | 461 |
|
488 | 462 |
def testTcpPingToLocalHostAccept(self): |
489 |
self.assert_(TcpPing("127.0.0.1",
|
|
490 |
"127.0.0.1",
|
|
463 |
self.assert_(TcpPing(constants.LOCALHOST_IP_ADDRESS,
|
|
464 |
constants.LOCALHOST_IP_ADDRESS,
|
|
491 | 465 |
self.listenerport, |
492 | 466 |
timeout=10, |
493 | 467 |
live_port_needed=True), |
... | ... | |
499 | 473 |
|
500 | 474 |
def setUp(self): |
501 | 475 |
self.deaflistener = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
502 |
self.deaflistener.bind(("127.0.0.1", 0))
|
|
476 |
self.deaflistener.bind((constants.LOCALHOST_IP_ADDRESS, 0))
|
|
503 | 477 |
self.deaflistenerport = self.deaflistener.getsockname()[1] |
504 | 478 |
|
505 | 479 |
def tearDown(self): |
... | ... | |
507 | 481 |
del self.deaflistenerport |
508 | 482 |
|
509 | 483 |
def testTcpPingToLocalHostAcceptDeaf(self): |
510 |
self.failIf(TcpPing("127.0.0.1",
|
|
511 |
"127.0.0.1",
|
|
484 |
self.failIf(TcpPing(constants.LOCALHOST_IP_ADDRESS,
|
|
485 |
constants.LOCALHOST_IP_ADDRESS,
|
|
512 | 486 |
self.deaflistenerport, |
513 |
timeout=10, # timeout for blocking operations
|
|
487 |
timeout=constants.TCP_PING_TIMEOUT,
|
|
514 | 488 |
live_port_needed=True), # need successful connect(2) |
515 | 489 |
"successfully connected to deaf listener") |
516 | 490 |
|
517 | 491 |
def testTcpPingToLocalHostNoAccept(self): |
518 |
self.assert_(TcpPing("127.0.0.1",
|
|
519 |
"127.0.0.1",
|
|
492 |
self.assert_(TcpPing(constants.LOCALHOST_IP_ADDRESS,
|
|
493 |
constants.LOCALHOST_IP_ADDRESS,
|
|
520 | 494 |
self.deaflistenerport, |
521 |
timeout=10, # timeout for blocking operations
|
|
495 |
timeout=constants.TCP_PING_TIMEOUT,
|
|
522 | 496 |
live_port_needed=False), # ECONNREFUSED is OK |
523 | 497 |
"failed to ping alive host on deaf port") |
524 | 498 |
|
Also available in: Unified diff