Skip to content

Commit d23d175

Browse files
{Packaging/MSI} Use embeddable python for MSI (Azure#14300)
1 parent 66ff8d1 commit d23d175

File tree

7 files changed

+104
-33
lines changed

7 files changed

+104
-33
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
*.bat eol=crlf
1414
# The az script for Git Bash/Cygwin should be LF
1515
build_scripts/windows/scripts/az eol=lf
16+
# sh scripts should be LF
17+
*.sh eol=lf

build_scripts/windows/scripts/build.cmd

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ if "%CLI_VERSION%"=="" (
99
echo Please set the CLI_VERSION environment variable, e.g. 2.0.13
1010
goto ERROR
1111
)
12-
set PYTHON_VERSION=3.6.6
12+
set PYTHON_VERSION=3.6.8
1313

1414
set WIX_DOWNLOAD_URL="https://azurecliprod.blob.core.windows.net/msi/wix310-binaries-mirror.zip"
15-
set PYTHON_DOWNLOAD_URL="https://azurecliprod.blob.core.windows.net/util/Python366-32.zip"
15+
set PYTHON_DOWNLOAD_URL="https://azurecliprod.blob.core.windows.net/util/Python368-32.zip"
1616
set PROPAGATE_ENV_CHANGE_DOWNLOAD_URL="https://azurecliprod.blob.core.windows.net/util/propagate_env_change.zip"
1717

1818
:: Set up the output directory and temp. directories
@@ -26,7 +26,7 @@ mkdir %ARTIFACTS_DIR%
2626
set TEMP_SCRATCH_FOLDER=%ARTIFACTS_DIR%\cli_scratch
2727
set BUILDING_DIR=%ARTIFACTS_DIR%\cli
2828
set WIX_DIR=%ARTIFACTS_DIR%\wix
29-
set PYTHON_DIR=%ARTIFACTS_DIR%\Python366-32
29+
set PYTHON_DIR=%ARTIFACTS_DIR%\Python368-32
3030
set PROPAGATE_ENV_CHANGE_DIR=%~dp0..\propagate_env_change
3131

3232
set REPO_ROOT=%~dp0..\..\..
@@ -75,10 +75,10 @@ if not exist %PYTHON_DIR% (
7575
mkdir %PYTHON_DIR%
7676
pushd %PYTHON_DIR%
7777
echo Downloading Python.
78-
curl -o Python366-32.zip %PYTHON_DOWNLOAD_URL% -k
79-
unzip -q Python366-32.zip
78+
curl -o Python368-32.zip %PYTHON_DOWNLOAD_URL% -k
79+
unzip -q Python368-32.zip
8080
if %errorlevel% neq 0 goto ERROR
81-
del Python366-32.zip
81+
del Python368-32.zip
8282
echo Python downloaded and extracted successfully.
8383
popd
8484
)
@@ -98,7 +98,6 @@ for %%a in (%CLI_SRC%\azure-cli %CLI_SRC%\azure-cli-core %CLI_SRC%\azure-cli-nsp
9898
if %errorlevel% neq 0 goto ERROR
9999

100100
%BUILDING_DIR%\python.exe -m pip install --no-warn-script-location --force-reinstall --upgrade azure-nspkg azure-mgmt-nspkg
101-
%BUILDING_DIR%\python.exe -m pip install --no-warn-script-location --force-reinstall urllib3==1.24.2
102101

103102
pushd %BUILDING_DIR%
104103
%BUILDING_DIR%\python.exe %~dp0\patch_models_v2.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Prerequisites:
2+
# 1. Install the MSI built with current branch
3+
# 2. Run bash azure-cli\scripts\ci\build.sh with Git Bash first to generate artifacts under azure-cli\artifacts\build so we can use the testsdk and fulltest wheels.
4+
5+
# Elevate to Admin
6+
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
7+
{
8+
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
9+
Start-Process powershell -Verb runAs -ArgumentList $arguments
10+
}
11+
12+
& 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' -m pip install pytest
13+
& 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' -m pip install pytest-xdist
14+
15+
$testsdk = Get-ChildItem -Path $PSScriptRoot\..\..\..\artifacts\build\azure_cli_testsdk*.whl | Select-Object Name
16+
& 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' -m pip install $PSScriptRoot\..\..\..\artifacts\build\$($testsdk.Name)
17+
18+
$fulltest = Get-ChildItem -Path $PSScriptRoot\..\..\..\artifacts\build\azure_cli_fulltest*.whl | Select-Object Name
19+
& 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' -m pip install $PSScriptRoot\..\..\..\artifacts\build\$($fulltest.Name)
20+
21+
& 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' $PSScriptRoot\test_msi_package.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
# Invoke this script in Powershell with:
7+
# & 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' test_msi_package.py <start_mod_name>
8+
9+
import os
10+
import sys
11+
import subprocess
12+
13+
base_dir = 'C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI2\\Lib\\site-packages\\azure\\cli'
14+
root_dir = '{}\\command_modules'.format(base_dir)
15+
mod_list = [mod for mod in sorted(os.listdir(root_dir)) if os.path.isdir(os.path.join(root_dir, mod)) and mod != '__pycache__']
16+
17+
pytest_base_cmd = ['python', '-m', 'pytest', '-x', '-v', '-p', 'no:warnings', '--log-level', 'WARN']
18+
pytest_parallel_cmd = pytest_base_cmd + ['-n', 'auto']
19+
20+
for mod_name in mod_list:
21+
try:
22+
start_mod = sys.argv[1]
23+
if mod_name < start_mod:
24+
continue
25+
except:
26+
pass
27+
mod_cmd = ['--junit-xml', '{}\\azure_cli_test_result\\{}.xml'.format(os.path.expanduser('~'), mod_name),
28+
'--pyargs', 'azure.cli.command_modules.{}'.format(mod_name)]
29+
if mod_name in ['botservice', 'network']:
30+
exit_code = subprocess.call(pytest_base_cmd + mod_cmd)
31+
else:
32+
exit_code = subprocess.call(pytest_parallel_cmd + mod_cmd)
33+
if exit_code == 5:
34+
print('No tests found for {}'.format(mod_name))
35+
elif exit_code != 0:
36+
sys.exit(exit_code)
37+
38+
core_dir = '{}\\core'.format(base_dir)
39+
exit_code = subprocess.call(['python', '-m', 'pytest', '-x', '-v', '-p', 'no:warnings', '--log-level', 'WARN',
40+
'--junit-xml', '{}\\azure_cli_test_result\\azure-cli-core.xml'.format(os.path.expanduser('~')), '-n', 'auto', '--import-mode=append', core_dir])
41+
sys.exit(exit_code)

src/azure-cli-core/azure/cli/core/tests/test_generic_update.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,16 @@ def my_get():
8585
def my_set(**kwargs): # pylint:disable=unused-argument
8686
return my_obj
8787

88-
test_type = CliCommandType(operations_tmpl='{}#{{}}'.format(__name__))
89-
setattr(sys.modules[__name__], my_get.__name__, my_get)
90-
setattr(sys.modules[__name__], my_set.__name__, my_set)
88+
test_module = 'azure.cli.core.tests.test_generic_update'
89+
test_type = CliCommandType(operations_tmpl='{}#{{}}'.format(test_module))
90+
try:
91+
setattr(sys.modules[test_module], my_get.__name__, my_get)
92+
setattr(sys.modules[test_module], my_set.__name__, my_set)
93+
except KeyError:
94+
import importlib
95+
loaded_module = importlib.import_module(test_module)
96+
setattr(loaded_module, my_get.__name__, my_get)
97+
setattr(loaded_module, my_set.__name__, my_set)
9198
with self.command_group('', test_type) as g:
9299
g.generic_update_command('genupdate', getter_name='my_get', setter_name='my_set')
93100

src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_sp_scenarios.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AmsSpTests(ScenarioTest):
1414
@StorageAccountPreparer(parameter_name='storage_account_for_create')
1515
@AllowLargeResponse()
1616
def test_ams_sp_create_reset(self, resource_group, storage_account_for_create):
17-
with mock.patch('azure.cli.command_modules.ams._utils._gen_guid', side_effect=self.create_guid):
17+
with mock.patch('azure.cli.command_modules.ams.operations.sp._gen_guid', side_effect=self.create_guid):
1818
amsname = self.create_random_name(prefix='ams', length=12)
1919

2020
self.kwargs.update({

src/azure-cli/azure/cli/command_modules/ams/tests/latest/test_ams_streaming_endpoint_scenarios.py

+23-22
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ def test_ams_streaming_endpoint_create_with_akamai(self, storage_account_for_cre
6969
'scaleUnits': 4,
7070
'tags': 'foo=bar',
7171
'ips': '1.1.1.1 2.2.2.2',
72-
'clientAccessPolicy': '@' + self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
73-
'crossDomainPolicy': '@' + self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml')),
72+
'clientAccessPolicy': self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
73+
'crossDomainPolicy': self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml')),
7474
'identifier': 'id1',
7575
'expiration': '2030-12-31T16:00:00-08:00',
7676
'base64Key': 'dGVzdGlkMQ=='
7777
})
7878

7979
self.cmd('az ams account create -n {amsname} -g {rg} --storage-account {storageAccount} -l {location}')
8080

81-
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName} --availability-set-name {availabilitySetName} --ips {ips} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy "{clientAccessPolicy}" --cross-domain-policy "{crossDomainPolicy}"', checks=[
81+
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName} --availability-set-name {availabilitySetName} --ips {ips} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy @"{clientAccessPolicy}" --cross-domain-policy @"{crossDomainPolicy}"', checks=[
8282
self.check('name', '{streamingEndpointName}'),
8383
self.check('resourceGroup', '{rg}'),
8484
self.check('location', 'North Europe'),
@@ -124,14 +124,14 @@ def test_ams_streaming_endpoint_update(self, storage_account_for_create):
124124
'maxCacheAge': 11,
125125
'scaleUnits': 5,
126126
'tags': 'foo=bar',
127-
'clientAccessPolicy': '@' + self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
128-
'crossDomainPolicy': '@' + self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml')),
127+
'clientAccessPolicy': self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
128+
'crossDomainPolicy': self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml')),
129129
'ip': '4.4.4.4'
130130
})
131131

