def test_full_backup_and_restore(self, container_uri, sas_token): # backup the vault backup_client = KeyVaultBackupClient(self.managed_hsm["url"], self.credential) backup_poller = backup_client.begin_backup(container_uri, sas_token) # check backup status and result job_id = backup_poller.polling_method().resource().job_id backup_status = backup_client.get_backup_status(job_id) assert_in_progress_operation(backup_status) backup_operation = backup_poller.result() assert_successful_operation(backup_operation) backup_status = backup_client.get_backup_status(job_id) assert_successful_operation(backup_status) # restore the backup restore_poller = backup_client.begin_restore(backup_status.folder_url, sas_token) # check restore status and result job_id = restore_poller.polling_method().resource().job_id restore_status = backup_client.get_restore_status(job_id) assert_in_progress_operation(restore_status) restore_operation = restore_poller.result() assert_successful_operation(restore_operation) restore_status = backup_client.get_restore_status(job_id) assert_successful_operation(restore_status)
def test_selective_key_restore(self, container_uri, sas_token): # create a key to selectively restore key_client = KeyClient(self.managed_hsm["url"], self.credential) key_name = self.get_resource_name("selective-restore-test-key") key_client.create_rsa_key(key_name) # backup the vault backup_client = KeyVaultBackupClient(self.managed_hsm["url"], self.credential) backup_poller = backup_client.begin_full_backup( container_uri, sas_token) # check backup status and result job_id = backup_poller.polling_method().resource().id backup_status = backup_client.get_backup_status(job_id) assert_in_progress_operation(backup_status) backup_operation = backup_poller.result() assert_successful_operation(backup_operation) backup_status = backup_client.get_backup_status(job_id) assert_successful_operation(backup_status) # restore the key folder_name = backup_operation.azure_storage_blob_container_uri.split( "/")[-1] restore_poller = backup_client.begin_selective_restore( container_uri, sas_token, folder_name, key_name) # check restore status and result job_id = restore_poller.polling_method().resource().id restore_status = backup_client.get_restore_status(job_id) assert_in_progress_operation(restore_status) restore_operation = restore_poller.result() assert_successful_operation(restore_operation) restore_status = backup_client.get_restore_status(job_id) assert_successful_operation(restore_status) # delete the key delete_function = partial(key_client.begin_delete_key, key_name) delete_poller = self._poll_until_no_exception(delete_function, ResourceExistsError) delete_poller.wait() key_client.purge_deleted_key(key_name)