summaryrefslogtreecommitdiff
path: root/magnum/tests/functional/api/v1/test_baymodel.py
blob: 5dfaef99427bf0bbc18b0687b1da76caf13ba58c (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# 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.lib.common.utils import data_utils
from tempest.lib import exceptions
import testtools

from magnum.tests.functional.api import base
from magnum.tests.functional.common import datagen


class BayModelTest(base.BaseTempestTest):

    """Tests for baymodel CRUD."""

    def __init__(self, *args, **kwargs):
        super(BayModelTest, self).__init__(*args, **kwargs)
        self.baymodels = []
        self.baymodel_client = None
        self.keypairs_client = None

    def setUp(self):
        try:
            super(BayModelTest, self).setUp()
            (self.baymodel_client,
             self.keypairs_client) = self.get_clients_with_new_creds(
                 type_of_creds='default',
                 request_type='baymodel')
        except Exception:
            self.tearDown()
            raise

    def tearDown(self):
        for baymodel_id in self.baymodels:
            self._delete_baymodel(baymodel_id)
            self.baymodels.remove(baymodel_id)
        super(BayModelTest, self).tearDown()

    def _create_baymodel(self, baymodel_model):
        resp, model = self.baymodel_client.post_baymodel(baymodel_model)
        self.assertEqual(201, resp.status)
        self.baymodels.append(model.uuid)
        return resp, model

    def _delete_baymodel(self, baymodel_id):
        resp, model = self.baymodel_client.delete_baymodel(baymodel_id)
        self.assertEqual(204, resp.status)
        return resp, model

    @testtools.testcase.attr('positive')
    def test_list_baymodels(self):
        gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
        _, temp_model = self._create_baymodel(gen_model)
        resp, model = self.baymodel_client.list_baymodels()
        self.assertEqual(200, resp.status)
        self.assertGreater(len(model.baymodels), 0)
        self.assertIn(
            temp_model.uuid, list([x['uuid'] for x in model.baymodels]))

    @testtools.testcase.attr('positive')
    def test_create_baymodel(self):
        gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
        resp, model = self._create_baymodel(gen_model)

    @testtools.testcase.attr('positive')
    def test_create_get_public_baymodel(self):
        gen_model = datagen.valid_swarm_baymodel(is_public=True)
        resp, model = self._create_baymodel(gen_model)

        resp, model = self.baymodel_client.get_baymodel(model.uuid)
        self.assertEqual(200, resp.status)
        self.assertTrue(model.public)

    @testtools.testcase.attr('positive')
    def test_update_baymodel_public_by_uuid(self):
        path = "/public"
        gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
        resp, old_model = self._create_baymodel(gen_model)

        patch_model = datagen.baymodel_replace_patch_data(path, value=True)
        resp, new_model = self.baymodel_client.patch_baymodel(
            old_model.uuid, patch_model)
        self.assertEqual(200, resp.status)

        resp, model = self.baymodel_client.get_baymodel(new_model.uuid)
        self.assertEqual(200, resp.status)
        self.assertTrue(model.public)

    @testtools.testcase.attr('positive')
    def test_update_baymodel_by_uuid(self):
        gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
        resp, old_model = self._create_baymodel(gen_model)

        path = "/name"
        patch_model = datagen.baymodel_replace_patch_data(path)
        resp, new_model = self.baymodel_client.patch_baymodel(
            old_model.uuid, patch_model)
        self.assertEqual(200, resp.status)

        resp, model = self.baymodel_client.get_baymodel(new_model.uuid)
        self.assertEqual(200, resp.status)
        self.assertEqual(old_model.uuid, new_model.uuid)
        self.assertEqual(model.name, new_model.name)

    @testtools.testcase.attr('positive')
    def test_delete_baymodel_by_uuid(self):
        gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
        resp, model = self._create_baymodel(gen_model)
        resp, _ = self.baymodel_client.delete_baymodel(model.uuid)
        self.assertEqual(204, resp.status)
        self.baymodels.remove(model.uuid)

    @testtools.testcase.attr('positive')
    def test_delete_baymodel_by_name(self):
        gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
        resp, model = self._create_baymodel(gen_model)
        resp, _ = self.baymodel_client.delete_baymodel(model.name)
        self.assertEqual(204, resp.status)
        self.baymodels.remove(model.uuid)

    @testtools.testcase.attr('negative')
    def test_get_baymodel_by_uuid_404(self):
        self.assertRaises(
            exceptions.NotFound,
            self.baymodel_client.get_baymodel, data_utils.rand_uuid())

    @testtools.testcase.attr('negative')
    def test_update_baymodel_404(self):
        path = "/name"
        patch_model = datagen.baymodel_replace_patch_data(path)

        self.assertRaises(
            exceptions.NotFound,
            self.baymodel_client.patch_baymodel,
            data_utils.rand_uuid(), patch_model)

    @testtools.testcase.attr('negative')
    def test_delete_baymodel_404(self):
        self.assertRaises(
            exceptions.NotFound,
            self.baymodel_client.delete_baymodel, data_utils.rand_uuid())

    @testtools.testcase.attr('negative')
    def test_get_baymodel_by_name_404(self):
        self.assertRaises(
            exceptions.NotFound,
            self.baymodel_client.get_baymodel, 'fooo')

    @testtools.testcase.attr('negative')
    def test_update_baymodel_name_not_found(self):
        path = "/name"
        patch_model = datagen.baymodel_replace_patch_data(path)

        self.assertRaises(
            exceptions.NotFound,
            self.baymodel_client.patch_baymodel, 'fooo', patch_model)

    @testtools.testcase.attr('negative')
    def test_delete_baymodel_by_name_404(self):
        self.assertRaises(
            exceptions.NotFound,
            self.baymodel_client.get_baymodel, 'fooo')

    @testtools.testcase.attr('negative')
    def test_create_baymodel_missing_image(self):
        gen_model = datagen.baymodel_data_with_missing_image()
        self.assertRaises(
            exceptions.BadRequest,
            self.baymodel_client.post_baymodel, gen_model)

    @testtools.testcase.attr('negative')
    def test_create_baymodel_missing_flavor(self):
        gen_model = datagen.baymodel_data_with_missing_flavor()
        self.assertRaises(
            exceptions.BadRequest,
            self.baymodel_client.post_baymodel, gen_model)

    @testtools.testcase.attr('negative')
    def test_update_baymodel_invalid_patch(self):
        # get json object
        gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
        resp, old_model = self._create_baymodel(gen_model)

        self.assertRaises(
            exceptions.BadRequest,
            self.baymodel_client.patch_baymodel, data_utils.rand_uuid(),
            gen_model)

    @testtools.testcase.attr('negative')
    def test_create_baymodel_invalid_network_driver(self):
        gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
        gen_model.network_driver = 'invalid_network_driver'
        self.assertRaises(
            exceptions.BadRequest,
            self.baymodel_client.post_baymodel, gen_model)

    @testtools.testcase.attr('negative')
    def test_create_baymodel_invalid_volume_driver(self):
        gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
        gen_model.volume_driver = 'invalid_volume_driver'
        self.assertRaises(
            exceptions.BadRequest,
            self.baymodel_client.post_baymodel, gen_model)