Example #1
0
    def test_nexusvlanbinding_get(self):
        """Test get of port bindings based on vlan and switch."""
        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_all_v100 = self._get_nexusvlan_binding(npb11)
        self.assertEqual(len(npb_all_v100), 2)
        npb_v200 = self._get_nexusvlan_binding(npb22)
        self.assertEqual(len(npb_v200), 1)
        self._assert_bindings_match(npb_v200[0], npb22)

        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.get_nexusvlan_binding(npb21.vlan, "dummySwitch")
    def _delete_switch_entry(self, vlan_id, device_id, host_id, vni,
                             is_provider_vlan):
        """Delete the nexus switch entry.

        By accessing the current db entries determine if switch
        configuration can be removed.

        Called during delete postcommit port event.
        """
        host_connections = self._get_switch_info(host_id)

        # (nexus_port,switch_ip) will be unique in each iteration.
        # But switch_ip will repeat if host has >1 connection to same switch.
        # So track which switch_ips already have vlan removed in this loop.
        vlan_already_removed = []
        for switch_ip, intf_type, nexus_port in host_connections:

            # if there are no remaining db entries using this vlan on this
            # nexus switch port then remove vlan from the switchport trunk.
            port_id = '%s:%s' % (intf_type, nexus_port)
            auto_create = True
            auto_trunk = True
            if is_provider_vlan:
                auto_create = cfg.CONF.ml2_cisco.provider_vlan_auto_create
                auto_trunk = cfg.CONF.ml2_cisco.provider_vlan_auto_trunk

            try:
                nxos_db.get_port_vlan_switch_binding(port_id, vlan_id,
                                                     switch_ip)
            except excep.NexusPortBindingNotFound:
                pass
            else:
                continue

            if auto_trunk:
                self.driver.disable_vlan_on_trunk_int(switch_ip, vlan_id,
                                                      intf_type, nexus_port)

            # if there are no remaining db entries using this vlan on this
            # nexus switch then remove the vlan.
            if auto_create:
                try:
                    nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
                except excep.NexusPortBindingNotFound:
                    # Do not perform a second time on same switch
                    if switch_ip not in vlan_already_removed:
                        self.driver.delete_vlan(switch_ip, vlan_id)
                        vlan_already_removed.append(switch_ip)
    def _delete_switch_entry(self, vlan_id, device_id, host_id, vni,
                             is_provider_vlan):
        """Delete the nexus switch entry.

        By accessing the current db entries determine if switch
        configuration can be removed.

        Called during delete postcommit port event.
        """
        host_connections = self._get_switch_info(host_id)

        # (nexus_port,switch_ip) will be unique in each iteration.
        # But switch_ip will repeat if host has >1 connection to same switch.
        # So track which switch_ips already have vlan removed in this loop.
        vlan_already_removed = []
        for switch_ip, intf_type, nexus_port in host_connections:

            # if there are no remaining db entries using this vlan on this
            # nexus switch port then remove vlan from the switchport trunk.
            port_id = '%s:%s' % (intf_type, nexus_port)
            auto_create = True
            auto_trunk = True
            if is_provider_vlan:
                auto_create = cfg.CONF.ml2_cisco.provider_vlan_auto_create
                auto_trunk = cfg.CONF.ml2_cisco.provider_vlan_auto_trunk

            try:
                nxos_db.get_port_vlan_switch_binding(port_id, vlan_id,
                                                     switch_ip)
            except excep.NexusPortBindingNotFound:
                pass
            else:
                continue

            if auto_trunk:
                self.driver.disable_vlan_on_trunk_int(
                    switch_ip, vlan_id, intf_type, nexus_port)

            # if there are no remaining db entries using this vlan on this
            # nexus switch then remove the vlan.
            if auto_create:
                try:
                    nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
                except excep.NexusPortBindingNotFound:
                    # Do not perform a second time on same switch
                    if switch_ip not in vlan_already_removed:
                        self.driver.delete_vlan(switch_ip, vlan_id)
                        vlan_already_removed.append(switch_ip)
Example #4
0
    def test_create_delete_duplicate_ports(self):
        """Tests creation and deletion of two new virtual Ports."""

        self._basic_create_verify_port_vlan(
            'test_config1', self.duplicate_add_port_driver_result)

        self._create_port(self.test_configs['test_config3'])
        # TODO(caboucha)
        # Commented out until the correct fix for
        # the following issue is resolved.
        # https://review.openstack.org/#/c/241216/
        #
        # verify first config was indeed configured
        # Original code was as follows:
        # self._verify_results(duplicate_add_port_driver_result)

        # Verify there are 2 port configs
        bindings = nexus_db_v2.get_nexusvlan_binding(
            test_cisco_nexus_base.VLAN_ID_1,
            test_cisco_nexus_base.NEXUS_IP_ADDRESS_1)
        self.assertEqual(2, len(bindings))

        # Clean all the ncclient mock_calls so we can evaluate
        # results of delete operations.
        self.mock_ncclient.reset_mock()

        # For results, pass empty list to verify no nexus action on
        # first port removal.
        self._basic_delete_verify_port_vlan('test_config1', [],
                                            nbr_of_bindings=1)

        self._basic_delete_verify_port_vlan(
            'test_config3', self.duplicate_delete_port_driver_result)
Example #5
0
    def test_nexus_vxlan_one_network_two_hosts(self):
        """Tests creation and deletion of two new virtual Ports."""

        self._basic_create_verify_port_vlan(
            'test_vxlan_config1',
            self.results.get_test_results('add_port_driver_result'))

        self._create_port(self.test_configs['test_vxlan_config2'])
        self._verify_results(
            self.results.get_test_results('add_port2_driver_result'))

        bindings = nexus_db_v2.get_nexusvlan_binding(
            test_cisco_nexus_base.VLAN_ID_1,
            test_cisco_nexus_base.NEXUS_IP_ADDRESS_1)
        self.assertEqual(2, len(bindings))

        # Clean all the ncclient mock_calls so we can evaluate
        # results of delete operations.
        self.mock_ncclient.reset_mock()

        self._basic_delete_verify_port_vlan(
            'test_vxlan_config2',
            self.results.get_test_results('delete_port2_driver_result'),
            nbr_of_bindings=1)

        self._basic_delete_verify_port_vlan(
            'test_vxlan_config1',
            self.results.get_test_results('delete_port_driver_result'))
    def test_create_delete_duplicate_ports(self):
        """Tests creation and deletion of two new virtual Ports."""

        self._basic_create_verify_port_vlan("test_config1", self.duplicate_add_port_driver_result)

        self._create_port(self.test_configs["test_config3"])
        # TODO(caboucha)
        # Commented out until the correct fix for
        # the following issue is resolved.
        # https://review.openstack.org/#/c/241216/
        #
        # verify first config was indeed configured
        # Original code was as follows:
        # self._verify_results(duplicate_add_port_driver_result)

        # Verify there are 2 port configs
        bindings = nexus_db_v2.get_nexusvlan_binding(
            test_cisco_nexus_base.VLAN_ID_1, test_cisco_nexus_base.NEXUS_IP_ADDRESS_1
        )
        self.assertEqual(2, len(bindings))

        # Clean all the ncclient mock_calls so we can evaluate
        # results of delete operations.
        self.mock_ncclient.reset_mock()

        # For results, pass empty list to verify no nexus action on
        # first port removal.
        self._basic_delete_verify_port_vlan("test_config1", [], nbr_of_bindings=1)

        self._basic_delete_verify_port_vlan("test_config3", self.duplicate_delete_port_driver_result)
    def test_nexus_vxlan_one_network_two_hosts(self):
        """Tests creation and deletion of two new virtual Ports."""

        add_port2_driver_result = ([
            test_cisco_nexus_base.RESULT_ADD_VLAN_VNI.format(267, 70000),
            test_cisco_nexus_base.RESULT_ADD_INTERFACE.format(
                'ethernet', '1\/20', 267)
        ])

        delete_port2_driver_result = ([
            test_cisco_nexus_base.RESULT_DEL_INTERFACE.format(
                'ethernet', '1\/20', 267)
        ])

        self._basic_create_verify_port_vlan('test_vxlan_config1',
                                            self.add_port_driver_result)

        self._create_port(self.test_configs['test_vxlan_config2'])
        self._verify_results(add_port2_driver_result)

        bindings = nexus_db_v2.get_nexusvlan_binding(
            test_cisco_nexus_base.VLAN_ID_1,
            test_cisco_nexus_base.NEXUS_IP_ADDRESS_1)
        self.assertEqual(2, len(bindings))

        # Clean all the ncclient mock_calls so we can evaluate
        # results of delete operations.
        self.mock_ncclient.reset_mock()

        self._basic_delete_verify_port_vlan('test_vxlan_config2',
                                            delete_port2_driver_result,
                                            nbr_of_bindings=1)

        self._basic_delete_verify_port_vlan('test_vxlan_config1',
                                            self.delete_port_driver_result)
Example #8
0
    def test_nexus_vxlan_one_network(self):
        """Test processing for creating one VXLAN segment."""

        # Since test_vxlan_config3 & test_vxlan_config4 share
        # the same host name they both get processed in the
        # next call.
        self._basic_create_verify_port_vlan(
            'test_vxlan_config3',
            self.results.get_test_results(
                'add_port_driver_result3'))

        for switch_ip, nbr_bind in [
            (test_cisco_nexus_base.NEXUS_IP_ADDRESS_1, 1),
            (test_cisco_nexus_base.NEXUS_IP_ADDRESS_2, 2)]:
            bindings = nexus_db_v2.get_nexusvlan_binding(
                           test_cisco_nexus_base.VLAN_ID_1,
                           switch_ip)
            self.assertEqual(nbr_bind, len(bindings))
            binding = nexus_db_v2.get_nve_switch_bindings(switch_ip)
            self.assertEqual(1, len(binding))

        # Since test_vxlan_config3 & test_vxlan_config4 share
        # the same host name they both get processed in the
        # next call.
        self._basic_delete_verify_port_vlan(
            'test_vxlan_config3',
            self.results.get_test_results(
                'delete_port_driver_result3'))

        for switch_ip in [
            test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
            test_cisco_nexus_base.NEXUS_IP_ADDRESS_2]:
            try:
                bindings = nexus_db_v2.get_nexusvlan_binding(
                               test_cisco_nexus_base.VLAN_ID_1,
                               switch_ip)
            except exceptions.NexusPortBindingNotFound:
                bindings = []
            self.assertEqual(0, len(bindings))
            try:
                binding = nexus_db_v2.get_nve_switch_bindings(switch_ip)
            except exceptions.NexusPortBindingNotFound:
                binding = []
            self.assertEqual(0, len(binding))
    def _configure_host_entries(self, vlan_id, device_id, host_id, vni,
                                is_provider_vlan):
        """Create a nexus switch entry.

        if needed, create a VLAN in the appropriate switch or port and
        configure the appropriate interfaces for this VLAN.

        Called during update postcommit port event.
        """
        host_connections = self._get_switch_info(host_id)

        # (nexus_port,switch_ip) will be unique in each iteration.
        # But switch_ip will repeat if host has >1 connection to same switch.
        # So track which switch_ips already have vlan created in this loop.
        vlan_already_created = []
        for switch_ip, intf_type, nexus_port in host_connections:

            if self.is_switch_configurable(switch_ip) is False:
                self.reset_switch_retry_count(switch_ip)
                continue

            # The VLAN needs to be created on the switch if no other
            # instance has been placed in this VLAN on a different host
            # attached to this switch.  Search the existing bindings in the
            # database.  If all the instance_id in the database match the
            # current device_id, then create the VLAN, but only once per
            # switch_ip.  Otherwise, just trunk.
            all_bindings = nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
            previous_bindings = [row for row in all_bindings
                    if row.instance_id != device_id]
            duplicate_port = [row for row in all_bindings
                    if row.instance_id != device_id and
                    row.port_id == intf_type + ':' + nexus_port]
            if duplicate_port:
                duplicate_type = const.DUPLICATE_PORT
            elif previous_bindings or (switch_ip in vlan_already_created):
                duplicate_type = const.DUPLICATE_VLAN
            else:
                vlan_already_created.append(switch_ip)
                duplicate_type = const.NO_DUPLICATE
            try:
                self._configure_port_binding(is_provider_vlan,
                                duplicate_type,
                                switch_ip, vlan_id,
                                intf_type, nexus_port,
                                vni)
            except Exception:
                with excutils.save_and_reraise_exception() as ctxt:
                    ctxt.reraise = (
                        self.choose_to_reraise_driver_exception(switch_ip,
                            '_configure_port_binding'))
    def _configure_host_entries(self, vlan_id, device_id, host_id, vni,
                                is_provider_vlan):
        """Create a nexus switch entry.

        if needed, create a VLAN in the appropriate switch or port and
        configure the appropriate interfaces for this VLAN.

        Called during update postcommit port event.
        """
        host_connections = self._get_switch_info(host_id)

        # (nexus_port,switch_ip) will be unique in each iteration.
        # But switch_ip will repeat if host has >1 connection to same switch.
        # So track which switch_ips already have vlan created in this loop.
        vlan_already_created = []
        for switch_ip, intf_type, nexus_port in host_connections:

            if self.is_switch_configurable(switch_ip) is False:
                self.reset_switch_retry_count(switch_ip)
                continue

            # The VLAN needs to be created on the switch if no other
            # instance has been placed in this VLAN on a different host
            # attached to this switch.  Search the existing bindings in the
            # database.  If all the instance_id in the database match the
            # current device_id, then create the VLAN, but only once per
            # switch_ip.  Otherwise, just trunk.
            all_bindings = nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
            previous_bindings = [
                row for row in all_bindings if row.instance_id != device_id
            ]
            duplicate_port = [
                row for row in all_bindings
                if row.instance_id != device_id and row.port_id == intf_type +
                ':' + nexus_port
            ]
            if duplicate_port:
                duplicate_type = const.DUPLICATE_PORT
            elif previous_bindings or (switch_ip in vlan_already_created):
                duplicate_type = const.DUPLICATE_VLAN
            else:
                vlan_already_created.append(switch_ip)
                duplicate_type = const.NO_DUPLICATE
            try:
                self._configure_port_binding(is_provider_vlan, duplicate_type,
                                             switch_ip, vlan_id, intf_type,
                                             nexus_port, vni)
            except Exception:
                with excutils.save_and_reraise_exception() as ctxt:
                    ctxt.reraise = (self.choose_to_reraise_driver_exception(
                        switch_ip, '_configure_port_binding'))
