listen_in/watch_in and AttributeError: 'str' object has no attribute 'iteritems'
Tried to test/apply following scenario:
crontab-env:
file.replace:
- name: /etc/crontab
- pattern: '^MAILTO=.*$'
- repl: 'MAILTO=""'
- prepend_if_not_found: True
- listen_in:
- cron-service
cron-service:
service.running:
- name: crond
- enable: True
and got an error:
# salt 'minion1' state.highstate
minion1:
The minion function caused an exception: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/minion.py", line 1332, in _thread_return
return_data = executor.execute()
File "/usr/lib/python2.7/site-packages/salt/executors/direct_call.py", line 28, in execute
return self.func(*self.args, **self.kwargs)
File "/usr/lib/python2.7/site-packages/salt/modules/state.py", line 722, in highstate
whitelist=kwargs.get('whitelist')
File "/usr/lib/python2.7/site-packages/salt/state.py", line 3274, in call_highstate
return self.state.call_high(high)
File "/usr/lib/python2.7/site-packages/salt/state.py", line 2280, in call_high
ret = self.call_listen(chunks, ret)
File "/usr/lib/python2.7/site-packages/salt/state.py", line 2182, in call_listen
for key, val in six.iteritems(l_in):
File "/usr/lib/python2.7/site-packages/salt/ext/six.py", line 583, in iteritems
return iter(d.iteritems(**kw))
AttributeError: 'str' object has no attribute 'iteritems'
Also it does not restart the service when I replace listen_in with watch_in, but the error disappears:
# salt 'minion1' state.highstate
minion1:
----------
ID: crontab-env
Function: file.replace
Name: /etc/crontab
Result: True
Comment: Changes were made
Started: 01:26:43.944672
Duration: 38.07 ms
Changes:
----------
diff:
---
+++
@@ -1,6 +1,6 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-MAILTO="root"
+MAILTO=""
# For details see man 4 crontabs
----------
ID: cron-service
Function: service.running
Name: crond
Result: True
Comment: The service crond is already running
Started: 01:26:44.652253
Duration: 104.541 ms
Changes:
Summary for minion1
------------
Succeeded: 2 (changed=1)
Failed: 0
------------
Total states run: 2
Total run time: 142.611 ms
Master and minion versions:
master# salt --versions-report
Salt Version:
Salt: 2016.3.3
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 1.5
gitdb: 0.5.4
gitpython: 0.3.2 RC1
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: 0.21.1
Mako: 0.9.1
msgpack-pure: Not Installed
msgpack-python: 0.3.0
mysql-python: 1.2.3
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
python-gnupg: Not Installed
PyYAML: 3.10
PyZMQ: 14.0.1
RAET: Not Installed
smmap: 0.8.2
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.4
System Versions:
dist: Ubuntu 14.04 trusty
machine: x86_64
release: 3.13.0-88-generic
system: Linux
version: Ubuntu 14.04 trusty
minion1# salt-call --versions-report
Salt Version:
Salt: 2016.3.3
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.8
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
Python: 2.7.5 (default, Nov 20 2015, 02:00:19)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.3.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4
System Versions:
dist: centos 7.2.1511 Core
machine: x86_64
release: 3.10.0-327.el7.x86_64
system: Linux
version: CentOS Linux 7.2.1511 Core
Seems only watch works properly - restarts service when changes in another state are present.
watch_in and listen - change the file but do not restart the service.
listen_in raises an error.
Is it documented somewhere that you don't have to use the module type in front of the name?
I was under the impression that you always had to give a type.
This should work.
crontab-env:
file.replace:
- name: /etc/crontab
- pattern: '^MAILTO=.*$'
- repl: 'MAILTO=""'
- prepend_if_not_found: True
- listen_in:
- service: cron-service
cron-service:
service.running:
- name: crond
- enable: True
Yes, it is documented here: https://docs.saltstack.com/en/latest/ref/states/requisites.html#omitting-state-module-in-requisites
Omitting state module in requisites
New in version 2016.3.0.
In version 2016.3.0, the state module name was made optional. If the state module is omitted, all states matching the ID will be required, regardless of which module they are using.
- require:
- vim
Interesting, thanks. Let me try and replicate this.
But nevertheless thanks a lot for the solution ! I'll pay attention on this moment.
It looks like this works if you use listen instead of listen_in, so the following state.
crontab-env:
file.replace:
- name: /etc/crontab
- pattern: '^MAILTO=.*$'
- repl: 'MAILTO=""'
- prepend_if_not_found: True
cron-service:
service.running:
- name: crond
- enable: True
- listen:
- crontab-env
But is should be made to work with listen_in and watch_in. I am going to tag this as a bug and for our core team to look at.
The second problem that the last example with listen does not raise an error, but also does not restart service after crontab replacement:
ID: crontab-env
Function: file.replace
Name: /etc/crontab
Result: True
Comment: Changes were made
Started: 17:50:08.162605
Duration: 38.048 ms
Changes:
----------
diff:
---
+++
@@ -1,6 +1,6 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-MAILTO="root"
+MAILTO=""
# For details see man 4 crontabs
----------
ID: cron-service
Function: service.running
Name: crond
Result: True
Comment: The service crond is already running
Started: 17:50:08.948026
Duration: 116.651 ms
Changes:
Summary for minion1
------------
Succeeded: 2 (changed=1)
Failed: 0
------------
Total states run: 2
Total run time: 154.699 ms
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
Thank you for updating this issue. It is no longer marked as stale.
Still an issue in 3005.1, am getting AttributeError: 'str' object has no attribute 'items' when using listen_in. watch_in works, so if combined with require_in it can replace listen_in if you only need it to run after the given state, not at the very end of the run (although order: last could probably help you with that as well):
- require_in:
- <state id>
- watch_in:
- <state id>
@faivirol We're currently making an effort to clean up some of these older issues. Can you confirm this is still a problem in 3006.x?
-
Yes, I can confirm this is still a problem in 3006.3
Heading off the stale-bot and confirming this 8-year-old bug is still a problem in 3006.7
@HL-SaltBae Thanks for that, but could you quickly retest with the latest 3006.9 which was released on Tuesday 2024-07-30.
@HL-SaltBae Thanks for that, but could you quickly retest with the latest 3006.9 which was released on Tuesday 2024-07-30.
Is this an automated response or are you telling me that a fix to this specific bug was released in 3006.8 or 3006.9?
I can see the value of wanting bug reports from the most recent version, but if the bug itself is this old I think we can pretty well expect that it wasn't fixed accidentally in the most recent release.
@HL-SaltBae The original bug is from when we didn't even have Python 3 updates correctly working, and Python 2.7, hence don't even want to touch that.
Lot of water between that release, also 3006.7 and the just released 3006.9, hence want to have it tested on the latest release, and if it still occurs, some log output showing versions output (helps to know if problem is RedHat or Debian/Ubuntu families) and some log output, since files can have changed quite a bit over the almost 10 years.
I wish we had automated response :rofl:
@HL-SaltBae Closing this due to unresponsive, please feel free to reopen if more information is provided.
This bug was verified in 3006.7. . . you can't close it because "a lot has changed in almost 10 years".
Are you closing ALL bugs every time there is a minor release and asking people to re-verify in the new minor release as a condition for re-opening?
Please take a minute and read the history of this bug.
The bug has been open for 8 years.
- Reported in ver
2016.3.3in Oct 2016 - closed as stale
- Confirmed as not fixed in ver
2018.3.3, in Nov 2018 (when duplicate bug #50682 filed) - assigned to 5 different developers
- closed as stale
- Confirmed as not fixed in ver
3005.1in Mar 2023 - closed as stale
- Confirmed as not fixed in ver
3006.1in Oct 2023 - Confirmed as not fixed in ver
3006.7in Aug 1, 2024 - Developer demands report against
3006.9because "A lot has changed in 10 years" Aug 1, 2024 - closed as "unresponsive" Aug 14, 2024
@HL-SaltBae Lots has changed since 2016.3.3 and most importantly the templates used for reporting issues, That is the reason for the new issue, as this allows for lots of tracking internally, which helps the much reduced Salt Team.
And yes, the Salt Team has been for over a year now closing 10 year plus old bugs, that were still open, and asking that new issues be generated if the problem still occurs. Lots of different code over 10 years, not just Python 2 to 3. But mostly GitHub tracking, please open a new issue for this problem.
Note: issues are generally getting closed if no response within 2-3 weeks to inquiries from Salt Team, a decision made just about a year ago to clear out backlog where the recipient is unresponsive.