Skip to content

Commit 338c439

Browse files
bgkleinxingwu1
authored andcommitted
Convert Blob Source to HttpUrl when expanding template (#99)
* Update bad model * minor changes * Move blobSource to resourceFile to template parsing * Add to job templates as well * Move to parse json level * pylint * update tests * remove redundant return statement
1 parent 832c314 commit 338c439

File tree

11 files changed

+2087
-4184
lines changed

11 files changed

+2087
-4184
lines changed

HISTORY.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
SDK Release History
44
===================
55

6+
5.0.3 (2019-02-19)
7+
------------------
8+
9+
* Fix bug where blobSource was no longer an attribute of ExtendedResourceFile
10+
* Improve test coverage
11+
612
5.0.2 (2019-02-15)
713
------------------
814

azext/batch/_file_utils.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
import copy
1313
import pathlib
1414

15-
from logging import getLogger
1615
from six.moves.urllib.parse import urlsplit # pylint: disable=import-error,relative-import
1716
from six.moves.urllib.parse import quote # pylint: disable=import-error,no-name-in-module,relative-import
1817

1918
from azure.storage.blob import BlobPermissions, BlockBlobService
2019
from . import models
2120

22-
logger = getLogger(__name__)
23-
2421
def construct_sas_url(blob, uri):
2522
"""Make up blob URL with container URL"""
2623
newuri = copy.copy(uri)
@@ -330,16 +327,6 @@ def resolve_resource_file(self, resource_file):
330327
'also have \'file_path\' attribute')
331328
return [resource_file]
332329

333-
if resource_file.blob_source:
334-
if not resource_file.file_path:
335-
raise ValueError('Malformed ResourceFile: \'blobSource\' must '
336-
'also have \'file_path\' attribute')
337-
resource_file.http_url = resource_file.blob_source
338-
logger.warning('BlobSource has been updated to HttpUrl to reflect new '
339-
'functionality of accepting any http url instead of just storage '
340-
'blobs. Please update your templates to reflect this')
341-
return [resource_file]
342-
343330
if resource_file.storage_container_url or resource_file.auto_storage_container_name:
344331
return [resource_file]
345332

azext/batch/_template_utils.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import copy
1010
import itertools
1111
import json
12+
from logging import getLogger
1213
import re
1314
from msrest.serialization import Model
1415
try:
@@ -20,7 +21,7 @@
2021
from . import _pool_utils as pool_utils
2122
from . import models
2223

23-
24+
logger = getLogger(__name__)
2425
try:
2526
_UNICODE_TYPE = unicode
2627
except NameError:
@@ -1184,3 +1185,26 @@ def validate_json_object(json_obj, obj):
11841185
else:
11851186
inner_type = getattr(obj, key_attr_map[item.lower()])
11861187
validate_json_object(json_obj[item], inner_type)
1188+
1189+
1190+
def convert_blob_source_to_http_url(obj):
1191+
if isinstance(obj, dict):
1192+
for key in obj:
1193+
if key in ['resourceFiles', 'commonResourceFiles']:
1194+
obj[key] = \
1195+
[_convert_blob_source_to_http_url(resource_file) for resource_file in obj[key]]
1196+
obj[key] = convert_blob_source_to_http_url(obj[key])
1197+
return obj
1198+
1199+
1200+
def _convert_blob_source_to_http_url(resource_file):
1201+
if 'blobSource' in resource_file:
1202+
if 'filePath' not in resource_file:
1203+
raise ValueError('Malformed ResourceFile: \'blobSource\' must '
1204+
'also have \'file_path\' attribute')
1205+
resource_file['httpUrl'] = resource_file.pop('blobSource', None)
1206+
logger.warning('BlobSource has been updated to HttpUrl to reflect new '
1207+
'functionality of accepting any http url instead of just'
1208+
' storage blobs. Please update your templates to'
1209+
' reflect this.')
1210+
return resource_file

azext/batch/operations/job_operations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def jobparameter_from_json(json_data):
7474
ExtendedJobParameter or a JobTemplate
7575
"""
7676
result = 'JobTemplate' if json_data.get('properties') else 'ExtendedJobParameter'
77+
json_data = templates.convert_blob_source_to_http_url(json_data)
7778
try:
7879
if result == 'JobTemplate':
7980
if 'apiVersion' in json_data:

azext/batch/operations/pool_operations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def poolparameter_from_json(json_data):
5454
ExtendedPoolParameter or a PoolTemplate.
5555
"""
5656
result = 'PoolTemplate' if json_data.get('properties') else 'ExtendedPoolParameter'
57+
json_data = templates.convert_blob_source_to_http_url(json_data)
5758
try:
5859
if result == 'PoolTemplate':
5960
if 'apiVersion' in json_data:

azext/batch/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
VERSION = "5.0.2"
6+
VERSION = "5.0.3"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"pool": {
3+
"id": "blobsource1",
4+
"displayName": "Blender Ubuntu standard pool",
5+
"vmSize": "Standard_D1_v2",
6+
"virtualMachineConfiguration": {
7+
"imageReference": {
8+
"publisher": "Canonical",
9+
"offer" : "UbuntuServer",
10+
"sku": "16.04.0-LTS",
11+
"version": "latest"
12+
},
13+
"nodeAgentSKUId": "batch.node.ubuntu 16.04"
14+
},
15+
"targetDedicatedNodes": "1",
16+
"targetLowPriorityNodes": "0",
17+
"enableAutoScale": false,
18+
"startTask": {
19+
"commandLine": "sleep 1",
20+
"waitForSuccess": true,
21+
"maxTaskRetryCount": 0,
22+
"userIdentity": {
23+
"autoUser": {
24+
"scope": "pool",
25+
"elevationLevel": "admin"
26+
}
27+
},
28+
"resourceFiles": [
29+
{
30+
"blobSource": "https://raw.githubusercontent.com/Azure/BatchExplorer-data/master/ncj/blender/scripts/setup-linux-pool.sh",
31+
"filePath": "setup-linux-pool.sh"
32+
}
33+
]
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)