Esempio n. 1
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()
Esempio n. 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()
Esempio n. 3
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()
Esempio n. 4
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()
Esempio n. 5
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))
 def test_timestamp_columns(self):
     """
         Test the time stamp columns createEpoch,
         modifiedEpoch and deletedEpoch
     """
     virSw1 = VirtualSwitch()
     virSw1.set_id("VS1_VH1")
     portGrp1 = PortGroup()
     portGrp1.set_id("PG1_VH1")
     virSw1.add_portGroups(portGrp1)
     # Check for createEpoch
     epoch_before = utils.get_current_epoch_ms()
     api.virtual_switch_save(self.admin_context, virSw1)
     epoch_after = utils.get_current_epoch_ms()
     virsw_queried = api.virtual_switch_get_by_ids(self.admin_context, [virSw1.get_id()])[0]
     self.assert_(test_utils.is_timestamp_between(epoch_before, epoch_after, virsw_queried.get_createEpoch()))
     for pg in virsw_queried.get_portGroups():
         self.assert_(test_utils.is_timestamp_between(epoch_before, epoch_after, pg.get_createEpoch()))
     # Check for lastModifiedEpoch after modifying switch
     virsw_modified = virsw_queried
     test_utils.unset_timestamp_fields(virsw_modified)
     virsw_modified.set_name("changed_name")
     epoch_before = utils.get_current_epoch_ms()
     api.virtual_switch_save(self.admin_context, virsw_modified)
     epoch_after = utils.get_current_epoch_ms()
     virsw_queried = api.virtual_switch_get_by_ids(self.admin_context, [virSw1.get_id()])[0]
     self.assert_(virsw_modified.get_createEpoch() == virsw_queried.get_createEpoch())
     self.assert_(test_utils.is_timestamp_between(epoch_before, epoch_after, virsw_queried.get_lastModifiedEpoch()))
     for pg in virsw_queried.get_portGroups():
         self.assert_(virsw_modified.get_portGroups()[0].get_createEpoch() == pg.get_createEpoch())
         self.assert_(test_utils.is_timestamp_between(epoch_before, epoch_after, pg.get_lastModifiedEpoch()))
     # Check for createdEpoch after adding portgroup to switch
     virsw_modified = virsw_queried
     test_utils.unset_timestamp_fields(virsw_modified)
     portGrp2 = PortGroup()
     portGrp2.set_id("PG2_VH1")
     virsw_modified.add_portGroups(portGrp2)
     epoch_before = utils.get_current_epoch_ms()
     api.virtual_switch_save(self.admin_context, virsw_modified)
     epoch_after = utils.get_current_epoch_ms()
     virsw_queried = api.virtual_switch_get_by_ids(self.admin_context, [virSw1.get_id()])[0]
     self.assert_(virsw_modified.get_createEpoch() == virsw_queried.get_createEpoch())
     self.assert_(test_utils.is_timestamp_between(epoch_before, epoch_after, virsw_queried.get_lastModifiedEpoch()))
     for pg in virsw_queried.get_portGroups():
         if pg.get_id() == portGrp2.get_id():
             self.assert_(test_utils.is_timestamp_between(epoch_before, epoch_after, pg.get_createEpoch()))
         else:
             self.assert_(test_utils.is_timestamp_between(epoch_before, epoch_after, pg.get_lastModifiedEpoch()))
 def test_virtual_switch_get_all_by_filters_changessince(self):
     # Create VirtualSwitches
     switch_ids = ('SW1', 'SW2', 'SW3')
     switch_names = ('name1', 'name2', 'name3')
     for i in range(len(switch_ids)):
         self.__create_virtual_switch(
             id=switch_ids[i], name=switch_names[i])
     created_time = long(time.time() * 1000L)
     # Wait for 1 sec and update second switch and delete third switch
     time.sleep(1)
     second_switch = api.virtual_switch_get_by_ids(
         self.admin_context, [switch_ids[1]])[0]
     second_switch.name = 'New name'
     api.virtual_switch_save(self.admin_context, second_switch)
     api.virtual_switch_delete_by_ids(self.admin_context, [switch_ids[2]])
     # Query with filter
     expected_updated_ids = [switch_ids[1], switch_ids[2]]
     filters = {'changes-since': created_time}
     switches = api.virtual_switch_get_all_by_filters(
         self.admin_context, filters,
         None, None)
     self.assert_(switches is not None)
     self.assert_(len(switches) == 2)
     for switch in switches:
         self.assert_(switch is not None)
         self.assert_(switch.id in expected_updated_ids)
