saltstack / saltstack/salt

[BUG] win_wua.uninstall fails on Python 3 minon

Open
#58,071 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description
Running the following command produces different results on v3000.3 depending on whether Python 2 or 3 is used. This problem is also present in v3001.

Salt-Minion-3000.3-Py2-AMD64-Setup - works fine
Salt-Minion-3000.3-Py3-AMD64-Setup - fails with error: Passed invalid arguments: a bytes-like object is required, not 'str'.

Command:
salt-call --local win_wua.uninstall c01629fc-64ea-45f3-b7cb-cabc7d566933 -l debug

Output:

[DEBUG   ] Reading configuration from c:\salt\conf\minion
[DEBUG   ] Including configuration from 'c:\salt\conf\minion.d\_schedule.conf'
[DEBUG   ] Reading configuration from c:\salt\conf\minion.d\_schedule.conf
[DEBUG   ] Configuration file path: c:\salt\conf\minion
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[DEBUG   ] Grains refresh requested. Refreshing grains.
[DEBUG   ] Reading configuration from c:\salt\conf\minion
[DEBUG   ] Including configuration from 'c:\salt\conf\minion.d\_schedule.conf'
[DEBUG   ] Reading configuration from c:\salt\conf\minion.d\_schedule.conf
[DEBUG   ] Determining pillar cache
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] LazyLoaded win_wua.uninstall
[DEBUG   ] LazyLoaded direct_call.execute
[DEBUG   ] To Be Uninstalled: c01629fc-64ea-45f3-b7cb-cabc7d566933
[DEBUG   ]      Title: Update for Windows Defender Antivirus antimalware platform - KB4052623 (Version 4.18.2001.10)
[DEBUG   ] Uninstalling Updates
[DEBUG   ] Uninstall Failed with WUA, attempting with DISM
[DEBUG   ] ['dism', '/Online', '/Get-Packages']

Passed invalid arguments: a bytes-like object is required, not 'str'.

Usage:

    .. versionadded:: 2017.7.0

    Uninstall updates.

    Args:

        names (str, list):
            A single update or a list of updates to uninstall. This can be any
            combination of GUIDs, KB numbers, or names. GUIDs or KBs are
            preferred.

    Returns:

        dict: A dictionary containing the details about the uninstalled updates

    CLI Examples:

    .. code-block:: bash

        # Normal Usage
        salt '*' win_wua.uninstall KB3121212

        # As a list
        salt '*' win_wua.uninstall guid=['12345678-abcd-1234-abcd-1234567890ab', 'KB1231231']

Traceback (most recent call last):
  File "C:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\utils\win_update.py", line 851, in uninstall
    result = installer.Uninstall()
  File "<COMObject CreateUpdateInstaller>", line 2, in Uninstall
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2145124312), None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\cli\caller.py", line 218, in call
    ret['return'] = self.minion.executors[fname](self.opts, data, func, args, kwargs)
  File "C:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\executors\direct_call.py", line 12, in execute
    return func(*args, **kwargs)
  File "C:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\modules\win_wua.py", line 622, in uninstall
    return wua.uninstall(updates)
  File "C:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\utils\win_update.py", line 880, in uninstall
    if 'kb' + kb in item.lower():
TypeError: a bytes-like object is required, not 'str'

Setup
Install Salt-Minion-3000.3-Py3-AMD64-Setup

Steps to Reproduce the behavior

  1. Get a valid patch number by listing installed patches.
    salt-call --local win_wua.list skip_installed=false

  2. Run the following command, replacing the UUID with a valid one form step #1.
    salt-call --local win_wua.uninstall c01629fc-64ea-45f3-b7cb-cabc7d566933 -l debug

  3. There is a note in salt.utils.win_update.WindowsUpdateAgent.uninstall() that could affect how this issue is reproduced:

            Starting with Windows 10 the Windows Update Agent is unable to
            uninstall updates. An ``Uninstall Not Allowed`` error is returned.
            If this error is encountered this function will instead attempt to
            use ``dism.exe`` to perform the un-installation. ``dism.exe`` may
            fail to to find the KB number for the package. In that case, removal
            will fail.

The code that is failing is in the error handler that is executed only if Windows Update Agent fails. I'm not sure what triggers that, but you will only see this error if you make it to the code that executes dism.exe after WUA fails.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Versions Report

Salt Version:
           Salt: 3000.3

Dependency Versions:
           cffi: 1.12.2
       cherrypy: 17.4.1
       dateutil: 2.8.0
      docker-py: Not Installed
          gitdb: 2.0.5
      gitpython: Not Installed
         Jinja2: 2.10.1
        libgit2: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.7
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: 2.19
       pycrypto: Not Installed
   pycryptodome: 3.8.1
         pygit2: Not Installed
         Python: 3.5.4 (v3.5.4:3f56838, Aug  8 2017, 02:17:05) [MSC v.1900 64 bit (AMD64)]
   python-gnupg: 0.4.4
         PyYAML: 5.1.2
          PyZMQ: 18.0.1
          smmap: 2.0.5
        timelib: 0.2.4
        Tornado: 4.5.3
            ZMQ: 4.3.1

System Versions:
           dist:
         locale: cp1252
        machine: AMD64
        release: 2019Server
         system: Windows
        version: 2019Server 10.0.17763 SP0 Multiprocessor Free

Additional context
Add any other context about the problem here.

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 in salt/utils/win_update.py at WindowsUpdateAgent.uninstall(), especially the error handler around line 880 that processes DISM output after WUA fails. Reproduce with salt-call --local win_wua.uninstall using a valid update UUID on Python 3, then verify that the DISM fallback no longer raises the bytes-versus-str error and proceeds with update removal.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.