On 01/20/2017 03:32 PM, dhbarboza82(a)gmail.com wrote:
From: Daniel Henrique Barboza <danielhb(a)linux.vnet.ibm.com>
- added user log capabilities on 'enable' and 'disable' actions
of /config/plugins/*name* API
- parser now accepts 'enable=' as a valid input to recognize the
plug-in option that enables or disables a plug-in.
Signed-off-by: Daniel Henrique Barboza <danielhb(a)linux.vnet.ibm.com>
---
src/wok/control/config.py | 9 +++++++++
src/wok/i18n.py | 5 ++++-
src/wok/utils.py | 4 +++-
tests/test_utils.py | 20 ++++++++++++++++++--
4 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/src/wok/control/config.py b/src/wok/control/config.py
index c0679f3..db61060 100644
--- a/src/wok/control/config.py
+++ b/src/wok/control/config.py
@@ -21,6 +21,14 @@ from wok.control.base import Collection, Resource
from wok.control.utils import UrlSubNode
+PLUGIN_REQUESTS = {
+ 'POST': {
+ 'enable': "WOKPLUGIN0001L",
+ 'disable': "WOKPLUGIN0002L",
+ },
+}
+
+
@UrlSubNode("config")
class Config(Resource):
def __init__(self, model, id=None):
@@ -43,6 +51,7 @@ class Plugin(Resource):
super(Plugin, self).__init__(model, ident)
self.ident = ident
self.uri_fmt = "/config/plugins/%s"
+ self.log_map = PLUGIN_REQUESTS
self.enable = self.generate_action_handler('enable')
self.disable = self.generate_action_handler('disable')
diff --git a/src/wok/i18n.py b/src/wok/i18n.py
index c96d14f..95ec20f 100644
--- a/src/wok/i18n.py
+++ b/src/wok/i18n.py
@@ -55,6 +55,8 @@ messages = {
"WOKUTILS0004E": _("Invalid data value '%(value)s'"),
"WOKUTILS0005E": _("Invalid data unit '%(unit)s'"),
+ "WOKPLUGIN0001E": _("Unable to find plug-in %(name)s"),
+
# These messages (ending with L) are for user log purposes
"WOKASYNC0001L": _("Successfully completed task
'%(target_uri)s'"),
"WOKASYNC0002L": _("Failed to complete task
'%(target_uri)s'"),
@@ -62,5 +64,6 @@ messages = {
"WOKRES0001L": _("Request made on resource"),
"WOKROOT0001L": _("User '%(username)s' login"),
"WOKROOT0002L": _("User '%(username)s' logout"),
- "WOKPLUGIN0001E": _("Unable to find plug-in %(name)s"),
+ "WOKPLUGIN0001L": _("Enabling plug-in %(ident)s."),
+ "WOKPLUGIN0002L": _("Disabling plug-in %(ident)s."),
}
diff --git a/src/wok/utils.py b/src/wok/utils.py
index c2d4724..5e87ee0 100644
--- a/src/wok/utils.py
+++ b/src/wok/utils.py
@@ -128,7 +128,9 @@ def set_plugin_state(name, state):
wok_section_found = True
continue
- if config_contents[i].startswith('enable =') and wok_section_found:
+ if (config_contents[i].startswith('enable =') or
+ config_contents[i].startswith('enable=')) and \
+ wok_section_found:
It is safer to use regex here.
config_contents[i] = 'enable = %s\n' %
str(state)
break
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 6f1a783..06930b8 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -82,6 +82,22 @@ enable = 1
[wok]
# Enable plugin on Wok server (values: True|False)
+enable=%s
+
+[fakeplugin]
+# Yet another comment on this config file
+enable = 2
+very_interesting_option = True
+""" % str(enable)
+
+ def _get_config_file_template(self, enable=True):
+ return """\
+[a_random_section]
+# a random section for testing purposes
+enable = 1
+
+[wok]
+# Enable plugin on Wok server (values: True|False)
enable = %s
[fakeplugin]
@@ -113,7 +129,7 @@ very_interesting_option = True
updated_conf = f.read()
self.assertEqual(
updated_conf,
- self._get_fake_config_file_content(enable=False)
+ self._get_config_file_template(enable=False)
)
set_plugin_state('pluginA', True)
@@ -121,5 +137,5 @@ very_interesting_option = True
updated_conf = f.read()
self.assertEqual(
updated_conf,
- self._get_fake_config_file_content(enable=True)
+ self._get_config_file_template(enable=True)
)