blob: c47548810065e97a0d7277171917b7691a9a991d [file] [log] [blame]
Justin Shepherd0d9bbd12011-08-11 12:57:44 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2010-2011 OpenStack LLC.
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import ConfigParser
19from hashlib import md5
20import nose.plugins.skip
21import os
Justin Shepherd66c861a2011-08-18 11:02:53 -050022from pprint import pprint
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050023import unittest2
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050024
25NOVA_DATA = {}
26GLANCE_DATA = {}
27SWIFT_DATA = {}
28RABBITMQ_DATA = {}
29CONFIG_DATA = {}
30KEYSTONE_DATA = {}
31
Soren Hansen826d5df2011-08-29 11:30:40 +020032
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050033class skip_test(object):
34 """Decorator that skips a test."""
35 def __init__(self, msg):
36 self.message = msg
37
38 def __call__(self, func):
39 def _skipper(*args, **kw):
40 """Wrapped skipper function."""
41 raise nose.SkipTest(self.message)
42 _skipper.__name__ = func.__name__
43 _skipper.__doc__ = func.__doc__
44 return _skipper
45
46
47class skip_if(object):
48 """Decorator that skips a test."""
49 def __init__(self, condition, msg):
50 self.condition = condition
51 self.message = msg
52
53 def __call__(self, func):
54 def _skipper(*args, **kw):
55 """Wrapped skipper function."""
56 if self.condition:
57 raise nose.SkipTest(self.message)
58 func(*args, **kw)
59 _skipper.__name__ = func.__name__
60 _skipper.__doc__ = func.__doc__
61 return _skipper
62
63
64class skip_unless(object):
65 """Decorator that skips a test."""
66 def __init__(self, condition, msg):
67 self.condition = condition
68 self.message = msg
69
70 def __call__(self, func):
71 def _skipper(*args, **kw):
72 """Wrapped skipper function."""
73 if not self.condition:
74 raise nose.SkipTest(self.message)
75 func(*args, **kw)
76 _skipper.__name__ = func.__name__
77 _skipper.__doc__ = func.__doc__
78 return _skipper
79
80
81class FunctionalTest(unittest2.TestCase):
82 def setUp(self):
Soren Hansen826d5df2011-08-29 11:30:40 +020083 global GLANCE_DATA, NOVA_DATA, SWIFT_DATA, RABBITMQ_DATA
84 global KEYSTONE_DATA, CONFIG_DATA
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050085 # Define config dict
86 self.config = CONFIG_DATA
87 # Define service specific dicts
88 self.glance = GLANCE_DATA
89 self.nova = NOVA_DATA
90 self.swift = SWIFT_DATA
91 self.rabbitmq = RABBITMQ_DATA
92 self.keystone = KEYSTONE_DATA
93
94 self._parse_defaults_file()
Justin Shepherd66c861a2011-08-18 11:02:53 -050095 pprint(self.config)
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050096
97 # Swift Setup
98 if 'swift' in self.config:
99 self.swift['auth_host'] = self.config['swift']['auth_host']
100 self.swift['auth_port'] = self.config['swift']['auth_port']
101 self.swift['auth_prefix'] = self.config['swift']['auth_prefix']
102 self.swift['auth_ssl'] = self.config['swift']['auth_ssl']
103 self.swift['account'] = self.config['swift']['account']
104 self.swift['username'] = self.config['swift']['username']
105 self.swift['password'] = self.config['swift']['password']
Soren Hansen826d5df2011-08-29 11:30:40 +0200106 self.swift['ver'] = 'v1.0' # need to find a better way to get this
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500107
108 # Glance Setup
109 self.glance['host'] = self.config['glance']['host']
110 self.glance['port'] = self.config['glance']['port']
111 if 'apiver' in self.config['glance']:
112 self.glance['apiver'] = self.config['glance']['apiver']
113
114 if 'nova' in self.config:
115 self.nova['host'] = self.config['nova']['host']
116 self.nova['port'] = self.config['nova']['port']
117 self.nova['ver'] = self.config['nova']['apiver']
118 self.nova['user'] = self.config['nova']['user']
119 self.nova['key'] = self.config['nova']['key']
Soren Hansena86180a2011-09-09 16:22:26 +0200120 self.nova['flavor_ref'] = self.config['nova']['flavor_ref']
121 self.nova['flavor_ref_alt'] = self.config['nova']['flavor_ref_alt']
122 self.nova['ssh_timeout'] = self.config['nova']['ssh_timeout']
123 self.nova['build_timeout'] = self.config['nova']['build_timeout']
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500124
125 if 'keystone' in self.config:
126 self.keystone['host'] = self.config['keystone']['host']
127 self.keystone['port'] = self.config['keystone']['port']
128 self.keystone['apiver'] = self.config['keystone']['apiver']
129 self.keystone['user'] = self.config['keystone']['user']
130 self.keystone['pass'] = self.config['keystone']['password']
131
132 def _md5sum_file(self, path):
133 md5sum = md5()
134 with open(path, 'rb') as file:
135 for chunk in iter(lambda: file.read(8192), ''):
136 md5sum.update(chunk)
137 return md5sum.hexdigest()
138
139 def _read_in_chunks(self, infile, chunk_size=1024 * 64):
140 file_data = open(infile, "rb")
141 while True:
142 # chunk = file_data.read(chunk_size).encode('base64')
143 chunk = file_data.read(chunk_size)
144 if chunk:
145 yield chunk
146 else:
147 return
148 file_data.close()
149
150 def _parse_defaults_file(self):
151 cfg = os.path.abspath(os.path.join(os.path.dirname(__file__),
Soren Hansenec3f7092011-09-08 13:03:42 +0200152 os.path.pardir, os.path.pardir,
153 "etc", "config.ini"))
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500154 if os.path.exists(cfg):
155 self._build_config(cfg)
156 else:
157 raise Exception("Cannot read %s" % cfg)
158
159 def _build_config(self, config_file):
160 parser = ConfigParser.ConfigParser()
161 parser.read(config_file)
162
163 for section in parser.sections():
164 self.config[section] = {}
165 for value in parser.options(section):
166 self.config[section][value] = parser.get(section, value)
167 # print "%s = %s" % (value, parser.get(section, value))