This repository has been archived by the owner on Feb 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
blueprint_test_configuration.py
80 lines (67 loc) · 2.58 KB
/
blueprint_test_configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Utilities to deal with blueprint test configuration files.
"""
import os
import yaml
from cloudless.util.log import logger
class BlueprintTestConfiguration:
"""
Base blueprint test configuration object
This is where to enforce things like types, required arguments, and just general configuration
constraints. This turns it into a kind of "schema" that someday we can probably auto generate
using a YAML schema library.
"""
def __init__(self, config):
with open(config, 'r') as stream:
try:
self.config = yaml.safe_load(stream)
except yaml.YAMLError as exc:
logger.error("Error parsing config: %s", exc)
raise exc
self.config_path = os.path.dirname(config)
if not self.config_path:
self.config_path = "./"
self.config_filename = config
def get_config_dir(self):
"""
Get directory of the file behind this configuration.
"""
return os.path.abspath(self.config_path)
def get_state_dir(self):
"""
Get temporary state directory for this configuration.
"""
return os.path.join(self.get_config_dir(), ".cloudless")
def get_count(self):
"""
Get number of instances needed to test.
"""
return int(self.config.get("create", {}).get("count", 1))
def get_blueprint_path(self):
"""
Get path to the blueprint being tested.
"""
relative_blueprint_path = self.config.get("create", {}).get("blueprint", "blueprint.yml")
return os.path.join(self.config_path, relative_blueprint_path)
def get_create_fixture_type(self):
"""
Get the fixture type for the create step.
"""
return self.config.get("create", {}).get("fixture_type", "python-blueprint-fixture")
def get_create_fixture_options(self):
"""
Get the fixture options for the create step.
"""
return self.config.get("create", {}).get("fixture_options",
{"module_name": "blueprint_fixture"})
def get_verify_fixture_type(self):
"""
Get the fixture type for the verify step.
"""
return self.config.get("verify", {}).get("fixture_type", "python-blueprint-fixture")
def get_verify_fixture_options(self):
"""
Get the fixture options for the verify step.
"""
return self.config.get("verify", {}).get("fixture_options",
{"module_name": "blueprint_fixture"})