Esempio n. 8
0
    def test_virtual_switch_multiple_save(self):
        """Test case to test the modification of VirtualSwitch along with Subnet"""
        virtualswitch = VirtualSwitch()
        virtualswitch.id = 'VS1'
        virtualswitch.switchType = 'switch'
        subnet_id_lst = ["subnet_1", "subnet_2"]
        'Add one subnet'
        self.__create_subnet(id=subnet_id_lst[0], name=subnet_id_lst[0])
        virtualswitch.set_subnetIds(subnet_id_lst)
        api.virtual_switch_save(self.admin_context, virtualswitch)

        'Update the virtual switch'
        virtualswitch.switchType = 'switchUpdated'
        'Add second subnet'
        self.__create_subnet(id=subnet_id_lst[1], name=subnet_id_lst[1])
        api.virtual_switch_save(self.admin_context, virtualswitch)
        virtualswitches = api.virtual_switch_get_by_ids(
            self.admin_context, [virtualswitch.id])

        self.assertFalse(virtualswitches is None,
                         'VirtualSwitch  all returned a list')
        self.assertTrue(virtualswitches[0].id == 'VS1',
                        'Virtual Switch id mismatch')
        self.assertTrue(virtualswitches[0].switchType == 'switchUpdated',
                        'Virtual Switch type mismatch')
        self.assertTrue(
            len(virtualswitches[0].subnetIds) >= 0,
            'Virtual Switch - subnetIds does not exist')
        self.assertTrue(virtualswitches[0].subnetIds[0] in subnet_id_lst,
                        'Virtual Switch - subnetIds is not api output')
        self.assertTrue(virtualswitches[0].subnetIds[1] in subnet_id_lst,
                        'Virtual Switch - subnetIds is not api output')
Esempio n. 9
0
 def test_virtual_switch_get_all_by_filters_changessince(self):
     # Create VirtualSwitches
     switch_ids = ('SW1', 'SW2', 'SW3')
     switch_names = ('name1', 'name2', 'name3')
     for i in range(len(switch_ids)):
         self.__create_virtual_switch(id=switch_ids[i],
                                      name=switch_names[i])
     created_time = long(time.time() * 1000L)
     # Wait for 1 sec and update second switch and delete third switch
     time.sleep(1)
     second_switch = api.virtual_switch_get_by_ids(self.admin_context,
                                                   [switch_ids[1]])[0]
     second_switch.name = 'New name'
     api.virtual_switch_save(self.admin_context, second_switch)
     api.virtual_switch_delete_by_ids(self.admin_context, [switch_ids[2]])
     # Query with filter
     expected_updated_ids = [switch_ids[1], switch_ids[2]]
     filters = {'changes-since': created_time}
     switches = api.virtual_switch_get_all_by_filters(
         self.admin_context, filters, None, None)
     self.assert_(switches is not None)
     self.assert_(len(switches) == 2)
     for switch in switches:
         self.assert_(switch is not None)
         self.assert_(switch.id in expected_updated_ids)
    def test_virtual_switch_multiple_save(self):
        """Test case to test the modification of VirtualSwitch along with Subnet"""
        virtualswitch = VirtualSwitch()
        virtualswitch.id = "VS1"
        virtualswitch.switchType = "switch"
        subnet_id_lst = ["subnet_1", "subnet_2"]
        "Add one subnet"
        self.__create_subnet(id=subnet_id_lst[0], name=subnet_id_lst[0])
        virtualswitch.set_subnetIds(subnet_id_lst)
        api.virtual_switch_save(self.admin_context, virtualswitch)

        "Update the virtual switch"
        virtualswitch.switchType = "switchUpdated"
        "Add second subnet"
        self.__create_subnet(id=subnet_id_lst[1], name=subnet_id_lst[1])
        api.virtual_switch_save(self.admin_context, virtualswitch)
        virtualswitches = api.virtual_switch_get_by_ids(self.admin_context, [virtualswitch.id])

        self.assertFalse(virtualswitches is None, "VirtualSwitch  all returned a list")
        self.assertTrue(virtualswitches[0].id == "VS1", "Virtual Switch id mismatch")
        self.assertTrue(virtualswitches[0].switchType == "switchUpdated", "Virtual Switch type mismatch")
        self.assertTrue(len(virtualswitches[0].subnetIds) >= 0, "Virtual Switch - subnetIds does not exist")
        self.assertTrue(
            virtualswitches[0].subnetIds[0] in subnet_id_lst, "Virtual Switch - subnetIds is not api output"
        )
        self.assertTrue(
            virtualswitches[0].subnetIds[1] in subnet_id_lst, "Virtual Switch - subnetIds is not api output"
        )
Esempio n. 11
0
def virtual_switch_get_by_ids(context, virtual_switch_ids):
    """ Fetch virtual switch details of the ids
            Parameters:
            virtual_switch_ids - List of virtual switch ids
            context - nova.context.RequestContext object
    """

    return api.virtual_switch_get_by_ids(context, virtual_switch_ids)
Esempio n. 12
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()
Esempio n. 13
0
def virtual_switch_get_by_ids(context, virtual_switch_ids):
    """ Fetch virtual switch details of the ids
            Parameters:
            virtual_switch_ids - List of virtual switch ids
            context - nova.context.RequestContext object
    """

    return api.virtual_switch_get_by_ids(context, virtual_switch_ids)
Esempio n. 14
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()
Esempio n. 15
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))
 def test_virtual_switch_get_by_ids(self):
     virtualswitch = VirtualSwitch()
     virtualswitch.id = "VS1"
     virtualswitch.switchType = "switch"
     api.virtual_switch_save(self.admin_context, virtualswitch)
     virtualswitches = api.virtual_switch_get_by_ids(self.admin_context, [virtualswitch.id])
     self.assertFalse(virtualswitches is None, "VirtualSwitch  all returned a list")
     self.assertTrue(virtualswitches[0].id == "VS1", "Virtual Switch Id mismatch")
     self.assertTrue(virtualswitches[0].switchType == "switch", "Virtual Switch Type mismatch")
Esempio n. 17
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)
Esempio n. 18
0
 def test_virtual_switch_get_by_ids(self):
     virtualswitch = VirtualSwitch()
     virtualswitch.id = 'VS1'
     virtualswitch.switchType = 'switch'
     api.virtual_switch_save(self.admin_context, virtualswitch)
     virtualswitches = \
         api.virtual_switch_get_by_ids(self.admin_context,
                                       [virtualswitch.id])
     self.assertFalse(virtualswitches is None,
                      'VirtualSwitch  all returned a list')
     self.assertTrue(virtualswitches[0].id == 'VS1',
                     'Virtual Switch Id mismatch')
     self.assertTrue(virtualswitches[0].switchType == 'switch',
                     'Virtual Switch Type mismatch')
 def test_virtual_switch_get_by_ids(self):
     virtualswitch = VirtualSwitch()
     virtualswitch.id = 'VS1'
     virtualswitch.switchType = 'switch'
     api.virtual_switch_save(self.admin_context, virtualswitch)
     virtualswitches = \
         api.virtual_switch_get_by_ids(self.admin_context,
                                       [virtualswitch.id])
     self.assertFalse(virtualswitches is None,
                      'VirtualSwitch  all returned a list')
     self.assertTrue(
         virtualswitches[0].id == 'VS1', 'Virtual Switch Id mismatch')
     self.assertTrue(virtualswitches[0].switchType == 'switch',
                     'Virtual Switch Type mismatch')
