def _create_delete_port(self, port_config):
        """Tests creation and deletion of a virtual port."""
        nexus_ip_addr = port_config.nexus_ip_addr
        host_name = port_config.host_name
        nexus_port = port_config.nexus_port
        instance_id = port_config.instance_id
        vlan_id = port_config.vlan_id

        network_context = FakeNetworkContext(vlan_id)
        port_context = FakePortContext(instance_id, host_name,
                                       network_context)

        self._cisco_mech_driver.update_port_precommit(port_context)
        self._cisco_mech_driver.update_port_postcommit(port_context)
        bindings = nexus_db_v2.get_nexusport_binding(nexus_port,
                                                     vlan_id,
                                                     nexus_ip_addr,
                                                     instance_id)
        self.assertEqual(len(bindings), 1)

        self._cisco_mech_driver.delete_port_precommit(port_context)
        self._cisco_mech_driver.delete_port_postcommit(port_context)
        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.get_nexusport_binding(nexus_port,
                                              vlan_id,
                                              nexus_ip_addr,
                                              instance_id)
Exemple #2
0
    def _create_delete_port(self, port_config):
        """Tests creation and deletion of a virtual port."""
        nexus_ip_addr = port_config.nexus_ip_addr
        host_name = port_config.host_name
        nexus_port = port_config.nexus_port
        instance_id = port_config.instance_id
        vlan_id = port_config.vlan_id

        network_context = FakeNetworkContext(vlan_id)
        port_context = FakePortContext(instance_id, host_name, network_context)

        self._cisco_mech_driver.update_port_precommit(port_context)
        self._cisco_mech_driver.update_port_postcommit(port_context)
        for port_id in nexus_port.split(','):
            bindings = nexus_db_v2.get_nexusport_binding(
                port_id, vlan_id, nexus_ip_addr, instance_id)
            self.assertEqual(len(bindings), 1)

        self._cisco_mech_driver.delete_port_precommit(port_context)
        self._cisco_mech_driver.delete_port_postcommit(port_context)
        for port_id in nexus_port.split(','):
            with testtools.ExpectedException(
                    exceptions.NexusPortBindingNotFound):
                nexus_db_v2.get_nexusport_binding(port_id, vlan_id,
                                                  nexus_ip_addr, instance_id)
    def test_nexusportbinding_get(self):
        """Tests get of specific port bindings from the database."""
        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_nexusport_binding(npb11)
        self.assertEqual(len(npb), 1)
        self._assert_bindings_match(npb[0], npb11)
        npb = self._get_nexusport_binding(npb21)
        self.assertEqual(len(npb), 1)
        self._assert_bindings_match(npb[0], npb21)
        npb = self._get_nexusport_binding(npb22)
        self.assertEqual(len(npb), 1)
        self._assert_bindings_match(npb[0], npb22)

        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.get_nexusport_binding(npb21.port, npb21.vlan,
                                              npb21.switch, "dummyInstance")
    def test_nexusportbinding_get(self):
        """Tests get of specific port bindings from the database."""
        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_nexusport_binding(npb11)
        self.assertEqual(len(npb), 1)
        self._assert_bindings_match(npb[0], npb11)
        npb = self._get_nexusport_binding(npb21)
        self.assertEqual(len(npb), 1)
        self._assert_bindings_match(npb[0], npb21)
        npb = self._get_nexusport_binding(npb22)
        self.assertEqual(len(npb), 1)
        self._assert_bindings_match(npb[0], npb22)

        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.get_nexusport_binding(
                npb21.port, npb21.vlan, npb21.switch, "dummyInstance")
 def _get_nexusport_binding(self, npb):
     """Gets a port binding based on port, vlan, switch, and instance."""
     return nexus_db_v2.get_nexusport_binding(npb.port, npb.vlan,
                                              npb.switch, npb.instance)
 def _get_nexusport_binding(self, npb):
     """Gets a port binding based on port, vlan, switch, and instance."""
     return nexus_db_v2.get_nexusport_binding(
         npb.port, npb.vlan, npb.switch, npb.instance)