Merge lp:~vishvananda/nova/keystone-migration into lp:~hudson-openstack/nova/trunk
- keystone-migration
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Vish Ishaya |
Approved revision: | 1320 |
Merged at revision: | 1348 |
Proposed branch: | lp:~vishvananda/nova/keystone-migration |
Merge into: | lp:~hudson-openstack/nova/trunk |
Diff against target: |
3614 lines (+475/-808) 51 files modified
nova/api/direct.py (+2/-1) nova/api/ec2/__init__.py (+17/-15) nova/api/openstack/auth.py (+16/-12) nova/api/openstack/create_instance_helper.py (+5/-2) nova/api/openstack/views/servers.py (+2/-12) nova/auth/manager.py (+9/-5) nova/cloudpipe/pipelib.py (+9/-9) nova/compute/api.py (+1/-1) nova/context.py (+27/-63) nova/db/sqlalchemy/api.py (+2/-2) nova/db/sqlalchemy/models.py (+0/-16) nova/image/s3.py (+8/-6) nova/log.py (+2/-2) nova/tests/api/openstack/contrib/test_floating_ips.py (+0/-5) nova/tests/api/openstack/contrib/test_multinic_xs.py (+0/-8) nova/tests/api/openstack/fakes.py (+27/-17) nova/tests/api/openstack/test_accounts.py (+1/-9) nova/tests/api/openstack/test_adminapi.py (+2/-15) nova/tests/api/openstack/test_auth.py (+18/-24) nova/tests/api/openstack/test_extensions.py (+23/-23) nova/tests/api/openstack/test_flavors.py (+0/-5) nova/tests/api/openstack/test_flavors_extra_specs.py (+24/-42) nova/tests/api/openstack/test_image_metadata.py (+1/-13) nova/tests/api/openstack/test_images.py (+12/-15) nova/tests/api/openstack/test_server_metadata.py (+2/-12) nova/tests/api/openstack/test_servers.py (+24/-42) nova/tests/api/openstack/test_shared_ip_groups.py (+0/-13) nova/tests/api/openstack/test_users.py (+1/-8) nova/tests/api/openstack/test_zones.py (+5/-20) nova/tests/hyperv_unittest.py (+3/-6) nova/tests/scheduler/test_scheduler.py (+4/-13) nova/tests/test_access.py (+10/-11) nova/tests/test_adminapi.py (+5/-11) nova/tests/test_api.py (+8/-68) nova/tests/test_auth.py (+9/-10) nova/tests/test_cloud.py (+10/-14) nova/tests/test_compute.py (+13/-24) nova/tests/test_console.py (+6/-13) nova/tests/test_db_api.py (+13/-21) nova/tests/test_libvirt.py (+13/-50) nova/tests/test_objectstore.py (+7/-20) nova/tests/test_quota.py (+27/-35) nova/tests/test_vmwareapi.py (+6/-9) nova/tests/test_xenapi.py (+41/-40) nova/utils.py (+16/-7) nova/virt/hyperv.py (+2/-4) nova/virt/images.py (+1/-1) nova/virt/libvirt/connection.py (+8/-11) nova/virt/xenapi/vm_utils.py (+15/-12) nova/virt/xenapi/vmops.py (+6/-11) nova/wsgi.py (+12/-0) |
To merge this branch: | bzr merge lp:~vishvananda/nova/keystone-migration |
Related bugs: | |
Related blueprints: |
Finalize Auth integration
(Essential)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brian Lamar (community) | Approve | ||
Jason Kölker (community) | Approve | ||
Devin Carlen (community) | Approve | ||
Review via email: mp+68915@code.launchpad.net |
Commit message
Description of the change
Round 1 of changes for keystone integration.
* Modified request context to allow it to hold all of the relevant data from the auth component.
* Pulled out access to AuthManager from as many places as possible
* Massive cleanup of unit tests
* Made the openstack api fakes use fake Authentication by default
There are now only a few places that are using auth manager:
* Authentication middleware for ec2 api (will move to stand-alone middleware)
* Authentication middleware for os api (will be deprecated in favor of keystone)
* Accounts and Users apis for os (will be switched to keystone or deprecated)
* Ec2 admin api for users and projects (will be removed)
* Nova-manage user and project commands (will be deprecated and removed with AuthManager)
* Tests that test the above sections (will be converted or removed with their relevant section)
* Tests for auth manager
* Pipelib (authman can be removed once ec2 stand-alone middleware is in place)
* xen_api (for getting images from old objectstore. I think this can be removed)
Vish
Vish Ishaya (vishvananda) wrote : | # |
> I have a question about keystone and openstack in terms of semantics. Is
> there any value in making the terms across keystone/nova/swift consistent?
> Keystone has tenants, Nova has projects, and Swift has accounts. Gets a bit
> confusing.
If you look at the linked blueprint you will see that renaming projects to tenants is one of the later steps. I agree that naming should be consistent, but I'm trying to keep it a series of smaller patches.
>
> I understand why the following change was made, though it seems like the key
> pair bits need a new place to live. Doesn't seem ideal to call the DB directly
> here:
>
>
> 205 - key_pairs = auth_manager.
> 206 + key_pairs = db.key_
> 207 + context.user_id)
>
Agreeed. Key pairs don't really fit into any of the current apis we have defined. Neither do the private keys and cas used by the ec2 api and cloudpipe. We could probably move all of that into a crypto api, but that seems outside the scope of this change set. I added a todo in the code for now.
>
>
> I don't think you meant to leave this in:
>
> 305 + LOG.info(locals())
Thanks, fixed.
- 1313. By Vish Ishaya
-
fix for reviews
- 1314. By Vish Ishaya
-
merged trunk
- 1315. By Vish Ishaya
-
fix tests broken in the merge
- 1316. By Vish Ishaya
-
remove authman from images/s3.py and replace with flags
Jason Kölker (jason-koelker) wrote : | # |
356 + if self.is_admin is None:
357 + if 'admin' in self.roles:
358 + self.is_admin = True
359 else:
360 self.is_admin = False
Could this be something like:
if not self.is_admin:
self.is_admin = 'admin' in self.roles
That way if is_admin is passed in as False but the roles specify admin you get an admin context. Or is there a situation were and admin role should not force an admin context?
3465 + # TODO(vish): this shouldn't be used anywhere anymore and
3466 + # can probably be removed
3467 + from nova.auth.manager import AuthManager
3468 + manager = AuthManager()
3469 + access = manager.
3470 + secret = manager.
Could this just not use the s3_* flags as well?
Vish Ishaya (vishvananda) wrote : | # |
> if not self.is_admin:
> self.is_admin = 'admin' in self.roles
>
> That way if is_admin is passed in as False but the roles specify admin you get
> an admin context. Or is there a situation were and admin role should not force
> an admin context?
I was thinking that the direct passing of is_admin should override what is set in roles
>
>
> 3465 + # TODO(vish): this shouldn't be used anywhere anymore and
> 3466 + # can probably be removed
> 3467 + from nova.auth.manager import AuthManager
> 3468 + manager = AuthManager()
> 3469 + access = manager.
> 3470 + secret = manager.
>
> Could this just not use the s3_* flags as well?
Anyone who is using this code would be using the old nova-objectstore which actually did check secret and access key per user. This should really be removed but I want to make sure from the xen guys that they aren't using for something i don't know about.
Vish Ishaya (vishvananda) wrote : | # |
> Could this be something like:
>
> if not self.is_admin:
> self.is_admin = 'admin' in self.roles
I did switch it to your simpler logic however.
- 1317. By Vish Ishaya
-
simplify if statement
Jason Kölker (jason-koelker) wrote : | # |
> > 3465 + # TODO(vish): this shouldn't be used anywhere anymore
> and
> > 3466 + # can probably be removed
> > 3467 + from nova.auth.manager import AuthManager
> > 3468 + manager = AuthManager()
> > 3469 + access = manager.
> > 3470 + secret = manager.
> >
> > Could this just not use the s3_* flags as well?
>
> Anyone who is using this code would be using the old nova-objectstore which
> actually did check secret and access key per user. This should really be
> removed but I want to make sure from the xen guys that they aren't using for
> something i don't know about.
Cools, I tracked it back through the xen plugin, and couldn't see an issue, but I think you're right to leave it as is for now, I'm far from an expert on how that all works.
Kevin L. Mitchell (klmitch) wrote : | # |
While comparing our respective branches, I ran across another LOG.info() you probably didn't mean to leave in, in nova/compute/api.py on line 692...
- 1318. By Vish Ishaya
-
remove extra log statement
Brian Lamar (blamar) wrote : | # |
There are a number of tests failing when merging with the current trunk, but they can be fixed by:
=== modified file 'nova/api/
--- nova/api/
+++ nova/api/
@@ -231,4 +231,4 @@
:param date_time: the datetime object to convert
"""
- return date_time.
+ return date_time.
After all tests pass, everything looks good to me. I've tested this functionally and all current tests pass.
Vish Ishaya (vishvananda) wrote : | # |
Ok fixed by changing the call to use utils.isotime() which did the same thing.
On Jul 29, 2011, at 9:07 AM, Brian Lamar wrote:
> Review: Needs Fixing
> There are a number of tests failing when merging with the current trunk, but they can be fixed by:
>
> === modified file 'nova/api/
> --- nova/api/
> +++ nova/api/
> @@ -231,4 +231,4 @@
> :param date_time: the datetime object to convert
>
> """
> - return date_time.
> + return date_time.
>
> After all tests pass, everything looks good to me. I've tested this functionally and all current tests pass.
> --
> https:/
> You are the owner of lp:~vishvananda/nova/keystone-migration.
- 1319. By Vish Ishaya
-
merged trunk and fix time call
Brian Lamar (blamar) wrote : | # |
Albeit with some delay, but I think we can get this pushed in now. Thanks Vish!
OpenStack Infra (hudson-openstack) wrote : | # |
Attempt to merge into lp:nova failed due to conflicts:
text conflict in nova/tests/
Vish Ishaya (vishvananda) wrote : | # |
wow, code is moving fast. Remerged trunk. Trying again
- 1320. By Vish Ishaya
-
merged trunk
Preview Diff
1 | === modified file 'nova/api/direct.py' |
2 | --- nova/api/direct.py 2011-06-07 19:17:34 +0000 |
3 | +++ nova/api/direct.py 2011-07-29 19:38:29 +0000 |
4 | @@ -107,7 +107,8 @@ |
5 | def process_request(self, request): |
6 | os_user = request.headers['X-OpenStack-User'] |
7 | os_project = request.headers['X-OpenStack-Project'] |
8 | - context_ref = context.RequestContext(user=os_user, project=os_project) |
9 | + context_ref = context.RequestContext(user_id=os_user, |
10 | + project_id=os_project) |
11 | request.environ['openstack.context'] = context_ref |
12 | |
13 | |
14 | |
15 | === modified file 'nova/api/ec2/__init__.py' |
16 | --- nova/api/ec2/__init__.py 2011-06-27 11:20:42 +0000 |
17 | +++ nova/api/ec2/__init__.py 2011-07-29 19:38:29 +0000 |
18 | @@ -66,7 +66,7 @@ |
19 | else: |
20 | controller = None |
21 | action = None |
22 | - ctxt = request.environ.get('ec2.context', None) |
23 | + ctxt = request.environ.get('nova.context', None) |
24 | delta = utils.utcnow() - start |
25 | seconds = delta.seconds |
26 | microseconds = delta.microseconds |
27 | @@ -139,8 +139,7 @@ |
28 | |
29 | |
30 | class Authenticate(wsgi.Middleware): |
31 | - |
32 | - """Authenticate an EC2 request and add 'ec2.context' to WSGI environ.""" |
33 | + """Authenticate an EC2 request and add 'nova.context' to WSGI environ.""" |
34 | |
35 | @webob.dec.wsgify(RequestClass=wsgi.Request) |
36 | def __call__(self, req): |
37 | @@ -157,8 +156,9 @@ |
38 | auth_params.pop('Signature') |
39 | |
40 | # Authenticate the request. |
41 | + authman = manager.AuthManager() |
42 | try: |
43 | - (user, project) = manager.AuthManager().authenticate( |
44 | + (user, project) = authman.authenticate( |
45 | access, |
46 | signature, |
47 | auth_params, |
48 | @@ -174,14 +174,17 @@ |
49 | remote_address = req.remote_addr |
50 | if FLAGS.use_forwarded_for: |
51 | remote_address = req.headers.get('X-Forwarded-For', remote_address) |
52 | - ctxt = context.RequestContext(user=user, |
53 | - project=project, |
54 | + roles = authman.get_active_roles(user, project) |
55 | + ctxt = context.RequestContext(user_id=user.id, |
56 | + project_id=project.id, |
57 | + is_admin=user.is_admin(), |
58 | + roles=roles, |
59 | remote_address=remote_address) |
60 | - req.environ['ec2.context'] = ctxt |
61 | + req.environ['nova.context'] = ctxt |
62 | uname = user.name |
63 | pname = project.name |
64 | msg = _('Authenticated Request For %(uname)s:%(pname)s)') % locals() |
65 | - LOG.audit(msg, context=req.environ['ec2.context']) |
66 | + LOG.audit(msg, context=req.environ['nova.context']) |
67 | return self.application |
68 | |
69 | |
70 | @@ -228,7 +231,7 @@ |
71 | """Authorize an EC2 API request. |
72 | |
73 | Return a 401 if ec2.controller and ec2.action in WSGI environ may not be |
74 | - executed in ec2.context. |
75 | + executed in nova.context. |
76 | """ |
77 | |
78 | def __init__(self, application): |
79 | @@ -282,7 +285,7 @@ |
80 | |
81 | @webob.dec.wsgify(RequestClass=wsgi.Request) |
82 | def __call__(self, req): |
83 | - context = req.environ['ec2.context'] |
84 | + context = req.environ['nova.context'] |
85 | controller = req.environ['ec2.request'].controller.__class__.__name__ |
86 | action = req.environ['ec2.request'].action |
87 | allowed_roles = self.action_roles[controller].get(action, ['none']) |
88 | @@ -295,28 +298,27 @@ |
89 | |
90 | def _matches_any_role(self, context, roles): |
91 | """Return True if any role in roles is allowed in context.""" |
92 | - if context.user.is_superuser(): |
93 | + if context.is_admin: |
94 | return True |
95 | if 'all' in roles: |
96 | return True |
97 | if 'none' in roles: |
98 | return False |
99 | - return any(context.project.has_role(context.user_id, role) |
100 | - for role in roles) |
101 | + return any(role in context.roles for role in roles) |
102 | |
103 | |
104 | class Executor(wsgi.Application): |
105 | |
106 | """Execute an EC2 API request. |
107 | |
108 | - Executes 'ec2.action' upon 'ec2.controller', passing 'ec2.context' and |
109 | + Executes 'ec2.action' upon 'ec2.controller', passing 'nova.context' and |
110 | 'ec2.action_args' (all variables in WSGI environ.) Returns an XML |
111 | response, or a 400 upon failure. |
112 | """ |
113 | |
114 | @webob.dec.wsgify(RequestClass=wsgi.Request) |
115 | def __call__(self, req): |
116 | - context = req.environ['ec2.context'] |
117 | + context = req.environ['nova.context'] |
118 | api_request = req.environ['ec2.request'] |
119 | result = None |
120 | try: |
121 | |
122 | === modified file 'nova/api/openstack/auth.py' |
123 | --- nova/api/openstack/auth.py 2011-07-01 20:33:00 +0000 |
124 | +++ nova/api/openstack/auth.py 2011-07-29 19:38:29 +0000 |
125 | @@ -48,31 +48,35 @@ |
126 | def __call__(self, req): |
127 | if not self.has_authentication(req): |
128 | return self.authenticate(req) |
129 | - user = self.get_user_by_authentication(req) |
130 | - if not user: |
131 | + user_id = self.get_user_by_authentication(req) |
132 | + if not user_id: |
133 | token = req.headers["X-Auth-Token"] |
134 | - msg = _("%(user)s could not be found with token '%(token)s'") |
135 | + msg = _("%(user_id)s could not be found with token '%(token)s'") |
136 | LOG.warn(msg % locals()) |
137 | return faults.Fault(webob.exc.HTTPUnauthorized()) |
138 | |
139 | try: |
140 | - account = req.headers["X-Auth-Project-Id"] |
141 | + project_id = req.headers["X-Auth-Project-Id"] |
142 | except KeyError: |
143 | # FIXME(usrleon): It needed only for compatibility |
144 | # while osapi clients don't use this header |
145 | - accounts = self.auth.get_projects(user=user) |
146 | - if accounts: |
147 | - account = accounts[0] |
148 | + projects = self.auth.get_projects(user_id) |
149 | + if projects: |
150 | + project_id = projects[0].id |
151 | else: |
152 | return faults.Fault(webob.exc.HTTPUnauthorized()) |
153 | |
154 | - if not self.auth.is_admin(user) and \ |
155 | - not self.auth.is_project_member(user, account): |
156 | - msg = _("%(user)s must be an admin or a member of %(account)s") |
157 | + is_admin = self.auth.is_admin(user_id) |
158 | + req.environ['nova.context'] = context.RequestContext(user_id, |
159 | + project_id, |
160 | + is_admin) |
161 | + if not is_admin and not self.auth.is_project_member(user_id, |
162 | + project_id): |
163 | + msg = _("%(user_id)s must be an admin or a " |
164 | + "member of %(project_id)s") |
165 | LOG.warn(msg % locals()) |
166 | return faults.Fault(webob.exc.HTTPUnauthorized()) |
167 | |
168 | - req.environ['nova.context'] = context.RequestContext(user, account) |
169 | return self.application |
170 | |
171 | def has_authentication(self, req): |
172 | @@ -133,7 +137,7 @@ |
173 | if delta.days >= 2: |
174 | self.db.auth_token_destroy(ctxt, token['token_hash']) |
175 | else: |
176 | - return self.auth.get_user(token['user_id']) |
177 | + return token['user_id'] |
178 | return None |
179 | |
180 | def _authorize_user(self, username, key, req): |
181 | |
182 | === modified file 'nova/api/openstack/create_instance_helper.py' |
183 | --- nova/api/openstack/create_instance_helper.py 2011-07-26 17:47:37 +0000 |
184 | +++ nova/api/openstack/create_instance_helper.py 2011-07-29 19:38:29 +0000 |
185 | @@ -20,6 +20,7 @@ |
186 | from webob import exc |
187 | from xml.dom import minidom |
188 | |
189 | +from nova import db |
190 | from nova import exception |
191 | from nova import flags |
192 | from nova import log as logging |
193 | @@ -29,7 +30,6 @@ |
194 | |
195 | from nova.compute import instance_types |
196 | from nova.api.openstack import wsgi |
197 | -from nova.auth import manager as auth_manager |
198 | |
199 | |
200 | LOG = logging.getLogger('nova.api.openstack.create_instance_helper') |
201 | @@ -80,7 +80,10 @@ |
202 | |
203 | key_name = None |
204 | key_data = None |
205 | - key_pairs = auth_manager.AuthManager.get_key_pairs(context) |
206 | + # TODO(vish): Key pair access should move into a common library |
207 | + # instead of being accessed directly from the db. |
208 | + key_pairs = db.key_pair_get_all_by_user(context.elevated(), |
209 | + context.user_id) |
210 | if key_pairs: |
211 | key_pair = key_pairs[0] |
212 | key_name = key_pair['name'] |
213 | |
214 | === modified file 'nova/api/openstack/views/servers.py' |
215 | --- nova/api/openstack/views/servers.py 2011-07-28 21:59:25 +0000 |
216 | +++ nova/api/openstack/views/servers.py 2011-07-29 19:38:29 +0000 |
217 | @@ -150,10 +150,8 @@ |
218 | |
219 | def _build_detail(self, inst): |
220 | response = super(ViewBuilderV11, self)._build_detail(inst) |
221 | - response['server']['created'] = \ |
222 | - self._convert_timeformat(inst['created_at']) |
223 | - response['server']['updated'] = \ |
224 | - self._convert_timeformat(inst['updated_at']) |
225 | + response['server']['created'] = utils.isotime(inst['created_at']) |
226 | + response['server']['updated'] = utils.isotime(inst['updated_at']) |
227 | if 'status' in response['server']: |
228 | if response['server']['status'] == "ACTIVE": |
229 | response['server']['progress'] = 100 |
230 | @@ -224,11 +222,3 @@ |
231 | """Create an url that refers to a specific flavor id.""" |
232 | return os.path.join(common.remove_version_from_href(self.base_url), |
233 | "servers", str(server_id)) |
234 | - |
235 | - def _convert_timeformat(self, date_time): |
236 | - """Converts the given time into the common time format |
237 | - |
238 | - :param date_time: the datetime object to convert |
239 | - |
240 | - """ |
241 | - return date_time.strftime(utils.TIME_FORMAT) |
242 | |
243 | === modified file 'nova/auth/manager.py' |
244 | --- nova/auth/manager.py 2011-06-03 18:34:54 +0000 |
245 | +++ nova/auth/manager.py 2011-07-29 19:38:29 +0000 |
246 | @@ -518,6 +518,14 @@ |
247 | return drv.get_user_roles(User.safe_id(user), |
248 | Project.safe_id(project)) |
249 | |
250 | + def get_active_roles(self, user, project=None): |
251 | + """Get all active roles for context""" |
252 | + if project: |
253 | + roles = FLAGS.allowed_roles + ['projectmanager'] |
254 | + else: |
255 | + roles = FLAGS.global_roles |
256 | + return [role for role in roles if self.has_role(user, role, project)] |
257 | + |
258 | def get_project(self, pid): |
259 | """Get project object by id""" |
260 | with self.driver() as drv: |
261 | @@ -730,10 +738,6 @@ |
262 | with self.driver() as drv: |
263 | drv.modify_user(uid, access_key, secret_key, admin) |
264 | |
265 | - @staticmethod |
266 | - def get_key_pairs(context): |
267 | - return db.key_pair_get_all_by_user(context.elevated(), context.user_id) |
268 | - |
269 | def get_credentials(self, user, project=None, use_dmz=True): |
270 | """Get credential zip for user in project""" |
271 | if not isinstance(user, User): |
272 | @@ -785,7 +789,7 @@ |
273 | return read_buffer |
274 | |
275 | def get_environment_rc(self, user, project=None, use_dmz=True): |
276 | - """Get credential zip for user in project""" |
277 | + """Get environment rc for user in project""" |
278 | if not isinstance(user, User): |
279 | user = self.get_user(user) |
280 | if project is None: |
281 | |
282 | === modified file 'nova/cloudpipe/pipelib.py' |
283 | --- nova/cloudpipe/pipelib.py 2011-04-19 16:32:33 +0000 |
284 | +++ nova/cloudpipe/pipelib.py 2011-07-29 19:38:29 +0000 |
285 | @@ -96,8 +96,8 @@ |
286 | def launch_vpn_instance(self, project_id): |
287 | LOG.debug(_("Launching VPN for %s") % (project_id)) |
288 | project = self.manager.get_project(project_id) |
289 | - ctxt = context.RequestContext(user=project.project_manager, |
290 | - project=project) |
291 | + ctxt = context.RequestContext(user=project.project_manager_id, |
292 | + project=project.id) |
293 | key_name = self.setup_key_pair(ctxt) |
294 | group_name = self.setup_security_group(ctxt) |
295 | |
296 | @@ -112,11 +112,11 @@ |
297 | security_group=[group_name]) |
298 | |
299 | def setup_security_group(self, context): |
300 | - group_name = '%s%s' % (context.project.id, FLAGS.vpn_key_suffix) |
301 | - if db.security_group_exists(context, context.project.id, group_name): |
302 | + group_name = '%s%s' % (context.project_id, FLAGS.vpn_key_suffix) |
303 | + if db.security_group_exists(context, context.project_id, group_name): |
304 | return group_name |
305 | - group = {'user_id': context.user.id, |
306 | - 'project_id': context.project.id, |
307 | + group = {'user_id': context.user_id, |
308 | + 'project_id': context.project_id, |
309 | 'name': group_name, |
310 | 'description': 'Group for vpn'} |
311 | group_ref = db.security_group_create(context, group) |
312 | @@ -137,12 +137,12 @@ |
313 | return group_name |
314 | |
315 | def setup_key_pair(self, context): |
316 | - key_name = '%s%s' % (context.project.id, FLAGS.vpn_key_suffix) |
317 | + key_name = '%s%s' % (context.project_id, FLAGS.vpn_key_suffix) |
318 | try: |
319 | - result = cloud._gen_key(context, context.user.id, key_name) |
320 | + result = cloud._gen_key(context, context.user_id, key_name) |
321 | private_key = result['private_key'] |
322 | try: |
323 | - key_dir = os.path.join(FLAGS.keys_path, context.user.id) |
324 | + key_dir = os.path.join(FLAGS.keys_path, context.user_id) |
325 | if not os.path.exists(key_dir): |
326 | os.makedirs(key_dir) |
327 | key_path = os.path.join(key_dir, '%s.pem' % key_name) |
328 | |
329 | === modified file 'nova/compute/api.py' |
330 | --- nova/compute/api.py 2011-07-26 17:13:41 +0000 |
331 | +++ nova/compute/api.py 2011-07-29 19:38:29 +0000 |
332 | @@ -689,7 +689,7 @@ |
333 | raise |
334 | instances = None |
335 | elif project_id or not context.is_admin: |
336 | - if not context.project: |
337 | + if not context.project_id: |
338 | instances = self.db.instance_get_all_by_user( |
339 | context, context.user_id) |
340 | else: |
341 | |
342 | === modified file 'nova/context.py' |
343 | --- nova/context.py 2011-06-02 21:23:05 +0000 |
344 | +++ nova/context.py 2011-07-29 19:38:29 +0000 |
345 | @@ -18,9 +18,8 @@ |
346 | |
347 | """RequestContext: context for requests that persist through all of nova.""" |
348 | |
349 | -import random |
350 | +import uuid |
351 | |
352 | -from nova import exception |
353 | from nova import utils |
354 | |
355 | |
356 | @@ -31,86 +30,51 @@ |
357 | |
358 | """ |
359 | |
360 | - def __init__(self, user, project, is_admin=None, read_deleted=False, |
361 | - remote_address=None, timestamp=None, request_id=None): |
362 | - if hasattr(user, 'id'): |
363 | - self._user = user |
364 | - self.user_id = user.id |
365 | - else: |
366 | - self._user = None |
367 | - self.user_id = user |
368 | - if hasattr(project, 'id'): |
369 | - self._project = project |
370 | - self.project_id = project.id |
371 | - else: |
372 | - self._project = None |
373 | - self.project_id = project |
374 | - if is_admin is None: |
375 | - if self.user_id and self.user: |
376 | - self.is_admin = self.user.is_admin() |
377 | - else: |
378 | - self.is_admin = False |
379 | - else: |
380 | - self.is_admin = is_admin |
381 | + def __init__(self, user_id, project_id, is_admin=None, read_deleted=False, |
382 | + roles=None, remote_address=None, timestamp=None, |
383 | + request_id=None): |
384 | + self.user_id = user_id |
385 | + self.project_id = project_id |
386 | + self.roles = roles or [] |
387 | + self.is_admin = is_admin |
388 | + if self.is_admin is None: |
389 | + self.admin = 'admin' in self.roles |
390 | self.read_deleted = read_deleted |
391 | self.remote_address = remote_address |
392 | if not timestamp: |
393 | timestamp = utils.utcnow() |
394 | - if isinstance(timestamp, str) or isinstance(timestamp, unicode): |
395 | - timestamp = utils.parse_isotime(timestamp) |
396 | + if isinstance(timestamp, basestring): |
397 | + timestamp = utils.parse_strtime(timestamp) |
398 | self.timestamp = timestamp |
399 | if not request_id: |
400 | - chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-' |
401 | - request_id = ''.join([random.choice(chars) for x in xrange(20)]) |
402 | + request_id = unicode(uuid.uuid4()) |
403 | self.request_id = request_id |
404 | |
405 | - @property |
406 | - def user(self): |
407 | - # NOTE(vish): Delay import of manager, so that we can import this |
408 | - # file from manager. |
409 | - from nova.auth import manager |
410 | - if not self._user: |
411 | - try: |
412 | - self._user = manager.AuthManager().get_user(self.user_id) |
413 | - except exception.NotFound: |
414 | - pass |
415 | - return self._user |
416 | - |
417 | - @property |
418 | - def project(self): |
419 | - # NOTE(vish): Delay import of manager, so that we can import this |
420 | - # file from manager. |
421 | - from nova.auth import manager |
422 | - if not self._project: |
423 | - try: |
424 | - auth_manager = manager.AuthManager() |
425 | - self._project = auth_manager.get_project(self.project_id) |
426 | - except exception.NotFound: |
427 | - pass |
428 | - return self._project |
429 | - |
430 | def to_dict(self): |
431 | - return {'user': self.user_id, |
432 | - 'project': self.project_id, |
433 | + return {'user_id': self.user_id, |
434 | + 'project_id': self.project_id, |
435 | 'is_admin': self.is_admin, |
436 | 'read_deleted': self.read_deleted, |
437 | + 'roles': self.roles, |
438 | 'remote_address': self.remote_address, |
439 | - 'timestamp': utils.isotime(self.timestamp), |
440 | + 'timestamp': utils.strtime(self.timestamp), |
441 | 'request_id': self.request_id} |
442 | |
443 | @classmethod |
444 | def from_dict(cls, values): |
445 | return cls(**values) |
446 | |
447 | - def elevated(self, read_deleted=False): |
448 | + def elevated(self, read_deleted=None): |
449 | """Return a version of this context with admin flag set.""" |
450 | - return RequestContext(self.user_id, |
451 | - self.project_id, |
452 | - True, |
453 | - read_deleted, |
454 | - self.remote_address, |
455 | - self.timestamp, |
456 | - self.request_id) |
457 | + rd = self.read_deleted if read_deleted is None else read_deleted |
458 | + return RequestContext(user_id=self.user_id, |
459 | + project_id=self.project_id, |
460 | + is_admin=True, |
461 | + read_deleted=rd, |
462 | + roles=self.roles, |
463 | + remote_address=self.remote_address, |
464 | + timestamp=self.timestamp, |
465 | + request_id=self.request_id) |
466 | |
467 | |
468 | def get_admin_context(read_deleted=False): |
469 | |
470 | === modified file 'nova/db/sqlalchemy/api.py' |
471 | --- nova/db/sqlalchemy/api.py 2011-07-26 17:03:55 +0000 |
472 | +++ nova/db/sqlalchemy/api.py 2011-07-29 19:38:29 +0000 |
473 | @@ -62,7 +62,7 @@ |
474 | def authorize_project_context(context, project_id): |
475 | """Ensures a request has permission to access the given project.""" |
476 | if is_user_context(context): |
477 | - if not context.project: |
478 | + if not context.project_id: |
479 | raise exception.NotAuthorized() |
480 | elif context.project_id != project_id: |
481 | raise exception.NotAuthorized() |
482 | @@ -71,7 +71,7 @@ |
483 | def authorize_user_context(context, user_id): |
484 | """Ensures a request has permission to access the given user.""" |
485 | if is_user_context(context): |
486 | - if not context.user: |
487 | + if not context.user_id: |
488 | raise exception.NotAuthorized() |
489 | elif context.user_id != user_id: |
490 | raise exception.NotAuthorized() |
491 | |
492 | === modified file 'nova/db/sqlalchemy/models.py' |
493 | --- nova/db/sqlalchemy/models.py 2011-07-22 21:47:37 +0000 |
494 | +++ nova/db/sqlalchemy/models.py 2011-07-29 19:38:29 +0000 |
495 | @@ -177,14 +177,6 @@ |
496 | user_id = Column(String(255)) |
497 | project_id = Column(String(255)) |
498 | |
499 | - @property |
500 | - def user(self): |
501 | - return auth.manager.AuthManager().get_user(self.user_id) |
502 | - |
503 | - @property |
504 | - def project(self): |
505 | - return auth.manager.AuthManager().get_project(self.project_id) |
506 | - |
507 | image_ref = Column(String(255)) |
508 | kernel_id = Column(String(255)) |
509 | ramdisk_id = Column(String(255)) |
510 | @@ -465,14 +457,6 @@ |
511 | 'Instance.deleted == False)', |
512 | backref='security_groups') |
513 | |
514 | - @property |
515 | - def user(self): |
516 | - return auth.manager.AuthManager().get_user(self.user_id) |
517 | - |
518 | - @property |
519 | - def project(self): |
520 | - return auth.manager.AuthManager().get_project(self.project_id) |
521 | - |
522 | |
523 | class SecurityGroupIngressRule(BASE, NovaBase): |
524 | """Represents a rule in a security group.""" |
525 | |
526 | === modified file 'nova/image/s3.py' |
527 | --- nova/image/s3.py 2011-07-20 17:45:55 +0000 |
528 | +++ nova/image/s3.py 2011-07-29 19:38:29 +0000 |
529 | @@ -34,7 +34,6 @@ |
530 | from nova import image |
531 | from nova import log as logging |
532 | from nova import utils |
533 | -from nova.auth import manager |
534 | from nova.image import service |
535 | from nova.api.ec2 import ec2utils |
536 | |
537 | @@ -43,6 +42,10 @@ |
538 | FLAGS = flags.FLAGS |
539 | flags.DEFINE_string('image_decryption_dir', '/tmp', |
540 | 'parent dir for tempdir used for image decryption') |
541 | +flags.DEFINE_string('s3_access_key', 'notchecked', |
542 | + 'access key to use for s3 server for images') |
543 | +flags.DEFINE_string('s3_secret_key', 'notchecked', |
544 | + 'secret key to use for s3 server for images') |
545 | |
546 | |
547 | class S3ImageService(service.BaseImageService): |
548 | @@ -82,11 +85,10 @@ |
549 | |
550 | @staticmethod |
551 | def _conn(context): |
552 | - # TODO(vish): is there a better way to get creds to sign |
553 | - # for the user? |
554 | - access = manager.AuthManager().get_access_key(context.user, |
555 | - context.project) |
556 | - secret = str(context.user.secret) |
557 | + # NOTE(vish): access and secret keys for s3 server are not |
558 | + # checked in nova-objectstore |
559 | + access = FLAGS.s3_access_key |
560 | + secret = FLAGS.s3_secret_key |
561 | calling = boto.s3.connection.OrdinaryCallingFormat() |
562 | return boto.s3.connection.S3Connection(aws_access_key_id=access, |
563 | aws_secret_access_key=secret, |
564 | |
565 | === modified file 'nova/log.py' |
566 | --- nova/log.py 2011-07-27 18:00:37 +0000 |
567 | +++ nova/log.py 2011-07-29 19:38:29 +0000 |
568 | @@ -43,8 +43,8 @@ |
569 | FLAGS = flags.FLAGS |
570 | flags.DEFINE_string('logging_context_format_string', |
571 | '%(asctime)s %(levelname)s %(name)s ' |
572 | - '[%(request_id)s %(user)s ' |
573 | - '%(project)s] %(message)s', |
574 | + '[%(request_id)s %(user_id)s ' |
575 | + '%(project_id)s] %(message)s', |
576 | 'format string to use for log messages with context') |
577 | flags.DEFINE_string('logging_default_format_string', |
578 | '%(asctime)s %(levelname)s %(name)s [-] ' |
579 | |
580 | === modified file 'nova/tests/api/openstack/contrib/test_floating_ips.py' |
581 | --- nova/tests/api/openstack/contrib/test_floating_ips.py 2011-07-06 20:28:10 +0000 |
582 | +++ nova/tests/api/openstack/contrib/test_floating_ips.py 2011-07-29 19:38:29 +0000 |
583 | @@ -74,12 +74,8 @@ |
584 | def setUp(self): |
585 | super(FloatingIpTest, self).setUp() |
586 | self.controller = FloatingIPController() |
587 | - self.stubs = stubout.StubOutForTesting() |
588 | - fakes.FakeAuthManager.reset_fake_data() |
589 | - fakes.FakeAuthDatabase.data = {} |
590 | fakes.stub_out_networking(self.stubs) |
591 | fakes.stub_out_rate_limiting(self.stubs) |
592 | - fakes.stub_out_auth(self.stubs) |
593 | self.stubs.Set(network.api.API, "get_floating_ip", |
594 | network_api_get_floating_ip) |
595 | self.stubs.Set(network.api.API, "list_floating_ips", |
596 | @@ -96,7 +92,6 @@ |
597 | self._create_floating_ip() |
598 | |
599 | def tearDown(self): |
600 | - self.stubs.UnsetAll() |
601 | self._delete_floating_ip() |
602 | super(FloatingIpTest, self).tearDown() |
603 | |
604 | |
605 | === modified file 'nova/tests/api/openstack/contrib/test_multinic_xs.py' |
606 | --- nova/tests/api/openstack/contrib/test_multinic_xs.py 2011-07-12 01:40:45 +0000 |
607 | +++ nova/tests/api/openstack/contrib/test_multinic_xs.py 2011-07-29 19:38:29 +0000 |
608 | @@ -42,22 +42,14 @@ |
609 | class FixedIpTest(test.TestCase): |
610 | def setUp(self): |
611 | super(FixedIpTest, self).setUp() |
612 | - self.stubs = stubout.StubOutForTesting() |
613 | - fakes.FakeAuthManager.reset_fake_data() |
614 | - fakes.FakeAuthDatabase.data = {} |
615 | fakes.stub_out_networking(self.stubs) |
616 | fakes.stub_out_rate_limiting(self.stubs) |
617 | - fakes.stub_out_auth(self.stubs) |
618 | self.stubs.Set(compute.api.API, "add_fixed_ip", |
619 | compute_api_add_fixed_ip) |
620 | self.stubs.Set(compute.api.API, "remove_fixed_ip", |
621 | compute_api_remove_fixed_ip) |
622 | self.context = context.get_admin_context() |
623 | |
624 | - def tearDown(self): |
625 | - self.stubs.UnsetAll() |
626 | - super(FixedIpTest, self).tearDown() |
627 | - |
628 | def test_add_fixed_ip(self): |
629 | global last_add_fixed_ip |
630 | last_add_fixed_ip = (None, None) |
631 | |
632 | === modified file 'nova/tests/api/openstack/fakes.py' |
633 | --- nova/tests/api/openstack/fakes.py 2011-06-28 22:05:41 +0000 |
634 | +++ nova/tests/api/openstack/fakes.py 2011-07-29 19:38:29 +0000 |
635 | @@ -29,6 +29,7 @@ |
636 | from nova import context |
637 | from nova import exception as exc |
638 | from nova import utils |
639 | +from nova import wsgi |
640 | import nova.api.openstack.auth |
641 | from nova.api import openstack |
642 | from nova.api.openstack import auth |
643 | @@ -40,14 +41,13 @@ |
644 | from nova.image import glance |
645 | from nova.image import service |
646 | from nova.tests import fake_flags |
647 | -from nova.wsgi import Router |
648 | |
649 | |
650 | class Context(object): |
651 | pass |
652 | |
653 | |
654 | -class FakeRouter(Router): |
655 | +class FakeRouter(wsgi.Router): |
656 | def __init__(self): |
657 | pass |
658 | |
659 | @@ -68,21 +68,30 @@ |
660 | |
661 | @webob.dec.wsgify |
662 | def fake_wsgi(self, req): |
663 | - req.environ['nova.context'] = context.RequestContext(1, 1) |
664 | return self.application |
665 | |
666 | |
667 | -def wsgi_app(inner_app10=None, inner_app11=None): |
668 | +def wsgi_app(inner_app10=None, inner_app11=None, fake_auth=True): |
669 | if not inner_app10: |
670 | inner_app10 = openstack.APIRouterV10() |
671 | if not inner_app11: |
672 | inner_app11 = openstack.APIRouterV11() |
673 | + |
674 | + if fake_auth: |
675 | + ctxt = context.RequestContext('fake', 'fake') |
676 | + api10 = openstack.FaultWrapper(wsgi.InjectContext(ctxt, |
677 | + limits.RateLimitingMiddleware(inner_app10))) |
678 | + api11 = openstack.FaultWrapper(wsgi.InjectContext(ctxt, |
679 | + limits.RateLimitingMiddleware( |
680 | + extensions.ExtensionMiddleware(inner_app11)))) |
681 | + else: |
682 | + api10 = openstack.FaultWrapper(auth.AuthMiddleware( |
683 | + limits.RateLimitingMiddleware(inner_app10))) |
684 | + api11 = openstack.FaultWrapper(auth.AuthMiddleware( |
685 | + limits.RateLimitingMiddleware( |
686 | + extensions.ExtensionMiddleware(inner_app11)))) |
687 | + Auth = auth |
688 | mapper = urlmap.URLMap() |
689 | - api10 = openstack.FaultWrapper(auth.AuthMiddleware( |
690 | - limits.RateLimitingMiddleware(inner_app10))) |
691 | - api11 = openstack.FaultWrapper(auth.AuthMiddleware( |
692 | - limits.RateLimitingMiddleware( |
693 | - extensions.ExtensionMiddleware(inner_app11)))) |
694 | mapper['/v1.0'] = api10 |
695 | mapper['/v1.1'] = api11 |
696 | mapper['/'] = openstack.FaultWrapper(versions.Versions()) |
697 | @@ -359,17 +368,18 @@ |
698 | if admin is not None: |
699 | user.admin = admin |
700 | |
701 | - def is_admin(self, user): |
702 | + def is_admin(self, user_id): |
703 | + user = self.get_user(user_id) |
704 | return user.admin |
705 | |
706 | - def is_project_member(self, user, project): |
707 | + def is_project_member(self, user_id, project): |
708 | if not isinstance(project, Project): |
709 | try: |
710 | project = self.get_project(project) |
711 | except exc.NotFound: |
712 | raise webob.exc.HTTPUnauthorized() |
713 | - return ((user.id in project.member_ids) or |
714 | - (user.id == project.project_manager_id)) |
715 | + return ((user_id in project.member_ids) or |
716 | + (user_id == project.project_manager_id)) |
717 | |
718 | def create_project(self, name, manager_user, description=None, |
719 | member_users=None): |
720 | @@ -396,13 +406,13 @@ |
721 | else: |
722 | raise exc.NotFound |
723 | |
724 | - def get_projects(self, user=None): |
725 | - if not user: |
726 | + def get_projects(self, user_id=None): |
727 | + if not user_id: |
728 | return FakeAuthManager.projects.values() |
729 | else: |
730 | return [p for p in FakeAuthManager.projects.values() |
731 | - if (user.id in p.member_ids) or |
732 | - (user.id == p.project_manager_id)] |
733 | + if (user_id in p.member_ids) or |
734 | + (user_id == p.project_manager_id)] |
735 | |
736 | |
737 | class FakeRateLimiter(object): |
738 | |
739 | === modified file 'nova/tests/api/openstack/test_accounts.py' |
740 | --- nova/tests/api/openstack/test_accounts.py 2011-03-16 19:15:57 +0000 |
741 | +++ nova/tests/api/openstack/test_accounts.py 2011-07-29 19:38:29 +0000 |
742 | @@ -16,7 +16,6 @@ |
743 | |
744 | import json |
745 | |
746 | -import stubout |
747 | import webob |
748 | |
749 | from nova import flags |
750 | @@ -41,7 +40,7 @@ |
751 | class AccountsTest(test.TestCase): |
752 | def setUp(self): |
753 | super(AccountsTest, self).setUp() |
754 | - self.stubs = stubout.StubOutForTesting() |
755 | + self.flags(allow_admin_api=True) |
756 | self.stubs.Set(accounts.Controller, '__init__', |
757 | fake_init) |
758 | self.stubs.Set(accounts.Controller, '_check_admin', |
759 | @@ -52,8 +51,6 @@ |
760 | fakes.stub_out_rate_limiting(self.stubs) |
761 | fakes.stub_out_auth(self.stubs) |
762 | |
763 | - self.allow_admin = FLAGS.allow_admin_api |
764 | - FLAGS.allow_admin_api = True |
765 | fakemgr = fakes.FakeAuthManager() |
766 | joeuser = User('id1', 'guy1', 'acc1', 'secret1', False) |
767 | superuser = User('id2', 'guy2', 'acc2', 'secret2', True) |
768 | @@ -62,11 +59,6 @@ |
769 | fakemgr.create_project('test1', joeuser) |
770 | fakemgr.create_project('test2', superuser) |
771 | |
772 | - def tearDown(self): |
773 | - self.stubs.UnsetAll() |
774 | - FLAGS.allow_admin_api = self.allow_admin |
775 | - super(AccountsTest, self).tearDown() |
776 | - |
777 | def test_get_account(self): |
778 | req = webob.Request.blank('/v1.0/accounts/test1') |
779 | res = req.get_response(fakes.wsgi_app()) |
780 | |
781 | === modified file 'nova/tests/api/openstack/test_adminapi.py' |
782 | --- nova/tests/api/openstack/test_adminapi.py 2011-03-15 20:49:19 +0000 |
783 | +++ nova/tests/api/openstack/test_adminapi.py 2011-07-29 19:38:29 +0000 |
784 | @@ -16,14 +16,10 @@ |
785 | # under the License. |
786 | |
787 | |
788 | -import stubout |
789 | import webob |
790 | -from paste import urlmap |
791 | |
792 | from nova import flags |
793 | from nova import test |
794 | -from nova.api import openstack |
795 | -from nova.api.openstack import auth |
796 | from nova.tests.api.openstack import fakes |
797 | |
798 | FLAGS = flags.FLAGS |
799 | @@ -33,21 +29,12 @@ |
800 | |
801 | def setUp(self): |
802 | super(AdminAPITest, self).setUp() |
803 | - self.stubs = stubout.StubOutForTesting() |
804 | - fakes.FakeAuthManager.reset_fake_data() |
805 | - fakes.FakeAuthDatabase.data = {} |
806 | fakes.stub_out_networking(self.stubs) |
807 | fakes.stub_out_rate_limiting(self.stubs) |
808 | - fakes.stub_out_auth(self.stubs) |
809 | self.allow_admin = FLAGS.allow_admin_api |
810 | |
811 | - def tearDown(self): |
812 | - self.stubs.UnsetAll() |
813 | - FLAGS.allow_admin_api = self.allow_admin |
814 | - super(AdminAPITest, self).tearDown() |
815 | - |
816 | def test_admin_enabled(self): |
817 | - FLAGS.allow_admin_api = True |
818 | + self.flags(allow_admin_api=True) |
819 | # We should still be able to access public operations. |
820 | req = webob.Request.blank('/v1.0/flavors') |
821 | res = req.get_response(fakes.wsgi_app()) |
822 | @@ -55,7 +42,7 @@ |
823 | # TODO: Confirm admin operations are available. |
824 | |
825 | def test_admin_disabled(self): |
826 | - FLAGS.allow_admin_api = False |
827 | + self.flags(allow_admin_api=False) |
828 | # We should still be able to access public operations. |
829 | req = webob.Request.blank('/v1.0/flavors') |
830 | res = req.get_response(fakes.wsgi_app()) |
831 | |
832 | === modified file 'nova/tests/api/openstack/test_auth.py' |
833 | --- nova/tests/api/openstack/test_auth.py 2011-06-08 17:58:59 +0000 |
834 | +++ nova/tests/api/openstack/test_auth.py 2011-07-29 19:38:29 +0000 |
835 | @@ -17,14 +17,12 @@ |
836 | |
837 | import datetime |
838 | |
839 | -import stubout |
840 | import webob |
841 | import webob.dec |
842 | |
843 | import nova.api |
844 | import nova.api.openstack.auth |
845 | import nova.auth.manager |
846 | -from nova import auth |
847 | from nova import context |
848 | from nova import db |
849 | from nova import test |
850 | @@ -35,7 +33,6 @@ |
851 | |
852 | def setUp(self): |
853 | super(Test, self).setUp() |
854 | - self.stubs = stubout.StubOutForTesting() |
855 | self.stubs.Set(nova.api.openstack.auth.AuthMiddleware, |
856 | '__init__', fakes.fake_auth_init) |
857 | self.stubs.Set(context, 'RequestContext', fakes.FakeRequestContext) |
858 | @@ -45,7 +42,6 @@ |
859 | fakes.stub_out_networking(self.stubs) |
860 | |
861 | def tearDown(self): |
862 | - self.stubs.UnsetAll() |
863 | fakes.fake_data_store = {} |
864 | super(Test, self).tearDown() |
865 | |
866 | @@ -57,7 +53,7 @@ |
867 | req = webob.Request.blank('/v1.0/') |
868 | req.headers['X-Auth-User'] = 'user1' |
869 | req.headers['X-Auth-Key'] = 'user1_key' |
870 | - result = req.get_response(fakes.wsgi_app()) |
871 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
872 | self.assertEqual(result.status, '204 No Content') |
873 | self.assertEqual(len(result.headers['X-Auth-Token']), 40) |
874 | self.assertEqual(result.headers['X-CDN-Management-Url'], |
875 | @@ -73,7 +69,7 @@ |
876 | req = webob.Request.blank('/v1.0/', {'HTTP_HOST': 'foo'}) |
877 | req.headers['X-Auth-User'] = 'user1' |
878 | req.headers['X-Auth-Key'] = 'user1_key' |
879 | - result = req.get_response(fakes.wsgi_app()) |
880 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
881 | self.assertEqual(result.status, '204 No Content') |
882 | self.assertEqual(len(result.headers['X-Auth-Token']), 40) |
883 | self.assertEqual(result.headers['X-Server-Management-Url'], |
884 | @@ -86,7 +82,7 @@ |
885 | self.stubs.Set(nova.api.openstack, 'APIRouterV10', fakes.FakeRouter) |
886 | req = webob.Request.blank('/v1.0/fake') |
887 | req.headers['X-Auth-Token'] = token |
888 | - result = req.get_response(fakes.wsgi_app()) |
889 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
890 | self.assertEqual(result.status, '200 OK') |
891 | self.assertEqual(result.headers['X-Test-Success'], 'True') |
892 | |
893 | @@ -110,7 +106,7 @@ |
894 | |
895 | req = webob.Request.blank('/v1.0/') |
896 | req.headers['X-Auth-Token'] = 'token_hash' |
897 | - result = req.get_response(fakes.wsgi_app()) |
898 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
899 | self.assertEqual(result.status, '401 Unauthorized') |
900 | self.assertEqual(self.destroy_called, True) |
901 | |
902 | @@ -124,7 +120,7 @@ |
903 | req = webob.Request.blank('/v1.0/', {'HTTP_HOST': 'foo'}) |
904 | req.headers['X-Auth-User'] = 'user1' |
905 | req.headers['X-Auth-Key'] = 'user1_key' |
906 | - result = req.get_response(fakes.wsgi_app()) |
907 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
908 | self.assertEqual(result.status, '204 No Content') |
909 | |
910 | token = result.headers['X-Auth-Token'] |
911 | @@ -132,7 +128,7 @@ |
912 | req = webob.Request.blank('/v1.0/fake') |
913 | req.headers['X-Auth-Token'] = token |
914 | req.headers['X-Auth-Project-Id'] = 'user2_project' |
915 | - result = req.get_response(fakes.wsgi_app()) |
916 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
917 | self.assertEqual(result.status, '200 OK') |
918 | self.assertEqual(result.headers['X-Test-Success'], 'True') |
919 | |
920 | @@ -140,7 +136,7 @@ |
921 | req = webob.Request.blank('/v1.0/') |
922 | req.headers['X-Auth-User'] = 'unknown_user' |
923 | req.headers['X-Auth-Key'] = 'unknown_user_key' |
924 | - result = req.get_response(fakes.wsgi_app()) |
925 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
926 | self.assertEqual(result.status, '401 Unauthorized') |
927 | |
928 | def test_bad_user_good_key(self): |
929 | @@ -151,18 +147,18 @@ |
930 | req = webob.Request.blank('/v1.0/') |
931 | req.headers['X-Auth-User'] = 'unknown_user' |
932 | req.headers['X-Auth-Key'] = 'user1_key' |
933 | - result = req.get_response(fakes.wsgi_app()) |
934 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
935 | self.assertEqual(result.status, '401 Unauthorized') |
936 | |
937 | def test_no_user(self): |
938 | req = webob.Request.blank('/v1.0/') |
939 | - result = req.get_response(fakes.wsgi_app()) |
940 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
941 | self.assertEqual(result.status, '401 Unauthorized') |
942 | |
943 | def test_bad_token(self): |
944 | req = webob.Request.blank('/v1.0/') |
945 | req.headers['X-Auth-Token'] = 'unknown_token' |
946 | - result = req.get_response(fakes.wsgi_app()) |
947 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
948 | self.assertEqual(result.status, '401 Unauthorized') |
949 | |
950 | def test_bad_project(self): |
951 | @@ -177,7 +173,7 @@ |
952 | req = webob.Request.blank('/v1.0/', {'HTTP_HOST': 'foo'}) |
953 | req.headers['X-Auth-User'] = 'user1' |
954 | req.headers['X-Auth-Key'] = 'user1_key' |
955 | - result = req.get_response(fakes.wsgi_app()) |
956 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
957 | self.assertEqual(result.status, '204 No Content') |
958 | |
959 | token = result.headers['X-Auth-Token'] |
960 | @@ -185,7 +181,7 @@ |
961 | req = webob.Request.blank('/v1.0/fake') |
962 | req.headers['X-Auth-Token'] = token |
963 | req.headers['X-Auth-Project-Id'] = 'user2_project' |
964 | - result = req.get_response(fakes.wsgi_app()) |
965 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
966 | self.assertEqual(result.status, '401 Unauthorized') |
967 | |
968 | def test_not_existing_project(self): |
969 | @@ -197,7 +193,7 @@ |
970 | req = webob.Request.blank('/v1.0/', {'HTTP_HOST': 'foo'}) |
971 | req.headers['X-Auth-User'] = 'user1' |
972 | req.headers['X-Auth-Key'] = 'user1_key' |
973 | - result = req.get_response(fakes.wsgi_app()) |
974 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
975 | self.assertEqual(result.status, '204 No Content') |
976 | |
977 | token = result.headers['X-Auth-Token'] |
978 | @@ -205,7 +201,7 @@ |
979 | req = webob.Request.blank('/v1.0/fake') |
980 | req.headers['X-Auth-Token'] = token |
981 | req.headers['X-Auth-Project-Id'] = 'unknown_project' |
982 | - result = req.get_response(fakes.wsgi_app()) |
983 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
984 | self.assertEqual(result.status, '401 Unauthorized') |
985 | |
986 | |
987 | @@ -226,20 +222,19 @@ |
988 | |
989 | req = webob.Request.blank('/v1.0/') |
990 | req.headers['X-Auth-Token'] = 'test_token_hash' |
991 | - result = req.get_response(fakes.wsgi_app()) |
992 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
993 | self.assertEqual(result.status, '401 Unauthorized') |
994 | |
995 | def test_token_doesnotexist(self): |
996 | req = webob.Request.blank('/v1.0/') |
997 | req.headers['X-Auth-Token'] = 'nonexistant_token_hash' |
998 | - result = req.get_response(fakes.wsgi_app()) |
999 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
1000 | self.assertEqual(result.status, '401 Unauthorized') |
1001 | |
1002 | |
1003 | class TestLimiter(test.TestCase): |
1004 | def setUp(self): |
1005 | super(TestLimiter, self).setUp() |
1006 | - self.stubs = stubout.StubOutForTesting() |
1007 | self.stubs.Set(nova.api.openstack.auth.AuthMiddleware, |
1008 | '__init__', fakes.fake_auth_init) |
1009 | self.stubs.Set(context, 'RequestContext', fakes.FakeRequestContext) |
1010 | @@ -248,7 +243,6 @@ |
1011 | fakes.stub_out_networking(self.stubs) |
1012 | |
1013 | def tearDown(self): |
1014 | - self.stubs.UnsetAll() |
1015 | fakes.fake_data_store = {} |
1016 | super(TestLimiter, self).tearDown() |
1017 | |
1018 | @@ -261,7 +255,7 @@ |
1019 | req = webob.Request.blank('/v1.0/') |
1020 | req.headers['X-Auth-User'] = 'user1' |
1021 | req.headers['X-Auth-Key'] = 'user1_key' |
1022 | - result = req.get_response(fakes.wsgi_app()) |
1023 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
1024 | self.assertEqual(len(result.headers['X-Auth-Token']), 40) |
1025 | |
1026 | token = result.headers['X-Auth-Token'] |
1027 | @@ -269,6 +263,6 @@ |
1028 | req = webob.Request.blank('/v1.0/fake') |
1029 | req.method = 'POST' |
1030 | req.headers['X-Auth-Token'] = token |
1031 | - result = req.get_response(fakes.wsgi_app()) |
1032 | + result = req.get_response(fakes.wsgi_app(fake_auth=False)) |
1033 | self.assertEqual(result.status, '200 OK') |
1034 | self.assertEqual(result.headers['X-Test-Success'], 'True') |
1035 | |
1036 | === modified file 'nova/tests/api/openstack/test_extensions.py' |
1037 | --- nova/tests/api/openstack/test_extensions.py 2011-07-28 16:01:38 +0000 |
1038 | +++ nova/tests/api/openstack/test_extensions.py 2011-07-29 19:38:29 +0000 |
1039 | @@ -17,13 +17,12 @@ |
1040 | |
1041 | import json |
1042 | import os.path |
1043 | -import stubout |
1044 | -import unittest |
1045 | import webob |
1046 | from xml.etree import ElementTree |
1047 | |
1048 | from nova import context |
1049 | from nova import flags |
1050 | +from nova import test |
1051 | from nova.api import openstack |
1052 | from nova.api.openstack import extensions |
1053 | from nova.api.openstack import flavors |
1054 | @@ -80,11 +79,12 @@ |
1055 | return request_extensions |
1056 | |
1057 | |
1058 | -class ExtensionControllerTest(unittest.TestCase): |
1059 | +class ExtensionControllerTest(test.TestCase): |
1060 | |
1061 | def setUp(self): |
1062 | - FLAGS.osapi_extensions_path = os.path.join( |
1063 | - os.path.dirname(__file__), "extensions") |
1064 | + super(ExtensionControllerTest, self).setUp() |
1065 | + ext_path = os.path.join(os.path.dirname(__file__), "extensions") |
1066 | + self.flags(osapi_extensions_path=ext_path) |
1067 | |
1068 | def test_list_extensions_json(self): |
1069 | app = openstack.APIRouterV11() |
1070 | @@ -176,7 +176,12 @@ |
1071 | 'The Fox In Socks Extension') |
1072 | |
1073 | |
1074 | -class ResourceExtensionTest(unittest.TestCase): |
1075 | +class ResourceExtensionTest(test.TestCase): |
1076 | + |
1077 | + def setUp(self): |
1078 | + super(ResourceExtensionTest, self).setUp() |
1079 | + ext_path = os.path.join(os.path.dirname(__file__), "extensions") |
1080 | + self.flags(osapi_extensions_path=ext_path) |
1081 | |
1082 | def test_no_extension_present(self): |
1083 | manager = StubExtensionManager(None) |
1084 | @@ -214,13 +219,14 @@ |
1085 | return "THIRD" |
1086 | |
1087 | |
1088 | -class ExtensionManagerTest(unittest.TestCase): |
1089 | +class ExtensionManagerTest(test.TestCase): |
1090 | |
1091 | response_body = "Try to say this Mr. Knox, sir..." |
1092 | |
1093 | def setUp(self): |
1094 | - FLAGS.osapi_extensions_path = os.path.join(os.path.dirname(__file__), |
1095 | - "extensions") |
1096 | + super(ExtensionManagerTest, self).setUp() |
1097 | + ext_path = os.path.join(os.path.dirname(__file__), "extensions") |
1098 | + self.flags(osapi_extensions_path=ext_path) |
1099 | |
1100 | def test_get_resources(self): |
1101 | app = openstack.APIRouterV11() |
1102 | @@ -239,11 +245,12 @@ |
1103 | self.assertTrue('THIRD' not in ext_mgr.extensions) |
1104 | |
1105 | |
1106 | -class ActionExtensionTest(unittest.TestCase): |
1107 | +class ActionExtensionTest(test.TestCase): |
1108 | |
1109 | def setUp(self): |
1110 | - FLAGS.osapi_extensions_path = os.path.join(os.path.dirname(__file__), |
1111 | - "extensions") |
1112 | + super(ActionExtensionTest, self).setUp() |
1113 | + ext_path = os.path.join(os.path.dirname(__file__), "extensions") |
1114 | + self.flags(osapi_extensions_path=ext_path) |
1115 | |
1116 | def _send_server_action_request(self, url, body): |
1117 | app = openstack.APIRouterV11() |
1118 | @@ -277,19 +284,12 @@ |
1119 | self.assertEqual(404, response.status_int) |
1120 | |
1121 | |
1122 | -class RequestExtensionTest(unittest.TestCase): |
1123 | +class RequestExtensionTest(test.TestCase): |
1124 | |
1125 | def setUp(self): |
1126 | super(RequestExtensionTest, self).setUp() |
1127 | - self.stubs = stubout.StubOutForTesting() |
1128 | - fakes.FakeAuthManager.reset_fake_data() |
1129 | - fakes.FakeAuthDatabase.data = {} |
1130 | - fakes.stub_out_auth(self.stubs) |
1131 | - self.context = context.get_admin_context() |
1132 | - |
1133 | - def tearDown(self): |
1134 | - self.stubs.UnsetAll() |
1135 | - super(RequestExtensionTest, self).tearDown() |
1136 | + ext_path = os.path.join(os.path.dirname(__file__), "extensions") |
1137 | + self.flags(osapi_extensions_path=ext_path) |
1138 | |
1139 | def test_get_resources_with_stub_mgr(self): |
1140 | |
1141 | @@ -327,7 +327,7 @@ |
1142 | self.assertEqual("Pig Bands!", response_data['big_bands']) |
1143 | |
1144 | |
1145 | -class ExtensionsXMLSerializerTest(unittest.TestCase): |
1146 | +class ExtensionsXMLSerializerTest(test.TestCase): |
1147 | |
1148 | def test_serialize_extenstion(self): |
1149 | serializer = extensions.ExtensionsXMLSerializer() |
1150 | |
1151 | === modified file 'nova/tests/api/openstack/test_flavors.py' |
1152 | --- nova/tests/api/openstack/test_flavors.py 2011-07-20 21:06:36 +0000 |
1153 | +++ nova/tests/api/openstack/test_flavors.py 2011-07-29 19:38:29 +0000 |
1154 | @@ -16,7 +16,6 @@ |
1155 | # under the License. |
1156 | |
1157 | import json |
1158 | -import stubout |
1159 | import webob |
1160 | import xml.dom.minidom as minidom |
1161 | |
1162 | @@ -56,12 +55,8 @@ |
1163 | class FlavorsTest(test.TestCase): |
1164 | def setUp(self): |
1165 | super(FlavorsTest, self).setUp() |
1166 | - self.stubs = stubout.StubOutForTesting() |
1167 | - fakes.FakeAuthManager.reset_fake_data() |
1168 | - fakes.FakeAuthDatabase.data = {} |
1169 | fakes.stub_out_networking(self.stubs) |
1170 | fakes.stub_out_rate_limiting(self.stubs) |
1171 | - fakes.stub_out_auth(self.stubs) |
1172 | self.stubs.Set(nova.db.api, "instance_type_get_all", |
1173 | return_instance_types) |
1174 | self.stubs.Set(nova.db.api, "instance_type_get_by_flavor_id", |
1175 | |
1176 | === renamed file 'nova/tests/api/openstack/extensions/test_flavors_extra_specs.py' => 'nova/tests/api/openstack/test_flavors_extra_specs.py' |
1177 | --- nova/tests/api/openstack/extensions/test_flavors_extra_specs.py 2011-06-27 00:02:18 +0000 |
1178 | +++ nova/tests/api/openstack/test_flavors_extra_specs.py 2011-07-29 19:38:29 +0000 |
1179 | @@ -17,14 +17,13 @@ |
1180 | |
1181 | import json |
1182 | import stubout |
1183 | -import unittest |
1184 | import webob |
1185 | import os.path |
1186 | |
1187 | |
1188 | from nova import flags |
1189 | +from nova import test |
1190 | from nova.api import openstack |
1191 | -from nova.api.openstack import auth |
1192 | from nova.api.openstack import extensions |
1193 | from nova.tests.api.openstack import fakes |
1194 | import nova.wsgi |
1195 | @@ -40,10 +39,6 @@ |
1196 | return stub_flavor_extra_specs() |
1197 | |
1198 | |
1199 | -def return_flavor_extra_specs(context, flavor_id): |
1200 | - return stub_flavor_extra_specs() |
1201 | - |
1202 | - |
1203 | def return_empty_flavor_extra_specs(context, flavor_id): |
1204 | return {} |
1205 | |
1206 | @@ -62,30 +57,17 @@ |
1207 | return specs |
1208 | |
1209 | |
1210 | -class FlavorsExtraSpecsTest(unittest.TestCase): |
1211 | +class FlavorsExtraSpecsTest(test.TestCase): |
1212 | |
1213 | def setUp(self): |
1214 | super(FlavorsExtraSpecsTest, self).setUp() |
1215 | - FLAGS.osapi_extensions_path = os.path.join(os.path.dirname(__file__), |
1216 | - "extensions") |
1217 | - self.stubs = stubout.StubOutForTesting() |
1218 | - fakes.FakeAuthManager.auth_data = {} |
1219 | - fakes.FakeAuthDatabase.data = {} |
1220 | - fakes.stub_out_auth(self.stubs) |
1221 | fakes.stub_out_key_pair_funcs(self.stubs) |
1222 | - self.mware = auth.AuthMiddleware( |
1223 | - extensions.ExtensionMiddleware( |
1224 | - openstack.APIRouterV11())) |
1225 | - |
1226 | - def tearDown(self): |
1227 | - self.stubs.UnsetAll() |
1228 | - super(FlavorsExtraSpecsTest, self).tearDown() |
1229 | |
1230 | def test_index(self): |
1231 | self.stubs.Set(nova.db.api, 'instance_type_extra_specs_get', |
1232 | return_flavor_extra_specs) |
1233 | - request = webob.Request.blank('/flavors/1/os-extra_specs') |
1234 | - res = request.get_response(self.mware) |
1235 | + request = webob.Request.blank('/v1.1/flavors/1/os-extra_specs') |
1236 | + res = request.get_response(fakes.wsgi_app()) |
1237 | self.assertEqual(200, res.status_int) |
1238 | res_dict = json.loads(res.body) |
1239 | self.assertEqual('application/json', res.headers['Content-Type']) |
1240 | @@ -94,8 +76,8 @@ |
1241 | def test_index_no_data(self): |
1242 | self.stubs.Set(nova.db.api, 'instance_type_extra_specs_get', |
1243 | return_empty_flavor_extra_specs) |
1244 | - req = webob.Request.blank('/flavors/1/os-extra_specs') |
1245 | - res = req.get_response(self.mware) |
1246 | + req = webob.Request.blank('/v1.1/flavors/1/os-extra_specs') |
1247 | + res = req.get_response(fakes.wsgi_app()) |
1248 | res_dict = json.loads(res.body) |
1249 | self.assertEqual(200, res.status_int) |
1250 | self.assertEqual('application/json', res.headers['Content-Type']) |
1251 | @@ -104,8 +86,8 @@ |
1252 | def test_show(self): |
1253 | self.stubs.Set(nova.db.api, 'instance_type_extra_specs_get', |
1254 | return_flavor_extra_specs) |
1255 | - req = webob.Request.blank('/flavors/1/os-extra_specs/key5') |
1256 | - res = req.get_response(self.mware) |
1257 | + req = webob.Request.blank('/v1.1/flavors/1/os-extra_specs/key5') |
1258 | + res = req.get_response(fakes.wsgi_app()) |
1259 | self.assertEqual(200, res.status_int) |
1260 | res_dict = json.loads(res.body) |
1261 | self.assertEqual('application/json', res.headers['Content-Type']) |
1262 | @@ -114,28 +96,28 @@ |
1263 | def test_show_spec_not_found(self): |
1264 | self.stubs.Set(nova.db.api, 'instance_type_extra_specs_get', |
1265 | return_empty_flavor_extra_specs) |
1266 | - req = webob.Request.blank('/flavors/1/os-extra_specs/key6') |
1267 | - res = req.get_response(self.mware) |
1268 | + req = webob.Request.blank('/v1.1/flavors/1/os-extra_specs/key6') |
1269 | + res = req.get_response(fakes.wsgi_app()) |
1270 | res_dict = json.loads(res.body) |
1271 | self.assertEqual(404, res.status_int) |
1272 | |
1273 | def test_delete(self): |
1274 | self.stubs.Set(nova.db.api, 'instance_type_extra_specs_delete', |
1275 | delete_flavor_extra_specs) |
1276 | - req = webob.Request.blank('/flavors/1/os-extra_specs/key5') |
1277 | + req = webob.Request.blank('/v1.1/flavors/1/os-extra_specs/key5') |
1278 | req.method = 'DELETE' |
1279 | - res = req.get_response(self.mware) |
1280 | + res = req.get_response(fakes.wsgi_app()) |
1281 | self.assertEqual(200, res.status_int) |
1282 | |
1283 | def test_create(self): |
1284 | self.stubs.Set(nova.db.api, |
1285 | 'instance_type_extra_specs_update_or_create', |
1286 | return_create_flavor_extra_specs) |
1287 | - req = webob.Request.blank('/flavors/1/os-extra_specs') |
1288 | + req = webob.Request.blank('/v1.1/flavors/1/os-extra_specs') |
1289 | req.method = 'POST' |
1290 | req.body = '{"extra_specs": {"key1": "value1"}}' |
1291 | req.headers["content-type"] = "application/json" |
1292 | - res = req.get_response(self.mware) |
1293 | + res = req.get_response(fakes.wsgi_app()) |
1294 | res_dict = json.loads(res.body) |
1295 | self.assertEqual(200, res.status_int) |
1296 | self.assertEqual('application/json', res.headers['Content-Type']) |
1297 | @@ -145,21 +127,21 @@ |
1298 | self.stubs.Set(nova.db.api, |
1299 | 'instance_type_extra_specs_update_or_create', |
1300 | return_create_flavor_extra_specs) |
1301 | - req = webob.Request.blank('/flavors/1/os-extra_specs') |
1302 | + req = webob.Request.blank('/v1.1/flavors/1/os-extra_specs') |
1303 | req.method = 'POST' |
1304 | req.headers["content-type"] = "application/json" |
1305 | - res = req.get_response(self.mware) |
1306 | + res = req.get_response(fakes.wsgi_app()) |
1307 | self.assertEqual(400, res.status_int) |
1308 | |
1309 | def test_update_item(self): |
1310 | self.stubs.Set(nova.db.api, |
1311 | 'instance_type_extra_specs_update_or_create', |
1312 | return_create_flavor_extra_specs) |
1313 | - req = webob.Request.blank('/flavors/1/os-extra_specs/key1') |
1314 | + req = webob.Request.blank('/v1.1/flavors/1/os-extra_specs/key1') |
1315 | req.method = 'PUT' |
1316 | req.body = '{"key1": "value1"}' |
1317 | req.headers["content-type"] = "application/json" |
1318 | - res = req.get_response(self.mware) |
1319 | + res = req.get_response(fakes.wsgi_app()) |
1320 | self.assertEqual(200, res.status_int) |
1321 | self.assertEqual('application/json', res.headers['Content-Type']) |
1322 | res_dict = json.loads(res.body) |
1323 | @@ -169,30 +151,30 @@ |
1324 | self.stubs.Set(nova.db.api, |
1325 | 'instance_type_extra_specs_update_or_create', |
1326 | return_create_flavor_extra_specs) |
1327 | - req = webob.Request.blank('/flavors/1/os-extra_specs/key1') |
1328 | + req = webob.Request.blank('/v1.1/flavors/1/os-extra_specs/key1') |
1329 | req.method = 'PUT' |
1330 | req.headers["content-type"] = "application/json" |
1331 | - res = req.get_response(self.mware) |
1332 | + res = req.get_response(fakes.wsgi_app()) |
1333 | self.assertEqual(400, res.status_int) |
1334 | |
1335 | def test_update_item_too_many_keys(self): |
1336 | self.stubs.Set(nova.db.api, |
1337 | 'instance_type_extra_specs_update_or_create', |
1338 | return_create_flavor_extra_specs) |
1339 | - req = webob.Request.blank('/flavors/1/os-extra_specs/key1') |
1340 | + req = webob.Request.blank('/v1.1/flavors/1/os-extra_specs/key1') |
1341 | req.method = 'PUT' |
1342 | req.body = '{"key1": "value1", "key2": "value2"}' |
1343 | req.headers["content-type"] = "application/json" |
1344 | - res = req.get_response(self.mware) |
1345 | + res = req.get_response(fakes.wsgi_app()) |
1346 | self.assertEqual(400, res.status_int) |
1347 | |
1348 | def test_update_item_body_uri_mismatch(self): |
1349 | self.stubs.Set(nova.db.api, |
1350 | 'instance_type_extra_specs_update_or_create', |
1351 | return_create_flavor_extra_specs) |
1352 | - req = webob.Request.blank('/flavors/1/os-extra_specs/bad') |
1353 | + req = webob.Request.blank('/v1.1/flavors/1/os-extra_specs/bad') |
1354 | req.method = 'PUT' |
1355 | req.body = '{"key1": "value1"}' |
1356 | req.headers["content-type"] = "application/json" |
1357 | - res = req.get_response(self.mware) |
1358 | + res = req.get_response(fakes.wsgi_app()) |
1359 | self.assertEqual(400, res.status_int) |
1360 | |
1361 | === modified file 'nova/tests/api/openstack/test_image_metadata.py' |
1362 | --- nova/tests/api/openstack/test_image_metadata.py 2011-07-26 13:22:41 +0000 |
1363 | +++ nova/tests/api/openstack/test_image_metadata.py 2011-07-29 19:38:29 +0000 |
1364 | @@ -16,8 +16,6 @@ |
1365 | # under the License. |
1366 | |
1367 | import json |
1368 | -import stubout |
1369 | -import unittest |
1370 | import webob |
1371 | |
1372 | |
1373 | @@ -84,23 +82,13 @@ |
1374 | |
1375 | def setUp(self): |
1376 | super(ImageMetaDataTest, self).setUp() |
1377 | - self.stubs = stubout.StubOutForTesting() |
1378 | - self.orig_image_service = FLAGS.image_service |
1379 | - FLAGS.image_service = 'nova.image.glance.GlanceImageService' |
1380 | - fakes.FakeAuthManager.auth_data = {} |
1381 | - fakes.FakeAuthDatabase.data = {} |
1382 | - fakes.stub_out_auth(self.stubs) |
1383 | + self.flags(image_service='nova.image.glance.GlanceImageService') |
1384 | # NOTE(dprince) max out properties/metadata in image 3 for testing |
1385 | img3 = self.IMAGE_FIXTURES[2] |
1386 | for num in range(FLAGS.quota_metadata_items): |
1387 | img3['properties']['key%i' % num] = "blah" |
1388 | fakes.stub_out_glance(self.stubs, self.IMAGE_FIXTURES) |
1389 | |
1390 | - def tearDown(self): |
1391 | - self.stubs.UnsetAll() |
1392 | - FLAGS.image_service = self.orig_image_service |
1393 | - super(ImageMetaDataTest, self).tearDown() |
1394 | - |
1395 | def test_index(self): |
1396 | req = webob.Request.blank('/v1.1/images/1/metadata') |
1397 | res = req.get_response(fakes.wsgi_app()) |
1398 | |
1399 | === modified file 'nova/tests/api/openstack/test_images.py' |
1400 | --- nova/tests/api/openstack/test_images.py 2011-07-25 17:28:22 +0000 |
1401 | +++ nova/tests/api/openstack/test_images.py 2011-07-29 19:38:29 +0000 |
1402 | @@ -155,7 +155,7 @@ |
1403 | fakes.stub_out_compute_api_snapshot(self.stubs) |
1404 | service_class = 'nova.image.glance.GlanceImageService' |
1405 | self.service = utils.import_object(service_class) |
1406 | - self.context = context.RequestContext(1, None) |
1407 | + self.context = context.RequestContext('fake', 'fake') |
1408 | self.service.delete_all() |
1409 | self.sent_to_glance = {} |
1410 | fakes.stub_out_glance_add_image(self.stubs, self.sent_to_glance) |
1411 | @@ -168,7 +168,7 @@ |
1412 | """Ensure instance_id is persisted as an image-property""" |
1413 | fixture = {'name': 'test image', |
1414 | 'is_public': False, |
1415 | - 'properties': {'instance_id': '42', 'user_id': '1'}} |
1416 | + 'properties': {'instance_id': '42', 'user_id': 'fake'}} |
1417 | |
1418 | image_id = self.service.create(self.context, fixture)['id'] |
1419 | expected = fixture |
1420 | @@ -178,7 +178,7 @@ |
1421 | expected = {'id': image_id, |
1422 | 'name': 'test image', |
1423 | 'is_public': False, |
1424 | - 'properties': {'instance_id': '42', 'user_id': '1'}} |
1425 | + 'properties': {'instance_id': '42', 'user_id': 'fake'}} |
1426 | self.assertDictMatch(image_meta, expected) |
1427 | |
1428 | image_metas = self.service.detail(self.context) |
1429 | @@ -331,11 +331,8 @@ |
1430 | self.orig_image_service = FLAGS.image_service |
1431 | FLAGS.image_service = 'nova.image.glance.GlanceImageService' |
1432 | self.stubs = stubout.StubOutForTesting() |
1433 | - fakes.FakeAuthManager.reset_fake_data() |
1434 | - fakes.FakeAuthDatabase.data = {} |
1435 | fakes.stub_out_networking(self.stubs) |
1436 | fakes.stub_out_rate_limiting(self.stubs) |
1437 | - fakes.stub_out_auth(self.stubs) |
1438 | fakes.stub_out_key_pair_funcs(self.stubs) |
1439 | self.fixtures = self._make_image_fixtures() |
1440 | fakes.stub_out_glance(self.stubs, initial_fixtures=self.fixtures) |
1441 | @@ -352,7 +349,7 @@ |
1442 | """Determine if this fixture is applicable for given user id.""" |
1443 | is_public = fixture["is_public"] |
1444 | try: |
1445 | - uid = int(fixture["properties"]["user_id"]) |
1446 | + uid = fixture["properties"]["user_id"] |
1447 | except KeyError: |
1448 | uid = None |
1449 | return uid == user_id or is_public |
1450 | @@ -424,7 +421,7 @@ |
1451 | }, |
1452 | "metadata": { |
1453 | "instance_ref": "http://localhost/v1.1/servers/42", |
1454 | - "user_id": "1", |
1455 | + "user_id": "fake", |
1456 | }, |
1457 | "links": [{ |
1458 | "rel": "self", |
1459 | @@ -559,7 +556,7 @@ |
1460 | fixtures = copy.copy(self.fixtures) |
1461 | |
1462 | for image in fixtures: |
1463 | - if not self._applicable_fixture(image, 1): |
1464 | + if not self._applicable_fixture(image, "fake"): |
1465 | fixtures.remove(image) |
1466 | continue |
1467 | |
1468 | @@ -666,7 +663,7 @@ |
1469 | 'name': 'queued snapshot', |
1470 | 'metadata': { |
1471 | u'instance_ref': u'http://localhost/v1.1/servers/42', |
1472 | - u'user_id': u'1', |
1473 | + u'user_id': u'fake', |
1474 | }, |
1475 | 'updated': self.NOW_API_FORMAT, |
1476 | 'created': self.NOW_API_FORMAT, |
1477 | @@ -696,7 +693,7 @@ |
1478 | 'name': 'saving snapshot', |
1479 | 'metadata': { |
1480 | u'instance_ref': u'http://localhost/v1.1/servers/42', |
1481 | - u'user_id': u'1', |
1482 | + u'user_id': u'fake', |
1483 | }, |
1484 | 'updated': self.NOW_API_FORMAT, |
1485 | 'created': self.NOW_API_FORMAT, |
1486 | @@ -727,7 +724,7 @@ |
1487 | 'name': 'active snapshot', |
1488 | 'metadata': { |
1489 | u'instance_ref': u'http://localhost/v1.1/servers/42', |
1490 | - u'user_id': u'1', |
1491 | + u'user_id': u'fake', |
1492 | }, |
1493 | 'updated': self.NOW_API_FORMAT, |
1494 | 'created': self.NOW_API_FORMAT, |
1495 | @@ -757,7 +754,7 @@ |
1496 | 'name': 'killed snapshot', |
1497 | 'metadata': { |
1498 | u'instance_ref': u'http://localhost/v1.1/servers/42', |
1499 | - u'user_id': u'1', |
1500 | + u'user_id': u'fake', |
1501 | }, |
1502 | 'updated': self.NOW_API_FORMAT, |
1503 | 'created': self.NOW_API_FORMAT, |
1504 | @@ -1259,7 +1256,7 @@ |
1505 | |
1506 | # Snapshot for User 1 |
1507 | server_ref = 'http://localhost/v1.1/servers/42' |
1508 | - snapshot_properties = {'instance_ref': server_ref, 'user_id': '1'} |
1509 | + snapshot_properties = {'instance_ref': server_ref, 'user_id': 'fake'} |
1510 | for status in ('queued', 'saving', 'active', 'killed'): |
1511 | add_fixture(id=image_id, name='%s snapshot' % status, |
1512 | is_public=False, status=status, |
1513 | @@ -1267,7 +1264,7 @@ |
1514 | image_id += 1 |
1515 | |
1516 | # Snapshot for User 2 |
1517 | - other_snapshot_properties = {'instance_id': '43', 'user_id': '2'} |
1518 | + other_snapshot_properties = {'instance_id': '43', 'user_id': 'other'} |
1519 | add_fixture(id=image_id, name='someone elses snapshot', |
1520 | is_public=False, status='active', |
1521 | properties=other_snapshot_properties) |
1522 | |
1523 | === modified file 'nova/tests/api/openstack/test_server_metadata.py' |
1524 | --- nova/tests/api/openstack/test_server_metadata.py 2011-06-24 12:01:51 +0000 |
1525 | +++ nova/tests/api/openstack/test_server_metadata.py 2011-07-29 19:38:29 +0000 |
1526 | @@ -16,14 +16,12 @@ |
1527 | # under the License. |
1528 | |
1529 | import json |
1530 | -import stubout |
1531 | -import unittest |
1532 | import webob |
1533 | |
1534 | |
1535 | from nova import exception |
1536 | from nova import flags |
1537 | -from nova.api import openstack |
1538 | +from nova import test |
1539 | from nova.tests.api.openstack import fakes |
1540 | import nova.wsgi |
1541 | |
1542 | @@ -76,21 +74,13 @@ |
1543 | raise exception.InstanceNotFound() |
1544 | |
1545 | |
1546 | -class ServerMetaDataTest(unittest.TestCase): |
1547 | +class ServerMetaDataTest(test.TestCase): |
1548 | |
1549 | def setUp(self): |
1550 | super(ServerMetaDataTest, self).setUp() |
1551 | - self.stubs = stubout.StubOutForTesting() |
1552 | - fakes.FakeAuthManager.auth_data = {} |
1553 | - fakes.FakeAuthDatabase.data = {} |
1554 | - fakes.stub_out_auth(self.stubs) |
1555 | fakes.stub_out_key_pair_funcs(self.stubs) |
1556 | self.stubs.Set(nova.db.api, 'instance_get', return_server) |
1557 | |
1558 | - def tearDown(self): |
1559 | - self.stubs.UnsetAll() |
1560 | - super(ServerMetaDataTest, self).tearDown() |
1561 | - |
1562 | def test_index(self): |
1563 | self.stubs.Set(nova.db.api, 'instance_metadata_get', |
1564 | return_server_metadata) |
1565 | |
1566 | === modified file 'nova/tests/api/openstack/test_servers.py' |
1567 | --- nova/tests/api/openstack/test_servers.py 2011-07-29 19:24:00 +0000 |
1568 | +++ nova/tests/api/openstack/test_servers.py 2011-07-29 19:38:29 +0000 |
1569 | @@ -21,7 +21,6 @@ |
1570 | import unittest |
1571 | from xml.dom import minidom |
1572 | |
1573 | -import stubout |
1574 | import webob |
1575 | |
1576 | from nova import context |
1577 | @@ -104,8 +103,8 @@ |
1578 | return _return_server |
1579 | |
1580 | |
1581 | -def return_servers(context, user_id=1): |
1582 | - return [stub_instance(i, user_id) for i in xrange(5)] |
1583 | +def return_servers(context, *args, **kwargs): |
1584 | + return [stub_instance(i, 'fake', 'fake') for i in xrange(5)] |
1585 | |
1586 | |
1587 | def return_servers_by_reservation(context, reservation_id=""): |
1588 | @@ -148,10 +147,10 @@ |
1589 | return None |
1590 | |
1591 | |
1592 | -def stub_instance(id, user_id=1, private_address=None, public_addresses=None, |
1593 | - host=None, power_state=0, reservation_id="", |
1594 | - uuid=FAKE_UUID, image_ref="10", flavor_id="1", |
1595 | - interfaces=None): |
1596 | +def stub_instance(id, user_id='fake', project_id='fake', private_address=None, |
1597 | + public_addresses=None, host=None, power_state=0, |
1598 | + reservation_id="", uuid=FAKE_UUID, image_ref="10", |
1599 | + flavor_id="1", interfaces=None): |
1600 | metadata = [] |
1601 | metadata.append(InstanceMetadata(key='seq', value=id)) |
1602 | |
1603 | @@ -177,7 +176,7 @@ |
1604 | "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0), |
1605 | "admin_pass": "", |
1606 | "user_id": user_id, |
1607 | - "project_id": "", |
1608 | + "project_id": project_id, |
1609 | "image_ref": image_ref, |
1610 | "kernel_id": "", |
1611 | "ramdisk_id": "", |
1612 | @@ -236,12 +235,8 @@ |
1613 | def setUp(self): |
1614 | self.maxDiff = None |
1615 | super(ServersTest, self).setUp() |
1616 | - self.stubs = stubout.StubOutForTesting() |
1617 | - fakes.FakeAuthManager.reset_fake_data() |
1618 | - fakes.FakeAuthDatabase.data = {} |
1619 | fakes.stub_out_networking(self.stubs) |
1620 | fakes.stub_out_rate_limiting(self.stubs) |
1621 | - fakes.stub_out_auth(self.stubs) |
1622 | fakes.stub_out_key_pair_funcs(self.stubs) |
1623 | fakes.stub_out_image_service(self.stubs) |
1624 | self.stubs.Set(utils, 'gen_uuid', fake_gen_uuid) |
1625 | @@ -249,7 +244,7 @@ |
1626 | self.stubs.Set(nova.db.api, 'instance_get', return_server_by_id) |
1627 | self.stubs.Set(nova.db, 'instance_get_by_uuid', |
1628 | return_server_by_uuid) |
1629 | - self.stubs.Set(nova.db.api, 'instance_get_all_by_user', |
1630 | + self.stubs.Set(nova.db.api, 'instance_get_all_by_project', |
1631 | return_servers) |
1632 | self.stubs.Set(nova.db.api, 'instance_add_security_group', |
1633 | return_security_group) |
1634 | @@ -264,15 +259,9 @@ |
1635 | self.stubs.Set(nova.compute.API, 'resume', fake_compute_api) |
1636 | self.stubs.Set(nova.compute.API, "get_diagnostics", fake_compute_api) |
1637 | self.stubs.Set(nova.compute.API, "get_actions", fake_compute_api) |
1638 | - self.allow_admin = FLAGS.allow_admin_api |
1639 | |
1640 | self.webreq = common.webob_factory('/v1.0/servers') |
1641 | |
1642 | - def tearDown(self): |
1643 | - self.stubs.UnsetAll() |
1644 | - FLAGS.allow_admin_api = self.allow_admin |
1645 | - super(ServersTest, self).tearDown() |
1646 | - |
1647 | def test_get_server_by_id(self): |
1648 | req = webob.Request.blank('/v1.0/servers/1') |
1649 | res = req.get_response(fakes.wsgi_app()) |
1650 | @@ -972,6 +961,7 @@ |
1651 | res = req.get_response(fakes.wsgi_app()) |
1652 | res_dict = json.loads(res.body) |
1653 | |
1654 | + self.assertEqual(len(res_dict['servers']), 5) |
1655 | i = 0 |
1656 | for s in res_dict['servers']: |
1657 | self.assertEqual(s['id'], i) |
1658 | @@ -1035,6 +1025,7 @@ |
1659 | res = req.get_response(fakes.wsgi_app()) |
1660 | res_dict = json.loads(res.body) |
1661 | |
1662 | + self.assertEqual(len(res_dict['servers']), 5) |
1663 | for i, s in enumerate(res_dict['servers']): |
1664 | self.assertEqual(s['id'], i) |
1665 | self.assertEqual(s['name'], 'server%d' % i) |
1666 | @@ -1197,7 +1188,7 @@ |
1667 | def test_create_instance_via_zones(self): |
1668 | """Server generated ReservationID""" |
1669 | self._setup_for_create_instance() |
1670 | - FLAGS.allow_admin_api = True |
1671 | + self.flags(allow_admin_api=True) |
1672 | |
1673 | body = dict(server=dict( |
1674 | name='server_test', imageId=3, flavorId=2, |
1675 | @@ -1219,7 +1210,7 @@ |
1676 | def test_create_instance_via_zones_with_resid(self): |
1677 | """User supplied ReservationID""" |
1678 | self._setup_for_create_instance() |
1679 | - FLAGS.allow_admin_api = True |
1680 | + self.flags(allow_admin_api=True) |
1681 | |
1682 | body = dict(server=dict( |
1683 | name='server_test', imageId=3, flavorId=2, |
1684 | @@ -1728,10 +1719,11 @@ |
1685 | instances - 2 on one host and 3 on another. |
1686 | ''' |
1687 | |
1688 | - def return_servers_with_host(context, user_id=1): |
1689 | - return [stub_instance(i, 1, None, None, i % 2) for i in xrange(5)] |
1690 | + def return_servers_with_host(context, *args, **kwargs): |
1691 | + return [stub_instance(i, 'fake', 'fake', None, None, i % 2) |
1692 | + for i in xrange(5)] |
1693 | |
1694 | - self.stubs.Set(nova.db.api, 'instance_get_all_by_user', |
1695 | + self.stubs.Set(nova.db.api, 'instance_get_all_by_project', |
1696 | return_servers_with_host) |
1697 | |
1698 | req = webob.Request.blank('/v1.0/servers/detail') |
1699 | @@ -1751,7 +1743,7 @@ |
1700 | self.assertEqual(s['flavorId'], 1) |
1701 | |
1702 | def test_server_pause(self): |
1703 | - FLAGS.allow_admin_api = True |
1704 | + self.flags(allow_admin_api=True) |
1705 | body = dict(server=dict( |
1706 | name='server_test', imageId=2, flavorId=2, metadata={}, |
1707 | personality={})) |
1708 | @@ -1763,7 +1755,7 @@ |
1709 | self.assertEqual(res.status_int, 202) |
1710 | |
1711 | def test_server_unpause(self): |
1712 | - FLAGS.allow_admin_api = True |
1713 | + self.flags(allow_admin_api=True) |
1714 | body = dict(server=dict( |
1715 | name='server_test', imageId=2, flavorId=2, metadata={}, |
1716 | personality={})) |
1717 | @@ -1775,7 +1767,7 @@ |
1718 | self.assertEqual(res.status_int, 202) |
1719 | |
1720 | def test_server_suspend(self): |
1721 | - FLAGS.allow_admin_api = True |
1722 | + self.flags(allow_admin_api=True) |
1723 | body = dict(server=dict( |
1724 | name='server_test', imageId=2, flavorId=2, metadata={}, |
1725 | personality={})) |
1726 | @@ -1787,7 +1779,7 @@ |
1727 | self.assertEqual(res.status_int, 202) |
1728 | |
1729 | def test_server_resume(self): |
1730 | - FLAGS.allow_admin_api = True |
1731 | + self.flags(allow_admin_api=True) |
1732 | body = dict(server=dict( |
1733 | name='server_test', imageId=2, flavorId=2, metadata={}, |
1734 | personality={})) |
1735 | @@ -1799,7 +1791,7 @@ |
1736 | self.assertEqual(res.status_int, 202) |
1737 | |
1738 | def test_server_reset_network(self): |
1739 | - FLAGS.allow_admin_api = True |
1740 | + self.flags(allow_admin_api=True) |
1741 | body = dict(server=dict( |
1742 | name='server_test', imageId=2, flavorId=2, metadata={}, |
1743 | personality={})) |
1744 | @@ -1811,7 +1803,7 @@ |
1745 | self.assertEqual(res.status_int, 202) |
1746 | |
1747 | def test_server_inject_network_info(self): |
1748 | - FLAGS.allow_admin_api = True |
1749 | + self.flags(allow_admin_api=True) |
1750 | body = dict(server=dict( |
1751 | name='server_test', imageId=2, flavorId=2, metadata={}, |
1752 | personality={})) |
1753 | @@ -2102,7 +2094,7 @@ |
1754 | self.assertEqual(self.server_delete_called, True) |
1755 | |
1756 | def test_rescue_accepted(self): |
1757 | - FLAGS.allow_admin_api = True |
1758 | + self.flags(allow_admin_api=True) |
1759 | body = {} |
1760 | |
1761 | self.called = False |
1762 | @@ -2121,7 +2113,7 @@ |
1763 | self.assertEqual(res.status_int, 202) |
1764 | |
1765 | def test_rescue_raises_handled(self): |
1766 | - FLAGS.allow_admin_api = True |
1767 | + self.flags(allow_admin_api=True) |
1768 | body = {} |
1769 | |
1770 | def rescue_mock(*args, **kwargs): |
1771 | @@ -2883,18 +2875,8 @@ |
1772 | |
1773 | def setUp(self): |
1774 | super(TestServerInstanceCreation, self).setUp() |
1775 | - self.stubs = stubout.StubOutForTesting() |
1776 | - fakes.FakeAuthManager.auth_data = {} |
1777 | - fakes.FakeAuthDatabase.data = {} |
1778 | - fakes.stub_out_auth(self.stubs) |
1779 | fakes.stub_out_image_service(self.stubs) |
1780 | fakes.stub_out_key_pair_funcs(self.stubs) |
1781 | - self.allow_admin = FLAGS.allow_admin_api |
1782 | - |
1783 | - def tearDown(self): |
1784 | - self.stubs.UnsetAll() |
1785 | - FLAGS.allow_admin_api = self.allow_admin |
1786 | - super(TestServerInstanceCreation, self).tearDown() |
1787 | |
1788 | def _setup_mock_compute_api_for_personality(self): |
1789 | |
1790 | |
1791 | === modified file 'nova/tests/api/openstack/test_shared_ip_groups.py' |
1792 | --- nova/tests/api/openstack/test_shared_ip_groups.py 2011-03-28 18:02:53 +0000 |
1793 | +++ nova/tests/api/openstack/test_shared_ip_groups.py 2011-07-29 19:38:29 +0000 |
1794 | @@ -15,26 +15,13 @@ |
1795 | # License for the specific language governing permissions and limitations |
1796 | # under the License. |
1797 | |
1798 | -import stubout |
1799 | import webob |
1800 | |
1801 | from nova import test |
1802 | -from nova.api.openstack import shared_ip_groups |
1803 | from nova.tests.api.openstack import fakes |
1804 | |
1805 | |
1806 | class SharedIpGroupsTest(test.TestCase): |
1807 | - def setUp(self): |
1808 | - super(SharedIpGroupsTest, self).setUp() |
1809 | - self.stubs = stubout.StubOutForTesting() |
1810 | - fakes.FakeAuthManager.reset_fake_data() |
1811 | - fakes.FakeAuthDatabase.data = {} |
1812 | - fakes.stub_out_auth(self.stubs) |
1813 | - |
1814 | - def tearDown(self): |
1815 | - self.stubs.UnsetAll() |
1816 | - super(SharedIpGroupsTest, self).tearDown() |
1817 | - |
1818 | def test_get_shared_ip_groups(self): |
1819 | req = webob.Request.blank('/v1.0/shared_ip_groups') |
1820 | res = req.get_response(fakes.wsgi_app()) |
1821 | |
1822 | === modified file 'nova/tests/api/openstack/test_users.py' |
1823 | --- nova/tests/api/openstack/test_users.py 2011-03-16 19:15:57 +0000 |
1824 | +++ nova/tests/api/openstack/test_users.py 2011-07-29 19:38:29 +0000 |
1825 | @@ -15,7 +15,6 @@ |
1826 | |
1827 | import json |
1828 | |
1829 | -import stubout |
1830 | import webob |
1831 | |
1832 | from nova import flags |
1833 | @@ -41,7 +40,7 @@ |
1834 | class UsersTest(test.TestCase): |
1835 | def setUp(self): |
1836 | super(UsersTest, self).setUp() |
1837 | - self.stubs = stubout.StubOutForTesting() |
1838 | + self.flags(allow_admin_api=True) |
1839 | self.stubs.Set(users.Controller, '__init__', |
1840 | fake_init) |
1841 | self.stubs.Set(users.Controller, '_check_admin', |
1842 | @@ -58,16 +57,10 @@ |
1843 | fakes.stub_out_auth(self.stubs) |
1844 | |
1845 | self.allow_admin = FLAGS.allow_admin_api |
1846 | - FLAGS.allow_admin_api = True |
1847 | fakemgr = fakes.FakeAuthManager() |
1848 | fakemgr.add_user(User('id1', 'guy1', 'acc1', 'secret1', False)) |
1849 | fakemgr.add_user(User('id2', 'guy2', 'acc2', 'secret2', True)) |
1850 | |
1851 | - def tearDown(self): |
1852 | - self.stubs.UnsetAll() |
1853 | - FLAGS.allow_admin_api = self.allow_admin |
1854 | - super(UsersTest, self).tearDown() |
1855 | - |
1856 | def test_get_user_list(self): |
1857 | req = webob.Request.blank('/v1.0/users') |
1858 | res = req.get_response(fakes.wsgi_app()) |
1859 | |
1860 | === modified file 'nova/tests/api/openstack/test_zones.py' |
1861 | --- nova/tests/api/openstack/test_zones.py 2011-06-20 14:45:21 +0000 |
1862 | +++ nova/tests/api/openstack/test_zones.py 2011-07-29 19:38:29 +0000 |
1863 | @@ -95,31 +95,15 @@ |
1864 | class ZonesTest(test.TestCase): |
1865 | def setUp(self): |
1866 | super(ZonesTest, self).setUp() |
1867 | - self.stubs = stubout.StubOutForTesting() |
1868 | - fakes.FakeAuthManager.reset_fake_data() |
1869 | - fakes.FakeAuthDatabase.data = {} |
1870 | + self.flags(allow_admin_api=True) |
1871 | fakes.stub_out_networking(self.stubs) |
1872 | fakes.stub_out_rate_limiting(self.stubs) |
1873 | - fakes.stub_out_auth(self.stubs) |
1874 | - |
1875 | - self.allow_admin = FLAGS.allow_admin_api |
1876 | - FLAGS.allow_admin_api = True |
1877 | |
1878 | self.stubs.Set(nova.db, 'zone_get', zone_get) |
1879 | self.stubs.Set(nova.db, 'zone_update', zone_update) |
1880 | self.stubs.Set(nova.db, 'zone_create', zone_create) |
1881 | self.stubs.Set(nova.db, 'zone_delete', zone_delete) |
1882 | |
1883 | - self.old_zone_name = FLAGS.zone_name |
1884 | - self.old_zone_capabilities = FLAGS.zone_capabilities |
1885 | - |
1886 | - def tearDown(self): |
1887 | - self.stubs.UnsetAll() |
1888 | - FLAGS.allow_admin_api = self.allow_admin |
1889 | - FLAGS.zone_name = self.old_zone_name |
1890 | - FLAGS.zone_capabilities = self.old_zone_capabilities |
1891 | - super(ZonesTest, self).tearDown() |
1892 | - |
1893 | def test_get_zone_list_scheduler(self): |
1894 | self.stubs.Set(api, '_call_scheduler', zone_get_all_scheduler) |
1895 | req = webob.Request.blank('/v1.0/zones') |
1896 | @@ -190,8 +174,8 @@ |
1897 | self.assertFalse('username' in res_dict['zone']) |
1898 | |
1899 | def test_zone_info(self): |
1900 | - FLAGS.zone_name = 'darksecret' |
1901 | - FLAGS.zone_capabilities = ['cap1=a;b', 'cap2=c;d'] |
1902 | + caps = ['cap1=a;b', 'cap2=c;d'] |
1903 | + self.flags(zone_name='darksecret', zone_capabilities=caps) |
1904 | self.stubs.Set(api, '_call_scheduler', zone_capabilities) |
1905 | |
1906 | body = dict(zone=dict(username='zeb', password='sneaky')) |
1907 | @@ -205,7 +189,8 @@ |
1908 | self.assertEqual(res_dict['zone']['cap2'], 'c;d') |
1909 | |
1910 | def test_zone_select(self): |
1911 | - FLAGS.build_plan_encryption_key = 'c286696d887c9aa0611bbb3e2025a45a' |
1912 | + key = 'c286696d887c9aa0611bbb3e2025a45a' |
1913 | + self.flags(build_plan_encryption_key=key) |
1914 | self.stubs.Set(api, 'select', zone_select) |
1915 | |
1916 | req = webob.Request.blank('/v1.0/zones/select') |
1917 | |
1918 | === modified file 'nova/tests/hyperv_unittest.py' |
1919 | --- nova/tests/hyperv_unittest.py 2011-03-18 13:56:05 +0000 |
1920 | +++ nova/tests/hyperv_unittest.py 2011-07-29 19:38:29 +0000 |
1921 | @@ -23,7 +23,6 @@ |
1922 | from nova import db |
1923 | from nova import flags |
1924 | from nova import test |
1925 | -from nova.auth import manager |
1926 | from nova.virt import hyperv |
1927 | |
1928 | FLAGS = flags.FLAGS |
1929 | @@ -34,11 +33,9 @@ |
1930 | """Test cases for the Hyper-V driver""" |
1931 | def setUp(self): |
1932 | super(HyperVTestCase, self).setUp() |
1933 | - self.manager = manager.AuthManager() |
1934 | - self.user = self.manager.create_user('fake', 'fake', 'fake', |
1935 | - admin=True) |
1936 | - self.project = self.manager.create_project('fake', 'fake', 'fake') |
1937 | - self.context = context.RequestContext(self.user, self.project) |
1938 | + self.user_id = 'fake' |
1939 | + self.project_id = 'fake' |
1940 | + self.context = context.RequestContext(self.user_id, self.project_id) |
1941 | |
1942 | def test_create_destroy(self): |
1943 | """Create a VM and destroy it""" |
1944 | |
1945 | === modified file 'nova/tests/scheduler/test_scheduler.py' |
1946 | --- nova/tests/scheduler/test_scheduler.py 2011-06-30 19:20:59 +0000 |
1947 | +++ nova/tests/scheduler/test_scheduler.py 2011-07-29 19:38:29 +0000 |
1948 | @@ -23,7 +23,6 @@ |
1949 | import mox |
1950 | import novaclient.exceptions |
1951 | import stubout |
1952 | -import webob |
1953 | |
1954 | from mox import IgnoreArg |
1955 | from nova import context |
1956 | @@ -34,12 +33,10 @@ |
1957 | from nova import test |
1958 | from nova import rpc |
1959 | from nova import utils |
1960 | -from nova.auth import manager as auth_manager |
1961 | from nova.scheduler import api |
1962 | from nova.scheduler import manager |
1963 | from nova.scheduler import driver |
1964 | from nova.compute import power_state |
1965 | -from nova.db.sqlalchemy import models |
1966 | |
1967 | |
1968 | FLAGS = flags.FLAGS |
1969 | @@ -250,23 +247,17 @@ |
1970 | volume_driver='nova.volume.driver.FakeISCSIDriver', |
1971 | scheduler_driver='nova.scheduler.simple.SimpleScheduler') |
1972 | self.scheduler = manager.SchedulerManager() |
1973 | - self.manager = auth_manager.AuthManager() |
1974 | - self.user = self.manager.create_user('fake', 'fake', 'fake') |
1975 | - self.project = self.manager.create_project('fake', 'fake', 'fake') |
1976 | self.context = context.get_admin_context() |
1977 | - |
1978 | - def tearDown(self): |
1979 | - self.manager.delete_user(self.user) |
1980 | - self.manager.delete_project(self.project) |
1981 | - super(SimpleDriverTestCase, self).tearDown() |
1982 | + self.user_id = 'fake' |
1983 | + self.project_id = 'fake' |
1984 | |
1985 | def _create_instance(self, **kwargs): |
1986 | """Create a test instance""" |
1987 | inst = {} |
1988 | inst['image_id'] = 1 |
1989 | inst['reservation_id'] = 'r-fakeres' |
1990 | - inst['user_id'] = self.user.id |
1991 | - inst['project_id'] = self.project.id |
1992 | + inst['user_id'] = self.user_id |
1993 | + inst['project_id'] = self.project_id |
1994 | inst['instance_type_id'] = '1' |
1995 | inst['vcpus'] = kwargs.get('vcpus', 1) |
1996 | inst['ami_launch_index'] = 0 |
1997 | |
1998 | === modified file 'nova/tests/test_access.py' |
1999 | --- nova/tests/test_access.py 2011-01-12 19:20:05 +0000 |
2000 | +++ nova/tests/test_access.py 2011-07-29 19:38:29 +0000 |
2001 | @@ -16,7 +16,6 @@ |
2002 | # License for the specific language governing permissions and limitations |
2003 | # under the License. |
2004 | |
2005 | -import unittest |
2006 | import webob |
2007 | |
2008 | from nova import context |
2009 | @@ -41,7 +40,7 @@ |
2010 | class AccessTestCase(test.TestCase): |
2011 | def _env_for(self, ctxt, action): |
2012 | env = {} |
2013 | - env['ec2.context'] = ctxt |
2014 | + env['nova.context'] = ctxt |
2015 | env['ec2.request'] = FakeApiRequest(action) |
2016 | return env |
2017 | |
2018 | @@ -93,7 +92,11 @@ |
2019 | super(AccessTestCase, self).tearDown() |
2020 | |
2021 | def response_status(self, user, methodName): |
2022 | - ctxt = context.RequestContext(user, self.project) |
2023 | + roles = manager.AuthManager().get_active_roles(user, self.project) |
2024 | + ctxt = context.RequestContext(user.id, |
2025 | + self.project.id, |
2026 | + is_admin=user.is_admin(), |
2027 | + roles=roles) |
2028 | environ = self._env_for(ctxt, methodName) |
2029 | req = webob.Request.blank('/', environ) |
2030 | resp = req.get_response(self.mw) |
2031 | @@ -105,30 +108,26 @@ |
2032 | def shouldDeny(self, user, methodName): |
2033 | self.assertEqual(401, self.response_status(user, methodName)) |
2034 | |
2035 | - def test_001_allow_all(self): |
2036 | + def test_allow_all(self): |
2037 | users = [self.testadmin, self.testpmsys, self.testnet, self.testsys] |
2038 | for user in users: |
2039 | self.shouldAllow(user, '_allow_all') |
2040 | |
2041 | - def test_002_allow_none(self): |
2042 | + def test_allow_none(self): |
2043 | self.shouldAllow(self.testadmin, '_allow_none') |
2044 | users = [self.testpmsys, self.testnet, self.testsys] |
2045 | for user in users: |
2046 | self.shouldDeny(user, '_allow_none') |
2047 | |
2048 | - def test_003_allow_project_manager(self): |
2049 | + def test_allow_project_manager(self): |
2050 | for user in [self.testadmin, self.testpmsys]: |
2051 | self.shouldAllow(user, '_allow_project_manager') |
2052 | for user in [self.testnet, self.testsys]: |
2053 | self.shouldDeny(user, '_allow_project_manager') |
2054 | |
2055 | - def test_004_allow_sys_and_net(self): |
2056 | + def test_allow_sys_and_net(self): |
2057 | for user in [self.testadmin, self.testnet, self.testsys]: |
2058 | self.shouldAllow(user, '_allow_sys_and_net') |
2059 | # denied because it doesn't have the per project sysadmin |
2060 | for user in [self.testpmsys]: |
2061 | self.shouldDeny(user, '_allow_sys_and_net') |
2062 | - |
2063 | -if __name__ == "__main__": |
2064 | - # TODO: Implement use_fake as an option |
2065 | - unittest.main() |
2066 | |
2067 | === modified file 'nova/tests/test_adminapi.py' |
2068 | --- nova/tests/test_adminapi.py 2011-07-26 23:29:50 +0000 |
2069 | +++ nova/tests/test_adminapi.py 2011-07-29 19:38:29 +0000 |
2070 | @@ -25,7 +25,6 @@ |
2071 | from nova import rpc |
2072 | from nova import test |
2073 | from nova import utils |
2074 | -from nova.auth import manager |
2075 | from nova.api.ec2 import admin |
2076 | from nova.image import fake |
2077 | |
2078 | @@ -51,11 +50,11 @@ |
2079 | self.volume = self.start_service('volume') |
2080 | self.image_service = utils.import_object(FLAGS.image_service) |
2081 | |
2082 | - self.manager = manager.AuthManager() |
2083 | - self.user = self.manager.create_user('admin', 'admin', 'admin', True) |
2084 | - self.project = self.manager.create_project('proj', 'admin', 'proj') |
2085 | - self.context = context.RequestContext(user=self.user, |
2086 | - project=self.project) |
2087 | + self.user_id = 'admin' |
2088 | + self.project_id = 'admin' |
2089 | + self.context = context.RequestContext(self.user_id, |
2090 | + self.project_id, |
2091 | + True) |
2092 | |
2093 | def fake_show(meh, context, id): |
2094 | return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1, |
2095 | @@ -73,11 +72,6 @@ |
2096 | |
2097 | self.stubs.Set(rpc, 'cast', finish_cast) |
2098 | |
2099 | - def tearDown(self): |
2100 | - self.manager.delete_project(self.project) |
2101 | - self.manager.delete_user(self.user) |
2102 | - super(AdminApiTestCase, self).tearDown() |
2103 | - |
2104 | def test_block_external_ips(self): |
2105 | """Make sure provider firewall rules are created.""" |
2106 | result = self.api.block_external_addresses(self.context, '1.1.1.1/32') |
2107 | |
2108 | === modified file 'nova/tests/test_api.py' |
2109 | --- nova/tests/test_api.py 2011-07-26 20:49:46 +0000 |
2110 | +++ nova/tests/test_api.py 2011-07-29 19:38:29 +0000 |
2111 | @@ -30,11 +30,11 @@ |
2112 | from nova import context |
2113 | from nova import exception |
2114 | from nova import test |
2115 | +from nova import wsgi |
2116 | from nova.api import ec2 |
2117 | from nova.api.ec2 import apirequest |
2118 | from nova.api.ec2 import cloud |
2119 | from nova.api.ec2 import ec2utils |
2120 | -from nova.auth import manager |
2121 | |
2122 | |
2123 | class FakeHttplibSocket(object): |
2124 | @@ -192,10 +192,13 @@ |
2125 | """Unit test for the cloud controller on an EC2 API""" |
2126 | def setUp(self): |
2127 | super(ApiEc2TestCase, self).setUp() |
2128 | - self.manager = manager.AuthManager() |
2129 | self.host = '127.0.0.1' |
2130 | - self.app = ec2.Authenticate(ec2.Requestify(ec2.Executor(), |
2131 | - 'nova.api.ec2.cloud.CloudController')) |
2132 | + # NOTE(vish): skipping the Authorizer |
2133 | + roles = ['sysadmin', 'netadmin'] |
2134 | + ctxt = context.RequestContext('fake', 'fake', roles=roles) |
2135 | + self.app = wsgi.InjectContext(ctxt, |
2136 | + ec2.Requestify(ec2.Authorizer(ec2.Executor()), |
2137 | + 'nova.api.ec2.cloud.CloudController')) |
2138 | |
2139 | def expect_http(self, host=None, is_secure=False, api_version=None): |
2140 | """Returns a new EC2 connection""" |
2141 | @@ -246,39 +249,25 @@ |
2142 | self.expect_http(api_version='2010-10-30') |
2143 | self.mox.ReplayAll() |
2144 | |
2145 | - user = self.manager.create_user('fake', 'fake', 'fake') |
2146 | - project = self.manager.create_project('fake', 'fake', 'fake') |
2147 | - |
2148 | # Any request should be fine |
2149 | self.ec2.get_all_instances() |
2150 | self.assertTrue(self.ec2.APIVersion in self.http.getresponsebody(), |
2151 | 'The version in the xmlns of the response does ' |
2152 | 'not match the API version given in the request.') |
2153 | |
2154 | - self.manager.delete_project(project) |
2155 | - self.manager.delete_user(user) |
2156 | - |
2157 | def test_describe_instances(self): |
2158 | """Test that, after creating a user and a project, the describe |
2159 | instances call to the API works properly""" |
2160 | self.expect_http() |
2161 | self.mox.ReplayAll() |
2162 | - user = self.manager.create_user('fake', 'fake', 'fake') |
2163 | - project = self.manager.create_project('fake', 'fake', 'fake') |
2164 | self.assertEqual(self.ec2.get_all_instances(), []) |
2165 | - self.manager.delete_project(project) |
2166 | - self.manager.delete_user(user) |
2167 | |
2168 | def test_terminate_invalid_instance(self): |
2169 | """Attempt to terminate an invalid instance""" |
2170 | self.expect_http() |
2171 | self.mox.ReplayAll() |
2172 | - user = self.manager.create_user('fake', 'fake', 'fake') |
2173 | - project = self.manager.create_project('fake', 'fake', 'fake') |
2174 | self.assertRaises(EC2ResponseError, self.ec2.terminate_instances, |
2175 | "i-00000005") |
2176 | - self.manager.delete_project(project) |
2177 | - self.manager.delete_user(user) |
2178 | |
2179 | def test_get_all_key_pairs(self): |
2180 | """Test that, after creating a user and project and generating |
2181 | @@ -287,16 +276,12 @@ |
2182 | self.mox.ReplayAll() |
2183 | keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd") \ |
2184 | for x in range(random.randint(4, 8))) |
2185 | - user = self.manager.create_user('fake', 'fake', 'fake') |
2186 | - project = self.manager.create_project('fake', 'fake', 'fake') |
2187 | # NOTE(vish): create depends on pool, so call helper directly |
2188 | - cloud._gen_key(context.get_admin_context(), user.id, keyname) |
2189 | + cloud._gen_key(context.get_admin_context(), 'fake', keyname) |
2190 | |
2191 | rv = self.ec2.get_all_key_pairs() |
2192 | results = [k for k in rv if k.name == keyname] |
2193 | self.assertEquals(len(results), 1) |
2194 | - self.manager.delete_project(project) |
2195 | - self.manager.delete_user(user) |
2196 | |
2197 | def test_create_duplicate_key_pair(self): |
2198 | """Test that, after successfully generating a keypair, |
2199 | @@ -305,8 +290,6 @@ |
2200 | self.mox.ReplayAll() |
2201 | keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd") \ |
2202 | for x in range(random.randint(4, 8))) |
2203 | - user = self.manager.create_user('fake', 'fake', 'fake') |
2204 | - project = self.manager.create_project('fake', 'fake', 'fake') |
2205 | # NOTE(vish): create depends on pool, so call helper directly |
2206 | self.ec2.create_key_pair('test') |
2207 | |
2208 | @@ -325,27 +308,16 @@ |
2209 | """Test that we can retrieve security groups""" |
2210 | self.expect_http() |
2211 | self.mox.ReplayAll() |
2212 | - user = self.manager.create_user('fake', 'fake', 'fake', admin=True) |
2213 | - project = self.manager.create_project('fake', 'fake', 'fake') |
2214 | |
2215 | rv = self.ec2.get_all_security_groups() |
2216 | |
2217 | self.assertEquals(len(rv), 1) |
2218 | self.assertEquals(rv[0].name, 'default') |
2219 | |
2220 | - self.manager.delete_project(project) |
2221 | - self.manager.delete_user(user) |
2222 | - |
2223 | def test_create_delete_security_group(self): |
2224 | """Test that we can create a security group""" |
2225 | self.expect_http() |
2226 | self.mox.ReplayAll() |
2227 | - user = self.manager.create_user('fake', 'fake', 'fake', admin=True) |
2228 | - project = self.manager.create_project('fake', 'fake', 'fake') |
2229 | - |
2230 | - # At the moment, you need both of these to actually be netadmin |
2231 | - self.manager.add_role('fake', 'netadmin') |
2232 | - project.add_role('fake', 'netadmin') |
2233 | |
2234 | security_group_name = "".join(random.choice("sdiuisudfsdcnpaqwertasd") |
2235 | for x in range(random.randint(4, 8))) |
2236 | @@ -364,9 +336,6 @@ |
2237 | |
2238 | self.ec2.delete_security_group(security_group_name) |
2239 | |
2240 | - self.manager.delete_project(project) |
2241 | - self.manager.delete_user(user) |
2242 | - |
2243 | def test_authorize_revoke_security_group_cidr(self): |
2244 | """ |
2245 | Test that we can add and remove CIDR based rules |
2246 | @@ -374,12 +343,6 @@ |
2247 | """ |
2248 | self.expect_http() |
2249 | self.mox.ReplayAll() |
2250 | - user = self.manager.create_user('fake', 'fake', 'fake') |
2251 | - project = self.manager.create_project('fake', 'fake', 'fake') |
2252 | - |
2253 | - # At the moment, you need both of these to actually be netadmin |
2254 | - self.manager.add_role('fake', 'netadmin') |
2255 | - project.add_role('fake', 'netadmin') |
2256 | |
2257 | security_group_name = "".join(random.choice("sdiuisudfsdcnpaqwertasd") |
2258 | for x in range(random.randint(4, 8))) |
2259 | @@ -426,9 +389,6 @@ |
2260 | self.assertEqual(len(rv), 1) |
2261 | self.assertEqual(rv[0].name, 'default') |
2262 | |
2263 | - self.manager.delete_project(project) |
2264 | - self.manager.delete_user(user) |
2265 | - |
2266 | return |
2267 | |
2268 | def test_authorize_revoke_security_group_cidr_v6(self): |
2269 | @@ -438,12 +398,6 @@ |
2270 | """ |
2271 | self.expect_http() |
2272 | self.mox.ReplayAll() |
2273 | - user = self.manager.create_user('fake', 'fake', 'fake') |
2274 | - project = self.manager.create_project('fake', 'fake', 'fake') |
2275 | - |
2276 | - # At the moment, you need both of these to actually be netadmin |
2277 | - self.manager.add_role('fake', 'netadmin') |
2278 | - project.add_role('fake', 'netadmin') |
2279 | |
2280 | security_group_name = "".join(random.choice("sdiuisudfsdcnpaqwertasd") |
2281 | for x in range(random.randint(4, 8))) |
2282 | @@ -489,9 +443,6 @@ |
2283 | self.assertEqual(len(rv), 1) |
2284 | self.assertEqual(rv[0].name, 'default') |
2285 | |
2286 | - self.manager.delete_project(project) |
2287 | - self.manager.delete_user(user) |
2288 | - |
2289 | return |
2290 | |
2291 | def test_authorize_revoke_security_group_foreign_group(self): |
2292 | @@ -501,12 +452,6 @@ |
2293 | """ |
2294 | self.expect_http() |
2295 | self.mox.ReplayAll() |
2296 | - user = self.manager.create_user('fake', 'fake', 'fake', admin=True) |
2297 | - project = self.manager.create_project('fake', 'fake', 'fake') |
2298 | - |
2299 | - # At the moment, you need both of these to actually be netadmin |
2300 | - self.manager.add_role('fake', 'netadmin') |
2301 | - project.add_role('fake', 'netadmin') |
2302 | |
2303 | rand_string = 'sdiuisudfsdcnpaqwertasd' |
2304 | security_group_name = "".join(random.choice(rand_string) |
2305 | @@ -560,8 +505,3 @@ |
2306 | self.mox.ReplayAll() |
2307 | |
2308 | self.ec2.delete_security_group(security_group_name) |
2309 | - |
2310 | - self.manager.delete_project(project) |
2311 | - self.manager.delete_user(user) |
2312 | - |
2313 | - return |
2314 | |
2315 | === modified file 'nova/tests/test_auth.py' |
2316 | --- nova/tests/test_auth.py 2011-06-28 14:52:22 +0000 |
2317 | +++ nova/tests/test_auth.py 2011-07-29 19:38:29 +0000 |
2318 | @@ -102,7 +102,7 @@ |
2319 | self.assertEqual('classified', u.secret) |
2320 | self.assertEqual('private-party', u.access) |
2321 | |
2322 | - def test_004_signature_is_valid(self): |
2323 | + def test_signature_is_valid(self): |
2324 | with user_generator(self.manager, name='admin', secret='admin', |
2325 | access='admin'): |
2326 | with project_generator(self.manager, name="admin", |
2327 | @@ -141,15 +141,14 @@ |
2328 | '127.0.0.1', |
2329 | '/services/Cloud')) |
2330 | |
2331 | - def test_005_can_get_credentials(self): |
2332 | - return |
2333 | - credentials = self.manager.get_user('test1').get_credentials() |
2334 | - self.assertEqual(credentials, |
2335 | - 'export EC2_ACCESS_KEY="access"\n' + |
2336 | - 'export EC2_SECRET_KEY="secret"\n' + |
2337 | - 'export EC2_URL="http://127.0.0.1:8773/services/Cloud"\n' + |
2338 | - 'export S3_URL="http://127.0.0.1:3333/"\n' + |
2339 | - 'export EC2_USER_ID="test1"\n') |
2340 | + def test_can_get_credentials(self): |
2341 | + st = {'access': 'access', 'secret': 'secret'} |
2342 | + with user_and_project_generator(self.manager, user_state=st) as (u, p): |
2343 | + credentials = self.manager.get_environment_rc(u, p) |
2344 | + LOG.debug(credentials) |
2345 | + self.assertTrue('export EC2_ACCESS_KEY="access:testproj"\n' |
2346 | + in credentials) |
2347 | + self.assertTrue('export EC2_SECRET_KEY="secret"\n' in credentials) |
2348 | |
2349 | def test_can_list_users(self): |
2350 | with user_generator(self.manager): |
2351 | |
2352 | === modified file 'nova/tests/test_cloud.py' |
2353 | --- nova/tests/test_cloud.py 2011-07-29 06:20:40 +0000 |
2354 | +++ nova/tests/test_cloud.py 2011-07-29 19:38:29 +0000 |
2355 | @@ -34,7 +34,6 @@ |
2356 | from nova import rpc |
2357 | from nova import test |
2358 | from nova import utils |
2359 | -from nova.auth import manager |
2360 | from nova.api.ec2 import cloud |
2361 | from nova.api.ec2 import ec2utils |
2362 | from nova.image import fake |
2363 | @@ -62,12 +61,11 @@ |
2364 | self.volume = self.start_service('volume') |
2365 | self.image_service = utils.import_object(FLAGS.image_service) |
2366 | |
2367 | - self.manager = manager.AuthManager() |
2368 | - self.user = self.manager.create_user('admin', 'admin', 'admin', True) |
2369 | - self.project = self.manager.create_project('proj', 'admin', 'proj') |
2370 | - self.context = context.RequestContext(user=self.user, |
2371 | - project=self.project) |
2372 | - host = self.network.host |
2373 | + self.user_id = 'fake' |
2374 | + self.project_id = 'fake' |
2375 | + self.context = context.RequestContext(self.user_id, |
2376 | + self.project_id, |
2377 | + True) |
2378 | |
2379 | def fake_show(meh, context, id): |
2380 | return {'id': 1, 'container_format': 'ami', |
2381 | @@ -87,17 +85,15 @@ |
2382 | self.stubs.Set(rpc, 'cast', finish_cast) |
2383 | |
2384 | def tearDown(self): |
2385 | - networks = db.project_get_networks(self.context, self.project.id, |
2386 | + networks = db.project_get_networks(self.context, self.project_id, |
2387 | associate=False) |
2388 | for network in networks: |
2389 | db.network_disassociate(self.context, network['id']) |
2390 | - self.manager.delete_project(self.project) |
2391 | - self.manager.delete_user(self.user) |
2392 | super(CloudTestCase, self).tearDown() |
2393 | |
2394 | def _create_key(self, name): |
2395 | # NOTE(vish): create depends on pool, so just call helper directly |
2396 | - return cloud._gen_key(self.context, self.context.user.id, name) |
2397 | + return cloud._gen_key(self.context, self.context.user_id, name) |
2398 | |
2399 | def test_describe_regions(self): |
2400 | """Makes sure describe regions runs without raising an exception""" |
2401 | @@ -982,7 +978,7 @@ |
2402 | key = RSA.load_key_string(private_key, callback=lambda: None) |
2403 | bio = BIO.MemoryBuffer() |
2404 | public_key = db.key_pair_get(self.context, |
2405 | - self.context.user.id, |
2406 | + self.context.user_id, |
2407 | 'test')['public_key'] |
2408 | key.save_pub_key_bio(bio) |
2409 | converted = crypto.ssl_pub_to_ssh_pub(bio.read()) |
2410 | @@ -1006,7 +1002,7 @@ |
2411 | 'mytestfprint') |
2412 | self.assertTrue(result1) |
2413 | keydata = db.key_pair_get(self.context, |
2414 | - self.context.user.id, |
2415 | + self.context.user_id, |
2416 | 'testimportkey1') |
2417 | self.assertEqual('mytestpubkey', keydata['public_key']) |
2418 | self.assertEqual('mytestfprint', keydata['fingerprint']) |
2419 | @@ -1023,7 +1019,7 @@ |
2420 | dummypub) |
2421 | self.assertTrue(result2) |
2422 | keydata = db.key_pair_get(self.context, |
2423 | - self.context.user.id, |
2424 | + self.context.user_id, |
2425 | 'testimportkey2') |
2426 | self.assertEqual(dummypub, keydata['public_key']) |
2427 | self.assertEqual(dummyfprint, keydata['fingerprint']) |
2428 | |
2429 | === modified file 'nova/tests/test_compute.py' |
2430 | --- nova/tests/test_compute.py 2011-07-27 22:02:49 +0000 |
2431 | +++ nova/tests/test_compute.py 2011-07-29 19:38:29 +0000 |
2432 | @@ -19,10 +19,6 @@ |
2433 | Tests For Compute |
2434 | """ |
2435 | |
2436 | -import mox |
2437 | -import stubout |
2438 | - |
2439 | -from nova.auth import manager |
2440 | from nova import compute |
2441 | from nova.compute import instance_types |
2442 | from nova.compute import manager as compute_manager |
2443 | @@ -67,10 +63,9 @@ |
2444 | network_manager='nova.network.manager.FlatManager') |
2445 | self.compute = utils.import_object(FLAGS.compute_manager) |
2446 | self.compute_api = compute.API() |
2447 | - self.manager = manager.AuthManager() |
2448 | - self.user = self.manager.create_user('fake', 'fake', 'fake') |
2449 | - self.project = self.manager.create_project('fake', 'fake', 'fake') |
2450 | - self.context = context.RequestContext('fake', 'fake', False) |
2451 | + self.user_id = 'fake' |
2452 | + self.project_id = 'fake' |
2453 | + self.context = context.RequestContext(self.user_id, self.project_id) |
2454 | test_notifier.NOTIFICATIONS = [] |
2455 | |
2456 | def fake_show(meh, context, id): |
2457 | @@ -78,19 +73,14 @@ |
2458 | |
2459 | self.stubs.Set(nova.image.fake._FakeImageService, 'show', fake_show) |
2460 | |
2461 | - def tearDown(self): |
2462 | - self.manager.delete_user(self.user) |
2463 | - self.manager.delete_project(self.project) |
2464 | - super(ComputeTestCase, self).tearDown() |
2465 | - |
2466 | def _create_instance(self, params={}): |
2467 | """Create a test instance""" |
2468 | inst = {} |
2469 | inst['image_ref'] = 1 |
2470 | inst['reservation_id'] = 'r-fakeres' |
2471 | inst['launch_time'] = '10' |
2472 | - inst['user_id'] = self.user.id |
2473 | - inst['project_id'] = self.project.id |
2474 | + inst['user_id'] = self.user_id |
2475 | + inst['project_id'] = self.project_id |
2476 | type_id = instance_types.get_instance_type_by_name('m1.tiny')['id'] |
2477 | inst['instance_type_id'] = type_id |
2478 | inst['ami_launch_index'] = 0 |
2479 | @@ -115,8 +105,8 @@ |
2480 | def _create_group(self): |
2481 | values = {'name': 'testgroup', |
2482 | 'description': 'testgroup', |
2483 | - 'user_id': self.user.id, |
2484 | - 'project_id': self.project.id} |
2485 | + 'user_id': self.user_id, |
2486 | + 'project_id': self.project_id} |
2487 | return db.security_group_create(self.context, values) |
2488 | |
2489 | def _get_dummy_instance(self): |
2490 | @@ -350,8 +340,8 @@ |
2491 | self.assertEquals(msg['priority'], 'INFO') |
2492 | self.assertEquals(msg['event_type'], 'compute.instance.create') |
2493 | payload = msg['payload'] |
2494 | - self.assertEquals(payload['tenant_id'], self.project.id) |
2495 | - self.assertEquals(payload['user_id'], self.user.id) |
2496 | + self.assertEquals(payload['tenant_id'], self.project_id) |
2497 | + self.assertEquals(payload['user_id'], self.user_id) |
2498 | self.assertEquals(payload['instance_id'], instance_id) |
2499 | self.assertEquals(payload['instance_type'], 'm1.tiny') |
2500 | type_id = instance_types.get_instance_type_by_name('m1.tiny')['id'] |
2501 | @@ -374,8 +364,8 @@ |
2502 | self.assertEquals(msg['priority'], 'INFO') |
2503 | self.assertEquals(msg['event_type'], 'compute.instance.delete') |
2504 | payload = msg['payload'] |
2505 | - self.assertEquals(payload['tenant_id'], self.project.id) |
2506 | - self.assertEquals(payload['user_id'], self.user.id) |
2507 | + self.assertEquals(payload['tenant_id'], self.project_id) |
2508 | + self.assertEquals(payload['user_id'], self.user_id) |
2509 | self.assertEquals(payload['instance_id'], instance_id) |
2510 | self.assertEquals(payload['instance_type'], 'm1.tiny') |
2511 | type_id = instance_types.get_instance_type_by_name('m1.tiny')['id'] |
2512 | @@ -457,8 +447,8 @@ |
2513 | self.assertEquals(msg['priority'], 'INFO') |
2514 | self.assertEquals(msg['event_type'], 'compute.instance.resize.prep') |
2515 | payload = msg['payload'] |
2516 | - self.assertEquals(payload['tenant_id'], self.project.id) |
2517 | - self.assertEquals(payload['user_id'], self.user.id) |
2518 | + self.assertEquals(payload['tenant_id'], self.project_id) |
2519 | + self.assertEquals(payload['user_id'], self.user_id) |
2520 | self.assertEquals(payload['instance_id'], instance_id) |
2521 | self.assertEquals(payload['instance_type'], 'm1.tiny') |
2522 | type_id = instance_types.get_instance_type_by_name('m1.tiny')['id'] |
2523 | @@ -849,7 +839,6 @@ |
2524 | |
2525 | def test_run_kill_vm(self): |
2526 | """Detect when a vm is terminated behind the scenes""" |
2527 | - self.stubs = stubout.StubOutForTesting() |
2528 | self.stubs.Set(compute_manager.ComputeManager, |
2529 | '_report_driver_status', nop_report_driver_status) |
2530 | |
2531 | |
2532 | === modified file 'nova/tests/test_console.py' |
2533 | --- nova/tests/test_console.py 2011-06-06 17:20:08 +0000 |
2534 | +++ nova/tests/test_console.py 2011-07-29 19:38:29 +0000 |
2535 | @@ -26,10 +26,9 @@ |
2536 | from nova import flags |
2537 | from nova import test |
2538 | from nova import utils |
2539 | -from nova.auth import manager |
2540 | -from nova.console import manager as console_manager |
2541 | |
2542 | FLAGS = flags.FLAGS |
2543 | +flags.DECLARE('console_driver', 'nova.console.manager') |
2544 | |
2545 | |
2546 | class ConsoleTestCase(test.TestCase): |
2547 | @@ -39,17 +38,11 @@ |
2548 | self.flags(console_driver='nova.console.fake.FakeConsoleProxy', |
2549 | stub_compute=True) |
2550 | self.console = utils.import_object(FLAGS.console_manager) |
2551 | - self.manager = manager.AuthManager() |
2552 | - self.user = self.manager.create_user('fake', 'fake', 'fake') |
2553 | - self.project = self.manager.create_project('fake', 'fake', 'fake') |
2554 | - self.context = context.get_admin_context() |
2555 | + self.user_id = 'fake' |
2556 | + self.project_id = 'fake' |
2557 | + self.context = context.RequestContext(self.user_id, self.project_id) |
2558 | self.host = 'test_compute_host' |
2559 | |
2560 | - def tearDown(self): |
2561 | - self.manager.delete_user(self.user) |
2562 | - self.manager.delete_project(self.project) |
2563 | - super(ConsoleTestCase, self).tearDown() |
2564 | - |
2565 | def _create_instance(self): |
2566 | """Create a test instance""" |
2567 | inst = {} |
2568 | @@ -58,8 +51,8 @@ |
2569 | inst['image_id'] = 1 |
2570 | inst['reservation_id'] = 'r-fakeres' |
2571 | inst['launch_time'] = '10' |
2572 | - inst['user_id'] = self.user.id |
2573 | - inst['project_id'] = self.project.id |
2574 | + inst['user_id'] = self.user_id |
2575 | + inst['project_id'] = self.project_id |
2576 | inst['instance_type_id'] = 1 |
2577 | inst['ami_launch_index'] = 0 |
2578 | return db.instance_create(self.context, inst)['id'] |
2579 | |
2580 | === modified file 'nova/tests/test_db_api.py' |
2581 | --- nova/tests/test_db_api.py 2011-07-28 16:01:38 +0000 |
2582 | +++ nova/tests/test_db_api.py 2011-07-29 19:38:29 +0000 |
2583 | @@ -22,7 +22,6 @@ |
2584 | from nova import context |
2585 | from nova import db |
2586 | from nova import flags |
2587 | -from nova.auth import manager |
2588 | |
2589 | FLAGS = flags.FLAGS |
2590 | |
2591 | @@ -45,42 +44,35 @@ |
2592 | db.fixed_ip_create(ctxt, fixed_ip) |
2593 | fix_ref = db.fixed_ip_get_by_address(ctxt, ip) |
2594 | db.floating_ip_create(ctxt, {'address': flo_addr, |
2595 | - 'fixed_ip_id': fix_ref.id}) |
2596 | + 'fixed_ip_id': fix_ref['id']}) |
2597 | |
2598 | |
2599 | class DbApiTestCase(test.TestCase): |
2600 | def setUp(self): |
2601 | super(DbApiTestCase, self).setUp() |
2602 | - self.manager = manager.AuthManager() |
2603 | - self.user = self.manager.create_user('admin', 'admin', 'admin', True) |
2604 | - self.project = self.manager.create_project('proj', 'admin', 'proj') |
2605 | - self.context = context.RequestContext(user=self.user, |
2606 | - project=self.project) |
2607 | - |
2608 | - def tearDown(self): |
2609 | - self.manager.delete_project(self.project) |
2610 | - self.manager.delete_user(self.user) |
2611 | - super(DbApiTestCase, self).tearDown() |
2612 | + self.user_id = 'fake' |
2613 | + self.project_id = 'fake' |
2614 | + self.context = context.RequestContext(self.user_id, self.project_id) |
2615 | |
2616 | def test_instance_get_project_vpn(self): |
2617 | - result = db.fixed_ip_get_all(self.context) |
2618 | values = {'instance_type_id': FLAGS.default_instance_type, |
2619 | 'image_ref': FLAGS.vpn_image_id, |
2620 | - 'project_id': self.project.id, |
2621 | + 'project_id': self.project_id |
2622 | } |
2623 | instance = db.instance_create(self.context, values) |
2624 | - result = db.instance_get_project_vpn(self.context, self.project.id) |
2625 | - self.assertEqual(instance.id, result.id) |
2626 | + result = db.instance_get_project_vpn(self.context.elevated(), |
2627 | + self.project_id) |
2628 | + self.assertEqual(instance['id'], result['id']) |
2629 | |
2630 | def test_instance_get_project_vpn_joins(self): |
2631 | - result = db.fixed_ip_get_all(self.context) |
2632 | values = {'instance_type_id': FLAGS.default_instance_type, |
2633 | 'image_ref': FLAGS.vpn_image_id, |
2634 | - 'project_id': self.project.id, |
2635 | + 'project_id': self.project_id |
2636 | } |
2637 | instance = db.instance_create(self.context, values) |
2638 | - _setup_networking(instance.id) |
2639 | - result = db.instance_get_project_vpn(self.context, self.project.id) |
2640 | - self.assertEqual(instance.id, result.id) |
2641 | + _setup_networking(instance['id']) |
2642 | + result = db.instance_get_project_vpn(self.context.elevated(), |
2643 | + self.project_id) |
2644 | + self.assertEqual(instance['id'], result['id']) |
2645 | self.assertEqual(result['fixed_ips'][0]['floating_ips'][0].address, |
2646 | '1.2.1.2') |
2647 | |
2648 | === modified file 'nova/tests/test_libvirt.py' |
2649 | --- nova/tests/test_libvirt.py 2011-07-28 16:01:38 +0000 |
2650 | +++ nova/tests/test_libvirt.py 2011-07-29 19:38:29 +0000 |
2651 | @@ -32,7 +32,6 @@ |
2652 | from nova import test |
2653 | from nova import utils |
2654 | from nova.api.ec2 import cloud |
2655 | -from nova.auth import manager |
2656 | from nova.compute import power_state |
2657 | from nova.virt.libvirt import connection |
2658 | from nova.virt.libvirt import firewall |
2659 | @@ -154,36 +153,15 @@ |
2660 | super(LibvirtConnTestCase, self).setUp() |
2661 | connection._late_load_cheetah() |
2662 | self.flags(fake_call=True) |
2663 | - self.manager = manager.AuthManager() |
2664 | - |
2665 | - try: |
2666 | - pjs = self.manager.get_projects() |
2667 | - pjs = [p for p in pjs if p.name == 'fake'] |
2668 | - if 0 != len(pjs): |
2669 | - self.manager.delete_project(pjs[0]) |
2670 | - |
2671 | - users = self.manager.get_users() |
2672 | - users = [u for u in users if u.name == 'fake'] |
2673 | - if 0 != len(users): |
2674 | - self.manager.delete_user(users[0]) |
2675 | - except Exception, e: |
2676 | - pass |
2677 | - |
2678 | - users = self.manager.get_users() |
2679 | - self.user = self.manager.create_user('fake', 'fake', 'fake', |
2680 | - admin=True) |
2681 | - self.project = self.manager.create_project('fake', 'fake', 'fake') |
2682 | + self.user_id = 'fake' |
2683 | + self.project_id = 'fake' |
2684 | + self.context = context.RequestContext(self.user_id, self.project_id) |
2685 | self.network = utils.import_object(FLAGS.network_manager) |
2686 | self.context = context.get_admin_context() |
2687 | FLAGS.instances_path = '' |
2688 | self.call_libvirt_dependant_setup = False |
2689 | self.test_ip = '10.11.12.13' |
2690 | |
2691 | - def tearDown(self): |
2692 | - self.manager.delete_project(self.project) |
2693 | - self.manager.delete_user(self.user) |
2694 | - super(LibvirtConnTestCase, self).tearDown() |
2695 | - |
2696 | test_instance = {'memory_kb': '1024000', |
2697 | 'basepath': '/some/path', |
2698 | 'bridge_name': 'br100', |
2699 | @@ -441,8 +419,8 @@ |
2700 | self.assertEquals(parameters[1].get('value'), 'fake') |
2701 | |
2702 | def _check_xml_and_container(self, instance): |
2703 | - user_context = context.RequestContext(project=self.project, |
2704 | - user=self.user) |
2705 | + user_context = context.RequestContext(self.user_id, |
2706 | + self.project_id) |
2707 | instance_ref = db.instance_create(user_context, instance) |
2708 | _setup_networking(instance_ref['id'], self.test_ip) |
2709 | |
2710 | @@ -470,11 +448,10 @@ |
2711 | |
2712 | def _check_xml_and_uri(self, instance, expect_ramdisk, expect_kernel, |
2713 | rescue=False): |
2714 | - user_context = context.RequestContext(project=self.project, |
2715 | - user=self.user) |
2716 | + user_context = context.RequestContext(self.user_id, self.project_id) |
2717 | instance_ref = db.instance_create(user_context, instance) |
2718 | network_ref = db.project_get_networks(context.get_admin_context(), |
2719 | - self.project.id)[0] |
2720 | + self.project_id)[0] |
2721 | |
2722 | _setup_networking(instance_ref['id'], self.test_ip) |
2723 | |
2724 | @@ -802,11 +779,9 @@ |
2725 | def setUp(self): |
2726 | super(IptablesFirewallTestCase, self).setUp() |
2727 | |
2728 | - self.manager = manager.AuthManager() |
2729 | - self.user = self.manager.create_user('fake', 'fake', 'fake', |
2730 | - admin=True) |
2731 | - self.project = self.manager.create_project('fake', 'fake', 'fake') |
2732 | - self.context = context.RequestContext('fake', 'fake') |
2733 | + self.user_id = 'fake' |
2734 | + self.project_id = 'fake' |
2735 | + self.context = context.RequestContext(self.user_id, self.project_id) |
2736 | self.network = utils.import_object(FLAGS.network_manager) |
2737 | |
2738 | class FakeLibvirtConnection(object): |
2739 | @@ -832,11 +807,6 @@ |
2740 | connection.libxml2 = __import__('libxml2') |
2741 | return True |
2742 | |
2743 | - def tearDown(self): |
2744 | - self.manager.delete_project(self.project) |
2745 | - self.manager.delete_user(self.user) |
2746 | - super(IptablesFirewallTestCase, self).tearDown() |
2747 | - |
2748 | in_nat_rules = [ |
2749 | '# Generated by iptables-save v1.4.10 on Sat Feb 19 00:03:19 2011', |
2750 | '*nat', |
2751 | @@ -1119,11 +1089,9 @@ |
2752 | class Mock(object): |
2753 | pass |
2754 | |
2755 | - self.manager = manager.AuthManager() |
2756 | - self.user = self.manager.create_user('fake', 'fake', 'fake', |
2757 | - admin=True) |
2758 | - self.project = self.manager.create_project('fake', 'fake', 'fake') |
2759 | - self.context = context.RequestContext(self.user, self.project) |
2760 | + self.user_id = 'fake' |
2761 | + self.project_id = 'fake' |
2762 | + self.context = context.RequestContext(self.user_id, self.project_id) |
2763 | |
2764 | self.fake_libvirt_connection = Mock() |
2765 | |
2766 | @@ -1131,11 +1099,6 @@ |
2767 | self.fw = firewall.NWFilterFirewall( |
2768 | lambda: self.fake_libvirt_connection) |
2769 | |
2770 | - def tearDown(self): |
2771 | - self.manager.delete_project(self.project) |
2772 | - self.manager.delete_user(self.user) |
2773 | - super(NWFilterTestCase, self).tearDown() |
2774 | - |
2775 | def test_cidr_rule_nwfilter_xml(self): |
2776 | cloud_controller = cloud.CloudController() |
2777 | cloud_controller.create_security_group(self.context, |
2778 | |
2779 | === modified file 'nova/tests/test_objectstore.py' |
2780 | --- nova/tests/test_objectstore.py 2011-06-21 15:50:28 +0000 |
2781 | +++ nova/tests/test_objectstore.py 2011-07-29 19:38:29 +0000 |
2782 | @@ -21,8 +21,6 @@ |
2783 | """ |
2784 | |
2785 | import boto |
2786 | -import glob |
2787 | -import hashlib |
2788 | import os |
2789 | import shutil |
2790 | import tempfile |
2791 | @@ -30,12 +28,9 @@ |
2792 | from boto import exception as boto_exception |
2793 | from boto.s3 import connection as s3 |
2794 | |
2795 | -from nova import context |
2796 | -from nova import exception |
2797 | from nova import flags |
2798 | from nova import wsgi |
2799 | from nova import test |
2800 | -from nova.auth import manager |
2801 | from nova.objectstore import s3server |
2802 | |
2803 | |
2804 | @@ -57,15 +52,9 @@ |
2805 | def setUp(self): |
2806 | """Setup users, projects, and start a test server.""" |
2807 | super(S3APITestCase, self).setUp() |
2808 | - self.flags(auth_driver='nova.auth.ldapdriver.FakeLdapDriver', |
2809 | - buckets_path=os.path.join(OSS_TEMPDIR, 'buckets'), |
2810 | + self.flags(buckets_path=os.path.join(OSS_TEMPDIR, 'buckets'), |
2811 | s3_host='127.0.0.1') |
2812 | |
2813 | - self.auth_manager = manager.AuthManager() |
2814 | - self.admin_user = self.auth_manager.create_user('admin', admin=True) |
2815 | - self.admin_project = self.auth_manager.create_project('admin', |
2816 | - self.admin_user) |
2817 | - |
2818 | shutil.rmtree(FLAGS.buckets_path) |
2819 | os.mkdir(FLAGS.buckets_path) |
2820 | |
2821 | @@ -80,8 +69,8 @@ |
2822 | boto.config.add_section('Boto') |
2823 | |
2824 | boto.config.set('Boto', 'num_retries', '0') |
2825 | - conn = s3.S3Connection(aws_access_key_id=self.admin_user.access, |
2826 | - aws_secret_access_key=self.admin_user.secret, |
2827 | + conn = s3.S3Connection(aws_access_key_id='fake', |
2828 | + aws_secret_access_key='fake', |
2829 | host=FLAGS.s3_host, |
2830 | port=FLAGS.s3_port, |
2831 | is_secure=False, |
2832 | @@ -104,11 +93,11 @@ |
2833 | self.assertEquals(buckets[0].name, name, "Wrong name") |
2834 | return True |
2835 | |
2836 | - def test_000_list_buckets(self): |
2837 | + def test_list_buckets(self): |
2838 | """Make sure we are starting with no buckets.""" |
2839 | self._ensure_no_buckets(self.conn.get_all_buckets()) |
2840 | |
2841 | - def test_001_create_and_delete_bucket(self): |
2842 | + def test_create_and_delete_bucket(self): |
2843 | """Test bucket creation and deletion.""" |
2844 | bucket_name = 'testbucket' |
2845 | |
2846 | @@ -117,7 +106,7 @@ |
2847 | self.conn.delete_bucket(bucket_name) |
2848 | self._ensure_no_buckets(self.conn.get_all_buckets()) |
2849 | |
2850 | - def test_002_create_bucket_and_key_and_delete_key_again(self): |
2851 | + def test_create_bucket_and_key_and_delete_key_again(self): |
2852 | """Test key operations on buckets.""" |
2853 | bucket_name = 'testbucket' |
2854 | key_name = 'somekey' |
2855 | @@ -146,8 +135,6 @@ |
2856 | bucket_name) |
2857 | |
2858 | def tearDown(self): |
2859 | - """Tear down auth and test server.""" |
2860 | - self.auth_manager.delete_user('admin') |
2861 | - self.auth_manager.delete_project('admin') |
2862 | + """Tear down test server.""" |
2863 | self.server.stop() |
2864 | super(S3APITestCase, self).tearDown() |
2865 | |
2866 | === modified file 'nova/tests/test_quota.py' |
2867 | --- nova/tests/test_quota.py 2011-07-27 00:40:50 +0000 |
2868 | +++ nova/tests/test_quota.py 2011-07-29 19:38:29 +0000 |
2869 | @@ -20,12 +20,9 @@ |
2870 | from nova import context |
2871 | from nova import db |
2872 | from nova import flags |
2873 | -from nova import network |
2874 | from nova import quota |
2875 | from nova import test |
2876 | -from nova import utils |
2877 | from nova import volume |
2878 | -from nova.auth import manager |
2879 | from nova.compute import instance_types |
2880 | |
2881 | |
2882 | @@ -48,25 +45,20 @@ |
2883 | quota_gigabytes=20, |
2884 | quota_floating_ips=1) |
2885 | |
2886 | - self.manager = manager.AuthManager() |
2887 | - self.user = self.manager.create_user('admin', 'admin', 'admin', True) |
2888 | - self.project = self.manager.create_project('admin', 'admin', 'admin') |
2889 | self.network = self.network = self.start_service('network') |
2890 | - self.context = context.RequestContext(project=self.project, |
2891 | - user=self.user) |
2892 | - |
2893 | - def tearDown(self): |
2894 | - manager.AuthManager().delete_project(self.project) |
2895 | - manager.AuthManager().delete_user(self.user) |
2896 | - super(QuotaTestCase, self).tearDown() |
2897 | + self.user_id = 'admin' |
2898 | + self.project_id = 'admin' |
2899 | + self.context = context.RequestContext(self.user_id, |
2900 | + self.project_id, |
2901 | + True) |
2902 | |
2903 | def _create_instance(self, cores=2): |
2904 | """Create a test instance""" |
2905 | inst = {} |
2906 | inst['image_id'] = 1 |
2907 | inst['reservation_id'] = 'r-fakeres' |
2908 | - inst['user_id'] = self.user.id |
2909 | - inst['project_id'] = self.project.id |
2910 | + inst['user_id'] = self.user_id |
2911 | + inst['project_id'] = self.project_id |
2912 | inst['instance_type_id'] = '3' # m1.large |
2913 | inst['vcpus'] = cores |
2914 | return db.instance_create(self.context, inst)['id'] |
2915 | @@ -74,8 +66,8 @@ |
2916 | def _create_volume(self, size=10): |
2917 | """Create a test volume""" |
2918 | vol = {} |
2919 | - vol['user_id'] = self.user.id |
2920 | - vol['project_id'] = self.project.id |
2921 | + vol['user_id'] = self.user_id |
2922 | + vol['project_id'] = self.project_id |
2923 | vol['size'] = size |
2924 | return db.volume_create(self.context, vol)['id'] |
2925 | |
2926 | @@ -95,15 +87,15 @@ |
2927 | num_instances = quota.allowed_instances(self.context, 100, |
2928 | self._get_instance_type('m1.small')) |
2929 | self.assertEqual(num_instances, 2) |
2930 | - db.quota_create(self.context, self.project.id, 'instances', 10) |
2931 | + db.quota_create(self.context, self.project_id, 'instances', 10) |
2932 | num_instances = quota.allowed_instances(self.context, 100, |
2933 | self._get_instance_type('m1.small')) |
2934 | self.assertEqual(num_instances, 4) |
2935 | - db.quota_create(self.context, self.project.id, 'cores', 100) |
2936 | + db.quota_create(self.context, self.project_id, 'cores', 100) |
2937 | num_instances = quota.allowed_instances(self.context, 100, |
2938 | self._get_instance_type('m1.small')) |
2939 | self.assertEqual(num_instances, 10) |
2940 | - db.quota_create(self.context, self.project.id, 'ram', 3 * 2048) |
2941 | + db.quota_create(self.context, self.project_id, 'ram', 3 * 2048) |
2942 | num_instances = quota.allowed_instances(self.context, 100, |
2943 | self._get_instance_type('m1.small')) |
2944 | self.assertEqual(num_instances, 3) |
2945 | @@ -113,13 +105,13 @@ |
2946 | num_metadata_items = quota.allowed_metadata_items(self.context, |
2947 | too_many_items) |
2948 | self.assertEqual(num_metadata_items, FLAGS.quota_metadata_items) |
2949 | - db.quota_create(self.context, self.project.id, 'metadata_items', 5) |
2950 | + db.quota_create(self.context, self.project_id, 'metadata_items', 5) |
2951 | num_metadata_items = quota.allowed_metadata_items(self.context, |
2952 | too_many_items) |
2953 | self.assertEqual(num_metadata_items, 5) |
2954 | |
2955 | # Cleanup |
2956 | - db.quota_destroy_all_by_project(self.context, self.project.id) |
2957 | + db.quota_destroy_all_by_project(self.context, self.project_id) |
2958 | |
2959 | def test_unlimited_instances(self): |
2960 | FLAGS.quota_instances = 2 |
2961 | @@ -129,7 +121,7 @@ |
2962 | num_instances = quota.allowed_instances(self.context, 100, |
2963 | instance_type) |
2964 | self.assertEqual(num_instances, 2) |
2965 | - db.quota_create(self.context, self.project.id, 'instances', None) |
2966 | + db.quota_create(self.context, self.project_id, 'instances', None) |
2967 | num_instances = quota.allowed_instances(self.context, 100, |
2968 | instance_type) |
2969 | self.assertEqual(num_instances, 100) |
2970 | @@ -145,7 +137,7 @@ |
2971 | num_instances = quota.allowed_instances(self.context, 100, |
2972 | instance_type) |
2973 | self.assertEqual(num_instances, 2) |
2974 | - db.quota_create(self.context, self.project.id, 'ram', None) |
2975 | + db.quota_create(self.context, self.project_id, 'ram', None) |
2976 | num_instances = quota.allowed_instances(self.context, 100, |
2977 | instance_type) |
2978 | self.assertEqual(num_instances, 100) |
2979 | @@ -161,7 +153,7 @@ |
2980 | num_instances = quota.allowed_instances(self.context, 100, |
2981 | instance_type) |
2982 | self.assertEqual(num_instances, 2) |
2983 | - db.quota_create(self.context, self.project.id, 'cores', None) |
2984 | + db.quota_create(self.context, self.project_id, 'cores', None) |
2985 | num_instances = quota.allowed_instances(self.context, 100, |
2986 | instance_type) |
2987 | self.assertEqual(num_instances, 100) |
2988 | @@ -174,7 +166,7 @@ |
2989 | FLAGS.quota_gigabytes = -1 |
2990 | volumes = quota.allowed_volumes(self.context, 100, 1) |
2991 | self.assertEqual(volumes, 10) |
2992 | - db.quota_create(self.context, self.project.id, 'volumes', None) |
2993 | + db.quota_create(self.context, self.project_id, 'volumes', None) |
2994 | volumes = quota.allowed_volumes(self.context, 100, 1) |
2995 | self.assertEqual(volumes, 100) |
2996 | volumes = quota.allowed_volumes(self.context, 101, 1) |
2997 | @@ -185,7 +177,7 @@ |
2998 | FLAGS.quota_gigabytes = 10 |
2999 | volumes = quota.allowed_volumes(self.context, 100, 1) |
3000 | self.assertEqual(volumes, 10) |
3001 | - db.quota_create(self.context, self.project.id, 'gigabytes', None) |
3002 | + db.quota_create(self.context, self.project_id, 'gigabytes', None) |
3003 | volumes = quota.allowed_volumes(self.context, 100, 1) |
3004 | self.assertEqual(volumes, 100) |
3005 | volumes = quota.allowed_volumes(self.context, 101, 1) |
3006 | @@ -195,7 +187,7 @@ |
3007 | FLAGS.quota_floating_ips = 10 |
3008 | floating_ips = quota.allowed_floating_ips(self.context, 100) |
3009 | self.assertEqual(floating_ips, 10) |
3010 | - db.quota_create(self.context, self.project.id, 'floating_ips', None) |
3011 | + db.quota_create(self.context, self.project_id, 'floating_ips', None) |
3012 | floating_ips = quota.allowed_floating_ips(self.context, 100) |
3013 | self.assertEqual(floating_ips, 100) |
3014 | floating_ips = quota.allowed_floating_ips(self.context, 101) |
3015 | @@ -205,7 +197,7 @@ |
3016 | FLAGS.quota_metadata_items = 10 |
3017 | items = quota.allowed_metadata_items(self.context, 100) |
3018 | self.assertEqual(items, 10) |
3019 | - db.quota_create(self.context, self.project.id, 'metadata_items', None) |
3020 | + db.quota_create(self.context, self.project_id, 'metadata_items', None) |
3021 | items = quota.allowed_metadata_items(self.context, 100) |
3022 | self.assertEqual(items, 100) |
3023 | items = quota.allowed_metadata_items(self.context, 101) |
3024 | @@ -273,11 +265,11 @@ |
3025 | address = '192.168.0.100' |
3026 | db.floating_ip_create(context.get_admin_context(), |
3027 | {'address': address, |
3028 | - 'project_id': self.project.id}) |
3029 | + 'project_id': self.project_id}) |
3030 | self.assertRaises(quota.QuotaError, |
3031 | self.network.allocate_floating_ip, |
3032 | self.context, |
3033 | - self.project.id) |
3034 | + self.project_id) |
3035 | db.floating_ip_destroy(context.get_admin_context(), address) |
3036 | |
3037 | def test_too_many_metadata_items(self): |
3038 | @@ -299,7 +291,7 @@ |
3039 | |
3040 | def test_overridden_allowed_injected_files(self): |
3041 | FLAGS.quota_max_injected_files = 5 |
3042 | - db.quota_create(self.context, self.project.id, 'injected_files', 77) |
3043 | + db.quota_create(self.context, self.project_id, 'injected_files', 77) |
3044 | self.assertEqual(quota.allowed_injected_files(self.context, 100), 77) |
3045 | |
3046 | def test_unlimited_default_allowed_injected_files(self): |
3047 | @@ -308,7 +300,7 @@ |
3048 | |
3049 | def test_unlimited_db_allowed_injected_files(self): |
3050 | FLAGS.quota_max_injected_files = 5 |
3051 | - db.quota_create(self.context, self.project.id, 'injected_files', None) |
3052 | + db.quota_create(self.context, self.project_id, 'injected_files', None) |
3053 | self.assertEqual(quota.allowed_injected_files(self.context, 100), 100) |
3054 | |
3055 | def test_default_allowed_injected_file_content_bytes(self): |
3056 | @@ -318,7 +310,7 @@ |
3057 | |
3058 | def test_overridden_allowed_injected_file_content_bytes(self): |
3059 | FLAGS.quota_max_injected_file_content_bytes = 12345 |
3060 | - db.quota_create(self.context, self.project.id, |
3061 | + db.quota_create(self.context, self.project_id, |
3062 | 'injected_file_content_bytes', 5678) |
3063 | limit = quota.allowed_injected_file_content_bytes(self.context, 23456) |
3064 | self.assertEqual(limit, 5678) |
3065 | @@ -330,7 +322,7 @@ |
3066 | |
3067 | def test_unlimited_db_allowed_injected_file_content_bytes(self): |
3068 | FLAGS.quota_max_injected_file_content_bytes = 12345 |
3069 | - db.quota_create(self.context, self.project.id, |
3070 | + db.quota_create(self.context, self.project_id, |
3071 | 'injected_file_content_bytes', None) |
3072 | limit = quota.allowed_injected_file_content_bytes(self.context, 23456) |
3073 | self.assertEqual(limit, 23456) |
3074 | |
3075 | === modified file 'nova/tests/test_vmwareapi.py' |
3076 | --- nova/tests/test_vmwareapi.py 2011-07-27 00:40:50 +0000 |
3077 | +++ nova/tests/test_vmwareapi.py 2011-07-29 19:38:29 +0000 |
3078 | @@ -19,11 +19,11 @@ |
3079 | Test suite for VMWareAPI. |
3080 | """ |
3081 | |
3082 | +from nova import context |
3083 | from nova import db |
3084 | from nova import flags |
3085 | from nova import test |
3086 | from nova import utils |
3087 | -from nova.auth import manager |
3088 | from nova.compute import power_state |
3089 | from nova.tests.glance import stubs as glance_stubs |
3090 | from nova.tests.vmwareapi import db_fakes |
3091 | @@ -43,10 +43,9 @@ |
3092 | self.flags(vmwareapi_host_ip='test_url', |
3093 | vmwareapi_host_username='test_username', |
3094 | vmwareapi_host_password='test_pass') |
3095 | - self.manager = manager.AuthManager() |
3096 | - self.user = self.manager.create_user('fake', 'fake', 'fake', |
3097 | - admin=True) |
3098 | - self.project = self.manager.create_project('fake', 'fake', 'fake') |
3099 | + self.user_id = 'fake' |
3100 | + self.project_id = 'fake' |
3101 | + self.context = context.RequestContext(self.user_id, self.project_id) |
3102 | self.network = utils.import_object(FLAGS.network_manager) |
3103 | vmwareapi_fake.reset() |
3104 | db_fakes.stub_out_db_instance_api(self.stubs) |
3105 | @@ -77,14 +76,12 @@ |
3106 | def tearDown(self): |
3107 | super(VMWareAPIVMTestCase, self).tearDown() |
3108 | vmwareapi_fake.cleanup() |
3109 | - self.manager.delete_project(self.project) |
3110 | - self.manager.delete_user(self.user) |
3111 | |
3112 | def _create_instance_in_the_db(self): |
3113 | values = {'name': 1, |
3114 | 'id': 1, |
3115 | - 'project_id': self.project.id, |
3116 | - 'user_id': self.user.id, |
3117 | + 'project_id': self.project_id, |
3118 | + 'user_id': self.user_id, |
3119 | 'image_ref': "1", |
3120 | 'kernel_id': "1", |
3121 | 'ramdisk_id': "1", |
3122 | |
3123 | === modified file 'nova/tests/test_xenapi.py' |
3124 | --- nova/tests/test_xenapi.py 2011-07-27 22:02:49 +0000 |
3125 | +++ nova/tests/test_xenapi.py 2011-07-29 19:38:29 +0000 |
3126 | @@ -30,7 +30,6 @@ |
3127 | from nova import log as logging |
3128 | from nova import test |
3129 | from nova import utils |
3130 | -from nova.auth import manager |
3131 | from nova.compute import instance_types |
3132 | from nova.compute import power_state |
3133 | from nova import exception |
3134 | @@ -69,7 +68,9 @@ |
3135 | def setUp(self): |
3136 | super(XenAPIVolumeTestCase, self).setUp() |
3137 | self.stubs = stubout.StubOutForTesting() |
3138 | - self.context = context.RequestContext('fake', 'fake', False) |
3139 | + self.user_id = 'fake' |
3140 | + self.project_id = 'fake' |
3141 | + self.context = context.RequestContext(self.user_id, self.project_id) |
3142 | FLAGS.target_host = '127.0.0.1' |
3143 | FLAGS.xenapi_connection_url = 'test_url' |
3144 | FLAGS.xenapi_connection_password = 'test_pass' |
3145 | @@ -77,7 +78,7 @@ |
3146 | stubs.stub_out_get_target(self.stubs) |
3147 | xenapi_fake.reset() |
3148 | self.values = {'id': 1, |
3149 | - 'project_id': 'fake', |
3150 | + 'project_id': self.user_id, |
3151 | 'user_id': 'fake', |
3152 | 'image_ref': 1, |
3153 | 'kernel_id': 2, |
3154 | @@ -173,10 +174,6 @@ |
3155 | """Unit tests for VM operations.""" |
3156 | def setUp(self): |
3157 | super(XenAPIVMTestCase, self).setUp() |
3158 | - self.manager = manager.AuthManager() |
3159 | - self.user = self.manager.create_user('fake', 'fake', 'fake', |
3160 | - admin=True) |
3161 | - self.project = self.manager.create_project('fake', 'fake', 'fake') |
3162 | self.network = utils.import_object(FLAGS.network_manager) |
3163 | self.stubs = stubout.StubOutForTesting() |
3164 | self.flags(xenapi_connection_url='test_url', |
3165 | @@ -195,7 +192,9 @@ |
3166 | stubs.stub_out_vm_methods(self.stubs) |
3167 | glance_stubs.stubout_glance_client(self.stubs) |
3168 | fake_utils.stub_out_utils_execute(self.stubs) |
3169 | - self.context = context.RequestContext('fake', 'fake', False) |
3170 | + self.user_id = 'fake' |
3171 | + self.project_id = 'fake' |
3172 | + self.context = context.RequestContext(self.user_id, self.project_id) |
3173 | self.conn = xenapi_conn.get_connection(False) |
3174 | |
3175 | def test_parallel_builds(self): |
3176 | @@ -229,8 +228,8 @@ |
3177 | instance = db.instance_create(self.context, values) |
3178 | self.conn.spawn(instance, network_info) |
3179 | |
3180 | - gt1 = eventlet.spawn(_do_build, 1, self.project.id, self.user.id) |
3181 | - gt2 = eventlet.spawn(_do_build, 2, self.project.id, self.user.id) |
3182 | + gt1 = eventlet.spawn(_do_build, 1, self.project_id, self.user_id) |
3183 | + gt2 = eventlet.spawn(_do_build, 2, self.project_id, self.user_id) |
3184 | gt1.wait() |
3185 | gt2.wait() |
3186 | |
3187 | @@ -401,8 +400,8 @@ |
3188 | stubs.stubout_loopingcall_start(self.stubs) |
3189 | if create_record: |
3190 | values = {'id': instance_id, |
3191 | - 'project_id': self.project.id, |
3192 | - 'user_id': self.user.id, |
3193 | + 'project_id': self.project_id, |
3194 | + 'user_id': self.user_id, |
3195 | 'image_ref': image_ref, |
3196 | 'kernel_id': kernel_id, |
3197 | 'ramdisk_id': ramdisk_id, |
3198 | @@ -469,12 +468,30 @@ |
3199 | self._check_vdis(vdi_recs_start, vdi_recs_end) |
3200 | |
3201 | def test_spawn_raw_objectstore(self): |
3202 | - FLAGS.xenapi_image_service = 'objectstore' |
3203 | - self._test_spawn(1, None, None) |
3204 | + # TODO(vish): deprecated |
3205 | + from nova.auth import manager |
3206 | + authman = manager.AuthManager() |
3207 | + authman.create_user('fake', 'fake') |
3208 | + authman.create_project('fake', 'fake') |
3209 | + try: |
3210 | + FLAGS.xenapi_image_service = 'objectstore' |
3211 | + self._test_spawn(1, None, None) |
3212 | + finally: |
3213 | + authman.delete_project('fake') |
3214 | + authman.delete_user('fake') |
3215 | |
3216 | def test_spawn_objectstore(self): |
3217 | - FLAGS.xenapi_image_service = 'objectstore' |
3218 | - self._test_spawn(1, 2, 3) |
3219 | + # TODO(vish): deprecated |
3220 | + from nova.auth import manager |
3221 | + authman = manager.AuthManager() |
3222 | + authman.create_user('fake', 'fake') |
3223 | + authman.create_project('fake', 'fake') |
3224 | + try: |
3225 | + FLAGS.xenapi_image_service = 'objectstore' |
3226 | + self._test_spawn(1, 2, 3) |
3227 | + finally: |
3228 | + authman.delete_project('fake') |
3229 | + authman.delete_user('fake') |
3230 | |
3231 | @stub_vm_utils_with_vdi_attached_here |
3232 | def test_spawn_raw_glance(self): |
3233 | @@ -626,7 +643,7 @@ |
3234 | host=FLAGS.host, |
3235 | vpn=None, |
3236 | instance_type_id=1, |
3237 | - project_id=self.project.id) |
3238 | + project_id=self.project_id) |
3239 | self._test_spawn(glance_stubs.FakeGlance.IMAGE_MACHINE, |
3240 | glance_stubs.FakeGlance.IMAGE_KERNEL, |
3241 | glance_stubs.FakeGlance.IMAGE_RAMDISK, |
3242 | @@ -656,21 +673,13 @@ |
3243 | # Ensure that it will not unrescue a non-rescued instance. |
3244 | self.assertRaises(Exception, conn.unrescue, instance, None) |
3245 | |
3246 | - def tearDown(self): |
3247 | - super(XenAPIVMTestCase, self).tearDown() |
3248 | - self.manager.delete_project(self.project) |
3249 | - self.manager.delete_user(self.user) |
3250 | - self.vm_info = None |
3251 | - self.vm = None |
3252 | - self.stubs.UnsetAll() |
3253 | - |
3254 | def _create_instance(self, instance_id=1, spawn=True): |
3255 | """Creates and spawns a test instance.""" |
3256 | stubs.stubout_loopingcall_start(self.stubs) |
3257 | values = { |
3258 | 'id': instance_id, |
3259 | - 'project_id': self.project.id, |
3260 | - 'user_id': self.user.id, |
3261 | + 'project_id': self.project_id, |
3262 | + 'user_id': self.user_id, |
3263 | 'image_ref': 1, |
3264 | 'kernel_id': 2, |
3265 | 'ramdisk_id': 3, |
3266 | @@ -752,14 +761,12 @@ |
3267 | stubs.stub_out_get_target(self.stubs) |
3268 | xenapi_fake.reset() |
3269 | xenapi_fake.create_network('fake', FLAGS.flat_network_bridge) |
3270 | - self.manager = manager.AuthManager() |
3271 | - self.user = self.manager.create_user('fake', 'fake', 'fake', |
3272 | - admin=True) |
3273 | - self.project = self.manager.create_project('fake', 'fake', 'fake') |
3274 | - self.context = context.RequestContext('fake', 'fake', False) |
3275 | + self.user_id = 'fake' |
3276 | + self.project_id = 'fake' |
3277 | + self.context = context.RequestContext(self.user_id, self.project_id) |
3278 | self.values = {'id': 1, |
3279 | - 'project_id': self.project.id, |
3280 | - 'user_id': self.user.id, |
3281 | + 'project_id': self.project_id, |
3282 | + 'user_id': self.user_id, |
3283 | 'image_ref': 1, |
3284 | 'kernel_id': None, |
3285 | 'ramdisk_id': None, |
3286 | @@ -773,12 +780,6 @@ |
3287 | stubs.stubout_get_this_vm_uuid(self.stubs) |
3288 | glance_stubs.stubout_glance_client(self.stubs) |
3289 | |
3290 | - def tearDown(self): |
3291 | - super(XenAPIMigrateInstance, self).tearDown() |
3292 | - self.manager.delete_project(self.project) |
3293 | - self.manager.delete_user(self.user) |
3294 | - self.stubs.UnsetAll() |
3295 | - |
3296 | def test_migrate_disk_and_power_off(self): |
3297 | instance = db.instance_create(self.context, self.values) |
3298 | stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) |
3299 | |
3300 | === modified file 'nova/utils.py' |
3301 | --- nova/utils.py 2011-07-29 17:33:58 +0000 |
3302 | +++ nova/utils.py 2011-07-29 19:38:29 +0000 |
3303 | @@ -19,7 +19,6 @@ |
3304 | |
3305 | """Utilities and helper functions.""" |
3306 | |
3307 | -import base64 |
3308 | import datetime |
3309 | import functools |
3310 | import inspect |
3311 | @@ -30,7 +29,6 @@ |
3312 | import random |
3313 | import re |
3314 | import socket |
3315 | -import string |
3316 | import struct |
3317 | import sys |
3318 | import time |
3319 | @@ -50,7 +48,8 @@ |
3320 | |
3321 | |
3322 | LOG = logging.getLogger("nova.utils") |
3323 | -TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" |
3324 | +ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" |
3325 | +PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f" |
3326 | FLAGS = flags.FLAGS |
3327 | |
3328 | |
3329 | @@ -361,16 +360,26 @@ |
3330 | utcnow.override_time = None |
3331 | |
3332 | |
3333 | +def strtime(at=None, fmt=PERFECT_TIME_FORMAT): |
3334 | + """Returns formatted utcnow.""" |
3335 | + if not at: |
3336 | + at = utcnow() |
3337 | + return at.strftime(fmt) |
3338 | + |
3339 | + |
3340 | +def parse_strtime(timestr, fmt=PERFECT_TIME_FORMAT): |
3341 | + """Turn a formatted time back into a datetime.""" |
3342 | + return datetime.datetime.strptime(timestr, fmt) |
3343 | + |
3344 | + |
3345 | def isotime(at=None): |
3346 | """Returns iso formatted utcnow.""" |
3347 | - if not at: |
3348 | - at = utcnow() |
3349 | - return at.strftime(TIME_FORMAT) |
3350 | + return strtime(at, ISO_TIME_FORMAT) |
3351 | |
3352 | |
3353 | def parse_isotime(timestr): |
3354 | """Turn an iso formatted time back into a datetime.""" |
3355 | - return datetime.datetime.strptime(timestr, TIME_FORMAT) |
3356 | + return parse_strtime(timestr, ISO_TIME_FORMAT) |
3357 | |
3358 | |
3359 | def parse_mailmap(mailmap='.mailmap'): |
3360 | |
3361 | === modified file 'nova/virt/hyperv.py' |
3362 | --- nova/virt/hyperv.py 2011-07-20 11:21:44 +0000 |
3363 | +++ nova/virt/hyperv.py 2011-07-29 19:38:29 +0000 |
3364 | @@ -66,7 +66,6 @@ |
3365 | from nova import exception |
3366 | from nova import flags |
3367 | from nova import log as logging |
3368 | -from nova.auth import manager |
3369 | from nova.compute import power_state |
3370 | from nova.virt import driver |
3371 | from nova.virt import images |
3372 | @@ -145,13 +144,12 @@ |
3373 | if vm is not None: |
3374 | raise exception.InstanceExists(name=instance.name) |
3375 | |
3376 | - user = manager.AuthManager().get_user(instance['user_id']) |
3377 | - project = manager.AuthManager().get_project(instance['project_id']) |
3378 | #Fetch the file, assume it is a VHD file. |
3379 | base_vhd_filename = os.path.join(FLAGS.instances_path, |
3380 | instance.name) |
3381 | vhdfile = "%s.vhd" % (base_vhd_filename) |
3382 | - images.fetch(instance['image_ref'], vhdfile, user, project) |
3383 | + images.fetch(instance['image_ref'], vhdfile, |
3384 | + instance['user_id'], instance['project_id']) |
3385 | |
3386 | try: |
3387 | self._create_vm(instance) |
3388 | |
3389 | === modified file 'nova/virt/images.py' |
3390 | --- nova/virt/images.py 2011-06-09 21:36:20 +0000 |
3391 | +++ nova/virt/images.py 2011-07-29 19:38:29 +0000 |
3392 | @@ -33,7 +33,7 @@ |
3393 | LOG = logging.getLogger('nova.virt.images') |
3394 | |
3395 | |
3396 | -def fetch(image_href, path, _user, _project): |
3397 | +def fetch(image_href, path, _user_id, _project_id): |
3398 | # TODO(vish): Improve context handling and add owner and auth data |
3399 | # when it is added to glance. Right now there is no |
3400 | # auth checking in glance, so we assume that access was |
3401 | |
3402 | === modified file 'nova/virt/libvirt/connection.py' |
3403 | --- nova/virt/libvirt/connection.py 2011-07-27 16:19:45 +0000 |
3404 | +++ nova/virt/libvirt/connection.py 2011-07-29 19:38:29 +0000 |
3405 | @@ -769,9 +769,9 @@ |
3406 | else: |
3407 | utils.execute('cp', base, target) |
3408 | |
3409 | - def _fetch_image(self, target, image_id, user, project, size=None): |
3410 | + def _fetch_image(self, target, image_id, user_id, project_id, size=None): |
3411 | """Grab image and optionally attempt to resize it""" |
3412 | - images.fetch(image_id, target, user, project) |
3413 | + images.fetch(image_id, target, user_id, project_id) |
3414 | if size: |
3415 | disk.extend(target, size) |
3416 | |
3417 | @@ -809,9 +809,6 @@ |
3418 | os.close(os.open(basepath('console.log', ''), |
3419 | os.O_CREAT | os.O_WRONLY, 0660)) |
3420 | |
3421 | - user = manager.AuthManager().get_user(inst['user_id']) |
3422 | - project = manager.AuthManager().get_project(inst['project_id']) |
3423 | - |
3424 | if not disk_images: |
3425 | disk_images = {'image_id': inst['image_ref'], |
3426 | 'kernel_id': inst['kernel_id'], |
3427 | @@ -823,16 +820,16 @@ |
3428 | target=basepath('kernel'), |
3429 | fname=fname, |
3430 | image_id=disk_images['kernel_id'], |
3431 | - user=user, |
3432 | - project=project) |
3433 | + user_id=inst['user_id'], |
3434 | + project_id=inst['project_id']) |
3435 | if disk_images['ramdisk_id']: |
3436 | fname = '%08x' % int(disk_images['ramdisk_id']) |
3437 | self._cache_image(fn=self._fetch_image, |
3438 | target=basepath('ramdisk'), |
3439 | fname=fname, |
3440 | image_id=disk_images['ramdisk_id'], |
3441 | - user=user, |
3442 | - project=project) |
3443 | + user_id=inst['user_id'], |
3444 | + project_id=inst['project_id']) |
3445 | |
3446 | root_fname = hashlib.sha1(disk_images['image_id']).hexdigest() |
3447 | size = FLAGS.minimum_root_size |
3448 | @@ -850,8 +847,8 @@ |
3449 | fname=root_fname, |
3450 | cow=FLAGS.use_cow_images, |
3451 | image_id=disk_images['image_id'], |
3452 | - user=user, |
3453 | - project=project, |
3454 | + user_id=inst['user_id'], |
3455 | + project_id=inst['project_id'], |
3456 | size=size) |
3457 | |
3458 | if inst_type['local_gb'] and not self._volume_in_mapping( |
3459 | |
3460 | === modified file 'nova/virt/xenapi/vm_utils.py' |
3461 | --- nova/virt/xenapi/vm_utils.py 2011-07-21 07:31:14 +0000 |
3462 | +++ nova/virt/xenapi/vm_utils.py 2011-07-29 19:38:29 +0000 |
3463 | @@ -37,7 +37,6 @@ |
3464 | from nova.image import glance as glance_image_service |
3465 | from nova import log as logging |
3466 | from nova import utils |
3467 | -from nova.auth.manager import AuthManager |
3468 | from nova.compute import instance_types |
3469 | from nova.compute import power_state |
3470 | from nova.virt import disk |
3471 | @@ -384,7 +383,7 @@ |
3472 | session.wait_for_task(task, instance.id) |
3473 | |
3474 | @classmethod |
3475 | - def fetch_image(cls, session, instance_id, image, user, project, |
3476 | + def fetch_image(cls, session, instance_id, image, user_id, project_id, |
3477 | image_type): |
3478 | """ |
3479 | image_type is interpreted as an ImageType instance |
3480 | @@ -396,18 +395,23 @@ |
3481 | Returns: A single filename if image_type is KERNEL_RAMDISK |
3482 | A list of dictionaries that describe VDIs, otherwise |
3483 | """ |
3484 | - access = AuthManager().get_access_key(user, project) |
3485 | |
3486 | if FLAGS.xenapi_image_service == 'glance': |
3487 | - return cls._fetch_image_glance(session, instance_id, image, |
3488 | - access, image_type) |
3489 | + return cls._fetch_image_glance(session, instance_id, |
3490 | + image, image_type) |
3491 | else: |
3492 | + # TODO(vish): this shouldn't be used anywhere anymore and |
3493 | + # can probably be removed |
3494 | + from nova.auth.manager import AuthManager |
3495 | + manager = AuthManager() |
3496 | + access = manager.get_access_key(user_id, project_id) |
3497 | + secret = manager.get_user(user_id).secret |
3498 | return cls._fetch_image_objectstore(session, instance_id, image, |
3499 | - access, user.secret, |
3500 | + access, secret, |
3501 | image_type) |
3502 | |
3503 | @classmethod |
3504 | - def _fetch_image_glance_vhd(cls, session, instance_id, image, access, |
3505 | + def _fetch_image_glance_vhd(cls, session, instance_id, image, |
3506 | image_type): |
3507 | """Tell glance to download an image and put the VHDs into the SR |
3508 | |
3509 | @@ -455,7 +459,7 @@ |
3510 | return vdis |
3511 | |
3512 | @classmethod |
3513 | - def _fetch_image_glance_disk(cls, session, instance_id, image, access, |
3514 | + def _fetch_image_glance_disk(cls, session, instance_id, image, |
3515 | image_type): |
3516 | """Fetch the image from Glance |
3517 | |
3518 | @@ -589,8 +593,7 @@ |
3519 | return image_type |
3520 | |
3521 | @classmethod |
3522 | - def _fetch_image_glance(cls, session, instance_id, image, access, |
3523 | - image_type): |
3524 | + def _fetch_image_glance(cls, session, instance_id, image, image_type): |
3525 | """Fetch image from glance based on image type. |
3526 | |
3527 | Returns: A single filename if image_type is KERNEL or RAMDISK |
3528 | @@ -598,10 +601,10 @@ |
3529 | """ |
3530 | if image_type == ImageType.DISK_VHD: |
3531 | return cls._fetch_image_glance_vhd( |
3532 | - session, instance_id, image, access, image_type) |
3533 | + session, instance_id, image, image_type) |
3534 | else: |
3535 | return cls._fetch_image_glance_disk( |
3536 | - session, instance_id, image, access, image_type) |
3537 | + session, instance_id, image, image_type) |
3538 | |
3539 | @classmethod |
3540 | def _fetch_image_objectstore(cls, session, instance_id, image, access, |
3541 | |
3542 | === modified file 'nova/virt/xenapi/vmops.py' |
3543 | --- nova/virt/xenapi/vmops.py 2011-07-28 19:01:30 +0000 |
3544 | +++ nova/virt/xenapi/vmops.py 2011-07-29 19:38:29 +0000 |
3545 | @@ -38,7 +38,6 @@ |
3546 | from nova import log as logging |
3547 | from nova import utils |
3548 | |
3549 | -from nova.auth.manager import AuthManager |
3550 | from nova.compute import power_state |
3551 | from nova.virt import driver |
3552 | from nova.virt.xenapi.network_utils import NetworkHelper |
3553 | @@ -136,11 +135,10 @@ |
3554 | self._session.call_xenapi('VM.start', vm_ref, False, False) |
3555 | |
3556 | def _create_disks(self, instance): |
3557 | - user = AuthManager().get_user(instance.user_id) |
3558 | - project = AuthManager().get_project(instance.project_id) |
3559 | disk_image_type = VMHelper.determine_disk_image_type(instance) |
3560 | vdis = VMHelper.fetch_image(self._session, |
3561 | - instance.id, instance.image_ref, user, project, |
3562 | + instance.id, instance.image_ref, |
3563 | + instance.user_id, instance.project_id, |
3564 | disk_image_type) |
3565 | return vdis |
3566 | |
3567 | @@ -178,21 +176,18 @@ |
3568 | power_state.SHUTDOWN) |
3569 | return |
3570 | |
3571 | - user = AuthManager().get_user(instance.user_id) |
3572 | - project = AuthManager().get_project(instance.project_id) |
3573 | - |
3574 | disk_image_type = VMHelper.determine_disk_image_type(instance) |
3575 | kernel = None |
3576 | ramdisk = None |
3577 | try: |
3578 | if instance.kernel_id: |
3579 | kernel = VMHelper.fetch_image(self._session, instance.id, |
3580 | - instance.kernel_id, user, project, |
3581 | - ImageType.KERNEL)[0] |
3582 | + instance.kernel_id, instance.user_id, |
3583 | + instance.project_id, ImageType.KERNEL)[0] |
3584 | if instance.ramdisk_id: |
3585 | ramdisk = VMHelper.fetch_image(self._session, instance.id, |
3586 | - instance.ramdisk_id, user, project, |
3587 | - ImageType.RAMDISK)[0] |
3588 | + instance.kernel_id, instance.user_id, |
3589 | + instance.project_id, ImageType.RAMDISK)[0] |
3590 | # Create the VM ref and attach the first disk |
3591 | first_vdi_ref = self._session.call_xenapi('VDI.get_by_uuid', |
3592 | vdis[0]['vdi_uuid']) |
3593 | |
3594 | === modified file 'nova/wsgi.py' |
3595 | --- nova/wsgi.py 2011-07-11 13:06:55 +0000 |
3596 | +++ nova/wsgi.py 2011-07-29 19:38:29 +0000 |
3597 | @@ -274,6 +274,18 @@ |
3598 | return self.process_response(response) |
3599 | |
3600 | |
3601 | +class InjectContext(Middleware): |
3602 | + """Add a 'nova.context' to WSGI environ.""" |
3603 | + def __init__(self, context, *args, **kwargs): |
3604 | + self.context = context |
3605 | + super(InjectContext, self).__init__(*args, **kwargs) |
3606 | + |
3607 | + @webob.dec.wsgify(RequestClass=Request) |
3608 | + def __call__(self, req): |
3609 | + req.environ['nova.context'] = self.context |
3610 | + return self.application |
3611 | + |
3612 | + |
3613 | class Debug(Middleware): |
3614 | """Helper class for debugging a WSGI application. |
3615 |
I have a question about keystone and openstack in terms of semantics. Is there any value in making the terms across keystone/nova/swift consistent? Keystone has tenants, Nova has projects, and Swift has accounts. Gets a bit confusing.
I understand why the following change was made, though it seems like the key pair bits need a new place to live. Doesn't seem ideal to call the DB directly here:
205 - key_pairs = auth_manager. AuthManager. get_key_ pairs(context) pair_get_ all_by_ user(context. elevated( ),
206 + key_pairs = db.key_
207 + context.user_id)
I don't think you meant to leave this in:
305 + LOG.info(locals())