|
9 | 9 | from azure.cli.testsdk import ScenarioTest, live_only |
10 | 10 | from azure.cli.testsdk.scenario_tests import AllowLargeResponse |
11 | 11 | import time |
| 12 | +import copy |
12 | 13 |
|
13 | 14 |
|
14 | 15 | def reset_softdelete_base_state(test): |
@@ -273,3 +274,57 @@ def test_dataprotection_backup_instance_softdelete(test): |
273 | 274 |
|
274 | 275 | # Once protection elsewhere is stopped, we can resume protection on the undeleted BI |
275 | 276 | reset_softdelete_base_state(test) |
| 277 | + |
| 278 | + @AllowLargeResponse() |
| 279 | + def test_dataprotection_backup_instance_update_aks_configuration(test): |
| 280 | + # Update with AKS backup configuration using simple az CLI commands. |
| 281 | + test.kwargs.update({ |
| 282 | + 'location': 'eastus2euap', |
| 283 | + 'rg': 'clitest-dpp-rg', |
| 284 | + 'vaultName': 'clitest-bkp-vault-aks-donotdelete', |
| 285 | + 'policyId': '/subscriptions/38304e13-357e-405e-9e9a-220351dcce8c/resourceGroups/clitest-dpp-rg/providers/Microsoft.DataProtection/backupVaults/clitest-bkp-vault-aks-donotdelete/backupPolicies/akspolicy', |
| 286 | + 'dataSourceType': 'AzureKubernetesService', |
| 287 | + 'aksClusterName': 'clitest-cluster1-donotdelete', |
| 288 | + 'aksClusterId': '/subscriptions/38304e13-357e-405e-9e9a-220351dcce8c/resourceGroups/oss-clitest-rg/providers/Microsoft.ContainerService/managedClusters/clitest-cluster1-donotdelete', |
| 289 | + 'friendlyName': 'clitest-friendly-aks', |
| 290 | + 'backupInstanceName': 'clitestsabidonotdelete-clitestsabidonotdelete-887c3538-0bfc-11ee-acd3-002b670b472e' |
| 291 | + }) |
| 292 | + |
| 293 | + # Fetch original BI backupDatasourceParametersList (if any) to allow resetting later |
| 294 | + original_bi = test.cmd('az dataprotection backup-instance show -g "{rg}" --vault-name "{vaultName}" --name "{backupInstanceName}"').get_output_in_json() |
| 295 | + original_bi_backup_config_json = original_bi['properties']['policyInfo']['policyParameters'].get('backupDatasourceParametersList')[0] |
| 296 | + test.kwargs.update({ |
| 297 | + 'backupConfig': original_bi_backup_config_json |
| 298 | + }) |
| 299 | + |
| 300 | + # Generate the AKS backup configuration using the dedicated CLI helper |
| 301 | + new_backup_config_json = test.cmd('az dataprotection backup-instance initialize-backupconfig --datasource-type AzureKubernetesService').get_output_in_json() |
| 302 | + |
| 303 | + # mutate a visible field to make the change observable |
| 304 | + new_backup_config_json['included_namespaces'] = ['nsA', 'nsB'] |
| 305 | + new_backup_config_json['label_selectors'] = ['app=web'] |
| 306 | + new_backup_config_json['excluded_resource_types'] = ['ResourceX'] |
| 307 | + new_backup_config_json['include_cluster_scope_resources'] = False |
| 308 | + new_backup_config_json['snapshot_volumes'] = False |
| 309 | + test.kwargs.update({ |
| 310 | + 'tempBackupConfig': new_backup_config_json |
| 311 | + }) |
| 312 | + |
| 313 | + # Apply temp configuration |
| 314 | + test.cmd('az dataprotection backup-instance update -g "{rg}" --vault-name "{vaultName}" --backup-instance-name "{backupInstanceName}" --backup-configuration "{tempBackupConfig}"', checks=[ |
| 315 | + test.check('name', "{backupInstanceName}") |
| 316 | + ]) |
| 317 | + |
| 318 | + # Fetch the BI and verify that the backupDatasourceParametersList was updated to reflect the AKS config |
| 319 | + test.cmd('az dataprotection backup-instance show -g "{rg}" --vault-name "{vaultName}" --name "{backupInstanceName}"', checks=[ |
| 320 | + test.check("properties.policyInfo.policyParameters.backupDatasourceParametersList[0].included_namespaces", ['nsA', 'nsB']), |
| 321 | + test.check("properties.policyInfo.policyParameters.backupDatasourceParametersList[0].label_selectors", ['app=web']), |
| 322 | + test.check("properties.policyInfo.policyParameters.backupDatasourceParametersList[0].excluded_resource_types", ['ResourceX']), |
| 323 | + test.check("properties.policyInfo.policyParameters.backupDatasourceParametersList[0].include_cluster_scope_resources", False), |
| 324 | + test.check("properties.policyInfo.policyParameters.backupDatasourceParametersList[0].snapshot_volumes", False) |
| 325 | + ]) |
| 326 | + |
| 327 | + # Reset to original configuration |
| 328 | + test.cmd('az dataprotection backup-instance update -g "{rg}" --vault-name "{vaultName}" --backup-instance-name "{backupInstanceName}" --backup-configuration "{backupConfig}"', checks=[ |
| 329 | + test.check('name', "{backupInstanceName}") |
| 330 | + ]) |
0 commit comments