Skip to content
Snippets Groups Projects
Commit 424908c1 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Rollback commit 356.

parent 2d6cfa31
No related branches found
No related tags found
No related merge requests found
......@@ -815,47 +815,6 @@ def RemoveEtcHostsEntry(file_name, hostname):
raise
def _SplitKnownHostsHosts(hosts):
"""Parses the first field of a known_hosts file.
TODO: Support other formats.
"""
return hosts.split(',')
def AddKnownHost(file_name, hostname, pubkey):
"""Adds a new known host to a known_hosts file.
"""
f = open(file_name, 'a+')
try:
nl = True
for line in f:
fields = line.split()
if (len(fields) < 3 or
fields[0].startswith('#') or
fields[1] != 'ssh-rsa'):
continue
hosts = _SplitKnownHostsHosts(fields[0])
if hostname in hosts and fields[2] == pubkey:
break
nl = line.endswith('\n')
else:
if not nl:
f.write("\n")
f.write(hostname)
f.write(' ssh-rsa ')
f.write(pubkey)
f.write("\n")
f.flush()
finally:
f.close()
def RemoveKnownHost(file_name, hostname):
pass
def CreateBackup(file_name):
"""Creates a backup of a file.
......
......@@ -38,8 +38,7 @@ from ganeti.utils import IsProcessAlive, Lock, Unlock, RunCmd, \
RemoveFile, CheckDict, MatchNameComponent, FormatUnit, \
ParseUnit, AddAuthorizedKey, RemoveAuthorizedKey, \
ShellQuote, ShellQuoteArgs, TcpPing, ListVisibleFiles, \
AddEtcHostsEntry, RemoveEtcHostsEntry, \
AddKnownHost, RemoveKnownHost
AddEtcHostsEntry, RemoveEtcHostsEntry
from ganeti.errors import LockError, UnitParseError
......@@ -519,51 +518,6 @@ class TestEtcHosts(unittest.TestCase):
os.unlink(tmpname)
class TestKnownHosts(unittest.TestCase):
"""Test functions modifying known_hosts files"""
def writeTestFile(self):
(fd, tmpname) = tempfile.mkstemp(prefix = 'ganeti-test')
f = os.fdopen(fd, 'w')
try:
f.write('node1.tld,node1\tssh-rsa AAAA1234567890=\n')
f.write('node2,node2.tld ssh-rsa AAAA1234567890=\n')
finally:
f.close()
return tmpname
def testAddingNewHost(self):
tmpname = self.writeTestFile()
try:
AddKnownHost(tmpname, 'node3.tld', 'AAAA0987654321=')
f = open(tmpname, 'r')
try:
self.assertEqual(md5.new(f.read(8192)).hexdigest(),
'86cf3c7c7983a3bd5c475c4c1a3e5678')
finally:
f.close()
finally:
os.unlink(tmpname)
def testAddingOldHost(self):
tmpname = self.writeTestFile()
try:
AddKnownHost(tmpname, 'node2.tld', 'AAAA0987654321=')
f = open(tmpname, 'r')
try:
os.system("vim %s" % tmpname)
self.assertEqual(md5.new(f.read(8192)).hexdigest(),
'86cf3c7c7983a3bd5c475c4c1a3e5678')
finally:
f.close()
finally:
os.unlink(tmpname)
class TestShellQuoting(unittest.TestCase):
"""Test case for shell quoting functions"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment