summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorAnh Vo <anhvo@microsoft.com>2020-07-15 16:57:43 -0400
committerGitHub <noreply@github.com>2020-07-15 16:57:43 -0400
commitebc145be5e15c64a31ba496625727a7308a57baf (patch)
tree08fbe4655da7b50c654e00f2ca3d603d52c2fe0f /cloudinit
parentc0d239c7eadeae9c9e0b4e692b49e79c8ffcafd2 (diff)
downloadvyos-cloud-init-ebc145be5e15c64a31ba496625727a7308a57baf.tar.gz
vyos-cloud-init-ebc145be5e15c64a31ba496625727a7308a57baf.zip
DataSourceAzure: Use ValueError when JSONDecodeError is not available (#490)
JSONDecodeError is only available in Python 3.5+. When it isn't available (i.e. on Python 3.4, which cloud-init still supports) use the more generic ValueError.
Diffstat (limited to 'cloudinit')
-rwxr-xr-xcloudinit/sources/DataSourceAzure.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index 8b34d047..068537ee 100755
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -8,7 +8,6 @@ import base64
import contextlib
import crypt
from functools import partial
-import json
import os
import os.path
import re
@@ -1437,8 +1436,14 @@ def _get_metadata_from_imds(retries):
LOG.debug(msg)
return {}
try:
+ from json.decoder import JSONDecodeError
+ json_decode_error = JSONDecodeError
+ except ImportError:
+ json_decode_error = ValueError
+
+ try:
return util.load_json(str(response))
- except json.decoder.JSONDecodeError as e:
+ except json_decode_error as e:
report_diagnostic_event('non-json imds response' % e)
LOG.warning(
'Ignoring non-json IMDS instance metadata: %s', str(response))