Salt: Windows Chocolatey package provider - State 'pkg.installed' found in SLS '' is unavailable

Created on 2 Nov 2015  路  4Comments  路  Source: saltstack/salt

Hello,

I am trying to write a chocolatey package provider, I am using functions of the existing chocolatey module.
The issue is that Line 320 of the state pkg.py, it assumes that the only windows package provider is win_pkg, and uses _get_package_info.

if salt.utils.is_windows():
    from salt.modules.win_pkg import _get_package_info
    from salt.modules.win_pkg import get_repo_data
    from salt.modules.win_pkg import _get_latest_pkg_version
    from salt.modules.win_pkg import _reverse_cmp_pkg_versions
    from salt.modules.win_pkg import _get_local_repo_dir
    _get_local_repo_dir = _namespaced_function(_get_local_repo_dir, globals())
    _get_package_info = _namespaced_function(_get_package_info, globals())
    get_repo_data = _namespaced_function(get_repo_data, globals())
    _get_latest_pkg_version = \
        _namespaced_function(_get_latest_pkg_version, globals())
    _reverse_cmp_pkg_versions = \
        _namespaced_function(_reverse_cmp_pkg_versions, globals())
    # The following imports are used by the namespaced win_pkg funcs                                                                                                                                                                          
    # and need to be included in their globals.                                                                                                                                                                                                      

......
         if salt.utils.is_windows():                                                                                                                                                                                                         
             pkginfo = _get_package_info(name)                                                                                                                                                                                               
             if not pkginfo:                                                                                                                                                                                                                 
                 return {'name': name,                                                                                                                                                                                                       
                     'changes': {},                                                                                                                                                                                                      
                     'result': False,                                                                                                                                                                                                    
                        'comment': 'Package {0} not found in the '                                                                                                                                                                           
                                    'repository.'.format(name)}                                                                                                                                                                              
             if version is None:                                                                                                                                                                                                             
                 version = _get_latest_pkg_version(pkginfo)     

So, I automatically ends up with the 'Package XXX not found in the repository', since I'm not looking for a win_pkg package, but a Chocolatey package.

I tried to comment out this condition inside a copy of pkg.py that I put in /srv/salt/base/_state/. Then I deployed my new custom pkg state on my minion.
Ever since I deployed my custom pkg state, I always get :

minion1:
----------
          ID: test
    Function: pkg.installed
        Name: Firefox
      Result: False
     Comment: State 'pkg.installed' found in SLS 'testNuget' is unavailable
     Started: 
    Duration: 
     Changes:   

Even when the pkg.py is a simple copy of the original file ....

Question stale

Most helpful comment

Currently you have to use chocolatey.installed instead of pkg.installed. This to me seems like a small hurdle for the large software library available via Chocolatey.org.

All 4 comments

@Pixcell, thanks for working on this. I think the best to do here is reconsider chocolatey, oneget, and salt's internal win_pkg as package providers for windows such that they could be used interchangeably in the pkg state as much as is sensible. There is already a feature request open related to this.

@UtahDave, @TheBigBear, @twangboy

My issue here was a missmatch between my state/pkg.py and the one used by my minion.
It's working again.
But a new issue arose:

Even when a sls file looking like this:


test:
  - pkg.installed:
    - name: Firefox
    - provider: chocolateypkg

The call to

__salt__['pkg.remove'](name)

and

__salt__['pkg.install'](name)

always ends up calling the install and remove functions of the module 'win_pkg.py', instead of the chocolateypkg one's (I am writing the chocolateypkg.py file, it isn't part of your project yet).
On the other hand,

__salt__['pkg.list_pkgs']()

calls my custom list_pkgs function

Currently you have to use chocolatey.installed instead of pkg.installed. This to me seems like a small hurdle for the large software library available via Chocolatey.org.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

Was this page helpful?
0 / 5 - 0 ratings