From b84eb40a66ccd74b8862cfa8708c9d3eda68a3c4 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 25 Feb 2019 18:52:41 -0500 Subject: [PATCH] Improve CinderFixtureNewAttachFlow This does three things: 1. Implements the attachment_complete method in order to fail if code is trying to complete an attachment that does not exist. 2. Adds logging in the various attachment CRUD methods to aid in debugging test failures. 3. Mirrors the method signature for is_microversion_supported to make sure code is at least calling it properly. Conflicts: nova/tests/fixtures.py NOTE(lyarwood): Conflicts due to Iabc1e55550e8d9d82e20facfaf84316892c5564a and I13102243f7ce36a5d44c1790f3a633703373ebf7 not being present in stable/rocky. Change-Id: If6a36d23768877bfa820ed44b610bfb113df5464 (cherry picked from commit 576a4e5260c4bc813474dead4eec19bd2a1cc680) (cherry picked from commit f81d1a5ce400e756836497d26ea5bd5f7c7c14a9) --- nova/tests/fixtures.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/nova/tests/fixtures.py b/nova/tests/fixtures.py index 7255355d2b26..650b9a47f68e 100644 --- a/nova/tests/fixtures.py +++ b/nova/tests/fixtures.py @@ -32,6 +32,7 @@ import mock from neutronclient.common import exceptions as neutron_client_exc from oslo_concurrency import lockutils from oslo_config import cfg +from oslo_log import log as logging import oslo_messaging as messaging from oslo_messaging import conffixture as messaging_conffixture from oslo_privsep import daemon as privsep_daemon @@ -65,6 +66,8 @@ CONF = cfg.CONF DB_SCHEMA = {'main': "", 'api': "", 'placement': ""} SESSION_CONFIGURED = False +LOG = logging.getLogger(__name__) + class ServiceFixture(fixtures.Fixture): """Run a service as a test fixture.""" @@ -1717,18 +1720,26 @@ class CinderFixtureNewAttachFlow(fixtures.Fixture): attachment = {'id': attachment_id, 'connection_info': {'data': {}}} self.volume_to_attachment[volume_id].append( (attachment_id, instance_uuid)) + LOG.info('Created attachment %s for volume %s. Total ' + 'attachments for volume: %d', attachment_id, volume_id, + len(self.volume_to_attachment[volume_id])) return attachment def fake_attachment_delete(_self, context, attachment_id): # 'attachment' is a tuple defining a attachment-instance mapping - _, attachment, attachments = _find_attachment(attachment_id) + volume_id, attachment, attachments = ( + _find_attachment(attachment_id)) attachments.remove(attachment) + LOG.info('Deleted attachment %s for volume %s. Total attachments ' + 'for volume: %d', attachment_id, volume_id, + len(attachments)) def fake_attachment_update(_self, context, attachment_id, connector, mountpoint=None): # Ensure the attachment exists _find_attachment(attachment_id) + LOG.info('Updating volume attachment: %s', attachment_id) attachment_ref = {'driver_volume_type': 'fake_type', 'id': attachment_id, 'connection_info': {'data': @@ -1750,6 +1761,11 @@ class CinderFixtureNewAttachFlow(fixtures.Fixture): 'target_lun': '1'}}} return attachment_ref + def fake_attachment_complete(_self, _context, attachment_id): + # Ensure the attachment exists + _find_attachment(attachment_id) + LOG.info('Completing volume attachment: %s', attachment_id) + self.test.stub_out('nova.volume.cinder.API.attachment_create', fake_attachment_create) self.test.stub_out('nova.volume.cinder.API.attachment_delete', @@ -1757,7 +1773,7 @@ class CinderFixtureNewAttachFlow(fixtures.Fixture): self.test.stub_out('nova.volume.cinder.API.attachment_update', fake_attachment_update) self.test.stub_out('nova.volume.cinder.API.attachment_complete', - lambda *args, **kwargs: None) + fake_attachment_complete) self.test.stub_out('nova.volume.cinder.API.attachment_get', fake_attachment_get) self.test.stub_out('nova.volume.cinder.API.begin_detaching', @@ -1770,7 +1786,7 @@ class CinderFixtureNewAttachFlow(fixtures.Fixture): self.test.stub_out('nova.volume.cinder.API.roll_detaching', lambda *args, **kwargs: None) self.test.stub_out('nova.volume.cinder.is_microversion_supported', - lambda *args, **kwargs: None) + lambda ctxt, microversion: None) self.test.stub_out('nova.volume.cinder.API.check_attached', lambda *args, **kwargs: None)