Skip to content

Support create RM storage Account with Kind "Storagev2" #5012

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 5 commits into from
Nov 27, 2017

Conversation

blueww
Copy link
Member

@blueww blueww commented Nov 20, 2017

Description

Support create RM storage Account with Kind "Storagev2"
Also need to upgrade SRP SDK to 7.0. Since there's a breaking change in SRP SDK API for NetworkACL->NetworkRuleSet, PowerShell also has code change on it. But since Powershell has wrappered all interface for NetworkRuleSet, PowerShell don't have breaking on it.

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

  • [Y ] Title of the pull request is clear and informative.
  • [Y ] 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.
  • [Y ] The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • [Y ] Pull request includes test coverage for the included changes.
  • [Y ] 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

  • [ Y] 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.
  • [Y ] Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThru parameter.

Cmdlet Parameter Guidelines

  • [Y ] Parameter types should not expose types from the management library - complex parameter types should be defined in the module.
  • [Y ] 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.
  • [Y ] Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

@blueww
Copy link
Member Author

blueww commented Nov 20, 2017

@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.

@blueww a couple of minor comments. Also, the NetworkAcls property of type StorageAccount was removed in the SDK, which is a breaking change. It looks like it was replaced by the NetworkRuleSet property, so this here's how it can be mitigated:

Create a new type PSStorageAccount, which is a wrapper over StorageAccount, and add the property NetworkAcls, which will just point to the NetworkRuleSet property. Add the Obsolete attribute on this property and add a message saying that this property will be removed in a future release. Let me know if you have any questions about this.

@@ -67,10 +67,13 @@
<HintPath>..\..\..\packages\Microsoft.Data.Services.Client.5.8.2\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
Copy link
Member

Choose a reason for hiding this comment

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

@blueww you can remove the references added in this file (Microsoft.Rest.*, Newtonsoft.Json) since they are already referenced by the Common.Dependencies.targets file

<packages>
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Storage" version="6.5.0-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Storage" version="7.1.0-preview" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.10" targetFramework="net452" />
Copy link
Member

Choose a reason for hiding this comment

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

@blueww same comment about removing the added references since they are already referenced from a common project

@blueww
Copy link
Member Author

blueww commented Nov 22, 2017

@cormacpayne

For the breaking change, it's for New/Set-AzureStorageAccount cmdelts output has type "Microsoft.Azure.Management.Storage.Models.StorageAccount", and NetworkAcls is remove from the type.

But actually, the real return type of New/Set-AzureStorageAccount is "PSStorageAccount" (Yes, PSStorageAccount is already defined in PSH code, and used as output type of account cmdlets), you can see both cmdelts use "WriteStorageAccount(storageAccount)" to write output, and actually output Type is "PSStorageAccount":

        protected void WriteStorageAccount(StorageModels.StorageAccount storageAccount)
        {
            WriteObject(PSStorageAccount.Create(storageAccount, this.StorageClient));
        }

So I have correct the output type in New/Set-AzureStorageAccount to "PSStorageAccount". This will show a breaking change in StaticAnalysis for the output type change, but it's actually not breaking, since the output of the 2 cmdelts not change (only the output section in help *.md change). So I have added the 2 output type change into Exception of breaking change.

"d:\workspace\powershell\src\Package\Debug\ResourceManager\AzureResourceManager\AzureRM.Storage\Microsoft.Azure.Commands.Management.Storage.dll","Microsoft.Azure.Commands.Management.Storage.NewAzureStorageAccountCommand","New-AzureRmStorageAccount","0","1020","The cmdlet 'New-AzureRmStorageAccount' no longer has output type 'Microsoft.Azure.Management.Storage.Models.StorageAccount'.","Make cmdlet 'New-AzureRmStorageAccount' return type 'Microsoft.Azure.Management.Storage.Models.StorageAccount'."

"d:\workspace\powershell\src\Package\Debug\ResourceManager\AzureResourceManager\AzureRM.Storage\Microsoft.Azure.Commands.Management.Storage.dll","Microsoft.Azure.Commands.Management.Storage.SetAzureStorageAccountCommand","Set-AzureRmStorageAccount","0","1020","The cmdlet 'Set-AzureRmStorageAccount' no longer has output type 'Microsoft.Azure.Management.Storage.Models.StorageAccount'.","Make cmdlet 'Set-AzureRmStorageAccount' return type 'Microsoft.Azure.Management.Storage.Models.StorageAccount'."

I have fixed all other comments from you.
Let me know if you have any concern.
Thanks!

@cormacpayne
Copy link
Member

@blueww the issue still remains: the NetworkAcls property is no longer accessible from the returned object of New/Set-AzureRmStorageAccount. You will need to add this property to the PSStorageAccount type so users are still able to use it in their scripts. Once you add this property, you can add the Obsolete attribute on it and let users know it will be removed in an upcoming breaking change release.

@cormacpayne
Copy link
Member

@blueww one other thing, please make sure to update the ChangeLog.md file located in src/ResourceManager/Storage witha snippet about the changes you are making in this PR

@blueww
Copy link
Member Author

blueww commented Nov 23, 2017

@cormacpayne
The Change log is added ,and on-demand test updated on https://azuresdkci.westus2.cloudapp.azure.com/job/powershell-demand/196/.

For the NetworkACLs, I might don't clarify it clearly in before comments. Actually, no need to add NetworkACLs, since the original output don't have NetworkACLs.

The original output type of the 2 effected cmdelts New/Set-AzureRmStorageAccount are PSStorageAccount , you can see it in the code: all output storage Account will be converted to PSStorageAccount , then write to PowerShell output. So the original output don't have NetworkACLs.

The before breaking alarm is come from the output Type declared in the begin of cmdlet code is wrong:

  • The declared Output Type is: OutputType(typeof(StorageModels.StorageAccount)) and StorageModels.StorageAccount has a property NetworkACLs missing .
  • The actually output type is PSStorageAccount and it don't have breaking.

So I just correct the output type for the 2 cmdelts to OutputType(typeof(PSStorageAccount)), this make the real output type and the output type declared in code aligned. This fix is not a breaking, since it not change the output of the 2 cmdlets, but just correct the Output Section in help *.md file. Anyway, StaticAnaylsis report alarm since the declared output type change (real output type not change), so I added the 2 output type change into Exception of breaking change.

It's interesting that the OutputType of a cmdlet don't enforce to be aligned with the real output type of the cmdelts, actually there are some discussion on it like link

@cormacpayne
Copy link
Member

@blueww thanks for the clarification ☺️ everything looks good

@cormacpayne cormacpayne merged commit 6e77f89 into Azure:storage-v2 Nov 27, 2017
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