Revision 33993ab8
b/lib/ssh.py | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import os |
28 | 28 |
import logging |
29 |
import re |
|
29 | 30 |
|
30 | 31 |
from ganeti import utils |
31 | 32 |
from ganeti import errors |
32 | 33 |
from ganeti import constants |
33 | 34 |
|
34 | 35 |
|
36 |
def FormatParamikoFingerprint(fingerprint): |
|
37 |
"""Formats the fingerprint of L{paramiko.PKey.get_fingerprint()} |
|
38 |
|
|
39 |
@type fingerprint: str |
|
40 |
@param fingerprint: PKey fingerprint |
|
41 |
@return The string hex representation of the fingerprint |
|
42 |
|
|
43 |
""" |
|
44 |
assert len(fingerprint) % 2 == 0 |
|
45 |
return ":".join(re.findall(r"..", fingerprint.lower())) |
|
46 |
|
|
47 |
|
|
35 | 48 |
def GetUserFiles(user, mkdir=False): |
36 | 49 |
"""Return the paths of a user's ssh files. |
37 | 50 |
|
b/test/ganeti.ssh_unittest.py | ||
---|---|---|
47 | 47 |
"%s ssh-rsa %s\n" % (cfg.GetClusterName(), |
48 | 48 |
mocks.FAKE_CLUSTER_KEY)) |
49 | 49 |
|
50 |
def testFormatParamikoFingerprintCorrect(self): |
|
51 |
self.assertEqual(ssh.FormatParamikoFingerprint("C0Ffee"), "c0:ff:ee") |
|
52 |
|
|
53 |
def testFormatParamikoFingerprintNotDividableByTwo(self): |
|
54 |
self.assertRaises(AssertionError, ssh.FormatParamikoFingerprint, "C0Ffe") |
|
55 |
|
|
50 | 56 |
|
51 | 57 |
if __name__ == '__main__': |
52 | 58 |
testutils.GanetiTestProgram() |
Also available in: Unified diff