Skip to content
Draft
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
6 changes: 6 additions & 0 deletions src/azure-cli/azure/cli/command_modules/resource/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1747,11 +1747,17 @@
helps['provider register'] = """
type: command
short-summary: Register a provider.
long-summary: By default, this command registers the provider in the current default subscription. Use
`--subscription` or `az account set` to change the default subscription when you need to target
another one.
examples:
- name: Register a provider. (autogenerated)
text: |
az provider register --namespace 'Microsoft.PolicyInsights'
crafted: true
- name: Register a provider for a specific subscription.
text: |
az provider register --namespace Microsoft.CognitiveServices --subscription 12345678-1234-1234-1234-123456789012
- name: Register a provider from RPaaS.
text: |
az provider register -n 'Microsoft.Confluent' --accept-terms
Expand Down
12 changes: 8 additions & 4 deletions src/azure-cli/azure/cli/command_modules/resource/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3459,14 +3459,18 @@ def list_features(client, resource_provider_namespace=None):


def register_feature(client, resource_provider_namespace, feature_name):
logger.warning("Once the feature '%s' is registered, invoking 'az provider register -n %s' is required "
"to get the change propagated", feature_name, resource_provider_namespace)
logger.warning("Once the feature '%s' is registered, invoke 'az provider register -n %s' in the current "
"default subscription to get the change propagated. Use '--subscription' or "
"'az account set' to change the default subscription if you need to target another one.",
feature_name, resource_provider_namespace)
return client.register(resource_provider_namespace, feature_name)


def unregister_feature(client, resource_provider_namespace, feature_name):
logger.warning("Once the feature '%s' is unregistered, invoking 'az provider register -n %s' is required "
"to get the change propagated", feature_name, resource_provider_namespace)
logger.warning("Once the feature '%s' is unregistered, invoke 'az provider register -n %s' in the current "
"default subscription to get the change propagated. Use '--subscription' or "
"'az account set' to change the default subscription if you need to target another one.",
feature_name, resource_provider_namespace)
return client.unregister(resource_provider_namespace, feature_name)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
publish_bicep_file,
_process_template_file,
_prepare_deployment_properties_unmodified,
register_feature,
unregister_feature,
)
from azure.cli.command_modules.resource._help import helps

from azure.cli.command_modules.resource._bicep import (run_bicep_command)

Expand Down Expand Up @@ -252,6 +255,34 @@ def prompt_function(x):
with self.assertRaisesRegex(CLIError, "Missing input parameters: missing"):
_get_missing_parameters(parameters, template, prompt_function)

@mock.patch('azure.cli.command_modules.resource.custom.logger.warning')
def test_feature_registration_warning_mentions_subscription_scope(self, logger_warning):
feature_name = 'TestFeature'
for method_name, operation in [('register', register_feature), ('unregister', unregister_feature)]:
with self.subTest(method_name=method_name):
logger_warning.reset_mock()
client = mock.Mock()
expected = object()
getattr(client, method_name).return_value = expected

result = operation(client, 'Microsoft.CognitiveServices', feature_name)

self.assertIs(result, expected)
getattr(client, method_name).assert_called_once_with(
'Microsoft.CognitiveServices', feature_name)
logger_warning.assert_called_once()
warning_message = logger_warning.call_args.args[0]
self.assertIn('current default subscription', warning_message)
self.assertIn('--subscription', warning_message)
self.assertIn('az account set', warning_message)

def test_provider_register_help_mentions_subscription_scope(self):
self.assertIn('provider register', helps)
help_text = helps['provider register']
self.assertIn('current default subscription', help_text)
self.assertIn('`--subscription`', help_text)
self.assertIn('Microsoft.CognitiveServices --subscription', help_text)

def test_deployment_parameters(self):

curr_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down