Ejemplo n.º 1
0
    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_bindings(npb21.vlan, "dummyInstance")[0]
Ejemplo n.º 2
0
    def _delete_nxos_db(self, vlan_id, device_id, host_id, vni,
                        is_provider_vlan):
        """Delete the nexus database entry.

        Called during delete precommit port event.
        """
        try:
            rows = nxos_db.get_nexusvm_bindings(vlan_id, device_id)
            for row in rows:
                nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id,
                                    row.vni, row.switch_ip, row.instance_id,
                                    row.is_provider_vlan)
        except excep.NexusPortBindingNotFound:
            return
Ejemplo n.º 3
0
    def _delete_nxos_db(self, vlan_id, device_id, host_id, vni,
                        is_provider_vlan):
        """Delete the nexus database entry.

        Called during delete precommit port event.
        """
        try:
            rows = nxos_db.get_nexusvm_bindings(vlan_id, device_id)
            for row in rows:
                nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id,
                                    row.vni, row.switch_ip, row.instance_id,
                                    row.is_provider_vlan)
        except excep.NexusPortBindingNotFound:
            return
Ejemplo n.º 4
0
 def _get_nexusvm_binding(self, npb):
     """Gets port binding based on vlan and instance."""
     return nexus_db_v2.get_nexusvm_bindings(npb.vlan, npb.instance)[0]
Ejemplo n.º 5
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_top_bound_segment: previous value
          PortContext.current['binding:host_id']: current (new) value
          PortContext.top_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_top_bound_segment: None
          PortContext.current['binding:host_id']: previous value
          PortContext.top_bound_segment: new value
        """
        migrate_add_host2_driver_result = ([
            test_cisco_nexus_base.RESULT_ADD_VLAN.format(267),
            test_cisco_nexus_base.RESULT_ADD_INTERFACE.format(
                'ethernet', '1\/20', 267)
        ])

        self._basic_create_verify_port_vlan(
            'test_config1', self.duplicate_add_port_driver_result)
        binding = nexus_db_v2.get_nexusvm_bindings(
            test_cisco_nexus_base.VLAN_ID_1,
            test_cisco_nexus_base.INSTANCE_1)[0]
        self.assertEqual(test_cisco_nexus_base.NEXUS_PORT_1, binding.port_id)

        port_context = self._generate_port_context(
            self.test_configs['test_config_migrate'], unbind_port=True)
        port_cfg = self.test_configs['test_config1']
        port_context.set_orig_port(port_cfg.instance_id, port_cfg.host_name,
                                   port_cfg.device_owner, port_cfg.profile,
                                   port_cfg.vnic_type,
                                   test_cisco_nexus_base.NETID)

        self._cisco_mech_driver.create_port_postcommit(port_context)
        self._cisco_mech_driver.update_port_precommit(port_context)
        self._cisco_mech_driver.update_port_postcommit(port_context)

        # Verify that port entry has been deleted.
        self.assertRaises(exceptions.NexusPortBindingNotFound,
                          nexus_db_v2.get_nexusvm_bindings,
                          test_cisco_nexus_base.VLAN_ID_1,
                          test_cisco_nexus_base.INSTANCE_1)

        # Clean all the ncclient mock_calls to clear exception
        # and other mock_call history.
        self.mock_ncclient.reset_mock()

        self._basic_create_verify_port_vlan('test_config_migrate',
                                            migrate_add_host2_driver_result)

        # 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_bindings(
            test_cisco_nexus_base.VLAN_ID_1,
            test_cisco_nexus_base.INSTANCE_1)[0]
        self.assertEqual(test_cisco_nexus_base.NEXUS_PORT_2, binding.port_id)
    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_top_bound_segment: previous value
          PortContext.current['binding:host_id']: current (new) value
          PortContext.top_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_top_bound_segment: None
          PortContext.current['binding:host_id']: previous value
          PortContext.top_bound_segment: new value
        """
        migrate_add_host2_driver_result = [
            test_cisco_nexus_base.RESULT_ADD_VLAN.format(267),
            test_cisco_nexus_base.RESULT_ADD_INTERFACE.format("ethernet", "1\/20", 267),
        ]

        self._basic_create_verify_port_vlan("test_config1", self.duplicate_add_port_driver_result)
        binding = nexus_db_v2.get_nexusvm_bindings(test_cisco_nexus_base.VLAN_ID_1, test_cisco_nexus_base.INSTANCE_1)[0]
        self.assertEqual(test_cisco_nexus_base.NEXUS_PORT_1, binding.port_id)

        port_context = self._generate_port_context(self.test_configs["test_config_migrate"], unbind_port=True)
        port_cfg = self.test_configs["test_config1"]
        port_context.set_orig_port(
            port_cfg.instance_id,
            port_cfg.host_name,
            port_cfg.device_owner,
            port_cfg.profile,
            port_cfg.vnic_type,
            test_cisco_nexus_base.NETID,
        )

        self._cisco_mech_driver.create_port_postcommit(port_context)
        self._cisco_mech_driver.update_port_precommit(port_context)
        self._cisco_mech_driver.update_port_postcommit(port_context)

        # Verify that port entry has been deleted.
        self.assertRaises(
            exceptions.NexusPortBindingNotFound,
            nexus_db_v2.get_nexusvm_bindings,
            test_cisco_nexus_base.VLAN_ID_1,
            test_cisco_nexus_base.INSTANCE_1,
        )

        # Clean all the ncclient mock_calls to clear exception
        # and other mock_call history.
        self.mock_ncclient.reset_mock()

        self._basic_create_verify_port_vlan("test_config_migrate", migrate_add_host2_driver_result)

        # 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_bindings(test_cisco_nexus_base.VLAN_ID_1, test_cisco_nexus_base.INSTANCE_1)[0]
        self.assertEqual(test_cisco_nexus_base.NEXUS_PORT_2, binding.port_id)