Repository navigation
Description
I'm currently using the win_update module to manage updates on some Windows boxes: I set it up following the documentation for the module whenever possible and then relying on the win_update state docs for the includes parameter which is undocumented in the module.
I set it to avoid updates that required reboot, but yet I still needed to reboot the machine.
I dug more into this, so I found some weird things within the module/state code itself and weird differences between them.
I appreciate there's no technical need to have them as similar as possible, but having different default values or different behaviours makes it a bit confusing to me.
I think the confusion begins with the parameter name "includes" and its internal variable names (skip*): if I understand correctly, if I either set UI, downloaded, present, installed, reboot, hidden to True, Salt will skip those categories of updates; yet if I set software or driver to True, that will include them. This is confusing and undocumented.
TL;DR jump to Conclusion
SALT.STATES.WIN_UPDATE
Default values
| Name | Value |
|---|---|
| UI | True |
| Downloaded | True |
| Installed | True |
| Reboot | False |
| Present | True |
| Software | True |
| Driver | False |
Behaviour
Behaviour seems to be correct: if skipInstalled is set to True it will add IsInstalled=0 to the search string; however when it comes to skipReboot it seems to be the other way round and broken:
source
if self.skipReboot:
searchParams.append('RebootRequired=1')
else:
searchParams.append('RebootRequired=0')
Also setting UI doesn't seem to make any difference as the only logic that concerns that variable is simply its declaration and assignment.
SALT.MODULES.WIN_UPDATE
Default values
Default values are different from the state and this is not documented (well, there's no documentation at all for the module).
| Name | Value |
|---|---|
| UI | True |
| Downloaded | FALSE |
| Installed | True |
| Reboot | False |
| Present | FALSE |
| Software | True |
| Driver | False |
Behaviour
Behaviour seems to be fully correct this time, however while in the state there's an if/else logic:
if variable:
set("variable", 1)
else:
set("variable", 0)
in the module we simply have an if logic:
if variable:
set("variable", 1)
Not sure how Windows Update handles the missing search string and what default values it has: if unset means 0 or a default value.
Setting UI doesn't seem to make any difference in the module as well as the only logic that concerns that variable is simply its declaration and assignment (just like in the state).
One more missing thing
After installing updates, Salt Minion will return a list of updates with the result code + update name following the installation, similarly to this:
2 : Windows Server 2012 Update (KB123456)
4 : Internet Explorer Security Update (KB098765)
2 : Malware Definition Update (KB321456)
...
yet those return codes are not documented and if you do a quick search on the Internet you'll get web results that link to pages similar to this, this,... instead of unofficial source codes that appear to finally shed some light.
Conclusion
I think there are a few issues:
- Inconsistent default values between win_update module and state;
- The module has no documentation regarding
includes; - State's
skipRebootseems to be the other way round; - UI (skipUI) apparently has no effect;
includesparameter name is confusing as, exceptsoftwareanddriver, nothing is really "included" but rather "excluded" if set toTrueorFalseas it skips those items;- Windows Update's return codes are undocumented and hard to find, providing documentation or official links from Microsoft Knowledge Base would be beneficial
I might have got it all wrong, in fact this is just the result of a series of doubts of mine 😄 .
So all of this is up for discussion of course, in fact I'd like to hear some feedback on this.
Many thanks!
Activity
cachedout commentedon Dec 30, 2015
Hi @mpreziuso
I wish all bug reports were like this. Well done!
@twangboy and @UtahDave along with @Narcolapser and @nmadhok are the first people who come to mind here. I'd like to hear from all of them about the concerns you've raised.
mpreziuso commentedon Dec 30, 2015
😄
Perfect, thanks very much!
Narcolapser commentedon Dec 31, 2015
Let me be the first to tell you that my code has some funky bugs in it. I had some unfortunate problems that keep me from being able to work on this module/state for a while, and now I've been deported, moved across an ocean, got married, and changed jobs so I really haven't been able to get back to it despite a desire to. All that to say, my desktop is in a box, so I have no access to my windows VM. I can give not but advice and guidance until Tuesday when my new case arrives.
Anyway, if you've seen the source you'll notice that I've actually re-created all of the module in the state, this is horribly inefficient, but was faster at the time. It would be much better done going by having the state use the module through salt's internals. If we fix that it should clear up some inconsistencies between the two. The module is the older of the two and needs the updates I did in the state. Also if you look closely at the module you will find references to Harry Potter I missed. (see original naming scheme here)
I agree with you totally in the general idea. My gut tells me that I did it the way I did for a reason. Can you confirm that when you give it the state of 'skipReboot = True' it skips those which require rebooting? I feel like I had to flip that flag around because of some backwardness of the windows API but can't remember for sure.
As to the inconsistencies between the defaults... huh. You got me there. I'm not sure why I made those different. Let me fiddle with a few quick changes...
Narcolapser commentedon Dec 31, 2015
Ok, so I updated it a little bit, give that a try and see if it gets you anywhere.
Two other comments. Sorry for no documentation at the top, but the individual functions are documented if you pull up salt minion sys.doc win_update.function you can read it. Other comment, about the codes that return from the windows update process, sorry bro, that's Microsoft's failing. I'd love to include more information but that is way beyond the scope of this module. (If I understand you correctly.)
mpreziuso commentedon Dec 31, 2015
Hi @Narcolapser, thanks very much for your feedback and your insights on this!
Hmm I'm afraid I'm not able to either confirm or deny at the moment...
If I run
win_update.list_updateswithreboot=Falseand then withreboot=True, I get the same list of updates on my environments. Interestingly, if I "inspect" those updates withwin_wua.list_update name=KBxxxxxxI'm gettingRebootBehavior: Can Require Rebootwhich is neither a yes or a no [ source ].So I'm not sure what I did back then but the machine needed a reboot; I could have just set the wrong value (True/False) as I was deceived by the variable name - in fact let's remember this is the event that made me go and look at the source code -... and I'm not entirely sure if I either run the state or the module at that time (as I started using states in my project and moved to modules as I think it's more suitable).
Sorry about that.
What shall we do about that: use the module's if logic or the state one?
Speaking of the new commit, I have a couple of small notes:
self.softwareUpdatesandself.driverUpdatesstill exist, but while adding thenotin theifstatement you also renamed those asself.skipSoftwareUpdatesandself.skipDriverUpdatesthat do not exist.So just, small oversights ... but it looks better now. :)
RE Return codes, you're right... it's way beyond the scope of this module: it's just a thing that it would be nice to have from a user perspective for completeness, but considering that it's not publicly documented AFAIK, I think we wouldn't even be able to keep it up to date if any changes were introduced etc... annoying, I'll see if I can find any better documentation on that.
Does Windows Update return any result "message" along with the code? If so, we could add it to the response (as - I think - replacing the code with a message could otherwise break third party custom scripts).
mpreziuso commentedon Jan 4, 2016
Hi @Narcolapser, happy new year!
I just forked your fork and pushed some commits that contains fixes for those typos and some basic documentation at the top of it: https://github.com/mpreziuso/salt/commits/patch-1.
I didn't want to add the
includespart, because I feel like it's an inappropriate name for that variable, what are your suggestions about that?EDIT: What about
skipUI, am I wrong for saying that setting it has no effect except for simply setting the variable? - Which makes sense, but what's the point of having it in the options?EDIT 2: This automatically skips updates that require User Interaction, but apparently it doesn't necessarily take into account updates that requires EULA acceptance (as it can be accepted via Shell prompt); Salt should probably skip that as well by adding
if update.EulaAccepted == False: continueor something similar; thoughts?EDIT 3: And what about
skipHiddenin both the module and the state, the variable is honoured but it can't be actually set from the arguments:SetIncludedoesn't set the object's variable; is there a reason for that or just an oversight? (See https://github.com/mpreziuso/salt/commit/08d2b522208173aedbfabc3bc0902aef6f062062)EDIT 4: Are you sure about the
RebootRequired=1issue? The official documentation claims to be 0 and 1 accordingly if they require a reboot or not and they claim it to be this way till:mpreziuso commentedon Jan 11, 2016
Hi @Narcolapser, any updates on this?
EDIT: In my branch, I changed the parameter name to "skips" rather than "includes".
stale commentedon Mar 11, 2018
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.