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

(MODULES-10514) Remove use of version_powershell task in install task #467

Merged
merged 1 commit into from
Jan 29, 2020

Conversation

beechtom
Copy link
Contributor

This removes the use of the version_powershell task in the
install_powershell task. Previously, this task was used to determine
whether the puppet-agent package was already installed. However, some
features used to run the script and parse its output are not available
in versions of powershell older than 3.0.

The install_powershell task instead uses behavior similar to the
version_powershell task by checking the system's registry entries to
check if the puppet-agent package is installed.

@beechtom beechtom requested a review from a team January 28, 2020 22:29
…owershell`

This removes the use of the `version_powershell` task in the
`install_powershell` task. Previously, this task was used to determine
whether the `puppet-agent` package was already installed. However, some
features used to run the script and parse its output are not available
in versions of powershell older than 3.0.

The `install_powershell` task instead uses behavior similar to the
`version_powershell` task by checking the system's registry entries to
check if the `puppet-agent` package is installed.
@beechtom beechtom force-pushed the maint-install-powershell branch from bd24843 to 6b8da89 Compare January 28, 2020 22:37
@puppetcla
Copy link

CLA signed by all contributors.

Copy link
Contributor

@donoghuc donoghuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What powershell < 3 features do not work? Can we figure out a way around it? Seems like we would want to update the version task to work with powershell < 3 if we are testing against it.

@donoghuc
Copy link
Contributor

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> $rootPath = 'HKLM:\SOFTWARE\Puppet Labs\Puppet'
PS C:\Users\Administrator>
PS C:\Users\Administrator> $reg = Get-ItemProperty -Path $rootPath -ErrorAction SilentlyContinue
PS C:\Users\Administrator> if ($null -ne $reg) {
>>   if ($null -ne $reg.RememberedInstallDir64) {
>>     $loc = $reg.RememberedInstallDir64+'VERSION'
>>   } elseif ($null -ne $reg.RememberedInstallDir) {
>>     $loc = $reg.RememberedInstallDir+'VERSION'
>>   }
>> }
>>
PS C:\Users\Administrator> if ( ($null -ne $loc) -and (Test-Path -Path $loc) ) {
>>   Write-Output "{`"version`":`"$(Get-Content -Path $loc -ErrorAction Stop)`",`"source`":`"$($loc.replace('\', '/'))`"
}"
>> } else {
>>   Write-Output '{"version":null,"source":null}'
>> }
>>
{"version":"6.12.0","source":"C:/Program Files/Puppet Labs/Puppet/VERSION"}
PS C:\Users\Administrator> $psversiontable

Name                           Value
----                           -----
CLRVersion                     2.0.50727.8806
BuildVersion                   6.0.6002.18111
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1


PS C:\Users\Administrator>

@beechtom
Copy link
Contributor Author

The version task works in powershell < 3. The issue is how the version task is used by the install task. Currently, the install task uses the $PSScriptRoot variable to get the directory that both scripts were saved to and then uses the ConvertFrom-Json cmdlet to parse the output from the version task. Neither of these are available in powershell < 3.

There are ways to get the parent directory and parse json in powershell < 3, but it seems overly complex for what the install task needs to do, which is just determine if the agent is installed at all, not determine its version or the source.

@lucywyman lucywyman merged commit dada397 into puppetlabs:master Jan 29, 2020
@beechtom beechtom deleted the maint-install-powershell branch January 29, 2020 18:20
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.

4 participants