Skip to content

Commit

Permalink
{PolicyInsights} Update SDK package azure-mgmt-policyinsights to `1…
Browse files Browse the repository at this point in the history
….1.0b2` (#22043)
  • Loading branch information
najagasi authored May 13, 2022
1 parent d977594 commit b4881c2
Show file tree
Hide file tree
Showing 13 changed files with 39,273 additions and 21,163 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,37 @@

class PolicyInsightsTests(ScenarioTest):

# Current recording was recorded against "Azure Governance Policy UX Test" (e78961ba-36fe-4739-9212-e3031b4c8db7)
# Current recording was recorded against "Azure Governance Perf 24" (3593b919-b078-4cc1-902f-201232a97ac0)
@record_only()
@AllowLargeResponse()
@AllowLargeResponse(8192)
def test_policy_insights(self):
self.kwargs.update({
'managementGroupId': 'azgovperftest',
'rg': 'PSTestRG1',
'keyVault': 'PSTestKV',
'subnet': 'PSTestVN',
'setDefinition': 'PSTestInitiative',
'definition': 'PSTestDINEDefinition',
'assignment': 'pstestdeployassignmentsub'
})
top_clause = '--top 2'
filter_clause = '--filter "isCompliant eq false"'
apply_clause = '--apply "groupby((policyAssignmentId, resourceId), aggregate($count as numRecords))"'
select_clause = '--select "policyAssignmentId, resourceId, numRecords"'
order_by_clause = '--order-by "numRecords desc"'
from_clause = '--from "2021-07-01T00:00:00Z"'
to_clause = '--to "2021-07-03T01:30:00Z"'
from_clause = '--from "2022-04-01T00:00:00Z"'
to_clause = '--to "2022-04-03T01:30:00Z"'
scopes = [
'-m "azgovtest5"',
'-m {managementGroupId}',
'',
'-g "defaultresourcegroup-eus"',
'--resource "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cheggpolicy/providers/microsoft.keyvault/vaults/cheggtmpkv"',
'--resource "cheggkv" --namespace "microsoft.keyvault" --resource-type "vaults" -g "cheggpolicy"',
'--resource "subnet2" --namespace "microsoft.network" --resource-type "subnets" --parent "virtualnetworks/cheggvnet" -g "cheggpolicy"',
'-s "1f3afdf9-d0c9-4c3d-847f-89da613e70a8"',
'-d "34c877ad-507e-4c82-993e-3452a6e0ad3c"',
'-a "4d31128e32d04a0098fd536e"',
'-a "f32eeddfc32345b585f9a70b" -g "cheggpolicy" '
'-g {rg}',
'--resource "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/{rg}/providers/microsoft.keyvault/vaults/{keyVault}"',
'--resource "{keyVault}" --namespace "microsoft.keyvault" --resource-type "vaults" -g "{rg}"',
'--resource "default" --namespace "microsoft.network" --resource-type "subnets" --parent "virtualnetworks/{subnet}" -g "{rg}"',
'-s {setDefinition}',
'-d {definition}',
'-a {assignment}',
'-a {assignment} -g {rg}'
]

for scope in scopes:
Expand Down Expand Up @@ -302,12 +311,16 @@ def test_policy_insights_remediation_management_group(self):
self.kwargs.update({
'pan': self.create_random_name('cli-test-pa', 23),
'rn': self.create_random_name('cli-test-remediation', 30),
'mg': self.create_random_name('cli-test-mg', 30),
'mg': 'cli-test-mg',
'bip': '06a78e20-9358-41c9-923c-fb736d382a4d'
})

# create a management group we can assign policy to
management_group = self.cmd('account management-group create -n {mg}').get_output_in_json()
self.cmd('account management-group create -n {mg}')
time.sleep(20)
management_group = self.cmd(
'account management-group show --name cli-test-mg').get_output_in_json()


try:
# create a policy assignment that we can trigger remediations on
Expand Down Expand Up @@ -359,17 +372,17 @@ def test_policy_insights_remediation_management_group(self):
# This record_only test executes a real remediation against a known non-compliant policy
# Test setup required for running the test live:
# 1. Create a resource group by name 'az-cli-policy-insights-test'
# 2. Create 2 Windows 10 Pro VMs in two different regions in above RG
# 3. At above RG scope, create a new policy assignment for built-in definition with name 'e0efc13a-122a-47c5-b817-2ccfe5d12615' and display name 'Deploy requirements to audit Windows VMs that do not have the specified Windows PowerShell execution policy'
# 2. Create 2 storage accounts in two different regions in above RG
# 3. At above RG scope, create a new policy assignment for built-in definition with name '361c2074-3595-4e5d-8cab-4f21dffc835c' and display name 'Deploy Advanced Threat Protection on storage accounts'
# 4. Update the 'pan' key value in test code below with the assignment name created above
# 5. Trigger an on-demand evaluation scan on above RG by calling triggerEvaluation API. Check https://docs.microsoft.com/en-us/azure/governance/policy/how-to/get-compliance-data#on-demand-evaluation-scan
# 6. After step 5 completes, you should see the two VMs listed as non-compliant resources for the above assignment
# 6. After step 5 completes, you should see the two storage accounts listed as non-compliant resources for the above assignment
# 7. Now run the testcase in live mode using command 'azdev test test_policy_insights_remediation_complete --live'
@record_only()
@AllowLargeResponse()
@AllowLargeResponse(8192)
def test_policy_insights_remediation_complete(self):
self.kwargs.update({
'pan': '98904c39668a4f70804aef09',
'pan': '78447a35ea2b4b14b701dae0',
'rg': 'az-cli-policy-insights-test',
'rn': self.create_random_name('azurecli-test-remediation', 40)
})
Expand All @@ -380,7 +393,6 @@ def test_policy_insights_remediation_complete(self):
# create a remediation at resource group scope
self.cmd('policy remediation create -n {rn} -g {rg} -a {pan}', checks=[
self.check('name', '{rn}'),
self.check('provisioningState', 'Accepted'),
self.check('resourceGroup', '{rg}'),
self.check('policyAssignmentId', '{pid}'),
self.check('policyDefinitionReferenceId', None),
Expand Down Expand Up @@ -411,7 +423,7 @@ def test_policy_insights_remediation_complete(self):
self.exists('[0].lastUpdatedOn'),
self.exists('[0].resourceLocation'),
self.exists('[0].status'),
self.check("length([?contains(@.remediatedResourceId, '/resourcegroups/{rg}/providers/microsoft.compute/virtualmachines')])", 2)
self.check("length([?contains(@.remediatedResourceId, '/resourcegroups/{rg}/providers/microsoft.storage/storageaccounts')])", 2)
])

# cancel the remediation
Expand Down Expand Up @@ -471,7 +483,7 @@ def test_policy_insights_remediation_reevaluate(self, resource_group_location, s
self.check('provisioningState', 'Cancelling')
])

