Skip to content

Commit

Permalink
remove provider auto-reg logics as msrest runtime will do it (Azure#4622
Browse files Browse the repository at this point in the history
)
  • Loading branch information
yugangw-msft authored Oct 6, 2017
1 parent 68d5a8c commit bf3ef28
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 87 deletions.
1 change: 0 additions & 1 deletion azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
<Compile Include="azure-cli-core\azure\cli\core\tests\test_profile.py" />
<Compile Include="azure-cli-core\azure\cli\core\tests\test_progress.py" />
<Compile Include="azure-cli-core\azure\cli\core\tests\test_resource_id.py" />
<Compile Include="azure-cli-core\azure\cli\core\tests\test_rp_auto_reg.py" />
<Compile Include="azure-cli-core\azure\cli\core\tests\test_storage_validators.py" />
<Compile Include="azure-cli-core\azure\cli\core\tests\test_telemetry.py" />
<Compile Include="azure-cli-core\azure\cli\core\tests\test_util.py" />
Expand Down
71 changes: 20 additions & 51 deletions src/azure-cli-core/azure/cli/core/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,32 +598,26 @@ def _execute_command(kwargs):
client = client_factory(kwargs) if client_factory else None
try:
op = get_op_handler(operation)
for _ in range(2): # for possible retry, we do maximum 2 times.
try:
result = op(client, **kwargs) if client else op(**kwargs)
if no_wait_param and kwargs.get(no_wait_param, None):
return None # return None for 'no-wait'

# apply results transform if specified
if transform_result:
return transform_result(result)

# otherwise handle based on return type of results
if _is_poller(result):
return LongRunningOperation('Starting {}'.format(name))(result)
elif _is_paged(result):
return list(result)
return result
except Exception as ex: # pylint: disable=broad-except
rp = _check_rp_not_registered_err(ex)
if rp:
_register_rp(rp)
continue # retry
if exception_handler:
exception_handler(ex)
return
else:
reraise(*sys.exc_info())
try:
result = op(client, **kwargs) if client else op(**kwargs)
if no_wait_param and kwargs.get(no_wait_param, None):
return None # return None for 'no-wait'

# apply results transform if specified
if transform_result:
return transform_result(result)

# otherwise handle based on return type of results
if _is_poller(result):
return LongRunningOperation('Starting {}'.format(name))(result)
elif _is_paged(result):
return list(result)
return result
except Exception as ex: # pylint: disable=broad-except
if exception_handler:
exception_handler(ex)
else:
reraise(*sys.exc_info())
except _load_validation_error_class() as validation_error:
fault_type = name.replace(' ', '-') + '-validation-error'
telemetry.set_exception(validation_error, fault_type=fault_type,
Expand Down Expand Up @@ -677,31 +671,6 @@ def _user_confirmed(confirmation, command_args):
return False


def _check_rp_not_registered_err(ex):
try:
response = json.loads(ex.response.content.decode())
if response['error']['code'] == 'MissingSubscriptionRegistration':
match = re.match(r".*'(.*)'", response['error']['message'])
return match.group(1)
except Exception: # pylint: disable=broad-except
pass
return None


def _register_rp(rp):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
rcf = get_mgmt_service_client(ResourceType.MGMT_RESOURCE_RESOURCES)
logger.warning("Resource provider '%s' used by the command is not "
"registered. We are registering for you", rp)
rcf.providers.register(rp)
while True:
time.sleep(10)
rp_info = rcf.providers.get(rp)
if rp_info.registration_state == 'Registered':
logger.warning("Registration succeeded.")
break


def _get_cli_argument(command, argname):
return _cli_argument_registry.get_cli_argument(command, argname)

Expand Down
35 changes: 0 additions & 35 deletions src/azure-cli-core/azure/cli/core/tests/test_rp_auto_reg.py

This file was deleted.

0 comments on commit bf3ef28

Please sign in to comment.