Addition to: Basic beacons.present state is not working #55591 [BUG]
I tried the fix suggested in Issue #55591 by using
service:
beacon.present:
- save: True
- enable: True
- services:
LogInsightAgentService:
onchangeonly: True
But I get the below errors
ID: service
Function: beacon.present
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/salt/state.py", line 1981, in call
**cdata['kwargs'])
File "/usr/lib/python3.6/site-packages/salt/loader.py", line 1977, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/states/beacon.py", line 130, in present
result = __salt__['beacons.add'](name, beacon_data, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/modules/beacons.py", line 181, in add
valid = event_ret['valid']
TypeError: 'NoneType' object is not subscriptable
Started: 16:40:41.768246
Duration: 60045.085 ms
Changes:
Hey @dtupy Can I get your salt version info and the exact steps to reproduce the issue that you followed from #55591, that would be super helpful in getting this resolved
@dtupy can you send the salt --versions-report, detailing any differences in master/minion versions, and the steps to reproduce for this bug? and/or MCVE: Minimal, Complete, and Verifiable Example?
Same issue here.
$ sudo salt --versions-report
Salt Version:
Salt: 3001
Dependency Versions:
cffi: 1.14.4
cherrypy: 3.5.0
dateutil: 2.4.2
docker-py: Not Installed
gitdb: 0.6.4
gitpython: 1.0.1
Jinja2: 2.8
libgit2: Not Installed
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.5.6
mysql-python: 1.3.7
pycparser: 2.20
pycrypto: 2.6.1
pycryptodome: 3.4.7
pygit2: Not Installed
Python: 3.5.2 (default, Oct 7 2020, 17:19:02)
python-gnupg: 0.3.8
PyYAML: 5.3.1
PyZMQ: 17.1.2
smmap: 0.9.0
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.1.4
System Versions:
dist: ubuntu 16.04 Xenial Xerus
locale: UTF-8
machine: x86_64
release: 4.4.0-200-generic
system: Linux
version: Ubuntu 16.04 Xenial Xerus
This is the state that I'm setting for a Windows minion.
instana-beacon:
beacon.present:
- name: service
- save: True
- services:
instana-agent-service:
onchangeonly: True
emitatstartup: False
Here is one for a Linux minion.
instana-beacon:
beacon.present:
- name: service
- save: True
- services:
instana-agent:
onchangeonly: True
emitatstartup: False
Both are exhibiting the same thing.
ID: instana-beacon
Function: beacon.present
Name: service
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "c:\salt\bin\lib\site-packages\salt-3001-py3.7.egg\salt\state.py", line 2154, in call
*cdata["args"], **cdata["kwargs"]
File "c:\salt\bin\lib\site-packages\salt-3001-py3.7.egg\salt\loader.py", line 2087, in wrapper
return f(*args, **kwargs)
File "c:\salt\bin\lib\site-packages\salt-3001-py3.7.egg\salt\states\beacon.py", line 120, in present
result = __salt__["beacons.modify"](name, beacon_data, **kwargs)
File "c:\salt\bin\lib\site-packages\salt-3001-py3.7.egg\salt\modules\beacons.py", line 288, in modify
valid = event_ret["valid"]
TypeError: 'NoneType' object is not subscriptable
Started: 15:40:35.468015
Duration: 60041.303 ms
Changes:
For what it's worth, I changed the format of the state to the following and it is now working as expected.
instana_service_beacon:
beacon.present:
- save: True
- enable: True
- services:
instana-agent-service:
onchangeonly: True
emitatstartup: False
- beacon_module: service
Thanks everyone for the additional information, I was able to reproduce this and the issue seems to be somewhere in the validation functions that are being run when adding beacons via the state module.
So the root of the issue was in the service beacon itself, the validate function was allowing an incorrect configuration through. The services item must be a dictionary and in this example:
instana-beacon:
beacon.present:
- name: service
- save: True
- services:
instana-agent:
onchangeonly: True
emitatstartup: False
Services ends up being None because of the spacing for the next 3 lines. This small patch catches the case if services isn't a dict. If anyone is able to manually patch and test, that would be great.
diff --git a/salt/beacons/service.py b/salt/beacons/service.py
index 671c95a1d6..5092a302b9 100644
--- a/salt/beacons/service.py
+++ b/salt/beacons/service.py
@@ -26,6 +26,14 @@ def validate(config):
if "services" not in _config:
return False, ("Configuration for service beacon requires services.")
else:
+ if not isinstance(_config["services"], dict):
+ return (
+ False,
+ (
+ "Services configuration item for service beacon must "
+ "be a dictionary."
+ ),
+ )
for config_item in _config["services"]:
if not isinstance(_config["services"][config_item], dict):
return (