From c54c41a1fd69b5c191b12a8da0eb12f2ee561f10 Mon Sep 17 00:00:00 2001 From: Brian Rosmaita Date: Tue, 8 Sep 2020 11:16:52 -0400 Subject: [PATCH] Revert "Fix for rbd connector to work with ceph octopus" This reverts commit 3e831480c29c07128f36ae67c44c25177b3d9f36. This change introduced a heavyweight bindep to os-brick. We will replace it with a more lightweight fix. Change-Id: I9eff1d0d8bab7aaf060d2c009bed2be65d212c04 Partial-bug: #1865754 --- os_brick/initiator/connectors/rbd.py | 43 +++-------------- .../tests/initiator/connectors/test_rbd.py | 47 +------------------ ...ctopus-compatibility-a56a05b7395efa7f.yaml | 9 ---- 3 files changed, 8 insertions(+), 91 deletions(-) delete mode 100644 releasenotes/notes/bug-1865754-ceph-octopus-compatibility-a56a05b7395efa7f.yaml diff --git a/os_brick/initiator/connectors/rbd.py b/os_brick/initiator/connectors/rbd.py index 96501fd11..8f797b255 100644 --- a/os_brick/initiator/connectors/rbd.py +++ b/os_brick/initiator/connectors/rbd.py @@ -22,7 +22,6 @@ from oslo_serialization import jsonutils from oslo_utils import excutils from oslo_utils import fileutils from oslo_utils import netutils -from oslo_utils import versionutils from os_brick import exception from os_brick.i18n import _ @@ -34,10 +33,6 @@ from os_brick import utils LOG = logging.getLogger(__name__) -# BUG: #1865754 - Set version base for ceph Octopus which requires additional -# handling of the config file. -OCTOPUS_BASE_VERSION = "15.2.0" - class RBDConnector(base.BaseLinuxConnector): """"Connector class to attach/detach RBD volumes.""" @@ -94,51 +89,25 @@ class RBDConnector(base.BaseLinuxConnector): msg = (_("Keyring path %s is not readable.") % (keyring_path)) raise exception.BrickException(msg=msg) - def _create_ceph_conf(self, monitor_ips, monitor_ports, + @classmethod + def _create_ceph_conf(cls, monitor_ips, monitor_ports, cluster_name, user, keyring): monitors = ["%s:%s" % (ip, port) for ip, port in - zip(self._sanitize_mon_hosts(monitor_ips), monitor_ports)] + zip(cls._sanitize_mon_hosts(monitor_ips), monitor_ports)] mon_hosts = "mon_host = %s" % (','.join(monitors)) - keyring = self._check_or_get_keyring_contents(keyring, cluster_name, - user) + keyring = cls._check_or_get_keyring_contents(keyring, cluster_name, + user) - ceph_version = self._determine_ceph_client_version() try: fd, ceph_conf_path = tempfile.mkstemp(prefix="brickrbd_") with os.fdopen(fd, 'w') as conf_file: - # BUG#1865754 - ceph octopus requires "[global]" as part of - # the ini conf file that is generated. The 'same_major=False' - # is based on the assumption that this is also the behaviour of - # ceph in future versions of ceph following octopus. - if versionutils.is_compatible(OCTOPUS_BASE_VERSION, - ceph_version, - same_major=False): - config = ["[global]", "\n", - mon_hosts, "\n", keyring, "\n"] - else: - config = [mon_hosts, "\n", keyring, "\n"] - - conf_file.writelines(config) + conf_file.writelines([mon_hosts, "\n", keyring, "\n"]) return ceph_conf_path except IOError: msg = (_("Failed to write data to %s.") % (ceph_conf_path)) raise exception.BrickException(msg=msg) - # output of 'ceph --version' on different versions of ceph - # ceph version 0.80.11 (8424145d49264624a3b0a204aedb127835161070) - # ceph version 10.2.11 (e4b061b47f07f583c92a050d9e84b1813a35671e) - # ceph version 12.2.13 (584a...) luminous (stable) - # ceph version 14.2.9 (581f...) nautilus (stable) - # ceph version 15.2.3 (d289...) octopus (stable) - # ceph version 14.2.11-99-gaf0268dc91 (af0268dc910f84b) nautilus (stable) - def _determine_ceph_client_version(self): - cmd = ['ceph', '--version'] - (out, _) = self._execute(*cmd) - if '-' in out: - out = out[:out.index('-')] - return out.split(" ")[2] - def _get_rbd_handle(self, connection_properties): try: user = connection_properties['auth_username'] diff --git a/os_brick/tests/initiator/connectors/test_rbd.py b/os_brick/tests/initiator/connectors/test_rbd.py index 09afe9d82..8c8f8edbc 100644 --- a/os_brick/tests/initiator/connectors/test_rbd.py +++ b/os_brick/tests/initiator/connectors/test_rbd.py @@ -158,13 +158,8 @@ class RBDConnectorTestCase(test_connector.ConnectorTestCase): conn = rbd.RBDConnector(None) self.assertEqual(hosts_out, conn._sanitize_mon_hosts(hosts_in)) - @ddt.data( - "ceph version 14.2.9 (581f...) nautilus (stable)", - "ceph version 14.2.11-99-gaf0268dc91 (af0268dc9) nautilus (stable)") - @mock.patch.object(priv_rootwrap, 'execute') @mock.patch('os_brick.initiator.connectors.rbd.tempfile.mkstemp') - def test_create_ceph_conf(self, ceph_version, mock_mkstemp, mock_execute): - mock_execute.return_value = (ceph_version, None) + def test_create_ceph_conf(self, mock_mkstemp): mockopen = mock.mock_open() fd = mock.sentinel.fd tmpfile = mock.sentinel.tmpfile @@ -177,37 +172,6 @@ class RBDConnectorTestCase(test_connector.ConnectorTestCase): self.keyring) self.assertEqual(conf_path, tmpfile) mock_mkstemp.assert_called_once_with(prefix='brickrbd_') - _, args, _ = mockopen().writelines.mock_calls[0] - self.assertNotIn('[global]', args[0]) - - @ddt.data( - ("ceph version 15.2.3 (d289...) octopus (stable)", True), - ("ceph version 15.2.3-00-d289 (d289) octopus (stable)", True), - ("ceph version 14.2.9 (581f...) nautilus (stable)", False), - ("ceph version 14.2.11-99-ga..1 (af0268dc9) nautilus (stable)", False)) - @mock.patch.object(priv_rootwrap, 'execute') - @mock.patch('os_brick.initiator.connectors.rbd.tempfile.mkstemp') - @ddt.unpack - def test_create_ceph_conf_octopus(self, ceph_version, is_octopus, - mock_mkstemp, mock_execute): - mock_execute.return_value = (ceph_version, None) - mockopen = mock.mock_open() - fd = mock.sentinel.fd - tmpfile = mock.sentinel.tmpfile - mock_mkstemp.return_value = (fd, tmpfile) - - with mock.patch('os.fdopen', mockopen, create=True): - rbd_connector = rbd.RBDConnector(None) - conf_path = rbd_connector._create_ceph_conf( - self.hosts, self.ports, self.clustername, self.user, - self.keyring) - self.assertEqual(conf_path, tmpfile) - mock_mkstemp.assert_called_once_with(prefix='brickrbd_') - _, args, _ = mockopen().writelines.mock_calls[0] - if is_octopus: - self.assertIn('[global]', args[0]) - else: - self.assertNotIn('[global]', args[0]) @mock.patch('os_brick.privileged.rbd.root_create_ceph_conf') def test_create_non_openstack_config(self, mock_priv_create): @@ -354,20 +318,13 @@ class RBDConnectorTestCase(test_connector.ConnectorTestCase): mock_delete.assert_called_once_with(mock_rbd_cfg.return_value) - @ddt.data( - "ceph version 14.2.9 (581f...) nautilus (stable)", - "ceph version 14.2.11-99-gaf0268dc91 (af0268dc9) nautilus (stable)") - @mock.patch.object(priv_rootwrap, 'execute') @mock.patch('os_brick.initiator.linuxrbd.rbd') @mock.patch('os_brick.initiator.linuxrbd.rados') @mock.patch.object(linuxrbd.RBDVolumeIOWrapper, 'close') - def test_disconnect_volume(self, ceph_version, volume_close, mock_rados, - mock_rbd, mock_execute): + def test_disconnect_volume(self, volume_close, mock_rados, mock_rbd): """Test the disconnect volume case.""" - mock_execute.return_value = (ceph_version, None) rbd_connector = rbd.RBDConnector(None) device_info = rbd_connector.connect_volume(self.connection_properties) - rbd_connector.disconnect_volume( self.connection_properties, device_info) diff --git a/releasenotes/notes/bug-1865754-ceph-octopus-compatibility-a56a05b7395efa7f.yaml b/releasenotes/notes/bug-1865754-ceph-octopus-compatibility-a56a05b7395efa7f.yaml deleted file mode 100644 index 3496a93e9..000000000 --- a/releasenotes/notes/bug-1865754-ceph-octopus-compatibility-a56a05b7395efa7f.yaml +++ /dev/null @@ -1,9 +0,0 @@ ---- -fixes: - - | - `Bug #1865754 `_: - Fix to the rbd connector to work with Ceph Octopus (Version 15.2.0 and - later). Octopus has slightly changed its requirements such that it now - needs a ``[global]`` heading at the beginning of the ``ini`` config file - that is generated within the ``RBDConnector`` class. This release - detects the Ceph version and supplies the appropriate config file.