saltstack / saltstack/salt

[BUG] dvs.portgroups_configured attempts to delete DPGs other than one specified, causing state to fail with `The resource '<id>' is in use.`

Open
#62,064 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
When dvs.portgroups_configured is used and a state run is done, Salt attempts to both delete DPGs other than the one specified. Deleting fails if the DPG is already in use, causing the state to fail

Debug:

[DEBUG   ] Rendered data from file: /var/cache/salt/proxy/vcenter01-dc1-cl1/files/base/test.sls:
dvs_VL1313-HV-MGMT:
  dvs.portgroups_configured:
    - name: VL1313-HV-MGMT
    - dvs: DATA
    - portgroups:
        - name: VL1313-HV-MGMT
          type: earlyBinding
          vlan_id: 1313
          description: |
            THIS OBJECT IS MANAGED BY SALT - DO NOT MODIFY
            Any changes to this object may be overwritten automatically and without warning.

            DPG for VLAN 1313 - HV-MGMT - Hypervisor Management

[DEBUG   ] Results of YAML rendering:
OrderedDict([('dvs_VL1313-HV-MGMT', OrderedDict([('dvs.portgroups_configured', [OrderedDict([('name', 'VL1313-HV-MGMT')]), OrderedDict([('dvs', 'DATA')]), OrderedDict([('portgroups', [OrderedDict([('name', 'VL1313-HV-MGMT'), ('type', 'earlyBinding'), ('vlan_id', 1313), ('description', 'THIS OBJECT IS MANAGED BY SALT - DO NOT MODIFY\nAny changes to this object may be overwritten automatically and without warning.\n\nDPG for VLAN 1313 - HV-MGMT - Hypervisor Management\n')])])])])]))])
[PROFILE ] Time (in seconds) to render '/var/cache/salt/proxy/vcenter01-dc1-cl1/files/base/test.sls' using 'yaml' renderer: 0.001766204833984375
[DEBUG   ] LazyLoaded config.option
[DEBUG   ] LazyLoaded dvs.portgroups_configured
[INFO    ] Running state [VL1313-HV-MGMT] at time 05:19:15.932598
[INFO    ] Executing state dvs.portgroups_configured for [VL1313-HV-MGMT]
[DEBUG   ] LazyLoaded vsphere.get_proxy_type
[DEBUG   ] LazyLoaded esxcluster.get_details
[INFO    ] Running state VL1313-HV-MGMT on DVS 'DATA', datacenter 'EGATE-TOR3'
[INFO    ] Checking pg 'VL1313-HV-MGMT'
[DEBUG   ] [ VL1312-HV-VMTN ] Waiting for <class 'pyVmomi.VmomiSupport.vim.Task'> task to finish [0 s]
[ERROR   ] (vim.fault.ResourceInUse) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   msg = "The resource '23' is in use.",
   faultCause = <unset>,
   faultMessage = (vmodl.LocalizableMessage) [
      (vmodl.LocalizableMessage) {
         dynamicType = <unset>,
         dynamicProperty = (vmodl.DynamicProperty) [],
         key = 'com.vmware.vim.vpxd.dvs.pgPortInUse.label',
         arg = (vmodl.KeyAnyValue) [
            (vmodl.KeyAnyValue) {
               dynamicType = <unset>,
               dynamicProperty = (vmodl.DynamicProperty) [],
               key = 'dvpg',
               value = 'VL1312-HV-VMTN'
            },
            (vmodl.KeyAnyValue) {
               dynamicType = <unset>,
               dynamicProperty = (vmodl.DynamicProperty) [],
               key = 'port',
               value = '23'
            }
         ],
         message = 'Distributed Port Group VL1312-HV-VMTN port 23 is in use'
      }
   ],
   type = vim.dvs.DistributedVirtualPort,
   name = '23'
}
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/salt/utils/vmware.py", line 3449, in wait_for_task
    raise task_info.error
pyVmomi.VmomiSupport.vim.fault.ResourceInUse: (vim.fault.ResourceInUse) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   msg = "The resource '23' is in use.",
   faultCause = <unset>,
   faultMessage = (vmodl.LocalizableMessage) [
      (vmodl.LocalizableMessage) {
         dynamicType = <unset>,
         dynamicProperty = (vmodl.DynamicProperty) [],
         key = 'com.vmware.vim.vpxd.dvs.pgPortInUse.label',
         arg = (vmodl.KeyAnyValue) [
            (vmodl.KeyAnyValue) {
               dynamicType = <unset>,
               dynamicProperty = (vmodl.DynamicProperty) [],
               key = 'dvpg',
               value = 'VL1312-HV-VMTN'
            },
            (vmodl.KeyAnyValue) {
               dynamicType = <unset>,
               dynamicProperty = (vmodl.DynamicProperty) [],
               key = 'port',
               value = '23'
            }
         ],
         message = 'Distributed Port Group VL1312-HV-VMTN port 23 is in use'
      }
   ],
   type = vim.dvs.DistributedVirtualPort,
   name = '23'
}
[ERROR   ] Error: The resource '23' is in use.
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/salt/utils/vmware.py", line 3449, in wait_for_task
    raise task_info.error
pyVmomi.VmomiSupport.vim.fault.ResourceInUse: (vim.fault.ResourceInUse) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   msg = "The resource '23' is in use.",
   faultCause = <unset>,
   faultMessage = (vmodl.LocalizableMessage) [
      (vmodl.LocalizableMessage) {
         dynamicType = <unset>,
         dynamicProperty = (vmodl.DynamicProperty) [],
         key = 'com.vmware.vim.vpxd.dvs.pgPortInUse.label',
         arg = (vmodl.KeyAnyValue) [
            (vmodl.KeyAnyValue) {
               dynamicType = <unset>,
               dynamicProperty = (vmodl.DynamicProperty) [],
               key = 'dvpg',
               value = 'VL1312-HV-VMTN'
            },
            (vmodl.KeyAnyValue) {
               dynamicType = <unset>,
               dynamicProperty = (vmodl.DynamicProperty) [],
               key = 'port',
               value = '23'
            }
         ],
         message = 'Distributed Port Group VL1312-HV-VMTN port 23 is in use'
      }
   ],
   type = vim.dvs.DistributedVirtualPort,
   name = '23'
}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/salt/states/dvs.py", line 654, in portgroups_configured
    portgroup=current_pg["name"], dvs=dvs, service_instance=si
  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/vsphere.py", line 372, in __supports_proxies_
    return fn(*args, **salt.utils.args.clean_kwargs(**kwargs))
  File "/usr/lib/python3.6/site-packages/salt/modules/vsphere.py", line 457, in _gets_service_instance_via_proxy_
    ret = fn(*args, **salt.utils.args.clean_kwargs(**kwargs))
  File "/usr/lib/python3.6/site-packages/salt/modules/vsphere.py", line 5471, in remove_dvportgroup
    salt.utils.vmware.remove_dvportgroup(pg_refs[0])
  File "/usr/lib/python3.6/site-packages/salt/utils/vmware.py", line 1539, in remove_dvportgroup
    wait_for_task(task, pg_name, str(task.__class__))
  File "/usr/lib/python3.6/site-packages/salt/utils/vmware.py", line 3460, in wait_for_task
    raise salt.exceptions.VMwareApiError(exc.msg)
salt.exceptions.VMwareApiError: The resource '23' is in use.
[ERROR   ] The resource '23' is in use.
[INFO    ] Completed state [VL1313-HV-MGMT] at time 05:19:17.728933 (duration_in_ms=1796.334)

Setup
/srv/salt/test.sls:

dvs_VL1313-HV-MGMT:
  dvs.portgroups_configured:
    - name: VL1313-HV-MGMT
    - dvs: DATA
    - portgroups:
        - name: VL1313-HV-MGMT
          type: earlyBinding
          vlan_id: 1313
          description: |
            THIS OBJECT IS MANAGED BY SALT - DO NOT MODIFY
            Any changes to this object may be overwritten automatically and without warning.
            
            DPG for VLAN 1313 - HV-MGMT - Hypervisor Management

Steps to Reproduce the behavior
salt minion state.apply test

Expected behavior
The DPG is created or modified as appropriate.

Screenshots

----------
          ID: dvs_VL1313-EGATE-TOR3-HV-MGMT
    Function: dvs.portgroups_configured
        Name: VL1313-EGATE-TOR3-HV-MGMT
      Result: False
     Comment: The resource '23' is in use.
     Started: 04:58:23.468283
    Duration: 3085.144 ms
     Changes:   

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
esxcluster proxy minion against vSphere 7.0.3. pyVmomi 7.0.3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with portgroups_configured in salt/states/dvs.py, then trace the remove_dvportgroup call through salt/modules/vsphere.py and salt/utils/vmware.py. Reproduce with the supplied test.sls and state.apply command; done means the specified DPG is created or modified without attempting to delete other in-use DPGs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.