blob: 2e6fc7107e4a43646a6446774516b9b645756ab9 [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']
120
121 if 'keystone' in self.config:
122 self.keystone['host'] = self.config['keystone']['host']
123 self.keystone['port'] = self.config['keystone']['port']
124 self.keystone['apiver'] = self.config['keystone']['apiver']
125 self.keystone['user'] = self.config['keystone']['user']
126 self.keystone['pass'] = self.config['keystone']['password']
127
128 def _md5sum_file(self, path):
129 md5sum = md5()
130 with open(path, 'rb') as file:
131 for chunk in iter(lambda: file.read(8192), ''):
132 md5sum.update(chunk)
133 return md5sum.hexdigest()
134
135 def _read_in_chunks(self, infile, chunk_size=1024 * 64):
136 file_data = open(infile, "rb")
137 while True:
138 # chunk = file_data.read(chunk_size).encode('base64')
139 chunk = file_data.read(chunk_size)
140 if chunk:
141 yield chunk
142 else:
143 return
144 file_data.close()
145
146 def _parse_defaults_file(self):
147 cfg = os.path.abspath(os.path.join(os.path.dirname(__file__),
Soren Hansenec3f7092011-09-08 13:03:42 +0200148 os.path.pardir, os.path.pardir,
149 "etc", "config.ini"))
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500150 if os.path.exists(cfg):
151 self._build_config(cfg)
152 else:
153 raise Exception("Cannot read %s" % cfg)
154
155 def _build_config(self, config_file):
156 parser = ConfigParser.ConfigParser()
157 parser.read(config_file)
158
159 for section in parser.sections():
160 self.config[section] = {}
161 for value in parser.options(section):
162 self.config[section][value] = parser.get(section, value)
163 # print "%s = %s" % (value, parser.get(section, value))