Example #1
0
    def test_list_extensions_xml(self):
        app = v2.APIRouter()
        ext_midware = extensions.ExtensionMiddleware(app)
        ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
        request = webob.Request.blank("/123/extensions")
        request.accept = "application/xml"
        response = request.get_response(ser_midware)
        self.assertEqual(200, response.status_int)
        print response.body

        root = etree.XML(response.body)
        self.assertEqual(root.tag.split('extensions')[0], NS)

        # Make sure we have all the extensions.
        exts = root.findall('{0}extension'.format(NS))
        self.assertEqual(len(exts), len(self.ext_list))

        # Make sure that at least Fox in Sox is correct.
        (fox_ext, ) = [x for x in exts if x.get('alias') == 'FOXNSOX']
        self.assertEqual(fox_ext.get('name'), 'Fox In Socks')
        self.assertEqual(fox_ext.get('namespace'),
            'http://www.fox.in.socks/api/ext/pie/v1.0')
        self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00')
        self.assertEqual(fox_ext.findtext('{0}description'.format(NS)),
            'The Fox In Socks Extension')

        xmlutil.validate_schema(root, 'extensions')
Example #2
0
    def test_list_extensions_json(self):
        app = v2.APIRouter()
        ext_midware = extensions.ExtensionMiddleware(app)
        ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
        request = webob.Request.blank("/123/extensions")
        response = request.get_response(ser_midware)
        self.assertEqual(200, response.status_int)

        # Make sure we have all the extensions.
        data = json.loads(response.body)
        names = [x['name'] for x in data['extensions']]
        names.sort()
        self.assertEqual(names, self.ext_list)

        # Make sure that at least Fox in Sox is correct.
        (fox_ext, ) = [
            x for x in data['extensions'] if x['alias'] == 'FOXNSOX']
        self.assertEqual(fox_ext, {
                'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0',
                'name': 'Fox In Socks',
                'updated': '2011-01-22T13:25:27-06:00',
                'description': 'The Fox In Socks Extension',
                'alias': 'FOXNSOX',
                'links': []
            },
        )
Example #3
0
 def setUp(self):
     super(CloudpipeTest, self).setUp()
     self.flags(allow_admin_api=True)
     self.app = fakes.wsgi_app()
     inner_app = v2.APIRouter()
     self.context = context.RequestContext('fake', 'fake', is_admin=True)
     self.app = auth.InjectContext(self.context, inner_app)
     route = inner_app.map.match('/1234/os-cloudpipe')
     self.controller = route['controller'].controller
     fakes.stub_out_networking(self.stubs)
     fakes.stub_out_rate_limiting(self.stubs)
     self.stubs.Set(db, "instance_get_all_by_project",
                    db_instance_get_all_by_project)
     self.stubs.Set(db, "security_group_exists", db_security_group_exists)
     self.stubs.SmartSet(self.controller.cloudpipe, "launch_vpn_instance",
                         pipelib_launch_vpn_instance)
     #self.stubs.SmartSet(self.controller.auth_manager, "get_project",
     #                    auth_manager_get_project)
     #self.stubs.SmartSet(self.controller.auth_manager, "get_projects",
     #                    auth_manager_get_projects)
     # NOTE(todd): The above code (just setting the stub, not invoking it)
     # causes failures in AuthManagerLdapTestCase.  So use a fake object.
     self.controller.auth_manager = FakeAuthManager()
     self.stubs.Set(utils, 'vpn_ping', utils_vpn_ping)
     global EMPTY_INSTANCE_LIST
     EMPTY_INSTANCE_LIST = True
Example #4
0
 def test_get_resources(self):
     app = v2.APIRouter()
     ext_midware = extensions.ExtensionMiddleware(app)
     ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
     request = webob.Request.blank("/123/foxnsocks")
     response = request.get_response(ser_midware)
     self.assertEqual(200, response.status_int)
     self.assertEqual(response_body, response.body)
Example #5
0
 def test_no_extension_present(self):
     manager = StubExtensionManager(None)
     app = v2.APIRouter(manager)
     ext_midware = extensions.ExtensionMiddleware(app, manager)
     ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
     request = webob.Request.blank("/blah")
     response = request.get_response(ser_midware)
     self.assertEqual(404, response.status_int)
