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

[BUG] win_wua.uninstall fails on Python 3 minon #58071

Open
amendlik opened this issue Jul 29, 2020 · 2 comments
Open

[BUG] win_wua.uninstall fails on Python 3 minon #58071

amendlik opened this issue Jul 29, 2020 · 2 comments
Labels
Bug broken, incorrect, or confusing behavior python3 regarding Python 3 support severity-low 4th level, cosemtic problems, work around exists
Milestone

Comments

@amendlik
Copy link
Contributor

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 Enable regex on the salt cli #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.

@amendlik amendlik added the Bug broken, incorrect, or confusing behavior label Jul 29, 2020
@twangboy twangboy self-assigned this Jul 29, 2020
@cmcmarrow cmcmarrow added python3 regarding Python 3 support severity-low 4th level, cosemtic problems, work around exists labels Jul 29, 2020
@cmcmarrow cmcmarrow added this to the Approved milestone Jul 29, 2020
@cmcmarrow
Copy link
Contributor

@amendlik thanks for the bug report. Looks like @twangboy took the job.

@rosscdh
Copy link

rosscdh commented Jan 12, 2022

+1 func does not take kwargs.. only list and that also does not work with more than 1 value

need to execute with right quoting

docker exec -it salt-master salt 'ws02' win_wua.uninstall "['KB4023057','KB4052623']"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior python3 regarding Python 3 support severity-low 4th level, cosemtic problems, work around exists
Projects
None yet
Development

No branches or pull requests

4 participants