From a6e010293abd2eace32da9fee1b27a8444277d87 Mon Sep 17 00:00:00 2001 From: Priyanshi Jain <87351063+priyjain358@users.noreply.github.com> Date: Wed, 17 Jul 2024 18:17:12 +0530 Subject: [PATCH] Revert 23H2 registration blocker (#25457) --- src/StackHCI/StackHCI.Autorest/README.md | 3 --- .../StackHCI.Autorest/custom/README.md | 8 +++--- .../StackHCI.Autorest/custom/stackhci.ps1 | 27 ------------------- src/StackHCI/StackHCI.Autorest/docs/README.md | 4 +-- .../StackHCI.Autorest/resources/README.md | 2 +- src/StackHCI/StackHCI.Autorest/test/README.md | 2 +- .../StackHCI.Autorest/test/loadEnv.ps1 | 2 +- .../utils/Get-SubscriptionIdTestSafe.ps1 | 7 +++++ 8 files changed, 16 insertions(+), 39 deletions(-) create mode 100644 src/StackHCI/StackHCI.Autorest/utils/Get-SubscriptionIdTestSafe.ps1 diff --git a/src/StackHCI/StackHCI.Autorest/README.md b/src/StackHCI/StackHCI.Autorest/README.md index fb50e3a46a81..700e9cc600ca 100644 --- a/src/StackHCI/StackHCI.Autorest/README.md +++ b/src/StackHCI/StackHCI.Autorest/README.md @@ -3,9 +3,6 @@ This directory contains the PowerShell module for the StackHci service. --- -## Status -[![Az.StackHCI](https://img.shields.io/powershellgallery/v/Az.StackHCI.svg?style=flat-square&label=Az.StackHCI "Az.StackHCI")](https://www.powershellgallery.com/packages/Az.StackHCI/) - ## Info - Modifiable: yes - Generated: all diff --git a/src/StackHCI/StackHCI.Autorest/custom/README.md b/src/StackHCI/StackHCI.Autorest/custom/README.md index 100ce9245fb7..e9c24f15b5a4 100644 --- a/src/StackHCI/StackHCI.Autorest/custom/README.md +++ b/src/StackHCI/StackHCI.Autorest/custom/README.md @@ -1,5 +1,5 @@ # Custom -This directory contains custom implementation for non-generated cmdlets for the `Az.StackHCI` module. Both scripts (`.ps1`) and C# files (`.cs`) can be implemented here. They will be used during the build process in `build-module.ps1`, and create cmdlets into the `../exports` folder. The only generated file into this folder is the `Az.StackHCI.custom.psm1`. This file should not be modified. +This directory contains custom implementation for non-generated cmdlets for the `Az.StackHCI` module. Both scripts (`.ps1`) and C# files (`.cs`) can be implemented here. They will be used during the build process in `build-module.ps1`, and create cmdlets into the `..\exports` folder. The only generated file into this folder is the `Az.StackHCI.custom.psm1`. This file should not be modified. ## Info - Modifiable: yes @@ -15,10 +15,10 @@ For C# cmdlets, they are compiled with the rest of the generated low-level cmdle For script cmdlets, these are loaded via the `Az.StackHCI.custom.psm1`. Then, during the build process, this module is loaded and processed in the same manner as the C# cmdlets. The fundamental difference is the script cmdlets use the `ParameterSetName` attribute and C# cmdlets do not. To create a script cmdlet variant of a generated cmdlet, simply decorate all parameters in the script with the new `ParameterSetName` in the `Parameter` attribute. This will appropriately treat each parameter set as a separate variant when processed to be exported during the build. ## Purpose -This allows the modules to have cmdlets that were not defined in the REST specification. It also allows combining logic using generated cmdlets. This is a level of customization beyond what can be done using the [readme configuration options](https://github.com/Azure/autorest/blob/master/docs/powershell/options.md) that are currently available. These custom cmdlets are then referenced by the cmdlets created at build-time in the `../exports` folder. +This allows the modules to have cmdlets that were not defined in the REST specification. It also allows combining logic using generated cmdlets. This is a level of customization beyond what can be done using the [readme configuration options](https://github.com/Azure/autorest/blob/master/docs/powershell/options.md) that are currently available. These custom cmdlets are then referenced by the cmdlets created at build-time in the `..\exports` folder. ## Usage -The easiest way currently to start developing custom cmdlets is to copy an existing cmdlet. For C# cmdlets, copy one from the `generated/cmdlets` folder. For script cmdlets, build the project using `build-module.ps1` and copy one of the scripts from the `../exports` folder. After that, if you want to add new parameter sets, follow the guidelines in the `Details` section above. For implementing a new cmdlets, at minimum, please keep these parameters: +The easiest way currently to start developing custom cmdlets is to copy an existing cmdlet. For C# cmdlets, copy one from the `generated/cmdlets` folder. For script cmdlets, build the project using `build-module.ps1` and copy one of the scripts from the `..\exports` folder. After that, if you want to add new parameter sets, follow the guidelines in the `Details` section above. For implementing a new cmdlets, at minimum, please keep these parameters: - Break - DefaultProfile - HttpPipelineAppend @@ -36,6 +36,6 @@ For processing the cmdlets, we've created some additional attributes: - `Microsoft.Azure.PowerShell.Cmdlets.StackHCI.DoNotExportAttribute` - Used in C# and script cmdlets to suppress creating an exported cmdlet at build-time. These cmdlets will *not be exposed* by `Az.StackHCI`. - `Microsoft.Azure.PowerShell.Cmdlets.StackHCI.InternalExportAttribute` - - Used in C# cmdlets to route exported cmdlets to the `../internal`, which are *not exposed* by `Az.StackHCI`. For more information, see [README.md](../internal/README.md) in the `../internal` folder. + - Used in C# cmdlets to route exported cmdlets to the `..\internal`, which are *not exposed* by `Az.StackHCI`. For more information, see [README.md](..\internal/README.md) in the `..\internal` folder. - `Microsoft.Azure.PowerShell.Cmdlets.StackHCI.ProfileAttribute` - Used in C# and script cmdlets to define which Azure profiles the cmdlet supports. This is only supported for Azure (`--azure`) modules. \ No newline at end of file diff --git a/src/StackHCI/StackHCI.Autorest/custom/stackhci.ps1 b/src/StackHCI/StackHCI.Autorest/custom/stackhci.ps1 index 4990379ae2af..7d302dcb9c2c 100644 --- a/src/StackHCI/StackHCI.Autorest/custom/stackhci.ps1 +++ b/src/StackHCI/StackHCI.Autorest/custom/stackhci.ps1 @@ -76,7 +76,6 @@ $StartingArcAgentMessage = "Enabling Azure Arc integration on every clustered no $VerifyingArcMessage = "Verifying Azure Arc for Servers registration" $WaitingUnregisterMessage = "Disabling Azure Arc integration on every clustered node" $CleanArcMessage = "Cleaning up Azure Arc integration" -$NonCloudDeploymentFor23H2DevicesErrorMessage = "Azure stack HCI version 23H2 and higher cannot be registered using this method. See details: https://learn.microsoft.com/en-us/azure-stack/hci/deploy/deploy-via-portal" $MissingDependentModulesError = "Can't find PowerShell module(s): {0}. Please install the missing module(s) using 'Install-Module -Name ' and try again." $ArcAlreadyEnabledInADifferentResourceError = "Below mentioned cluster node(s) are already Arc enabled with a different ARM Resource Id:`n{0}`nDisconnect Arc agent on these nodes and run Register-AzStackHCI again." @@ -2895,21 +2894,6 @@ param( Write-VerboseLog ("Cloud Management supported: {0}" -f $isCloudManagementSupported) Write-VerboseLog ("Cloud Management Infra supported: {0}" -f $isCloudManagementInfraSupported) Write-VerboseLog ("Installing Mandatory extensions supported: {0}" -f $isDefaultExtensionSupported) - - $allowFor23H2Devices = Verify-23H2VanillaRegistration -clusterNodeSession $clusterNodeSession - if(([Int]::Parse($osVersionInfo.BuildNumber) -ge $23H2BuildNumber) -and !($allowFor23H2Devices)) - { - #error message - Write-ErrorLog -Message $NonCloudDeploymentFor23H2DevicesErrorMessage -Category OperationStopped - $resultValue = [OperationStatus]::Failed - $registrationOutput | Add-Member -MemberType NoteProperty -Name $OutputPropertyResult -Value [OperationStatus]::Failed -ErrorAction Continue - $NonCloudDeploymentFor23H2DevicesErrorCode = 9132 - Set-WacOutputProperty -IsWAC $IsWAC -PropertyName $OutputPropertyWacResult -PropertyValue $resultValue.ToString() -Output $registrationOutput - Set-WacOutputProperty -IsWAC $IsWAC -PropertyName $OutputPropertyWacErrorCode -PropertyValue $NonCloudDeploymentFor23H2DevicesErrorCode -Output $registrationOutput - Write-Output $registrationOutput | Format-List - Write-NodeEventLog -Message $NonCloudDeploymentFor23H2DevicesErrorMessage -EventID 9132 -IsManagementNode $IsManagementNode -credentials $Credential -ComputerName $ComputerName -Level Error - throw - } if(-Not ([string]::IsNullOrEmpty($RegContext.AzureResourceUri))) { @@ -3888,17 +3872,6 @@ Set-WacOutputProperty -IsWAC $IsWAC -PropertyName $OutputPropertyWacResult -Prop } } -function Verify-23H2VanillaRegistration { - [Microsoft.Azure.PowerShell.Cmdlets.StackHCI.DoNotExportAttribute()] - param( - [System.Management.Automation.Runspaces.PSSession] $clusterNodeSession - ) - - $detectRegKeyfor23H2 = { $lcmRegKey = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\LCMAzureStackStampInformation" -Name "InitializationComplete" -ErrorAction SilentlyContinue; $lcmRegKey -ne $null } - $allowFor23H2Devices = Invoke-Command -Session $clusterNodeSession -ScriptBlock $detectRegKeyfor23H2 - - return $allowFor23H2Devices -} function Set-ArcRoleforRPSpn { [Microsoft.Azure.PowerShell.Cmdlets.StackHCI.DoNotExportAttribute()] diff --git a/src/StackHCI/StackHCI.Autorest/docs/README.md b/src/StackHCI/StackHCI.Autorest/docs/README.md index 94ace3898911..9b3bed064617 100644 --- a/src/StackHCI/StackHCI.Autorest/docs/README.md +++ b/src/StackHCI/StackHCI.Autorest/docs/README.md @@ -1,5 +1,5 @@ # Docs -This directory contains the documentation of the cmdlets for the `Az.StackHCI` module. To run documentation generation, use the `generate-help.ps1` script at the root module folder. Files in this folder will *always be overridden on regeneration*. To update documentation examples, please use the `../examples` folder. +This directory contains the documentation of the cmdlets for the `Az.StackHCI` module. To run documentation generation, use the `generate-help.ps1` script at the root module folder. Files in this folder will *always be overridden on regeneration*. To update documentation examples, please use the `..\examples` folder. ## Info - Modifiable: no @@ -8,4 +8,4 @@ This directory contains the documentation of the cmdlets for the `Az.StackHCI` m - Packaged: yes ## Details -The process of documentation generation loads `Az.StackHCI` and analyzes the exported cmdlets from the module. It recognizes the [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) that are generated into the scripts in the `../exports` folder. Additionally, when writing custom cmdlets in the `../custom` folder, you can use the help comments syntax, which decorate the exported scripts at build-time. The documentation examples are taken from the `../examples` folder. \ No newline at end of file +The process of documentation generation loads `Az.StackHCI` and analyzes the exported cmdlets from the module. It recognizes the [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) that are generated into the scripts in the `..\exports` folder. Additionally, when writing custom cmdlets in the `..\custom` folder, you can use the help comments syntax, which decorate the exported scripts at build-time. The documentation examples are taken from the `..\examples` folder. \ No newline at end of file diff --git a/src/StackHCI/StackHCI.Autorest/resources/README.md b/src/StackHCI/StackHCI.Autorest/resources/README.md index 736492341e3d..937f07f8fec2 100644 --- a/src/StackHCI/StackHCI.Autorest/resources/README.md +++ b/src/StackHCI/StackHCI.Autorest/resources/README.md @@ -1,5 +1,5 @@ # Resources -This directory can contain any additional resources for module that are not required at runtime. This directory **does not** get packaged with the module. If you have assets for custom implementation, place them into the `../custom` folder. +This directory can contain any additional resources for module that are not required at runtime. This directory **does not** get packaged with the module. If you have assets for custom implementation, place them into the `..\custom` folder. ## Info - Modifiable: yes diff --git a/src/StackHCI/StackHCI.Autorest/test/README.md b/src/StackHCI/StackHCI.Autorest/test/README.md index 1969200c6a09..7c752b4c8c43 100644 --- a/src/StackHCI/StackHCI.Autorest/test/README.md +++ b/src/StackHCI/StackHCI.Autorest/test/README.md @@ -1,5 +1,5 @@ # Test -This directory contains the [Pester](https://www.powershellgallery.com/packages/Pester) tests to run for the module. We use Pester as it is the unofficial standard for PowerShell unit testing. Test stubs for custom cmdlets (created in `../custom`) will be generated into this folder when `build-module.ps1` is ran. These test stubs will fail automatically, to indicate that tests should be written for custom cmdlets. +This directory contains the [Pester](https://www.powershellgallery.com/packages/Pester) tests to run for the module. We use Pester as it is the unofficial standard for PowerShell unit testing. Test stubs for custom cmdlets (created in `..\custom`) will be generated into this folder when `build-module.ps1` is ran. These test stubs will fail automatically, to indicate that tests should be written for custom cmdlets. ## Info - Modifiable: yes diff --git a/src/StackHCI/StackHCI.Autorest/test/loadEnv.ps1 b/src/StackHCI/StackHCI.Autorest/test/loadEnv.ps1 index 5f079e89615e..6a7c385c6b7d 100644 --- a/src/StackHCI/StackHCI.Autorest/test/loadEnv.ps1 +++ b/src/StackHCI/StackHCI.Autorest/test/loadEnv.ps1 @@ -25,5 +25,5 @@ if (Test-Path -Path (Join-Path $PSScriptRoot $envFile)) { $env = @{} if (Test-Path -Path $envFilePath) { $env = Get-Content (Join-Path $PSScriptRoot $envFile) | ConvertFrom-Json - $PSDefaultParameterValues=@{"*:SubscriptionId"=$env.SubscriptionId; "*:Tenant"=$env.Tenant} + $PSDefaultParameterValues=@{"*:Tenant"=$env.Tenant} } \ No newline at end of file diff --git a/src/StackHCI/StackHCI.Autorest/utils/Get-SubscriptionIdTestSafe.ps1 b/src/StackHCI/StackHCI.Autorest/utils/Get-SubscriptionIdTestSafe.ps1 new file mode 100644 index 000000000000..5319862d3372 --- /dev/null +++ b/src/StackHCI/StackHCI.Autorest/utils/Get-SubscriptionIdTestSafe.ps1 @@ -0,0 +1,7 @@ +param() +if ($env:AzPSAutorestTestPlaybackMode) { + $loadEnvPath = Join-Path $PSScriptRoot '..' 'test' 'loadEnv.ps1' + . ($loadEnvPath) + return $env.SubscriptionId +} +return (Get-AzContext).Subscription.Id \ No newline at end of file