Skip to content
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

[Batch] Added Batch to KnackConversion CI #5071

Merged
merged 3 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ exclude =
src/command_modules/azure-cli-sql
src/command_modules/azure-cli-vm
src/command_modules/azure-cli-acs
src/command_modules/azure-cli-batch
src/command_modules/azure-cli-cosmosdb
src/command_modules/azure-cli-dla
src/command_modules/azure-cli-dls
Expand Down
1 change: 0 additions & 1 deletion scripts/ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ for name in $(ls src/command_modules | grep azure-cli-); do
if [ "$name" == "azure-cli-advisor" ]; then continue; fi
if [ "$name" == "azure-cli-appservice" ]; then continue; fi
if [ "$name" == "azure-cli-backup" ]; then continue; fi
if [ "$name" == "azure-cli-batch" ]; then continue; fi
if [ "$name" == "azure-cli-batchai" ]; then continue; fi
if [ "$name" == "azure-cli-consumption" ]; then continue; fi
if [ "$name" == "azure-cli-container" ]; then continue; fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/test_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ run_style azure.cli.command_modules.acs
#run_style azure.cli.command_modules.advisor
#run_style azure.cli.command_modules.appservice
#run_style azure.cli.command_modules.backup
#run_style azure.cli.command_modules.batch
run_style azure.cli.command_modules.batch
#run_style azure.cli.command_modules.batchai
run_style azure.cli.command_modules.billing
run_style azure.cli.command_modules.cdn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from azure.cli.command_modules.batch import _validators as validators
from azure.cli.command_modules.batch import _format as transformers
from azure.cli.command_modules.batch import _parameter_format as params
from azure.cli.command_modules.batch import _parameter_format as pformat

from azure.cli.core import EXCLUDED_PARAMS
from azure.cli.core.commands import CONFIRM_PARAM_NAME
Expand Down Expand Up @@ -204,7 +204,7 @@ def _is_silent(self, name):
"""Whether argument should not be exposed"""
arg = self._arg_tree[name]
full_path = full_name(arg)
return arg['path'] in params.SILENT_PARAMETERS or full_path in params.SILENT_PARAMETERS
return arg['path'] in pformat.SILENT_PARAMETERS or full_path in pformat.SILENT_PARAMETERS

def _is_bool(self, name):
"""Whether argument value is a boolean"""
Expand Down Expand Up @@ -428,13 +428,13 @@ def parse(self, namespace):


class AzureBatchDataPlaneCommand(object):
# pylint: disable=too-many-instance-attributes, too-few-public-methods
# pylint: disable=too-many-instance-attributes, too-few-public-methods, too-many-statements
def __init__(self, name, operation, op_handler, client_factory=None, validator=None, **kwargs):

if not isinstance(operation, string_types):
raise ValueError("Operation must be a string. Got '{}'".format(operation))

self._flatten = kwargs.pop('flatten', params.FLATTEN) # Number of object levels to flatten
self._flatten = kwargs.pop('flatten', pformat.FLATTEN) # Number of object levels to flatten
self._head_cmd = False

self.parser = None
Expand All @@ -460,7 +460,6 @@ def _execute_command(kwargs):
from msrest.exceptions import ValidationError, ClientRequestError
from azure.batch.models import BatchErrorException
from knack.util import CLIError
from knack.commands import CLICommand
cmd = kwargs.pop('cmd')

try:
Expand Down Expand Up @@ -542,7 +541,6 @@ def get_kwargs(self):
'description_loader': self.description_loader,
'table_transformer': self.table_transformer,
'confirmation': self.confirmation,
#'validator': self.validator,
'client_factory': self.client_factory
}
args.update(self.merged_kwargs)
Expand Down Expand Up @@ -572,7 +570,7 @@ def _build_options(self, kwargs):
"""
kwargs[self._options_param] = self._options_model
for param in self._options_attrs:
if param in params.IGNORE_OPTIONS:
if param in pformat.IGNORE_OPTIONS:
continue
param_value = kwargs.pop(param)
if param_value is None:
Expand All @@ -593,7 +591,7 @@ def _should_flatten(self, param):
:param str param: The parameter name with complete namespace.
:returns: bool
"""
return param.count('.') < self._flatten and param not in params.IGNORE_PARAMETERS
return param.count('.') < self._flatten and param not in pformat.IGNORE_PARAMETERS

def _get_attrs(self, model, path):
"""Get all the attributes from the complex parameter model that should
Expand All @@ -603,26 +601,26 @@ def _get_attrs(self, model, path):
"""
for attr, details in model._attribute_map.items(): # pylint: disable=protected-access
conditions = []
full_path = '.'.join([self.parser._request_param['name'], path, attr])
full_path = '.'.join([self.parser._request_param['name'], path, attr]) # pylint: disable=protected-access
conditions.append(
model._validation.get(attr, {}).get('readonly')) # pylint: disable=protected-access
conditions.append(
model._validation.get(attr, {}).get('constant')) # pylint: disable=protected-access
conditions.append(any([i for i in params.IGNORE_PARAMETERS if i in full_path]))
conditions.append(any([i for i in pformat.IGNORE_PARAMETERS if i in full_path]))
conditions.append(details['type'][0] in ['{'])
if not any(conditions):
yield attr, details

def _process_options(self):
"""Process the request options parameter to expose as arguments."""
for param in [o for o in self._options_attrs if o not in params.IGNORE_OPTIONS]:
for param in [o for o in self._options_attrs if o not in pformat.IGNORE_OPTIONS]:
options = {}
options['required'] = False
options['arg_group'] = 'Pre-condition and Query'
if param in ['if_modified_since', 'if_unmodified_since']:
options['type'] = validators.datetime_format
if param in params.FLATTEN_OPTIONS:
for f_param, f_docstring in params.FLATTEN_OPTIONS[param].items():
if param in pformat.FLATTEN_OPTIONS:
for f_param, f_docstring in pformat.FLATTEN_OPTIONS[param].items():
options['default'] = None
options['help'] = f_docstring
options['options_list'] = [arg_name(f_param)]
Expand Down Expand Up @@ -654,9 +652,9 @@ def _resolve_conflict(self,
new = _build_prefix(arg, param, path)
options['options_list'] = [arg_name(new)]
self._resolve_conflict(new, param, path, options, typestr, dependencies, conflicting)
elif arg in conflicting or arg in params.QUALIFIED_PROPERTIES:
elif arg in conflicting or arg in pformat.QUALIFIED_PROPERTIES:
new = _build_prefix(arg, param, path)
if new in conflicting or new in params.QUALIFIED_PROPERTIES and '.' not in path:
if new in conflicting or new in pformat.QUALIFIED_PROPERTIES and '.' not in path:
self.parser.queue_argument(arg, path, param, options, typestr, dependencies)
else:
options['options_list'] = [arg_name(new)]
Expand Down Expand Up @@ -687,14 +685,14 @@ def _flatten_object(self, path, param_model, conflict_names=None):
lambda ns: validators.validate_required_parameter(ns, self.parser)
options['default'] = None # Extract details from signature

if details['type'] in params.BASIC_TYPES:
if details['type'] in pformat.BASIC_TYPES:
self._resolve_conflict(param_attr, param_attr, path, options,
details['type'], required_attrs, conflict_names)
elif details['type'].startswith('['):
# We only expose a list arg if there's a validator for it
# This will fail for 2D arrays - though Batch doesn't have any yet
inner_type = details['type'][1:-1]
if inner_type in params.BASIC_TYPES:
if inner_type in pformat.BASIC_TYPES:
options['help'] += " Space separated values."
self._resolve_conflict(
param_attr, param_attr, path, options,
Expand Down Expand Up @@ -770,7 +768,7 @@ def _load_transformed_arguments(self, handler):
type=file_type,
completer=FilesCompleter(),
help=docstring)))
elif arg[0] not in params.IGNORE_PARAMETERS:
elif arg[0] not in pformat.IGNORE_PARAMETERS:
args.append(arg)
return_type = find_return_type(handler)
if return_type == 'Generator':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from azure.cli.core.decorators import Completer


@Completer
def load_node_agent_skus(cmd, prefix, namespace): # pylint: disable=unused-argument
from msrest.exceptions import ClientRequestError
Expand All @@ -27,4 +28,4 @@ def load_node_agent_skus(cmd, prefix, namespace): # pylint: disable=unused-argu
image['version']))
return all_images
except (ClientRequestError, BatchErrorException):
return []
return []
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def batch_exception_handler(ex):
raise CLIError(message)
except AttributeError:
raise CLIError(ex)
elif isinstance(ex, ValidationError) or isinstance(ex, ClientRequestError):
elif isinstance(ex, (ValidationError, ClientRequestError)):
raise CLIError(ex)
elif isinstance(ex, CloudError):
raise CLIError(ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@
'start_range': "The byte range to be retrieved. If not set the file will be retrieved from the beginning.",
'end_range': "The byte range to be retrieved. If not set the file will be retrieved to the end."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

from knack.arguments import CLIArgumentType

# pylint: disable=line-too-long

# pylint: disable=line-too-long, too-many-statements
def load_arguments(self, _):
batch_name_type = CLIArgumentType(
help='Name of the Batch account.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,3 @@ def validate_client_parameters(cmd, namespace):

if cmd.cli_ctx.config.get('batch', 'auth_mode', 'shared_key') == 'aad':
namespace.account_key = None

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def get_mgmt_type(name):
with self.command_group('batch location quotas', get_mgmt_type('location')) as g:
g.command('show', 'get_quotas')


# Data Plane Commands
with self.command_group('batch application summary', get_data_type('application')) as g:
g.batch_command('list', 'list')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ def delete_certificate(client, thumbprint, abort=False):
thumbprint_algorithm = 'sha1'
if abort:
return client.cancel_deletion(thumbprint_algorithm, thumbprint)
else:
return client.delete(thumbprint_algorithm, thumbprint)
return client.delete(thumbprint_algorithm, thumbprint)


@transfer_doc(PoolResizeParameter)
Expand Down
Loading