def _create_port(self, port_config, override_netid=None):
        """Tests creation of a virtual port."""

        port_context = self._generate_port_context(
            port_config, override_netid=override_netid)

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

        if nexus_help.is_baremetal(port_context.current):
            connections = self._cisco_mech_driver._get_port_connections(
                port_context.current, '')
        else:
            connections = self._cisco_mech_driver._get_port_connections(
                port_context.current, port_config.host_name)

        # for port_id in port_config.nexus_port.split(','):
        for switch_ip, intf_type, port, is_p_vlan, _ in connections:
            if switch_ip is not port_config.nexus_ip_addr:
                continue
            port_id = intf_type + ':' + port
            bindings = nexus_db_v2.get_nexusport_binding(
                port_id, port_config.vlan_id, port_config.nexus_ip_addr,
                port_config.instance_id)
            self.assertEqual(1, len(bindings))
Exemplo n.º 2
0
    def subport_postcommit(self, resource, event, trunk_plugin, payload):
        trunkport = self.plugin.get_port(payload.context,
                                         payload.current_trunk.port_id)

        if (nexus_help.is_baremetal(trunkport)
                and trunkport['status'] == bc.constants.PORT_STATUS_ACTIVE):
            host_id = trunkport.get(bc.dns.DNSNAME)
            subport = payload.subports[0]
            trunk_subport = subport.to_dict()

            # Set the subport port attributes to match the parent port.
            if event == events.AFTER_CREATE:
                self.plugin.update_port(
                    payload.context, trunk_subport['port_id'], {
                        'port': {
                            bc.portbindings.HOST_ID: host_id,
                            'device_owner': bc.trunk_consts.TRUNK_SUBPORT_OWNER
                        }
                    })
            elif event == events.AFTER_DELETE:
                self._unbind_subport(payload.context, trunk_subport['port_id'],
                                     bc.constants.PORT_STATUS_DOWN)

            # Trunk drivers are responsible for setting the trunk
            # status. Use the trunk parent port's status.
            trunk_obj = bc.trunk_objects.Trunk.get_object(payload.context,
                                                          id=payload.trunk_id)
            trunk_obj.update(status=trunkport['status'])
Exemplo n.º 3
0
    def trunk_update_postcommit(self, resource, event, trunk_plugin, payload):
        current_trunk_data = payload.current_trunk.to_dict()
        trunkport = self.plugin.get_port(payload.context,
                                         current_trunk_data['port_id'])

        if (nexus_help.is_baremetal(trunkport) and current_trunk_data['status']
                != bc.constants.PORT_STATUS_ACTIVE):
            for subport in current_trunk_data['sub_ports']:
                self._unbind_subport(payload.context, subport['port_id'],
                                     current_trunk_data['status'])
    def _basic_delete_verify_port_vlan(self,
                                       test_name,
                                       test_result,
                                       nbr_of_bindings=0,
                                       nbr_of_mappings=0,
                                       other_test=None):
        """Create port vlan and verify results."""

        if other_test is None:
            other_test = self.test_configs[test_name]

        self._delete_port(other_test)

        # Verify port binding has been removed
        # Verify failure stats is not reset and
        # verify no driver transactions have been sent
        port_cfg = other_test
        ipaddrs = self._get_ip_addrs(port_cfg)
        bindings_found = 0
        for ipaddr in ipaddrs:
            try:
                port_bindings = nexus_db_v2.get_nexusport_switch_bindings(
                    ipaddr)
                bindings_found += len(port_bindings)
                if self._cisco_mech_driver.is_replay_enabled():
                    # Add one for the reserved switch state entry
                    nbr_of_bindings += 1
            except exceptions.NexusPortBindingNotFound:
                pass
        self.assertEqual(nbr_of_bindings, bindings_found)

        port_context = self._generate_port_context(other_test)
        if nexus_help.is_baremetal(port_context.current):
            connections = self._cisco_mech_driver._get_baremetal_connections(
                port_context.current, False, True)
            for switch_ip, intf_type, port, is_p_vlan, _ in connections:
                port_id = intf_type + ':' + port
                try:
                    host_mapping = nexus_db_v2.get_switch_if_host_mappings(
                        switch_ip, port_id)
                except exceptions.NexusHostMappingNotFound:
                    host_mapping = []
                self.assertEqual(nbr_of_mappings, len(host_mapping))

        # Make sure there is only a single attempt to configure.
        self._verify_results(test_result)

        # Clean all the ncclient mock_calls to clear exception
        # and other mock_call history.
        self.mock_ncclient.reset_mock()
Exemplo n.º 5
0
    def is_trunk_subport_baremetal(self, port):
        context = bc.get_context()
        el_context = context.elevated()

        subport_obj = bc.trunk_objects.SubPort.get_object(el_context,
                                                          port_id=port['id'])
        if subport_obj:
            trunk_obj = bc.trunk_objects.Trunk.get_object(
                el_context, id=subport_obj.trunk_id)
            trunk_port = bc.get_plugin().get_port(el_context,
                                                  trunk_obj.port_id)
            return nexus_help.is_baremetal(trunk_port)
        else:
            return False
    def _delete_port(self, port_config):
        """Tests deletion of a virtual port."""
        port_context = self._generate_port_context(port_config)

        self._cisco_mech_driver.delete_port_precommit(port_context)
        self._cisco_mech_driver.delete_port_postcommit(port_context)

        if nexus_help.is_baremetal(port_context.current):
            connections = self._cisco_mech_driver._get_port_connections(
                port_context.current, '')
        else:
            connections = self._cisco_mech_driver._get_port_connections(
                port_context.current, port_config.host_name)

        # for port_id in port_config.nexus_port.split(','):
        for switch_ip, intf_type, port, is_p_vlan, _ in connections:
            if switch_ip is not port_config.nexus_ip_addr:
                continue
            port_id = intf_type + ':' + port
            with testtools.ExpectedException(
                    exceptions.NexusPortBindingNotFound):
                nexus_db_v2.get_nexusport_binding(port_id, port_config.vlan_id,
                                                  port_config.nexus_ip_addr,
                                                  port_config.instance_id)