-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Storage][Test] Test multiple service versions #19039
Changes from all commits
19df257
a205f3e
5b52e48
db1a868
508e5dd
741b098
519ab4a
fa78e37
bbbb81f
7fec5e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from datetime import datetime | ||
from enum import Enum | ||
import os | ||
|
||
|
||
class ServiceVersion(str, Enum): | ||
|
||
V2019_02_02 = "2019-02-02" | ||
V2019_07_07 = "2019-07-07" | ||
V2019_10_10 = "2019-10-10" | ||
V2019_12_12 = "2019-12-12" | ||
V2020_02_10 = "2020-02-10" | ||
V2020_04_08 = "2020-04-08" | ||
V2020_06_12 = "2020-06-12" | ||
V2020_08_04 = "2020-08-04" | ||
|
||
|
||
service_version_map = { | ||
"V2019_02_02": ServiceVersion.V2019_02_02, | ||
"V2019_07_07": ServiceVersion.V2019_07_07, | ||
"V2019_10_10": ServiceVersion.V2019_10_10, | ||
"V2019_12_12": ServiceVersion.V2019_12_12, | ||
"V2020_02_10": ServiceVersion.V2020_02_10, | ||
"V2020_04_08": ServiceVersion.V2020_04_08, | ||
"V2020_06_12": ServiceVersion.V2020_06_12, | ||
"V2020_08_04": ServiceVersion.V2020_08_04, | ||
"LATEST": ServiceVersion.V2020_08_04, | ||
"LATEST_PLUS_1": ServiceVersion.V2020_06_12 | ||
} | ||
|
||
|
||
def is_version_before(test_version): | ||
""" Return True if the current version is after a given one or if the | ||
service version is not set. | ||
""" | ||
current_version = service_version_map.get(os.environ.get("AZURE_LIVE_TEST_SERVICE_VERSION")) | ||
if not current_version: | ||
return True | ||
current_version_data = datetime.strptime(current_version, "%Y-%m-%d") | ||
test_version_minimum = datetime.strptime(test_version, "%Y-%m-%d") | ||
ret = current_version_data < test_version_minimum | ||
return ret |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
import zlib | ||
import math | ||
import sys | ||
import string | ||
import os | ||
import random | ||
import re | ||
import logging | ||
|
@@ -34,6 +34,7 @@ | |
except ImportError: | ||
from io import StringIO | ||
|
||
from azure.core.pipeline.policies import SansIOHTTPPolicy | ||
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError | ||
from azure.core.credentials import AccessToken | ||
from azure.storage.blob import generate_account_sas, AccountSasPermissions, ResourceTypes | ||
|
@@ -50,6 +51,8 @@ | |
except ImportError: | ||
from devtools_testutils import mgmt_settings_fake as settings | ||
|
||
from .service_versions import service_version_map | ||
|
||
import pytest | ||
|
||
|
||
|
@@ -310,6 +313,32 @@ def generate_sas_token(self): | |
def generate_fake_token(self): | ||
return FakeTokenCredential() | ||
|
||
def _get_service_version(self, **kwargs): | ||
env_version = service_version_map.get(os.environ.get("AZURE_LIVE_TEST_SERVICE_VERSION","LATEST")) | ||
return kwargs.pop("service_version", env_version) | ||
|
||
def create_storage_client(self, client, *args, **kwargs): | ||
kwargs["api_version"] = self._get_service_version(**kwargs) | ||
kwargs["_additional_pipeline_policies"] = [ApiVersionAssertPolicy(kwargs["api_version"])] | ||
return client(*args, **kwargs) | ||
seankane-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def create_storage_client_from_conn_str(self, client, *args, **kwargs): | ||
kwargs["api_version"] = self._get_service_version(**kwargs) | ||
kwargs["_additional_pipeline_policies"] = [ApiVersionAssertPolicy(kwargs["api_version"])] | ||
return client.from_connection_string(*args, **kwargs) | ||
|
||
|
||
class ApiVersionAssertPolicy(SansIOHTTPPolicy): | ||
""" | ||
Assert the ApiVersion is set properly on the response | ||
""" | ||
|
||
def __init__(self, api_version): | ||
self.api_version = api_version | ||
|
||
def on_request(self, request): | ||
assert request.http_request.headers['x-ms-version'] == self.api_version | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this throw if env variable is empty? , we should either handle it here or not inject policy if there's no service version provided extrenally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, if the env variable is empty it will default to |
||
|
||
|
||
def not_for_emulator(test): | ||
def skip_test_if_targeting_emulator(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from enum import Enum | ||
|
||
|
||
class ServiceVersion(str, Enum): | ||
|
||
V2019_02_02 = "2019-02-02" | ||
V2019_07_07 = "2019-07-07" | ||
V2019_10_10 = "2019-10-10" | ||
V2019_12_12 = "2019-12-12" | ||
V2020_02_10 = "2020-02-10" | ||
V2020_04_08 = "2020-04-08" | ||
V2020_06_12 = "2020-06-12" | ||
V2020_08_04 = "2020-08-04" | ||
|
||
|
||
service_version_map = { | ||
"V2019_02_02": ServiceVersion.V2019_02_02, | ||
"V2019_07_07": ServiceVersion.V2019_07_07, | ||
"V2019_10_10": ServiceVersion.V2019_10_10, | ||
"V2019_12_12": ServiceVersion.V2019_12_12, | ||
"V2020_02_10": ServiceVersion.V2020_02_10, | ||
"V2020_04_08": ServiceVersion.V2020_04_08, | ||
"V2020_06_12": ServiceVersion.V2020_06_12, | ||
"V2020_08_04": ServiceVersion.V2020_08_04, | ||
"LATEST": ServiceVersion.V2020_08_04, | ||
"LATEST_PLUS_1": ServiceVersion.V2020_06_12 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"displayNames": { | ||
"--disablecov": "", | ||
"false": "", | ||
"true": "" | ||
}, | ||
"matrix": { | ||
"Agent": { | ||
"ubuntu-18.04": { "OSVmImage": "MMSUbuntu18.04", "Pool": "azsdk-pool-mms-ubuntu-1804-general" }, | ||
"windows-2019": { "OSVmImage": "MMS2019", "Pool": "azsdk-pool-mms-win-2019-general" }, | ||
"macOS-10.15": { "OSVmImage": "macOS-10.15", "Pool": "Azure Pipelines" } | ||
}, | ||
"PythonVersion": [ "pypy3", "2.7", "3.6", "3.7", "3.8", "3.9" ], | ||
"CoverageArg": "--disablecov", | ||
"TestSamples": "false", | ||
"AZURE_LIVE_TEST_SERVICE_VERSION": [ | ||
"V2019_02_02", | ||
"V2019_07_07", | ||
"V2019_12_12", | ||
"V2020_02_10", | ||
"V2020_04_08", | ||
"V2020_06_12", | ||
"V2020_08_04" | ||
] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in nightly pipeline we'd like clients to pick the default, i.e. env variable is empty.
does this code achieve this by leaving "api_version" kwarg empty or we need some "if" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the environment variable is empty, it will default to
LATEST_SERVICE_VERSION