Skip test cases unless RHEL image is available

Change-Id: I95825598871f1138c70d8f25548bf07343a73896
Depends-On: https://review.opendev.org/c/x/devstack-plugin-tobiko/+/805018
This commit is contained in:
Federico Ressi 2021-08-17 16:33:43 +02:00
parent 54a3bd1dcd
commit 4233ae5ddf
2 changed files with 38 additions and 3 deletions

View File

@ -353,6 +353,12 @@ class URLGlanceImageFixture(FileGlanceImageFixture):
def get_image_file(self, image_file: str):
http_request = requests.get(self.image_url, stream=True)
try:
http_request.raise_for_status()
except requests.exceptions.HTTPError:
LOG.exception("Error getting image file from URL: "
f"{self.image_url}")
raise
expected_size = int(http_request.headers.get('content-length', 0))
chunks = http_request.iter_content(chunk_size=io.DEFAULT_BUFFER_SIZE)
download_image = True

View File

@ -13,12 +13,17 @@
# under the License.
from __future__ import absolute_import
import functools
from oslo_log import log
import requests
import tobiko
from tobiko import config
from tobiko.openstack import glance
from tobiko.openstack.stacks import _centos
LOG = log.getLogger(__name__)
CONF = config.CONF
RHEL_IMAGE_MAJOR_VERSION = '8.4'
@ -31,6 +36,31 @@ RHEL_IMAGE_URL = ('http://download.devel.redhat.com/brewroot/packages/'
f'{RHEL_IMAGE_MINOR_VERSION}.x86_64.qcow2')
def skip_unless_has_rhel_image():
return tobiko.skip_unless('RHEL image not found',
has_rhel_image)
@functools.lru_cache()
def has_rhel_image() -> bool:
image_url = tobiko.get_fixture(RhelImageFixture).image_url
try:
response = requests.get(image_url, stream=True)
except requests.exceptions.ConnectionError as ex:
LOG.debug(f'RHEL image file not found at {image_url}: {ex}',
exc_info=1)
return False
if response.status_code == 404:
LOG.debug(f'RHEL image file not found at {image_url}')
return False
response.raise_for_status()
LOG.debug(f'RHEL image file found at {image_url}')
return True
@skip_unless_has_rhel_image()
class RhelImageFixture(glance.URLGlanceImageFixture):
image_url = CONF.tobiko.rhel.image_url or RHEL_IMAGE_URL
@ -52,8 +82,7 @@ class RedHatServerStackFixture(_centos.CentosServerStackFixture):
#: Glance image used to create a Nova server instance
# (alternative is given for cases the RHEL image is failed to be
# set up)
image_fixture = tobiko.required_setup_fixture(
RhelImageFixture, alternative=_centos.CentosImageFixture)
image_fixture = tobiko.required_setup_fixture(RhelImageFixture)
#: Flavor used to create a Nova server instance
flavor_stack = tobiko.required_setup_fixture(RedHatFlavorStackFixture)