Revision 2d6cfa31 test/ganeti.utils_unittest.py

b/test/ganeti.utils_unittest.py
38 38
     RemoveFile, CheckDict, MatchNameComponent, FormatUnit, \
39 39
     ParseUnit, AddAuthorizedKey, RemoveAuthorizedKey, \
40 40
     ShellQuote, ShellQuoteArgs, TcpPing, ListVisibleFiles, \
41
     AddEtcHostsEntry, RemoveEtcHostsEntry
41
     AddEtcHostsEntry, RemoveEtcHostsEntry, \
42
     AddKnownHost, RemoveKnownHost
42 43
from ganeti.errors import LockError, UnitParseError
43 44

  
44 45

  
......
518 519
      os.unlink(tmpname)
519 520

  
520 521

  
522
class TestKnownHosts(unittest.TestCase):
523
  """Test functions modifying known_hosts files"""
524

  
525
  def writeTestFile(self):
526
    (fd, tmpname) = tempfile.mkstemp(prefix = 'ganeti-test')
527
    f = os.fdopen(fd, 'w')
528
    try:
529
      f.write('node1.tld,node1\tssh-rsa AAAA1234567890=\n')
530
      f.write('node2,node2.tld ssh-rsa AAAA1234567890=\n')
531
    finally:
532
      f.close()
533

  
534
    return tmpname
535

  
536
  def testAddingNewHost(self):
537
    tmpname = self.writeTestFile()
538
    try:
539
      AddKnownHost(tmpname, 'node3.tld', 'AAAA0987654321=')
540

  
541
      f = open(tmpname, 'r')
542
      try:
543
        self.assertEqual(md5.new(f.read(8192)).hexdigest(),
544
                         '86cf3c7c7983a3bd5c475c4c1a3e5678')
545
      finally:
546
        f.close()
547
    finally:
548
      os.unlink(tmpname)
549

  
550
  def testAddingOldHost(self):
551
    tmpname = self.writeTestFile()
552
    try:
553
      AddKnownHost(tmpname, 'node2.tld', 'AAAA0987654321=')
554

  
555
      f = open(tmpname, 'r')
556
      try:
557
        os.system("vim %s" % tmpname)
558
        self.assertEqual(md5.new(f.read(8192)).hexdigest(),
559
                         '86cf3c7c7983a3bd5c475c4c1a3e5678')
560
      finally:
561
        f.close()
562
    finally:
563
      os.unlink(tmpname)
564

  
565

  
566

  
521 567
class TestShellQuoting(unittest.TestCase):
522 568
  """Test case for shell quoting functions"""
523 569

  

Also available in: Unified diff