blob: 92725cbfc06a29960653fecff912f2166a01b748 [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
22import unittest2
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050023
24NOVA_DATA = {}
25GLANCE_DATA = {}
26SWIFT_DATA = {}
27RABBITMQ_DATA = {}
28CONFIG_DATA = {}
29KEYSTONE_DATA = {}
30
Soren Hansen826d5df2011-08-29 11:30:40 +020031
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050032class 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):
Soren Hansen826d5df2011-08-29 11:30:40 +020082 global GLANCE_DATA, NOVA_DATA, SWIFT_DATA, RABBITMQ_DATA
83 global KEYSTONE_DATA, CONFIG_DATA
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050084 # Define config dict
85 self.config = CONFIG_DATA
86 # Define service specific dicts
87 self.glance = GLANCE_DATA
88 self.nova = NOVA_DATA
89 self.swift = SWIFT_DATA
90 self.rabbitmq = RABBITMQ_DATA
91 self.keystone = KEYSTONE_DATA
92
93 self._parse_defaults_file()
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050094
95 # Swift Setup
96 if 'swift' in self.config:
Aaron Lee35b8c922011-10-18 17:07:19 -050097 self.swift = self.config['swift']
Soren Hansen826d5df2011-08-29 11:30:40 +020098 self.swift['ver'] = 'v1.0' # need to find a better way to get this
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050099
100 # Glance Setup
Aaron Lee35b8c922011-10-18 17:07:19 -0500101 self.glance = self.config['glance']
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500102
103 if 'nova' in self.config:
Aaron Lee35b8c922011-10-18 17:07:19 -0500104 self.nova = self.config['nova']
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500105 self.nova['ver'] = self.config['nova']['apiver']
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500106
107 if 'keystone' in self.config:
Aaron Lee35b8c922011-10-18 17:07:19 -0500108 self.keystone = self.config['keystone']
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500109 self.keystone['pass'] = self.config['keystone']['password']
110
111 def _md5sum_file(self, path):
112 md5sum = md5()
113 with open(path, 'rb') as file:
114 for chunk in iter(lambda: file.read(8192), ''):
115 md5sum.update(chunk)
116 return md5sum.hexdigest()
117
118 def _read_in_chunks(self, infile, chunk_size=1024 * 64):
119 file_data = open(infile, "rb")
120 while True:
121 # chunk = file_data.read(chunk_size).encode('base64')
122 chunk = file_data.read(chunk_size)
123 if chunk:
124 yield chunk
125 else:
126 return
127 file_data.close()
128
129 def _parse_defaults_file(self):
130 cfg = os.path.abspath(os.path.join(os.path.dirname(__file__),
Soren Hansenec3f7092011-09-08 13:03:42 +0200131 os.path.pardir, os.path.pardir,
132 "etc", "config.ini"))
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500133 if os.path.exists(cfg):
134 self._build_config(cfg)
135 else:
136 raise Exception("Cannot read %s" % cfg)
137
138 def _build_config(self, config_file):
139 parser = ConfigParser.ConfigParser()
140 parser.read(config_file)
141
142 for section in parser.sections():
143 self.config[section] = {}
144 for value in parser.options(section):
145 self.config[section][value] = parser.get(section, value)
146 # print "%s = %s" % (value, parser.get(section, value))