Skip to content

Update to PR 35899 states/pkg (refresh fix) and win_pkg (winrepo cache mgt, refresh, doco, performance) - #36222

Merged
UtahDave merged 14 commits into
saltstack:carbonfrom
damon-atkins:update_to_35899_win_pkg
Sep 27, 2016
Merged

UtahDave merged 14 commits into
saltstack:carbonfrom
damon-atkins:update_to_35899_win_pkg

Conversation

@damon-atkins

@damon-atkins damon-atkins commented Sep 12, 2016 •

Copy link
Copy Markdown
Contributor

What does this PR do?

modules/win_pkg.py
Code clean up and improvements based on feed back on the original PR
e.g. dealing with configuration options, and refresh_db
Also:

  • add missing doco mainly around parameters for functions
  • Memory caching of the metadata db per run, instead of reading it multiple times
    from disk.
  • centralised the refresh test, instead of a if statement in most functions, allow better logging etc
  • list_available issue with code which tried sort the list, did not. Now Fixed
  • raise_error renamed to failhard (note this was never in a production release)
  • get_name_map() removed (Add to release notes, use get_repo_data() instead)
  • previous updates for saltenv changes in develop several months ago broke compatibility with older 2015 and 2016 release, updates here to try to fix this.
    e.g.
2016 def list_available(*names):
develop def list_available(saltenv='base', *names)
fixed to def list_available(*names, **kwargs)  saltenv taken from kwargs

states/pkg.py Fixes

  • Fixes installed() in states/pkg.py which was calling calling refresh DB to much. This involved replacing the current code with a new function called _refresh_tag_file()
  • latest() in states/pkgpy change to use the new function _refresh_tag_file()
  • remove windows specific code around refreshing db

config additions
winrepo_cache_expire_max and winrepo_cache_expire_min

What issues does this PR fix or reference?

See PR 35899
Thanks should go to @terminalmage for reviewing not just my code but the whole of win_pkg.py coding and improving it and also bring all of it back into line with salt coding style.

Previous Behavior

Carbon branch has compatibility issues with 2015 and 2016 with saltenv changes
Missing metadata db was reported as an error

New Behavior

More compatible with 2015 and 2016 re saltenv
Package State Files fetched and metadata created if missing or stale.

Tests written?

No Updates tests

Please review Salt's Contributing Guide for best practices.

Damon Atkins added 4 commits September 12, 2016 15:08
code clean up and improvements based on feed back on the orginal PR
e.g. dealing with configuration options, and  refresh_db
Also:
- add missing doco mainly around parmeters to functions
- previous updates for saltenv changes in develop several months ago broke
compatibility with older 2015 and 2016 release, updates here to try to fix this.
@damon-atkins

Copy link
Copy Markdown
Contributor Author

Hi @rallytime
Ready to merge passes all but

default — Pull Requests » Salt PR - Main Build #5229
jenkins/PR/salt-pr-rs-cent7-n — Pull Requests » Salt PR - RS CentOS 7 #5314 — FAILURE

@UtahDave

Copy link
Copy Markdown
Contributor

Hi, @damon-atkins I'm testing this off your PR and I'm getting the following error:

root@bouchamaster:~# time salt davewintest state.highstate
davewintest:
----------
          ID: filezilla
    Function: pkg.installed
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "C:\salt\bin\lib\site-packages\salt\state.py", line 1744, in call
                  **cdata['kwargs'])
                File "C:\salt\bin\lib\site-packages\salt\loader.py", line 1704, in wrapper
                  return f(*args, **kwargs)
                File "C:\salt\bin\lib\site-packages\salt\states\pkg.py", line 1272, in installed
                  **kwargs)
                File "C:\salt\bin\lib\site-packages\salt\states\pkg.py", line 373, in _find_install_targets
                  pkginfo = _get_package_info(name, saltenv=kwargs['saltenv'])
                File "C:\salt\bin\lib\site-packages\salt\modules\win_pkg.py", line 1569, in _get_package_info
                  return get_repo_data(saltenv).get('repo', {}).get(name, {})
                File "C:\salt\bin\lib\site-packages\salt\modules\win_pkg.py", line 1498, in get_repo_data
                  (_, _, winrepo, repo_age_sec) = _get_repo_src_dest_details(saltenv)
                File "C:\salt\bin\lib\site-packages\salt\modules\win_pkg.py", line 584, in _get_repo_src_dest_details
                  winrepo_age = time.time()-os.stat(winrepo_file).st_mtime
              NameError: global name 'time' is not defined
     Started: 12:21:41.868000
    Duration: 60767.0 ms
     Changes:   

