blob: 8db7896057aa21919839daea44984a6875cee12a [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
24from xmlrpclib import Server
25
26NOVA_DATA = {}
27GLANCE_DATA = {}
28SWIFT_DATA = {}
29RABBITMQ_DATA = {}
30CONFIG_DATA = {}
31KEYSTONE_DATA = {}
32
33class 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):
83 global GLANCE_DATA, NOVA_DATA, SWIFT_DATA, RABBITMQ_DATA, KEYSTONE_DATA, CONFIG_DATA
84 # 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 Shepherd66c861a2011-08-18 11:02:53 -050094 pprint(self.config)
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050095
96 # Swift Setup
97 if 'swift' in self.config:
98 self.swift['auth_host'] = self.config['swift']['auth_host']
99 self.swift['auth_port'] = self.config['swift']['auth_port']
100 self.swift['auth_prefix'] = self.config['swift']['auth_prefix']
101 self.swift['auth_ssl'] = self.config['swift']['auth_ssl']
102 self.swift['account'] = self.config['swift']['account']
103 self.swift['username'] = self.config['swift']['username']
104 self.swift['password'] = self.config['swift']['password']
105 self.swift['ver'] = 'v1.0' # need to find a better way to get this.
106
107 # Glance Setup
108 self.glance['host'] = self.config['glance']['host']
109 self.glance['port'] = self.config['glance']['port']
110 if 'apiver' in self.config['glance']:
111 self.glance['apiver'] = self.config['glance']['apiver']
112
113 if 'nova' in self.config:
114 self.nova['host'] = self.config['nova']['host']
115 self.nova['port'] = self.config['nova']['port']
116 self.nova['ver'] = self.config['nova']['apiver']
117 self.nova['user'] = self.config['nova']['user']
118 self.nova['key'] = self.config['nova']['key']
119
120 if 'keystone' in self.config:
121 self.keystone['host'] = self.config['keystone']['host']
122 self.keystone['port'] = self.config['keystone']['port']
123 self.keystone['apiver'] = self.config['keystone']['apiver']
124 self.keystone['user'] = self.config['keystone']['user']
125 self.keystone['pass'] = self.config['keystone']['password']
126
127 def _md5sum_file(self, path):
128 md5sum = md5()
129 with open(path, 'rb') as file:
130 for chunk in iter(lambda: file.read(8192), ''):
131 md5sum.update(chunk)
132 return md5sum.hexdigest()
133
134 def _read_in_chunks(self, infile, chunk_size=1024 * 64):
135 file_data = open(infile, "rb")
136 while True:
137 # chunk = file_data.read(chunk_size).encode('base64')
138 chunk = file_data.read(chunk_size)
139 if chunk:
140 yield chunk
141 else:
142 return
143 file_data.close()
144
145 def _parse_defaults_file(self):
146 cfg = os.path.abspath(os.path.join(os.path.dirname(__file__),
147 "..", "etc", "config.ini"))
148 if os.path.exists(cfg):
149 self._build_config(cfg)
150 else:
151 raise Exception("Cannot read %s" % cfg)
152
153 def _build_config(self, config_file):
154 parser = ConfigParser.ConfigParser()
155 parser.read(config_file)
156
157 for section in parser.sections():
158 self.config[section] = {}
159 for value in parser.options(section):
160 self.config[section][value] = parser.get(section, value)
161 # print "%s = %s" % (value, parser.get(section, value))