Add test cases for nova server creation

Change-Id: I8771f5a3965d38799a2babcf8e44f6a8d6a8226f
This commit is contained in:
Federico Ressi 2020-07-07 15:14:22 +02:00
parent 05c7a924be
commit 92d9e9fc9a
4 changed files with 210 additions and 0 deletions

View File

@ -0,0 +1,27 @@
# 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
from tobiko.openstack.tests import _nova
test_evacuable_server_creation = _nova.test_evacuable_server_creation
test_server_creation = _nova.test_server_creation
test_servers_creation = _nova.test_servers_creation
test_server_creation_and_shutoff = _nova.test_server_creation_and_shutoff
TestServerCreationStack = _nova.TestServerCreationStack
TestEvacuableServerCreationStack = _nova.TestEvacuableServerCreationStack

View File

@ -0,0 +1,93 @@
# 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 os
import typing # noqa
# import testtools
import tobiko
from tobiko.shell import ping
from tobiko.shell import sh
from tobiko.openstack import nova
from tobiko.openstack.stacks import _cirros
from tobiko.openstack.stacks import _nova
class TestServerCreationStack(_cirros.CirrosServerStackFixture):
"""Nova instance intended to be used for testing server creation"""
def test_server_creation(stack=TestServerCreationStack):
"""Test Nova server creation
"""
return test_servers_creation(stack=stack,
number_of_servers=0).first
class TestEvacuableServerCreationStack(_cirros.EvacuableServerStackFixture):
"""Nova instance intended to be used for testing server creation"""
def test_evacuable_server_creation():
"""Test evacuable Nova server creation
"""
return test_server_creation(stack=TestEvacuableServerCreationStack)
def test_server_creation_and_shutoff(stack=TestServerCreationStack):
result = test_server_creation(stack=stack)
nova.shutoff_server(result.server_details)
return result
def test_servers_creation(stack=TestServerCreationStack,
number_of_servers=2) -> \
typing.List[_nova.ServerStackFixture]:
pid = os.getpid()
fixture_obj = tobiko.get_fixture_class(stack)
# Get list of server stack instances
fixtures = tobiko.Selection(
tobiko.get_fixture(fixture_obj, fixture_id=f'{pid}-{i}')
for i in range(number_of_servers or 1))
testcase = tobiko.get_test_case()
# Check fixtures types
for fixture in fixtures:
testcase.assertIsInstance(fixture, _nova.ServerStackFixture)
# Delete all servers stacks
for fixture in fixtures:
tobiko.cleanup_fixture(fixture)
# Create all servers stacks
for fixture in fixtures:
testcase.useFixture(fixture)
# Test SSH connectivity to floating IP address
testcase.assertEqual(
{fixture.server_id: fixture.server_name
for fixture in fixtures},
{fixture.server_id: sh.get_hostname(ssh_client=fixture.ssh_client)
for fixture in fixtures})
# Test pinging to floating IP address
ping.assert_reachable_hosts(fixture.floating_ip_address
for fixture in fixtures)
return fixtures

View File

@ -0,0 +1,68 @@
# 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 os
import testtools
import tobiko
from tobiko.openstack import glance
from tobiko.openstack import nova
from tobiko.openstack import tests
class MyServerStack(tests.TestServerCreationStack):
pass
class ServerCreationTest(testtools.TestCase):
def test_server_creation(self):
all_servers_ids = {server.id for server in nova.list_servers()}
stack = tests.test_server_creation()
self.assertIsInstance(stack, tests.TestServerCreationStack)
class_name = tobiko.get_fixture_name(tests.TestServerCreationStack)
pid = os.getpid()
self.assertEqual(f"{class_name}-{pid}-0", stack.stack_name)
self.assertNotIn(stack.server_id, all_servers_ids)
self.assertEqual('ACTIVE', nova.get_server(stack.server_id).status)
def test_server_creation_with_stack(self):
stack = tests.test_server_creation(stack=MyServerStack)
self.assertIsInstance(stack, tests.TestServerCreationStack)
def test_evacuable_server_creation(self):
stack = tests.test_evacuable_server_creation()
self.assertIsInstance(stack, tests.TestEvacuableServerCreationStack)
self.assertIn('evacuable', glance.get_image(stack.image).tags)
def test_server_creation_and_shutoff(self):
stack = tests.test_server_creation_and_shutoff()
self.assertIsInstance(stack, tests.TestServerCreationStack)
self.assertEqual('SHUTOFF', nova.get_server(stack.server_id).status)
def test_servers_creation(self):
all_servers_ids = {server.id for server in nova.list_servers()}
stacks = tests.test_servers_creation()
self.assertEqual(2, len(stacks))
pid = os.getpid()
for i, stack in enumerate(stacks):
self.assertIsInstance(stack, tests.TestServerCreationStack)
class_name = tobiko.get_fixture_name(tests.TestServerCreationStack)
self.assertEqual(f"{class_name}-{pid}-{i}", stack.stack_name)
self.assertNotIn(stack.server_id, all_servers_ids)
self.assertEqual('ACTIVE', nova.get_server(stack.server_id).status)

View File

@ -17,9 +17,11 @@ from __future__ import absolute_import
import testtools
import tobiko
from tobiko import config
from tobiko.openstack import stacks
from tobiko.openstack import neutron
from tobiko.openstack import nova
from tobiko.openstack import tests
class ServerStackResourcesTest(testtools.TestCase):
@ -42,3 +44,23 @@ class ServerStackResourcesTest(testtools.TestCase):
# Verify actual port status (is alive, etc.)
port_data = neutron.get_port(port.physical_resource_id)
self.assertEqual(port.physical_resource_id, port_data['id'])
class ServerCreationTest(testtools.TestCase):
def setUp(self):
testtools.TestCase.setUp(self)
if config.get_bool_env('TOBIKO_PREVENT_CREATE'):
self.skip('TOBIKO_PREVENT_CREATE is true')
def test_server_creation(self):
tests.test_server_creation()
def test_evacuable_server_creation(self):
tests.test_evacuable_server_creation()
def test_server_creation_and_shutoff(self):
tests.test_server_creation_and_shutoff()
def test_servers_creation(self):
tests.test_servers_creation()