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

Introduce Azure Maps cmdlets #6259

Merged
merged 14 commits into from
May 23, 2018
Merged

Introduce Azure Maps cmdlets #6259

merged 14 commits into from
May 23, 2018

Conversation

jp94
Copy link
Contributor

@jp94 jp94 commented May 21, 2018

Description

Introduce Azure maps cmdlets.

Most are renaming LocationBasedServices cmdlets to Maps.
However, I had to attach a Microsoft.Azure.Management.ResourceManager.ResourceManagementClient to pass test cases.

Cmdlet review:
https://github.com/Azure/azure-powershell-cmdlet-review-pr/issues/21

Checklist

@maddieclayton
Copy link
Contributor

@jp94 Looks like the reason the build is failing is because the online help link is not added to the help files: https://azuresdkci.westus2.cloudapp.azure.com/job/powershell/4635/ (ValidateHelpIssues.csv).

@maddieclayton
Copy link
Contributor

@jp94 Doing a comparison of the file structures: it looks like you have forgotten to remove a folder in the Test/SessionsRecords folder:

Previous (correct): https://github.com/Azure/azure-powershell/tree/preview/src/ResourceManager/LocationBasedServices/LocationBasedServices.Test/SessionRecords
Now (incorrect): https://github.com/jp94/azure-powershell/tree/preview/src/ResourceManager/Maps/Maps.Test/SessionRecords

Looks like you need to remove the LocationBasedServices.Test folder.

@jp94
Copy link
Contributor Author

jp94 commented May 21, 2018

@maddieclayton
Do you mean to add https://docs.microsoft.com/en-us/powershell/module/azurerm.maps
to AzureRM.Maps.md and https://docs.microsoft.com/en-us/powershell/module/azurerm.maps/get-azurermmapsaccount to Get-AzureRmMapsAccount.md etc.? Since the links do not exist yet, do I also submit a PR to azure-docs-powershell?

For second comment, I think you were looking at the wrong branch jp94:preview rather than jp94:maps.

Also, I realized that I've submitted a PR with renaming LocationBasedServices to Maps.
Would it be better to cancel this and submit two PRs where one introduces Maps and another deprecates LocationBasedServices? We did send out emails to our customers that LocationBasedServices PS cmdlets (total 5 downloads) will no longer work prior to going forward with the breaking changes.

Thanks.

# Test
$accountname = 'ps-' + $rgname;
$skuname = 'S0';
$location = 'West US';
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be Get-Location 'Microsoft.Maps' 'accounts' 'West US';

Apply everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing to $location = Get-Location -providerNamespace 'Microsoft.Maps' -resourceType 'accounts' -preferredLocation 'West US'; or Get-Location 'Microsoft.Maps' 'accounts' 'West US'; yields this error:

Test Name:	Microsoft.Azure.Commands.Maps.Test.ScenarioTests.MapsAccountTests.TestGetAccounts
Test Outcome:	Failed
Result Message:	System.Management.Automation.ActionPreferenceStopException : The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Exception of type 'System.Management.Automation.PSInvalidOperationException' was thrown.

Perhaps I've mis-configured something? In Maps.Test/bin/Debug/Common.ps1, Get-Location function is there, but looks like it's failing to recognize it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I can't find anything in your code that would cause this error. My recommendation would be to do a git clean -xdf (after committing all local changes, as this will erase all local changes), rebuilding and rerunning the test. I would think that something happened during all the renaming that is causing the function to not be found. Ping me if you are still having problems after this.

---
Module Name: AzureRM.Maps
Module Guid: bf60f35d-6c0b-42f2-be30-eb333a31279d
Download Help Link: None
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it okay to reference the old locationbasedservices link over maps?

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -12,7 +12,7 @@
# RootModule = ''

# Version number of this module.
ModuleVersion = '1.0.1'
ModuleVersion = '2.0.0'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you'd want to start as 1.0.0 for this module (since it will be new to the gallery) - let me know if you disagree.

CmdletsToExport = 'Get-AzureRmMapsAccount',
'New-AzureRmMapsAccount',
'Remove-AzureRmMapsAccount',
'Set-AzureRmMapsAccount',
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this just missing before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's interesting.
I see Set-AzureRmLocationBasedServicesAccount in netcore, but not on the original psd1. Should I remove that on both files?

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is no Set, it should be removed everywhere.


# Prerelease string of this module
Prerelease = 'preview'
Prerelease = ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Please comment this out (add a # to the beginning).

@@ -71,11 +75,15 @@
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this new reference - in common targets.

Assert-AreEqual $createdAccount.Location $createdAccountAgain.Location;
Assert-AreEqual $createdAccount.Sku.Name $createdAccountAgain.Sku.Name;

Retry-IfException { Remove-AzureRmMapsAccount -ResourceGroupName $rgname -Name $accountname -Confirm:$false; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a check here to ensure the account was deleted (make sure get returns nothing)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the check is in under function Test-RemoveAzureRmMapsAccount at line 73 & 83. I think this check is good, but I can also add to all other test cases if needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as remove has an assert somewhere in the tests, no need to add the check here. 👍

return context.GetServiceClient<MapsManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
}

private LegacyResourceManagementClient GetLegacyResourceManagementClient(RestTestFramework.MockContext context)
Copy link
Contributor

Choose a reason for hiding this comment

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

What changed to mean that you need this? Did you change the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No changes were introduced.
If I recall, it worked ~2 months ago, but broke recently after pulling the latest code from the preview branch. This includes unmodified LocationBasedServices cmdlet tests, that yields the same error like shown below:

Test Name:	Microsoft.Azure.Commands.Maps.Test.ScenarioTests.MapsAccountTests.TestRemoveAccount
Test Outcome:	Failed
Result Message:	System.Management.Automation.ActionPreferenceStopException : The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: TestManagementClientHelper class wasn't initialized with the ResourceManagementClient client.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. This is fine then.

<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.10" targetFramework="net452" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this.

@@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.ResourceManager.Co
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Resources", "..\Resources\Commands.Resources\Commands.Resources.csproj", "{E1F5201D-6067-430E-B303-4E367652991B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Tags", "..\Tags\Commands.Tags\Commands.Tags.csproj", "{2493A8F7-1949-4F29-8D53-9D459046C3B8}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this added?

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.

@maddieclayton
Copy link
Contributor

@jp94 To answer questions from above:

No need to open a new PR in docs. Once the release is live, the docs team will pull the docs from our repo. You just need to add the links (what you said about which links to add is correct).

The current PR removing the old module and adding the new simulataneous is much easier to review because it only shows the changes. Please keep like this.

@@ -47,6 +47,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyVersion("2.0.0")]
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be 1.0.0 as well.

@@ -56,6 +56,10 @@ Global
{E1F5201D-6067-430E-B303-4E367652991B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1F5201D-6067-430E-B303-4E367652991B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1F5201D-6067-430E-B303-4E367652991B}.Release|Any CPU.Build.0 = Release|Any CPU
{2493A8F7-1949-4F29-8D53-9D459046C3B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove these four lines as well - this is from the tags.common project.

@maddieclayton
Copy link
Contributor

@jp94 Looks like the build is failing because your "Remove" cmdlet does not implement passthru. To add this, simply add a switchparameter "PassThru", and when the parameter is specified, print a boolean indicating the success or failure of the removal. Let me know if you have any questions about this.

@jp94
Copy link
Contributor Author

jp94 commented May 23, 2018

@maddieclayton
Sorry about that (forgot to run msbuild build.proj after merging with Azure/preview).
I want to confirm the changes below before pushing.

    [...]
+   [Cmdlet(VerbsCommon.Remove, MapsAccountNounStr, DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(bool))]
    public class RemoveAzureMapsAccount : MapsAccountBaseCmdlet
    {
        [...]

+       [Parameter(Mandatory = false)]
+       public SwitchParameter PassThru { get; set; }

        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            RunCmdLet(() =>
            {
                [...]

                if (!string.IsNullOrEmpty(rgName)
                    && !string.IsNullOrEmpty(name)
                    && ShouldProcess(name, string.Format(CultureInfo.CurrentCulture, Resources.RemoveAccount_ProcessMessage, name)))
                {
                    this.MapsClient.Accounts.Delete(rgName, name);
+                   if (PassThru.IsPresent)
+                   {
+                       WriteObject(true);
+                   }
                }
            });
        }
    }
}

I was able to complete the build without errors, and you can see the changes noted by + on the left side.
Original
Thanks.

@maddieclayton
Copy link
Contributor

@jp94 That looks great! My only comment would be to add a "HelpMessage" to the PassThru parameter.

@maddieclayton
Copy link
Contributor

@jp94 You will also need to regenerate the help file, so the new parameter gets picked up. Thanks!

@@ -106,6 +106,19 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -PassThru
Return whether the specified account was successfully deleted or not.```yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this yaml tag down to the next line (this is a known issue in platyps)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep.. I fixed the issue, and am running the whole msbuild build.proj again right now.

@maddieclayton
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants