Пример #1
0
 def test_list_subnets_none_check(self):
     self.mock.StubOutWithMock(api, 'subnet_get_all_by_filters')
     api.subnet_get_all_by_filters(mox.IgnoreArg(), mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(None)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/subnets',
                                   base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = SubnetController().index(request)
     self.assertEqual(resp.body, '{"subnets": []}', 'Return json string')
Пример #2
0
 def test_list_subnet_detail_xml(self):
     subnet_list = self.get_subnet_list()
     self.mock.StubOutWithMock(api, 'subnet_get_all_by_filters')
     api.subnet_get_all_by_filters(mox.IgnoreArg(), mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(subnet_list)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/subnets/detail.xml',
                                   base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = SubnetController().detail(request)
     self.assertEqual(resp.body, self.expected_detail_xml)
Пример #3
0
 def test_list_subnets_none_check(self):
     self.mock.StubOutWithMock(api, 'subnet_get_all_by_filters')
     api.subnet_get_all_by_filters(mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(None)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/subnets',
                                   base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = SubnetController().index(request)
     self.assertEqual(resp.body, '{"subnets": []}',
                      'Return json string')
Пример #4
0
 def test_list_subnet_none_detail_xml(self):
     subnet_list = None
     self.mock.StubOutWithMock(api, 'subnet_get_all_by_filters')
     api.subnet_get_all_by_filters(mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(subnet_list)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/subnets/detail.xml',
                                   base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = SubnetController().detail(request)
     self.assertNotEqual(resp, None, 'Return xml string')
Пример #5
0
 def test_list_subnet_json(self):
     subnet_list = self.get_subnet_list()
     self.mock.StubOutWithMock(api, 'subnet_get_all_by_filters')
     api.subnet_get_all_by_filters(mox.IgnoreArg(), mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(subnet_list)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/subnets.json',
                                   base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = SubnetController().index(request)
     self.assertNotEqual(resp, None, 'Return json string')
     self.assertEqual(self.expected_index_json, resp.body)
     self.mock.stubs.UnsetAll()
Пример #6
0
 def test_list_limited_subnet_detail_xml(self):
     subnet_list = self.get_subnet_list()
     self.mock.StubOutWithMock(api, 'subnet_get_all_by_filters')
     api.subnet_get_all_by_filters(mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(subnet_list)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/subnets/detail.xml?'
                                   'limit=1&marker=subnet-01',
                                   base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = SubnetController().detail(request)
     self.assertEqual(resp.body, self.expected_limited_detail_xml)
Пример #7
0
 def test_list_subnet_xml_header(self):
     subnets = self.get_subnet_list()
     self.mock.StubOutWithMock(api, 'subnet_get_all_by_filters')
     api.subnet_get_all_by_filters(mox.IgnoreArg(), mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(subnets)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/subnets',
                                   base_url='http://localhost:8774/v2.0/')
     request.headers['Accept'] = 'application/xml'
     request.environ['nova.context'] = self.admin_context
     resp = SubnetController().index(request)
     self.assertNotEqual(resp, None, 'Return xml string')
     self.assertEqual(resp.body, self.expected_xml_header)
     self.mock.stubs.UnsetAll()
Пример #8
0
 def test_list_subnet_json(self):
     subnet_list = self.get_subnet_list()
     self.mock.StubOutWithMock(api, 'subnet_get_all_by_filters')
     api.subnet_get_all_by_filters(mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(subnet_list)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/subnets.json',
                                   base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = SubnetController().index(request)
     self.assertNotEqual(resp, None, 'Return json string')
     self.assertEqual(self.expected_index_json, resp.body)
     self.mock.stubs.UnsetAll()
Пример #9
0
 def test_list_subnet_xml_header(self):
     subnets = self.get_subnet_list()
     self.mock.StubOutWithMock(api, 'subnet_get_all_by_filters')
     api.subnet_get_all_by_filters(mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(subnets)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/subnets',
                                   base_url='http://localhost:8774/v2.0/')
     request.headers['Accept'] = 'application/xml'
     request.environ['nova.context'] = self.admin_context
     resp = SubnetController().index(request)
     self.assertNotEqual(resp, None, 'Return xml string')
     self.assertEqual(resp.body, self.expected_xml_header)
     self.mock.stubs.UnsetAll()
Пример #10
0
def subnet_get_all_by_filters(context, filters, sort_key, sort_dir):
    """ This API will make a call to db layer to fetch the list of all the
        Subnet objects.
        Parameters:
            context - nova.context.RequestContext object
            filters - dictionary of filters to be applied
                      keys should be fields of Subnet model
                      if value is simple value = filter is applied and
                      if value is list or tuple 'IN' filter is applied
                      eg : {'isPublic':True, 'name':['n1', 'n2']} will filter as
                      isPublic = True AND name in ('n1', 'n2')
            sort_key - Field on which sorting is to be applied
            sort_dir - asc for Ascending sort direction, desc for descending sort direction
        Returns:
            list of subnet that match all filters and sorted with sort_key
    """
    return api.subnet_get_all_by_filters(context, filters, sort_key, sort_dir)
Пример #11
0
def subnet_get_all_by_filters(context, filters, sort_key, sort_dir):
    """ This API will make a call to db layer to fetch the list of all the
        Subnet objects.
        Parameters:
            context - nova.context.RequestContext object
            filters - dictionary of filters to be applied
                      keys should be fields of Subnet model
                      if value is simple value = filter is applied and
                      if value is list or tuple 'IN' filter is applied
                      eg : {'isPublic':True, 'name':['n1', 'n2']} will filter as
                      isPublic = True AND name in ('n1', 'n2')
            sort_key - Field on which sorting is to be applied
            sort_dir - asc for Ascending sort direction, desc for descending sort direction
        Returns:
            list of subnet that match all filters and sorted with sort_key
    """
    return api.subnet_get_all_by_filters(context, filters, sort_key, sort_dir)