blob: 0d5a0961602824d9370938d6bf4120a540b5b4a0 [file] [log] [blame]
Daryl Walleck1465d612011-11-02 02:22:15 -05001import ConfigParser
Jay Pipes7f757632011-12-02 15:53:32 -05002import logging
3import os
kavan-patil4ea2efb2011-12-09 08:58:50 +00004from tempest.common.utils import data_utils
Jay Pipes7f757632011-12-02 15:53:32 -05005
6LOG = logging.getLogger(__name__)
Daryl Walleck1465d612011-11-02 02:22:15 -05007
8
9class NovaConfig(object):
10 """Provides configuration information for connecting to Nova."""
11
12 def __init__(self, conf):
Daryl Wallecke5b83d42011-11-10 14:39:02 -060013 """Initialize a Nova-specific configuration object"""
Daryl Walleck1465d612011-11-02 02:22:15 -050014 self.conf = conf
15
donald-ngo7fb1efa2011-12-13 17:17:36 -080016 def get(self, item_name, default_value=None):
Daryl Walleck1465d612011-11-02 02:22:15 -050017 try:
18 return self.conf.get("nova", item_name)
19 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
20 return default_value
21
22 @property
Rohit Karajgie1b050d2011-12-02 16:13:18 -080023 def host(self):
24 """Host IP for making Nova API requests. Defaults to '127.0.0.1'."""
donald-ngo7fb1efa2011-12-13 17:17:36 -080025 return self.get("host", "127.0.0.1")
Rohit Karajgie1b050d2011-12-02 16:13:18 -080026
27 @property
28 def port(self):
29 """Listen port of the Nova service."""
30 return self.get("port", "8773")
31
32 @property
33 def apiVer(self):
34 """Version of the API"""
35 return self.get("apiVer", "v1.1")
36
37 @property
38 def path(self):
39 """Path of API request"""
40 return self.get("path", "/")
41
kavan-patil4ea2efb2011-12-09 08:58:50 +000042 @property
43 def auth_url(self):
44 """The Auth URL (derived)"""
45 auth_url = data_utils.build_url(self.host,
46 self.port,
47 self.apiVer,
donald-ngo7fb1efa2011-12-13 17:17:36 -080048 self.path,
49 use_ssl=self.use_ssl)
kavan-patil4ea2efb2011-12-09 08:58:50 +000050 return auth_url
51
Rohit Karajgie1b050d2011-12-02 16:13:18 -080052 def params(self):
53 """Parameters to be passed with the API request"""
54 return self.get("params", "")
Daryl Walleck1465d612011-11-02 02:22:15 -050055
56 @property
donald-ngo7fb1efa2011-12-13 17:17:36 -080057 def use_ssl(self):
58 """Specifies if we are using https."""
59 return bool(self.get("use_ssl", False))
60
61 @property
Daryl Walleck1465d612011-11-02 02:22:15 -050062 def username(self):
63 """Username to use for Nova API requests. Defaults to 'admin'."""
64 return self.get("user", "admin")
65
66 @property
67 def tenant_name(self):
68 """Tenant name to use for Nova API requests. Defaults to 'admin'."""
69 return self.get("tenant_name", "admin")
70
71 @property
72 def api_key(self):
73 """API key to use when authenticating. Defaults to 'admin_key'."""
74 return self.get("api_key", "admin_key")
75
76 @property
77 def build_interval(self):
78 """Time in seconds between build status checks."""
79 return float(self.get("build_interval", 10))
80
81 @property
82 def ssh_timeout(self):
83 """Timeout in seconds to use when connecting via ssh."""
84 return float(self.get("ssh_timeout", 300))
85
86 @property
87 def build_timeout(self):
88 """Timeout in seconds to wait for an entity to build."""
89 return float(self.get("build_timeout", 300))
90
91
92class EnvironmentConfig(object):
93 def __init__(self, conf):
94 """Initialize a Environment-specific configuration object."""
95 self.conf = conf
96
97 def get(self, item_name, default_value):
98 try:
99 return self.conf.get("environment", item_name)
100 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
101 return default_value
102
103 @property
104 def image_ref(self):
105 """Valid imageRef to use """
106 return self.get("image_ref", 3)
107
108 @property
109 def image_ref_alt(self):
110 """Valid imageRef to rebuild images with"""
111 return self.get("image_ref_alt", 3)
112
113 @property
114 def flavor_ref(self):
115 """Valid flavorRef to use"""
Daryl Walleckadea1fa2011-11-15 18:36:39 -0600116 return self.get("flavor_ref", 1)
Daryl Walleck1465d612011-11-02 02:22:15 -0500117
118 @property
119 def flavor_ref_alt(self):
120 """Valid flavorRef to resize images with"""
121 return self.get("flavor_ref_alt", 2)
122
123 @property
124 def resize_available(self):
125 """ Does the test environment support resizing """
126 return self.get("resize_available", 'false') != 'false'
127
128 @property
129 def create_image_enabled(self):
kavan-patil4ea2efb2011-12-09 08:58:50 +0000130 """ Does the test environment support snapshots """
Daryl Walleck1465d612011-11-02 02:22:15 -0500131 return self.get("create_image_enabled", 'false') != 'false'
132
133 @property
134 def authentication(self):
135 """ What auth method does the environment use (basic|keystone) """
136 return self.get("authentication", 'keystone')
137
138
Daryl Wallecked8bef32011-12-05 23:02:08 -0600139class TempestConfig(object):
Daryl Walleck1465d612011-11-02 02:22:15 -0500140 """Provides OpenStack configuration information."""
141
Brian Waldon738cd632011-12-12 18:45:09 -0500142 DEFAULT_CONFIG_DIR = os.path.join(
143 os.path.abspath(
144 os.path.dirname(
145 os.path.dirname(__file__))),
146 "etc")
Daryl Walleck1465d612011-11-02 02:22:15 -0500147
Brian Waldon738cd632011-12-12 18:45:09 -0500148 DEFAULT_CONFIG_FILE = "tempest.conf"
149
150 def __init__(self):
151 """Initialize a configuration from a conf directory and conf file."""
152
153 # Environment variables override defaults...
154 conf_dir = os.environ.get('TEMPEST_CONFIG_DIR',
155 self.DEFAULT_CONFIG_DIR)
156 conf_file = os.environ.get('TEMPEST_CONFIG',
157 self.DEFAULT_CONFIG_FILE)
158
Jay Pipes7f757632011-12-02 15:53:32 -0500159 path = os.path.join(conf_dir, conf_file)
160
161 if not os.path.exists(path):
162 msg = "Config file %(path)s not found" % locals()
163 raise RuntimeError(msg)
164
165 self._conf = self.load_config(path)
Daryl Walleck1465d612011-11-02 02:22:15 -0500166 self.nova = NovaConfig(self._conf)
167 self.env = EnvironmentConfig(self._conf)
168
Jay Pipes7f757632011-12-02 15:53:32 -0500169 def load_config(self, path):
Daryl Walleck1465d612011-11-02 02:22:15 -0500170 """Read configuration from given path and return a config object."""
171 config = ConfigParser.SafeConfigParser()
172 config.read(path)
173 return config