Example #1
0
    def test_list_virtual_switch_xml(self):
        expected_out_xml = \
            '<virtualswitches xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/ext/healthnmon/api/v2.0">\
        <virtualswitch id="virtual-switch-01" name="virtual-switch-01">\
        <atom:link href="http://localhost:8774/v2.0/virtualswitches/virtual-switch-01" rel="self"/>\
        <atom:link href="http://localhost:8774/virtualswitches/virtual-switch-01" rel="bookmark"/>\
        </virtualswitch><virtualswitch id="virtual-switch-02" name="virtual-switch-02">\
        <atom:link href="http://localhost:8774/v2.0/virtualswitches/virtual-switch-02" rel="self"/>\
        <atom:link href="http://localhost:8774/virtualswitches/virtual-switch-02" rel="bookmark"/>\
        </virtualswitch></virtualswitches>'

        virtual_switch_list = self.get_virtual_switch_list()
        self.mock.StubOutWithMock(api, 'virtual_switch_get_all_by_filters')
        api.virtual_switch_get_all_by_filters(
            mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn(virtual_switch_list)
        self.mock.ReplayAll()
        request = webob.Request.blank('/v2.0/virtualswitches.xml',
                                      base_url='http://localhost:8774/v2.0/')
        request.environ['nova.context'] = self.admin_context
        resp = VirtualSwitchController().index(request)
        self.assertNotEqual(resp, None, 'Return xml string')
        self.compare_xml(expected_out_xml, resp.body)

        #        self.assertEqual(resp.body, self.expected_index_xml)

        self.mock.stubs.UnsetAll()
Example #2
0
    def test_virtual_switch_details_xml(self):
        expected_out_xml = \
            '<VirtualSwitch><id>virtual-switch-01</id><name>virtual-switch-01</name><switchType>dvSwitch</switchType>\
        <subnet xmlns:atom="http://www.w3.org/2005/Atom" id="subnet-3883">\
        <atom:link href="http://localhost:8774/v2.0/subnets/subnet-3883" rel="self"/>\
        <atom:link href="http://localhost:8774/subnets/subnet-3883" rel="bookmark"/></subnet>\
        <subnet xmlns:atom="http://www.w3.org/2005/Atom" id="subnet-323">\
        <atom:link href="http://localhost:8774/v2.0/subnets/subnet-323" rel="self"/>\
        <atom:link href="http://localhost:8774/subnets/subnet-323" rel="bookmark"/></subnet></VirtualSwitch>'

        virtual_switch_list = self.get_single_virtual_switch()
        self.mock.StubOutWithMock(api, 'virtual_switch_get_by_ids')

        api.virtual_switch_get_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(virtual_switch_list)
        self.mock.ReplayAll()
        request = \
            webob.Request.blank(
                '/v2.0/virtualswitches/virtual-switch-01.xml',
                base_url='http://localhost:8774/v2.0/'
            )
        request.environ['nova.context'] = self.admin_context
        resp = VirtualSwitchController().show(request, 'virtual-switch-01')
        self.assertNotEqual(resp, None,
                            'Return xml response for virtual-switch-01')
        self.compare_xml(expected_out_xml, resp.body)
        self.mock.stubs.UnsetAll()
Example #3
0
 def test_list_virtual_switch_none_check(self):
     self.mock.StubOutWithMock(api, 'virtual_switch_get_all_by_filters')
     api.virtual_switch_get_all_by_filters(mox.IgnoreArg(), mox.IgnoreArg(),
                                           mox.IgnoreArg(),
                                           mox.IgnoreArg()).AndReturn(None)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/virtualswitches',
                                   base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = VirtualSwitchController().index(request)
     self.assertEqual(resp.body, '{"virtualswitches": []}',
                      'Return json string')
Example #4
0
 def test_list_virtual_switch_detail_none_xml(self):
     virtual_switches = None
     self.mock.StubOutWithMock(api, 'virtual_switch_get_all_by_filters')
     api.virtual_switch_get_all_by_filters(
         mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(),
         mox.IgnoreArg()).AndReturn(virtual_switches)
     self.mock.ReplayAll()
     request = webob.Request.blank('/v2.0/virtualswitches/detail.xml',
                                   base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = VirtualSwitchController().detail(request)
     self.assertNotEqual(resp, None, 'Return xml string')
Example #5
0
 def test_list_limited_virtual_switch_detail_xml(self):
     virtual_switches = self.get_virtual_switch_list()
     self.mock.StubOutWithMock(api, 'virtual_switch_get_all_by_filters')
     api.virtual_switch_get_all_by_filters(
         mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(),
         mox.IgnoreArg()).AndReturn(virtual_switches)
     self.mock.ReplayAll()
     request = webob.Request.blank(
         '/v2.0/virtualswitches/detail.xml?'
         'limit=1&marker=virtual-switch-01',
         base_url='http://localhost:8774/v2.0/')
     request.environ['nova.context'] = self.admin_context
     resp = VirtualSwitchController().detail(request)
     self.assertEqual(resp.body, self.expected_limited_detail_xml)
Example #6
0
    def test_virtual_switch_none_details_xml(self):
        virtual_switch_list = None
        self.mock.StubOutWithMock(api, 'virtual_switch_get_by_ids')

        api.virtual_switch_get_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(virtual_switch_list)
        self.mock.ReplayAll()
        request = \
            webob.Request.blank(
                '/v2.0/virtualswitches/virtual-switch-01.xml',
                base_url='http://localhost:8774/v2.0/'
            )
        request.environ['nova.context'] = self.admin_context
        resp = VirtualSwitchController().show(request, 'virtual-switch-01')
        self.assertNotEqual(resp, None,
                            'Return xml response for virtual-switch-01')
        self.mock.stubs.UnsetAll()
Example #7
0
    def test_query_field_key(self):
        expected_out_json = '{"VirtualSwitch": {"id": "virtual-switch-01", "name": "virtual-switch-01"}}'

        virtual_switch_list = self.get_single_virtual_switch()
        self.mock.StubOutWithMock(api, 'virtual_switch_get_by_ids')

        api.virtual_switch_get_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(virtual_switch_list)
        self.mock.ReplayAll()
        request = \
            webob.Request.blank('/v2.0/vm/vm-01.json?fields=id,name',
                                base_url='http://localhost:8774/v2.0/')
        request.environ['nova.context'] = self.admin_context
        resp = VirtualSwitchController().show(request, 'virtual-switch-01')
        self.assertNotEqual(resp, None,
                            'Return xml response for virtual-switch-01')
        self.compare_json(expected_out_json, resp.body)
        self.mock.stubs.UnsetAll()
Example #8
0
    def test_virtual_switch_details_json_exception(self):
        virtual_switch_list = self.get_single_virtual_switch()
        xml_utils = util
        self.mock.StubOutWithMock(xml_utils, 'xml_to_dict')
        xml_utils.xml_to_dict(mox.IgnoreArg()).AndRaise(
            IndexError('Test index'))
        self.mock.StubOutWithMock(api, 'virtual_switch_get_by_ids')

        api.virtual_switch_get_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(virtual_switch_list)
        self.mock.ReplayAll()
        request = \
            webob.Request.blank(
                '/v2.0/virtualswitches/virtual-switch-01.json',
                base_url='http://localhost:8774/v2.0/')
        request.environ['nova.context'] = self.admin_context
        resp = VirtualSwitchController().show(request, 'virtual-switch-01')
        self.assertTrue(isinstance(resp, HTTPNotFound))
Example #9
0
    def test_list_virtual_switch_json(self):
        expected_out_json = \
            '{"virtualswitches": [{"id": "virtual-switch-01", "links": [{"href": "http://localhost:8774/v2.0/virtualswitches/virtual-switch-01", "rel": "self"}, \
        {"href": "http://localhost:8774/virtualswitches/virtual-switch-01", "rel": "bookmark"}], "name": "virtual-switch-01"}, \
        {"id": "virtual-switch-02", "links": [{"href": "http://localhost:8774/v2.0/virtualswitches/virtual-switch-02", "rel": "self"}, \
        {"href": "http://localhost:8774/virtualswitches/virtual-switch-02", "rel": "bookmark"}], "name": "virtual-switch-02"}]}'

        virtual_switch_list = self.get_virtual_switch_list()
        self.mock.StubOutWithMock(api, 'virtual_switch_get_all_by_filters')
        api.virtual_switch_get_all_by_filters(
            mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn(virtual_switch_list)
        self.mock.ReplayAll()
        request = webob.Request.blank('/v2.0/virtualswitches.json',
                                      base_url='http://localhost:8774/v2.0/')
        request.environ['nova.context'] = self.admin_context
        resp = VirtualSwitchController().index(request)
        self.assertNotEqual(resp, None, 'Return json string')
        self.compare_json(expected_out_json, resp.body)

        #        self.assertEqual(self.expected_index_json, resp.body)

        self.mock.stubs.UnsetAll()
Example #10
0
    def test_virtual_switch_details_json(self):
        expected_out_json = \
            '{"VirtualSwitch": {"subnets": [{"id": "subnet-3883", "links": [{"href": "http://localhost:8774/v2.0/subnets/subnet-3883", "rel": "self"}, \
        {"href": "http://localhost:8774/subnets/subnet-3883", "rel": "bookmark"}]}, \
        {"id": "subnet-323", "links": [{"href": "http://localhost:8774/v2.0/subnets/subnet-323", "rel": "self"}, \
        {"href": "http://localhost:8774/subnets/subnet-323", "rel": "bookmark"}]}], "id": "virtual-switch-01", "switchType": "dvSwitch", "name": "virtual-switch-01"}}'

        virtual_switch_list = self.get_single_virtual_switch()
        self.mock.StubOutWithMock(api, 'virtual_switch_get_by_ids')

        api.virtual_switch_get_by_ids(
            mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(virtual_switch_list)
        self.mock.ReplayAll()
        request = \
            webob.Request.blank(
                '/v2.0/virtualswitches/virtual-switch-01.json',
                base_url='http://localhost:8774/v2.0/'
            )
        request.environ['nova.context'] = self.admin_context
        resp = VirtualSwitchController().show(request, 'virtual-switch-01')
        self.assertNotEqual(resp, None,
                            'Return json response for virtual-switch-01')
        self.mock.stubs.UnsetAll()
        self.compare_json(expected_out_json, resp.body)