Esempio n. 20
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)
    def test_virtual_switch_delete(self):
        virtualswitch = VirtualSwitch()
        virtualswitch.id = "VS1"
        virtualswitch.switchType = "switch"

        portGroup = PortGroup()
        portGroup.set_id("pg-01")
        portGroup.set_name("pg-01")
        portGroup.set_resourceManagerId("rmId")
        portGroup.set_type("portgroup_type")
        virtualswitch.add_portGroups(portGroup)
        api.virtual_switch_save(self.admin_context, virtualswitch)

        # virtualswitchs = api.virtual_switch_get_by_ids([virtualswitch.id])

        api.virtual_switch_delete_by_ids(self.admin_context, [virtualswitch.id])
        virtualswitchs = api.virtual_switch_get_by_ids(self.admin_context, [virtualswitch.id])
        self.assertTrue(virtualswitchs is None or len(virtualswitchs) == 0, "switch not deleted")
Esempio n. 22
0
    def test_virtual_switch_delete(self):
        virtualswitch = VirtualSwitch()
        virtualswitch.id = 'VS1'
        virtualswitch.switchType = 'switch'

        portGroup = PortGroup()
        portGroup.set_id('pg-01')
        portGroup.set_name('pg-01')
        portGroup.set_resourceManagerId('rmId')
        portGroup.set_type('portgroup_type')
        virtualswitch.add_portGroups(portGroup)
        api.virtual_switch_save(self.admin_context, virtualswitch)

        #virtualswitchs = api.virtual_switch_get_by_ids([virtualswitch.id])

        api.virtual_switch_delete_by_ids(self.admin_context,
                                         [virtualswitch.id])
        virtualswitchs = \
            api.virtual_switch_get_by_ids(self.admin_context,
                                          [virtualswitch.id])
        self.assertTrue(virtualswitchs is None or len(virtualswitchs) == 0,
                        'switch not deleted')
    def test_virtual_switch_delete(self):
        virtualswitch = VirtualSwitch()
        virtualswitch.id = 'VS1'
        virtualswitch.switchType = 'switch'

        portGroup = PortGroup()
        portGroup.set_id('pg-01')
        portGroup.set_name('pg-01')
        portGroup.set_resourceManagerId('rmId')
        portGroup.set_type('portgroup_type')
        virtualswitch.add_portGroups(portGroup)
        api.virtual_switch_save(self.admin_context, virtualswitch)

        #virtualswitchs = api.virtual_switch_get_by_ids([virtualswitch.id])

        api.virtual_switch_delete_by_ids(self.admin_context,
                                         [virtualswitch.id])
        virtualswitchs = \
            api.virtual_switch_get_by_ids(self.admin_context,
                                          [virtualswitch.id])
        self.assertTrue(virtualswitchs is None or len(virtualswitchs)
                        == 0, 'switch not deleted')
