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>
This commit is contained in:
Doug Hellmann 2018-07-17 12:20:55 -04:00
parent 45425e938d
commit b79f763b49
2 changed files with 8 additions and 6 deletions

View File

@ -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,

View File

@ -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:],
)