Move 'attach.end' notify to attachment_complete

Since microversion 3.44, we update `attachemnt_update` to return
connector and make volume to 'attaching', and add a new api
`attachment_complete` to change volume status to 'in-use', that means
the end of attachment is changed to `attachment_complete`.

But the 'attach.end' notify is still send in attachment_update, which
is unexpected. So, in this patch we move 'attach.end' notify to
`attachment_complete`.

Change-Id: I86dad7afb52d2d253799b543f484e2d55f6e9e6d
Closes-bug: #1808941
This commit is contained in:
Yikun Jiang 2018-12-18 17:21:29 +08:00
parent 84d268d9a0
commit 283e1c2194
3 changed files with 25 additions and 1 deletions

View File

@ -28,6 +28,7 @@ from cinder.objects import fields
from cinder.policies import attachments as attachment_policy
from cinder import utils
from cinder.volume import api as volume_api
from cinder.volume import utils as volume_utils
LOG = logging.getLogger(__name__)
@ -286,6 +287,8 @@ class AttachmentsController(wsgi.Controller):
attachment_ref.save()
volume_ref.update({'status': 'in-use', 'attach_status': 'attached'})
volume_ref.save()
volume_utils.notify_about_volume_usage(context, volume_ref,
"attach.end")
def create_resource(ext_mgr):

View File

@ -30,6 +30,7 @@ from cinder.tests.unit.api import fakes
from cinder.tests.unit import fake_constants as fake
from cinder.volume import api as volume_api
from cinder.volume import rpcapi as volume_rpcapi
from cinder.volume import utils as volume_utils
@ddt.ddt
@ -341,3 +342,24 @@ class AttachmentsAPITestCase(test.TestCase):
self.assertEqual(1, len(res_dict))
self.assertEqual(count, len(res_dict['attachments']))
@mock.patch.object(volume_utils, 'notify_about_volume_usage')
def test_complete_attachment(self, mock_notify):
def fake_notify(context, volume, event_suffix,
extra_usage_info=None, host=None):
# Check the notify content is in-use volume and 'attach.end'
self.assertEqual('in-use', volume['status'])
self.assertEqual('attach.end', event_suffix)
mock_notify.side_effect = fake_notify
req = fakes.HTTPRequest.blank('/v3/%s/attachments/%s/action' %
(fake.PROJECT_ID, self.attachment1.id),
version=mv.NEW_ATTACH_COMPLETION,
use_admin_context=True)
body = {"os-complete": {}}
self.controller.complete(req, self.attachment1.id,
body=body)
# Check notify has been called once
mock_notify.assert_called_once()

View File

@ -4450,7 +4450,6 @@ class VolumeManager(manager.CleanableManager,
False)
vref.refresh()
attachment_ref.refresh()
self._notify_about_volume_usage(context, vref, "attach.end")
LOG.info("attachment_update completed successfully.",
resource=vref)
return connection_info