From f4019f7831e5366f7e5e40e9715f3bd981f2b7df Mon Sep 17 00:00:00 2001 From: hamalq Date: Tue, 16 Jun 2020 17:59:07 +0000 Subject: [PATCH] Fix "Remove VxFlex OS credentials" regression Change Ib7778ba9d38a68d8b56ca632c5f1c353d55830b0 uses a ConfigParser instance in a way that is incompatible with python 2.7, resulting in a "ConfigParser instance has no attribute '__getitem__'" error. This patch accesses the ConfigParser using the "old" API that works in both Python 2.7 and Python 3 and adds some tests. Co-authored-by: Brian Rosmaita Change-Id: Ie2db587c3bc379acd53cfd449788d171ae58dec5 Closes-Bug: 1883654 (cherry picked from commit 12d252db9cb9deffea3c87b86ea71b3013d93892) (cherry picked from commit 750999db0de0fcfc923cd453add808ca42a4e2b4) Conflicts: - remove os_brick/privileged/scaleio.py (function with bug is in the connector in this branch) - move the test file to tests/initiator/connectors/ - modify the unit tests because the config file is accessed differently in this branch (cherry picked from commit 867767ffdae124fcdb9b04a9089e226689c476d7) --- os_brick/initiator/connectors/scaleio.py | 2 +- .../connectors/test_scaleio_get_password.py | 62 +++++++++++++++++++ .../notes/bug-1883654-cc069892496bd4a8.yaml | 28 +++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 os_brick/tests/initiator/connectors/test_scaleio_get_password.py create mode 100644 releasenotes/notes/bug-1883654-cc069892496bd4a8.yaml diff --git a/os_brick/initiator/connectors/scaleio.py b/os_brick/initiator/connectors/scaleio.py index d134e0eff..9d798eb6d 100644 --- a/os_brick/initiator/connectors/scaleio.py +++ b/os_brick/initiator/connectors/scaleio.py @@ -239,7 +239,7 @@ class ScaleIOConnector(base.BaseLinuxConnector): root_helper=self._root_helper) conf = configparser.ConfigParser() conf.readfp(six.StringIO(out)) - return conf[config_group]["san_password"] + return conf.get(config_group, "san_password") except putils.ProcessExecutionError as e: msg = _("Error reading ScaleIO connector " "configuration file: %s") % e.stderr diff --git a/os_brick/tests/initiator/connectors/test_scaleio_get_password.py b/os_brick/tests/initiator/connectors/test_scaleio_get_password.py new file mode 100644 index 000000000..6d9aaa5f7 --- /dev/null +++ b/os_brick/tests/initiator/connectors/test_scaleio_get_password.py @@ -0,0 +1,62 @@ +# Copyright 2020, Red Hat Inc. +# +# 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 mock +import os + +from os_brick import exception +from os_brick.initiator.connectors import scaleio +from os_brick.tests import base + +EXPECTED_SECTION = "scalio_test" +EXPECTED_PASSWORD = "This is not a good password" +FAKE_CONF = """ +[DEFAULT] +san_password = not me + +[{}] +san_password = {} + +[section_2] +san_password = not me either +""".format(EXPECTED_SECTION, EXPECTED_PASSWORD) + + +class ScaleioGetPasswordTestCase(base.TestCase): + """Check the get_connector_password function. + + Launchpad bug #1883654: a change that worked fine in the + python 3-only branches broke when run under py2.7 in the stable + branches. + + """ + + def setUp(self): + super(ScaleioGetPasswordTestCase, self).setUp() + # The actual ScaleIO connector + self.connector = scaleio.ScaleIOConnector('sudo') + + @mock.patch.object(os.path, 'isfile', return_value=False) + def test_get_connector_password_bad_filename(self, mock_isfile): + self.assertRaises(exception.BrickException, + self.connector._get_connector_password, + EXPECTED_SECTION) + + @mock.patch.object(scaleio.ScaleIOConnector, '_execute') + @mock.patch.object(os.path, 'isfile', return_value=True) + def test_get_connector_password(self, mock_isfile, mock_execute): + mock_execute.return_value = (FAKE_CONF, 0) + found_password = self.connector._get_connector_password( + EXPECTED_SECTION) + self.assertEqual(EXPECTED_PASSWORD, found_password) diff --git a/releasenotes/notes/bug-1883654-cc069892496bd4a8.yaml b/releasenotes/notes/bug-1883654-cc069892496bd4a8.yaml new file mode 100644 index 000000000..a183a1c6a --- /dev/null +++ b/releasenotes/notes/bug-1883654-cc069892496bd4a8.yaml @@ -0,0 +1,28 @@ +--- +security: + - | + Dell EMC VxFlex OS driver: This release corrects an issue where the + fix for `Bug #1823200 `_ + did not run correctly when using Python 2.7. If you are interested + in this release because of `OSSN-0086 + `_, be aware that + you must also deploy a configuration file on compute nodes, cinder + nodes, and anywhere you would perform a volume attachment in your + deployment. Please see the release notes for the previous release + for details. +upgrade: + - | + This release corrects a problem with the fix for `Bug #1823200 + `_ in the previous + release. If you are running OpenStack on Python 3, you should not + be impacted by this bug. If you are not using Dell EMC VxFlex OS + (ScaleIO) Storage as a backend for Cinder, you do not need to upgrade + to this release. +fixes: + - | + `Bug #1883654 `_: + The fix for `Bug #1823200 + `_ in the previous + release used a Python 3-specific language feature and thus did not + run correctly when used with Python 2.7. The problem has been corrected + in this release.