summaryrefslogtreecommitdiff
path: root/cloudinit/handlers
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-10-30 20:02:38 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-10-30 20:02:38 +0000
commitd74d3f0ff5c8d453f626b113f4e6065322f822fa (patch)
tree9bccbc3de8cc63f1624e2188d8d869f102987c0c /cloudinit/handlers
parentdc0be9c56f78537f1808934d26f5aa0868ae7842 (diff)
downloadvyos-cloud-init-d74d3f0ff5c8d453f626b113f4e6065322f822fa.tar.gz
vyos-cloud-init-d74d3f0ff5c8d453f626b113f4e6065322f822fa.zip
query: better error when missing read permission on instance-data
Emit a permissions error instead of "Missing instance-data.json" when non-root user doesn't have read-permission on /run/cloud-init/instance-data.json
Diffstat (limited to 'cloudinit/handlers')
-rw-r--r--cloudinit/handlers/jinja_template.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/cloudinit/handlers/jinja_template.py b/cloudinit/handlers/jinja_template.py
index 3fa4097e..ce3accf6 100644
--- a/cloudinit/handlers/jinja_template.py
+++ b/cloudinit/handlers/jinja_template.py
@@ -1,5 +1,6 @@
# This file is part of cloud-init. See LICENSE file for license information.
+from errno import EACCES
import os
import re
@@ -76,7 +77,14 @@ def render_jinja_payload_from_file(
raise RuntimeError(
'Cannot render jinja template vars. Instance data not yet'
' present at %s' % instance_data_file)
- instance_data = load_json(load_file(instance_data_file))
+ try:
+ instance_data = load_json(load_file(instance_data_file))
+ except (IOError, OSError) as e:
+ if e.errno == EACCES:
+ raise RuntimeError(
+ 'Cannot render jinja template vars. No read permission on'
+ " '%s'. Try sudo" % instance_data_file)
+
rendered_payload = render_jinja_payload(
payload, payload_fn, instance_data, debug)
if not rendered_payload: