Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crmsh-4.6] Fix: Add a new option 'has_fa_advised_op' (bsc#1228858) #1531

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions crmsh/cibconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,12 @@ def parse_cli_to_xml(cli, oldnode=None):
output: XML, obj_type, obj_id
"""
node = None
# Flag to auto add adviced operation values and time units
auto_add = False
# Flag to auto add advised operation values for resource agents
has_ra_advised_op = False
# Flag to auto add adviced operation values for fence agents
has_fa_advised_op = False
# Flag to auto add time units for operations
auto_add_time_units = False
default_promotable_meta = False
comments = []
if isinstance(cli, str):
Expand All @@ -866,12 +870,22 @@ 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("@"):
auto_add = False
has_ra_advised_op = False
has_fa_advised_op = False
auto_add_time_units = False
default_promotable_meta = False
else:
auto_add = config.core.add_advised_op_values
has_ra_advised_op = config.core.has_ra_advised_op
has_fa_advised_op = config.core.has_fa_advised_op
auto_add_time_units = True
default_promotable_meta = True
node = parse.parse(cli, comments=comments, ignore_empty=False, auto_add=auto_add)
node = parse.parse(
cli,
comments=comments,
ignore_empty=False,
has_ra_advised_op=has_ra_advised_op,
has_fa_advised_op=has_fa_advised_op,
auto_add_time_units=auto_add_time_units)
if node is False:
return None, None, None
elif node is None:
Expand Down
3 changes: 2 additions & 1 deletion crmsh/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ def get(self, value):
'lock_timeout': opt_string('120'),
'no_ssh': opt_boolean('no'),
'OCF_1_1_SUPPORT': opt_boolean('no'),
'add_advised_op_values': opt_boolean('yes'),
'has_ra_advised_op': opt_boolean('yes'),
'has_fa_advised_op': opt_boolean('no'),
'obscure_pattern': opt_string('passw*')
},
'path': {
Expand Down
26 changes: 18 additions & 8 deletions crmsh/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,15 @@ 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, auto_add):
def do_parse(self, cmd, ignore_empty, has_ra_advised_op, has_fa_advised_op, auto_add_time_unit):
"""
Called by CliParser. Calls parse()
Parsers should pass their return value through this method.
"""
self.ignore_empty = ignore_empty
self.auto_add = auto_add
self.has_ra_advised_op = has_ra_advised_op
self.has_fa_advised_op = has_fa_advised_op
self.auto_add_time_unit = auto_add_time_unit
out = self.parse(cmd)
if self.has_tokens():
self.err("Unknown arguments: " + ' '.join(self._cmd[self._currtok:]))
Expand Down Expand Up @@ -661,9 +663,12 @@ def add_default_advised_ops(self, out):
"""
Add default operation actions advised values
"""
if not self.auto_add or out.tag != "primitive":
if not self.has_ra_advised_op or out.tag != "primitive":
return
ra_inst = ra.RAInfo(out.get('class'), out.get('type'), out.get('provider'))
ra_class = out.get('class')
if ra_class == "stonith" and not self.has_fa_advised_op:
return
ra_inst = ra.RAInfo(ra_class, out.get('type'), out.get('provider'))
ra_actions_dict = ra_inst.actions()
if not ra_actions_dict:
return
Expand Down Expand Up @@ -753,7 +758,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.auto_add:
if self.has_ra_advised_op:
id_str = f"{bundle_id}_{name.replace('-', '_')}_{index}"
inst_attrs.set('id', id_str)
child_flag = True
Expand Down Expand Up @@ -794,7 +799,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') and self.auto_add:
if name in ('interval', 'timeout') and self.auto_add_time_unit:
value = add_time_unit_if_needed(value)
node.set(name, value)
else:
Expand Down Expand Up @@ -1795,7 +1800,12 @@ def parse(self):
return ret


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

try:
ret = parser.do_parse(s, ignore_empty, auto_add)
ret = parser.do_parse(s, ignore_empty, has_ra_advised_op, has_fa_advised_op, auto_add_time_units)
if ret is not None and len(comments) > 0:
if ret.tag in constants.defaults_tags:
xmlutil.stuff_comments(ret[0], comments)
Expand Down
7 changes: 6 additions & 1 deletion etc/crm.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
; ignore_missing_metadata = no
; report_tool_options =
; lock_timeout = 120
; add_advised_op_values = yes
; no_ssh = no

; For resource agent, automatically add the advised values, default is yes.
; has_ra_advised_op = yes

; For fence agent, automatically add the advised values, default is no.
; has_fa_advised_op = no

; set OCF_1_1_SUPPORT to yes is to fully turn on OCF 1.1 feature once the corresponding CIB detected.
; OCF_1_1_SUPPORT = yes

Expand Down
1 change: 1 addition & 0 deletions test/run-functional-tests
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ adjust_test_case() {
run_origin_regression_test() {
CONFIG_COROSYNC_FLAG=0
setup_cluster "hanode1"
docker_exec "hanode1" "echo -e '[core]\nhas_fa_advised_op = yes' > /etc/crm/crm.conf"
docker_exec "hanode1" "sh /usr/share/crmsh/tests/regression.sh"
return $?
}
Expand Down
Loading