From d95df04c748c50a6dad14b126549f20caada71c1 Mon Sep 17 00:00:00 2001
From: xin liang <xliang@suse.com>
Date: Mon, 5 Aug 2024 21:14:27 +0800
Subject: [PATCH] Fix: Don't add time units to values for existing CIB
 (bsc#1228817)

Commit 7b2cfb23 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.
---
 crmsh/cibconfig.py |  9 +++++----
 crmsh/parse.py     | 14 +++++++-------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/crmsh/cibconfig.py b/crmsh/cibconfig.py
index fa19b9d79..cade7a5d1 100644
--- a/crmsh/cibconfig.py
+++ b/crmsh/cibconfig.py
@@ -855,7 +855,8 @@ def parse_cli_to_xml(cli, oldnode=None):
     output: XML, obj_type, obj_id
     """
     node = None
-    default_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):
@@ -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("@"):
-            default_op_values = False
+            auto_add = False
             default_promotable_meta = False
         else:
-            default_op_values = True
+            auto_add = True
             default_promotable_meta = True
-        node = parse.parse(cli, comments=comments, ignore_empty=False, add_default_op_values=default_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:
diff --git a/crmsh/parse.py b/crmsh/parse.py
index 276d076e0..34cbc0a2c 100644
--- a/crmsh/parse.py
+++ b/crmsh/parse.py
@@ -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_default_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_default_op_values = add_default_op_values
+        self.auto_add = auto_add
         out = self.parse(cmd)
         if self.has_tokens():
             self.err("Unknown arguments: " + ' '.join(self._cmd[self._currtok:]))
@@ -661,7 +661,7 @@ def add_default_advised_ops(self, out):
         """
         Add default operation actions advised values
         """
-        if not self.add_default_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()
@@ -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_default_op_values:
+                    if self.auto_add:
                         id_str = f"{bundle_id}_{name.replace('-', '_')}_{index}"
                         inst_attrs.set('id', id_str)
                     child_flag = True
@@ -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:
@@ -1795,7 +1795,7 @@ def parse(self):
         return ret
 
 
-def parse(s, comments=None, ignore_empty=True, add_default_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
@@ -1841,7 +1841,7 @@ def parse(s, comments=None, ignore_empty=True, add_default_op_values=False):
         return False
 
     try:
-        ret = parser.do_parse(s, ignore_empty, add_default_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)
