Skip to content

Dev: Parsing resource meta attributes dynamically #1424

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

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
8 changes: 4 additions & 4 deletions crmsh/cibconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from . import crm_gv
from . import ui_utils
from . import userdir
from .ra import get_ra, get_properties_list, get_pe_meta, get_properties_meta, RAInfo
from .ra import get_ra, get_properties_list, get_pe_meta, get_properties_meta, RAInfo, get_resource_meta_list
from .utils import ext_cmd, safe_open_w, pipe_string, safe_close_w, crm_msec
from .utils import ask, lines2cli, olist
from .utils import page_string, str2tmp, ensure_sudo_readable
Expand Down Expand Up @@ -1571,7 +1571,7 @@ def check_sanity(self):
if self.node is None: # eh?
logger.error("%s: no xml (strange)", self.obj_id)
return utils.get_check_rc()
rc3 = sanity_check_meta(self.obj_id, self.node, constants.rsc_meta_attributes)
rc3 = sanity_check_meta(self.obj_id, self.node, get_resource_meta_list())
if self.obj_type == "primitive":
r_node = reduce_primitive(self.node)
if r_node is None:
Expand Down Expand Up @@ -1681,7 +1681,7 @@ def check_sanity(self):
if self.node is None: # eh?
logger.error("%s: no xml (strange)", self.obj_id)
return utils.get_check_rc()
l = constants.rsc_meta_attributes
l = get_resource_meta_list()
if self.obj_type == "clone":
l += constants.clone_meta_attributes
elif self.obj_type == "ms":
Expand Down Expand Up @@ -2045,7 +2045,7 @@ def check_sanity(self):
elif self.obj_type == "op_defaults":
l = schema.get('attr', 'op', 'a')
elif self.obj_type == "rsc_defaults":
l = constants.rsc_meta_attributes
l = get_resource_meta_list()
rc = sanity_check_nvpairs(self.obj_id, self.node, l)
return rc

Expand Down
17 changes: 17 additions & 0 deletions crmsh/ra.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,23 @@
return []


@utils.memoize
def get_resource_meta():
resource_meta = utils.get_resource_metadata()
if resource_meta:
return RAInfo("resource_meta", None, meta_string=resource_meta)

Check warning on line 235 in crmsh/ra.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ra.py#L235

Added line #L235 was not covered by tests
return None


@utils.memoize
def get_resource_meta_list():
try:
return list(get_resource_meta().params().keys())
# use legacy code to get the resource metadata list
except:
return constants.rsc_meta_attributes


def prog_meta(prog):
'''
Do external program metadata.
Expand Down
16 changes: 14 additions & 2 deletions crmsh/ui_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,14 @@
completing = args[-1]
if completing == 'meta':
return ['meta']
if completing.endswith('='):
if len(completing) > 1 and options.interactive:
topic = completing[:-1]
CompletionHelp.help(topic, agent.meta_parameter(topic), args)
return []

Check warning on line 245 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L241-L245

Added lines #L241 - L245 were not covered by tests
if '=' in completing:
return []
return utils.filter_keys(constants.rsc_meta_attributes, args)
return utils.filter_keys(ra.get_resource_meta_list(), args)

Check warning on line 248 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L248

Added line #L248 was not covered by tests


def _prim_op_completer(agent, args):
Expand Down Expand Up @@ -304,6 +309,11 @@
return _prim_params_completer(agent, args)


def _rsc_meta_completer(args):
agent = ra.get_resource_meta()
return _prim_meta_completer(agent, args)

Check warning on line 314 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L313-L314

Added lines #L313 - L314 were not covered by tests


def primitive_complete_complex(args):
'''
This completer depends on the content of the line, i.e. on
Expand Down Expand Up @@ -334,6 +344,8 @@
if last_keyw is None:
return []

if last_keyw == 'meta':
agent = ra.get_resource_meta()

Check warning on line 348 in crmsh/ui_configure.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_configure.py#L347-L348

Added lines #L347 - L348 were not covered by tests
complete_results = completers_set[last_keyw](agent, args)
if len(args) > 4 and '=' in args[-1]:
return complete_results + keywords
Expand Down Expand Up @@ -1125,7 +1137,7 @@
return self.__conf_object(context.get_command_name(), *args)

