summaryrefslogtreecommitdiff
path: root/nova/tests/functional/notification_sample_tests/test_flavor.py
blob: f206a01b978801af6aed0d88af19567084db6198 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#    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 nova.tests.functional.notification_sample_tests \
    import notification_sample_base
from nova.tests.unit import fake_notifier


class TestFlavorNotificationSample(
        notification_sample_base.NotificationSampleTestBase):

    def test_flavor_create(self):
        body = {
            "flavor": {
                "name": "test_flavor",
                "ram": 1024,
                "vcpus": 2,
                "disk": 10,
                "id": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
                "rxtx_factor": 2.0
            }
        }
        self.admin_api.api_post('flavors', body)
        self._verify_notification('flavor-create')

    def test_flavor_destroy(self):
        body = {
            "flavor": {
                "name": "test_flavor",
                "ram": 1024,
                "vcpus": 2,
                "disk": 10,
                "id": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
                "rxtx_factor": 2.0
            }
        }
        # Create a flavor.
        self.admin_api.api_post('flavors', body)
        self.admin_api.api_delete(
            'flavors/a22d5517-147c-4147-a0d1-e698df5cd4e3')
        self._verify_notification(
            'flavor-delete', actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])

    def test_flavor_update(self):
        body = {
            "flavor": {
                "name": "test_flavor",
                "ram": 1024,
                "vcpus": 2,
                "disk": 10,
                "id": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
                "os-flavor-access:is_public": False,
                "rxtx_factor": 2.0
            }
        }
        # Create a flavor.
        self.admin_api.api_post('flavors', body)

        body = {
            "extra_specs": {
                "hw:numa_nodes": "2",
            }
        }
        self.admin_api.api_post(
            'flavors/a22d5517-147c-4147-a0d1-e698df5cd4e3/os-extra_specs',
            body)

        body = {
            "addTenantAccess": {
                "tenant": "fake_tenant"
            }
        }
        self.admin_api.api_post(
            'flavors/a22d5517-147c-4147-a0d1-e698df5cd4e3/action',
            body)

        self._verify_notification(
            'flavor-update', actual=fake_notifier.VERSIONED_NOTIFICATIONS[2])


class TestFlavorNotificationSamplev2_55(
        notification_sample_base.NotificationSampleTestBase):
    """Tests PUT /flavors/{flavor_id} with a description."""

    MAX_MICROVERSION = '2.55'

    def test_flavor_udpate_with_description(self):
        # First create a flavor without a description.
        body = {
            "flavor": {
                "name": "test_flavor",
                "ram": 1024,
                "vcpus": 2,
                "disk": 10,
                "id": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
                "os-flavor-access:is_public": False,
                "rxtx_factor": 2.0
            }
        }
        # Create a flavor.
        flavor = self.admin_api.api_post('flavors', body).body['flavor']
        # Check the notification; should be the same as the sample where there
        # is no description set.
        self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))
        self._verify_notification(
            'flavor-create',
            replacements={'is_public': False},
            actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])

        # Update and set the flavor description.
        self.admin_api.api_put(
            'flavors/%s' % flavor['id'],
            {'flavor': {'description': 'test description'}}).body['flavor']

        # Assert the notifications, one for create and one for update.
        self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
        self._verify_notification(
            'flavor-update',
            replacements={'description': 'test description',
                          'extra_specs': {},
                          'projects': []},
            actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])