Example #11
0
    def test_nexusbinding_update(self):
        """Tests update of vlan IDs for port bindings."""
        npb11 = self._npb_test_obj(10, 100, switch='1.1.1.1', instance='test')
        npb21 = self._npb_test_obj(20, 100, switch='1.1.1.1', instance='test')
        self._add_bindings_to_db([npb11, npb21])

        npb_all_v100 = nexus_db_v2.get_nexusvlan_binding(100, '1.1.1.1')
        self.assertEqual(len(npb_all_v100), 2)

        npb22 = self._npb_test_obj(20, 200, switch='1.1.1.1', instance='test')
        npb = nexus_db_v2.update_nexusport_binding(npb21.port, 200)
        self._assert_bindings_match(npb, npb22)

        npb_all_v100 = nexus_db_v2.get_nexusvlan_binding(100, '1.1.1.1')
        self.assertEqual(len(npb_all_v100), 1)
        self._assert_bindings_match(npb_all_v100[0], npb11)

        npb = nexus_db_v2.update_nexusport_binding(npb21.port, 0)
        self.assertIsNone(npb)

        npb33 = self._npb_test_obj(30, 300, switch='1.1.1.1', instance='test')
        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.update_nexusport_binding(npb33.port, 200)
    def test_create_delete_duplicate_ports(self):
        """Tests creation and deletion of two new virtual Ports."""
        duplicate_add_port_driver_result = [
            '\<vlan\-name\>q\-267\<\/vlan\-name>',
            '\<vstate\>active\<\/vstate>',
            '\<no\>\s+\<shutdown\/\>\s+\<\/no\>',
            '\<interface\>1\/10\<\/interface\>\s+'
            '[\x20-\x7e]+\s+\<switchport\>\s+\<trunk\>\s+'
            '\<allowed\>\s+\<vlan\>\s+\<vlan_id\>267',
        ]
        duplicate_delete_port_driver_result = [
            '\<interface\>1\/10\<\/interface\>\s+'
            '[\x20-\x7e\s]+\<switchport\>\s+\<trunk\>\s+'
            '\<allowed\>\s+\<vlan\>\s+\<remove\>\s+\<vlan\>267',
            '\<no\>\s+\<vlan\>\s+<vlan-id-create-delete\>'
            '\s+\<__XML__PARAM_value\>267',
        ]

        self._create_port(
            TestCiscoNexusDevice.test_configs['test_config1'])
        # verify first config was indeed configured
        self._verify_results(duplicate_add_port_driver_result)

        self._create_port(
            TestCiscoNexusDevice.test_configs['test_config3'])
        # verify only the first config was applied
        self._verify_results(duplicate_add_port_driver_result)

        # Verify there are 2 port configs
        bindings = nexus_db_v2.get_nexusvlan_binding(VLAN_ID_1,
                                                     NEXUS_IP_ADDRESS)
        self.assertEqual(len(bindings), 2)

        # Clean all the ncclient mock_calls so we can evaluate
        # results of delete operations.
        self.mock_ncclient.reset_mock()

        self._delete_port(
            TestCiscoNexusDevice.test_configs['test_config1'])
        # Using empty list verify no nexus action on first port removal
        self._verify_results([])

        self._delete_port(
            TestCiscoNexusDevice.test_configs['test_config3'])
        # verify port removed on 2nd port delete
        self._verify_results(duplicate_delete_port_driver_result)
Example #13
0
    def test_create_delete_duplicate_ports(self):
        """Tests creation and deletion of two new virtual Ports."""
        duplicate_add_port_driver_result = [
            '\<vlan\-name\>q\-267\<\/vlan\-name>',
            '\<vstate\>active\<\/vstate>',
            '\<no\>\s+\<shutdown\/\>\s+\<\/no\>',
            '\<interface\>1\/10\<\/interface\>\s+'
            '[\x20-\x7e]+\s+\<switchport\>\s+\<trunk\>\s+'
            '\<allowed\>\s+\<vlan\>\s+\<vlan_id\>267',
        ]
        duplicate_delete_port_driver_result = [
            '\<interface\>1\/10\<\/interface\>\s+'
            '[\x20-\x7e\s]+\<switchport\>\s+\<trunk\>\s+'
            '\<allowed\>\s+\<vlan\>\s+\<remove\>\s+\<vlan\>267',
            '\<no\>\s+\<vlan\>\s+<vlan-id-create-delete\>'
            '\s+\<__XML__PARAM_value\>267',
        ]

        self._create_port(TestCiscoNexusDevice.test_configs['test_config1'])
        # verify first config was indeed configured
        self._verify_results(duplicate_add_port_driver_result)

        self._create_port(TestCiscoNexusDevice.test_configs['test_config3'])
        # verify only the first config was applied
        self._verify_results(duplicate_add_port_driver_result)

        # Verify there are 2 port configs
        bindings = nexus_db_v2.get_nexusvlan_binding(VLAN_ID_1,
                                                     NEXUS_IP_ADDRESS)
        self.assertEqual(len(bindings), 2)

        # Clean all the ncclient mock_calls so we can evaluate
        # results of delete operations.
        self.mock_ncclient.reset_mock()

        self._delete_port(TestCiscoNexusDevice.test_configs['test_config1'])
        # Using empty list verify no nexus action on first port removal
        self._verify_results([])

        self._delete_port(TestCiscoNexusDevice.test_configs['test_config3'])
        # verify port removed on 2nd port delete
        self._verify_results(duplicate_delete_port_driver_result)
    def test_nexus_vxlan_one_network_two_hosts(self):
        """Tests creation and deletion of two new virtual Ports."""

        add_port2_driver_result = (
            [test_cisco_nexus_base.RESULT_ADD_VLAN_VNI.
                format(267, 70000),
            test_cisco_nexus_base.RESULT_ADD_INTERFACE.
                format('ethernet', '1\/20', 267)])

        delete_port2_driver_result = (
            [test_cisco_nexus_base.RESULT_DEL_INTERFACE.
                format('ethernet', '1\/20', 267)])

        self._basic_create_verify_port_vlan(
            'test_vxlan_config1',
            self.add_port_driver_result)

        self._create_port(
            self.test_configs['test_vxlan_config2'])
        self._verify_results(add_port2_driver_result)

        bindings = nexus_db_v2.get_nexusvlan_binding(
                       test_cisco_nexus_base.VLAN_ID_1,
                       test_cisco_nexus_base.NEXUS_IP_ADDRESS_1)
        self.assertEqual(2, len(bindings))

        # Clean all the ncclient mock_calls so we can evaluate
        # results of delete operations.
        self.mock_ncclient.reset_mock()

        self._basic_delete_verify_port_vlan(
            'test_vxlan_config2',
            delete_port2_driver_result, nbr_of_bindings=1)

        self._basic_delete_verify_port_vlan(
            'test_vxlan_config1',
            self.delete_port_driver_result)
    def test_nexus_vxlan_one_network(self):
        """Test processing for creating one VXLAN segment."""

        add_port_driver_result3 = ([
            test_cisco_nexus_base.RESULT_ADD_NVE_INTERFACE.format(
                1, 70000, '255.1.1.1'),
            test_cisco_nexus_base.RESULT_ADD_NVE_INTERFACE.format(
                1, 70000, '255.1.1.1'),
            test_cisco_nexus_base.RESULT_ADD_VLAN_VNI.format(267, 70000),
            test_cisco_nexus_base.RESULT_ADD_INTERFACE.format(
                'ethernet', '1\/10', 267),
            test_cisco_nexus_base.RESULT_ADD_VLAN_VNI.format(267, 70000),
            test_cisco_nexus_base.RESULT_ADD_INTERFACE.format(
                'ethernet', '1\/2', 267),
            test_cisco_nexus_base.RESULT_ADD_VLAN_VNI.format(267, 70000),
            test_cisco_nexus_base.RESULT_ADD_INTERFACE.format(
                'ethernet', '1\/3', 267)
        ])

        delete_port_driver_result3 = ([
            test_cisco_nexus_base.RESULT_DEL_NVE_INTERFACE.format(
                1, 70000, 267),
            test_cisco_nexus_base.RESULT_DEL_NVE_INTERFACE.format(
                1, 70000, 267),
            test_cisco_nexus_base.RESULT_DEL_INTERFACE.format(
                'ethernet', '1\/10', 267),
            test_cisco_nexus_base.RESULT_DEL_VLAN.format(267),
            test_cisco_nexus_base.RESULT_DEL_INTERFACE.format(
                'ethernet', '1\/2', 267),
            test_cisco_nexus_base.RESULT_DEL_VLAN.format(267),
            test_cisco_nexus_base.RESULT_DEL_INTERFACE.format(
                'ethernet', '1\/3', 267)
        ])

        # Since test_vxlan_config3 & test_vxlan_config4 share
        # the same host name they both get processed in the
        # next call.
        self._basic_create_verify_port_vlan('test_vxlan_config3',
                                            add_port_driver_result3)

        for switch_ip, nbr_bind in [
            (test_cisco_nexus_base.NEXUS_IP_ADDRESS_1, 1),
            (test_cisco_nexus_base.NEXUS_IP_ADDRESS_2, 2)
        ]:
            bindings = nexus_db_v2.get_nexusvlan_binding(
                test_cisco_nexus_base.VLAN_ID_1, switch_ip)
            self.assertEqual(nbr_bind, len(bindings))
            binding = nexus_db_v2.get_nve_switch_bindings(switch_ip)
            self.assertEqual(1, len(binding))

        # Since test_vxlan_config3 & test_vxlan_config4 share
        # the same host name they both get processed in the
        # next call.
        self._basic_delete_verify_port_vlan('test_vxlan_config3',
                                            delete_port_driver_result3)

        for switch_ip in [
                test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
                test_cisco_nexus_base.NEXUS_IP_ADDRESS_2
        ]:
            try:
                bindings = nexus_db_v2.get_nexusvlan_binding(
                    test_cisco_nexus_base.VLAN_ID_1, switch_ip)
            except exceptions.NexusPortBindingNotFound:
                bindings = []
            self.assertEqual(0, len(bindings))
            try:
                binding = nexus_db_v2.get_nve_switch_bindings(switch_ip)
            except exceptions.NexusPortBindingNotFound:
                binding = []
            self.assertEqual(0, len(binding))
Example #16
0
 def _get_nexusvlan_binding(self, npb):
     """Gets port bindings based on vlan and switch."""
     return nexus_db_v2.get_nexusvlan_binding(npb.vlan, npb.switch)
    def test_nexus_vxlan_one_network(self):
        """Test processing for creating one VXLAN segment."""

        add_port_driver_result3 = (
            [test_cisco_nexus_base.RESULT_ADD_NVE_INTERFACE.
                format(1, 70000, '255.1.1.1'),
            test_cisco_nexus_base.RESULT_ADD_NVE_INTERFACE.
                format(1, 70000, '255.1.1.1'),
            test_cisco_nexus_base.RESULT_ADD_VLAN_VNI.
                format(267, 70000),
            test_cisco_nexus_base.RESULT_ADD_INTERFACE.
                format('ethernet', '1\/10', 267),
            test_cisco_nexus_base.RESULT_ADD_VLAN_VNI.
                format(267, 70000),
            test_cisco_nexus_base.RESULT_ADD_INTERFACE.
                format('ethernet', '1\/2', 267),
            test_cisco_nexus_base.RESULT_ADD_VLAN_VNI.
                format(267, 70000),
            test_cisco_nexus_base.RESULT_ADD_INTERFACE.
                format('ethernet', '1\/3', 267)])

        delete_port_driver_result3 = (
            [test_cisco_nexus_base.RESULT_DEL_NVE_INTERFACE.
                format(1, 70000, 267),
             test_cisco_nexus_base.RESULT_DEL_NVE_INTERFACE.
                format(1, 70000, 267),
            test_cisco_nexus_base.RESULT_DEL_INTERFACE.
                format('ethernet', '1\/10', 267),
            test_cisco_nexus_base.RESULT_DEL_VLAN.format(267),
            test_cisco_nexus_base.RESULT_DEL_INTERFACE.
                format('ethernet', '1\/2', 267),
            test_cisco_nexus_base.RESULT_DEL_VLAN.format(267),
            test_cisco_nexus_base.RESULT_DEL_INTERFACE.
                format('ethernet', '1\/3', 267)])

        # Since test_vxlan_config3 & test_vxlan_config4 share
        # the same host name they both get processed in the
        # next call.
        self._basic_create_verify_port_vlan(
            'test_vxlan_config3',
            add_port_driver_result3)

        for switch_ip, nbr_bind in [
            (test_cisco_nexus_base.NEXUS_IP_ADDRESS_1, 1),
            (test_cisco_nexus_base.NEXUS_IP_ADDRESS_2, 2)]:
            bindings = nexus_db_v2.get_nexusvlan_binding(
                           test_cisco_nexus_base.VLAN_ID_1,
                           switch_ip)
            self.assertEqual(nbr_bind, len(bindings))
            binding = nexus_db_v2.get_nve_switch_bindings(switch_ip)
            self.assertEqual(1, len(binding))

        # Since test_vxlan_config3 & test_vxlan_config4 share
        # the same host name they both get processed in the
        # next call.
        self._basic_delete_verify_port_vlan(
            'test_vxlan_config3',
            delete_port_driver_result3)

        for switch_ip in [
            test_cisco_nexus_base.NEXUS_IP_ADDRESS_1,
            test_cisco_nexus_base.NEXUS_IP_ADDRESS_2]:
            try:
                bindings = nexus_db_v2.get_nexusvlan_binding(
                               test_cisco_nexus_base.VLAN_ID_1,
                               switch_ip)
            except exceptions.NexusPortBindingNotFound:
                bindings = []
            self.assertEqual(0, len(bindings))
            try:
                binding = nexus_db_v2.get_nve_switch_bindings(switch_ip)
            except exceptions.NexusPortBindingNotFound:
                binding = []
            self.assertEqual(0, len(binding))