Revision 75a5f456
b/lib/ssh.py | ||
---|---|---|
212 | 212 |
return False, "hostname mismatch, got %s" % remotehostname |
213 | 213 |
|
214 | 214 |
return True, "host matches" |
215 |
|
|
216 |
|
|
217 |
def WriteKnownHostsFile(cfg, sstore, file_name): |
|
218 |
"""Writes the cluster-wide equally known_hosts file. |
|
219 |
|
|
220 |
""" |
|
221 |
utils.WriteFile(file_name, mode=0700, |
|
222 |
data="%s ssh-rsa %s\n" % (sstore.GetClusterName(), |
|
223 |
cfg.GetHostKey())) |
b/test/Makefile.am | ||
---|---|---|
3 | 3 |
ganeti.hooks_unittest.py \ |
4 | 4 |
ganeti.utils_unittest.py \ |
5 | 5 |
ganeti.bdev_unittest.py \ |
6 |
ganeti.ssh_unittest.py \ |
|
6 | 7 |
ganeti.locking_unittest.py |
7 | 8 |
|
8 | 9 |
TESTS_ENVIRONMENT = PYTHONPATH=.:$(top_builddir) |
b/test/ganeti.ssh_unittest.py | ||
---|---|---|
1 |
#!/usr/bin/python |
|
2 |
# |
|
3 |
|
|
4 |
# Copyright (C) 2006, 2007, 2008 Google Inc. |
|
5 |
# |
|
6 |
# This program is free software; you can redistribute it and/or modify |
|
7 |
# it under the terms of the GNU General Public License as published by |
|
8 |
# the Free Software Foundation; either version 2 of the License, or |
|
9 |
# (at your option) any later version. |
|
10 |
# |
|
11 |
# This program is distributed in the hope that it will be useful, but |
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
# General Public License for more details. |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License |
|
17 |
# along with this program; if not, write to the Free Software |
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
19 |
# 02110-1301, USA. |
|
20 |
|
|
21 |
|
|
22 |
"""Script for unittesting the ssh module""" |
|
23 |
|
|
24 |
import os |
|
25 |
import tempfile |
|
26 |
import unittest |
|
27 |
|
|
28 |
import testutils |
|
29 |
import mocks |
|
30 |
|
|
31 |
from ganeti import constants |
|
32 |
from ganeti import utils |
|
33 |
from ganeti import ssh |
|
34 |
|
|
35 |
|
|
36 |
class TestKnownHosts(testutils.GanetiTestCase): |
|
37 |
"""Test case for function writing the known_hosts file""" |
|
38 |
|
|
39 |
def setUp(self): |
|
40 |
self.tmpfile = tempfile.NamedTemporaryFile() |
|
41 |
|
|
42 |
def test(self): |
|
43 |
cfg = mocks.FakeConfig() |
|
44 |
sstore = mocks.FakeSStore() |
|
45 |
ssh.WriteKnownHostsFile(cfg, sstore, self.tmpfile.name) |
|
46 |
self.assertFileContent(self.tmpfile.name, |
|
47 |
"%s ssh-rsa %s\n" % (sstore.GetClusterName(), |
|
48 |
mocks.FAKE_CLUSTER_KEY)) |
|
49 |
|
|
50 |
|
|
51 |
if __name__ == '__main__': |
|
52 |
unittest.main() |
b/test/mocks.py | ||
---|---|---|
21 | 21 |
|
22 | 22 |
"""Module implementing a fake ConfigWriter""" |
23 | 23 |
|
24 |
import socket |
|
25 | 24 |
from ganeti import utils |
26 | 25 |
|
26 |
|
|
27 |
FAKE_CLUSTER_KEY = ("AAAAB3NzaC1yc2EAAAABIwAAAQEAsuGLw70et3eApJ/ZEJkAVZogIrm" |
|
28 |
"EYPQJvb1ll52Ti0nr80Wztxibaa8bYGzY22rQIAloIlePeTGcJceAYK" |
|
29 |
"PZgm0I/Mp2EUGg2NVsQZIzasz6cW0vYuiUbF9GkVlROmvOAykT58RfM" |
|
30 |
"L8RhPrjrQxZc+NXgZtgDugYSZcXHDLUyWM1xKUoYy0MqYG6ZXCC/Zno" |
|
31 |
"RThhmjOJgEmvwrMcTWQjmzH3NeJAxaBsEHR8tiVZ/Y23C/ULWLyNT6R" |
|
32 |
"fB+DE7IovsMQaS+83AK1Teg7RWNyQczachatf/JT8VjUqFYjJepPjMb" |
|
33 |
"vYdB2nQds7/+Bf40C/OpbvnAxna1kVtgFHAo18cQ==") |
|
34 |
|
|
35 |
|
|
27 | 36 |
class FakeConfig: |
28 | 37 |
"""Fake configuration object""" |
29 | 38 |
|
... | ... | |
36 | 45 |
def GetMaster(self): |
37 | 46 |
return utils.HostInfo().name |
38 | 47 |
|
48 |
def GetHostKey(self): |
|
49 |
return FAKE_CLUSTER_KEY |
|
50 |
|
|
39 | 51 |
|
40 | 52 |
class FakeSStore: |
41 | 53 |
"""Fake simplestore object""" |
Also available in: Unified diff