Exemplo n.º 1
0
 def test_keypair_cleanup(self, mock_safe_remove, mock_osclients):
     keypair_ctx = keypair.Keypair(self.ctx_with_keys)
     keypair_ctx.cleanup()
     mock_clients = mock_osclients.return_value
     mock_nova = mock_clients.nova.return_value
     self.assertEqual([mock.call(mock_nova)] * self.users,
                      mock_safe_remove.mock_calls)
Exemplo n.º 2
0
 def test_keypair_safe_remove(self):
     mock_nova = mock.MagicMock()
     keypair_ctx = keypair.Keypair(self.ctx_without_keys)
     keypair_ctx._keypair_safe_remove(mock_nova)
     self.assertEqual(
         [mock.call.delete('rally_ssh_key')],
         mock_nova.keypairs.mock_calls)
Exemplo n.º 3
0
 def test_keypair_generate(self, mock_osclients, mock_safe_remove):
     keypair_ctx = keypair.Keypair(self.ctx_without_keys)
     keypair_ctx._generate_keypair('endpoint')
     mock_clients = mock_osclients.return_value
     mock_nova = mock_clients.nova.return_value
     self.assertIn(mock.call().nova().keypairs.create('rally_ssh_key'),
                   mock_osclients.mock_calls)
     mock_safe_remove.assert_called_once_with(mock_nova)
Exemplo n.º 4
0
    def test_keypair_setup(self, mock_generate):
        mock_generate.side_effect = [
            {
                "id": "key_id",
                "key": "key",
                "name": self.keypair_name
            },
            {
                "id": "key_id",
                "key": "key",
                "name": self.keypair_name
            },
        ]

        keypair_ctx = keypair.Keypair(self.ctx_without_keys)
        keypair_ctx.setup()
        self.assertEqual(self.ctx_with_keys, keypair_ctx.context)

        self.assertEqual([mock.call("endpoint")] * 2, mock_generate.mock_calls)
Exemplo n.º 5
0
    def test_keypair_generate(self, mock_osclients):
        mock_keypairs = mock_osclients.return_value.nova.return_value.keypairs
        mock_keypair = mock_keypairs.create.return_value
        mock_keypair.public_key = "public_key"
        mock_keypair.private_key = "private_key"
        mock_keypair.id = "key_id"
        keypair_ctx = keypair.Keypair(self.ctx_without_keys)
        key = keypair_ctx._generate_keypair("endpoint")

        self.assertEqual(
            {
                "id": "key_id",
                "name": "rally_ssh_key_foo_task_id",
                "private": "private_key",
                "public": "public_key"
            }, key)

        mock_osclients.assert_has_calls([
            mock.call().nova().keypairs.delete("rally_ssh_key_foo_task_id"),
            mock.call().nova().keypairs.create("rally_ssh_key_foo_task_id"),
        ])
Exemplo n.º 6
0
 def test_keypair_setup(self, mock_generate):
     mock_generate.return_value = "key"
     keypair_ctx = keypair.Keypair(self.ctx_without_keys)
     keypair_ctx.setup()
     self.assertEqual(self.ctx_without_keys, self.ctx_with_keys)
Exemplo n.º 7
0
 def test_keypair_cleanup(self, mock_cleanup):
     keypair_ctx = keypair.Keypair(self.ctx_with_keys)
     keypair_ctx.cleanup()
     mock_cleanup.assert_called_once_with(names=["nova.keypairs"],
                                          users=self.ctx_with_keys["users"])