Bulk-remove SSH keys of potential master candidates
authorHelga Velroyen <helgav@google.com>
Fri, 20 Nov 2015 09:30:08 +0000 (10:30 +0100)
committerHelga Velroyen <helgav@google.com>
Thu, 17 Dec 2015 08:12:58 +0000 (09:12 +0100)
This patch adds a unit test for bulk-removing potential
master candidates.

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

test/py/ganeti.backend_unittest.py

index 99a9c4d..31c3973 100755 (executable)
@@ -1423,6 +1423,37 @@ class TestAddRemoveGenerateNodeSshKey(testutils.GanetiTestCase):
     self.assertEqual(1,
         len(self._ssh_file_manager.GetAuthorizedKeysOfNode(node_name)))
 
+  def testRemovePotentialMasterCandidateBulk(self):
+    node_list = []
+    key_map = {}
+    for node_name, (node_uuid, node_key, _, _, _) in \
+        self._ssh_file_manager.GetAllPurePotentialMasterCandidates()[:3]:
+      node_list.append(backend.SshRemoveNodeInfo(uuid=node_uuid,
+                                                 name=node_name,
+                                                 from_authorized_keys=False,
+                                                 from_public_keys=True,
+                                                 clear_authorized_keys=True,
+                                                 clear_public_keys=True))
+      key_map[node_name] = node_key
+
+    backend.RemoveNodeSshKeyBulk(node_list,
+                                 self._master_candidate_uuids,
+                                 self._potential_master_candidates,
+                                 pub_key_file=self._pub_key_file,
+                                 ssconf_store=self._ssconf_mock,
+                                 noded_cert_file=self.noded_cert_file,
+                                 run_cmd_fn=self._run_cmd_mock)
+
+    for node_info in node_list:
+      self._ssh_file_manager.AssertNoNodeHasPublicKey(
+          node_info.uuid, key_map[node_info.name])
+      self._ssh_file_manager.AssertNodeSetOnlyHasAuthorizedKey(
+          [node_info.name], key_map[node_info.name])
+      self.assertEqual(0,
+          len(self._ssh_file_manager.GetPublicKeysOfNode(node_info.name)))
+      self.assertEqual(1,
+          len(self._ssh_file_manager.GetAuthorizedKeysOfNode(node_info.name)))
+
   def testRemoveNormalNode(self):
     node_name, node_info = self._ssh_file_manager.GetAllNormalNodes()[0]