blob: cb4e52cf96b064c329e828d770931538f7552372 [file] [log] [blame]
Brianna Poulos011292a2017-03-15 16:24:38 -04001# Copyright 2012 OpenStack Foundation
2# Copyright 2013 IBM Corp.
3# All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17from oslo_log import log
18
Brianna Poulos011292a2017-03-15 16:24:38 -040019from tempest.common import waiters
20from tempest import config
21from tempest.lib.common.utils import data_utils
Brianna Poulos011292a2017-03-15 16:24:38 -040022from tempest.lib import exceptions as lib_exc
Ihar Hrachyshkaecce1f62018-01-18 13:32:05 -080023from tempest.scenario import manager
Brianna Poulos011292a2017-03-15 16:24:38 -040024
25CONF = config.CONF
26
27LOG = log.getLogger(__name__)
28
29
Ihar Hrachyshka2d0cf0a2018-01-18 13:40:09 -080030# we inherit from NetworkScenarioTest since some test cases need access to
31# check_*_connectivity methods to validate instances are up and accessible
32class ScenarioTest(manager.NetworkScenarioTest):
Brianna Poulos011292a2017-03-15 16:24:38 -040033 """Base class for scenario tests. Uses tempest own clients. """
Brianna Poulos011292a2017-03-15 16:24:38 -040034 # ## Test functions library
35 #
36 # The create_[resource] functions only return body and discard the
37 # resp part which is not used in scenario tests
Brianna Poulos011292a2017-03-15 16:24:38 -040038
Brianna Poulos011292a2017-03-15 16:24:38 -040039 def _image_create(self, name, fmt, path,
40 disk_format=None, properties=None):
41 if properties is None:
42 properties = {}
43 name = data_utils.rand_name('%s-' % name)
44 params = {
45 'name': name,
46 'container_format': fmt,
47 'disk_format': disk_format or fmt,
Ghanshyam Manne5ed4b92023-08-06 12:03:34 -070048 'visibility': 'private'
Brianna Poulos011292a2017-03-15 16:24:38 -040049 }
Ghanshyam Manne5ed4b92023-08-06 12:03:34 -070050 # Additional properties are flattened out in the v2 API.
51 params.update(properties)
Brianna Poulos011292a2017-03-15 16:24:38 -040052 body = self.image_client.create_image(**params)
53 image = body['image'] if 'image' in body else body
54 self.addCleanup(self.image_client.delete_image, image['id'])
55 self.assertEqual("queued", image['status'])
56 with open(path, 'rb') as image_file:
Ghanshyam Manne5ed4b92023-08-06 12:03:34 -070057 self.image_client.store_image_file(image['id'], image_file)
Marian Krcmarik1972c462020-11-20 01:33:02 +010058
59 if CONF.image_feature_enabled.import_image:
60 available_stores = []
61 try:
62 available_stores = self.image_client.info_stores()['stores']
Luigi Toscano4e9303e2022-06-24 11:37:34 +020063 except lib_exc.NotFound:
Marian Krcmarik1972c462020-11-20 01:33:02 +010064 pass
65 available_import_methods = self.image_client.info_import()[
66 'import-methods']['value']
67 if ('copy-image' in available_import_methods and
68 len(available_stores) > 1):
69 self.image_client.image_import(image['id'],
70 method='copy-image',
71 all_stores=True,
72 all_stores_must_succeed=False)
73 failed_stores = waiters.wait_for_image_copied_to_stores(
74 self.image_client, image['id'])
75 self.assertEqual(0, len(failed_stores),
76 "Failed to copy the following stores: %s" %
77 str(failed_stores))
78
Brianna Poulos011292a2017-03-15 16:24:38 -040079 return image['id']