diff --git a/img_proof/ipa_azure.py b/img_proof/ipa_azure.py index 1945d63..cfd07b8 100644 --- a/img_proof/ipa_azure.py +++ b/img_proof/ipa_azure.py @@ -59,6 +59,11 @@ def post_init(self): ' are all required to use an existing subnet.' ) + if not self.region: + raise AzureCloudException( + 'Region is required to connect to Azure.' + ) + self.service_account_file = ( self.custom_args.get('service_account_file') or self.ipa_config['service_account_file'] diff --git a/tests/test_ipa_azure.py b/tests/test_ipa_azure.py index 2189cd9..7095bc4 100644 --- a/tests/test_ipa_azure.py +++ b/tests/test_ipa_azure.py @@ -63,10 +63,15 @@ def test_azure_exception_required_args(self): msg = 'SSH private key file is required to connect to instance.' # Test ssh private key file required - with pytest.raises(AzureCloudException) as error: + with pytest.raises(AzureCloudException, match=msg): AzureCloud(**self.kwargs) - assert str(error.value) == msg + # Test region required + self.kwargs['config'] = 'tests/data/config.noregion' + msg = 'Region is required to connect to Azure.' + + with pytest.raises(AzureCloudException, match=msg): + AzureCloud(**self.kwargs) @patch.object(AzureCloud, '_get_client_from_json') def test_get_management_client(self, mock_get_client):