Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 1 | import ConfigParser |
Jay Pipes | 7f75763 | 2011-12-02 15:53:32 -0500 | [diff] [blame] | 2 | import logging |
| 3 | import os |
kavan-patil | 4ea2efb | 2011-12-09 08:58:50 +0000 | [diff] [blame] | 4 | from tempest.common.utils import data_utils |
Jay Pipes | 7f75763 | 2011-12-02 15:53:32 -0500 | [diff] [blame] | 5 | |
| 6 | LOG = logging.getLogger(__name__) |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 7 | |
| 8 | |
| 9 | class NovaConfig(object): |
| 10 | """Provides configuration information for connecting to Nova.""" |
| 11 | |
| 12 | def __init__(self, conf): |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 13 | """Initialize a Nova-specific configuration object""" |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 14 | self.conf = conf |
| 15 | |
donald-ngo | 7fb1efa | 2011-12-13 17:17:36 -0800 | [diff] [blame] | 16 | def get(self, item_name, default_value=None): |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 17 | try: |
| 18 | return self.conf.get("nova", item_name) |
| 19 | except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): |
| 20 | return default_value |
| 21 | |
| 22 | @property |
Rohit Karajgi | e1b050d | 2011-12-02 16:13:18 -0800 | [diff] [blame] | 23 | def host(self): |
| 24 | """Host IP for making Nova API requests. Defaults to '127.0.0.1'.""" |
donald-ngo | 7fb1efa | 2011-12-13 17:17:36 -0800 | [diff] [blame] | 25 | return self.get("host", "127.0.0.1") |
Rohit Karajgi | e1b050d | 2011-12-02 16:13:18 -0800 | [diff] [blame] | 26 | |
| 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-patil | 4ea2efb | 2011-12-09 08:58:50 +0000 | [diff] [blame] | 42 | @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-ngo | 7fb1efa | 2011-12-13 17:17:36 -0800 | [diff] [blame] | 48 | self.path, |
| 49 | use_ssl=self.use_ssl) |
kavan-patil | 4ea2efb | 2011-12-09 08:58:50 +0000 | [diff] [blame] | 50 | return auth_url |
| 51 | |
Rohit Karajgi | e1b050d | 2011-12-02 16:13:18 -0800 | [diff] [blame] | 52 | def params(self): |
| 53 | """Parameters to be passed with the API request""" |
| 54 | return self.get("params", "") |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 55 | |
| 56 | @property |
donald-ngo | 7fb1efa | 2011-12-13 17:17:36 -0800 | [diff] [blame] | 57 | def use_ssl(self): |
| 58 | """Specifies if we are using https.""" |
| 59 | return bool(self.get("use_ssl", False)) |
| 60 | |
| 61 | @property |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 62 | 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 | |
| 92 | class 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 Walleck | adea1fa | 2011-11-15 18:36:39 -0600 | [diff] [blame] | 116 | return self.get("flavor_ref", 1) |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 117 | |
| 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-patil | 4ea2efb | 2011-12-09 08:58:50 +0000 | [diff] [blame] | 130 | """ Does the test environment support snapshots """ |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 131 | 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 Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 139 | class TempestConfig(object): |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 140 | """Provides OpenStack configuration information.""" |
| 141 | |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 142 | DEFAULT_CONFIG_DIR = os.path.join( |
| 143 | os.path.abspath( |
| 144 | os.path.dirname( |
| 145 | os.path.dirname(__file__))), |
| 146 | "etc") |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 147 | |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 148 | 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 Pipes | 7f75763 | 2011-12-02 15:53:32 -0500 | [diff] [blame] | 159 | 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 Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 166 | self.nova = NovaConfig(self._conf) |
| 167 | self.env = EnvironmentConfig(self._conf) |
| 168 | |
Jay Pipes | 7f75763 | 2011-12-02 15:53:32 -0500 | [diff] [blame] | 169 | def load_config(self, path): |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 170 | """Read configuration from given path and return a config object.""" |
| 171 | config = ConfigParser.SafeConfigParser() |
| 172 | config.read(path) |
| 173 | return config |