salt.states.augeas.change: New XML elements created when trying to add attributes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description of Issue/Question
When trying to add attributes to a newly created element in XML using augeas.change and the example shown here https://github.com/hercules-team/augeas/issues/175#issuecomment-286603937 , multiple elements are created instead
Setup
xml file at /tmp/test.xml
<host>
<server name="one" attr1="dog" attr2="brown"/>
<server name="two"/>
</host>
Steps to Reproduce Issue
SLS file:
add test:
augeas.change:
- lens: xml.lns
- context: /files/tmp/test.xml
- changes:
- set host/server[last()+1]/#attribute/name 'new_server'
- set host/server[#attribute/name="new_server"] '#empty'
- set host/server[#attribute/name="new_server"]/#attribute/attr1 'cat'
- set host/server[#attribute/name="new_server"]/#attribute/attr2 'dog'
result:
<host>
<server name="one" attr1="dog" attr2="brown"/>
<server name="two"/>
<server name="new_server"></server>
<server/>
<server attr1="cat"></server>
<server attr2="dog"></server>
</host>
desired result:
<host>
<server name="one" attr1="dog" attr2="brown"/>
<server name="two"/>
<server name="new_server" attr1="cat" attr2="dog"/>
</host>
augtool commands that produce the desired result:
transform Xml.lns incl /tmp/test.xml
load
set /augeas/context /files/tmp/test.xml
set host/server[last()+1]/#attribute/name new_server
set host/server[#attribute/name="new_server"] #empty
set host/server[#attribute/name="new_server"]/#attribute/attr1 cat
set host/server[#attribute/name="new_server"]/#attribute/attr2 dog
save
Note: This works
add test:
augeas.change:
- lens: xml.lns
- context: /files/tmp/test.xml
- changes:
- set host/server[last()+1]/#attribute/name 'new_server'
- set host/server[last()] '#empty'
- set host/server[last()]/#attribute/attr1 'cat'
- set host/server[last()]/#attribute/attr2 'dog'
Versions Report
Salt Version:
Salt: 2017.7.1
Dependency Versions:
cffi: 1.5.2
cherrypy: Not Installed
dateutil: 2.4.2
docker-py: Not Installed
gitdb: 0.6.4
gitpython: 1.0.1
ioflo: Not Installed
Jinja2: 2.8
libgit2: 0.24.0
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: 2.14
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: 0.24.0
Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.2.0
RAET: Not Installed
smmap: 0.9.0
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4
System Versions:
dist: Ubuntu 16.04 xenial
locale: UTF-8
machine: x86_64
release: 4.4.0-96-generic
system: Linux
version: Ubuntu 16.04 xenial
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the SLS example with augeas.change, xml.lns, and /tmp/test.xml, then compare its result with the listed augtool commands. Trace the Salt augeas.change path and its handling of sequential XML node changes; done means the SLS produces one new server element with all three attributes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, xml
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100