Summary for davewintest
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:  60.767 s
ERROR: Minions returned with non-zero exit code

real    1m25.816s
user    0m1.835s
sys 0m0.236s

@damon-atkins

Copy link
Copy Markdown
Contributor Author

Thanks @UtahDave not sure how I missed that. I tested every function within win_pkg. It's good to have a review process. It will be fanatic when windows is tested in Jenkins.

@UtahDave

Copy link
Copy Markdown
Contributor

I added import time to states/pkg.py under the gated windows imports and the error went away.

@UtahDave

Copy link
Copy Markdown
Contributor

Sorry, after that fix I found another thing.

Even with refresh=False the repo is still refreshed.

@UtahDave

Copy link
Copy Markdown
Contributor

Also, I'm still seeing a pkg refresh_db for each pkg.installed in this sls file:

filezilla:
  pkg.installed

pidgin:
  pkg.installed

vlc:
  pkg.installed

ccleaner:
  pkg.installed

@damon-atkins

Copy link
Copy Markdown
Contributor Author

The issue is with states/pkg.py The same issue exist in 2016.3 and most likely earlier see issue 36133. If you wish to test using highstate you need to use pkg.latest which works correctly

C:\salt>salt-call pkg.refresh_db
[ERROR   ] pkgname "dvschedulerX" version "1" within "dvscheduler2.sls", "version number" is not a string
[ERROR   ] pkgname "dvschedulerX" version "2" within "dvscheduler2.sls", "version number" is not a string
[ERROR   ] failed to compile "salt-winrepo-ng\check-mk-agent.sls", check syntax, Conflicting ID 'Not Found'
[ERROR   ] pkgname "duplicati" version "skip_urltest" within "salt-winrepo-ng\duplicati.sls", "version number" is not defined as dictionary(hash) key
[ERROR   ] failed to compile "salt-winrepo-ng\intellij.sls", check syntax, Conflicting ID '1'
Error running 'pkg.refresh_db': Error occurred while generating repo db. Additional info follows:

failed:
    4
failed_list:
    ----------
    dvscheduler2.sls:
        - pkgname "dvschedulerX", version "1" is not a string
        - pkgname "dvschedulerX", version "2" is not a string
    salt-winrepo-ng\check-mk-agent.sls:
        - failed to compile, check syntax, Conflicting ID 'Not Found'
    salt-winrepo-ng\duplicati.sls:
        - pkgname "duplicati", version "skip_urltest" is not defined as a dictionary(hash) key
    salt-winrepo-ng\intellij.sls:
        - failed to compile, check syntax, Conflicting ID '1'
success:
    228
total:
    232

