summaryrefslogtreecommitdiff
path: root/openstack_dashboard/test/integration_tests/tests/test_instances.py
blob: 852b17055026f1403014da674f6c0d4b9cd3b1e3 (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#    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 openstack_dashboard.test.integration_tests import helpers
from openstack_dashboard.test.integration_tests.regions import messages


class TestInstances(helpers.TestCase):
    INSTANCE_NAME = helpers.gen_random_resource_name('instance',
                                                     timestamp=False)

    @property
    def instances_page(self):
        return self.home_pg.go_to_project_compute_instancespage()

    @property
    def instance_table_name_column(self):
        return 'Instance Name'

    def test_create_delete_instance(self):
        """tests the instance creation and deletion functionality:

        * creates a new instance in Project > Compute > Instances page
        * verifies the instance appears in the instances table as active
        * deletes the newly created instance via proper page (depends on user)
        * verifies the instance does not appear in the table after deletion
        """
        instances_page = self.home_pg.go_to_project_compute_instancespage()

        instances_page.create_instance(self.INSTANCE_NAME)
        self.assertTrue(instances_page.find_message_and_dismiss(messages.INFO))
        self.assertFalse(
            instances_page.find_message_and_dismiss(messages.ERROR))
        self.assertTrue(instances_page.is_instance_active(self.INSTANCE_NAME))

        instances_page = self.instances_page
        instances_page.delete_instance(self.INSTANCE_NAME)
        self.assertTrue(instances_page.find_message_and_dismiss(messages.INFO))
        self.assertFalse(
            instances_page.find_message_and_dismiss(messages.ERROR))
        self.assertTrue(instances_page.is_instance_deleted(self.INSTANCE_NAME))

    def test_instances_pagination(self):
        """This test checks instance pagination

        Steps:
        1) Login to Horizon Dashboard as regular user
        2) Navigate to user settings page
        3) Change 'Items Per Page' value to 1
        4) Go to Project > Compute > Instances page
        5) Create 2 instances
        6) Go to appropriate page (depends on user)
        7) Check that only 'Next' link is available, only one instance is
           available (and it has correct name) on the first page
        8) Click 'Next' and check that on the second page only one instance is
           available (and it has correct name), there is no 'Next' link on page
        9) Go to user settings page and restore 'Items Per Page'
        10) Delete created instances via proper page (depends on user)
        """
        items_per_page = 1
        instance_count = 2
        instance_list = ["{0}-{1}".format(self.INSTANCE_NAME, item)
                         for item in range(1, instance_count + 1)]
        first_page_definition = {'Next': True, 'Prev': False,
                                 'Count': items_per_page,
                                 'Names': [instance_list[1]]}
        second_page_definition = {'Next': False, 'Prev': True,
                                  'Count': items_per_page,
                                  'Names': [instance_list[0]]}
        settings_page = self.home_pg.go_to_settings_usersettingspage()
        settings_page.change_pagesize(items_per_page)
        self.assertTrue(
            settings_page.find_message_and_dismiss(messages.SUCCESS))

        instances_page = self.home_pg.go_to_project_compute_instancespage()
        instances_page.create_instance(self.INSTANCE_NAME,
                                       instance_count=instance_count)
        self.assertTrue(
            instances_page.find_message_and_dismiss(messages.INFO))
        self.assertTrue(instances_page.is_instance_active(instance_list[1]))

        instances_page = self.instances_page
        instances_page.instances_table.assert_definition(
            first_page_definition, sorting=True, name_column="Instance Name")

        instances_page.instances_table.turn_next_page()
        instances_page.instances_table.assert_definition(
            second_page_definition, sorting=True, name_column="Instance Name")

        instances_page = self.instances_page
        instances_page.instances_table.assert_definition(
            first_page_definition, sorting=True, name_column="Instance Name")

        settings_page = self.home_pg.go_to_settings_usersettingspage()
        settings_page.change_pagesize()
        self.assertTrue(
            settings_page.find_message_and_dismiss(messages.SUCCESS))

        instances_page = self.instances_page
        instances_page.delete_instances(instance_list)
        self.assertTrue(
            instances_page.find_message_and_dismiss(messages.INFO))
        self.assertTrue(instances_page.are_instances_deleted(instance_list))

    def test_instances_pagination_and_filtration(self):
        """This test checks instance pagination and filtration

        Steps:
        1) Login to Horizon Dashboard as regular user
        2) Go to to user settings page
        3) Change 'Items Per Page' value to 1
        4) Go to Project > Compute > Instances page
        5) Create 2 instances
        6) Go to appropriate page (depends on user)
        7) Check filter by Name of the first and the second instance in order
           to have one instance in the list (and it should have correct name)
           and no 'Next' link is available
        8) Check filter by common part of Name of in order to have one instance
           in the list (and it should have correct name) and 'Next' link is
           available on the first page and is not available on the second page
        9) Go to user settings page and restore 'Items Per Page'
        10) Delete created instances via proper page (depends on user)

        """
        items_per_page = 1
        instance_count = 2
        instance_list = ["{0}-{1}".format(self.INSTANCE_NAME, item)
                         for item in range(1, instance_count + 1)]
        first_page_definition = {'Next': True, 'Prev': False,
                                 'Count': items_per_page,
                                 'Names': [instance_list[1]]}
        second_page_definition = {'Next': False, 'Prev': False,
                                  'Count': items_per_page,
                                  'Names': [instance_list[0]]}
        filter_first_page_definition = {'Next': False, 'Prev': False,
                                        'Count': items_per_page,
                                        'Names': [instance_list[1]]}

        settings_page = self.home_pg.go_to_settings_usersettingspage()
        settings_page.change_pagesize(items_per_page)
        self.assertTrue(
            settings_page.find_message_and_dismiss(messages.SUCCESS))

        instances_page = self.home_pg.go_to_project_compute_instancespage()
        instances_page.create_instance(self.INSTANCE_NAME,
                                       instance_count=instance_count)
        self.assertTrue(
            instances_page.find_message_and_dismiss(messages.INFO))
        self.assertTrue(instances_page.is_instance_active(instance_list[1]))

        instances_page = self.instances_page
        instances_page.instances_table.set_filter_value('name')
        instances_page.instances_table.filter(instance_list[1])
        instances_page.instances_table.assert_definition(
            filter_first_page_definition, sorting=True,
            name_column="Instance Name")

        instances_page.instances_table.filter(instance_list[0])
        instances_page.instances_table.assert_definition(
            second_page_definition, sorting=True,
            name_column="Instance Name")

        instances_page.instances_table.filter(self.INSTANCE_NAME)
        instances_page.instances_table.assert_definition(
            first_page_definition, sorting=True,
            name_column="Instance Name")
        instances_page.instances_table.filter('')

        settings_page = self.home_pg.go_to_settings_usersettingspage()
        settings_page.change_pagesize()
        self.assertTrue(
            settings_page.find_message_and_dismiss(messages.SUCCESS))

        instances_page = self.instances_page
        instances_page.delete_instances(instance_list)
        self.assertTrue(
            instances_page.find_message_and_dismiss(messages.INFO))
        self.assertTrue(instances_page.are_instances_deleted(instance_list))

    def test_filter_instances(self):
        """This test checks filtering of instances by Instance Name

        Steps:
        1) Login to Horizon dashboard as regular user
        2) Go to Project > Compute > Instances
        3) Create 2 instances
        4) Go to appropriate page (depends on user)
        5) Use filter by Instance Name
        6) Check that filtered table has one instance only (which name is equal
           to filter value) and no other instances in the table
        7) Check that filtered table has both instances (search by common part
           of instance names)
        8) Set nonexistent instance name. Check that 0 rows are displayed
        9) Clear filter and delete instances via proper page (depends on user)
        """
        instance_count = 2
        instance_list = ["{0}-{1}".format(self.INSTANCE_NAME, item)
                         for item in range(1, instance_count + 1)]

        instances_page = self.home_pg.go_to_project_compute_instancespage()
        instances_page.create_instance(self.INSTANCE_NAME,
                                       instance_count=instance_count)
        self.assertTrue(
            instances_page.find_message_and_dismiss(messages.INFO))
        self.assertTrue(instances_page.is_instance_active(instance_list[0]))

        instances_page = self.instances_page
        instances_page.instances_table.set_filter_value('name')

        instances_page.instances_table.filter(instance_list[0])
        self.assertTrue(instances_page.is_instance_present(instance_list[0]))
        for instance in instance_list[1:]:
            self.assertFalse(instances_page.is_instance_present(instance))

        instances_page.instances_table.filter(self.INSTANCE_NAME)
        for instance in instance_list:
            self.assertTrue(instances_page.is_instance_present(instance))

        nonexistent_instance_name = "{0}_test".format(self.INSTANCE_NAME)
        instances_page.instances_table.filter(nonexistent_instance_name)
        self.assertEqual(instances_page.instances_table.rows, [])
        instances_page.instances_table.filter('')

        instances_page.delete_instances(instance_list)
        self.assertTrue(
            instances_page.find_message_and_dismiss(messages.INFO))
        self.assertTrue(instances_page.are_instances_deleted(instance_list))


class TestAdminInstances(helpers.AdminTestCase, TestInstances):
    INSTANCE_NAME = helpers.gen_random_resource_name('instance',
                                                     timestamp=False)

    @property
    def instances_page(self):
        self.home_pg.go_to_admin_overviewpage()
        return self.home_pg.go_to_admin_compute_instancespage()

    @property
    def instance_table_name_column(self):
        return 'Name'

    def test_instances_pagination(self):
        """This test checks instance pagination

        Steps:
        1) Login to Horizon Dashboard as admin
        2) Navigate to user settings page
        3) Change 'Items Per Page' value to 1
        4) Go to Project > Compute > Instances page
        5) Create 2 instances
        6) Go to Admin > Compute > Instances page
        7) Check that only 'Next' link is available, only one instance is
           available (and it has correct name) on the first page
        8) Click 'Next' and check that on the second page only one instance is
           available (and it has correct name), there is no 'Next' link on page
        9) Go to user settings page and restore 'Items Per Page'
        10) Delete created instances via proper page
        """
        items_per_page = 1
        instance_count = 2
        instance_list = ["{0}-{1}".format(self.INSTANCE_NAME, item)
                         for item in range(1, instance_count + 1)]
        first_page_definition = {'Next': True, 'Prev': False,
                                 'Count': items_per_page,
                                 'Names': [instance_list[1]]}
        second_page_definition = {'Next': False, 'Prev': True,
                                  'Count': items_per_page,
                                  'Names': [instance_list[0]]}
        settings_page = self.home_pg.go_to_settings_usersettingspage()
        settings_page.change_pagesize(items_per_page)
        self.assertTrue(
            settings_page.find_message_and_dismiss(messages.SUCCESS))

        instances_page = self.home_pg.go_to_project_compute_instancespage()
        instances_page.create_instance(self.INSTANCE_NAME,
                                       instance_count=instance_count)
        self.assertTrue(
            instances_page.find_message_and_dismiss(messages.INFO))
        self.assertTrue(instances_page.is_instance_active(instance_list[1]))

        instances_page = self.instances_page
        instances_page.instances_table.assert_definition(
            first_page_definition, sorting=True)

        instances_page.instances_table.turn_next_page()
        instances_page.instances_table.assert_definition(
            second_page_definition, sorting=True)

        instances_page = self.instances_page
        instances_page.instances_table.assert_definition(
            first_page_definition, sorting=True)

        settings_page = self.home_pg.go_to_settings_usersettingspage()
        settings_page.change_pagesize()
        self.assertTrue(
            settings_page.find_message_and_dismiss(messages.SUCCESS))

        instances_page = self.instances_page
        instances_page.delete_instances(instance_list)
        self.assertTrue(
            instances_page.find_message_and_dismiss(messages.INFO))
        self.assertTrue(instances_page.are_instances_deleted(instance_list))

    def test_instances_pagination_and_filtration(self):
        """This test checks instance pagination and filtration

        Steps:
        1) Login to Horizon Dashboard as admin
        2) Go to to user settings page
        3) Change 'Items Per Page' value to 1
        4) Go to Project > Compute > Instances page
        5) Create 2 instances
        6) Go to Admin > Compute > Instances page
        7) Check filter by Name of the first and the second instance in order
           to have one instance in the list (and it should have correct name)
           and no 'Next' link is available
        8) Check filter by common part of Name of in order to have one instance
           in the list (and it should have correct name) and 'Next' link is
           available on the first page and is not available on the second page
        9) Go to user settings page and restore 'Items Per Page'
        10) Delete created instances via proper page

        """
        items_per_page = 1
        instance_count = 2
        instance_list = ["{0}-{1}".format(self.INSTANCE_NAME, item)
                         for item in range(1, instance_count + 1)]
        first_page_definition = {'Next': True, 'Prev': False,
                                 'Count': items_per_page,
                                 'Names': [instance_list[1]]}
        second_page_definition = {'Next': False, 'Prev': False,
                                  'Count': items_per_page,
                                  'Names': [instance_list[0]]}
        filter_first_page_definition = {'Next': False, 'Prev': False,
                                        'Count': items_per_page,
                                        'Names': [instance_list[1]]}

        settings_page = self.home_pg.go_to_settings_usersettingspage()
        settings_page.change_pagesize(items_per_page)
        self.assertTrue(
            settings_page.find_message_and_dismiss(messages.SUCCESS))

        instances_page = self.home_pg.go_to_project_compute_instancespage()
        instances_page.create_instance(self.INSTANCE_NAME,
                                       instance_count=instance_count)
        self.assertTrue(
            instances_page.find_message_and_dismiss(messages.INFO))
        self.assertTrue(instances_page.is_instance_active(instance_list[1]))

        instances_page = self.instances_page
        instances_page.instances_table.set_filter_value('name')
        instances_page.instances_table.filter(instance_list[1])
        instances_page.instances_table.assert_definition(
            filter_first_page_definition, sorting=True)

        instances_page.instances_table.filter(instance_list[0])
        instances_page.instances_table.assert_definition(
            second_page_definition, sorting=True)

        instances_page.instances_table.filter(self.INSTANCE_NAME)
        instances_page.instances_table.assert_definition(
            first_page_definition, sorting=True)
        instances_page.instances_table.filter('')

        settings_page = self.home_pg.go_to_settings_usersettingspage()
        settings_page.change_pagesize()
        self.assertTrue(
            settings_page.find_message_and_dismiss(messages.SUCCESS))

        instances_page = self.instances_page
        instances_page.delete_instances(instance_list)
        self.assertTrue(
            instances_page.find_message_and_dismiss(messages.INFO))
        self.assertTrue(instances_page.are_instances_deleted(instance_list))