Skip to content

Commit

Permalink
Test preparer region config loader (and DeleteAfter fixes) (#12924)
Browse files Browse the repository at this point in the history
* Initial implementation of region-loading-from-config, and opting in for SB and EH to support canary region specification.

* Truncate DeleteAfter at milliseconds to hopefully allow it to get picked up by engsys.  Add get_region_override to __init__ exports.

* Provide better validation semantics for the get_region_override function. (empty/null regions is invalid)
  • Loading branch information
KieranBrantnerMagee authored Sep 11, 2020
1 parent df594e0 commit 3ae3e09
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion sdk/eventhub/azure-eventhub/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from uamqp import ReceiveClient
from uamqp.authentication import SASTokenAuth

from devtools_testutils import get_region_override

# Ignore async tests for Python < 3.5
collect_ignore = []
Expand All @@ -32,7 +33,7 @@
NAMESPACE_PREFIX = "eh-ns"
EVENTHUB_PREFIX = "eh"
EVENTHUB_DEFAULT_AUTH_RULE_NAME = 'RootManageSharedAccessKey'
LOCATION = "westus"
LOCATION = get_region_override("westus")


def pytest_addoption(parser):
Expand Down
4 changes: 2 additions & 2 deletions sdk/servicebus/azure-servicebus/tests/servicebus_preparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from azure_devtools.scenario_tests.exceptions import AzureTestError

from devtools_testutils import (
ResourceGroupPreparer, AzureMgmtPreparer, FakeResource
ResourceGroupPreparer, AzureMgmtPreparer, FakeResource, get_region_override
)

from devtools_testutils.resource_testcase import RESOURCE_GROUP_PARAM
Expand All @@ -27,7 +27,7 @@ class ServiceBusNamespacePreparer(AzureMgmtPreparer):
def __init__(self,
name_prefix='',
use_cache=False,
sku='Standard', location='westus',
sku='Standard', location=get_region_override('westus'),
parameter_name=SERVICEBUS_NAMESPACE_PARAM,
resource_group_parameter_name=RESOURCE_GROUP_PARAM,
disable_recording=True, playback_fake_resource=None,
Expand Down
4 changes: 2 additions & 2 deletions tools/azure-sdk-tools/devtools_testutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .mgmt_testcase import (AzureMgmtTestCase, AzureMgmtPreparer)
from .azure_testcase import AzureTestCase, is_live
from .azure_testcase import AzureTestCase, is_live, get_region_override
from .resource_testcase import (FakeResource, ResourceGroupPreparer, RandomNameResourceGroupPreparer, CachedResourceGroupPreparer)
from .storage_testcase import (FakeStorageAccount, StorageAccountPreparer)
from .keyvault_preparer import KeyVaultPreparer
Expand All @@ -8,7 +8,7 @@
'AzureMgmtTestCase', 'AzureMgmtPreparer',
'FakeResource', 'ResourceGroupPreparer',
'FakeStorageAccount', 'StorageAccountPreparer',
'AzureTestCase', 'is_live',
'AzureTestCase', 'is_live', 'get_region_override',
'KeyVaultPreparer', 'RandomNameResourceGroupPreparer',
'CachedResourceGroupPreparer'
]
7 changes: 7 additions & 0 deletions tools/azure-sdk-tools/devtools_testutils/azure_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def is_live():
return is_live._cache


def get_region_override(default='westus'):
region = os.environ.get('RESOURCE_REGION', None) or default
if not region:
raise ValueError('Region should not be None; set a non-empty-string region to either the RESOURCE_REGION environment variable or the default parameter to this function.')
return region


def _is_autorest_v3(client_class):
""" IS this client a autorestv3/track2 one?.
Could be refined later if necessary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create_resource(self, name, **kwargs):
parameters = {'location': self.location}
if self.delete_after_tag_timedelta:
expiry = datetime.datetime.utcnow() + self.delete_after_tag_timedelta
parameters['tags'] = {'DeleteAfter': expiry.isoformat()}
parameters['tags'] = {'DeleteAfter': expiry.replace(microsecond=0).isoformat()}
try:
self.resource = self.client.resource_groups.create_or_update(
name, parameters
Expand Down

0 comments on commit 3ae3e09

Please sign in to comment.