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

When generating CIB syntax, elide initial in some cases #96

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
48 changes: 32 additions & 16 deletions modules/cibconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,33 +978,51 @@ def repr_cli(self, format=1):
desc = self.node.get("description")
if desc:
l.append(nvpair_format("description", desc))
first = True
for c in self.node.iterchildren():
if is_comment(c):
comments.append(c.text)
continue
s = self._repr_cli_child(c, format)
s = self._repr_cli_child(c, format, first)
if s:
l.append(s)
first = False
return self._cli_format_and_comment(l, comments, break_lines=(format > 0))

def _attr_set_str(self, node):
def _may_elide_initial(self, xml_attr_list_name):
"""
If true, may generate elided initial attribute
list typename. The idea is that this will be
false where there are multiple attribute lists.
"""
attr_list_name = self.set_names[xml_attr_list_name]
initial = constants.implicit_initial.get(self.xml_obj_type)
if len(self.node.xpath('./%s' % (xml_attr_list_name))) > 1:
return False
if initial is None:
return False
return initial == attr_list_name

def _attr_set_str(self, node, first):
'''
Add $id=<id> if the set id is referenced by another
element.

also show rule expressions if found
'''

# has_nvpairs = len(node.xpath('.//nvpair')) > 0
has_nvpairs = len(node.xpath('.//nvpair')) > 0
idref = node.get('id-ref')

# don't skip empty sets: skipping these breaks
# patching
# empty set
# if not (has_nvpairs or idref is not None):
# return ''

ret = "%s " % (clidisplay.keyword(self.set_names[node.tag]))
if first and (has_nvpairs or idref is not None) and self._may_elide_initial(node.tag):
ret = ""
else:
ret = "%s " % (clidisplay.keyword(self.set_names[node.tag]))
node_id = node.get("id")
if node_id is not None and cib_factory.is_id_refd(node.tag, node_id):
ret += "%s " % (nvpair_format("$id", node_id))
Expand All @@ -1021,13 +1039,11 @@ def _attr_set_str(self, node):
for c in node.iterchildren():
if c.tag == "nvpair":
ret += "%s " % (cli_nvpair(c))
if ret[-1] == ' ':
ret = ret[:-1]
return ret
return ret.rstrip()

def _repr_cli_child(self, c, format):
def _repr_cli_child(self, c, format, first):
if c.tag in self.set_names:
return self._attr_set_str(c)
return self._attr_set_str(c, first)

def _get_oldnode(self):
'''
Expand Down Expand Up @@ -1408,9 +1424,9 @@ def _repr_cli_head(self, format):
id = clidisplay.id(self.obj_id)
return "%s %s %s" % (s, id, rsc_spec)

def _repr_cli_child(self, c, format):
def _repr_cli_child(self, c, format, first):
if c.tag in self.set_names:
return self._attr_set_str(c)
return self._attr_set_str(c, first)
elif c.tag == "operations":
return cli_operations(c, break_lines=(format > 0))

Expand Down Expand Up @@ -1674,7 +1690,7 @@ def _repr_cli_head(self, format):
s = "%s %s: %s" % (s, score, pref_node)
return s

def _repr_cli_child(self, c, format):
def _repr_cli_child(self, c, format, first):
if c.tag == "rule":
return "%s %s" % \
(clidisplay.keyword("rule"), cli_rule(c))
Expand Down Expand Up @@ -1879,7 +1895,7 @@ def _repr_cli_head(self, format):
return "%s %s" % (clidisplay.keyword(self.obj_type),
head_id_format(self.obj_id))

def _repr_cli_child(self, c, format):
def _repr_cli_child(self, c, format, first):
if c.tag == "rule":
return ' '.join((clidisplay.keyword("rule"),
cli_rule(c)))
Expand Down Expand Up @@ -1958,7 +1974,7 @@ def _repr_cli_head(self, format):
for x in dd.keys()],
break_lines=(format > 0))

def _repr_cli_child(self, c, format):
def _repr_cli_child(self, c, format, first):
pass # no children here

def check_sanity(self):
Expand Down Expand Up @@ -2001,7 +2017,7 @@ def _repr_cli_head(self, format):
id = clidisplay.id(self.obj_id)
return "%s %s" % (s, id)

def _repr_cli_child(self, c, format):
def _repr_cli_child(self, c, format, first):
if c.tag in constants.acl_rule_names:
return cli_acl_rule(c, format)
elif c.tag == "role_ref":
Expand Down
9 changes: 9 additions & 0 deletions modules/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
"fencing-topology": "fencing_topology",
"tag": "tag"
}
# xml name => implicit initial
implicit_initial = {
"node": "attributes",
"primitive": "params",
"template": "params",
"master": "params",
"clone": "params",
"group": "params"
}
container_tags = ("group", "clone", "ms", "master")
clonems_tags = ("clone", "ms", "master")
resource_tags = ("primitive", "group", "clone", "ms", "master", "template")
Expand Down
2 changes: 1 addition & 1 deletion test/testcases/acl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ show ACL
node node1
property enable-acl=true
primitive st stonith:ssh \
params hostlist='node1' \
hostlist='node1' \
meta target-role="Started" \
op start requires=nothing timeout=60s \
op monitor interval=60m timeout=60s
Expand Down
4 changes: 2 additions & 2 deletions test/testcases/acl.exp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.INP: erase nodes
.INP: node node1
.INP: property enable-acl=true
.INP: primitive st stonith:ssh params hostlist='node1' meta target-role="Started" op start requires=nothing timeout=60s op monitor interval=60m timeout=60s
.INP: primitive st stonith:ssh hostlist='node1' meta target-role="Started" op start requires=nothing timeout=60s op monitor interval=60m timeout=60s
.INP: primitive d0 ocf:pacemaker:Dummy
.INP: primitive d1 ocf:pacemaker:Dummy
.INP: role basic-read read status read type:node attribute:uname read type:node attribute:type read property
Expand All @@ -30,7 +30,7 @@ node node1
primitive d0 ocf:pacemaker:Dummy
primitive d1 ocf:pacemaker:Dummy
primitive st stonith:ssh \
params hostlist=node1 \
hostlist=node1 \
meta target-role=Started \
op start requires=nothing timeout=60s interval=0 \
op monitor interval=60m timeout=60s
Expand Down
2 changes: 1 addition & 1 deletion test/testcases/bugs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ up
configure
erase
primitive st stonith:null \
params hostlist='node1' \
hostlist='node1' \
meta description="some description here" \
op start requires=nothing \
op monitor interval=60m
Expand Down
8 changes: 4 additions & 4 deletions test/testcases/bugs.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.INP: up
.INP: configure
.INP: erase
.INP: primitive st stonith:null params hostlist='node1' meta description="some description here" op start requires=nothing op monitor interval=60m
.INP: primitive st stonith:null hostlist='node1' meta description="some description here" op start requires=nothing op monitor interval=60m
.INP: primitive p4 Dummy
.INP: primitive p3 Dummy
.INP: primitive p2 Dummy
Expand All @@ -24,7 +24,7 @@ colocation c2 inf: ( p1 p2 ) p3 p4
.INP: show
node node1
primitive st stonith:null \
params hostlist=node1 \
hostlist=node1 \
meta description="some description here" \
op start requires=nothing interval=0 \
op monitor interval=60m
Expand All @@ -46,7 +46,7 @@ colocation c2 inf: ( p1 p2 ) p3 p4
.INP: show
node node1
primitive st stonith:null \
params hostlist=node1 \
hostlist=node1 \
meta description="some description here" \
op start requires=nothing interval=0 \
op monitor interval=60m
Expand All @@ -67,7 +67,7 @@ colocation c2 inf: ( p1 p2 ) p3 p4
.INP: show
node node1
primitive st stonith:null \
params hostlist=node1
hostlist=node1
primitive p4 Dummy
primitive p3 Dummy
primitive p2 Dummy
Expand Down
4 changes: 2 additions & 2 deletions test/testcases/commit
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
show Commits of all kinds
property default-action-timeout=2m
primitive st stonith:null \
params hostlist='node1' \
hostlist='node1' \
meta yoyo-meta="yoyo 2" \
op start requires=nothing \
op monitor interval=60m
commit
node node1 \
attributes mem=16G
mem=16G
primitive p1 ocf:heartbeat:Dummy \
op monitor interval=60m \
op monitor interval=120m OCF_CHECK_LEVEL=10
Expand Down
8 changes: 4 additions & 4 deletions test/testcases/commit.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
.INP: erase
.INP: erase nodes
.INP: property default-action-timeout=2m
.INP: primitive st stonith:null params hostlist='node1' meta yoyo-meta="yoyo 2" op start requires=nothing op monitor interval=60m
.INP: primitive st stonith:null hostlist='node1' meta yoyo-meta="yoyo 2" op start requires=nothing op monitor interval=60m
.INP: commit
.EXT crm_resource --show-metadata stonith:null
.EXT stonithd metadata
.EXT crmd metadata
.EXT pengine metadata
.EXT cib metadata
ERROR: 7: st: attribute yoyo-meta does not exist
.INP: node node1 attributes mem=16G
.INP: node node1 mem=16G
.INP: primitive p1 ocf:heartbeat:Dummy op monitor interval=60m op monitor interval=120m OCF_CHECK_LEVEL=10
.INP: primitive p2 ocf:heartbeat:Dummy
.INP: primitive p3 ocf:heartbeat:Dummy
Expand Down Expand Up @@ -52,7 +52,7 @@ INFO: 24: resource references in order:o1 updated
ERROR: 35: st: attribute yoyo-meta does not exist
.INP: show
node node1 \
attributes mem=16G
mem=16G
primitive d1 Dummy
primitive d3 Dummy
primitive p1 Dummy \
Expand All @@ -61,7 +61,7 @@ primitive p1 Dummy \
primitive p2 Dummy
primitive p3 Dummy
primitive st stonith:null \
params hostlist=node1 \
hostlist=node1 \
meta yoyo-meta="yoyo 2" \
op start requires=nothing interval=0 \
op monitor interval=60m
Expand Down
8 changes: 4 additions & 4 deletions test/testcases/confbasic
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ show Basic configure
node node1
delete node1
node node1 \
attributes mem=16G
mem=16G
node node2 utilization cpu=4
primitive st stonith:ssh \
params hostlist='node1 node2' \
hostlist='node1 node2' \
meta target-role="Started" \
op start requires=nothing timeout=60s \
op monitor interval=60m timeout=60s
primitive st2 stonith:ssh \
params hostlist='node1 node2'
hostlist='node1 node2'
primitive d1 ocf:pacemaker:Dummy \
operations $id=d1-ops \
op monitor interval=60m \
op monitor interval=120m OCF_CHECK_LEVEL=10
monitor d1 60s:30s
primitive d2 ocf:heartbeat:Delay \
params mondelay=60 \
mondelay=60 \
op start timeout=60s \
op stop timeout=60s
monitor d2:Started 60s:30s
Expand Down
8 changes: 4 additions & 4 deletions test/testcases/confbasic-xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ showxml Basic configure (xml dump)
node node1
delete node1
node node1 \
attributes mem=16G
mem=16G
node node2 utilization cpu=4
primitive st stonith:ssh \
params hostlist='node1 node2' \
hostlist='node1 node2' \
meta target-role=Started \
op start requires=nothing timeout=60s \
op monitor interval=60m timeout=60s
primitive st2 stonith:ssh \
params hostlist='node1 node2'
hostlist='node1 node2'
primitive d1 ocf:pacemaker:Dummy \
operations $id=d1-ops \
op monitor interval=60m \
op monitor interval=120m OCF_CHECK_LEVEL=10
monitor d1 60s:30s
primitive d2 ocf:heartbeat:Delay \
params mondelay=60 \
mondelay=60 \
op start timeout=60s \
op stop timeout=60s
monitor d2:Started 60s:30s
Expand Down
16 changes: 8 additions & 8 deletions test/testcases/confbasic.exp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
.INP: erase nodes
.INP: node node1
.INP: delete node1
.INP: node node1 attributes mem=16G
.INP: node node1 mem=16G
.INP: node node2 utilization cpu=4
.INP: primitive st stonith:ssh params hostlist='node1 node2' meta target-role="Started" op start requires=nothing timeout=60s op monitor interval=60m timeout=60s
.INP: primitive st2 stonith:ssh params hostlist='node1 node2'
.INP: primitive st stonith:ssh hostlist='node1 node2' meta target-role="Started" op start requires=nothing timeout=60s op monitor interval=60m timeout=60s
.INP: primitive st2 stonith:ssh hostlist='node1 node2'
.INP: primitive d1 ocf:pacemaker:Dummy operations $id=d1-ops op monitor interval=60m op monitor interval=120m OCF_CHECK_LEVEL=10
.INP: monitor d1 60s:30s
.INP: primitive d2 ocf:heartbeat:Delay params mondelay=60 op start timeout=60s op stop timeout=60s
.INP: primitive d2 ocf:heartbeat:Delay mondelay=60 op start timeout=60s op stop timeout=60s
.INP: monitor d2:Started 60s:30s
.INP: group g1 d1 d2
.INP: primitive d3 ocf:pacemaker:Dummy
Expand Down Expand Up @@ -61,7 +61,7 @@
.EXT cib metadata
.INP: show
node node1 \
attributes mem=16G
mem=16G
node node2 \
utilization cpu=4
primitive d1 ocf:pacemaker:Dummy \
Expand All @@ -70,7 +70,7 @@ primitive d1 ocf:pacemaker:Dummy \
op monitor interval=120m OCF_CHECK_LEVEL=10 \
op monitor interval=60s timeout=30s
primitive d2 Delay \
params mondelay=45 \
mondelay=45 \
op start timeout=60s interval=0 \
op stop timeout=60s interval=0 \
op monitor role=Started interval=60s timeout=30s
Expand All @@ -84,12 +84,12 @@ primitive s5 ocf:pacemaker:Stateful \
primitive s6 ocf:pacemaker:Stateful \
operations $id-ref=d1-ops
primitive st stonith:ssh \
params hostlist="node1 node2" \
hostlist="node1 node2" \
meta target-role=Started \
op start requires=nothing timeout=60s interval=0 \
op monitor interval=60m timeout=60s
primitive st2 stonith:ssh \
params hostlist="node1 node2"
hostlist="node1 node2"
group g1 d1 d2
ms m d4
ms m5 s5
Expand Down
2 changes: 1 addition & 1 deletion test/testcases/delete
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ erase nodes
node node1
# create one stonith so that verify does not complain
primitive st stonith:ssh \
params hostlist='node1' \
hostlist='node1' \
meta target-role="Started" \
op start requires=nothing timeout=60s \
op monitor interval=60m timeout=60s
Expand Down
Loading