saltstack / saltstack/salt

[BUG] win_task.create_task_from_xml doesn't open file

Open
#59,035 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description
xml_path in function win_task.create_task_from_xml doesn't read file
https://github.com/saltstack/salt/blob/master/salt/modules/win_task.py#L649

Setup

minion:

use_superseded:
  - module.run
'Create Tasks':
  module.run:
  - task.create_task_from_xml:
    - name: "\\MyTestTask"
    - xml_path: "{{ salt['environ.get']('SystemDrive') }}\\MyTestTask.xml"

Steps to Reproduce the behavior

salt -G 'os:windows' task.create_task_from_xml name=MyTestTask xml_path="C:\\MyTestTask.xml"
MyWindowsMinion:
    ERROR: Unknown Failure: 0x8004131a

Expected behavior

MyWindowsMinion:
    True

Also the error code is display because, in code is wrote upercase so that doesn't match. https://github.com/saltstack/salt/blob/master/salt/modules/win_task.py#L704

Versions Report

MASTER
Salt Version:
          Salt: 3002.2
 
Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.7.3
     docker-py: Not Installed
         gitdb: 2.0.6
     gitpython: 3.0.7
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.6.1
        pygit2: Not Installed
        Python: 3.8.5 (default, Jul 28 2020, 12:59:40)
  python-gnupg: 0.4.5
        PyYAML: 5.3.1
         PyZMQ: 18.1.1
         smmap: 2.0.5
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.2
 
System Versions:
          dist: ubuntu 20.04 focal
        locale: utf-8
       machine: x86_64
       release: 5.4.0-54-generic
        system: Linux
       version: Ubuntu 20.04 focal

MINION
Salt Version:
          Salt: 3002.2

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: 1.0.0
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.19
      pycrypto: Not Installed
  pycryptodome: 3.9.8
        pygit2: Not Installed
        Python: 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]
  python-gnupg: 0.4.4
        PyYAML: 5.3.1
         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

Additional context

2020-11-27 09:16:20,891 [salt.minion      :1940][ERROR   ][8968] A command in 'task.create_task_from_xml' had a problem: Unknown Failure: 0x8004131a
Traceback (most recent call last):
  File "c:\salt\bin\lib\site-packages\salt-3002.2-py3.7.egg\salt\modules\win_task.py", line 674, in create_task_from_xml
    name, xml_text, TASK_CREATE, user_name, password, logon_type
  File "<COMObject GetFolder>", line 5, in RegisterTask
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, '(1,2)::ERROR: incorrect document syntax', None, 0, -2147216614), None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\salt\bin\lib\site-packages\salt-3002.2-py3.7.egg\salt\minion.py", line 1890, in _thread_return
    function_name, function_args, executors, opts, data
  File "c:\salt\bin\lib\site-packages\salt-3002.2-py3.7.egg\salt\minion.py", line 1846, in _execute_job_function
    return_data = self.executors[fname](opts, data, func, args, kwargs)
  File "c:\salt\bin\lib\site-packages\salt-3002.2-py3.7.egg\salt\executors\direct_call.py", line 12, in execute
    return func(*args, **kwargs)
  File "c:\salt\bin\lib\site-packages\salt-3002.2-py3.7.egg\salt\modules\win_task.py", line 715, in create_task_from_xml
    raise CommandExecutionError(failure_code)
salt.exceptions.CommandExecutionError: Unknown Failure: 0x8004131a

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/modules/win_task.py at create_task_from_xml around lines 649 and 704, then reproduce the reported Windows command with an XML file. Verify how xml_path is handled and how the hexadecimal error code is matched; done means the XML task creation returns True and the reported error is displayed correctly.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.