132132
self.cmd('az ams account create -n {amsname} -g {rg} --storage-account {storageAccount} -l {location}')
133133

134-
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName} --availability-set-name {availabilitySetName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy "{clientAccessPolicy}" --cross-domain-policy "{crossDomainPolicy}"', checks=[
134+
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName} --availability-set-name {availabilitySetName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy @"{clientAccessPolicy}" --cross-domain-policy @"{crossDomainPolicy}"', checks=[
135135
self.check('name', '{streamingEndpointName}'),
136136
self.check('resourceGroup', '{rg}'),
137137
self.check('location', 'Australia East'),
@@ -155,12 +155,12 @@ def test_ams_streaming_endpoint_update(self, storage_account_for_create):
155155
'description': 'test streaming description2',
156156
'maxCacheAge': 9,
157157
'tags': 'foo2=bar2 foo3=bar3',
158-
'clientAccessPolicy': '@' + self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
159-
'crossDomainPolicy': '@' + self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml')),
158+
'clientAccessPolicy': self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
159+
'crossDomainPolicy': self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml')),
160160
'ips': '1.1.1.1 2.2.2.2 192.168.0.0/28'
161161
})
162162

163-
self.cmd('az ams streaming-endpoint update -g {rg} -a {amsname} -n {streamingEndpointName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --tags {tags} --client-access-policy "{clientAccessPolicy}" --cross-domain-policy "{crossDomainPolicy}"', checks=[
163+
self.cmd('az ams streaming-endpoint update -g {rg} -a {amsname} -n {streamingEndpointName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --tags {tags} --client-access-policy @"{clientAccessPolicy}" --cross-domain-policy @"{crossDomainPolicy}"', checks=[
164164
self.check('name', '{streamingEndpointName}'),
165165
self.check('cdnProvider', '{cdnProvider}'),
166166
self.check('cdnProfile', '{cdnProfile}'),
@@ -201,13 +201,13 @@ def test_ams_streaming_endpoint_create(self, storage_account_for_create):
201201
'maxCacheAge': 11,
202202
'scaleUnits': 6,
203203
'tags': 'foo=bar',
204-
'clientAccessPolicy': '@' + self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
205-
'crossDomainPolicy': '@' + self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml'))
204+
'clientAccessPolicy': self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
205+
'crossDomainPolicy': self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml'))
206206
})
207207

208208
self.cmd('az ams account create -n {amsname} -g {rg} --storage-account {storageAccount} -l {location}')
209209

210-
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName} --availability-set-name {availabilitySetName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy "{clientAccessPolicy}" --cross-domain-policy "{crossDomainPolicy}"', checks=[
210+
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName} --availability-set-name {availabilitySetName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy @"{clientAccessPolicy}" --cross-domain-policy @"{crossDomainPolicy}"', checks=[
211211
self.check('name', '{streamingEndpointName}'),
212212
self.check('resourceGroup', '{rg}'),
213213
self.check('location', 'Canada Central'),
@@ -240,13 +240,13 @@ def test_ams_streaming_endpoint_show(self, storage_account_for_show):
240240
'maxCacheAge': 11,
241241
'scaleUnits': 7,
242242
'tags': 'foo=bar',
243-
'clientAccessPolicy': '@' + self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
244-
'crossDomainPolicy': '@' + self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml'))
243+
'clientAccessPolicy': self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
244+
'crossDomainPolicy': self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml'))
245245
})
246246

