def create_resource(self, name, **kwargs): if self.is_live: self.client = self.create_mgmt_client( azure.mgmt.batch.BatchManagementClient) group = self._get_resource_group(**kwargs) batch_account = models.BatchAccountCreateParameters( location=self.location, ) storage = self._get_storage_account(**kwargs) if storage: storage_resource = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Storage/storageAccounts/{}'.format( self.test_class_instance.settings.SUBSCRIPTION_ID, group.name, storage.name) batch_account.auto_storage = models.AutoStorageBaseProperties( storage_account_id=storage_resource) account_setup = self.client.batch_account.create( group.name, name, batch_account) self.resource = account_setup.result() keys = self.client.batch_account.get_keys(group.name, name) credentials = SharedKeyCredentials(keys.account_name, keys.primary) if storage: self._add_app_package(group.name, name) self.test_class_instance.scrubber.register_name_pair( name, self.resource_moniker) else: self.resource = FakeAccount( name=name, account_endpoint="https://{}.{}.batch.azure.com".format( name, self.location)) credentials = SharedKeyCredentials(name, 'ZmFrZV9hY29jdW50X2tleQ==') return { self.parameter_name: self.resource, self.creds_parameter: credentials }
def test_mgmt_batch_applications(self, resource_group, location, storage_account, storage_account_key): # Test Create Account with Auto-Storage storage_resource = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Storage/storageAccounts/{}'.format( self.get_settings_value("SUBSCRIPTION_ID"), resource_group.name, storage_account.name) batch_account = models.BatchAccountCreateParameters( location=location, auto_storage=models.AutoStorageBaseProperties( storage_account_id=storage_resource)) # account_name = self._get_account_name() account_name = "batch11" account_setup = self.mgmt_batch_client.batch_account.begin_create( resource_group.name, account_name, batch_account) account_setup.result() # Test Sync AutoStorage Keys response = self.mgmt_batch_client.batch_account.synchronize_auto_storage_keys( resource_group.name, account_name) assert response is None # Test Add Application application_id = 'my_application_id' application_name = 'my_application_name' application_ver = 'v1.0' application_properties = models.Application( display_name=application_name, allow_updates=True) application = self.mgmt_batch_client.application.create( resource_group.name, account_name, application_id, parameters=application_properties) assert isinstance(application, models.Application) assert application_id in application.id assert application_name in application.display_name assert application.allow_updates # Test Mgmt Get Application application = self.mgmt_batch_client.application.get( resource_group.name, account_name, application_id) assert isinstance(application, models.Application) assert application_id in application.id assert application_name in application.display_name assert application.allow_updates # Test Mgmt List Applications applications = self.mgmt_batch_client.application.list( resource_group.name, account_name) assert len(list(applications)) > 0 # Test Add Application Package package_ref = self.mgmt_batch_client.application_package.create( resource_group.name, account_name, application_id, application_ver) assert isinstance(package_ref, models.ApplicationPackage) with io.BytesIO(b'Hello World') as f: headers = {'x-ms-blob-type': 'BlockBlob'} upload = requests.put(package_ref.storage_url, headers=headers, data=f.read()) if not upload: raise ValueError('Upload failed: {!r}'.format(upload)) # Test Activate Application Package response = self.mgmt_batch_client.application_package.activate( resource_group.name, account_name, application_id, application_ver, {"format": 'zip'}) assert response.state == models.PackageState.active # Test Update Application params = models.Application(allow_updates=False, display_name='my_updated_name', default_version=application_ver) response = self.mgmt_batch_client.application.update( resource_group.name, account_name, application_id, params) assert application_ver in response.default_version assert 'my_updated_name' in response.display_name assert not response.allow_updates # Test Get Application Package package_ref = self.mgmt_batch_client.application_package.get( resource_group.name, account_name, application_id, application_ver) assert isinstance(package_ref, models.ApplicationPackage) assert application_id in package_ref.id assert package_ref.format == 'zip' assert package_ref.state == models.PackageState.active # Test Delete Application Package response = self.mgmt_batch_client.application_package.delete( resource_group.name, account_name, application_id, application_ver) assert response is None # Test Delete Application response = self.mgmt_batch_client.application.delete( resource_group.name, account_name, application_id) assert response is None # Test Delete Account response = self.mgmt_batch_client.batch_account.begin_delete( resource_group.name, account_name) assert response.result() is None