Example #6
0
 def test_admin_extensions_no_admin_api(self):
     self.flags(allow_admin_api=False)
     app = v2.APIRouter()
     ext_midware = extensions.ExtensionMiddleware(app)
     ext_mgr = ext_midware.ext_mgr
     ext_mgr.register(AdminExtension())
     self.assertTrue('FOXNSOX' in ext_mgr.extensions)
     self.assertTrue('ADMIN' not in ext_mgr.extensions)
Example #7
0
 def test_invalid_extensions(self):
     # Don't need the serialization middleware here because we're
     # not testing any serialization
     app = v2.APIRouter()
     ext_midware = extensions.ExtensionMiddleware(app)
     ext_mgr = ext_midware.ext_mgr
     ext_mgr.register(InvalidExtension())
     self.assertTrue('FOXNSOX' in ext_mgr.extensions)
     self.assertTrue('THIRD' not in ext_mgr.extensions)
Example #8
0
 def _send_server_action_request(self, url, body):
     app = v2.APIRouter()
     ext_midware = extensions.ExtensionMiddleware(app)
     ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
     request = webob.Request.blank(url)
     request.method = 'POST'
     request.content_type = 'application/json'
     request.body = json.dumps(body)
     response = request.get_response(ser_midware)
     return response
Example #9
0
 def test_get_resources_with_controller(self):
     res_ext = extensions.ResourceExtension('tweedles',
                                            StubController(response_body))
     manager = StubExtensionManager(res_ext)
     app = v2.APIRouter(manager)
     ext_midware = extensions.ExtensionMiddleware(app, manager)
     ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
     request = webob.Request.blank("/123/tweedles")
     response = request.get_response(ser_midware)
     self.assertEqual(200, response.status_int)
     self.assertEqual(response_body, response.body)
Example #10
0
    def setUp(self):
        super(ServerDiagnosticsTest, self).setUp()
        self.flags(allow_admin_api=True)
        self.flags(verbose=True)
        self.stubs.Set(nova.compute.API, 'get_actions', fake_get_actions)
        self.stubs.Set(nova.compute.API, 'get', fake_instance_get)
        self.compute_api = nova.compute.API()

        self.router = v2.APIRouter()
        ext_middleware = extensions.ExtensionMiddleware(self.router)
        self.app = wsgi.LazySerializationMiddleware(ext_middleware)
Example #11
0
    def setUp(self):
        super(CreateBackupTests, self).setUp()

        self.stubs.Set(compute.API, 'get', fake_compute_api_get)
        self.backup_stubs = fakes.stub_out_compute_api_backup(self.stubs)

        self.flags(allow_admin_api=True)
        router = v2.APIRouter()
        ext_middleware = extensions.ExtensionMiddleware(router)
        self.app = wsgi.LazySerializationMiddleware(ext_middleware)

        self.uuid = utils.gen_uuid()
Example #12
0
    def test_get_extension_json(self):
        app = v2.APIRouter()
        ext_midware = extensions.ExtensionMiddleware(app)
        ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
        request = webob.Request.blank("/123/extensions/FOXNSOX")
        response = request.get_response(ser_midware)
        self.assertEqual(200, response.status_int)

        data = json.loads(response.body)
        self.assertEqual(data['extension'], {
                "namespace": "http://www.fox.in.socks/api/ext/pie/v1.0",
                "name": "Fox In Socks",
                "updated": "2011-01-22T13:25:27-06:00",
                "description": "The Fox In Socks Extension",
                "alias": "FOXNSOX",
                "links": []})
Example #13
0
 def test_non_exist_resource(self):
     res_ext = extensions.ResourceExtension('tweedles',
                                            StubController(response_body))
     manager = StubExtensionManager(res_ext)
     app = v2.APIRouter(manager)
     ext_midware = extensions.ExtensionMiddleware(app, manager)
     ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
     request = webob.Request.blank("/123/tweedles/1")
     response = request.get_response(ser_midware)
     self.assertEqual(404, response.status_int)
     self.assertEqual('application/json', response.content_type)
     body = json.loads(response.body)
     expected = {
         "itemNotFound": {
             "message": "The resource could not be found.",
             "code": 404
         }
     }
     self.assertDictMatch(expected, body)
