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