testutils: add keys to own 'authorized_keys' file
authorHelga Velroyen <helgav@google.com>
Tue, 24 Nov 2015 10:11:41 +0000 (11:11 +0100)
committerHelga Velroyen <helgav@google.com>
Thu, 17 Dec 2015 08:12:53 +0000 (09:12 +0100)
This patch updates the SSH testutils to match reality better.
So far, the test framework did not consider the fact that
the key of each node should be added to it's own
'authorized_keys' file, even if the node is not a master
candidate. This patch fixes that to represent the production
behavior more accurately.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Lisa Velden <velden@google.com>

test/py/ganeti.backend_unittest.py
test/py/testutils_ssh.py

index 35ea9f4..e90d9af 100755 (executable)
@@ -1385,10 +1385,11 @@ class TestAddRemoveGenerateNodeSshKey(testutils.GanetiTestCase):
 
     self._ssh_file_manager.AssertNoNodeHasPublicKey(
         node_info.uuid, node_info.key)
-    self._ssh_file_manager.AssertNoNodeHasAuthorizedKey(node_info.key)
+    self._ssh_file_manager.AssertNodeSetOnlyHasAuthorizedKey(
+        [node_name], node_info.key)
     self.assertEqual(0,
         len(self._ssh_file_manager.GetPublicKeysOfNode(node_name)))
-    self.assertEqual(0,
+    self.assertEqual(1,
         len(self._ssh_file_manager.GetAuthorizedKeysOfNode(node_name)))
 
   def testRemoveNormalNode(self):
@@ -1408,10 +1409,11 @@ class TestAddRemoveGenerateNodeSshKey(testutils.GanetiTestCase):
 
     self._ssh_file_manager.AssertNoNodeHasPublicKey(
         node_info.uuid, node_info.key)
-    self._ssh_file_manager.AssertNoNodeHasAuthorizedKey(node_info.key)
+    self._ssh_file_manager.AssertNodeSetOnlyHasAuthorizedKey(
+        [node_name], node_info.key)
     self.assertEqual(0,
         len(self._ssh_file_manager.GetPublicKeysOfNode(node_name)))
-    self.assertEqual(0,
+    self.assertEqual(1,
         len(self._ssh_file_manager.GetAuthorizedKeysOfNode(node_name)))
 
   def testDemoteMasterCandidateToPotentialMasterCandidate(self):
@@ -1458,7 +1460,8 @@ class TestAddRemoveGenerateNodeSshKey(testutils.GanetiTestCase):
 
     self._ssh_file_manager.AssertNoNodeHasPublicKey(
         node_info.uuid, node_info.key)
-    self._ssh_file_manager.AssertNoNodeHasAuthorizedKey(node_info.key)
+    self._ssh_file_manager.AssertNodeSetOnlyHasAuthorizedKey(
+        [node_name], node_info.key)
 
   def _GetReducedOnlineNodeList(self):
     """'Randomly' mark some nodes as offline."""
index e4d76c1..fa4df3d 100644 (file)
@@ -126,8 +126,9 @@ class FakeSshFileManager(object):
         self._public_keys[receiving_node_name][node_info.uuid] = [node_info.key]
 
   def _FillAuthorizedKeyOfOneNode(self, receiving_node_name):
-    for node_info in self._all_node_data.values():
-      if node_info.is_master_candidate:
+    for node_name, node_info in self._all_node_data.items():
+      if node_info.is_master_candidate \
+          or node_name == receiving_node_name:
         self._authorized_keys[receiving_node_name].add(node_info.key)
 
   def InitAllNodes(self, num_nodes, num_pot_mcs, num_mcs):
@@ -279,6 +280,7 @@ class FakeSshFileManager(object):
     @param query_node_key: key which is looked for
 
     """
+    assert isinstance(node_set, list)
     for node_name in self._all_node_data.keys():
       if node_name in node_set:
         if not self.NodeHasAuthorizedKey(node_name, query_node_key):
@@ -588,7 +590,6 @@ class FakeSshFileManager(object):
     @see: C{ssh.QueryPubKey}
 
     """
-
     assert self._master_node_name
     all_keys = target_uuids is None
     if all_keys: