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

Update Automation Module cmdlets to support Powershell7.2 #23482

Merged
merged 7 commits into from
Nov 26, 2023

Conversation

sushil490023
Copy link
Contributor

Description

Checklist

  • SHOULD select appropriate branch. Cmdlets from Autorest.PowerShell should go to generation branch.
  • SHOULD make the title of PR clear and informative, and in the present imperative tense.
  • SHOULD update ChangeLog.md file(s) appropriately
    • For any service, the ChangeLog.md file can be found at src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md
    • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense. Add changelog in description section if PR goes into generation branch.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD have approved design review for the changes in this repository (Microsoft internal only) with following situations
    • Create new module from scratch
    • Create new resource types which are not easy to conform to Azure PowerShell Design Guidelines
    • Create new resource type which name doesn't use module name as prefix
    • Have design question before implementation
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT introduce breaking changes in Az minor release except preview version.
  • SHOULD NOT adjust version of module manually in pull request

Copy link

azure-client-tools-bot-prd bot commented Nov 20, 2023

️✔️Az.Accounts
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
⚠️Az.Automation
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Breaking Change Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Signature Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Help Example Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Help File Existence Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️File Change Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️UX Metadata Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Generated Sdk Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
⚠️Test
⚠️ - Linux
Type Title Current Coverage Description
⚠️ Test Coverage Less Than 50% 38.00 % Test coverage for the module cannot be lower than 50%.
⚠️ - MacOS
Type Title Current Coverage Description
⚠️ Test Coverage Less Than 50% 38.00% Test coverage for the module cannot be lower than 50%.
⚠️PowerShell Core - Windows
Type Title Current Coverage Description
⚠️ Test Coverage Less Than 50% 38.00% Test coverage for the module cannot be lower than 50%.
⚠️Windows PowerShell - Windows
Type Title Current Coverage Description
⚠️ Test Coverage Less Than 50% 38.00% Test coverage for the module cannot be lower than 50%.

@NoriZC
Copy link
Contributor

NoriZC commented Nov 20, 2023

Hi @sushil490023 To pass the CI pipelines:

  • Please re-record the failed test cases.
  • Do you think the Position = 4 for RuntimeVersion is necessary? If not, please remove it because a parameter with a position larger than four is discouraged.

src/Automation/Automation/ChangeLog.md Outdated Show resolved Hide resolved
Comment on lines 475 to 493
public Module GetPowerShell72Module(string resourceGroupName, string automationAccountName, string name)
{
try
{
var module =
this.automationManagementClient.Module.Get(resourceGroupName, automationAccountName, name);
return new Module(resourceGroupName, automationAccountName, module);
}
catch (ErrorResponseException cloudException)
{
if (cloudException.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
{
throw new ResourceNotFoundException(typeof(Module),
string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, name));
}

throw;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't see any difference between this function and L352-L370. Could you explain why a new set of PowerShell72 is needed?

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 have Updated the function. Thanks for pointing it

src/Automation/Automation/Common/AutomationPSClient.cs Outdated Show resolved Hide resolved
Copy link

This PR was labeled "needs-revision" because it has unresolved review comments or CI failures.
Please resolve all open review comments and make sure all CI checks are green. Refer to our guide to troubleshoot common CI failures.

@NoriZC
Copy link
Contributor

NoriZC commented Nov 22, 2023

Hi @sushil490023

  • The affetced test cases are not re-recorded. Please record them ans make sure they can work
  • As I commented above, you still have Module which haven't been updated as PowerShell72Module. Currently we cannot determine you code correctness by reviewing. Could you design a set of e2e tests to cover the senario?
  • The difference between function Create() and CreatePowerShell72Module() is small, which means there are lots of unnecessary overlaps. Could you refine the code to make it simpler? (For example, can we add a optional parameter into the create() to flag PowerShell 7.2?)

@sushil490023
Copy link
Contributor Author

Hi @NoriZC ,

  1. I have recorded the test cases impacted by swagger changes in Azure/azure-rest-api-specs@9807153. The test cases for UpdateManagementTests and UpdateDynamicGroupPrePostTests are not recorded as there have been no changes in the SDK, apart from the API version change.
image

Recording these end-to-end (E2E) test cases requires setting up resources, which will take some time. We are actively working on adding these test cases with a subsequent pull request (PR) along with Abhimanyu Varma and Sanjeev Kumar.

  1. The existing set of E2E test cases currently verifies that the module is created and updated correctly. However, the response object of the cmdlets (i.e., Module) does not have any distinct parameter to distinguish whether it's PowerShell 5 or 7. I have added an explicit assertion to check that no PowerShell 7.2 modules are created or imported in PowerShell 5.1 operations, and vice versa for PowerShell 5.1.

  2. Further simplification in AutomationPSClient.cs would impact the readability of the code with the addition of if-else statements, as for most lines of code, "Module" needs to be replaced with "PowerShell72Module."

Thanks

@NoriZC
Copy link
Contributor

NoriZC commented Nov 23, 2023

Hi @sushil490023

  1. Big thanks that you can understand our practice of keeping the test cases running for code quality. For the currently unrecorded and failed cases, please

    • confirm that the behavior is the same as before after upgrading the API version.
    • give an ETA of recording.

    After that you can skip them by adding [Fact(Skip = "<the reason why this is temporarily skipped>")]. Here is an example.

  2. The e2e tests look good.

  3. I understand your concern. But as shown below, the two method has little differences. Except the line I flagged, other code are duplicated unnecessarily. We should reduce the duplication of code. If you think the if-else is unnecessarily introduced as I suggested, we can discuss a better one. But at least the current duplication is unexpected as well.

public Module GetModule(string resourceGroupName, string automationAccountName, string name)
        {
            try
            {
                var module =
+                    this.automationManagementClient.Module.Get(resourceGroupName, automationAccountName, name);
                return new Module(resourceGroupName, automationAccountName, module);
            }
            catch (ErrorResponseException cloudException)
            {
                if (cloudException.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new ResourceNotFoundException(typeof(Module),
                        string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, name));
                }

                throw;
            }
        }
public Module GetPowerShell72Module(string resourceGroupName, string automationAccountName, string name)
        {
            try
            {
                var module =
+                   this.automationManagementClient.PowerShell72Module.Get(resourceGroupName, automationAccountName, name);
                return new Module(resourceGroupName, automationAccountName, module);
            }
            catch (ErrorResponseException cloudException)
            {
                if (cloudException.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new ResourceNotFoundException(typeof(Module),
                        string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, name));
                }

                throw;
            }
        }
  1. Please follow the second point I mentioned in this comment to check the Position in parameter. I will locate one case and raise a suggestion for you. We are not encouraging position parameter any more now.

Hi @sushil490023 To pass the CI pipelines:

  • Please re-record the failed test cases.
  • Do you think the Position = 4 for RuntimeVersion is necessary? If not, please remove it because a parameter with a position larger than four is discouraged.

@sushil490023
Copy link
Contributor Author

Hi @NoriZC

  1. I can confirm that no changes in skipped test cases apart from API versions changes and ETA for recording test case is 12/5.
  2. I have refactored the code now to use overlapping code.
  3. Removed positional parameter from all effected cmdlets.

Thanks

@NoriZC NoriZC merged commit 3981d9d into Azure:main Nov 26, 2023
12 checks passed
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