@command.skill_level('administrator')
@command.completers_repeating(_prim_meta_completer)
@command.completers_repeating(_rsc_meta_completer)
def do_rsc_defaults(self, context, *args):
"usage: rsc_defaults [$id=<set_id>] <option>=<value>"
return self.__conf_object(context.get_command_name(), *args)
Expand Down
9 changes: 9 additions & 0 deletions crmsh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@
return None


def get_resource_metadata(show_xml=True) -> str:
output_type = "xml" if show_xml else "text"
cmd = f"crm_resource --list-options=primitive --all --output-as={output_type}"
rc, out, _ = ShellUtils().get_stdout_stderr(cmd)
if rc == 0 and out:
return out

Check warning on line 202 in crmsh/utils.py

View check run for this annotation

Codecov / codecov/patch

crmsh/utils.py#L202

Added line #L202 was not covered by tests
return None


def pacemaker_20_daemon(new, old):
"helper to discover renamed pacemaker daemons"
if is_program(new):
Expand Down
1 change: 1 addition & 0 deletions test/testcases/acl.exp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
.INP: _test
.INP: verify
.EXT crm_attribute --list-options=cluster --all --output-as=xml
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: show
node node1
primitive d0 ocf:pacemaker:Dummy \
Expand Down
4 changes: 4 additions & 0 deletions test/testcases/bugs.exp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ clone cl-p5 p5 \
meta interleave=true
colocation c2 inf: ( p1 p2 ) p3 p4
.INP: commit
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: _test
.INP: verify
.INP: show
Expand Down Expand Up @@ -153,6 +154,7 @@ op_defaults op-options: \
.INP: commit
.EXT crm_resource --show-metadata stonith:null
.EXT stonithd metadata
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: _test
.INP: verify
.TRY Unknown properties
Expand All @@ -176,6 +178,7 @@ primitive st stonith:null \
property SAPHanaSR: \
hana_ha1_site_lss_WDF1=4
.INP: commit
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: _test
.INP: verify
.INP: property SAPHanaSR_2: hana_ha1_site_iss_WDF1=cde hana_ha1_site_bss_WDF1=abc
Expand Down Expand Up @@ -211,5 +214,6 @@ INFO: 6: pulling in template virtual-ip
.EXT crm_resource --list-ocf-alternatives IPaddr
.INP: up
.INP: commit
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: _test
.INP: verify
1 change: 1 addition & 0 deletions test/testcases/bundle.exp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
.INP: _test
.INP: verify
.EXT crm_attribute --list-options=cluster --all --output-as=xml
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: show
node node1 \
attributes mem=16G
Expand Down
1 change: 1 addition & 0 deletions test/testcases/commit.exp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.EXT crm_resource --show-metadata stonith:null
.EXT stonithd metadata
.INP: commit
.EXT crm_resource --list-options=primitive --all --output-as=xml
WARNING: 7: st: unknown attribute 'yoyo-meta'
.INP: node node1 attributes mem=16G
.INP: primitive p1 ocf:heartbeat:Dummy op monitor interval=60m op monitor interval=120m OCF_CHECK_LEVEL=10
Expand Down
1 change: 1 addition & 0 deletions test/testcases/confbasic.exp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ INFO: 37: "collocation" is accepted as "colocation"
.INP: set d2.mondelay 45
.INP: _test
.INP: verify
.EXT crm_resource --list-options=primitive --all --output-as=xml
WARNING: 53: c2: resource d1 is grouped, constraints should apply to the group
.EXT crm_attribute --list-options=cluster --all --output-as=xml
.INP: show
Expand Down
1 change: 1 addition & 0 deletions test/testcases/delete.exp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ primitive st stonith:ssh \
op stop timeout=15s interval=0s
location d1-pref d1 100: node1
.INP: verify
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: # delete a group which is in a clone
.INP: primitive d2 ocf:pacemaker:Dummy
.INP: group g1 d2 d1
Expand Down
1 change: 1 addition & 0 deletions test/testcases/edit.exp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ rsc_defaults rsc_options: \
op_defaults op-options: \
timeout=60s
.INP: commit
.EXT crm_resource --list-options=primitive --all --output-as=xml
.EXT crm_attribute --list-options=cluster --all --output-as=xml
.INP: _test
.INP: verify
Expand Down
1 change: 1 addition & 0 deletions test/testcases/file.exp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ op_defaults op-options: \
.EXT crm_resource --show-metadata ocf:heartbeat:Delay
.EXT crm_resource --show-metadata stonith:null
.EXT stonithd metadata
.EXT crm_resource --list-options=primitive --all --output-as=xml
.EXT sed -i 's/60s/2m/' sample.txt
.EXT sed -i '8a # comment' sample.txt
.TRY Load update
Expand Down
1 change: 1 addition & 0 deletions test/testcases/newfeatures.exp
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ alert notify_9 "/usr/share/pacemaker/alerts/alert_snmp.sh" \
.INP: _test
.INP: verify
.EXT crm_attribute --list-options=cluster --all --output-as=xml
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: commit
2 changes: 2 additions & 0 deletions test/testcases/node.exp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ node1: member
.EXT crm_resource --show-metadata stonith:null
.EXT stonithd metadata
.EXT crm_resource --show-metadata ocf:heartbeat:Delay
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: configure
.INP: _regtest on
.INP: show xml node1
Expand All @@ -25,6 +26,7 @@ node1: member
</cib>

.TRY configure group g0 p5
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: configure
.INP: _regtest on
.INP: show xml node1
Expand Down
7 changes: 7 additions & 0 deletions test/testcases/resource.exp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ INFO: Stop tracing p0 for operation stop
</cib>

.TRY configure group g p0 p3
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: configure
.INP: _regtest on
.INP: show xml p0
Expand Down Expand Up @@ -778,6 +779,7 @@ INFO: Stop tracing p0 for operation stop
</cib>

.TRY configure clone cg g
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: configure
.INP: _regtest on
.INP: show xml p0
Expand Down Expand Up @@ -1125,12 +1127,14 @@ INFO: Stop tracing p0 for operation stop
.EXT stonithd metadata
.EXT crm_resource --show-metadata ocf:pacemaker:Dummy
.EXT crm_resource --show-metadata ocf:heartbeat:Delay
.EXT crm_resource --list-options=primitive --all --output-as=xml
.TRY configure primitive p3 Dummy
.EXT crm_resource --show-metadata ocf:heartbeat:Dummy
.EXT crm_resource --show-metadata stonith:null
.EXT stonithd metadata
.EXT crm_resource --show-metadata ocf:pacemaker:Dummy
.EXT crm_resource --show-metadata ocf:heartbeat:Delay
.EXT crm_resource --list-options=primitive --all --output-as=xml
.TRY resource stop p3
.TRY resource start p3
.TRY resource stop p3
Expand All @@ -1139,6 +1143,7 @@ WARNING: This command 'rm' is deprecated, please use 'delete'
INFO: "rm" is accepted as "delete"
.TRY configure ms msg g
WARNING: "ms" is deprecated. Please use "clone msg g meta promotable=true"
.EXT crm_resource --list-options=primitive --all --output-as=xml
.TRY resource scores
.EXT crm_simulate -sUL
2 of 6 resource instances DISABLED and 0 BLOCKED from further action due to failure
Expand Down Expand Up @@ -1180,7 +1185,9 @@ Remaining: node1 capacity:
.EXT stonithd metadata
.EXT crm_resource --show-metadata ocf:pacemaker:Dummy
.EXT crm_resource --show-metadata ocf:heartbeat:Delay
.EXT crm_resource --list-options=primitive --all --output-as=xml
.TRY configure group g1 p5
.EXT crm_resource --list-options=primitive --all --output-as=xml
.TRY resource manage p5
.SETENV showobj=p5
.TRY -F resource maintenance p5 on
Expand Down
1 change: 1 addition & 0 deletions test/testcases/rset.exp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ colocation c3 inf: d3 d1
order o1 Serialize: d1 d3
.INP: _test
.INP: verify
.EXT crm_resource --list-options=primitive --all --output-as=xml
.INP: show
node node1
primitive d1 ocf:pacemaker:Dummy \
Expand Down
Loading