Skip to content

Rollback modules script #5140

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

Merged
merged 9 commits into from
Dec 20, 2017
Merged

Rollback modules script #5140

merged 9 commits into from
Dec 20, 2017

Conversation

maddieclayton
Copy link
Contributor

@maddieclayton maddieclayton commented Dec 13, 2017

Description

#4455


This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.
  • The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • PowerShell scripts used in tests should do any necessary setup as part of the test or suite setup, and should not use hard-coded values for locations or existing resources.

Cmdlet Signature Guidelines

  • New cmdlets that make changes or have side effects should implement ShouldProcess and have SupportShouldProcess=true specified in the cmdlet attribute. You can find more information on ShouldProcess here.
  • Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThru parameter.

Cmdlet Parameter Guidelines

  • Parameter types should not expose types from the management library - complex parameter types should be defined in the module.
  • Complex parameter types are discouraged - a parameter type should be simple types as often as possible. If complex types are used, they should be shallow and easily creatable from a constructor or another cmdlet.
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

@cormacpayne
Copy link
Member

@azuresdkci test this please

Copy link
Member

@cormacpayne cormacpayne left a comment

Choose a reason for hiding this comment

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

@maddieclayton a couple of comments to take a look at

# limitations under the License.
# ----------------------------------------------------------------------------------

param(
Copy link
Member

Choose a reason for hiding this comment

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

@maddieclayton I would add a CmdletBinding attribute to this file and implement SupportsShouldProcess so we can pass -WhatIf to see which modules are being deleted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

$repoName = "PSGallery"
}

if (($scope -eq "ModuleList") -and ($listOfModules -eq $null))
Copy link
Member

Choose a reason for hiding this comment

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

@maddieclayton can we create two separate parameter sets, one that takes Scope and another that takes ListOfModules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

$azureRmCurrent = $azureRmAllVersions[0]
$azureRmPrevious = $azureRmAllVersions[1]
$currentDependencies = Find-Module -Name $query -Repository $repoName -RequiredVersion $azureRmCurrent.Version -IncludeDependencies
$previousDependencies = Find-Module -Name $query -Repository $repoName -RequiredVersion $azureRmPrevious.Version -IncludeDependencies
Copy link
Member

Choose a reason for hiding this comment

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

@maddieclayton these two calls to Find-Module ... -IncludeDependencies are very time expensive. The same information we are getting with these calls (dependent module names and versions) is already contained in $azureRmCurrent.Dependencies and $azureRmPrevious.Dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Add-AzureRMAccount
}

$secret = Get-AzureKeyVaultSecret -VaultName kv-azuresdk -Name $vaultKey
Copy link
Member

Choose a reason for hiding this comment

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

@maddieclayton since this cmdlet requires us to have AzureRM.KeyVault installed, we should have a #Requires at the top of this script for AzureRM.KeyVault

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


if ([string]::IsNullOrEmpty($nugetExe))
{
Write-Verbose "Use default nuget path"
Copy link
Member

Choose a reason for hiding this comment

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

@maddieclayton I would change this Write-Verbose to Write-Host, move it below the if-statement, and change the text to

Using the following NuGet path: $nugetExe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


if ([string]::IsNullOrEmpty($repoName))
{
Write-Verbose "Deleting from PSGallery"
Copy link
Member

Choose a reason for hiding this comment

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

@maddieclayton I would change this to Write-Host, moving it below the if-statement, and changing the text to

Deleting modules from the following repository: $repoName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

$ModulesToDelete = Get-TargetModules -scope $scope -moduleList $listOfModules
$ModulesToDelete
$azureModules = Find-Module Azure* -Repository $repoName
$ModulesToDelete | ForEach-Object {
Copy link
Member

Choose a reason for hiding this comment

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

@maddieclayton this should be wrapped in the ShouldProcess

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@maddieclayton
Copy link
Contributor Author

@azuresdkci Test this please

Copy link
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

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

A few minor changes, otherwise LGTM

[Parameter(ParameterSetName='Scope', Mandatory = $true, Position = 0)]
[ValidateSet("AzureRMAndDependencies", "AzureAndDependencies", "NetCoreModules", "AzureStackAndDependencies")]
[string] $scope,
[Parameter(ParameterSetName='ModuleList', Mandatory = $false)]
Copy link
Member

Choose a reason for hiding this comment

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

I think this is mandatory for the ModuleList parameter set, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

[string] $scope,
[Parameter(ParameterSetName='ModuleList', Mandatory = $false)]
[string[]] $listOfModules,
[Parameter(Mandatory = $false)]
Copy link
Member

Choose a reason for hiding this comment

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

One thing that would be nice is the ability to remove specific versions of modules - this would be useful for AzureStack client modules, for example. Having another parameter set with the module list as a HashTable Name => Version or the like would make this possible

Copy link
Member

Choose a reason for hiding this comment

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

Note - this is something we do not need to do for this check-in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Syntax is:
.\DeleteModules.ps1 -moduleVersionTable @(@{"Module" = "AzureRM.Websites"; "Version" = "3.0.0"}, @{"Module" = "AzureRM.Websites"; "Version" = "4.0.0"}) -repoName TestGallery

Does that look good to you?

[Parameter(ParameterSetName='ModuleList', Mandatory = $false)]
[string[]] $listOfModules,
[Parameter(Mandatory = $false)]
[ValidateSet("TestGallery", "PSGallery")]
Copy link
Member

Choose a reason for hiding this comment

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

This seems like it should be a completer. It should be possible to remove a module from any registered repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think I can add an argument completer to a script like this - I could refactor the whole thing into a psm1 with functions you can import but that seems like a lot of work for not much additional functionality. Just deleting the validate set for now and making the default PSGallery.

[string]$repoName,
[string]$moduleName,
[string]$moduleVersion,
$allModules,
Copy link
Member

Choose a reason for hiding this comment

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

what types are these last two parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

$allModules | ForEach-Object {
if ($_.Name -eq $targetName)
{
$moduleNotBeingDeleted = $false
Copy link
Member

Choose a reason for hiding this comment

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

I think we should make this $moduleBeingDeleted and reverse the sense of the bool

Copy link
Member

Choose a reason for hiding this comment

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

Also, I think this would be easier to follow if we used $allModules | Where {$_.Name -eq $targetName} to get the set of elements matching target name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

}
if ($dependencies.Count -ne 0)
{
Write-Warning "$moduleName $moduleVersion is a dependency for $dependencies the module(s) will have an orphaned dependency."
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be a ShouldContinue prompt (which would mean adding a Force parameter)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


$ModulesToDelete = Get-TargetModules -scope $scope -moduleList $listOfModules
$ModulesToDeleteName = $ModulesToDelete | ForEach-Object {$_.Name}
$ModulesToDeleteName
Copy link
Member

Choose a reason for hiding this comment

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

This returns the value on the Output stream. Use Write-Verbose to make this informational

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed - you can run whatif to get the same information.


$context = $null
try {
$context = Get-AzureRMContext
Copy link
Member

Choose a reason for hiding this comment

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

You can use -ErrorAction Stop in this call to ensure that it throws whatever the setting is in the PowerShell session

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@markcowl markcowl dismissed cormacpayne’s stale review December 20, 2017 00:47

All review comments addressed

@markcowl markcowl merged commit 1047cd0 into Azure:preview Dec 20, 2017
@maddieclayton maddieclayton deleted the RollBack branch December 20, 2017 01:14
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.

6 participants