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

saltext.vmware.states.license_mgr.present and saltext.vmware.states.license_mgr.absent fail with KeyError: 'changes' #270

Open
ggiesen opened this issue May 21, 2022 · 1 comment

Comments

@ggiesen
Copy link
Contributor

ggiesen commented May 21, 2022

Using the saltext.vmware.states.license_mgr.present state module fails with fails with KeyError: 'changes'.

licence_present.sls:

licence_vsphere:
   vmware_license_mgr.present:
     - license_key: 1A1AA-11111-111AA-1A1AA-1AAAA

Using a vcenter proxy:

vc01:
    The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python3.6/site-packages/salt/metaproxy/proxy.py", line 483, in thread_return
        opts, data, func, args, kwargs
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
        return self.loader.run(run_func, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
        return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
        return callable(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
        return _func_or_method(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/executors/direct_call.py", line 10, in execute
        return func(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
        return self.loader.run(run_func, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
        return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
        return callable(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
        return _func_or_method(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/modules/state.py", line 793, in apply_
        return sls(mods, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/modules/state.py", line 1392, in sls
        ret = st_.state.call_high(high_, orchestration_jid)
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 3279, in call_high
        ret = self.call_chunks(chunks)
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 2497, in call_chunks
        running = self.call_chunk(low, running, chunks)
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 3003, in call_chunk
        running[tag] = self.call(low, chunks, running)
      File "/usr/lib/python3.6/site-packages/salt/utils/decorators/state.py", line 45, in _func
        result = func(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 2237, in call
        self.check_refresh(low, ret)
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 1253, in check_refresh
        if not ret["changes"]:
    KeyError: 'changes'

licence_absent.sls:

licence_vsphere:
   vmware_license_mgr.absent:
     - license_key: 1A1AA-11111-111AA-1A1AA-1AAAA
vc01:
    The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python3.6/site-packages/salt/metaproxy/proxy.py", line 483, in thread_return
        opts, data, func, args, kwargs
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
        return self.loader.run(run_func, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
        return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
        return callable(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
        return _func_or_method(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/executors/direct_call.py", line 10, in execute
        return func(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
        return self.loader.run(run_func, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
        return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
      File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
        return callable(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
        return _func_or_method(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/modules/state.py", line 793, in apply_
        return sls(mods, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/modules/state.py", line 1392, in sls
        ret = st_.state.call_high(high_, orchestration_jid)
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 3279, in call_high
        ret = self.call_chunks(chunks)
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 2497, in call_chunks
        running = self.call_chunk(low, running, chunks)
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 3003, in call_chunk
        running[tag] = self.call(low, chunks, running)
      File "/usr/lib/python3.6/site-packages/salt/utils/decorators/state.py", line 45, in _func
        result = func(*args, **kwargs)
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 2237, in call
        self.check_refresh(low, ret)
      File "/usr/lib/python3.6/site-packages/salt/state.py", line 1253, in check_refresh
        if not ret["changes"]:
    KeyError: 'changes'

The execution modules work, however:

salt vc01 vmware_license_mgr.list:

vc01:
    ----------
    licenses:
        - 1A1AA-AAAA-11AA1-11AA1-1A111
        - 222B2-2BB2B-222BB-22BBB-2BBBB
        - 3C3CC-33333-333CC-3C3CC-3CCCC
        - DD4DD-444DD-D4DDD-4DDDD-D4444

salt vc01 vmware_license_mgr.remove 1A1AA-AAAA-11AA1-11AA1-1A111:

vc01:
    ----------

salt vc01 vmware_license_mgr.list:

vc01:
    ----------
    licenses:
        - 222B2-2BB2B-222BB-22BBB-2BBBB
        - 3C3CC-33333-333CC-3C3CC-3CCCC
        - DD4DD-444DD-D4DDD-4DDDD-D4444

salt vc01 vmware_license_mgr.add 1A1AA-AAAA-11AA1-11AA1-1A111:

vc01:
    ----------
    licenses:
        1A1AA-AAAA-11AA1-11AA1-1A111

salt vc01 vmware_license_mgr.list:

vc01:
    ----------
    licenses:
        - 1A1AA-AAAA-11AA1-11AA1-1A111
        - 222B2-2BB2B-222BB-22BBB-2BBBB
        - 3C3CC-33333-333CC-3C3CC-3CCCC
        - DD4DD-444DD-D4DDD-4DDDD-D4444

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3004.1

Dependency Versions:
          cffi: 1.11.5
      cherrypy: unknown
      dateutil: 2.6.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: 0.26.8
      M2Crypto: 0.35.2
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.14
      pycrypto: Not Installed
  pycryptodome: Not Installed
        pygit2: 0.26.4
        Python: 3.6.8 (default, Nov 17 2021, 16:10:06)
  python-gnupg: Not Installed
        PyYAML: 3.12
         PyZMQ: 19.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: almalinux 8.5 Arctic Sphynx
        locale: UTF-8
       machine: x86_64
       release: 4.18.0-348.20.1.el8_5.x86_64
        system: Linux
       version: AlmaLinux 8.5 Arctic Sphynx

Additional context
vcenter proxy minion against vSphere 7.0.3. pyVmomi 7.0.3

@ggiesen ggiesen changed the title saltext.vmware.states.license_mgr.present fails with KeyError: 'changes' saltext.vmware.states.license_mgr.present and saltext.vmware.states.license_mgr.absent fail with KeyError: 'changes' May 21, 2022
@ggiesen
Copy link
Contributor Author

ggiesen commented May 22, 2022

A workaround is to use a jinja check with module.run:

{% if '1A1AA-AAAA-11AA1-11AA1-1A111' not in salt['vmware_license_mgr.list']()['licenses'] %}
saltmod_license_mgr_add-vsphere
  module.run:
    - vmware_license_mgr.add:
        - license_key: '1A1AA-AAAA-11AA1-11AA1-1A111' 
{% endif %}

This will throw an exception:

vc01:
----------
          ID: saltmod_license_mgr_add-vsphere
    Function: module.run
      Result: True
     Comment: vmware_license_mgr.add: Success
     Started: 06:43:19.459083
    Duration: 384.757 ms
     Changes:   
              ----------
              vmware_license_mgr.add:
                  ----------
                  message:
                      Failed to add a license key due to Exception 'A specified parameter was not correct: licenseKey'
                  result:
                      False

Summary for vc01
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time: 384.757 ms

but will still add the licence if it's not present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant