From 581f4ed338593f001d5f6c8ebff45f11d5614af5 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Mon, 15 Jul 2019 12:57:22 +0200 Subject: [PATCH] Move default server fixture to new cirros module. Change-Id: I13f5c13d1e04e90c550551e535dc5ce0404d8744 --- tobiko/openstack/stacks/__init__.py | 12 ++- tobiko/openstack/stacks/_cirros.py | 49 ++++++++++++ tobiko/openstack/stacks/_neutron.py | 79 ------------------- tobiko/openstack/stacks/_nova.py | 75 +++++++++++++++++- .../functional/openstack/stacks/__init__.py | 0 .../openstack/stacks/test_cirros.py | 51 ++++++++++++ .../test_neutron.py} | 28 ------- .../tests/functional/openstack/test_glance.py | 4 +- tobiko/tests/functional/shell/test_execute.py | 4 +- .../scenario/neutron/test_floating_ip.py | 6 +- .../{test_server_create.py => test_server.py} | 2 +- 11 files changed, 189 insertions(+), 121 deletions(-) create mode 100644 tobiko/openstack/stacks/_cirros.py create mode 100644 tobiko/tests/functional/openstack/stacks/__init__.py create mode 100644 tobiko/tests/functional/openstack/stacks/test_cirros.py rename tobiko/tests/functional/openstack/{test_stacks.py => stacks/test_neutron.py} (78%) rename tobiko/tests/scenario/nova/{test_server_create.py => test_server.py} (95%) diff --git a/tobiko/openstack/stacks/__init__.py b/tobiko/openstack/stacks/__init__.py index 785eaf717..8083d46ac 100644 --- a/tobiko/openstack/stacks/__init__.py +++ b/tobiko/openstack/stacks/__init__.py @@ -15,15 +15,19 @@ # under the License. from __future__ import absolute_import +from tobiko.openstack.stacks import _cirros from tobiko.openstack.stacks import _neutron from tobiko.openstack.stacks import _nova -KeyPairStackFixture = _nova.KeyPairStackFixture -FlavorStackFixture = _nova.FlavorStackFixture -CirrosFlavorStackFixture = _nova.CirrosFlavorStackFixture +CirrosFlavorStackFixture = _cirros.CirrosFlavorStackFixture +CirrosImageFixture = _cirros.CirrosImageFixture +CirrosServerStackFixture = _cirros.CirrosServerStackFixture NetworkStackFixture = _neutron.NetworkStackFixture NetworkWithNetMtuWriteStackFixture = ( _neutron.NetworkWithNetMtuWriteStackFixture) -FloatingIpServerStackFixture = _neutron.FloatingIpServerStackFixture SecurityGroupsFixture = _neutron.SecurityGroupsFixture + +ServerStackFixture = _nova.ServerStackFixture +KeyPairStackFixture = _nova.KeyPairStackFixture +FlavorStackFixture = _nova.FlavorStackFixture diff --git a/tobiko/openstack/stacks/_cirros.py b/tobiko/openstack/stacks/_cirros.py new file mode 100644 index 000000000..546182cea --- /dev/null +++ b/tobiko/openstack/stacks/_cirros.py @@ -0,0 +1,49 @@ +# 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 + + +CIRROS_IMAGE_URL = \ + 'http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img' + + +class CirrosImageFixture(glance.URLGlanceImageFixture): + + image_url = CONF.tobiko.cirros.image_url or CIRROS_IMAGE_URL + image_name = CONF.tobiko.cirros.image_name + image_file = CONF.tobiko.cirros.image_file + container_format = CONF.tobiko.cirros.container_format or "bare" + disk_format = CONF.tobiko.cirros.disk_format or "raw" + username = CONF.tobiko.cirros.username or 'cirros' + password = CONF.tobiko.cirros.password or 'gocubsgo' + + +class CirrosFlavorStackFixture(_nova.FlavorStackFixture): + ram = 128 + + +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_stack = tobiko.required_setup_fixture(CirrosFlavorStackFixture) diff --git a/tobiko/openstack/stacks/_neutron.py b/tobiko/openstack/stacks/_neutron.py index 90f451569..c2e353518 100644 --- a/tobiko/openstack/stacks/_neutron.py +++ b/tobiko/openstack/stacks/_neutron.py @@ -18,14 +18,10 @@ from __future__ import absolute_import import netaddr from oslo_log import log -import tobiko from tobiko import config from tobiko.openstack import heat from tobiko.openstack import neutron -from tobiko.openstack import images from tobiko.openstack.stacks import _hot -from tobiko.openstack.stacks import _nova -from tobiko.shell import ssh CONF = config.CONF @@ -153,78 +149,3 @@ class SecurityGroupsFixture(heat.HeatStackFixture): """ #: Heat template file template = _hot.heat_template_file('neutron/security_groups.yaml') - - -@neutron.skip_if_missing_networking_extensions('port-security') -class FloatingIpServerStackFixture(heat.HeatStackFixture): - - #: Heat template file - template = _hot.heat_template_file('neutron/floating_ip_server.yaml') - - #: stack with the key pair for the server instance - key_pair_stack = tobiko.required_setup_fixture( - _nova.KeyPairStackFixture) - - #: stack with the internal where the server port is created - network_stack = tobiko.required_setup_fixture(NetworkStackFixture) - - #: Glance image used to create a Nova server instance - image_fixture = tobiko.required_setup_fixture( - images.CirrosGlanceImageFixture) - - @property - def image(self): - return self.image_fixture.image_id - - @property - def username(self): - """username used to login to a Nova server instance""" - return self.image_fixture.username - - @property - def password(self): - """password used to login to a Nova server instance""" - return self.image_fixture.password - - # Stack used to create flavor for Nova server instance - flavor_stack = tobiko.required_setup_fixture( - _nova.CirrosFlavorStackFixture) - - @property - def flavor(self): - """Flavor for Nova server instance""" - return self.flavor_stack.flavor_id - - #: Whenever port security on internal network is enable - port_security_enabled = False - - #: Security groups to be associated to network ports - security_groups = [] - - @property - def key_name(self): - return self.key_pair_stack.key_name - - @property - def network(self): - return self.network_stack.network_id - - #: Floating IP network where the Neutron floating IP is created - floating_network = CONF.tobiko.neutron.floating_network - - @property - def has_floating_ip(self): - return bool(self.floating_network) - - @property - def ssh_client(self): - return ssh.ssh_client( - host=self.floating_ip_address, - username=self.username, - password=self.password) - - @property - def ssh_command(self): - return ssh.ssh_command( - host=self.floating_ip_address, - username=self.username) diff --git a/tobiko/openstack/stacks/_nova.py b/tobiko/openstack/stacks/_nova.py index c27460295..5786e3ce5 100644 --- a/tobiko/openstack/stacks/_nova.py +++ b/tobiko/openstack/stacks/_nova.py @@ -19,9 +19,13 @@ import os import six +import tobiko from tobiko import config from tobiko.openstack import heat +from tobiko.openstack import neutron from tobiko.openstack.stacks import _hot +from tobiko.openstack.stacks import _neutron +from tobiko.shell import ssh CONF = config.CONF @@ -57,8 +61,75 @@ class FlavorStackFixture(heat.HeatStackFixture): vcpus = None -class CirrosFlavorStackFixture(FlavorStackFixture): - ram = 128 +@neutron.skip_if_missing_networking_extensions('port-security') +class ServerStackFixture(heat.HeatStackFixture): + + #: Heat template file + template = _hot.heat_template_file('neutron/floating_ip_server.yaml') + + #: stack with the key pair for the server instance + key_pair_stack = tobiko.required_setup_fixture(KeyPairStackFixture) + + #: stack with the internal where the server port is created + network_stack = tobiko.required_setup_fixture(_neutron.NetworkStackFixture) + + #: Glance image used to create a Nova server instance + image_fixture = None + + @property + def image(self): + return self.image_fixture.image_id + + @property + def username(self): + """username used to login to a Nova server instance""" + return self.image_fixture.username + + @property + def password(self): + """password used to login to a Nova server instance""" + return self.image_fixture.password + + # Stack used to create flavor for Nova server instance + flavor_stack = None + + @property + def flavor(self): + """Flavor for Nova server instance""" + return self.flavor_stack.flavor_id + + #: Whenever port security on internal network is enable + port_security_enabled = False + + #: Security groups to be associated to network ports + security_groups = [] + + @property + def key_name(self): + return self.key_pair_stack.key_name + + @property + def network(self): + return self.network_stack.network_id + + #: Floating IP network where the Neutron floating IP is created + floating_network = CONF.tobiko.neutron.floating_network + + @property + def has_floating_ip(self): + return bool(self.floating_network) + + @property + def ssh_client(self): + client = ssh.ssh_client(host=self.floating_ip_address, + username=self.username, + password=self.password) + return client + + @property + def ssh_command(self): + return ssh.ssh_command(host=self.floating_ip_address, + username=self.username) def as_str(text): diff --git a/tobiko/tests/functional/openstack/stacks/__init__.py b/tobiko/tests/functional/openstack/stacks/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tobiko/tests/functional/openstack/stacks/test_cirros.py b/tobiko/tests/functional/openstack/stacks/test_cirros.py new file mode 100644 index 000000000..e59321c9a --- /dev/null +++ b/tobiko/tests/functional/openstack/stacks/test_cirros.py @@ -0,0 +1,51 @@ +# 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 testtools + +import tobiko +from tobiko.openstack import stacks +from tobiko.shell import ping +from tobiko.shell import sh + + +class CirrosServerStackTest(testtools.TestCase): + """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.CirrosServerStackFixture) + + def test_ping(self): + """Test connectivity to floating IP address""" + ping.ping_until_received( + self.stack.floating_ip_address).assert_replied() + + def test_ssh_connect(self): + """Test SSH connectivity via Paramiko SSHClient""" + self.stack.ssh_client.connect() + + def test_ssh_command(self): + """Test SSH connectivity via OpenSSH client""" + sh.execute('true', shell=self.stack.ssh_command) + + def test_hostname(self): + """Test that hostname of instance server matches Nova server name""" + self.stack.ssh_client.connect() + + hostname, = sh.execute( + 'hostname', ssh_client=self.stack.ssh_client).stdout.splitlines() + self.assertEqual(hostname, self.stack.server_name) diff --git a/tobiko/tests/functional/openstack/test_stacks.py b/tobiko/tests/functional/openstack/stacks/test_neutron.py similarity index 78% rename from tobiko/tests/functional/openstack/test_stacks.py rename to tobiko/tests/functional/openstack/stacks/test_neutron.py index cc57297a0..ce04ed21f 100644 --- a/tobiko/tests/functional/openstack/test_stacks.py +++ b/tobiko/tests/functional/openstack/stacks/test_neutron.py @@ -20,8 +20,6 @@ import testtools import tobiko from tobiko.openstack import neutron from tobiko.openstack import stacks -from tobiko.shell import ping -from tobiko.shell import sh class NetworkTestCase(testtools.TestCase): @@ -93,29 +91,3 @@ class NetworkWithNetMtuWriteTestCase(NetworkTestCase): def test_net_mtu_write(self): self.assertEqual(self.stack.mtu, self.stack.outputs.mtu) - - -class FloatingIpServerTest(testtools.TestCase): - """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.FloatingIpServerStackFixture) - - def test_ping(self): - """Test connectivity to floating IP address""" - ping.ping_until_received( - self.stack.floating_ip_address).assert_replied() - - def test_ssh_connect(self): - """Test SSH connectivity via Paramiko SSHClient""" - self.stack.ssh_client.connect() - - def test_ssh_command(self): - """Test SSH connectivity via OpenSSH client""" - sh.execute('true', shell=self.stack.ssh_command) - - def test_hostname(self): - """Test that hostname of instance server matches Nova server name""" - result = sh.execute('hostname', ssh_client=self.stack.ssh_client) - hostname, = str(result.stdout).splitlines() - self.assertEqual(hostname, self.stack.server_name) diff --git a/tobiko/tests/functional/openstack/test_glance.py b/tobiko/tests/functional/openstack/test_glance.py index d5dbf9ccb..1dbb1e8fb 100644 --- a/tobiko/tests/functional/openstack/test_glance.py +++ b/tobiko/tests/functional/openstack/test_glance.py @@ -19,14 +19,14 @@ import testtools import tobiko from tobiko.openstack import glance -from tobiko.openstack import images +from tobiko.openstack import stacks class GlanceApiTestCase(testtools.TestCase): """Tests glance images API""" #: Stack of resources with a network with a gateway router - fixture = tobiko.required_setup_fixture(images.CirrosGlanceImageFixture) + fixture = tobiko.required_setup_fixture(stacks.CirrosImageFixture) def test_get_image(self): image = glance.get_image(self.fixture.image_id) diff --git a/tobiko/tests/functional/shell/test_execute.py b/tobiko/tests/functional/shell/test_execute.py index 7acc8a259..303531f94 100644 --- a/tobiko/tests/functional/shell/test_execute.py +++ b/tobiko/tests/functional/shell/test_execute.py @@ -163,7 +163,7 @@ class LocalExecuteTest(ExecuteTest): class SSHExecuteTest(ExecuteTest): server_stack = tobiko.required_setup_fixture( - stacks.FloatingIpServerStackFixture) + stacks.CirrosServerStackFixture) @property def ssh_client(self): @@ -177,7 +177,7 @@ class SSHExecuteTest(ExecuteTest): class ExecuteWithSSHCommandTest(ExecuteTest): server_stack = tobiko.required_setup_fixture( - stacks.FloatingIpServerStackFixture) + stacks.CirrosServerStackFixture) @property def shell(self): diff --git a/tobiko/tests/scenario/neutron/test_floating_ip.py b/tobiko/tests/scenario/neutron/test_floating_ip.py index 22b2649d8..8c42bd3fc 100644 --- a/tobiko/tests/scenario/neutron/test_floating_ip.py +++ b/tobiko/tests/scenario/neutron/test_floating_ip.py @@ -30,7 +30,7 @@ class FloatingIPTest(base.TobikoTest): """Tests connectivity via floating IPs""" #: Resources stack with floating IP and Nova server - stack = tobiko.required_setup_fixture(stacks.FloatingIpServerStackFixture) + stack = tobiko.required_setup_fixture(stacks.CirrosServerStackFixture) def test_stack_create_complete(self): self.stack.key_pair_stack.wait_for_create_complete() @@ -118,7 +118,7 @@ class FloatingIPTest(base.TobikoTest): @neutron.skip_if_missing_networking_extensions('port-security', 'security-group') -class FloatingIPWithPortSecurityFixture(stacks.FloatingIpServerStackFixture): +class FloatingIPWithPortSecurityFixture(stacks.CirrosServerStackFixture): """Heat stack for testing a floating IP instance with port security""" #: Resources stack with security group to allow ping Nova servers @@ -199,7 +199,7 @@ class FloatingIPWithICMPSecurityGroupTest(FloatingIPTest): # --- Test net-mtu-write extension -------------------------------------------- @neutron.skip_if_missing_networking_extensions('net-mtu-writable') -class FloatingIPWithNetMtuWritableFixture(stacks.FloatingIpServerStackFixture): +class FloatingIPWithNetMtuWritableFixture(stacks.CirrosServerStackFixture): """Heat stack for testing floating IP with a custom MTU network value""" #: Heat stack for creating internal network with custom MTU value diff --git a/tobiko/tests/scenario/nova/test_server_create.py b/tobiko/tests/scenario/nova/test_server.py similarity index 95% rename from tobiko/tests/scenario/nova/test_server_create.py rename to tobiko/tests/scenario/nova/test_server.py index df0ff68f9..6748f37d6 100644 --- a/tobiko/tests/scenario/nova/test_server_create.py +++ b/tobiko/tests/scenario/nova/test_server.py @@ -23,7 +23,7 @@ from tobiko.openstack import nova class ServerStackResourcesTest(testtools.TestCase): - stack = tobiko.required_setup_fixture(stacks.FloatingIpServerStackFixture) + stack = tobiko.required_setup_fixture(stacks.CirrosServerStackFixture) def test_server(self): "Test actual server details"