compute: Add negative volume detach test
This negative volume detach test stops libvirtd on the compute to cause a failure and asserts that the volume state remains in-use and that number of attached devices to the domain remains the same. Change-Id: I02744e366cfbc536c94f00ceb1ed19a45f9bc33e
This commit is contained in:
parent
9395f5d9ea
commit
287cdd2d0e
@ -17,6 +17,9 @@ function configure {
|
||||
iniset $TEMPEST_CONFIG whitebox-nova-compute config_path "$WHITEBOX_NOVA_COMPUTE_CONFIG_PATH"
|
||||
iniset $TEMPEST_CONFIG whitebox-nova-compute restart_command "$WHITEBOX_NOVA_COMPUTE_RESTART_COMMAND"
|
||||
|
||||
iniset $TEMPEST_CONFIG whitebox-nova-libvirt restart_command "$WHITEBOX_NOVA_LIBVIRT_RESTART_COMMAND"
|
||||
iniset $TEMPEST_CONFIG whitebox-nova-libvirt stop_command "$WHITEBOX_NOVA_LIBVIRT_STOP_COMMAND"
|
||||
|
||||
iniset $TEMPEST_CONFIG whitebox-database user $DATABASE_USER
|
||||
iniset $TEMPEST_CONFIG whitebox-database password $DATABASE_PASSWORD
|
||||
iniset $TEMPEST_CONFIG whitebox-database host $DATABASE_HOST
|
||||
|
@ -2,3 +2,6 @@ NOVA_FILTERS="$NOVA_FILTERS,NUMATopologyFilter"
|
||||
|
||||
WHITEBOX_NOVA_COMPUTE_CONFIG_PATH=${WHITEBOX_NOVA_COMPUTE_CONFIG_PATH:-/etc/nova/nova-cpu.conf}
|
||||
WHITEBOX_NOVA_COMPUTE_RESTART_COMMAND=${WHITEBOX_NOVA_COMPUTE_RESTART_COMMAND:-'systemctl restart devstack@n-cpu'}
|
||||
|
||||
WHITEBOX_NOVA_LIBVIRT_RESTART_COMMAND=${WHITEBOX_NOVA_LIBVIRT_RESTART_COMMAND:-'systemctl restart libvirtd'}
|
||||
WHITEBOX_NOVA_LIBVIRT_STOP_COMMAND=${WHITEBOX_NOVA_LIBVIRT_STOP_COMMAND:-'systemctl stop libvirtd'}
|
||||
|
95
whitebox_tempest_plugin/api/compute/test_volume_negative.py
Normal file
95
whitebox_tempest_plugin/api/compute/test_volume_negative.py
Normal file
@ -0,0 +1,95 @@
|
||||
# Copyright 2019 Red Hat
|
||||
# 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.
|
||||
|
||||
import testtools
|
||||
|
||||
from tempest.api.compute.volumes import test_attach_volume
|
||||
from tempest.common.utils.linux import remote_client
|
||||
from tempest.common import waiters
|
||||
from tempest import config
|
||||
|
||||
from whitebox_tempest_plugin.api.compute import base
|
||||
from whitebox_tempest_plugin.services import clients
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class VolumesAdminNegativeTest(base.BaseWhiteboxComputeTest,
|
||||
test_attach_volume.BaseAttachVolumeTest):
|
||||
|
||||
@classmethod
|
||||
def skip_checks(cls):
|
||||
super(VolumesAdminNegativeTest, cls).skip_checks()
|
||||
if not CONF.service_available.cinder:
|
||||
skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
|
||||
raise cls.skipException(skip_msg)
|
||||
|
||||
@classmethod
|
||||
def setup_credentials(cls):
|
||||
cls.prepare_instance_network()
|
||||
super(VolumesAdminNegativeTest, cls).setup_credentials()
|
||||
|
||||
@testtools.skipUnless(
|
||||
CONF.validation.run_validation,
|
||||
'ssh to instance will not work without run validation enabled.')
|
||||
def test_detach_failure(self):
|
||||
"""Assert that volumes remain in-use and attached after detach failure
|
||||
"""
|
||||
server, validation_resources = self._create_server()
|
||||
# NOTE: Create one remote client used throughout the test.
|
||||
linux_client = remote_client.RemoteClient(
|
||||
self.get_server_ip(server, validation_resources),
|
||||
self.image_ssh_user,
|
||||
self.image_ssh_password,
|
||||
validation_resources['keypair']['private_key'],
|
||||
server=server,
|
||||
servers_client=self.servers_client)
|
||||
# NOTE: We need to ensure the ssh key has been injected in the
|
||||
# guest before we power cycle
|
||||
linux_client.validate_authentication()
|
||||
disks_before_attach = linux_client.list_disks()
|
||||
|
||||
volume = self.create_volume()
|
||||
# Attach the volume
|
||||
attachment = self.attach_volume(server, volume)
|
||||
waiters.wait_for_volume_resource_status(
|
||||
self.volumes_client, attachment['volumeId'], 'in-use')
|
||||
disks_after_attach = linux_client.list_disks()
|
||||
self.assertGreater(
|
||||
len(disks_after_attach),
|
||||
len(disks_before_attach))
|
||||
hypervisor = self.get_hypervisor_ip(server['id'])
|
||||
|
||||
# stop the nova_libvirt service
|
||||
clients.ServiceManager(hypervisor, 'nova-libvirt').stop()
|
||||
|
||||
# While this call to n-api will return successfully the underlying call
|
||||
# to the virt driver will fail as the libvirt service is stopped.
|
||||
self.servers_client.detach_volume(server['id'], attachment['volumeId'])
|
||||
waiters.wait_for_volume_resource_status(
|
||||
self.volumes_client, attachment['volumeId'], 'in-use')
|
||||
disks_after_failed_detach = linux_client.list_disks()
|
||||
self.assertEqual(
|
||||
len(disks_after_failed_detach), len(disks_after_attach))
|
||||
|
||||
# restart the nova_libvirt after failed detach
|
||||
clients.ServiceManager(hypervisor, 'nova-libvirt').restart()
|
||||
|
||||
# This will be a successful detach as nova_libvirt is started again
|
||||
self.servers_client.detach_volume(server['id'], attachment['volumeId'])
|
||||
waiters.wait_for_volume_resource_status(
|
||||
self.volumes_client, attachment['volumeId'], 'available')
|
||||
disks_after_detach = linux_client.list_disks()
|
||||
self.assertEqual(len(disks_before_attach), len(disks_after_detach))
|
@ -79,6 +79,21 @@ nova_compute_opts = [
|
||||
'privilege management (ie, no sudo).'),
|
||||
]
|
||||
|
||||
nova_libvirt_group = cfg.OptGroup(
|
||||
name='whitebox-nova-libvirt',
|
||||
title='Config options to manage the nova-libvirt service')
|
||||
|
||||
nova_libvirt_opts = [
|
||||
cfg.StrOpt(
|
||||
'restart_command',
|
||||
help='Command to restart the nova-libvirt service, without any '
|
||||
'privilege management (ie, no sudo).'),
|
||||
cfg.StrOpt(
|
||||
'stop_command',
|
||||
help='Command to stop the nova-libvirt service, without any '
|
||||
'privilege management (ie, no sudo).'),
|
||||
]
|
||||
|
||||
database_group = cfg.OptGroup(
|
||||
name='whitebox-database',
|
||||
title='Config options to access the database.')
|
||||
|
@ -38,11 +38,15 @@ class WhiteboxTempestPlugin(plugins.TempestPlugin):
|
||||
whitebox_config.nova_compute_opts)
|
||||
config.register_opt_group(conf, whitebox_config.database_group,
|
||||
whitebox_config.database_opts)
|
||||
config.register_opt_group(conf, whitebox_config.nova_libvirt_group,
|
||||
whitebox_config.nova_libvirt_opts)
|
||||
|
||||
def get_opt_lists(self):
|
||||
return [(whitebox_config.general_group.name,
|
||||
whitebox_config.general_opts),
|
||||
(whitebox_config.nova_compute_group.name,
|
||||
whitebox_config.nova_compute_opts),
|
||||
(whitebox_config.nova_libvirt_group.name,
|
||||
whitebox_config.nova_libvirt_opts),
|
||||
(whitebox_config.database_group.name,
|
||||
whitebox_config.database_opts)]
|
||||
|
@ -84,8 +84,9 @@ class ServiceManager(SSHClient):
|
||||
conf = getattr(CONF, 'whitebox-%s' % service)
|
||||
except AttributeError:
|
||||
raise exceptions.MissingServiceSectionException(service=service)
|
||||
self.config_path = conf.config_path
|
||||
self.restart_command = conf.restart_command
|
||||
self.config_path = getattr(conf, 'config_path', None)
|
||||
self.restart_command = getattr(conf, 'restart_command', None)
|
||||
self.stop_command = getattr(conf, 'stop_command', None)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def config_option(self, section, option, value):
|
||||
@ -147,6 +148,11 @@ class ServiceManager(SSHClient):
|
||||
time.sleep(15)
|
||||
return result
|
||||
|
||||
def stop(self):
|
||||
result = self.execute(self.stop_command, sudo=True)
|
||||
time.sleep(5)
|
||||
return result
|
||||
|
||||
|
||||
class NUMAClient(SSHClient):
|
||||
"""A client to get host NUMA information. `numactl` needs to be installed
|
||||
|
@ -148,6 +148,14 @@ class ServiceManagerTestCase(base.WhiteboxPluginTestCase):
|
||||
service.restart()
|
||||
mock_exec.assert_called_with('fake restart command', sudo=True)
|
||||
|
||||
def test_stop(self):
|
||||
self.flags(stop_command='fake stop command',
|
||||
group='whitebox-nova-libvirt')
|
||||
service = clients.ServiceManager('fake-host', 'nova-libvirt')
|
||||
with mock.patch.object(service, 'execute') as mock_exec:
|
||||
service.stop()
|
||||
mock_exec.assert_called_with('fake stop command', sudo=True)
|
||||
|
||||
|
||||
class NUMAClientTestCase(base.WhiteboxPluginTestCase):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user