From 7896ec482c9cd51e481c93480cfd0d18fe9a2f00 Mon Sep 17 00:00:00 2001 From: Eduardo Olivares Date: Fri, 19 Jun 2020 13:46:18 +0200 Subject: [PATCH] Add RedHat 8.2 server instance Change-Id: I6753b7cdccb45699f43ab246d7c849001158c643 Co-Authored-By: Eduardo Olivares --- tobiko/common/_fixture.py | 35 +++++++---- tobiko/openstack/glance/config.py | 1 + tobiko/openstack/stacks/__init__.py | 5 ++ tobiko/openstack/stacks/_nova.py | 2 +- tobiko/openstack/stacks/_redhat.py | 59 +++++++++++++++++++ .../openstack/stacks/test_centos.py | 2 +- .../openstack/stacks/test_red_hat.py | 29 +++++++++ 7 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 tobiko/openstack/stacks/_redhat.py create mode 100644 tobiko/tests/functional/openstack/stacks/test_red_hat.py diff --git a/tobiko/common/_fixture.py b/tobiko/common/_fixture.py index 3701f893a..6a874ea79 100644 --- a/tobiko/common/_fixture.py +++ b/tobiko/common/_fixture.py @@ -16,6 +16,7 @@ from __future__ import absolute_import import json import os import inspect +import sys import fixtures from oslo_log import log @@ -97,12 +98,25 @@ def remove_fixture(obj, fixture_id=None, manager=None): return manager.remove_fixture(obj, fixture_id=fixture_id) -def setup_fixture(obj, fixture_id=None, manager=None): +def setup_fixture(obj, fixture_id=None, manager=None, alternative=None): '''Get registered fixture and setup it up''' - fixture = get_fixture(obj, fixture_id=fixture_id, manager=manager) + if alternative is None: + objs = [obj] + else: + objs = [obj, alternative] with _exception.handle_multiple_exceptions( handle_exception=handle_setup_error): - fixture.setUp() + errors = [] + for _obj in objs: + fixture = get_fixture(_obj, fixture_id=fixture_id, manager=manager) + try: + fixture.setUp() + break + except testtools.MultipleExceptions: + errors.append(sys.exc_info()) + else: + raise testtools.MultipleExceptions(*errors) + return fixture @@ -260,18 +274,18 @@ def fixture_property(*args, **kwargs): return FixtureProperty(*args, **kwargs) -def required_fixture(obj): +def required_fixture(obj, **params): '''Creates a property that gets fixture identified by given :param obj: ''' - return RequiredFixtureProperty(obj) + return RequiredFixtureProperty(obj, **params) -def required_setup_fixture(obj): +def required_setup_fixture(obj, **params): '''Creates a property that sets up fixture identified by given :param obj: ''' - return RequiredSetupFixtureProperty(obj) + return RequiredSetupFixtureProperty(obj, **params) def get_object_name(obj): @@ -430,8 +444,9 @@ class FixtureProperty(property): class RequiredFixtureProperty(object): - def __init__(self, fixture): + def __init__(self, fixture, **params): self.fixture = fixture + self.fixture_params = params def __get__(self, instance, _): if instance is None: @@ -440,7 +455,7 @@ class RequiredFixtureProperty(object): return self.get_fixture(instance) def get_fixture(self, _instance): - return get_fixture(self.fixture) + return get_fixture(self.fixture, **self.fixture_params) @property def __tobiko_required_fixtures__(self): @@ -450,7 +465,7 @@ class RequiredFixtureProperty(object): class RequiredSetupFixtureProperty(RequiredFixtureProperty): def get_fixture(self, _instance): - fixture = setup_fixture(self.fixture) + fixture = setup_fixture(self.fixture, **self.fixture_params) if (hasattr(_instance, 'addCleanup') and hasattr(_instance, 'getDetails')): _instance.addCleanup(_detail.gather_details, diff --git a/tobiko/openstack/glance/config.py b/tobiko/openstack/glance/config.py index 272c07d0e..2fc9f1c5e 100644 --- a/tobiko/openstack/glance/config.py +++ b/tobiko/openstack/glance/config.py @@ -29,6 +29,7 @@ OPTIONS = [ GLANCE_IMAGE_NAMES = ['centos', 'cirros', + 'rhel', 'ubuntu'] diff --git a/tobiko/openstack/stacks/__init__.py b/tobiko/openstack/stacks/__init__.py index bd4a47984..90baf2720 100644 --- a/tobiko/openstack/stacks/__init__.py +++ b/tobiko/openstack/stacks/__init__.py @@ -17,6 +17,7 @@ from __future__ import absolute_import from tobiko.openstack.stacks import _centos from tobiko.openstack.stacks import _cirros +from tobiko.openstack.stacks import _redhat from tobiko.openstack.stacks import _l3ha from tobiko.openstack.stacks import _neutron from tobiko.openstack.stacks import _nova @@ -39,6 +40,10 @@ RebootCirrosServerOperation = _cirros.RebootCirrosServerOperation EvacuableCirrosImageFixture = _cirros.EvacuableCirrosImageFixture EvacuableServerStackFixture = _cirros.EvacuableServerStackFixture +RedHatFlavorStackFixture = _redhat.RedHatFlavorStackFixture +RhelImageFixture = _redhat.RhelImageFixture +RedHatServerStackFixture = _redhat.RedHatServerStackFixture + L3haNetworkStackFixture = _l3ha.L3haNetworkStackFixture L3haServerStackFixture = _l3ha.L3haServerStackFixture L3haUbuntuServerStackFixture = _l3ha.L3haUbuntuServerStackFixture diff --git a/tobiko/openstack/stacks/_nova.py b/tobiko/openstack/stacks/_nova.py index 772b449a7..9213612d0 100644 --- a/tobiko/openstack/stacks/_nova.py +++ b/tobiko/openstack/stacks/_nova.py @@ -70,7 +70,7 @@ class KeyPairStackFixture(heat.HeatStackFixture): class FlavorStackFixture(heat.HeatStackFixture): template = _hot.heat_template_file('nova/flavor.yaml') - disk = None + disk: typing.Optional[int] = None ephemeral = None extra_specs = None is_public = None diff --git a/tobiko/openstack/stacks/_redhat.py b/tobiko/openstack/stacks/_redhat.py new file mode 100644 index 000000000..c135f7917 --- /dev/null +++ b/tobiko/openstack/stacks/_redhat.py @@ -0,0 +1,59 @@ +# Copyright 2020 Red Hat +# +# 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 __future__ import absolute_import + +import tobiko +from tobiko import config +from tobiko.openstack import glance +from tobiko.openstack.stacks import _centos + + +CONF = config.CONF + +RHEL_IMAGE_MAJOR_VERSION = '8.2' +RHEL_IMAGE_MINOR_VERSION = '501' + +RHEL_IMAGE_URL = ('http://download.devel.redhat.com/brewroot/packages/' + f'rhel-guest-image/{RHEL_IMAGE_MAJOR_VERSION}/' + f'{RHEL_IMAGE_MINOR_VERSION}/images/' + f'rhel-guest-image-{RHEL_IMAGE_MAJOR_VERSION}-' + f'{RHEL_IMAGE_MINOR_VERSION}.x86_64.qcow2') + + +class RhelImageFixture(glance.URLGlanceImageFixture): + + image_url = CONF.tobiko.rhel.image_url or RHEL_IMAGE_URL + image_name = CONF.tobiko.rhel.image_name + image_file = CONF.tobiko.rhel.image_file + disk_format = CONF.tobiko.rhel.disk_format or "qcow2" + container_format = CONF.tobiko.rhel.container_format or "bare" + username = CONF.tobiko.rhel.username or 'cloud-user' + password = CONF.tobiko.rhel.password + connection_timeout = CONF.tobiko.rhel.connection_timeout + + +class RedHatFlavorStackFixture(_centos.CentosFlavorStackFixture): + pass + + +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) + + #: Flavor used to create a Nova server instance + flavor_stack = tobiko.required_setup_fixture(RedHatFlavorStackFixture) diff --git a/tobiko/tests/functional/openstack/stacks/test_centos.py b/tobiko/tests/functional/openstack/stacks/test_centos.py index b425e5edc..48fc9ff70 100644 --- a/tobiko/tests/functional/openstack/stacks/test_centos.py +++ b/tobiko/tests/functional/openstack/stacks/test_centos.py @@ -27,7 +27,7 @@ from tobiko.tests.functional.openstack.stacks import test_cirros @keystone.skip_unless_has_keystone_credentials() class CentosServerStackTest(test_cirros.CirrosServerStackTest): - """Tests connectivity to Nova instances via floating IPs""" + """Test CentOS server instance""" #: Stack of resources with a server attached to a floating IP stack = tobiko.required_setup_fixture(stacks.CentosServerStackFixture) diff --git a/tobiko/tests/functional/openstack/stacks/test_red_hat.py b/tobiko/tests/functional/openstack/stacks/test_red_hat.py new file mode 100644 index 000000000..7282a3352 --- /dev/null +++ b/tobiko/tests/functional/openstack/stacks/test_red_hat.py @@ -0,0 +1,29 @@ +# Copyright (c) 2020 Red Hat, Inc. +# +# All Rights Reserved. +# +# 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 __future__ import absolute_import + +import tobiko +from tobiko.openstack import keystone +from tobiko.openstack import stacks +from tobiko.tests.functional.openstack.stacks import test_centos + + +@keystone.skip_unless_has_keystone_credentials() +class RedHatServerStackTest(test_centos.CentosServerStackTest): + """Test Red Hat server instance""" + + #: Stack of resources with a server attached to a floating IP + stack = tobiko.required_setup_fixture(stacks.RedHatServerStackFixture)