-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[Draft] Support az what-if
#32138
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
Draft
MoChilia
wants to merge
20
commits into
Azure:dev
Choose a base branch
from
MoChilia:whatif
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[Draft] Support az what-if
#32138
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
abb2f17
az what-if (save)
MoChilia 46cf88d
az what-if
MoChilia f126b42
update
MoChilia 08cc6c1
add progress bar and support pretty output
MoChilia 6a1b839
fix style issue
MoChilia 6a52aac
add a mock test
MoChilia b4aae27
use get_raw_token
MoChilia b764741
def PropertyChange
MoChilia c3caf10
update mock test
MoChilia 499e477
move call what-if to core
MoChilia e11f6aa
Merge remote-tracking branch 'upstream/dev' into whatif
MoChilia b9aac2d
Wzl/Support `--what-if` argument (#2)
MoChilia dbb01fc
merge support `--what-if`
MoChilia 53ce56b
format
MoChilia 5f1096d
enhanced progress bar
MoChilia 525939c
modify error output
MoChilia 819531e
update url
MoChilia 9b1d254
Check if stderr supports interactive output
MoChilia 333bc80
Merge branch 'dev' into whatif
MoChilia a9cfa26
update
MoChilia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/azure-cli/azure/cli/command_modules/util/tests/latest/test_whatif.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import unittest | ||
| import os | ||
| from unittest.mock import patch, Mock | ||
| from azure.cli.testsdk import ScenarioTest | ||
|
|
||
| TEST_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
|
|
||
|
|
||
| class WhatIfTest(ScenarioTest): | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| self.test_script_path = os.path.join(TEST_DIR, 'test_whatif_script.sh') | ||
|
|
||
| @patch('requests.Session.send') | ||
| def test_what_if_command(self, mock_session_send): | ||
| mock_response = Mock() | ||
| mock_response.json.return_value = { | ||
| "what_if_result": { | ||
| "changes": [ | ||
| { | ||
| "changeType": "Create", | ||
| "resourceId": "/subscriptions/test/resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/MyVM_01", | ||
| "before": None, | ||
| "after": { | ||
| "name": "MyVM_01", | ||
| "type": "Microsoft.Compute/virtualMachines", | ||
| "location": "eastus" | ||
| }, | ||
| "delta": [] | ||
| } | ||
| ], | ||
| "potential_changes": [], | ||
| "diagnostics": [] | ||
| } | ||
| } | ||
| mock_session_send.return_value = mock_response | ||
| result = self.cmd('az what-if --script-path "{}" --no-pretty-print'.format(self.test_script_path)) | ||
| output = result.get_output_in_json() | ||
| self.assertIsInstance(output, dict) | ||
| self.assertIn("changes", output) | ||
| self.assertEqual(len(output["changes"]), 1) | ||
| self.assertEqual(output["changes"][0]["changeType"], "Create") | ||
| mock_session_send.assert_called_once() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
2 changes: 2 additions & 0 deletions
2
src/azure-cli/azure/cli/command_modules/util/tests/latest/test_whatif_script.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Create a VM directly instead of using an ARM template | ||
| az vm create --resource-group myrg --name MyVM_01 --image UbuntuLTS --size Standard_D2s_v3 --admin-username azureuser --generate-ssh-keys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.