Skip to content

Commit

Permalink
high: cibconfig: don't elide if there are multiple attr lists (of tha…
Browse files Browse the repository at this point in the history
…t type)
  • Loading branch information
krig committed May 18, 2015
1 parent 9ff6fd7 commit a28b7fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
25 changes: 18 additions & 7 deletions modules/cibconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,20 @@ def repr_cli(self, format=1):
first = False
return self._cli_format_and_comment(l, comments, break_lines=(format > 0))

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
Expand All @@ -997,21 +1011,18 @@ def _attr_set_str(self, node, first):
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 = ""
set_name = self.set_names[node.tag]
initial = constants.implicit_initial.get(self.xml_obj_type)
if first and initial is not None and initial == set_name:
ret += ""
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]))
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 Down
5 changes: 4 additions & 1 deletion test/unittests/test_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ def test_pengine_test():
assert obj is not None
data = obj.repr_cli(format=-1)
print "OUTPUT:", data
exp = 'primitive rsc1 ocf:pacemaker:Dummy rule 0: #cluster-name eq clusterA state="/var/run/Dummy-rsc1-clusterA" params rule 0: #cluster-name eq clusterB state="/var/run/Dummy-rsc1-clusterB" op monitor interval=10'
exp = ('primitive rsc1 ocf:pacemaker:Dummy ' +
'params rule 0: #cluster-name eq clusterA state="/var/run/Dummy-rsc1-clusterA" ' +
'params rule 0: #cluster-name eq clusterB state="/var/run/Dummy-rsc1-clusterB" ' +
'op monitor interval=10')
assert data == exp
assert obj.cli_use_validate()

Expand Down
4 changes: 2 additions & 2 deletions test/unittests/test_cliformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ def test_master():

def test_param_rules():
roundtrip('primitive foo Dummy ' +
'rule #uname eq wizbang laser=yes ' +
'params rule #uname eq wizbang laser=yes ' +
'params rule #uname eq gandalf staff=yes')

roundtrip('primitive mySpecialRsc me:Special ' +
'3: rule #uname eq node1 interface=eth1 ' +
'params 3: rule #uname eq node1 interface=eth1 ' +
'params 2: rule #uname eq node2 interface=eth2 port=8888 ' +
'params 1: interface=eth0 port=9999')

Expand Down

0 comments on commit a28b7fb

Please sign in to comment.