This commit is contained in:
antisch 2018-01-05 16:07:34 -08:00
Родитель 77b58ad492
Коммит 1b5e82a9dd
7 изменённых файлов: 29 добавлений и 40 удалений

Просмотреть файл

@ -4,7 +4,7 @@
# --------------------------------------------------------------------------------------------
def batch_extensions_client(cli_ctx, kwargs):
def batch_extensions_client(cli_ctx, kwargs): # pylint: disable=unused-argument
from knack.util import CLIError
import azure.batch_extensions as batch

Просмотреть файл

@ -5,9 +5,7 @@
from argcomplete.completers import FilesCompleter
from knack.arguments import CLIArgumentType
from azure.cli.core.commands.parameters import get_resource_name_completion_list, file_type
from azure.cli.core.commands.parameters import file_type
from azure.cli.command_modules.batch._completers import load_node_agent_skus
from azure.cli.command_modules.batch._validators import (
metadata_item_format, certificate_reference_format, validate_json_file,
@ -17,11 +15,6 @@ from azext_batch._validators import validate_pool_settings, validate_client_para
# pylint: disable=line-too-long, too-many-statements
def load_arguments(self, _):
batch_name_type = CLIArgumentType(
help='Name of the Batch account.',
options_list=('--account-name',),
completer=get_resource_name_completion_list('Microsoft.Batch/batchAccounts'),
id_part=None)
with self.argument_context('batch pool create') as c:
c.argument('json_file', type=file_type, help='The file containing the pool to create in JSON format, if this parameter is specified, all other parameters are ignored.', validator=validate_json_file, completer=FilesCompleter())
@ -35,10 +28,10 @@ def load_arguments(self, _):
c.argument('start_task_resource_files', arg_group='Pool: Start Task', nargs='+', type=resource_file_format, help='A list of files that the Batch service will download to the compute node before running the command line. Space separated resource references in filename=blobsource format.')
c.argument('start_task_wait_for_success', arg_group='Pool: Start Task', action='store_true', help='Whether the Batch service should wait for the start task to complete successfully (that is, to exit with exit code 0) before scheduling any tasks on the compute node. If true and the start task fails on a compute node, the Batch service retries the start task up to its maximum retry count (maxTaskRetryCount). If the task has still not completed successfully after all retries, then the Batch service marks the compute node unusable, and will not schedule tasks to it. This condition can be detected via the node state and scheduling error detail. If false, the Batch service will not wait for the start task to complete. In this case, other tasks can start executing on the compute node while the start task is still running; and even if the start task fails, new tasks will continue to be scheduled on the node. The default is false. True if flag present.')
c.argument('os_family', arg_group="Pool: Cloud Service Configuration",
help='The Azure Guest OS family to be installed on the virtual machines in the pool. Possible values are: 2 - OS Family 2, equivalent to Windows Server 2008 R2 SP1. 3 - OS Family 3, equivalent to Windows Server 2012. 4 - OS Family 4, equivalent to Windows Server 2012 R2. 5 - OS Family 5, equivalent to Windows Server 2016. For more information, see Azure Guest OS Releases (https://azure.microsoft.com/documentation/articles/cloud-services-guestos-update-matrix/#releases). Allowed values: 2, 3, 4, 5.')
help='The Azure Guest OS family to be installed on the virtual machines in the pool. Possible values are: 2 - OS Family 2, equivalent to Windows Server 2008 R2 SP1. 3 - OS Family 3, equivalent to Windows Server 2012. 4 - OS Family 4, equivalent to Windows Server 2012 R2. 5 - OS Family 5, equivalent to Windows Server 2016. For more information, see Azure Guest OS Releases (https://azure.microsoft.com/documentation/articles/cloud-services-guestos-update-matrix/#releases). Allowed values: 2, 3, 4, 5.')
c.argument('node_agent_sku_id', arg_group="Pool: Virtual Machine Configuration", help='The SKU of the Batch node agent to be provisioned on compute nodes in the pool. The Batch node agent is a program that runs on each node in the pool, and provides the command-and-control interface between the node and the Batch service. There are different implementations of the node agent, known as SKUs, for different operating systems. You must specify a node agent SKU which matches the selected image reference. To get the list of supported node agent SKUs along with their list of verified image references, see the \'List supported node agent SKUs\' operation.')
c.argument('image', completer=load_node_agent_skus, arg_group="Pool: Virtual Machine Configuration",
help="OS image reference. This can be either 'publisher:offer:sku[:version]' format, or a fully qualified ARM image id of the form '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/images/{imageName}'. If 'publisher:offer:sku[:version]' format, version is optional and if omitted latest will be used. Valid values can be retrieved via 'az batch pool node-agent-skus list'. For example: 'MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:latest'")
help="OS image reference. This can be either 'publisher:offer:sku[:version]' format, or a fully qualified ARM image id of the form '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/images/{imageName}'. If 'publisher:offer:sku[:version]' format, version is optional and if omitted latest will be used. Valid values can be retrieved via 'az batch pool node-agent-skus list'. For example: 'MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:latest'")
with self.argument_context('batch job create') as c:
c.argument('json_file', type=file_type, help='The file containing the job to create in JSON format, if this parameter is specified, all other parameters are ignored.', validator=validate_json_file, completer=FilesCompleter())

