Basic error handling
This commit is contained in:
@@ -42,11 +42,21 @@ class FabricTestFile(pytest.File):
|
||||
will be taken from the file test-name.yaml
|
||||
|
||||
"""
|
||||
raw = yaml.safe_load(self.path.open())
|
||||
module = raw.pop('module')
|
||||
try:
|
||||
raw = yaml.safe_load(self.path.open())
|
||||
module = raw.pop('module')
|
||||
except (IOError, OSError, yaml.YAMLError) as e:
|
||||
raise Exception(f'cannot read test spec {self.path}: {e}')
|
||||
except KeyError as e:
|
||||
raise Exception(f'`module` key not found in {self.path}: {e}')
|
||||
for test_name, spec in raw.items():
|
||||
inventories = spec.get('inventory', [f'{test_name}.yaml'])
|
||||
tfvars = spec['tfvars']
|
||||
try:
|
||||
tfvars = spec['tfvars']
|
||||
except KeyError:
|
||||
raise Exception(
|
||||
f'test definition `{test_name}` in {self.path} does not contain a `tfvars` key'
|
||||
)
|
||||
for i in inventories:
|
||||
name = test_name
|
||||
if isinstance(inventories, list) and len(inventories) > 1:
|
||||
|
||||
@@ -146,7 +146,10 @@ def plan_validator(module_path, inventory_paths, basedir, tf_var_files=None,
|
||||
for path in inventory_paths:
|
||||
# allow tfvars and inventory to be relative to the caller
|
||||
path = basedir / path
|
||||
inventory = yaml.safe_load(path.read_text())
|
||||
try:
|
||||
inventory = yaml.safe_load(path.read_text())
|
||||
except (IOError, OSError, yaml.YAMLError) as e:
|
||||
raise Exception(f'cannot read test inventory {path}: {e}')
|
||||
|
||||
# don't fail if the inventory is empty
|
||||
inventory = inventory or {}
|
||||
|
||||
Reference in New Issue
Block a user