Skip to content

Commit

Permalink
Fix: Don't add time units to values for existing CIB (bsc#1228817)
Browse files Browse the repository at this point in the history
Commit 7b2cfb2 automatically appends 's' as the default time unit for
timeout and interval. This causes inconsistency in the existing CIB.

This commit renames the variable to reflect that it handles both adding
advised operation values and time units, but only when the input is from
a new CLI command.
  • Loading branch information
liangxin1300 committed Aug 16, 2024
1 parent 5a3c45a commit 6990656
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions crmsh/cibconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,8 @@ def parse_cli_to_xml(cli, oldnode=None):
output: XML, obj_type, obj_id
"""
node = None
advised_op_values = False
# Flag to auto add adviced operation values and time units
auto_add = False
default_promotable_meta = False
comments = []
if isinstance(cli, str):
Expand All @@ -865,12 +866,12 @@ def parse_cli_to_xml(cli, oldnode=None):
else: # should be a pre-tokenized list
utils.auto_convert_role = True
if len(cli) >= 3 and cli[0] == "primitive" and cli[2].startswith("@"):
advised_op_values = False
auto_add = False
default_promotable_meta = False
else:
advised_op_values = config.core.add_advised_op_values
auto_add = config.core.add_advised_op_values
default_promotable_meta = True
node = parse.parse(cli, comments=comments, ignore_empty=False, add_advised_op_values=advised_op_values)
node = parse.parse(cli, comments=comments, ignore_empty=False, auto_add=auto_add)
if node is False:
return None, None, None
elif node is None:
Expand Down
14 changes: 7 additions & 7 deletions crmsh/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ def begin_dispatch(self, cmd, min_args=-1):
self.begin(cmd, min_args=min_args)
return self.match_dispatch(errmsg="Unknown command")

def do_parse(self, cmd, ignore_empty, add_advised_op_values):
def do_parse(self, cmd, ignore_empty, auto_add):
"""
Called by CliParser. Calls parse()
Parsers should pass their return value through this method.
"""
self.ignore_empty = ignore_empty
self.add_advised_op_values = add_advised_op_values
self.auto_add = auto_add
out = self.parse(cmd)
if self.has_tokens():
self.err("Unknown arguments: " + ' '.join(self._cmd[self._currtok:]))
Expand Down Expand Up @@ -661,7 +661,7 @@ def add_default_advised_ops(self, out):
"""
Add default operation actions advised values
"""
if not self.add_advised_op_values or out.tag != "primitive":
if not self.auto_add or out.tag != "primitive":
return
ra_inst = ra.RAInfo(out.get('class'), out.get('type'), out.get('provider'))
ra_actions_dict = ra_inst.actions()
Expand Down Expand Up @@ -753,7 +753,7 @@ def match_container(self, out, _type):
inst_attrs = xmlutil.child(container_node, name)
# set meaningful id for port-mapping and storage-mapping
# when the bundle is newly created
if self.add_advised_op_values:
if self.auto_add:
id_str = f"{bundle_id}_{name.replace('-', '_')}_{index}"
inst_attrs.set('id', id_str)
child_flag = True
Expand Down Expand Up @@ -794,7 +794,7 @@ def match_op(self, out, pfx='op'):
if inst_attrs is not None:
self.err(f"Attribute order error: {name} must appear before any instance attribute")
value = nvp.get('value')
if name in ('interval', 'timeout'):
if name in ('interval', 'timeout') and self.auto_add:
value = add_time_unit_if_needed(value)
node.set(name, value)
else:
Expand Down Expand Up @@ -1795,7 +1795,7 @@ def parse(self):
return ret


def parse(s, comments=None, ignore_empty=True, add_advised_op_values=False):
def parse(s, comments=None, ignore_empty=True, auto_add=False):
'''
Input: a list of tokens (or a CLI format string).
Return: a cibobject
Expand Down Expand Up @@ -1841,7 +1841,7 @@ def parse(s, comments=None, ignore_empty=True, add_advised_op_values=False):
return False

try:
ret = parser.do_parse(s, ignore_empty, add_advised_op_values)
ret = parser.do_parse(s, ignore_empty, auto_add)
if ret is not None and len(comments) > 0:
if ret.tag in constants.defaults_tags:
xmlutil.stuff_comments(ret[0], comments)
Expand Down

0 comments on commit 6990656

Please sign in to comment.