247247
self.cmd('az ams account create -n {amsname} -g {rg} --storage-account {storageAccount} -l {location}')
248248

249-
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName} --availability-set-name {availabilitySetName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy "{clientAccessPolicy}" --cross-domain-policy "{crossDomainPolicy}"')
249+
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName} --availability-set-name {availabilitySetName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy @"{clientAccessPolicy}" --cross-domain-policy @"{crossDomainPolicy}"')
250250

251251
self.cmd('az ams streaming-endpoint show -g {rg} -a {amsname} -n {streamingEndpointName}', checks=[
252252
self.check('name', '{streamingEndpointName}'),
@@ -288,13 +288,13 @@ def test_ams_streaming_endpoint_delete(self, storage_account_for_delete):
288288
'maxCacheAge': 11,
289289
'scaleUnits': 8,
290290
'tags': 'foo=bar',
291-
'clientAccessPolicy': '@' + self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
292-
'crossDomainPolicy': '@' + self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml'))
291+
'clientAccessPolicy': self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
292+
'crossDomainPolicy': self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml'))
293293
})
294294

295295
self.cmd('az ams account create -n {amsname} -g {rg} --storage-account {storageAccount} -l {location}')
296296

297-
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName1} --availability-set-name {availabilitySetName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy "{clientAccessPolicy}" --cross-domain-policy "{crossDomainPolicy}"')
297+
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName1} --availability-set-name {availabilitySetName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy @"{clientAccessPolicy}" --cross-domain-policy @"{crossDomainPolicy}"')
298298

299299
self.cmd('az ams streaming-endpoint list -g {rg} -a {amsname}', checks=[
300300
self.check('length(@)', 2)
@@ -325,13 +325,13 @@ def test_ams_streaming_endpoint_scale(self, storage_account_for_scale):
325325
'scaleUnits': 9,
326326
'scaleUnits2': 10,
327327
'tags': 'foo=bar',
328-
'clientAccessPolicy': '@' + self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
329-
'crossDomainPolicy': '@' + self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml'))
328+
'clientAccessPolicy': self._normalize_filename(_get_test_data_file('clientAccessPolicy.xml')),
329+
'crossDomainPolicy': self._normalize_filename(_get_test_data_file('crossDomainPolicy.xml'))
330330
})
331331

332332
self.cmd('az ams account create -n {amsname} -g {rg} --storage-account {storageAccount} -l {location}')
333333

334-
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName} --availability-set-name {availabilitySetName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy "{clientAccessPolicy}" --cross-domain-policy "{crossDomainPolicy}"', checks=[
334+
self.cmd('az ams streaming-endpoint create -g {rg} -a {amsname} -n {streamingEndpointName} --availability-set-name {availabilitySetName} --cdn-provider {cdnProvider} --cdn-profile {cdnProfile} --description "{description}" --max-cache-age {maxCacheAge} --scale-units {scaleUnits} --tags "{tags}" --client-access-policy @"{clientAccessPolicy}" --cross-domain-policy @"{crossDomainPolicy}"', checks=[
335335
self.check('scaleUnits', '{scaleUnits}')
336336
])
337337

@@ -468,4 +468,5 @@ def test_ams_streaming_endpoint_list(self, storage_account_for_create):
468468
# Helper functions
469469

470470
def _normalize_filename(cmd, string):
471-
return '"' + string.replace('\\', '/') + '"'
471+
import platform
472+
return '"' + string.replace('\\', '/') + '"' if platform.system() != 'Windows' else string

0 commit comments

Comments
 (0)