Skip to content
Snippets Groups Projects
Commit 33993ab8 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

Adding a paramiko fingerprint format helper


And provide unittests for them

Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent e4d89284
No related branches found
No related tags found
No related merge requests found
......@@ -26,12 +26,25 @@
import os
import logging
import re
from ganeti import utils
from ganeti import errors
from ganeti import constants
def FormatParamikoFingerprint(fingerprint):
"""Formats the fingerprint of L{paramiko.PKey.get_fingerprint()}
@type fingerprint: str
@param fingerprint: PKey fingerprint
@return The string hex representation of the fingerprint
"""
assert len(fingerprint) % 2 == 0
return ":".join(re.findall(r"..", fingerprint.lower()))
def GetUserFiles(user, mkdir=False):
"""Return the paths of a user's ssh files.
......
......@@ -47,6 +47,12 @@ class TestKnownHosts(testutils.GanetiTestCase):
"%s ssh-rsa %s\n" % (cfg.GetClusterName(),
mocks.FAKE_CLUSTER_KEY))
def testFormatParamikoFingerprintCorrect(self):
self.assertEqual(ssh.FormatParamikoFingerprint("C0Ffee"), "c0:ff:ee")
def testFormatParamikoFingerprintNotDividableByTwo(self):
self.assertRaises(AssertionError, ssh.FormatParamikoFingerprint, "C0Ffe")
if __name__ == '__main__':
testutils.GanetiTestProgram()
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