summaryrefslogtreecommitdiff
path: root/tempest/api/compute/servers/test_instance_actions.py
blob: 028da68be1f9e03d7c61f868c8180b7b1542c942 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempest.api.compute import base
from tempest.common import waiters
from tempest.lib import decorators


class InstanceActionsTestJSON(base.BaseV2ComputeTest):
    """Test instance actions API"""

    create_default_network = True

    @classmethod
    def setup_clients(cls):
        super(InstanceActionsTestJSON, cls).setup_clients()
        cls.client = cls.servers_client

    @classmethod
    def resource_setup(cls):
        super(InstanceActionsTestJSON, cls).resource_setup()
        cls.server = cls.create_test_server(wait_until='ACTIVE')
        cls.request_id = cls.server.response['x-compute-request-id']

    @decorators.idempotent_id('77ca5cc5-9990-45e0-ab98-1de8fead201a')
    def test_list_instance_actions(self):
        """Test listing actions of the provided server"""
        self.reboot_server(self.server['id'], type='HARD')

        body = (self.client.list_instance_actions(self.server['id'])
                ['instanceActions'])
        self.assertEqual(len(body), 2, str(body))
        self.assertEqual(sorted([i['action'] for i in body]),
                         ['create', 'reboot'])

    @decorators.idempotent_id('aacc71ca-1d70-4aa5-bbf6-0ff71470e43c')
    def test_get_instance_action(self):
        """Test getting the action details of the provided server"""
        body = self.client.show_instance_action(
            self.server['id'], self.request_id)['instanceAction']
        self.assertEqual(self.server['id'], body['instance_uuid'])
        self.assertEqual('create', body['action'])


class InstanceActionsV221TestJSON(base.BaseV2ComputeTest):
    """Test instance actions with compute microversion greater than 2.20"""

    create_default_network = True

    min_microversion = '2.21'
    max_microversion = 'latest'

    @classmethod
    def setup_clients(cls):
        super(InstanceActionsV221TestJSON, cls).setup_clients()
        cls.client = cls.servers_client

    @decorators.idempotent_id('0a0f85d4-10fa-41f6-bf80-a54fb4aa2ae1')
    def test_get_list_deleted_instance_actions(self):
        """Test listing actions for deleted instance

        Listing actions for deleted instance should succeed and the returned
        actions should contain 'create' and 'delete'.
        """
        server = self.create_test_server(wait_until='ACTIVE')
        self.client.delete_server(server['id'])
        waiters.wait_for_server_termination(self.client, server['id'])
        body = (self.client.list_instance_actions(server['id'])
                ['instanceActions'])
        self.assertEqual(len(body), 2, str(body))
        self.assertEqual(sorted([i['action'] for i in body]),
                         ['create', 'delete'])