diff --git a/sdk/datalake/azure-mgmt-datalake-analytics/MANIFEST.in b/sdk/datalake/azure-mgmt-datalake-analytics/MANIFEST.in index 1c9ebaab0de4..c0cf549166ee 100644 --- a/sdk/datalake/azure-mgmt-datalake-analytics/MANIFEST.in +++ b/sdk/datalake/azure-mgmt-datalake-analytics/MANIFEST.in @@ -1,4 +1,6 @@ +recursive-include tests *.py *.yaml include *.rst include azure/__init__.py include azure/mgmt/__init__.py include azure/mgmt/datalake/__init__.py + diff --git a/sdk/datalake/azure-mgmt-datalake-analytics/README.rst b/sdk/datalake/azure-mgmt-datalake-analytics/README.rst index 756ded7f07a9..fb18ab8d347d 100644 --- a/sdk/datalake/azure-mgmt-datalake-analytics/README.rst +++ b/sdk/datalake/azure-mgmt-datalake-analytics/README.rst @@ -6,7 +6,7 @@ This is the Microsoft Azure Data Lake Analytics Management Client Library. Azure Resource Manager (ARM) is the next generation of management APIs that replace the old Azure Service Management (ASM). -This package has been tested with Python 2.7, 3.4, 3.5, 3.6 and 3.7. +This package has been tested with Python 2.7, 3.5, 3.6 and 3.7. For the older Azure Service Management (ASM) libraries, see `azure-servicemanagement-legacy `__ library. @@ -14,25 +14,6 @@ For the older Azure Service Management (ASM) libraries, see For a more complete set of Azure libraries, see the `azure `__ bundle package. -Compatibility -============= - -**IMPORTANT**: If you have an earlier version of the azure package -(version < 1.0), you should uninstall it before installing this package. - -You can check the version using pip: - -.. code:: shell - - pip freeze - -If you see azure==0.11.0 (or any version below 1.0), uninstall it first: - -.. code:: shell - - pip uninstall azure - - Usage ===== diff --git a/sdk/datalake/azure-mgmt-datalake-analytics/setup.py b/sdk/datalake/azure-mgmt-datalake-analytics/setup.py index 68f340388091..4ba2e4e83639 100644 --- a/sdk/datalake/azure-mgmt-datalake-analytics/setup.py +++ b/sdk/datalake/azure-mgmt-datalake-analytics/setup.py @@ -53,6 +53,7 @@ version=version, description='Microsoft Azure {} Client Library for Python'.format(PACKAGE_PPRINT_NAME), long_description=readme + '\n\n' + history, + long_description_content_type='text/x-rst', license='MIT License', author='Microsoft Corporation', author_email='azpysdkhelp@microsoft.com', @@ -63,7 +64,6 @@ 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', diff --git a/sdk/datalake/azure-mgmt-datalake-analytics/tests/test_mgmt_datalake_analytics.py b/sdk/datalake/azure-mgmt-datalake-analytics/tests/test_mgmt_datalake_analytics.py index 6f23cefc7841..fd9d27cf5e6a 100644 --- a/sdk/datalake/azure-mgmt-datalake-analytics/tests/test_mgmt_datalake_analytics.py +++ b/sdk/datalake/azure-mgmt-datalake-analytics/tests/test_mgmt_datalake_analytics.py @@ -16,10 +16,13 @@ # 'East US 2' is the ADL production region for now _REGION = 'East US 2' +# this is used explicitly for ADLA job id replacement in recordings. +ADLA_JOB_ID = "00000000-0000-0000-0000-000000000000" + class MgmtDataLakeAnalyticsTest(AzureMgmtTestCase): def setUp(self): super(MgmtDataLakeAnalyticsTest, self).setUp() - + self.adls_account_client = self.create_mgmt_client( azure.mgmt.datalake.store.DataLakeStoreAccountManagementClient ) @@ -54,20 +57,20 @@ def setUp(self): self.credential_name = self.get_resource_name('adlacredential') self.credential_id = self.get_resource_name('adlacredid') self.schema_name = 'dbo' - - self.catalog_script = """DROP DATABASE IF EXISTS {0}; CREATE DATABASE {0}; + + self.catalog_script = """DROP DATABASE IF EXISTS {0}; CREATE DATABASE {0}; CREATE TABLE {0}.dbo.{1} ( //Define schema of table - UserId int, - Start DateTime, - Region string, - Query string, - Duration int, - Urls string, + UserId int, + Start DateTime, + Region string, + Query string, + Duration int, + Urls string, ClickedUrls string, - INDEX idx1 - CLUSTERED (Region ASC) + INDEX idx1 + CLUSTERED (Region ASC) PARTITIONED BY (UserId) HASH (Region) ); @@ -88,23 +91,23 @@ def setUp(self): s_date DateTime, s_time string, s_sitename string, - cs_method string, + cs_method string, cs_uristem string, cs_uriquery string, s_port int, - cs_username string, + cs_username string, c_ip string, cs_useragent string, cs_cookie string, - cs_referer string, + cs_referer string, cs_host string, sc_status int, sc_substatus int, - sc_win32status int, + sc_win32status int, sc_bytes int, cs_bytes int, s_timetaken int -) +) AS BEGIN @@ -133,38 +136,38 @@ def setUp(self): RETURN; END; -CREATE VIEW {0}.dbo.{3} -AS - SELECT * FROM +CREATE VIEW {0}.dbo.{3} +AS + SELECT * FROM ( VALUES(1,2),(2,4) - ) -AS + ) +AS T(a, b); CREATE PROCEDURE {0}.dbo.{4}() AS BEGIN - CREATE VIEW {0}.dbo.{3} - AS - SELECT * FROM + CREATE VIEW {0}.dbo.{3} + AS + SELECT * FROM ( VALUES(1,2),(2,4) - ) - AS + ) + AS T(a, b); END;""".format(self.db_name, self.table_name, self.tvf_name, self.view_name, self.proc_name) # define all the job IDs to be used during execution if self.is_playback(): - self.cancel_id = self._fake_settings.ADLA_JOB_ID - self.run_id = self._fake_settings.ADLA_JOB_ID - self.catalog_id = self._fake_settings.ADLA_JOB_ID - self.cred_create_id = self._fake_settings.ADLA_JOB_ID - self.cred_drop_id = self._fake_settings.ADLA_JOB_ID - self.pipeline_id = self._fake_settings.ADLA_JOB_ID - self.recurrence_id = self._fake_settings.ADLA_JOB_ID - self.run_id_2 = self._fake_settings.ADLA_JOB_ID - self.run_id_3 = self._fake_settings.ADLA_JOB_ID - self.principal_id = self._fake_settings.ADLA_JOB_ID + self.cancel_id = ADLA_JOB_ID + self.run_id = ADLA_JOB_ID + self.catalog_id = ADLA_JOB_ID + self.cred_create_id = ADLA_JOB_ID + self.cred_drop_id = ADLA_JOB_ID + self.pipeline_id = ADLA_JOB_ID + self.recurrence_id = ADLA_JOB_ID + self.run_id_2 = ADLA_JOB_ID + self.run_id_3 = ADLA_JOB_ID + self.principal_id = ADLA_JOB_ID else: self.cancel_id = str(uuid.uuid1()) self.run_id = str(uuid.uuid1()) @@ -178,16 +181,16 @@ def setUp(self): self.principal_id = str(uuid.uuid1()) real_to_fake_dict = { - self.cancel_id: self._fake_settings.ADLA_JOB_ID, - self.run_id: self._fake_settings.ADLA_JOB_ID, - self.catalog_id: self._fake_settings.ADLA_JOB_ID, - self.cred_create_id: self._fake_settings.ADLA_JOB_ID, - self.cred_drop_id: self._fake_settings.ADLA_JOB_ID, - self.pipeline_id: self._fake_settings.ADLA_JOB_ID, - self.recurrence_id: self._fake_settings.ADLA_JOB_ID, - self.run_id_2: self._fake_settings.ADLA_JOB_ID, - self.run_id_3: self._fake_settings.ADLA_JOB_ID, - self.principal_id: self._fake_settings.ADLA_JOB_ID + self.cancel_id: ADLA_JOB_ID, + self.run_id: ADLA_JOB_ID, + self.catalog_id: ADLA_JOB_ID, + self.cred_create_id: ADLA_JOB_ID, + self.cred_drop_id: ADLA_JOB_ID, + self.pipeline_id: ADLA_JOB_ID, + self.recurrence_id: ADLA_JOB_ID, + self.run_id_2: ADLA_JOB_ID, + self.run_id_3: ADLA_JOB_ID, + self.principal_id: ADLA_JOB_ID } for key in real_to_fake_dict: @@ -205,7 +208,7 @@ def run_prereqs(self, resource_group, location, create_job_acct = False, create_ self.adls_account_name, params_create, ).result() - + # validation of the create self.assertEqual(adls_account.name, self.adls_account_name) @@ -226,14 +229,14 @@ def run_prereqs(self, resource_group, location, create_job_acct = False, create_ self.job_account_name, params_create, ).result() - + # full validation of the create self.assertEqual(adla_account.name, self.job_account_name) # wait five minutes for the account to be fully provisioned with a queue. if self.is_live: time.sleep(300) - + if create_catalog: self.run_job_to_completion(self.job_account_name, self.catalog_id, self.catalog_script) @@ -254,7 +257,7 @@ def run_job_to_completion(self, adla_account_name, job_id, script_to_run, job_pa job_params ) self.assertIsNotNone(create_response) - + max_wait_in_seconds = 180 cur_wait_in_seconds = 0 adla_job = self.adla_job_client.job.get( @@ -262,7 +265,7 @@ def run_job_to_completion(self, adla_account_name, job_id, script_to_run, job_pa job_id ) self.assertIsNotNone(adla_job) - + while adla_job.state != azure.mgmt.datalake.analytics.job.models.JobState.ended and cur_wait_in_seconds < max_wait_in_seconds: if self.is_live: time.sleep(5) @@ -276,9 +279,9 @@ def run_job_to_completion(self, adla_account_name, job_id, script_to_run, job_pa self.assertTrue(cur_wait_in_seconds <= max_wait_in_seconds) self.assertTrue(adla_job.state == azure.mgmt.datalake.analytics.job.models.JobState.ended and adla_job.result == azure.mgmt.datalake.analytics.job.models.JobResult.succeeded, 'Job: {0} did not return success. Current job state: {1}. Actual result: {2}. Error (if any): {3}'.format( - adla_job.job_id, - adla_job.state, - adla_job.result, + adla_job.job_id, + adla_job.state, + adla_job.result, adla_job.error_message )) @@ -419,7 +422,7 @@ def test_adla_catalog_items(self, resource_group, location): self.assertIsNotNone(table_match) self.assertEqual(len(table_match), 1) self.assertIsNotNone(table_match[0].column_list) - + # get the tabe list with only basic info and verify that extended properties are empty table_list = list(self.adla_catalog_client.catalog.list_tables(self.job_account_name, self.db_name, self.schema_name, basic=True)) self.assertGreater(len(table_list), 0) @@ -473,14 +476,14 @@ def test_adla_catalog_items(self, resource_group, location): tvf_match = [item for item in tvf_list if item.name == self.tvf_name] self.assertIsNotNone(tvf_list) self.assertEqual(len(tvf_list), 1) - + # get tvf list by database tvf_list = list(self.adla_catalog_client.catalog.list_table_valued_functions_by_database(self.job_account_name, self.db_name)) self.assertGreater(len(tvf_list), 0) tvf_match = [item for item in tvf_list if item.name == self.tvf_name] self.assertIsNotNone(tvf_list) self.assertEqual(len(tvf_list), 1) - + # get specific tvf specific_tvf = self.adla_catalog_client.catalog.get_table_valued_function(self.job_account_name, self.db_name, self.schema_name, self.tvf_name) self.assertEqual(specific_tvf.name, tvf_match[0].name) @@ -553,7 +556,7 @@ def test_adla_catalog_items(self, resource_group, location): # get the initial number of ACLs by db acl_by_db_list = list( self.adla_catalog_client.catalog.list_acls_by_database( - self.job_account_name, + self.job_account_name, self.db_name ) ) @@ -566,14 +569,14 @@ def test_adla_catalog_items(self, resource_group, location): # grant ACL to the db self.adla_catalog_client.catalog.grant_acl_to_database( - self.job_account_name, - self.db_name, + self.job_account_name, + self.db_name, grant_acl_param ) acl_by_db_list = list( self.adla_catalog_client.catalog.list_acls_by_database( - self.job_account_name, + self.job_account_name, self.db_name ) ) @@ -588,15 +591,15 @@ def test_adla_catalog_items(self, resource_group, location): # revoke ACL from the db self.adla_catalog_client.catalog.revoke_acl_from_database( - self.job_account_name, - self.db_name, - revoke_ace_type, + self.job_account_name, + self.db_name, + revoke_ace_type, revoke_principal_id ) acl_by_db_list = list( self.adla_catalog_client.catalog.list_acls_by_database( - self.job_account_name, + self.job_account_name, self.db_name ) ) @@ -605,7 +608,7 @@ def test_adla_catalog_items(self, resource_group, location): # grant ACL to the catalog self.adla_catalog_client.catalog.grant_acl( - self.job_account_name, + self.job_account_name, grant_acl_param ) @@ -620,8 +623,8 @@ def test_adla_catalog_items(self, resource_group, location): # revoke ACL from the catalog self.adla_catalog_client.catalog.revoke_acl( - self.job_account_name, - revoke_ace_type, + self.job_account_name, + revoke_ace_type, revoke_principal_id ) @@ -643,7 +646,7 @@ def test_adla_catalog_credentials(self, resource_group, location): user_id = self.credential_id ) ) - + # try to create the credential again. try: self.adla_catalog_client.catalog.create_credential( @@ -659,7 +662,7 @@ def test_adla_catalog_credentials(self, resource_group, location): self.assertTrue(False, 'should not have made it here') except Exception: pass - + # get credential and ensure the response is not null cred_response = self.adla_catalog_client.catalog.get_credential( self.job_account_name, @@ -676,7 +679,7 @@ def test_adla_catalog_credentials(self, resource_group, location): self.db_name ) ) - + self.assertIsNotNone(cred_list) self.assertGreater(len(cred_list), 0) specific_cred = [item for item in cred_list if item.name == self.credential_name] @@ -737,7 +740,7 @@ def test_adla_compute_policies(self, resource_group, location): account_name, params_create, ).result() - + # full validation of the create self.assertEqual(adla_account.name, account_name) self.assertIsNotNone(adla_account.id) @@ -768,7 +771,7 @@ def test_adla_compute_policies(self, resource_group, location): min_priority_per_job = 1 ) ) - + self.assertEqual(group_id, new_policy.object_id) self.assertEqual(azure.mgmt.datalake.analytics.account.models.AADObjectType.group.value, new_policy.object_type) self.assertEqual(1, new_policy.max_degree_of_parallelism_per_job) @@ -840,7 +843,7 @@ def test_adla_accounts(self, resource_group, location): # ensure that the account name is available name_availability = self.adla_account_client.accounts.check_name_availability( - location.replace(" ", ""), + location.replace(" ", ""), account_name ) self.assertTrue(name_availability.name_available) @@ -851,10 +854,10 @@ def test_adla_accounts(self, resource_group, location): account_name, params_create ).result() - + # ensure that the account name is no longer available name_availability = self.adla_account_client.accounts.check_name_availability( - location.replace(" ", ""), + location.replace(" ", ""), account_name ) self.assertFalse(name_availability.name_available) @@ -907,7 +910,7 @@ def test_adla_accounts(self, resource_group, location): self.assertEqual(adla_account.tags['tag2'], 'value2') - # confirm that 'locations.get_capability' is functional + # confirm that 'locations.get_capability' is functional get_capability = self.adla_account_client.locations.get_capability(location.replace(" ", "")) self.assertIsNotNone(get_capability) diff --git a/sdk/graphrbac/azure-graphrbac/README.rst b/sdk/graphrbac/azure-graphrbac/README.rst index 308d61ae5702..daa1a719d920 100644 --- a/sdk/graphrbac/azure-graphrbac/README.rst +++ b/sdk/graphrbac/azure-graphrbac/README.rst @@ -3,7 +3,7 @@ Microsoft Azure SDK for Python This is the Microsoft Azure Graph RBAC Client Library. -This package has been tested with Python 2.7, 3.4, 3.5, 3.6 and 3.7. +This package has been tested with Python 2.7, 3.5, 3.6 and 3.7. For a more complete set of Azure libraries, see the `azure `__ bundle package. diff --git a/sdk/graphrbac/azure-graphrbac/setup.py b/sdk/graphrbac/azure-graphrbac/setup.py index b076f30459e8..8dca49caa9f1 100644 --- a/sdk/graphrbac/azure-graphrbac/setup.py +++ b/sdk/graphrbac/azure-graphrbac/setup.py @@ -64,7 +64,6 @@ 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', diff --git a/sdk/graphrbac/azure-graphrbac/tests/test_graphrbac.py b/sdk/graphrbac/azure-graphrbac/tests/test_graphrbac.py index 735007590725..2c9401ae65ee 100644 --- a/sdk/graphrbac/azure-graphrbac/tests/test_graphrbac.py +++ b/sdk/graphrbac/azure-graphrbac/tests/test_graphrbac.py @@ -12,18 +12,24 @@ import pytest +# GraphRBAC tests +AD_DOMAIN = "myaddomain.onmicrosoft.com" + class GraphRbacTest(AzureMgmtTestCase): def setUp(self): super(GraphRbacTest, self).setUp() + # Set the env variable AZURE_AD_DOMAIN or put AD_DOMAIN in your "mgmt_settings_real" file + self.ad_domain = self.set_value_to_scrub('AD_DOMAIN', AD_DOMAIN) + self.graphrbac_client = self.create_basic_client( azure.graphrbac.GraphRbacManagementClient, - tenant_id=self.settings.AD_DOMAIN + tenant_id=self.ad_domain ) def _build_object_url(self, object_id): return "https://graph.windows.net/{}/directoryObjects/{}".format( - self.settings.AD_DOMAIN, + self.ad_domain, object_id ) @@ -105,7 +111,7 @@ def test_graphrbac_users(self): user = self.graphrbac_client.users.create( azure.graphrbac.models.UserCreateParameters( - user_principal_name="testbuddy#TEST@{}".format(self.settings.AD_DOMAIN), + user_principal_name="testbuddy#TEST@{}".format(self.ad_domain), account_enabled=False, display_name='Test Buddy', mail_nickname='testbuddy', diff --git a/sdk/hdinsight/azure-mgmt-hdinsight/test/mgmt_hdinsight_preparers.py b/sdk/hdinsight/azure-mgmt-hdinsight/test/mgmt_hdinsight_preparers.py index 5837c64fd368..a75193bdd36a 100644 --- a/sdk/hdinsight/azure-mgmt-hdinsight/test/mgmt_hdinsight_preparers.py +++ b/sdk/hdinsight/azure-mgmt-hdinsight/test/mgmt_hdinsight_preparers.py @@ -27,6 +27,8 @@ certificates=[perm.value for perm in CertificatePermissions], storage=[perm.value for perm in StoragePermissions]) DEFAULT_SKU = SkuName.premium.value +CLIENT_OID = '00000000-0000-0000-0000-000000000000' + class KeyVaultPreparer(AzureMgmtPreparer): def __init__(self, @@ -58,6 +60,7 @@ def __init__(self, self.parameter_name = parameter_name self.creds_parameter = 'credentials' self.parameter_name_for_location = 'location' + self.client_oid = None def _get_resource_group(self, **kwargs): try: @@ -69,10 +72,11 @@ def _get_resource_group(self, **kwargs): def create_resource(self, name, **kwargs): + self.client_oid = self.test_class_instance.set_value_to_scrub('CLIENT_OID', CLIENT_OID) group = self._get_resource_group(**kwargs).name access_policies = [AccessPolicyEntry(tenant_id=self.test_class_instance.settings.TENANT_ID, - object_id=self.test_class_instance.settings.CLIENT_OID, + object_id=self.client_oid, permissions=self.permissions)] properties = VaultProperties(tenant_id=self.test_class_instance.settings.TENANT_ID, sku=Sku(name=self.sku), diff --git a/sdk/keyvault/azure-keyvault-certificates/sdk_packaging.toml b/sdk/keyvault/azure-keyvault-certificates/sdk_packaging.toml new file mode 100644 index 000000000000..e7687fdae93b --- /dev/null +++ b/sdk/keyvault/azure-keyvault-certificates/sdk_packaging.toml @@ -0,0 +1,2 @@ +[packaging] +auto_update = false \ No newline at end of file diff --git a/sdk/keyvault/azure-keyvault-certificates/tests/certificates_preparer.py b/sdk/keyvault/azure-keyvault-certificates/tests/certificates_preparer.py index 5c69a25a32a7..e95af94471b4 100644 --- a/sdk/keyvault/azure-keyvault-certificates/tests/certificates_preparer.py +++ b/sdk/keyvault/azure-keyvault-certificates/tests/certificates_preparer.py @@ -41,6 +41,7 @@ storage=[perm.value for perm in StoragePermissions], ) DEFAULT_SKU = SkuName.premium.value +CLIENT_OID = '00000000-0000-0000-0000-000000000000' class VaultClientPreparer(AzureMgmtPreparer): @@ -78,6 +79,7 @@ def __init__( self.parameter_name = parameter_name self.creds_parameter = "credentials" self.parameter_name_for_location = "location" + self.client_oid = None def _get_resource_group(self, **kwargs): try: @@ -90,13 +92,14 @@ def _get_resource_group(self, **kwargs): raise AzureTestError(template.format(ResourceGroupPreparer.__name__)) def create_resource(self, name, **kwargs): + self.client_oid = self.test_class_instance.set_value_to_scrub('CLIENT_OID', CLIENT_OID) if self.is_live: # create a vault with the management client group = self._get_resource_group(**kwargs).name access_policies = [ AccessPolicyEntry( tenant_id=self.test_class_instance.settings.TENANT_ID, - object_id=self.test_class_instance.settings.CLIENT_OID, + object_id=self.client_oid, permissions=self.permissions, ) ] diff --git a/sdk/keyvault/azure-keyvault-keys/tests/keys_preparer.py b/sdk/keyvault/azure-keyvault-keys/tests/keys_preparer.py index 4d23f439e3c8..a04cb238fd40 100644 --- a/sdk/keyvault/azure-keyvault-keys/tests/keys_preparer.py +++ b/sdk/keyvault/azure-keyvault-keys/tests/keys_preparer.py @@ -40,6 +40,7 @@ storage=[perm.value for perm in StoragePermissions], ) DEFAULT_SKU = SkuName.premium.value +CLIENT_OID = '00000000-0000-0000-0000-000000000000' class VaultClientPreparer(AzureMgmtPreparer): @@ -77,6 +78,7 @@ def __init__( self.parameter_name = parameter_name self.creds_parameter = "credentials" self.parameter_name_for_location = "location" + self.client_oid = None def _get_resource_group(self, **kwargs): try: @@ -89,13 +91,14 @@ def _get_resource_group(self, **kwargs): raise AzureTestError(template.format(ResourceGroupPreparer.__name__)) def create_resource(self, name, **kwargs): + self.client_oid = self.test_class_instance.set_value_to_scrub('CLIENT_OID', CLIENT_OID) if self.is_live: # create a vault with the management client group = self._get_resource_group(**kwargs).name access_policies = [ AccessPolicyEntry( tenant_id=self.test_class_instance.settings.TENANT_ID, - object_id=self.test_class_instance.settings.CLIENT_OID, + object_id=self.client_oid, permissions=self.permissions, ) ] diff --git a/sdk/keyvault/azure-keyvault-secrets/tests/secrets_preparer.py b/sdk/keyvault/azure-keyvault-secrets/tests/secrets_preparer.py index bf76c1718178..2c19732edbaf 100644 --- a/sdk/keyvault/azure-keyvault-secrets/tests/secrets_preparer.py +++ b/sdk/keyvault/azure-keyvault-secrets/tests/secrets_preparer.py @@ -40,6 +40,7 @@ storage=[perm.value for perm in StoragePermissions], ) DEFAULT_SKU = SkuName.premium.value +CLIENT_OID = '00000000-0000-0000-0000-000000000000' class VaultClientPreparer(AzureMgmtPreparer): @@ -77,6 +78,7 @@ def __init__( self.parameter_name = parameter_name self.creds_parameter = "credentials" self.parameter_name_for_location = "location" + self.client_oid = None def _get_resource_group(self, **kwargs): try: @@ -89,13 +91,14 @@ def _get_resource_group(self, **kwargs): raise AzureTestError(template.format(ResourceGroupPreparer.__name__)) def create_resource(self, name, **kwargs): + self.client_oid = self.test_class_instance.set_value_to_scrub('CLIENT_OID', CLIENT_OID) if self.is_live: # create a vault with the management client group = self._get_resource_group(**kwargs).name access_policies = [ AccessPolicyEntry( tenant_id=self.test_class_instance.settings.TENANT_ID, - object_id=self.test_class_instance.settings.CLIENT_OID, + object_id=self.client_oid, permissions=self.permissions, ) ] diff --git a/tools/azure-sdk-tools/devtools_testutils/azure_testcase.py b/tools/azure-sdk-tools/devtools_testutils/azure_testcase.py index 2fcf684f7e51..f201869ecf2b 100644 --- a/tools/azure-sdk-tools/devtools_testutils/azure_testcase.py +++ b/tools/azure-sdk-tools/devtools_testutils/azure_testcase.py @@ -100,6 +100,24 @@ def _get_replay_processors(self): def is_playback(self): return not self.is_live + def get_settings_value(self, key): + key_value = os.environ.get("AZURE_"+key, None) + + if key_value and self._real_settings and getattr(self._real_settings, key) != key_value: + raise ValueError("You have both AZURE_{key} env variable and mgmt_settings_real.py for {key} to difference values".format(key=key)) + + if not key_value: + key_value = getattr(self.settings, key) + return key_value + + def set_value_to_scrub(self, key, default_value): + if self.is_live: + value = self.get_settings_value(key) + self.scrubber.register_name_pair(value, default_value) + return value + else: + return default_value + def setUp(self): # Every test uses a different resource group name calculated from its @@ -130,9 +148,23 @@ def create_basic_client(self, client_class, **kwargs): **kwargs ) + tenant_id = os.environ.get("AZURE_TENANT_ID", None) + client_id = os.environ.get("AZURE_CLIENT_ID", None) + secret = os.environ.get("AZURE_CLIENT_SECRET", None) + + if tenant_id and client_id and secret and self.is_live: + from msrestazure.azure_active_directory import ServicePrincipalCredentials + credentials = ServicePrincipalCredentials( + tenant=tenant_id, + client_id=client_id, + secret=secret + ) + else: + credentials = self.settings.get_credentials() + # Real client creation client = client_class( - credentials=self.settings.get_credentials(), + credentials=credentials, **kwargs ) if self.is_playback(): diff --git a/tools/azure-sdk-tools/devtools_testutils/mgmt_settings_fake.py b/tools/azure-sdk-tools/devtools_testutils/mgmt_settings_fake.py index d2945f2d34ab..ad339b470b7f 100644 --- a/tools/azure-sdk-tools/devtools_testutils/mgmt_settings_fake.py +++ b/tools/azure-sdk-tools/devtools_testutils/mgmt_settings_fake.py @@ -11,13 +11,8 @@ SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000" -# this is used explicitly for ADLA job id replacement in recordings. -ADLA_JOB_ID = "00000000-0000-0000-0000-000000000000" -# GraphRBAC tests -AD_DOMAIN = "myaddomain.onmicrosoft.com" # Keyvault tests TENANT_ID = '00000000-0000-0000-0000-000000000000' -CLIENT_OID = '00000000-0000-0000-0000-000000000000' # Cognitive Services tests CS_SUBSCRIPTION_KEY = '0000000000000000000000000000' # Event Grid key @@ -44,7 +39,7 @@ def get_credentials(**kwargs): # 'user@myaddomain.onmicrosoft.com', # 'Password' #) - # note that UserCredential does not work any longer. Must use a ServicePrincipal. + # note that UserCredential does not work any longer. Must use a ServicePrincipal. # for deprecated APIs I believe will still work. # return ServicePrincipalCredentials( # client_id = '', diff --git a/tools/azure-sdk-tools/devtools_testutils/mgmt_testcase.py b/tools/azure-sdk-tools/devtools_testutils/mgmt_testcase.py index f1ccbd77521b..26d2f84cf884 100644 --- a/tools/azure-sdk-tools/devtools_testutils/mgmt_testcase.py +++ b/tools/azure-sdk-tools/devtools_testutils/mgmt_testcase.py @@ -73,10 +73,11 @@ def __init__(self, method_name, config_file=None, ) def _setup_scrubber(self): - constants_to_scrub = ['SUBSCRIPTION_ID', 'AD_DOMAIN', 'TENANT_ID', 'CLIENT_OID', 'ADLA_JOB_ID'] + constants_to_scrub = ['SUBSCRIPTION_ID', 'TENANT_ID'] for key in constants_to_scrub: - if hasattr(self.settings, key) and hasattr(self._fake_settings, key): - self.scrubber.register_name_pair(getattr(self.settings, key), + key_value = self.get_settings_value(key) + if key_value and hasattr(self._fake_settings, key): + self.scrubber.register_name_pair(key_value, getattr(self._fake_settings, key)) def setUp(self): @@ -110,9 +111,15 @@ def create_mgmt_client(self, client_class, **kwargs): **kwargs ) + subscription_id = None + if self.is_live: + subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", None) + if not subscription_id: + subscription_id = self.settings.SUBSCRIPTION_ID + return self.create_basic_client( client_class, - subscription_id=self.settings.SUBSCRIPTION_ID, + subscription_id=subscription_id, **kwargs ) @@ -152,8 +159,6 @@ def moniker(self): return self.resource_moniker def create_mgmt_client(self, client_class): - return client_class( - credentials=self.test_class_instance.settings.get_credentials(), - subscription_id=self.test_class_instance.settings.SUBSCRIPTION_ID, - **self.client_kwargs + return self.test_class_instance.create_mgmt_client( + client_class )