Esempio n. 24
0
 def test_timestamp_columns(self):
     """
         Test the time stamp columns createEpoch, modifiedEpoch and deletedEpoch
     """
     virSw1 = VirtualSwitch()
     virSw1.set_id('VS1_VH1')
     portGrp1 = PortGroup()
     portGrp1.set_id('PG1_VH1')
     virSw1.add_portGroups(portGrp1)
     # Check for createEpoch
     epoch_before = utils.get_current_epoch_ms()
     api.virtual_switch_save(self.admin_context, virSw1)
     epoch_after = utils.get_current_epoch_ms()
     virsw_queried = api.virtual_switch_get_by_ids(self.admin_context,
                                                   [virSw1.get_id()])[0]
     self.assert_(
         test_utils.is_timestamp_between(epoch_before, epoch_after,
                                         virsw_queried.get_createEpoch()))
     for pg in virsw_queried.get_portGroups():
         self.assert_(
             test_utils.is_timestamp_between(epoch_before, epoch_after,
                                             pg.get_createEpoch()))
     # Check for lastModifiedEpoch after modifying switch
     virsw_modified = virsw_queried
     test_utils.unset_timestamp_fields(virsw_modified)
     virsw_modified.set_name('changed_name')
     epoch_before = utils.get_current_epoch_ms()
     api.virtual_switch_save(self.admin_context, virsw_modified)
     epoch_after = utils.get_current_epoch_ms()
     virsw_queried = api.virtual_switch_get_by_ids(self.admin_context,
                                                   [virSw1.get_id()])[0]
     self.assert_(virsw_modified.get_createEpoch() ==
                  virsw_queried.get_createEpoch())
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after,
             virsw_queried.get_lastModifiedEpoch()))
     for pg in virsw_queried.get_portGroups():
         self.assert_(virsw_modified.get_portGroups()[0].get_createEpoch()
                      == pg.get_createEpoch())
         self.assert_(
             test_utils.is_timestamp_between(epoch_before, epoch_after,
                                             pg.get_lastModifiedEpoch()))
     # Check for createdEpoch after adding portgroup to switch
     virsw_modified = virsw_queried
     test_utils.unset_timestamp_fields(virsw_modified)
     portGrp2 = PortGroup()
     portGrp2.set_id('PG2_VH1')
     virsw_modified.add_portGroups(portGrp2)
     epoch_before = utils.get_current_epoch_ms()
     api.virtual_switch_save(self.admin_context, virsw_modified)
     epoch_after = utils.get_current_epoch_ms()
     virsw_queried = api.virtual_switch_get_by_ids(self.admin_context,
                                                   [virSw1.get_id()])[0]
     self.assert_(virsw_modified.get_createEpoch() ==
                  virsw_queried.get_createEpoch())
     self.assert_(
         test_utils.is_timestamp_between(
             epoch_before, epoch_after,
             virsw_queried.get_lastModifiedEpoch()))
     for pg in virsw_queried.get_portGroups():
         if pg.get_id() == portGrp2.get_id():
             self.assert_(
                 test_utils.is_timestamp_between(epoch_before, epoch_after,
                                                 pg.get_createEpoch()))
         else:
             self.assert_(
                 test_utils.is_timestamp_between(
                     epoch_before, epoch_after, pg.get_lastModifiedEpoch()))
