From ff2d87ce5cea305d6d5724bf8dbcdf2b7a11713f Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Thu, 18 Jul 2019 14:55:42 +0200 Subject: [PATCH] Add CentOS image and flavor fixtures Change-Id: I3f1f86cb9b35c2be02703960e502140645a36da8 --- tobiko/openstack/glance/config.py | 6 +- tobiko/openstack/stacks/__init__.py | 5 ++ tobiko/openstack/stacks/_centos.py | 55 +++++++++++++++++++ tobiko/openstack/stacks/_cirros.py | 2 +- tobiko/openstack/stacks/_ubuntu.py | 3 +- tobiko/shell/sh/_process.py | 7 +++ .../openstack/stacks/test_centos.py | 34 ++++++++++++ 7 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 tobiko/openstack/stacks/_centos.py create mode 100644 tobiko/tests/functional/openstack/stacks/test_centos.py diff --git a/tobiko/openstack/glance/config.py b/tobiko/openstack/glance/config.py index d90420d48..043c9c79c 100644 --- a/tobiko/openstack/glance/config.py +++ b/tobiko/openstack/glance/config.py @@ -18,9 +18,6 @@ import itertools from oslo_config import cfg -CIRROS_IMAGE_URL = \ - 'http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img' - GROUP_NAME = 'glance' OPTIONS = [ cfg.StrOpt('image_dir', @@ -30,7 +27,8 @@ OPTIONS = [ ] -GLANCE_IMAGE_NAMES = ['cirros', +GLANCE_IMAGE_NAMES = ['centos', + 'cirros', 'ubuntu'] diff --git a/tobiko/openstack/stacks/__init__.py b/tobiko/openstack/stacks/__init__.py index 47d4ad1ef..ac243954a 100644 --- a/tobiko/openstack/stacks/__init__.py +++ b/tobiko/openstack/stacks/__init__.py @@ -15,12 +15,17 @@ # under the License. from __future__ import absolute_import +from tobiko.openstack.stacks import _centos from tobiko.openstack.stacks import _cirros from tobiko.openstack.stacks import _l3ha from tobiko.openstack.stacks import _neutron from tobiko.openstack.stacks import _nova from tobiko.openstack.stacks import _ubuntu +CentosFlavorStackFixture = _centos.CentosFlavorStackFixture +CentosImageFixture = _centos.CentosImageFixture +CentosServerStackFixture = _centos.CentosServerStackFixture + CirrosFlavorStackFixture = _cirros.CirrosFlavorStackFixture CirrosImageFixture = _cirros.CirrosImageFixture CirrosServerStackFixture = _cirros.CirrosServerStackFixture diff --git a/tobiko/openstack/stacks/_centos.py b/tobiko/openstack/stacks/_centos.py new file mode 100644 index 000000000..8855ed19d --- /dev/null +++ b/tobiko/openstack/stacks/_centos.py @@ -0,0 +1,55 @@ +# Copyright 2019 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 _nova + + +CONF = config.CONF + + +if glance.has_lzma(): + CENTOS_IMAGE_URL = ( + 'http://cloud.centos.org/centos/7/images/' + 'CentOS-7-x86_64-GenericCloud.qcow2.xz') +else: + CENTOS_IMAGE_URL = ( + 'http://cloud.centos.org/centos/7/images/' + 'CentOS-7-x86_64-GenericCloud.qcow2c') + + +class CentosImageFixture(glance.URLGlanceImageFixture): + image_url = CONF.tobiko.centos.image_url or CENTOS_IMAGE_URL + image_name = CONF.tobiko.centos.image_name + image_file = CONF.tobiko.centos.image_file + disk_format = CONF.tobiko.centos.disk_format or "qcow2" + container_format = CONF.tobiko.centos.container_format or "bare" + username = CONF.tobiko.centos.username or 'centos' + password = CONF.tobiko.centos.password + + +class CentosFlavorStackFixture(_nova.FlavorStackFixture): + ram = 512 + + +class CentosServerStackFixture(_nova.ServerStackFixture): + + #: Glance image used to create a Nova server instance + image_fixture = tobiko.required_setup_fixture(CentosImageFixture) + + #: Flavor used to create a Nova server instance + flavor_stack = tobiko.required_setup_fixture(CentosFlavorStackFixture) diff --git a/tobiko/openstack/stacks/_cirros.py b/tobiko/openstack/stacks/_cirros.py index 14c65a23f..d11ff5d56 100644 --- a/tobiko/openstack/stacks/_cirros.py +++ b/tobiko/openstack/stacks/_cirros.py @@ -45,7 +45,7 @@ class CirrosServerStackFixture(_nova.ServerStackFixture): #: Glance image used to create a Nova server instance image_fixture = tobiko.required_setup_fixture(CirrosImageFixture) - #: Glance image used to create a Nova server instance + #: Flavor used to create a Nova server instance flavor_stack = tobiko.required_setup_fixture(CirrosFlavorStackFixture) diff --git a/tobiko/openstack/stacks/_ubuntu.py b/tobiko/openstack/stacks/_ubuntu.py index a2f8c71f7..cc5d12470 100644 --- a/tobiko/openstack/stacks/_ubuntu.py +++ b/tobiko/openstack/stacks/_ubuntu.py @@ -26,7 +26,6 @@ UBUNTU_IMAGE_URL = \ class UbuntuImageFixture(glance.URLGlanceImageFixture): - image_url = CONF.tobiko.ubuntu.image_url or UBUNTU_IMAGE_URL image_name = CONF.tobiko.ubuntu.image_name image_file = CONF.tobiko.ubuntu.image_file @@ -45,5 +44,5 @@ class UbuntuServerStackFixture(_nova.ServerStackFixture): #: Glance image used to create a Nova server instance image_fixture = tobiko.required_setup_fixture(UbuntuImageFixture) - #: Glance image used to create a Nova server instance + #: Flavor used to create a Nova server instance flavor_stack = tobiko.required_setup_fixture(UbuntuFlavorStackFixture) diff --git a/tobiko/shell/sh/_process.py b/tobiko/shell/sh/_process.py index d9f2b246d..1315dc349 100644 --- a/tobiko/shell/sh/_process.py +++ b/tobiko/shell/sh/_process.py @@ -271,16 +271,21 @@ class ShellProcessFixture(tobiko.SharedFixture): self.check_stdin_is_opened() sent_bytes = self.stdin.write(data) if sent_bytes: + LOG.debug("Written %d bytes to STDIN (%s)", sent_bytes, + self.command) return data[sent_bytes:] or None else: LOG.debug("%r closed by peer on %r", self.stdin, self) self.stdin.close() + return data def _read_from_stdout(self, buffer_size=None): """Read data from remote stream""" # Read data from remote stream chunk = self.stdout.read(buffer_size) if chunk: + LOG.debug("Read %d bytes from STDOUT (%s)", len(chunk), + self.command) return chunk else: LOG.debug("%r closed by peer on %r", self.stdout, self) @@ -292,6 +297,8 @@ class ShellProcessFixture(tobiko.SharedFixture): # Read data from remote stream chunk = self.stderr.read(buffer_size) if chunk: + LOG.debug("Read %d bytes from STDERR (%s)", len(chunk), + self.command) return chunk else: LOG.debug("%r closed by peer on %r", self.stderr, self) diff --git a/tobiko/tests/functional/openstack/stacks/test_centos.py b/tobiko/tests/functional/openstack/stacks/test_centos.py new file mode 100644 index 000000000..9596c2ee2 --- /dev/null +++ b/tobiko/tests/functional/openstack/stacks/test_centos.py @@ -0,0 +1,34 @@ +# Copyright (c) 2019 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.shell import sh +from tobiko.openstack import stacks +from tobiko.tests.functional.openstack.stacks import test_cirros + + +class CentosServerStackTest(test_cirros.CirrosServerStackTest): + """Tests connectivity to Nova instances via floating IPs""" + + #: Stack of resources with a server attached to a floating IP + stack = tobiko.required_setup_fixture(stacks.CentosServerStackFixture) + + def test_python(self): + python_version = sh.execute(['python', '--version'], + ssh_client=self.stack.ssh_client).stderr + self.assertTrue(python_version.startswith('Python 2.7'), + python_version)