@AllowLargeResponse()
@AllowLargeResponse(8192)
def test_policy_insights_metadata(self):
# Get all metadata resources
all_metadata_resources = self.cmd('policy metadata list').get_output_in_json()
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ azure-mgmt-monitor==3.0.0
azure-mgmt-msi==6.0.0
azure-mgmt-netapp==7.0.0
azure-mgmt-network==19.3.0
azure-mgmt-policyinsights==1.0.0
azure-mgmt-policyinsights==1.1.0b2
azure-mgmt-privatedns==1.0.0
azure-mgmt-rdbms==10.0.0
azure-mgmt-recoveryservices==2.0.0
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ azure-mgmt-monitor==3.0.0
azure-mgmt-msi==6.0.0
azure-mgmt-netapp==7.0.0
azure-mgmt-network==19.3.0
azure-mgmt-policyinsights==1.0.0
azure-mgmt-policyinsights==1.1.0b2
azure-mgmt-privatedns==1.0.0
azure-mgmt-rdbms==10.0.0
azure-mgmt-recoveryservices==2.0.0
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ azure-mgmt-monitor==3.0.0
azure-mgmt-msi==6.0.0
azure-mgmt-netapp==7.0.0
azure-mgmt-network==19.3.0
azure-mgmt-policyinsights==1.0.0
azure-mgmt-policyinsights==1.1.0b2
azure-mgmt-privatedns==1.0.0
azure-mgmt-rdbms==10.0.0
azure-mgmt-recoveryservices==2.0.0
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
'azure-mgmt-msi~=6.0.0',
'azure-mgmt-netapp~=7.0.0',
'azure-mgmt-network~=19.3.0',
'azure-mgmt-policyinsights~=1.0.0',
'azure-mgmt-policyinsights~=1.1.0b2',
'azure-mgmt-privatedns~=1.0.0',
'azure-mgmt-rdbms~=10.0.0',
'azure-mgmt-recoveryservicesbackup~=4.1.1',
Expand Down

0 comments on commit b4881c2

Please sign in to comment.