From 328471e7fd5cedef4053e2a7a15effe24eb26730 Mon Sep 17 00:00:00 2001 From: Sean Marlow Date: Mon, 27 Sep 2021 10:44:48 -0500 Subject: [PATCH] Raise if no region is provided for Azure CSP Fixes #310 --- img_proof/ipa_azure.py | 5 +++++ tests/test_ipa_azure.py | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) 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):