summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug@doughellmann.com>2018-07-17 12:20:55 -0400
committerDoug Hellmann <doug@doughellmann.com>2018-07-17 12:35:13 -0400
commitb79f763b49557bf9d7f4fa595489f8c835f55da9 (patch)
tree36faefecdeafbb87c6cfa1553cf44b7d3b06bda8
parent45425e938de0d24be9809f8b315552c693a14e5f (diff)
downloadoslo-config-b79f763b49557bf9d7f4fa595489f8c835f55da9.tar.gz
ensure we do not modify private data from drivers
When we ask for a list of options from a drivere for generating the sample config or documentation, we want to insert the actual 'driver' option at the front of the list. This keeps each driver from having to do that, and allows us to generate the sample with good defaults. However, if a driver returns us a static data structure, we do not want to modify *that* set of data, because the driver tests will need the original structure intact. So, have list_opts() deepcopy the data it is given, again to avoid having to ensure each driver author does that copy. This change also requires updating the test for list_opts() for the URI driver to no longer assume the 'driver' option will be in the results. At the same time I am reordering the arguments to assertEqual() so that the expected value is listed first and renaming the variable holding the actual values from the discovery call. Change-Id: Ie8c1bc606f5f69a72b2383200a40b26e252067a9 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
-rw-r--r--oslo_config/_list_opts.py3
-rw-r--r--oslo_config/tests/test_sources.py11
2 files changed, 8 insertions, 6 deletions
diff --git a/oslo_config/_list_opts.py b/oslo_config/_list_opts.py
index d89e1bb..141b52b 100644
--- a/oslo_config/_list_opts.py
+++ b/oslo_config/_list_opts.py
@@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import copy
import inspect
from oslo_config import cfg
@@ -42,7 +43,7 @@ def list_opts():
source_names = ext_mgr.names()
for source_name in source_names:
source = ext_mgr[source_name].obj
- source_options = source.list_options_for_discovery()
+ source_options = copy.deepcopy(source.list_options_for_discovery())
source_description = inspect.getdoc(source)
source_options.insert(
0,
diff --git a/oslo_config/tests/test_sources.py b/oslo_config/tests/test_sources.py
index b42476b..8b8588f 100644
--- a/oslo_config/tests/test_sources.py
+++ b/oslo_config/tests/test_sources.py
@@ -282,16 +282,17 @@ class URISourceTestCase(base.BaseTestCase):
self.assertEqual(option, self.conf[option])
def test_list_opts(self):
- expected_group = None
+ discovered_group = None
for group in _list_opts.list_opts():
if group[0] is not None:
if group[0].name == "sample_remote_file_source":
- expected_group = group
+ discovered_group = group
break
- self.assertIsNotNone(expected_group)
+ self.assertIsNotNone(discovered_group)
self.assertEqual(
- expected_group[1],
- _uri.URIConfigurationSourceDriver().list_options_for_discovery()
+ _uri.URIConfigurationSourceDriver().list_options_for_discovery(),
+ # NOTE: Ignore 'driver' option inserted automatically.
+ discovered_group[1][1:],
)