C:\salt>salt-call state.single pkg.installed name=filezilla refresh=False test=True
[ERROR   ] Command 'Import-Module ServerManager' failed with return code: 1
[ERROR   ] output: Import-Module : The specified module 'ServerManager' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module ServerManager
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (ServerManager:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
local:
----------
          ID: filezilla
    Function: pkg.installed
      Result: None
     Comment: The following packages would be installed/updated: filezilla=3.16.0
     Started: 12:12:19.281000
    Duration: 67.0 ms
     Changes:

Summary for local
------------
Succeeded: 1 (unchanged=1)
Failed:    0
------------
Total states run:     1
Total run time:  67.000 ms

C:\salt>salt-call state.single pkg.installed name=filezilla refresh=True test=True
[ERROR   ] Command 'Import-Module ServerManager' failed with return code: 1
[ERROR   ] output: Import-Module : The specified module 'ServerManager' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module ServerManager
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (ServerManager:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
[ERROR   ] pkgname "dvschedulerX" version "1" within "dvscheduler2.sls", "version number" is not a string
[ERROR   ] pkgname "dvschedulerX" version "2" within "dvscheduler2.sls", "version number" is not a string
[ERROR   ] failed to compile "salt-winrepo-ng\check-mk-agent.sls", check syntax, Conflicting ID 'Not Found'
[ERROR   ] pkgname "duplicati" version "skip_urltest" within "salt-winrepo-ng\duplicati.sls", "version number" is not defined as dictionary(hash) key
[ERROR   ] failed to compile "salt-winrepo-ng\intellij.sls", check syntax, Conflicting ID '1'
local:
----------
          ID: filezilla
    Function: pkg.installed
      Result: None
     Comment: The following packages would be installed/updated: filezilla=3.16.0
     Started: 12:12:45.542000
    Duration: 12465.0 ms
     Changes:

Summary for local
------------
Succeeded: 1 (unchanged=1)
Failed:    0
------------
Total states run:     1
Total run time:  12.465 s

C:\salt>salt-call state.single pkg.installed name=filezilla refresh=False test=True
[ERROR   ] Command 'Import-Module ServerManager' failed with return code: 1
[ERROR   ] output: Import-Module : The specified module 'ServerManager' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module ServerManager
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (ServerManager:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
local:
----------
          ID: filezilla
    Function: pkg.installed
      Result: None
     Comment: The following packages would be installed/updated: filezilla=3.16.0
     Started: 12:13:24.389000
    Duration: 69.0 ms
     Changes:

Summary for local
------------
Succeeded: 1 (unchanged=1)
Failed:    0
------------
Total states run:     1
Total run time:  69.000 ms

C:\salt>salt-call state.single pkg.installed name=filezilla  test=True
[ERROR   ] Command 'Import-Module ServerManager' failed with return code: 1
[ERROR   ] output: Import-Module : The specified module 'ServerManager' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module ServerManager
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (ServerManager:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
[ERROR   ] pkgname "dvschedulerX" version "1" within "dvscheduler2.sls", "version number" is not a string
[ERROR   ] pkgname "dvschedulerX" version "2" within "dvscheduler2.sls", "version number" is not a string
[ERROR   ] failed to compile "salt-winrepo-ng\check-mk-agent.sls", check syntax, Conflicting ID 'Not Found'
[ERROR   ] pkgname "duplicati" version "skip_urltest" within "salt-winrepo-ng\duplicati.sls", "version number" is not defined as dictionary(hash) key
[ERROR   ] failed to compile "salt-winrepo-ng\intellij.sls", check syntax, Conflicting ID '1'
local:
----------
          ID: filezilla
    Function: pkg.installed
      Result: None
     Comment: The following packages would be installed/updated: filezilla=3.16.0
     Started: 12:13:47.921000
    Duration: 12415.0 ms
     Changes:

Summary for local
------------
Succeeded: 1 (unchanged=1)
Failed:    0
------------
Total states run:     1
Total run time:  12.415 s

@damon-atkins

damon-atkins commented Sep 13, 2016 •

Copy link
Copy Markdown
Contributor Author

Hi @UtahDave
I have added a patch to Issue 36133 as its not an issue, which is associated with this this PR and the patch needs to be applied to at least 2016, not sure how far back it should go.

Damon Atkins added 3 commits September 14, 2016 00:28
…x 36133 for carbon release, needs fixing older version still

- Remove rtag function which return a file name
- Create a new function called _refresh_tag_file which manages the refresh_db process rather than repeating simillar code in installed() and latest()
- A few spots where missing logic to remove the refresh tag or it was called to late in the code, this has been fixed.
@damon-atkins

Copy link
Copy Markdown
Contributor Author

Hi @UtahDave please re-test.

@UtahDave

Copy link
Copy Markdown
Contributor

@damon-atkins this is looking pretty good according to my tests!

@damon-atkins

Copy link
Copy Markdown
Contributor Author

@meggiebot Please Label C4 & Carbon

@meggiebot

Copy link
Copy Markdown

@damon-atkins I have the issue labeled: #36133 We don't usually add the labels to PRs. I checked in on this and we're doing a final review internally, but it should be good to merge into Carbon shortly.

@terminalmage

Copy link
Copy Markdown
Contributor

@damon-atkins I'm reviewing this right now and also working on cleaning some of this up, so please don't submit any further commits as I'm working on changes of my own.

This parameter is very awkwardly named. It also doesn't exist in any of the other package providers. I don't like the idea of the same function having different features on different platforms, and since there is literally nothing in the Salt codebase which utilizes this argument, I don't think it should be here.

@terminalmage

Copy link
Copy Markdown
Contributor

I also don't understand the reason for the raise_error param that's being passed around. The error contains the results printed via the nested outputter to the console, but the exception (if caught) does retain the info param passed to it as an attribute:

>>> from salt.exceptions import CommandExecutionError
>>> exc = CommandExecutionError('Message goes here', info={'foo': 1, 'bar': 2})
>>> exc.info
{'foo': 1, 'bar': 2}
>>>

Do you have a use case for not raising an exception? In some cases (like in your _refresh_db_conditional() it looks like we're only doing this so we can see if something failed and then raise an exception if there were any failures. However, we're already doing this check in refresh_db() and raising the exception there, so this seems redundant.

@damon-atkins

Copy link
Copy Markdown
Contributor Author

OK. You sort of need a page with common parameter names, so people can pick from them if they need one. I try to grep through all of the files to try and get an existing one.

The problem is that some of the function return different structures based on how many argument are passed, which means its not consistent..

@terminalmage

Copy link
Copy Markdown
Contributor

_refresh_db_conditional() is returning a bool that nothing is ever done with.

@damon-atkins

Copy link
Copy Markdown
Contributor Author

@twangboy get_name_map() what was the reason for making this public
in #26625 does it still need to remain public.

@twangboy

Copy link
Copy Markdown
Contributor

@damon-atkins I don't think it needs to remain public. I probably did it so I could more easily see what I was getting in the name map. Probably forgot to put it back... or thought it may be useful.

@terminalmage

Copy link
Copy Markdown
Contributor

OK, I made that function private again, and also made the last change that @damon-atkins mentioned. I also documented the two new parameters that @damon-atkins added to control whether or not the metadata is refreshed based on age.

I also squashed the changes again and force-pushed the changes to my fork. Once @damon-atkins has had the chance to test this early next week, and we know that no further changes need to be made, then I can submit a pull request to his fork to get my cleanup into this PR.

@damon-atkins

Copy link
Copy Markdown
Contributor Author

Testing Almost Complete. Looking Good So Far

@damon-atkins damon-atkins changed the title Update to PR 35899 Update to PR 35899 win_pkg Sep 26, 2016
@damon-atkins

Copy link
Copy Markdown
Contributor Author

Here are the results of the testing all looking Good.

salt-testing.bat.txt
test.log.txt

@terminalmage

Copy link
Copy Markdown
Contributor

@damon-atkins OK, if you are satisfied then I can submit my changes as a pull request to your fork, and once merged my changes will show up in this PR and we can get it merged.

@damon-atkins

Copy link
Copy Markdown
Contributor Author

Thats fine with me. Just need to line up @UtahDave to test as well.

terminalmage added a commit to terminalmage/salt that referenced this pull request Sep 26, 2016
Also make necessary changes to salt/states/pkg.py to make win_pkg.py
play nicely with it.
@terminalmage

Copy link
Copy Markdown
Contributor

OK, my changes have been submitted in damon-atkins#1.

@UtahDave

Copy link
Copy Markdown
Contributor

This is working fine in the manual tests I've been doing

@UtahDave

Copy link
Copy Markdown
Contributor

@damon-atkins if you can merge terminalmage's changes to your PR, I'll test again.

Updates to  salt/states/pkg.py, modules/win_pkg.py, doc/ref/configuration/minion.rst
@UtahDave
UtahDave merged commit 9d3ad82 into saltstack:carbon Sep 27, 2016
@damon-atkins

Copy link
Copy Markdown
Contributor Author

@UtahDave What about the lint errors from @terminalmage changes.

@UtahDave

Copy link
Copy Markdown
Contributor

I'll get them. Thanks, @damon-atkins !

@terminalmage

Copy link
Copy Markdown
Contributor

It looks like the lint errors did not make it in once merged.

@terminalmage

Copy link
Copy Markdown
Contributor

Oh, I may not have pulled, checking again.

@terminalmage

Copy link
Copy Markdown
Contributor

I did indeed forget to pull. PR incoming.

@terminalmage

Copy link
Copy Markdown
Contributor

#36590 takes care of the lint and fixes a traceback that Dave found in his testing which occurs when an uninstaller does not properly clear the registry entries for the software.

@damon-atkins damon-atkins changed the title Update to PR 35899 win_pkg Update to PR 35899 win_pkg and states/pkg Sep 27, 2016
@damon-atkins
damon-atkins deleted the update_to_35899_win_pkg branch September 27, 2016 04:24
@damon-atkins

Copy link
Copy Markdown
Contributor Author

@meggiebot some items for release notes:

  • get_name_map() removed as a public function, please use get_repo_data() instead which contains the same information and more.
  • Fix: All platforms were performing additional refresh during a state run with pkg.installed
  • New: Smart Management of the package metedata within win_pkg which includes, configuration items winrepo_cache_expire_max (6h) and winrepo_cache_expire_min (0s)
  • Fix: General performance improvements to win_pkg

@damon-atkins damon-atkins changed the title Update to PR 35899 win_pkg and states/pkg Update to PR 35899 states/pkg (refresh fix) and win_pkg (winrepo cache mgt, refresh, doco, performance) Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants