Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE
crmsh.9422
0003-high-cibconfig-Normalize-to-_-in-param-nam...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0003-high-cibconfig-Normalize-to-_-in-param-names-bsc-111.patch of Package crmsh.9422
From 3a5c126ce2fc352af115fcc3ed0cf88a18fff601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Gr=C3=B6nlund?= <krig@koru.se> Date: Fri, 9 Nov 2018 14:48:06 +0100 Subject: [PATCH 3/3] high: cibconfig: Normalize - to _ in param names (bsc#1111579) --- crmsh/cibconfig.py | 22 ++++++++++++++++++++++ crmsh/ra.py | 17 +++++++++++++++++ test/unittests/test_cliformat.py | 10 ++++++++++ 3 files changed, 49 insertions(+) diff --git a/crmsh/cibconfig.py b/crmsh/cibconfig.py index 0d0151d1..8bf38180 100644 --- a/crmsh/cibconfig.py +++ b/crmsh/cibconfig.py @@ -909,6 +909,9 @@ class CibObject(object): ''' pass + def normalize_parameters(self): + pass + def _repr_cli_head(self, format_mode): 'implemented in subclasses' pass @@ -1450,6 +1453,23 @@ class CibPrimitive(CibObject): self.set_updated() return new_op_node + def normalize_parameters(self): + """ + Normalize parameter names: + If a parameter "foo-bar" is set but the + agent doesn't have a parameter "foo-bar", + and instead has a parameter "foo_bar", then + change the name to set the value of "foo_bar" + instead. + """ + r_node = self.node + if self.obj_type == "primitive": + r_node = reduce_primitive(self.node) + if r_node is None: + return + ra = get_ra(r_node) + ra.normalize_parameters(r_node) + def check_sanity(self): ''' Check operation timeouts and if all required parameters @@ -3272,6 +3292,7 @@ class CibFactory(object): topnode.append(obj.node) self.cib_objects.append(obj) copy_nvpairs(obj.node, node) + obj.normalize_parameters() obj.set_updated() return obj @@ -3600,6 +3621,7 @@ class CibFactory(object): return None pnode.append(node) self._redirect_children_constraints(obj) + obj.normalize_parameters() if not obj.cli_use_validate(): self.nocli_warn = True obj.nocli = True diff --git a/crmsh/ra.py b/crmsh/ra.py index 4c371026..2a7cb217 100644 --- a/crmsh/ra.py +++ b/crmsh/ra.py @@ -540,6 +540,23 @@ class RAInfo(object): return True return False + def normalize_parameters(self, root): + """ + Find all instance_attributes/nvpair objects, + check if parameter exists. If not, normalize name + and check if THAT exists (replacing - with _). + If so, change the name of the parameter. + """ + params = self.params() + if not params: + return + for nvp in root.xpath("instance_attributes/nvpair"): + name = nvp.get("name") + if name is not None and name not in params: + name = name.replace("-", "_") + if name in params: + nvp.attrib["name"] = name + def sanity_check_params(self, ident, nvpairs, existence_only=False): ''' nvpairs is a list of <nvpair> tags. diff --git a/test/unittests/test_cliformat.py b/test/unittests/test_cliformat.py index e196c7d4..4da1ab0c 100644 --- a/test/unittests/test_cliformat.py +++ b/test/unittests/test_cliformat.py @@ -60,6 +60,16 @@ def test_rscset(): roundtrip('order order_2 Mandatory: [ A B ] C') roundtrip('rsc_template public_vm Xen') +@with_setup(setup_func, teardown_func) +def test_normalize(): + """ + Test automatic normalization of parameter names: + "shutdown_timeout" is a parameter name, but + "shutdown-timeout" is not. + """ + roundtrip('primitive vm1 Xen params shutdown-timeout=0', + expected='primitive vm1 Xen params shutdown_timeout=0') + @with_setup(setup_func, teardown_func) def test_group(): -- 2.16.4
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor