diff --git a/src/azure-cli/azure/cli/command_modules/resource/_help.py b/src/azure-cli/azure/cli/command_modules/resource/_help.py index 524c4a48210..f3aa56b58b1 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/_help.py +++ b/src/azure-cli/azure/cli/command_modules/resource/_help.py @@ -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 diff --git a/src/azure-cli/azure/cli/command_modules/resource/custom.py b/src/azure-cli/azure/cli/command_modules/resource/custom.py index 67bfae06581..93f6ba0aeae 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -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) diff --git a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py index 29b893ce80b..9d9bce0c88f 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py @@ -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) @@ -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__))