summaryrefslogtreecommitdiff
path: root/openstack_dashboard/test/integration_tests/tests/test_images.py
blob: 8065eaa9212213169a2cc238aeec4cf51680e302 (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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#    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.
import pytest

from openstack_dashboard.test.integration_tests import helpers
from openstack_dashboard.test.integration_tests.regions import messages

from openstack_dashboard.test.integration_tests.pages.project.\
    compute.instancespage import InstancesPage
from openstack_dashboard.test.integration_tests.pages.project.\
    volumes.volumespage import VolumesPage


class TestImagesBasicAngular(helpers.TestCase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.IMAGE_NAME = helpers.gen_random_resource_name("image")

    @property
    def images_page(self):
        return self.home_pg.go_to_project_compute_imagespage()

    def test_basic_image_browse(self):
        images_page = self.images_page
        self.assertEqual(images_page.header.text, 'Images')

    def image_create(self, local_file=None, **kwargs):
        images_page = self.images_page
        if local_file:
            images_page.create_image(self.IMAGE_NAME,
                                     image_file=local_file,
                                     **kwargs)
        else:
            images_page.create_image(self.IMAGE_NAME,
                                     image_source_type='url',
                                     **kwargs)
        self.assertTrue(images_page.find_message_and_dismiss(messages.SUCCESS))
        self.assertFalse(images_page.find_message_and_dismiss(messages.ERROR))
        self.assertTrue(images_page.is_image_present(self.IMAGE_NAME))
        self.assertTrue(images_page.is_image_active(self.IMAGE_NAME))
        return images_page

    def image_delete(self, image_name):
        images_page = self.images_page
        images_page.delete_image(image_name)
        self.assertTrue(images_page.find_message_and_dismiss(messages.SUCCESS))
        self.assertFalse(images_page.find_message_and_dismiss(messages.ERROR))
        self.assertFalse(images_page.is_image_present(self.IMAGE_NAME))

    def test_image_create_delete_from_local_file(self):
        """tests the image creation and deletion functionalities:

        * creates a new image from a generated file
        * verifies the image appears in the images table as active
        * deletes the newly created image
        * verifies the image does not appear in the table after deletion
        """
        with helpers.gen_temporary_file() as file_name:
            self.image_create(local_file=file_name)
            self.image_delete(self.IMAGE_NAME)

    # Run when Glance configuration and policies allow setting locations.
    @pytest.mark.skip(reason="IMAGES_ALLOW_LOCATION = False")
    def test_image_create_delete_from_url(self):
        """tests the image creation and deletion functionalities:

        * creates a new image from horizon.conf http_image
        * verifies the image appears in the images table as active
        * deletes the newly created image
        * verifies the image does not appear in the table after deletion
        """
        self.image_create()
        self.image_delete(self.IMAGE_NAME)

    def test_images_pagination(self):
        """This test checks images pagination

        Steps:
        1) Login to Horizon Dashboard as horizon user
        2) Navigate to user settings page
        3) Change 'Items Per Page' value to 1
        4) Go to Project -> Compute -> Images page
        5) Check that only 'Next' link is available, only one image is
           available (and it has correct name)
        6) Click 'Next' and check that both 'Prev' and 'Next' links are
           available, only one image is available (and it has correct name)
        7) Click 'Next' and check that only 'Prev' link is available,
           only one image is visible (and it has correct name)
        8) Click 'Prev' and check results (should be the same as for step6)
        9) Click 'Prev' and check results (should be the same as for step5)
        10) Go to user settings page and restore 'Items Per Page'
        """

        default_image_list = self.CONFIG.image.images_list

        images_page = self.images_page

        # delete any old images except default ones
        images_page.wait_until_image_present(default_image_list[0])
        image_list = images_page.images_table.get_column_data(
            name_column='Name')
        garbage = [i for i in image_list if i not in default_image_list]
        if garbage:
            images_page.delete_images(garbage)
            self.assertTrue(
                images_page.find_message_and_dismiss(messages.SUCCESS))

        items_per_page = 1
        images_count = 2
        images_names = ["{0}_{1}".format(self.IMAGE_NAME, item)
                        for item in range(images_count)]
        for image_name in images_names:
            with helpers.gen_temporary_file() as file_name:
                images_page.create_image(image_name, image_file=file_name)
            self.assertTrue(
                images_page.find_message_and_dismiss(messages.SUCCESS))
            self.assertFalse(
                images_page.find_message_and_dismiss(messages.ERROR))
            self.assertTrue(images_page.is_image_present(image_name))

        first_page_definition = {'Next': True, 'Prev': False,
                                 'Count': items_per_page,
                                 'Names': [default_image_list[0]]}
        second_page_definition = {'Next': True, 'Prev': True,
                                  'Count': items_per_page,
                                  'Names': [images_names[0]]}
        third_page_definition = {'Next': False, 'Prev': True,
                                 'Count': items_per_page,
                                 'Names': [images_names[1]]}

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

        images_page = self.images_page
        if not images_page.is_image_present(default_image_list[0]):
            images_page.wait_until_image_present(default_image_list[0])
        images_page.images_table.assert_definition(first_page_definition)

        images_page.images_table.turn_next_page()
        images_page.images_table.assert_definition(second_page_definition)

        images_page.images_table.turn_next_page()
        images_page.images_table.assert_definition(third_page_definition)

        images_page.images_table.turn_prev_page()
        images_page.images_table.assert_definition(second_page_definition)

        images_page.images_table.turn_prev_page()
        images_page.images_table.assert_definition(first_page_definition)

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

        images_page = self.images_page
        images_page.wait_until_image_present(default_image_list[0])
        images_page.delete_images(images_names)
        self.assertTrue(images_page.find_message_and_dismiss(messages.SUCCESS))
        self.assertFalse(images_page.find_message_and_dismiss(messages.ERROR))


class TestImagesAdminAngular(helpers.AdminTestCase, TestImagesBasicAngular):
    """Login as admin user"""

    @property
    def images_page(self):
        return self.home_pg.go_to_admin_compute_imagespage()

    def test_update_image_metadata(self):
        """Test update image metadata

        * logs in as admin user
        * creates image from locally downloaded file
        * verifies the image appears in the images table as active
        * invokes action 'Update Metadata' for the image
        * adds custom filed 'metadata'
        * adds value 'image' for the custom filed 'metadata'
        * gets the actual description of the image
        * verifies that custom filed is present in the image description
        * deletes the image
        * verifies the image does not appear in the table after deletion
        """
        new_metadata = {'metadata1': helpers.gen_random_resource_name("value"),
                        'metadata2': helpers.gen_random_resource_name("value")}

        with helpers.gen_temporary_file() as file_name:
            images_page = self.image_create(local_file=file_name,
                                            description='test description')
            images_page.add_custom_metadata(self.IMAGE_NAME, new_metadata)
            results = images_page.check_image_details(self.IMAGE_NAME,
                                                      new_metadata)
            self.image_delete(self.IMAGE_NAME)
            self.assertSequenceTrue(results)

    def test_remove_protected_image(self):
        """tests that protected image is not deletable

        * logs in as admin user
        * creates image from locally downloaded file
        * verifies the image appears in the images table as active
        * marks 'Protected' checkbox
        * verifies that edit action was successful
        * verifies that delete action is not available in the list
        * tries to delete the image
        * verifies that exception is generated for the protected image
        * unmarks 'Protected' checkbox
        * deletes the image
        * verifies the image does not appear in the table after deletion
        """
        with helpers.gen_temporary_file() as file_name:
            images_page = self.image_create(local_file=file_name)
            images_page.edit_image(self.IMAGE_NAME, protected=True)
            self.assertTrue(
                images_page.find_message_and_dismiss(messages.SUCCESS))

            # Check that Delete action is not available in the action list.
            # The below action will generate exception since the bind fails.
            # But only ValueError with message below is expected here.
            message = "Could not bind method 'delete_image_via_row_action' " \
                      "to action control 'Delete Image'"
            with self.assertRaisesRegex(ValueError, message):
                images_page.delete_image_via_row_action(self.IMAGE_NAME)

            # Edit image to make it not protected again and delete it.
            images_page = self.images_page

            images_page.edit_image(self.IMAGE_NAME, protected=False)
            self.assertTrue(
                images_page.find_message_and_dismiss(messages.SUCCESS))
            self.assertFalse(
                images_page.find_message_and_dismiss(messages.ERROR))

            self.image_delete(self.IMAGE_NAME)
            self.assertFalse(
                images_page.find_message_and_dismiss(messages.ERROR))
            self.assertFalse(images_page.is_image_present(self.IMAGE_NAME))

    def test_edit_image_description_and_name(self):
        """tests that image description is editable

        * creates image from locally downloaded file
        * verifies the image appears in the images table as active
        * toggle edit action and adds some description
        * verifies that edit action was successful
        * verifies that new description is seen on image details page
        * toggle edit action and changes image name
        * verifies that edit action was successful
        * verifies that image with new name is seen on the page
        * deletes the image
        * verifies the image does not appear in the table after deletion
        """
        new_description_text = helpers.gen_random_resource_name("description")
        new_image_name = helpers.gen_random_resource_name("image")
        with helpers.gen_temporary_file() as file_name:
            images_page = self.image_create(local_file=file_name)
            images_page.edit_image(self.IMAGE_NAME,
                                   description=new_description_text)
            self.assertTrue(
                images_page.find_message_and_dismiss(messages.SUCCESS))
            self.assertFalse(
                images_page.find_message_and_dismiss(messages.ERROR))

            results = images_page.check_image_details(self.IMAGE_NAME,
                                                      {'Description':
                                                       new_description_text})
            self.assertSequenceTrue(results)

            # Just go back to the images page and toggle edit again
            images_page = self.images_page
            images_page.edit_image(self.IMAGE_NAME,
                                   new_name=new_image_name)
            self.assertTrue(
                images_page.find_message_and_dismiss(messages.SUCCESS))
            self.assertFalse(
                images_page.find_message_and_dismiss(messages.ERROR))

            results = images_page.check_image_details(new_image_name,
                                                      {'Name':
                                                       new_image_name})
            self.assertSequenceTrue(results)

            self.image_delete(new_image_name)
            self.assertFalse(
                images_page.find_message_and_dismiss(messages.ERROR))
            self.assertFalse(images_page.is_image_present(self.IMAGE_NAME))

    def test_filter_images(self):
        """This test checks filtering of images

        Steps:
        1) Login to Horizon dashboard as admin user
        2) Go to Admin -> Compute -> Images
        3) Use filter by Image Name
        4) Check that filtered table has one image only (which name is
           equal to filter value)
        5) Check that no other images in the table
        6) Clear filter and set nonexistent image name. Check that 0 rows
           are displayed
        """
        default_image_list = self.CONFIG.image.images_list
        images_page = self.images_page

        images_page.filter(default_image_list[0])
        self.assertTrue(images_page.is_image_present(default_image_list[0]))
        for image in default_image_list[1:]:
            self.assertFalse(images_page.is_image_present(image))

        images_page = self.images_page
        nonexistent_image_name = "{0}_test".format(self.IMAGE_NAME)
        images_page.filter(nonexistent_image_name)
        self.assertEqual(images_page.images_table.rows, [])

        images_page.filter('')


class TestImagesAdvancedAngular(helpers.TestCase):

    @property
    def images_page(self):
        return self.home_pg.go_to_project_compute_imagespage()

    def volumes_page(self):
        self.home_pg.go_to_project_volumes_volumespage()
        return VolumesPage(self.driver, self.CONFIG)

    def instances_page(self):
        self.home_pg.go_to_project_compute_instancespage()
        return InstancesPage(self.driver, self.CONFIG)

    """Login as demo user"""
    def test_create_volume_from_image(self):
        """This test case checks create volume from image functionality:

        Steps:
        1. Login to Horizon Dashboard as regular user
        2. Navigate to Project -> Compute -> Images
        3. Create new volume from image
        4. Check that volume is created with expected name
        5. Check that volume status is Available
        """
        images_page = self.images_page
        source_image = self.CONFIG.image.images_list[0]
        target_volume = "created_from_{0}".format(source_image)

        images_page.create_volume_from_image(
            source_image, volume_name=target_volume)
        self.assertTrue(
            images_page.find_message_and_dismiss(messages.INFO))
        self.assertFalse(
            images_page.find_message_and_dismiss(messages.ERROR))

        volumes_page = self.volumes_page()

        self.assertTrue(volumes_page.is_volume_present(target_volume))
        self.assertTrue(volumes_page.is_volume_status(target_volume,
                                                      'Available'))
        volumes_page.delete_volume(target_volume)
        volumes_page.find_message_and_dismiss(messages.SUCCESS)
        volumes_page.find_message_and_dismiss(messages.ERROR)

        volumes_page = self.volumes_page()
        self.assertTrue(volumes_page.is_volume_deleted(target_volume))

    def test_launch_instance_from_image(self):
        """This test case checks launch instance from image functionality:

        Steps:
        1. Login to Horizon Dashboard as regular user
        2. Navigate to Project -> Compute -> Images
        3. Launch new instance from image
        4. Check that instance is create
        5. Check that status of newly created instance is Active
        6. Check that image_name in correct in instances table
        """
        images_page = self.images_page
        source_image = self.CONFIG.image.images_list[0]
        target_instance = "created_from_{0}".format(source_image)

        images_page.launch_instance_from_image(source_image, target_instance)
        self.assertTrue(
            images_page.find_message_and_dismiss(messages.INFO))
        self.assertFalse(
            images_page.find_message_and_dismiss(messages.ERROR))

        instances_page = self.instances_page()
        self.assertTrue(instances_page.is_instance_active(target_instance))
        instances_page = self.instances_page()
        actual_image_name = instances_page.get_image_name(target_instance)
        self.assertEqual(source_image, actual_image_name)

        instances_page.delete_instance(target_instance)
        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(target_instance))