From 12a49bebdfbea48078dbb97dfc353ca9432d4847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Cont=C3=A9?= Date: Tue, 4 Dec 2018 09:46:12 +0100 Subject: [PATCH] Fix KeyError if bkp_storage_account not defined in tags (#17) --- azfilebak/backupconfiguration.py | 2 +- sample_instance_metadata.json | 4 ++-- tests/test_azurevminstancemetadata.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azfilebak/backupconfiguration.py b/azfilebak/backupconfiguration.py index 6fbef26..c348111 100644 --- a/azfilebak/backupconfiguration.py +++ b/azfilebak/backupconfiguration.py @@ -170,7 +170,7 @@ class BackupConfiguration(object): information. """ try: - account = self.instance_metadata.get_tags()['bkp_storage_account'] + account = self.instance_metadata_tag_value('bkp_storage_account') logging.debug("Using storage account name from instance metadata: %s", account) except BackupException: cid = self.cfg_file_value("DEFAULT.CID").lower() diff --git a/sample_instance_metadata.json b/sample_instance_metadata.json index 77763c7..2514829 100644 --- a/sample_instance_metadata.json +++ b/sample_instance_metadata.json @@ -8,7 +8,7 @@ "subscriptionId": "2e394ee6-2714-4080-88c3-ecfc33d85147", "vmId": "0b9d6e6e-8f30-4e9c-8fe0-aacfb574f718", "vmSize": "Standard_D8s_v3", - "tags": "InfrastructureProvider:GMPTIC;Name:hec42v106014;Serial:AFD83530-840D-11E8-9E6C-FC820C452436;bkp_db_schedule:mo:111111111111111111111111, tu:111111111111111111111111, we:111111111111111111111111, th:111111111111111111111111, fr:111111111111111111111111, sa:111111111111111111111111, su:111111111111111111111111, min:1d, max:3d;bkp_fs_schedule:mo:111111111111111111111111, tu:111111111111111111111111, we:111111111111111111111111, th:111111111111111111111111, fr:111111111111111111111111, sa:111111111111111111111111, su:111111111111111111111111, min:1d, max:3d;bkp_log_schedule:mo:111111111111111111111111, tu:111111111111111111111111, we:111111111111111111111111, th:111111111111111111111111, fr:111111111111111111111111, sa:111111111111111111111111, su:111111111111111111111111, min:10m, max:30m;bkp_storage_account:sahec99az1backup0001" + "tags": "InfrastructureProvider:GMPTIC;Name:hec42v106014;Serial:AFD83530-840D-11E8-9E6C-FC820C452436;bkp_db_schedule:mo:111111111111111111111111, tu:111111111111111111111111, we:111111111111111111111111, th:111111111111111111111111, fr:111111111111111111111111, sa:111111111111111111111111, su:111111111111111111111111, min:1d, max:3d;bkp_fs_schedule:mo:111111111111111111111111, tu:111111111111111111111111, we:111111111111111111111111, th:111111111111111111111111, fr:111111111111111111111111, sa:111111111111111111111111, su:111111111111111111111111, min:1d, max:3d;bkp_log_schedule:mo:111111111111111111111111, tu:111111111111111111111111, we:111111111111111111111111, th:111111111111111111111111, fr:111111111111111111111111, sa:111111111111111111111111, su:111111111111111111111111, min:10m, max:30m" }, "network": { "interface": [ @@ -26,4 +26,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tests/test_azurevminstancemetadata.py b/tests/test_azurevminstancemetadata.py index fb0c3b4..373cf85 100644 --- a/tests/test_azurevminstancemetadata.py +++ b/tests/test_azurevminstancemetadata.py @@ -26,7 +26,7 @@ class TestAzureVMInstanceMetadata(LoggedTestCase): def test_get_tags(self): """test get_tags with empty tags property""" tags = self.meta.get_tags() - self.assertEqual(len(tags), 7) + self.assertEqual(len(tags), 6) self.assertEqual(tags['Name'], 'hec42v106014') def test_vm_name(self):