Esempio n. 25
0
 def test_virtual_switch_save_with_subnet(self):
     # Save virtual switch with a port group
     vSwitch = VirtualSwitch()
     vSwitch.set_id('vSwitch-11')
     vSwitch.set_name('vSwitch-11')
     vSwitch.set_resourceManagerId('rmId')
     vSwitch.set_switchType('vSwitch')
     cost1 = Cost()
     cost1.set_value(100)
     cost1.set_units('USD')
     vSwitch.set_cost(cost1)
     portGroup = PortGroup()
     portGroup.set_id('pg-01')
     portGroup.set_name('pg-01')
     portGroup.set_resourceManagerId('rmId')
     portGroup.set_type('portgroup_type')
     portGroup.set_cost(cost1)
     vSwitch.add_portGroups(portGroup)
     api.virtual_switch_save(self.admin_context, vSwitch)
     # Update after adding a port group and subnet
     vSwitch = api.virtual_switch_get_by_ids(self.admin_context,
                                             [vSwitch.id])[0]
     portGroup2 = PortGroup()
     portGroup2.set_id('pg-02')
     portGroup2.set_name('pg-02')
     portGroup2.set_resourceManagerId('rmId')
     portGroup2.set_type('portgroup_type')
     vSwitch.add_portGroups(portGroup2)
     subnet = Subnet()
     subnet.set_id('subnet-02')
     subnet.set_name('subnet-02')
     subnet.set_networkAddress('1.1.1.1')
     api.subnet_save(self.admin_context, subnet)
     vSwitch.add_subnetIds(subnet.id)
     vSwitch.add_networkInterfaces('1')
     api.virtual_switch_save(self.admin_context, vSwitch)
     virtualswitches = \
         api.virtual_switch_get_by_ids(self.admin_context,
                                       [vSwitch.id])
     # Assert the values
     self.assertTrue(
         len(virtualswitches) == 1,
         'Unexpected number of Virtual Switch returned')
     self.assertTrue(virtualswitches[0].get_id() == 'vSwitch-11',
                     'Virtual Switch id mismatch')
     self.assertTrue(virtualswitches[0].get_name() == 'vSwitch-11',
                     'Virtual Switch name mismatch')
     self.assertTrue(virtualswitches[0].get_resourceManagerId() == 'rmId',
                     'Virtual Switch Resource Manager id mismatch')
     self.assertTrue(virtualswitches[0].get_switchType() == 'vSwitch',
                     'Virtual Switch type mismatch')
     cost1 = virtualswitches[0].get_cost()
     self.assertTrue(cost1.get_value() == 100,
                     'VSwitch Cost Value mismatch')
     self.assertTrue(cost1.get_units() == 'USD',
                     'VSwitch Cost units mismatch')
     portGroups = virtualswitches[0].get_portGroups()
     self.assertTrue(
         len(portGroups) == 2, 'All the portgroups have not been saved')
     self.assertTrue(portGroups[0].get_id() == 'pg-01',
                     'VSwitch Port Group id mismatch')
     self.assertTrue(portGroups[0].get_name() == 'pg-01',
                     'VSwitch Port Group Name mismatch')
     self.assertTrue(portGroups[0].get_resourceManagerId() == 'rmId',
                     'VSwitch portgroup Resource Manager id mismatch')
     self.assertTrue(portGroups[0].get_type() == 'portgroup_type',
                     'VSwitch port group type mismatched')
     cost2 = portGroups[0].get_cost()
     self.assertTrue(cost2.get_value() == 100,
                     'PortGroup Cost Value mismatch')
     self.assertTrue(cost2.get_units() == 'USD',
                     'PortGroup Cost units mismatch')
     self.assertTrue(portGroups[1].get_id() == 'pg-02',
                     'VSwitch Port Group id mismatch')
     self.assertTrue(portGroups[1].get_name() == 'pg-02',
                     'VSwitch Port Group Name mismatch')
     self.assertTrue(portGroups[1].get_resourceManagerId() == 'rmId',
                     'VSwitch portgroup Resource Manager id mismatch')
     self.assertTrue(portGroups[1].get_type() == 'portgroup_type',
                     'VSwitch port group type mismatched')
     subnetId = virtualswitches[0].get_subnetIds()
     self.assertTrue(subnetId[0] == 'subnet-02',
                     'Virtual Switch subnet id mismatch')
     self.assertTrue(virtualswitches[0].get_networkInterfaces()[0] == '1',
                     'Virtual Switch network INterfaces mismatch')
 def test_virtual_switch_save_with_subnet(self):
     # Save virtual switch with a port group
     vSwitch = VirtualSwitch()
     vSwitch.set_id('vSwitch-11')
     vSwitch.set_name('vSwitch-11')
     vSwitch.set_resourceManagerId('rmId')
     vSwitch.set_switchType('vSwitch')
     cost1 = Cost()
     cost1.set_value(100)
     cost1.set_units('USD')
     vSwitch.set_cost(cost1)
     portGroup = PortGroup()
     portGroup.set_id('pg-01')
     portGroup.set_name('pg-01')
     portGroup.set_resourceManagerId('rmId')
     portGroup.set_type('portgroup_type')
     portGroup.set_cost(cost1)
     vSwitch.add_portGroups(portGroup)
     api.virtual_switch_save(self.admin_context, vSwitch)
     # Update after adding a port group and subnet
     vSwitch = api.virtual_switch_get_by_ids(self.admin_context,
                                             [vSwitch.id])[0]
     portGroup2 = PortGroup()
     portGroup2.set_id('pg-02')
     portGroup2.set_name('pg-02')
     portGroup2.set_resourceManagerId('rmId')
     portGroup2.set_type('portgroup_type')
     vSwitch.add_portGroups(portGroup2)
     subnet = Subnet()
     subnet.set_id('subnet-02')
     subnet.set_name('subnet-02')
     subnet.set_networkAddress('1.1.1.1')
     api.subnet_save(self.admin_context, subnet)
     vSwitch.add_subnetIds(subnet.id)
     vSwitch.add_networkInterfaces('1')
     api.virtual_switch_save(self.admin_context, vSwitch)
     virtualswitches = \
         api.virtual_switch_get_by_ids(self.admin_context,
                                       [vSwitch.id])
     # Assert the values
     self.assertTrue(len(virtualswitches) == 1,
                     'Unexpected number of Virtual Switch returned')
     self.assertTrue(virtualswitches[0].get_id(
     ) == 'vSwitch-11', 'Virtual Switch id mismatch')
     self.assertTrue(virtualswitches[0].get_name(
     ) == 'vSwitch-11', 'Virtual Switch name mismatch')
     self.assertTrue(virtualswitches[0].get_resourceManagerId(
     ) == 'rmId', 'Virtual Switch Resource Manager id mismatch')
     self.assertTrue(virtualswitches[0].get_switchType(
     ) == 'vSwitch', 'Virtual Switch type mismatch')
     cost1 = virtualswitches[0].get_cost()
     self.assertTrue(
         cost1.get_value() == 100, 'VSwitch Cost Value mismatch')
     self.assertTrue(
         cost1.get_units() == 'USD', 'VSwitch Cost units mismatch')
     portGroups = virtualswitches[0].get_portGroups()
     self.assertTrue(
         len(portGroups) == 2, 'All the portgroups have not been saved')
     self.assertTrue(portGroups[0].get_id(
     ) == 'pg-01', 'VSwitch Port Group id mismatch')
     self.assertTrue(portGroups[0].get_name(
     ) == 'pg-01', 'VSwitch Port Group Name mismatch')
     self.assertTrue(portGroups[0].get_resourceManagerId(
     ) == 'rmId', 'VSwitch portgroup Resource Manager id mismatch')
     self.assertTrue(portGroups[0].get_type(
     ) == 'portgroup_type', 'VSwitch port group type mismatched')
     cost2 = portGroups[0].get_cost()
     self.assertTrue(
         cost2.get_value() == 100, 'PortGroup Cost Value mismatch')
     self.assertTrue(
         cost2.get_units() == 'USD', 'PortGroup Cost units mismatch')
     self.assertTrue(portGroups[1].get_id(
     ) == 'pg-02', 'VSwitch Port Group id mismatch')
     self.assertTrue(portGroups[1].get_name(
     ) == 'pg-02', 'VSwitch Port Group Name mismatch')
     self.assertTrue(portGroups[1].get_resourceManagerId(
     ) == 'rmId', 'VSwitch portgroup Resource Manager id mismatch')
     self.assertTrue(portGroups[1].get_type(
     ) == 'portgroup_type', 'VSwitch port group type mismatched')
     subnetId = virtualswitches[0].get_subnetIds()
     self.assertTrue(
         subnetId[0] == 'subnet-02', 'Virtual Switch subnet id mismatch')
     self.assertTrue(virtualswitches[0].get_networkInterfaces(
     )[0] == '1', 'Virtual Switch network INterfaces mismatch')
 def test_virtual_switch_get_by_ids_none(self):
     virtualswitches = api.virtual_switch_get_by_ids(self.admin_context, None)
     self.assertTrue(virtualswitches is None, "VirtualSwitch  all returned a none list")
