remove provider auto-reg logics as msrest runtime will do it (#4622)

This commit is contained in:
Yugang Wang 2017-10-06 09:54:28 -07:00 коммит произвёл GitHub
Родитель 68d5a8c950
Коммит bf3ef28f9d
3 изменённых файлов: 18 добавлений и 85 удалений

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

@ -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" />

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

@ -598,32 +598,26 @@ def create_command(module_name, name, operation,
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'
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)
# 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())
# 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,
@ -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)

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

@ -1,35 +0,0 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import unittest
import json
import time
import mock
from azure.cli.testsdk import (JMESPathCheck, ResourceGroupPreparer, ScenarioTest, record_only)
from azure.cli.core.commands import _check_rp_not_registered_err
class TestRPErrorPolish(unittest.TestCase):
def test_rp_error_polish(self):
ex = mock.MagicMock()
# bad error
ex.response.content = b'bad error'
result = _check_rp_not_registered_err(ex)
self.assertFalse(bool(result))
# good error (but not we are interested)
ex.response.content = b'{"error":{"code":"c1","message":"m1"}}'
result = _check_rp_not_registered_err(ex)
self.assertFalse(bool(result))
# the error we want to polish
ex.response.content = (b'{"error":{"code":"MissingSubscriptionRegistration","message":'
b'"The subscription is not registered to use namespace '
b'\'Microsoft.Sql\'. See https://aka.ms/rps-not-found for how '
b'to register subscriptions."}}')
result = _check_rp_not_registered_err(ex)
self.assertEqual(str(result), 'Microsoft.Sql')