Moves auth.manager to the data layer.
A couple weird things are going on, I added a try-except in Manager.delete_project because it seems to have an issue finding the network to delete, I think something is probably deleting it before the tests get a chance to. Also stubbed out task.LoopingCall in service_unittest because there wasn't a good way to kill the task from outside of service.Service.create()
This commit is contained in:
		| @@ -29,6 +29,7 @@ import uuid | ||||
| import zipfile | ||||
|  | ||||
| from nova import crypto | ||||
| from nova import db | ||||
| from nova import exception | ||||
| from nova import flags | ||||
| from nova import models | ||||
| @@ -202,11 +203,6 @@ class Project(AuthBase): | ||||
|         ip, port = AuthManager().get_project_vpn_data(self) | ||||
|         return port | ||||
|  | ||||
|     @property | ||||
|     def network(self): | ||||
|         session = models.create_session() | ||||
|         return session.query(models.Network).filter_by(project_id=self.id).first() | ||||
|  | ||||
|     def has_manager(self, user): | ||||
|         return AuthManager().is_project_manager(user, self) | ||||
|  | ||||
| @@ -498,8 +494,8 @@ class AuthManager(object): | ||||
|                 return [] | ||||
|             return [Project(**project_dict) for project_dict in project_list] | ||||
|  | ||||
|     def create_project(self, name, manager_user, | ||||
|                        description=None, member_users=None): | ||||
|     def create_project(self, name, manager_user, description=None, | ||||
|                        member_users=None, context=None): | ||||
|         """Create a project | ||||
|  | ||||
|         @type name: str | ||||
| @@ -530,8 +526,7 @@ class AuthManager(object): | ||||
|             if project_dict: | ||||
|                 project = Project(**project_dict) | ||||
|                 # FIXME(ja): EVIL HACK | ||||
|                 net = models.Network(project_id=project.id) | ||||
|                 net.save() | ||||
|                 db.network_create(context, {'project_id': project.id}) | ||||
|                 return project | ||||
|  | ||||
|     def add_to_project(self, user, project): | ||||
| @@ -558,7 +553,7 @@ class AuthManager(object): | ||||
|             return drv.remove_from_project(User.safe_id(user), | ||||
|                                             Project.safe_id(project)) | ||||
|  | ||||
|     def get_project_vpn_data(self, project): | ||||
|     def get_project_vpn_data(self, project, context=None): | ||||
|         """Gets vpn ip and port for project | ||||
|  | ||||
|         @type project: Project or project_id | ||||
| @@ -571,19 +566,27 @@ class AuthManager(object): | ||||
|         # FIXME(vish): this shouldn't be messing with the datamodel directly | ||||
|         if not isinstance(project, Project): | ||||
|             project = self.get_project(project) | ||||
|         if not project.network.vpn_public_port: | ||||
|             raise exception.NotFound('project network data has not been set') | ||||
|         return (project.network.vpn_public_ip_str, | ||||
|                 project.network.vpn_public_port) | ||||
|          | ||||
|         network_ref = db.project_get_network(context, project.id) | ||||
|  | ||||
|     def delete_project(self, project): | ||||
|         if not network_ref['vpn_public_port']: | ||||
|             raise exception.NotFound('project network data has not been set') | ||||
|         return (network_ref['vpn_public_ip_str'], | ||||
|                 network_ref['vpn_public_port']) | ||||
|  | ||||
|     def delete_project(self, project, context=None): | ||||
|         """Deletes a project""" | ||||
|         # FIXME(ja): EVIL HACK | ||||
|         if not isinstance(project, Project): | ||||
|             project = self.get_project(project) | ||||
|         project.network.delete() | ||||
|         network_ref = db.project_get_network(context, project.id) | ||||
|         try: | ||||
|             db.network_destroy(context, network_ref['id']) | ||||
|         except: | ||||
|             logging.exception('Could not destroy network: %s', | ||||
|                               network_ref['id']) | ||||
|         with self.driver() as drv: | ||||
|             return drv.delete_project(Project.safe_id(project)) | ||||
|             drv.delete_project(Project.safe_id(project)) | ||||
|  | ||||
|     def get_user(self, uid): | ||||
|         """Retrieves a user by id""" | ||||
|   | ||||
| @@ -67,6 +67,8 @@ class NetworkTestCase(test.TrialTestCase): | ||||
|  | ||||
|     def tearDown(self):  # pylint: disable=C0103 | ||||
|         super(NetworkTestCase, self).tearDown() | ||||
|         # TODO(termie): this should really be instantiating clean datastores | ||||
|         #               in between runs, one failure kills all the tests | ||||
|         for project in self.projects: | ||||
|             self.manager.delete_project(project) | ||||
|         self.manager.delete_user(self.user) | ||||
| @@ -275,6 +277,8 @@ def is_allocated_in_project(address, project_id): | ||||
|     fixed_ip = models.FixedIp.find_by_ip_str(address) | ||||
|     project_net = service.get_network_for_project(project_id) | ||||
|     # instance exists until release | ||||
|     logging.error('fixed_ip.instance: %s', fixed_ip.instance) | ||||
|     logging.error('project_net: %s', project_net) | ||||
|     return fixed_ip.instance is not None and fixed_ip.network == project_net | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -43,6 +43,8 @@ class ServiceTestCase(test.BaseTestCase): | ||||
|  | ||||
|     def test_create(self): | ||||
|         self.mox.StubOutWithMock(rpc, 'AdapterConsumer', use_mock_anything=True) | ||||
|         self.mox.StubOutWithMock( | ||||
|                 service.task, 'LoopingCall', use_mock_anything=True) | ||||
|         rpc.AdapterConsumer(connection=mox.IgnoreArg(), | ||||
|                             topic='run_tests.py', | ||||
|                             proxy=mox.IsA(service.Service) | ||||
| @@ -52,6 +54,15 @@ class ServiceTestCase(test.BaseTestCase): | ||||
|                             topic='run_tests.py.%s' % FLAGS.node_name, | ||||
|                             proxy=mox.IsA(service.Service) | ||||
|                             ).AndReturn(rpc.AdapterConsumer) | ||||
|  | ||||
|         # Stub out looping call a bit needlessly since we don't have an easy | ||||
|         # way to cancel it (yet) when the tests finishes | ||||
|         service.task.LoopingCall( | ||||
|                 mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn( | ||||
|                         service.task.LoopingCall) | ||||
|         service.task.LoopingCall.start(interval=mox.IgnoreArg(), | ||||
|                                        now=mox.IgnoreArg()) | ||||
|  | ||||
|         rpc.AdapterConsumer.attach_to_twisted() | ||||
|         rpc.AdapterConsumer.attach_to_twisted() | ||||
|         self.mox.ReplayAll() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 andy
					andy