blob: b1002583998862006e2aaf055c1121041d619822 [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
32class skip_test(object):
33 """Decorator that skips a test."""
34 def __init__(self, msg):
35 self.message = msg
36
37 def __call__(self, func):
38 def _skipper(*args, **kw):
39 """Wrapped skipper function."""
40 raise nose.SkipTest(self.message)
41 _skipper.__name__ = func.__name__
42 _skipper.__doc__ = func.__doc__
43 return _skipper
44
45
46class skip_if(object):
47 """Decorator that skips a test."""
48 def __init__(self, condition, msg):
49 self.condition = condition
50 self.message = msg
51
52 def __call__(self, func):
53 def _skipper(*args, **kw):
54 """Wrapped skipper function."""
55 if self.condition:
56 raise nose.SkipTest(self.message)
57 func(*args, **kw)
58 _skipper.__name__ = func.__name__
59 _skipper.__doc__ = func.__doc__
60 return _skipper
61
62
63class skip_unless(object):
64 """Decorator that skips a test."""
65 def __init__(self, condition, msg):
66 self.condition = condition
67 self.message = msg
68
69 def __call__(self, func):
70 def _skipper(*args, **kw):
71 """Wrapped skipper function."""
72 if not self.condition:
73 raise nose.SkipTest(self.message)
74 func(*args, **kw)
75 _skipper.__name__ = func.__name__
76 _skipper.__doc__ = func.__doc__
77 return _skipper
78
79
80class FunctionalTest(unittest2.TestCase):
81 def setUp(self):
82 global GLANCE_DATA, NOVA_DATA, SWIFT_DATA, RABBITMQ_DATA, KEYSTONE_DATA, CONFIG_DATA
83 # Define config dict
84 self.config = CONFIG_DATA
85 # Define service specific dicts
86 self.glance = GLANCE_DATA
87 self.nova = NOVA_DATA
88 self.swift = SWIFT_DATA
89 self.rabbitmq = RABBITMQ_DATA
90 self.keystone = KEYSTONE_DATA
91
92 self._parse_defaults_file()
Justin Shepherd66c861a2011-08-18 11:02:53 -050093 pprint(self.config)
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050094
95 # Swift Setup
96 if 'swift' in self.config:
97 self.swift['auth_host'] = self.config['swift']['auth_host']
98 self.swift['auth_port'] = self.config['swift']['auth_port']
99 self.swift['auth_prefix'] = self.config['swift']['auth_prefix']
100 self.swift['auth_ssl'] = self.config['swift']['auth_ssl']
101 self.swift['account'] = self.config['swift']['account']
102 self.swift['username'] = self.config['swift']['username']
103 self.swift['password'] = self.config['swift']['password']
104 self.swift['ver'] = 'v1.0' # need to find a better way to get this.
105
106 # Glance Setup
107 self.glance['host'] = self.config['glance']['host']
108 self.glance['port'] = self.config['glance']['port']
109 if 'apiver' in self.config['glance']:
110 self.glance['apiver'] = self.config['glance']['apiver']
111
112 if 'nova' in self.config:
113 self.nova['host'] = self.config['nova']['host']
114 self.nova['port'] = self.config['nova']['port']
115 self.nova['ver'] = self.config['nova']['apiver']
116 self.nova['user'] = self.config['nova']['user']
117 self.nova['key'] = self.config['nova']['key']
118
119 if 'keystone' in self.config:
120 self.keystone['host'] = self.config['keystone']['host']
121 self.keystone['port'] = self.config['keystone']['port']
122 self.keystone['apiver'] = self.config['keystone']['apiver']
123 self.keystone['user'] = self.config['keystone']['user']
124 self.keystone['pass'] = self.config['keystone']['password']
125
126 def _md5sum_file(self, path):
127 md5sum = md5()
128 with open(path, 'rb') as file:
129 for chunk in iter(lambda: file.read(8192), ''):
130 md5sum.update(chunk)
131 return md5sum.hexdigest()
132
133 def _read_in_chunks(self, infile, chunk_size=1024 * 64):
134 file_data = open(infile, "rb")
135 while True:
136 # chunk = file_data.read(chunk_size).encode('base64')
137 chunk = file_data.read(chunk_size)
138 if chunk:
139 yield chunk
140 else:
141 return
142 file_data.close()
143
144 def _parse_defaults_file(self):
145 cfg = os.path.abspath(os.path.join(os.path.dirname(__file__),
146 "..", "etc", "config.ini"))
147 if os.path.exists(cfg):
148 self._build_config(cfg)
149 else:
150 raise Exception("Cannot read %s" % cfg)
151
152 def _build_config(self, config_file):
153 parser = ConfigParser.ConfigParser()
154 parser.read(config_file)
155
156 for section in parser.sections():
157 self.config[section] = {}
158 for value in parser.options(section):
159 self.config[section][value] = parser.get(section, value)
160 # print "%s = %s" % (value, parser.get(section, value))