From 78db9bcd17f61f65964832ea9d221877e9688ee9 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Thu, 23 Jun 2016 09:57:32 +0200 Subject: [PATCH] Don't fail when trying to set a missing option Since the framework supports different versions of the plugins, some plugin options may be missing for older versions. Change-Id: I01243b323a0048588d7f55870a749891f7d4c6be --- stacklight_tests/helpers/helpers.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/stacklight_tests/helpers/helpers.py b/stacklight_tests/helpers/helpers.py index 1a534df..698740f 100644 --- a/stacklight_tests/helpers/helpers.py +++ b/stacklight_tests/helpers/helpers.py @@ -111,7 +111,7 @@ class PluginHelper(object): self.env.admin_actions.install_plugin( plugin_file_name=os.path.basename(plugin_path)) - def activate_plugin(self, name, version, options=None): + def activate_plugin(self, name, version, options=None, strict=False): """Enable and configure a plugin for the cluster. :param name: name of the plugin. @@ -120,6 +120,9 @@ class PluginHelper(object): :type name: str :param options: configuration of the plugin (optional). :type options: dict + :param strict: whether or not to fail when setting an unknown option + (default: False). + :type options: boolean :returns: None """ if options is None: @@ -147,8 +150,19 @@ class PluginHelper(object): for option, value in options.items(): path = option.split("/") for p in path[:-1]: - plugin_settings = plugin_data[p] - plugin_settings[path[-1]] = value + if p in plugin_data: + plugin_option = plugin_data[p] + else: + msg = "Plugin option {} not found".format(option) + if strict: + raise NotFound(msg) + logger.warn(msg) + plugin_option = None + break + + if plugin_option is not None: + plugin_option[path[-1]] = value + self.nailgun_client.update_cluster_attributes(self.cluster_id, { "editable": {name: attributes} })