File: test_mgmt_batch_test.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (516 lines) | stat: -rw-r--r-- 27,906 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# coding: utf-8

#-------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#--------------------------------------------------------------------------
import io
import time

import pytest
import requests
import os

import azure.mgmt.batch
from azure.mgmt.batch import models
import azure.mgmt.network.models
from mgmt_batch_preparers import KeyVaultPreparer, SimpleBatchPreparer
from devtools_testutils import (
    AzureMgmtRecordedTestCase, recorded_by_proxy,
    ResourceGroupPreparer,
    StorageAccountPreparer
)

# When running live, these variables may need to be updated depending on the
# test environment
AZURE_ARM_ENDPOINT = "https://centraluseuap.management.azure.com"
AZURE_LOCATION = 'eastus'
EXISTING_BATCH_ACCOUNT = {'name': 'dawatroupp2acct', 'location': 'eastus'}
EXPECTED_ACCOUNT_QUOTA = 3
EXPECTED_DEDICATED_CORE_QUOTA = 500
EXPECTED_LOW_PRIO_CORE_QUOTA = 500
EXPECTED_POOL_QUOTA = 100
SECRET_FIELDS = ["primary", "secondary"]

@pytest.mark.live_test_only
class TestMgmtBatch(AzureMgmtRecordedTestCase):

    def setup_method(self, method):
        self.mgmt_batch_client = self.create_mgmt_client(
            azure.mgmt.batch.BatchManagementClient,
            base_url=AZURE_ARM_ENDPOINT)
        if self.is_live:
            self.mgmt_network = self.create_mgmt_client(
                azure.mgmt.network.NetworkManagementClient,
                base_url=AZURE_ARM_ENDPOINT)

    def _get_account_name(self):
        return self.get_resource_name('batch')[-24:]

    @recorded_by_proxy
    def test_mgmt_batch_list_operations(self):
        operations = self.mgmt_batch_client.operations.list()
        all_ops = list(operations)
        assert len(all_ops)
        assert all_ops[0].name == 'Microsoft.Batch/batchAccounts/providers/Microsoft.Insights/diagnosticSettings/read'
        assert all_ops[0].origin == 'system'
        assert all_ops[0].display.provider == 'Microsoft Batch'
        assert all_ops[0].display.operation == 'Read diagnostic setting'

    @recorded_by_proxy
    def test_mgmt_batch_subscription_quota(self):
        quotas = self.mgmt_batch_client.location.get_quotas(AZURE_LOCATION)
        assert isinstance(quotas, models.BatchLocationQuota)
        assert quotas.account_quota == EXPECTED_ACCOUNT_QUOTA

    @recorded_by_proxy
    def test_mgmt_batch_account_name(self):
        # Test Invalid Account Name
        availability = self.mgmt_batch_client.location.check_name_availability(
            AZURE_LOCATION,
            {
                "name": "randombatchaccount@5^$g9873495873"
            }
        )
        assert isinstance(availability, models.CheckNameAvailabilityResult)
        assert not availability.name_available
        assert availability.reason == models.NameAvailabilityReason.invalid

        # Test Available Account Name
        availability = self.mgmt_batch_client.location.check_name_availability(
            AZURE_LOCATION,
            {
                "name": self._get_account_name()
            }
        )
        assert isinstance(availability, models.CheckNameAvailabilityResult)
        assert availability.name_available

    # @KeyVaultPreparer(location=AZURE_LOCATION)
    @ResourceGroupPreparer(location=AZURE_LOCATION)
    @recorded_by_proxy
    def test_mgmt_batch_byos_account(self, resource_group, location):
        # if self.is_live:
        #     keyvault = keyvault.result()
        batch_account = models.BatchAccountCreateParameters(
                location=location,
                pool_allocation_mode=models.PoolAllocationMode.user_subscription)
        with pytest.raises(Exception):  # TODO: What exception
            creating = self.mgmt_batch_client.batch_account.begin_create(
                resource_group.name,
                self._get_account_name(),
                batch_account)
            creating.result()

        # keyvault_id = "/subscriptions/{}/resourceGroups/{}/providers/Microsoft.KeyVault/vaults/{}".format(
        #     self.get_settings_value("SUBSCRIPTION_ID"), resource_group.name, keyvault.name)
        # keyvault_url = "https://{}.vault.azure.net/".format(keyvault.name)
        # batch_account = models.BatchAccountCreateParameters(
        #         location=location,
        #         pool_allocation_mode=models.PoolAllocationMode.user_subscription,
        #         key_vault_reference={'id': keyvault_id, 'url': keyvault_url})
        # creating = self.mgmt_batch_client.batch_account.begin_create(
        #         resource_group.name,
        #         self._get_account_name(),
        #         batch_account)
        # creating.result()

    @pytest.mark.skip('hard to test')
    @ResourceGroupPreparer(location=AZURE_LOCATION)
    @recorded_by_proxy
    def test_mgmt_batch_account(self, resource_group, location):
        batch_account = models.BatchAccountCreateParameters(
            location=location,
        )
        account_name = self._get_account_name()
        account_setup = self.mgmt_batch_client.batch_account.begin_create(
            resource_group.name,
            account_name,
            batch_account)
        account_setup.result()

        # Test Get Account
        account = self.mgmt_batch_client.batch_account.get(resource_group.name, account_name)
        assert account.dedicated_core_quota == EXPECTED_DEDICATED_CORE_QUOTA
        assert account.low_priority_core_quota == EXPECTED_LOW_PRIO_CORE_QUOTA
        assert account.pool_quota == EXPECTED_POOL_QUOTA
        assert account.pool_allocation_mode == 'BatchService'

        # Test List Accounts by Resource Group
        accounts = self.mgmt_batch_client.batch_account.list_by_resource_group(resource_group.name)
        assert len(list(accounts)) == 1

        # Test List Account Keys
        keys = self.mgmt_batch_client.batch_account.get_keys(resource_group.name, account_name)
        assert isinstance(keys, models.BatchAccountKeys)
        assert keys.account_name == account_name
        secondary = keys.secondary

        # Test Regenerate Account Key
        keys = self.mgmt_batch_client.batch_account.regenerate_key(
            resource_group.name,
            account_name,
            {
                "key_name": 'Secondary'
            }
        )
        assert isinstance(keys, models.BatchAccountKeys)
        assert not keys.secondary == secondary

        # Test Update Account
        update_tags = {'Name': 'tagName', 'Value': 'tagValue'}
        updated = self.mgmt_batch_client.batch_account.update(resource_group.name, account_name, models.BatchAccountUpdateParameters(tags=update_tags))
        assert isinstance(updated, models.BatchAccount)
        assert updated.tags['Name'] == 'tagName'
        assert updated.tags['Value'] == 'tagValue'

        # Test Delete Account
        response = self.mgmt_batch_client.batch_account.begin_delete(resource_group.name, account_name)
        assert response.result() is None

    @pytest.mark.skipif(os.getenv('AZURE_TEST_RUN_LIVE') not in ('yes', 'true'), reason='only run live test')
    @ResourceGroupPreparer(location=AZURE_LOCATION)
    @StorageAccountPreparer(name_prefix='batchx', location=AZURE_LOCATION)
    @recorded_by_proxy
    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

    @pytest.mark.skipif(os.getenv('AZURE_TEST_RUN_LIVE') not in ('yes', 'true'), reason='only run live test')
    @ResourceGroupPreparer(location=AZURE_LOCATION)
    @SimpleBatchPreparer(location=AZURE_LOCATION)
    @recorded_by_proxy
    def test_mgmt_batch_certificates(self, resource_group, location, batch_account):
        # Test Add Certificate
        parameters = models.CertificateCreateOrUpdateParameters(
            thumbprint='cff2ab63c8c955aaf71989efa641b906558d9fb7',
            thumbprint_algorithm='sha1',
            data='MIIGMQIBAzCCBe0GCSqGSIb3DQEHAaCCBd4EggXaMIIF1jCCA8AGCSqGSIb3DQEHAaCCA7EEggOtMIIDqTCCA6UGCyqGSIb3DQEMCgECoIICtjCCArIwHAYKKoZIhvcNAQwBAzAOBAhyd3xCtln3iQICB9AEggKQhe5P10V9iV1BsDlwWT561Yu2hVq3JT8ae/ebx1ZR/gMApVereDKkS9Zg4vFyssusHebbK5pDpU8vfAqle0TM4m7wGsRj453ZorSPUfMpHvQnAOn+2pEpWdMThU7xvZ6DVpwhDOQk9166z+KnKdHGuJKh4haMT7Rw/6xZ1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AbMwggGvMIIBXaADAgECAhAdka3aTQsIsUphgIXGUmeRMAkGBSsOAwIdBQAwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3kwHhcNMTYwMTAxMDcwMDAwWhcNMTgwMTAxMDcwMDAwWjASMRAwDgYDVQQDEwdub2Rlc2RrMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC5fhcxbJHxxBEIDzVOMc56s04U6k4GPY7yMR1m+rBGVRiAyV4RjY6U936dqXHCVD36ps2Q0Z+OeEgyCInkIyVeB1EwXcToOcyeS2YcUb0vRWZDouC3tuFdHwiK1Ed5iW/LksmXDotyV7kpqzaPhOFiMtBuMEwNJcPge9k17hRgRQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwCQYFKw4DAh0FAANBAHl2M97QbpzdnwO5HoRBsiEExOcLTNg+GKCr7HUsbzfvrUivw+JLL7qjHAIc5phnK+F5bQ8HKe0L9YXBSKl+fvwxFTATBgkqhkiG9w0BCRUxBgQEAQAAADA7MB8wBwYFKw4DAhoEFGVtyGMqiBd32fGpzlGZQoRM6UQwBBTI0YHFFqTS4Go8CoLgswn29EiuUQICB9A=',
            format=models.CertificateFormat.pfx,
            password='nodesdk')

        certificate = 'SHA1-cff2ab63c8c955aaf71989efa641b906558d9fb7'
        response = self.mgmt_batch_client.certificate.create(resource_group.name, batch_account.name, certificate, parameters)
        assert isinstance(response, models.Certificate)

        # Test List Certificates
        certs = self.mgmt_batch_client.certificate.list_by_batch_account(resource_group.name, batch_account.name)
        assert len(list(certs)) == 1

        # Test Get Certificate
        cert = self.mgmt_batch_client.certificate.get(resource_group.name, batch_account.name, certificate)
        assert isinstance(cert, models.Certificate)
        assert cert.thumbprint.lower() == 'cff2ab63c8c955aaf71989efa641b906558d9fb7'
        assert cert.thumbprint_algorithm == 'sha1'
        assert cert.delete_certificate_error is None

        # Test Update Certiciate
        parameters = models.CertificateCreateOrUpdateParameters(
            password='nodesdk',
            data='MIIGMQIBAzCCBe0GCSqGSIb3DQEHAaCCBd4EggXaMIIF1jCCA8AGCSqGSIb3DQEHAaCCA7EEggOtMIIDqTCCA6UGCyqGSIb3DQEMCgECoIICtjCCArIwHAYKKoZIhvcNAQwBAzAOBAhyd3xCtln3iQICB9AEggKQhe5P10V9iV1BsDlwWT561Yu2hVq3JT8ae/ebx1ZR/gMApVereDKkS9Zg4vFyssusHebbK5pDpU8vfAqle0TM4m7wGsRj453ZorSPUfMpHvQnAOn+2pEpWdMThU7xvZ6DVpwhDOQk9166z+KnKdHGuJKh4haMT7Rw/6xZ1rsBt2423cwTrQVMQyACrEkianpuujubKltN99qRoFAxhQcnYE2KlYKw7lRcExq6mDSYAyk5xJZ1ZFdLj6MAryZroQit/0g5eyhoNEKwWbi8px5j71pRTf7yjN+deMGQKwbGl+3OgaL1UZ5fCjypbVL60kpIBxLZwIJ7p3jJ+q9pbq9zSdzshPYor5lxyUfXqaso/0/91ayNoBzg4hQGh618PhFI6RMGjwkzhB9xk74iweJ9HQyIHf8yx2RCSI22JuCMitPMWSGvOszhbNx3AEDLuiiAOHg391mprEtKZguOIr9LrJwem/YmcHbwyz5YAbZmiseKPkllfC7dafFfCFEkj6R2oegIsZo0pEKYisAXBqT0g+6/jGwuhlZcBo0f7UIZm88iA3MrJCjlXEgV5OcQdoWj+hq0lKEdnhtCKr03AIfukN6+4vjjarZeW1bs0swq0l3XFf5RHa11otshMS4mpewshB9iO9MuKWpRxuxeng4PlKZ/zuBqmPeUrjJ9454oK35Pq+dghfemt7AUpBH/KycDNIZgfdEWUZrRKBGnc519C+RTqxyt5hWL18nJk4LvSd3QKlJ1iyJxClhhb/NWEzPqNdyA5cxen+2T9bd/EqJ2KzRv5/BPVwTQkHH9W/TZElFyvFfOFIW2+03RKbVGw72Mr/0xKZ+awAnEfoU+SL/2Gj2m6PHkqFX2sOCi/tN9EA4xgdswEw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A=',)
        response = self.mgmt_batch_client.certificate.update(resource_group.name, batch_account.name, certificate, parameters)
        assert isinstance(response, models.Certificate)

        # Test Cancel Certificate Delete
        #with pytest.raises(models.DeleteCertificateError):
        self.mgmt_batch_client.certificate.cancel_deletion(
            resource_group.name, batch_account.name, certificate)

        # Test Delete Certificate
        response = self.mgmt_batch_client.certificate.begin_delete(resource_group.name, batch_account.name, certificate)
        assert response.result() is None

    @pytest.mark.skip("model CloudServiceConfiguration deprecated")
    @pytest.mark.skipif(os.getenv('AZURE_TEST_RUN_LIVE') not in ('yes', 'true'), reason='only run live test')
    @ResourceGroupPreparer(location=AZURE_LOCATION)
    @SimpleBatchPreparer(location=AZURE_LOCATION)
    @recorded_by_proxy
    def test_mgmt_batch_pools(self, resource_group, location, batch_account):
        # Test create PAAS pool
        paas_pool = "test_paas_pool"
        parameters = models.Pool(
            display_name="test_pool",
            vm_size='small',
            deployment_configuration=models.DeploymentConfiguration(
                cloud_service_configuration=models.CloudServiceConfiguration(os_family='5')
            ),
            start_task=models.StartTask(
                command_line="cmd.exe /c \"echo hello world\"",
                resource_files=[models.ResourceFile(http_url='https://blobsource.com', file_path='filename.txt')],
                environment_settings=[models.EnvironmentSetting(name='ENV_VAR', value='env_value')],
                user_identity=models.UserIdentity(
                    auto_user=models.AutoUserSpecification(
                        elevation_level=models.ElevationLevel.admin
                    )
                )
            ),
            user_accounts=[models.UserAccount(name='UserName', password='p@55wOrd')],
            scale_settings=models.ScaleSettings(
                fixed_scale=models.FixedScaleSettings(
                    target_dedicated_nodes=0,
                    target_low_priority_nodes=0
                )
            )
        )
        response = self.mgmt_batch_client.pool.create(
            resource_group.name, batch_account.name, paas_pool, parameters)
        assert isinstance(response, models.Pool)

        # Test create IAAS pool
        iaas_pool = "test_iaas_pool"
        parameters = models.Pool(
            display_name="test_pool",
            vm_size='Standard_A1',
            deployment_configuration=models.DeploymentConfiguration(
                virtual_machine_configuration=models.VirtualMachineConfiguration(
                    image_reference=models.ImageReference(
                        publisher='MicrosoftWindowsServer',
                        offer='WindowsServer',
                        sku='2016-Datacenter-smalldisk'
                    ),
                    node_agent_sku_id='batch.node.windows amd64',
                    windows_configuration=models.WindowsConfiguration(enable_automatic_updates=True)
                )
            ),
            scale_settings=models.ScaleSettings(
                fixed_scale=models.FixedScaleSettings(
                    target_dedicated_nodes=0,
                    target_low_priority_nodes=0
                )
            )
        )

        response = self.mgmt_batch_client.pool.create(
            resource_group.name, batch_account.name, iaas_pool, parameters)
        assert isinstance(response, models.Pool)

        # Test list pools
        pools = self.mgmt_batch_client.pool.list_by_batch_account(resource_group.name, batch_account.name)
        assert len(list(pools)) == 2

        # Test Update pool
        parameters = models.Pool(
            scale_settings=models.ScaleSettings(
                auto_scale=models.AutoScaleSettings(
                    # Change this to a value once accounts get default quotas
                    formula='$TargetDedicatedNodes=0'
                )
            )
        )
        if self.is_live:
            time.sleep(15)
        response = self.mgmt_batch_client.pool.update(
            resource_group.name, batch_account.name, iaas_pool, parameters)
        assert isinstance(response, models.Pool)

        # Test Get pool
        pool = self.mgmt_batch_client.pool.get(
            resource_group.name, batch_account.name, iaas_pool)
        assert isinstance(pool, models.Pool)
        assert pool.vm_size == 'STANDARD_A1'
        assert pool.display_name is not None
        # This assert should be reintroduced when targetDedidicated nodes can be 1+
        # assert pool.allocation_state == models.AllocationState.resizing
        assert pool.deployment_configuration.virtual_machine_configuration.node_agent_sku_id == 'batch.node.windows amd64'

        # Test stop resizing
        # with pytest.raises(CloudError):
        #     self.mgmt_batch_client.pool.stop_resize(resource_group.name, batch_account.name, iaas_pool)
        # if self.is_live:
        #     time.sleep(300)
        # # Test disable auto-scale
        # response = self.mgmt_batch_client.pool.disable_auto_scale(
        #     resource_group.name, batch_account.name, iaas_pool)
        # assert isinstance(response, models.Pool)

        # Test delete pool
        response = self.mgmt_batch_client.pool.begin_delete(
            resource_group.name, batch_account.name, iaas_pool)
        assert response.result() is None

    @pytest.mark.skipif(os.getenv('AZURE_TEST_RUN_LIVE') not in ('yes', 'true'), reason='only run live test')
    @ResourceGroupPreparer(location=AZURE_LOCATION, random_name_enabled=True)
    @recorded_by_proxy
    def test_mgmt_batch_account_advanced(self, resource_group, location):
        batch_account_name = self.get_resource_name('batchpendpoint')
        vnet_name = self.get_resource_name('vnet')
        subnet_name = self.get_resource_name('subnet')
        subnet_id = "/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Network/virtualNetworks/{}/subnets/{}".format(
            self.get_settings_value("SUBSCRIPTION_ID"),
            resource_group.name,
            vnet_name,
            subnet_name)
        private_endpoint_name = self.get_resource_name('pe')
        private_connection_name = self.get_resource_name('pec')
        private_link_service_id = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Batch/batchAccounts/{}'.format(
            self.get_settings_value("SUBSCRIPTION_ID"),
            resource_group.name,
            batch_account_name)
        batch_account = models.BatchAccountCreateParameters(
            location=location,
            public_network_access='Disabled',
            identity=models.BatchAccountIdentity(
                type='SystemAssigned'
            ))
        self.mgmt_batch_client.batch_account.begin_create(
            resource_group_name=resource_group.name,
            account_name=batch_account_name,
            parameters=batch_account).result()
        if self.is_live:
            self.mgmt_network.virtual_networks.begin_create_or_update(
                resource_group_name=resource_group.name,
                virtual_network_name=vnet_name,
                parameters=self.mgmt_network.models().VirtualNetwork(
                    address_space=self.mgmt_network.models().AddressSpace(
                        address_prefixes=['10.0.0.0/16']),
                    location=location,
                    subnets=[
                        self.mgmt_network.models().Subnet(
                            address_prefix='10.0.0.0/24',
                            name=subnet_name,
                            private_endpoint_network_policies='Disabled')])
            ).result()
            self.mgmt_network.private_endpoints.begin_create_or_update(
                resource_group_name=resource_group.name,
                private_endpoint_name=private_endpoint_name,
                parameters=self.mgmt_network.models().PrivateEndpoint(
                    location=location,
                    subnet=self.mgmt_network.models().Subnet(
                        id=subnet_id
                    ),
                    manual_private_link_service_connections=[
                        self.mgmt_network.models().PrivateLinkServiceConnection(
                            private_link_service_id=private_link_service_id,
                            group_ids=['batchAccount'],
                            name=private_connection_name
                        )]
                )
            ).result()
        private_links = self.mgmt_batch_client.private_link_resource.list_by_batch_account(
            resource_group_name=resource_group.name,
            account_name=batch_account_name)
        private_link = private_links.__next__()
        self.mgmt_batch_client.private_link_resource.get(
            resource_group_name=resource_group.name,
            account_name=batch_account_name,
            private_link_resource_name=private_link.name)
        private_endpoints = self.mgmt_batch_client.private_endpoint_connection.list_by_batch_account(
            resource_group_name=resource_group.name,
            account_name=batch_account_name)

        private_endpoint = private_endpoints.__next__()
        self.mgmt_batch_client.private_endpoint_connection.get(
            resource_group_name=resource_group.name,
            account_name=batch_account_name,
            private_endpoint_connection_name=private_endpoint.name)
        self.mgmt_batch_client.private_endpoint_connection.begin_update(
            resource_group_name=resource_group.name,
            account_name=batch_account_name,
            private_endpoint_connection_name=private_endpoint.name,
            parameters={
                "private_link_service_connection_state": {
                    "status": "Approved",
                    "description": "Approved for test"
                }
            }
        ).result()