Example #14
0
 def test_bad_request(self):
     res_ext = extensions.ResourceExtension('tweedles',
                                            StubController(response_body))
     manager = StubExtensionManager(res_ext)
     app = v2.APIRouter(manager)
     ext_midware = extensions.ExtensionMiddleware(app, manager)
     ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
     request = webob.Request.blank("/123/tweedles")
     request.method = "POST"
     response = request.get_response(ser_midware)
     self.assertEqual(400, response.status_int)
     self.assertEqual('application/json', response.content_type)
     body = json.loads(response.body)
     expected = {
         "badRequest": {
             "message": "All aboard the fail train!",
             "code": 400
         }
     }
     self.assertDictMatch(expected, body)
Example #15
0
    def test_get_extension_xml(self):
        app = v2.APIRouter()
        ext_midware = extensions.ExtensionMiddleware(app)
        ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
        request = webob.Request.blank("/123/extensions/FOXNSOX")
        request.accept = "application/xml"
        response = request.get_response(ser_midware)
        self.assertEqual(200, response.status_int)
        xml = response.body
        print xml

        root = etree.XML(xml)
        self.assertEqual(root.tag.split('extension')[0], NS)
        self.assertEqual(root.get('alias'), 'FOXNSOX')
        self.assertEqual(root.get('name'), 'Fox In Socks')
        self.assertEqual(root.get('namespace'),
            'http://www.fox.in.socks/api/ext/pie/v1.0')
        self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00')
        self.assertEqual(root.findtext('{0}description'.format(NS)),
            'The Fox In Socks Extension')

        xmlutil.validate_schema(root, 'extension')
Example #16
0
    def setUp(self):
        super(DiskConfigTestCase, self).setUp()
        self.flags(verbose=True)
        fakes.stub_out_nw_api(self.stubs)

        FAKE_INSTANCES = [
            fakes.stub_instance(1,
                                uuid=MANUAL_INSTANCE_UUID,
                                auto_disk_config=False),
            fakes.stub_instance(2,
                                uuid=AUTO_INSTANCE_UUID,
                                auto_disk_config=True)
        ]

        def fake_instance_get(context, id_):
            for instance in FAKE_INSTANCES:
                if id_ == instance['id']:
                    return instance

        self.stubs.Set(nova.db.api, 'instance_get', fake_instance_get)
        self.stubs.Set(nova.db, 'instance_get', fake_instance_get)

        def fake_instance_get_by_uuid(context, uuid):
            for instance in FAKE_INSTANCES:
                if uuid == instance['uuid']:
                    return instance

        self.stubs.Set(nova.db, 'instance_get_by_uuid',
                       fake_instance_get_by_uuid)

        def fake_instance_get_all(context, *args, **kwargs):
            return FAKE_INSTANCES

        self.stubs.Set(nova.db, 'instance_get_all', fake_instance_get_all)
        self.stubs.Set(nova.db.api, 'instance_get_all_by_filters',
                       fake_instance_get_all)

        def fake_instance_create(context, inst_, session=None):
            class FakeModel(dict):
                def save(self, session=None):
                    pass

            inst = FakeModel(**inst_)
            inst['id'] = 1
            inst['uuid'] = AUTO_INSTANCE_UUID
            inst['created_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0)
            inst['updated_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0)
            inst['progress'] = 0
            inst['name'] = 'instance-1'  # this is a property

            def fake_instance_get_for_create(context, id_, session=None):
                return inst

            self.stubs.Set(nova.db, 'instance_get',
                           fake_instance_get_for_create)
            self.stubs.Set(nova.db.api, 'instance_get',
                           fake_instance_get_for_create)
            self.stubs.Set(nova.db.sqlalchemy.api, 'instance_get',
                           fake_instance_get_for_create)

            def fake_instance_add_security_group(context, instance_id,
                                                 security_group_id):
                pass

            self.stubs.Set(nova.db.sqlalchemy.api,
                           'instance_add_security_group',
                           fake_instance_add_security_group)

            return inst

        self.stubs.Set(nova.db, 'instance_create', fake_instance_create)

        app = v2.APIRouter()
        app = extensions.ExtensionMiddleware(app)
        app = wsgi.LazySerializationMiddleware(app)
        self.app = app
Example #17
0
 def test_get_non_existing_extension_json(self):
     app = v2.APIRouter()
     ext_midware = extensions.ExtensionMiddleware(app)
     request = webob.Request.blank("/123/extensions/4")
     response = request.get_response(ext_midware)
     self.assertEqual(404, response.status_int)