Esempio n. 1
0
    def test_nexus_vm_migration(self):
        """Verify VM (live) migration.

        Simulate the following:
        Nova informs neutron of live-migration with port-update(new host).
        This should trigger two update_port_pre/postcommit() calls.

        The first one should only change the current host_id and remove the
        binding resulting in the mechanism drivers receiving:
          PortContext.original['binding:host_id']: previous value
          PortContext.original_bound_segment: previous value
          PortContext.current['binding:host_id']: current (new) value
          PortContext.bound_segment: None

        The second one binds the new host resulting in the mechanism
        drivers receiving:
          PortContext.original['binding:host_id']: previous value
          PortContext.original_bound_segment: None
          PortContext.current['binding:host_id']: previous value
          PortContext.bound_segment: new value
        """

        # Create network, subnet and port.
        with self._create_resources() as result:
            # Verify initial database entry.
            # Use port_id to verify that 1st host name was used.
            binding = nexus_db_v2.get_nexusvm_binding(VLAN_START, DEVICE_ID_1)
            self.assertEqual(binding.port_id, NEXUS_INTERFACE)

            port = self.deserialize(self.fmt, result)
            port_id = port['port']['id']

            # Trigger update event to unbind segment.
            # Results in port being deleted from nexus DB and switch.
            data = {'port': {portbindings.HOST_ID: COMP_HOST_NAME_2}}
            self.mock_bound_segment.return_value = None
            self.mock_original_bound_segment.return_value = BOUND_SEGMENT1
            self.new_update_request('ports', data,
                                    port_id).get_response(self.api)

            # Verify that port entry has been deleted.
            self.assertRaises(c_exc.NexusPortBindingNotFound,
                              nexus_db_v2.get_nexusvm_binding,
                              VLAN_START, DEVICE_ID_1)

            # Trigger update event to bind segment with new host.
            self.mock_bound_segment.return_value = BOUND_SEGMENT1
            self.mock_original_bound_segment.return_value = None
            self.new_update_request('ports', data,
                                    port_id).get_response(self.api)

            # Verify that port entry has been added using new host name.
            # Use port_id to verify that 2nd host name was used.
            binding = nexus_db_v2.get_nexusvm_binding(VLAN_START, DEVICE_ID_1)
            self.assertEqual(binding.port_id, NEXUS_INTERFACE_2)
    def test_nexus_vm_migration(self):
        """Verify VM (live) migration.

        Simulate the following:
        Nova informs neutron of live-migration with port-update(new host).
        This should trigger two update_port_pre/postcommit() calls.

        The first one should only change the current host_id and remove the
        binding resulting in the mechanism drivers receiving:
          PortContext.original['binding:host_id']: previous value
          PortContext.original_bound_segment: previous value
          PortContext.current['binding:host_id']: current (new) value
          PortContext.bound_segment: None

        The second one binds the new host resulting in the mechanism
        drivers receiving:
          PortContext.original['binding:host_id']: previous value
          PortContext.original_bound_segment: None
          PortContext.current['binding:host_id']: previous value
          PortContext.bound_segment: new value
        """

        # Create network, subnet and port.
        with self._create_resources() as result:
            # Verify initial database entry.
            # Use port_id to verify that 1st host name was used.
            binding = nexus_db_v2.get_nexusvm_binding(VLAN_START, DEVICE_ID_1)
            self.assertEqual(binding.port_id, NEXUS_INTERFACE)

            port = self.deserialize(self.fmt, result)
            port_id = port['port']['id']

            # Trigger update event to unbind segment.
            # Results in port being deleted from nexus DB and switch.
            data = {'port': {portbindings.HOST_ID: COMP_HOST_NAME_2}}
            self.mock_bound_segment.return_value = None
            self.mock_original_bound_segment.return_value = BOUND_SEGMENT1
            self.new_update_request('ports', data,
                                    port_id).get_response(self.api)

            # Verify that port entry has been deleted.
            self.assertRaises(c_exc.NexusPortBindingNotFound,
                              nexus_db_v2.get_nexusvm_binding, VLAN_START,
                              DEVICE_ID_1)

            # Trigger update event to bind segment with new host.
            self.mock_bound_segment.return_value = BOUND_SEGMENT1
            self.mock_original_bound_segment.return_value = None
            self.new_update_request('ports', data,
                                    port_id).get_response(self.api)

            # Verify that port entry has been added using new host name.
            # Use port_id to verify that 2nd host name was used.
            binding = nexus_db_v2.get_nexusvm_binding(VLAN_START, DEVICE_ID_1)
            self.assertEqual(binding.port_id, NEXUS_INTERFACE_2)
    def test_nexusvmbinding_get(self):
        """Test get of port bindings based on vlan and instance."""
        npb11 = self._npb_test_obj(10, 100)
        npb21 = self._npb_test_obj(20, 100)
        npb22 = self._npb_test_obj(20, 200)
        self._add_bindings_to_db([npb11, npb21, npb22])

        npb = self._get_nexusvm_binding(npb21)
        self._assert_bindings_match(npb, npb21)
        npb = self._get_nexusvm_binding(npb22)
        self._assert_bindings_match(npb, npb22)

        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.get_nexusvm_binding(npb21.vlan, "dummyInstance")
    def test_nexusvmbinding_get(self):
        """Test get of port bindings based on vlan and instance."""
        npb11 = self._npb_test_obj(10, 100)
        npb21 = self._npb_test_obj(20, 100)
        npb22 = self._npb_test_obj(20, 200)
        self._add_bindings_to_db([npb11, npb21, npb22])

        npb = self._get_nexusvm_binding(npb21)
        self._assert_bindings_match(npb, npb21)
        npb = self._get_nexusvm_binding(npb22)
        self._assert_bindings_match(npb, npb22)

        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.get_nexusvm_binding(npb21.vlan, "dummyInstance")
Esempio n. 5
0
    def _delete_nxos_db(self, vlan_id, device_id, host_id):
        """Delete the nexus database entry.

        Called during delete precommit port event.
        """
        try:
            row = nxos_db.get_nexusvm_binding(vlan_id, device_id)
            nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id,
                                             row.switch_ip, row.instance_id)
        except excep.NexusPortBindingNotFound:
            return
    def _delete_nxos_db(self, vlan_id, device_id, host_id):
        """Delete the nexus database entry.

        Called during delete precommit port event.
        """
        try:
            row = nxos_db.get_nexusvm_binding(vlan_id, device_id)
            nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id,
                                             row.switch_ip, row.instance_id)
        except excep.NexusPortBindingNotFound:
            return
 def _get_nexusvm_binding(self, npb):
     """Gets port bindings based on vlan and instance."""
     return nexus_db_v2.get_nexusvm_binding(npb.vlan, npb.instance)
 def _get_nexusvm_binding(self, npb):
     """Gets port bindings based on vlan and instance."""
     return nexus_db_v2.get_nexusvm_binding(npb.vlan, npb.instance)