Peter Pentchev | 5006ff6 | 2021-10-26 01:28:45 +0300 | [diff] [blame] | 1 | From d38aa0fff72db40f4501bfac661313c5aeda51f3 Mon Sep 17 00:00:00 2001 |
| 2 | From: Peter Penchev <openstack-dev@storpool.com> |
| 3 | Date: Tue, 20 Apr 2021 17:46:41 +0300 |
| 4 | Subject: [PATCH] StorPool: drop _attach_volume() and _detach_volume(). |
| 5 | |
| 6 | Our os-brick connector already handles the "keep track of which volume |
| 7 | is attached for what reason" calls to storpool.spopenstack. However, |
| 8 | we need to explicitly specify the access mode in initialize_connection() |
| 9 | now, since our os-brick connector does not know how to divine it yet. |
| 10 | (this will come later with the "attach snapshot" functionality) |
| 11 | |
| 12 | Incidentally, this fixes the "create an encrypted volume" flow, since |
| 13 | our _attach_volume() implementation never actually returned a connector |
| 14 | in the attachment info... |
| 15 | |
| 16 | Change-Id: I5da7ae04b87b4fd52a682a6545060e852174f6c8 |
| 17 | --- |
| 18 | .../unit/volume/drivers/test_storpool.py | 6 ++- |
| 19 | cinder/volume/drivers/storpool.py | 44 ++----------------- |
| 20 | 2 files changed, 8 insertions(+), 42 deletions(-) |
| 21 | |
| 22 | diff --git a/cinder/tests/unit/volume/drivers/test_storpool.py b/cinder/tests/unit/volume/drivers/test_storpool.py |
| 23 | index a5f763b96..843283db4 100644 |
| 24 | --- a/cinder/tests/unit/volume/drivers/test_storpool.py |
| 25 | +++ b/cinder/tests/unit/volume/drivers/test_storpool.py |
| 26 | @@ -1,4 +1,4 @@ |
| 27 | -# Copyright 2014 - 2017, 2019 StorPool |
| 28 | +# Copyright 2014 - 2017, 2019 - 2021 StorPool |
| 29 | # All Rights Reserved. |
| 30 | # |
| 31 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 32 | @@ -225,7 +225,9 @@ class StorPoolTestCase(test.TestCase): |
| 33 | def test_initialize_connection_good(self, cid, hid, name): |
| 34 | c = self.driver.initialize_connection({'id': hid}, {'host': name}) |
| 35 | self.assertEqual('storpool', c['driver_volume_type']) |
| 36 | - self.assertDictEqual({'client_id': cid, 'volume': hid}, c['data']) |
| 37 | + self.assertDictEqual({'client_id': cid, 'volume': hid, |
| 38 | + 'access_mode': 'rw'}, |
| 39 | + c['data']) |
| 40 | |
| 41 | def test_noop_functions(self): |
| 42 | self.driver.terminate_connection(None, None) |
| 43 | diff --git a/cinder/volume/drivers/storpool.py b/cinder/volume/drivers/storpool.py |
| 44 | index cf5707cbc..a1388677b 100644 |
| 45 | --- a/cinder/volume/drivers/storpool.py |
| 46 | +++ b/cinder/volume/drivers/storpool.py |
| 47 | @@ -1,4 +1,4 @@ |
| 48 | -# Copyright (c) 2014 - 2019 StorPool |
| 49 | +# Copyright (c) 2014 - 2021 StorPool |
| 50 | # All Rights Reserved. |
| 51 | # |
| 52 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 53 | @@ -90,6 +90,8 @@ class StorPoolDriver(driver.VolumeDriver): |
| 54 | 1.2.2 - Reintroduce the driver into OpenStack Queens, |
| 55 | add ignore_errors to the internal _detach_volume() method |
| 56 | 1.2.3 - Advertise some more driver capabilities. |
| 57 | + 2.0.0 - Drop _attach_volume() and _detach_volume(), our os-brick |
| 58 | + connector will handle this. |
| 59 | """ |
| 60 | |
| 61 | VERSION = '1.2.3' |
| 62 | @@ -167,6 +169,7 @@ class StorPoolDriver(driver.VolumeDriver): |
| 63 | 'data': { |
| 64 | 'client_id': self._storpool_client_id(connector), |
| 65 | 'volume': volume['id'], |
| 66 | + 'access_mode': 'rw', |
| 67 | }} |
| 68 | |
| 69 | def terminate_connection(self, volume, connector, **kwargs): |
| 70 | @@ -312,45 +315,6 @@ class StorPoolDriver(driver.VolumeDriver): |
| 71 | 'pools': pools |
| 72 | } |
| 73 | |
| 74 | - def _attach_volume(self, context, volume, properties, remote=False): |
| 75 | - if remote: |
| 76 | - return super(StorPoolDriver, self)._attach_volume( |
| 77 | - context, volume, properties, remote=remote) |
| 78 | - req_id = context.request_id |
| 79 | - req = self._attach.get().get(req_id, None) |
| 80 | - if req is None: |
| 81 | - req = { |
| 82 | - 'volume': self._attach.volumeName(volume['id']), |
| 83 | - 'type': 'cinder-attach', |
| 84 | - 'id': context.request_id, |
| 85 | - 'rights': 2, |
| 86 | - 'volsnap': False, |
| 87 | - 'remove_on_detach': True |
| 88 | - } |
| 89 | - self._attach.add(req_id, req) |
| 90 | - name = req['volume'] |
| 91 | - self._attach.sync(req_id, None) |
| 92 | - return {'device': {'path': '/dev/storpool/' + name, |
| 93 | - 'storpool_attach_req': req_id}}, volume |
| 94 | - |
| 95 | - def _detach_volume(self, context, attach_info, volume, properties, |
| 96 | - force=False, remote=False, ignore_errors=False): |
| 97 | - if remote: |
| 98 | - return super(StorPoolDriver, self)._detach_volume( |
| 99 | - context, attach_info, volume, properties, |
| 100 | - force=force, remote=remote, ignore_errors=ignore_errors) |
| 101 | - try: |
| 102 | - req_id = attach_info.get('device', {}).get( |
| 103 | - 'storpool_attach_req', context.request_id) |
| 104 | - req = self._attach.get()[req_id] |
| 105 | - name = req['volume'] |
| 106 | - self._attach.sync(req_id, name) |
| 107 | - if req.get('remove_on_detach', False): |
| 108 | - self._attach.remove(req_id) |
| 109 | - except BaseException: |
| 110 | - if not ignore_errors: |
| 111 | - raise |
| 112 | - |
| 113 | def backup_volume(self, context, backup, backup_service): |
| 114 | volume = self.db.volume_get(context, backup['volume_id']) |
| 115 | req_id = context.request_id |
| 116 | -- |
| 117 | 2.30.2 |
| 118 | |