Exemplo n.º 1
0
 def _TestUpdate(self, failcmd):
   data = {
     constants.SSHS_SSH_HOST_KEY: [
       (constants.SSHK_DSA, "dsapriv", "dsapub"),
       (constants.SSHK_ECDSA, "ecdsapriv", "ecdsapub"),
       (constants.SSHK_RSA, "rsapriv", "rsapub"),
       ],
     constants.SSHS_SSH_KEY_TYPE: "dsa",
     constants.SSHS_SSH_KEY_BITS: 1024,
     }
   runcmd_fn = compat.partial(self._RunCmd, failcmd)
   if failcmd:
     self.assertRaises(_JoinError, prepare_node_join.UpdateSshDaemon,
                       data, False, _runcmd_fn=runcmd_fn,
                       _keyfiles=self.keyfiles)
   else:
     prepare_node_join.UpdateSshDaemon(data, False, _runcmd_fn=runcmd_fn,
                                       _keyfiles=self.keyfiles)
   self.assertEqual(sorted(os.listdir(self.tmpdir)), sorted([
     "rsa.public", "rsa.private",
     "dsa.public", "dsa.private",
     "ecdsa.public", "ecdsa.private",
     ]))
   self.assertEqual(utils.ReadFile(utils.PathJoin(self.tmpdir, "rsa.public")),
                    "rsapub")
   self.assertEqual(utils.ReadFile(utils.PathJoin(self.tmpdir, "rsa.private")),
                    "rsapriv")
   self.assertEqual(utils.ReadFile(utils.PathJoin(self.tmpdir, "dsa.public")),
                    "dsapub")
   self.assertEqual(utils.ReadFile(utils.PathJoin(self.tmpdir, "dsa.private")),
                    "dsapriv")
   self.assertEqual(utils.ReadFile(utils.PathJoin(
       self.tmpdir, "ecdsa.public")), "ecdsapub")
   self.assertEqual(utils.ReadFile(utils.PathJoin(
       self.tmpdir, "ecdsa.private")), "ecdsapriv")
Exemplo n.º 2
0
  def testNoKeys(self):
    data_empty_keys = {
      constants.SSHS_SSH_HOST_KEY: [],
      }

    for data in [{}, data_empty_keys]:
      for dry_run in [False, True]:
        prepare_node_join.UpdateSshDaemon(data, dry_run,
                                          _runcmd_fn=NotImplemented,
                                          _keyfiles=NotImplemented)
    self.assertEqual(os.listdir(self.tmpdir), [])
 def _TestDryRun(self, data):
     prepare_node_join.UpdateSshDaemon(data,
                                       True,
                                       _runcmd_fn=NotImplemented,
                                       _keyfiles=self.keyfiles)
     self.assertEqual(os.listdir(self.tmpdir), [])