Просмотреть файл

@ -5,12 +5,11 @@
import json
from knack.log import get_logger
from azure.batch_extensions.models import PoolAddParameter, JobAddParameter, JobConstraints
from knack.log import get_logger
from knack.prompting import prompt
from knack.util import CLIError
logger = get_logger(__name__)
@ -27,7 +26,7 @@ def create_pool(client, template=None, parameters=None, json_file=None, id=None,
# pylint: disable=too-many-branches, too-many-statements
from azure.batch_extensions.errors import MissingParameterValue
from azure.batch_extensions.models import (
PoolInformation, PoolAddOptions, StartTask, ImageReference,
PoolAddOptions, StartTask, ImageReference,
CloudServiceConfiguration, VirtualMachineConfiguration)
if template or json_file:
if template:
@ -123,7 +122,7 @@ def create_job(client, template=None, parameters=None, json_file=None, id=None,
job_manager_task_id=None, job_manager_task_resource_files=None):
# pylint: disable=too-many-branches, too-many-statements
from azure.batch_extensions.errors import MissingParameterValue
from azure.batch_extensions.models import JobManagerTask, JobAddOptions
from azure.batch_extensions.models import JobManagerTask, JobAddOptions, PoolInformation
if template or json_file:
if template:
logger.warning('You are using an experimental feature {Job Template}.')

Просмотреть файл

@ -125,16 +125,16 @@ def verify_packages():
sys.exit(1)
# STEP 4:: Add CLI extension wheel to CLI
try:
# try:
extension_whl = os.path.join(built_packages_dir, 'azure_batch_cli_extensions-1000.0.0-py2.py3-none-any.whl')
az_output = subprocess.check_output(['az', 'extension', 'add', '--source', extension_whl, '--debug'], stderr=subprocess.STDOUT,
universal_newlines=True)
success = 'Successfully installed azure-batch-cli-extensions-1000.0.0' in az_output
print(az_output, file=sys.stderr)
except subprocess.CalledProcessError as err:
success = False
print(err, file=sys.stderr)
# extension_whl = os.path.join(built_packages_dir, 'azure_batch_cli_extensions-1000.0.0-py2.py3-none-any.whl')
# az_output = subprocess.check_output(['az', 'extension', 'add', '--source', extension_whl, '--debug'], stderr=subprocess.STDOUT,
# universal_newlines=True)
# success = 'Successfully installed azure-batch-cli-extensions-1000.0.0' in az_output
# print(az_output, file=sys.stderr)
# except subprocess.CalledProcessError as err:
# success = False
# print(err, file=sys.stderr)
# STEP 5:: Verify extension loading correctly
try:

Просмотреть файл

@ -42,7 +42,7 @@ interactions:
accept-language: [en-US]
x-ms-client-request-id: [a59b4f9c-a55b-11e7-a5d0-ecb1d755839a]
method: POST
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_rg/providers/Microsoft.Storage/storageAccounts/batchtest1/listKeys?api-version=2017-06-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_rg/providers/Microsoft.Storage/storageAccounts/batchtest1/listKeys?api-version=2017-10-01
response:
body: {string: '{"keys":[{"keyName":"key1","permissions":"Full","value":"abc=="},{"keyName":"key2","permissions":"Full","value":"xyz=="}]}'}
headers:
@ -170,7 +170,7 @@ interactions:
accept-language: [en-US]
x-ms-client-request-id: [a782c0d2-a55b-11e7-9903-ecb1d755839a]
method: POST
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_rg/providers/Microsoft.Storage/storageAccounts/batchtest1/listKeys?api-version=2017-06-01
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test_rg/providers/Microsoft.Storage/storageAccounts/batchtest1/listKeys?api-version=2017-10-01
response:
body: {string: '{"keys":[{"keyName":"key1","permissions":"Full","value":"abc=="},{"keyName":"key2","permissions":"Full","value":"xyz=="}]}'}
headers:

Просмотреть файл

@ -13,9 +13,12 @@ import azure.batch.batch_auth as batchauth
import azure.batch_extensions as batch
from tests.vcr_test_base import VCRTestBase
from azure.cli.core.profiles import get_sdk, ResourceType
from azure.cli.core import get_default_cli
CloudStorageAccount = get_sdk(ResourceType.DATA_STORAGE, 'common.cloudstorageaccount#CloudStorageAccount')
BlobPermissions = get_sdk(ResourceType.DATA_STORAGE, 'blob.models#BlobPermissions')
az_cli = get_default_cli()
CloudStorageAccount = get_sdk(az_cli, ResourceType.DATA_STORAGE, 'common.cloudstorageaccount#CloudStorageAccount')
BlobPermissions = get_sdk(az_cli, ResourceType.DATA_STORAGE, 'blob.models#BlobPermissions')
class TestFileUpload(VCRTestBase):

Просмотреть файл

@ -27,12 +27,8 @@ except ImportError:
import vcr
import jmespath
from six import StringIO
# TODO Should not depend on azure.cli.main package here.
# Will be ok if this test file is not part of azure.cli.core.utils
from azure.cli.main import main as cli_main
from azure.cli.core import get_default_cli
from azure.cli.core import __version__ as core_version
import azure.cli.core._debug as _debug
from azure.cli.core._profile import Profile
@ -251,6 +247,7 @@ class VCRTestBase(unittest.TestCase): # pylint: disable=too-many-instance-attri
def __init__(self, test_file, test_name, run_live=False, debug=False, debug_vcr=False,
skip_setup=False, skip_teardown=False):
super(VCRTestBase, self).__init__(test_name)
self.cli = get_default_cli()
self.test_name = test_name
self.recording_dir = os.path.join(os.path.dirname(test_file), 'recordings')
self.cassette_path = os.path.join(self.recording_dir, '{}.yaml'.format(test_name))
@ -331,7 +328,7 @@ class VCRTestBase(unittest.TestCase): # pylint: disable=too-many-instance-attri
return response
@mock.patch('azure.cli.main.handle_exception', _mock_handle_exceptions)
@mock.patch('azure.cli.core.util.handle_exception', _mock_handle_exceptions)
@mock.patch('azure.cli.core.commands.client_factory._get_mgmt_service_client',
_mock_get_mgmt_service_client) # pylint: disable=line-too-long
def _execute_live_or_recording(self):
@ -357,7 +354,7 @@ class VCRTestBase(unittest.TestCase): # pylint: disable=too-many-instance-attri
@mock.patch('azure.cli.core._profile.Profile.load_cached_subscriptions', _mock_subscriptions)
@mock.patch('azure.cli.core._profile.CredsCache.retrieve_token_for_user',
_mock_user_access_token) # pylint: disable=line-too-long
@mock.patch('azure.cli.main.handle_exception', _mock_handle_exceptions)
@mock.patch('azure.cli.core.util.handle_exception', _mock_handle_exceptions)
@mock.patch('azure.cli.core.commands.client_factory._get_mgmt_service_client',
_mock_get_mgmt_service_client) # pylint: disable=line-too-long
@mock.patch('msrestazure.azure_operation.AzureOperationPoller._delay', _mock_operation_delay)
@ -404,16 +401,13 @@ class VCRTestBase(unittest.TestCase): # pylint: disable=too-many-instance-attri
if self._debug or debug:
print('\n\tRUNNING: {}'.format(command))
command_list = shlex.split(command)
output = StringIO()
try:
cli_main(command_list, output=output)
result = self.cli.invoke(command_list)
except Exception as ex: # pylint: disable=broad-except
ex_msg = str(ex)
if not next((x for x in allowed_exceptions if x in ex_msg), None):
raise ex
self._track_executed_commands(command_list)
result = output.getvalue().strip()
output.close()
if self._debug or debug:
print('\tRESULT: {}\n'.format(result))