Esempio n. 28
0
 def test_virtual_switch_get_by_ids_none(self):
     virtualswitches = \
         api.virtual_switch_get_by_ids(self.admin_context, None)
     self.assertTrue(virtualswitches is None,
                     'VirtualSwitch  all returned a none list')
 def test_virtual_switch_save_with_subnet(self):
     # Save virtual switch with a port group
     vSwitch = VirtualSwitch()
     vSwitch.set_id("vSwitch-11")
     vSwitch.set_name("vSwitch-11")
     vSwitch.set_resourceManagerId("rmId")
     vSwitch.set_switchType("vSwitch")
     cost1 = Cost()
     cost1.set_value(100)
     cost1.set_units("USD")
     vSwitch.set_cost(cost1)
     portGroup = PortGroup()
     portGroup.set_id("pg-01")
     portGroup.set_name("pg-01")
     portGroup.set_resourceManagerId("rmId")
     portGroup.set_type("portgroup_type")
     portGroup.set_cost(cost1)
     vSwitch.add_portGroups(portGroup)
     api.virtual_switch_save(self.admin_context, vSwitch)
     # Update after adding a port group and subnet
     vSwitch = api.virtual_switch_get_by_ids(self.admin_context, [vSwitch.id])[0]
     portGroup2 = PortGroup()
     portGroup2.set_id("pg-02")
     portGroup2.set_name("pg-02")
     portGroup2.set_resourceManagerId("rmId")
     portGroup2.set_type("portgroup_type")
     vSwitch.add_portGroups(portGroup2)
     subnet = Subnet()
     subnet.set_id("subnet-02")
     subnet.set_name("subnet-02")
     subnet.set_networkAddress("1.1.1.1")
     api.subnet_save(self.admin_context, subnet)
     vSwitch.add_subnetIds(subnet.id)
     vSwitch.add_networkInterfaces("1")
     api.virtual_switch_save(self.admin_context, vSwitch)
     virtualswitches = api.virtual_switch_get_by_ids(self.admin_context, [vSwitch.id])
     # Assert the values
     self.assertTrue(len(virtualswitches) == 1, "Unexpected number of Virtual Switch returned")
     self.assertTrue(virtualswitches[0].get_id() == "vSwitch-11", "Virtual Switch id mismatch")
     self.assertTrue(virtualswitches[0].get_name() == "vSwitch-11", "Virtual Switch name mismatch")
     self.assertTrue(
         virtualswitches[0].get_resourceManagerId() == "rmId", "Virtual Switch Resource Manager id mismatch"
     )
     self.assertTrue(virtualswitches[0].get_switchType() == "vSwitch", "Virtual Switch type mismatch")
     cost1 = virtualswitches[0].get_cost()
     self.assertTrue(cost1.get_value() == 100, "VSwitch Cost Value mismatch")
     self.assertTrue(cost1.get_units() == "USD", "VSwitch Cost units mismatch")
     portGroups = virtualswitches[0].get_portGroups()
     self.assertTrue(len(portGroups) == 2, "All the portgroups have not been saved")
     self.assertTrue(portGroups[0].get_id() == "pg-01", "VSwitch Port Group id mismatch")
     self.assertTrue(portGroups[0].get_name() == "pg-01", "VSwitch Port Group Name mismatch")
     self.assertTrue(
         portGroups[0].get_resourceManagerId() == "rmId", "VSwitch portgroup Resource Manager id mismatch"
     )
     self.assertTrue(portGroups[0].get_type() == "portgroup_type", "VSwitch port group type mismatched")
     cost2 = portGroups[0].get_cost()
     self.assertTrue(cost2.get_value() == 100, "PortGroup Cost Value mismatch")
     self.assertTrue(cost2.get_units() == "USD", "PortGroup Cost units mismatch")
     self.assertTrue(portGroups[1].get_id() == "pg-02", "VSwitch Port Group id mismatch")
     self.assertTrue(portGroups[1].get_name() == "pg-02", "VSwitch Port Group Name mismatch")
     self.assertTrue(
         portGroups[1].get_resourceManagerId() == "rmId", "VSwitch portgroup Resource Manager id mismatch"
     )
     self.assertTrue(portGroups[1].get_type() == "portgroup_type", "VSwitch port group type mismatched")
     subnetId = virtualswitches[0].get_subnetIds()
     self.assertTrue(subnetId[0] == "subnet-02", "Virtual Switch subnet id mismatch")
     self.assertTrue(
         virtualswitches[0].get_networkInterfaces()[0] == "1", "Virtual Switch network INterfaces mismatch"
     )