예제 #1
0
 def test_keypair_cleanup(self, mock_cleanup):
     keypair_ctx = keypairs.Keypair(self.ctx_with_keys)
     keypair_ctx.cleanup()
     mock_cleanup.assert_called_once_with(
         names=["nova.keypairs"],
         users=self.ctx_with_keys["users"],
         superclass=keypairs.Keypair,
         task_id=self.ctx_with_keys["task"]["uuid"])
예제 #2
0
    def test_keypair_setup(self, mock_keypair__generate_keypair):
        mock_keypair__generate_keypair.side_effect = [
            {"id": "key_id", "key": "key", "name": self.keypair_name},
            {"id": "key_id", "key": "key", "name": self.keypair_name},
        ]

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

        self.assertEqual(
            [mock.call("endpoint")] * 2,
            mock_keypair__generate_keypair.mock_calls)
예제 #3
0
    def test_keypair_generate(self, mock_clients):
        mock_keypairs = mock_clients.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 = keypairs.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_clients.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"),
        ])
예제 #4
0
    def test_keypair_setup(self):
        keypair_ctx = keypairs.Keypair(self.ctx_without_keys)
        keypair_ctx._generate_keypair = mock.Mock(side_effect=[
            {
                "id": "key_id_1",
                "key": "key_1",
                "name": "key_name_1"
            },
            {
                "id": "key_id_2",
                "key": "key_2",
                "name": "key_name_2"
            },
        ])

        keypair_ctx.setup()
        self.assertEqual(keypair_ctx.context, self.ctx_with_keys)

        keypair_ctx._generate_keypair.assert_has_calls(
            [mock.call("credential_1"),
             mock.call("credential_2")])
예제 #5
0
    def test_keypair_generate(self, mock_clients):
        mock_keypairs = mock_clients.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 = keypairs.Keypair(self.ctx_without_keys)
        keypair_ctx.generate_random_name = mock.Mock()

        key = keypair_ctx._generate_keypair("credential")

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

        mock_clients.assert_has_calls([
            mock.call().nova().keypairs.create(
                keypair_ctx.generate_random_name.return_value),
        ])
예제 #6
0
 def test_keypair_cleanup(self, mock_cleanup):
     keypair_ctx = keypairs.Keypair(self.ctx_with_keys)
     keypair_ctx.cleanup()
     mock_cleanup.assert_called_once_with(names=["nova.keypairs"],
                                          users=self.ctx_with_keys["users"])