def _configure_vlan_subport(self, vm, vlan_tag, vlan_subnet):
        self.wait_for_server_active(server=vm.server)
        self.wait_for_guest_os_ready(vm.server)
        self._wait_for_trunk(trunk=vm.trunk)
        self._wait_for_port(port=vm.port)
        self._wait_for_port(port=vm.subport)
        self.check_connectivity(host=vm.floating_ip['floating_ip_address'],
                                ssh_client=vm.ssh_client,
                                servers=[vm.server])

        ip_command = ip.IPCommand(ssh_client=vm.ssh_client)
        for address in ip_command.list_addresses(port=vm.port):
            port_iface = address.device.name
            break
        else:
            self.fail("Parent port fixed IP not found on server.")

        subport_iface = ip_command.configure_vlan_subport(
            port=vm.port,
            subport=vm.subport,
            vlan_tag=vlan_tag,
            subnets=[vlan_subnet])
        for address in ip_command.list_addresses(port=vm.subport):
            self.assertEqual(subport_iface, address.device.name)
            self.assertEqual(port_iface, address.device.parent)
            break
        else:
            self.fail("Sub-port fixed IP not found on server.")
示例#2
0
    def _log_ns_network_status(self, ns_name=None):
        try:
            local_ips = ip_utils.IPCommand(namespace=ns_name).list_addresses()
            local_routes = ip_utils.IPCommand(namespace=ns_name).list_routes()
            arp_table = ip_utils.arp_table(namespace=ns_name)
            iptables = ip_utils.list_iptables(namespace=ns_name)
            lsockets = ip_utils.list_listening_sockets(namespace=ns_name)
        except exceptions.ShellCommandFailed:
            LOG.debug(
                'Namespace %s has been deleted synchronously during the '
                'host network collection process', ns_name)
            return

        LOG.debug('Namespace %s; IP Addresses:\n%s', ns_name,
                  '\n'.join(str(r) for r in local_ips))
        LOG.debug('Namespace %s; Local routes:\n%s', ns_name,
                  '\n'.join(str(r) for r in local_routes))
        LOG.debug('Namespace %s; Local ARP table:\n%s', ns_name,
                  '\n'.join(str(r) for r in arp_table))
        LOG.debug('Namespace %s; Local iptables:\n%s', ns_name, iptables)
        LOG.debug('Namespace %s; Listening sockets:\n%s', ns_name, lsockets)
示例#3
0
 def _prepare_unregistered(self, server, mcast_address):
     ssh_client = ssh.Client(server['fip']['floating_ip_address'],
                             self.username,
                             pkey=self.keypair['private_key'])
     ip_command = ip.IPCommand(ssh_client=ssh_client)
     addresses = ip_command.list_addresses(port=server['port'])
     port_iface = ip.get_port_device_name(addresses, server['port'])
     check_script = get_unregistered_script(
         interface=port_iface,
         group=mcast_address,
         result_file=self.unregistered_output_file)
     self._check_cmd_installed_on_server(ssh_client, server, 'tcpdump')
     server['ssh_client'].execute_script(
         'echo "%s" > /tmp/unregistered_traffic_receiver.sh' % check_script)
示例#4
0
    def _configure_vlan_transparent(self, port, ssh_client,
                                    vlan_tag, vlan_ip):
        ip_command = ip.IPCommand(ssh_client=ssh_client)
        addresses = ip_command.list_addresses(port=port)
        port_iface = ip.get_port_device_name(addresses, port)
        subport_iface = ip_command.configure_vlan_transparent(
            port=port, vlan_tag=vlan_tag, ip_addresses=[vlan_ip])

        for address in ip_command.list_addresses(ip_addresses=vlan_ip):
            self.assertEqual(subport_iface, address.device.name)
            self.assertEqual(port_iface, address.device.parent)
            break
        else:
            self.fail("Sub-port fixed IP not found on server.")
示例#5
0
    def _test_ipv6_address_configured(self, ssh_client, vm, ipv6_port):
        ipv6_address = ipv6_port['fixed_ips'][0]['ip_address']
        ip_command = ip.IPCommand(ssh_client)

        def guest_has_address(expected_address):
            ip_addresses = [a.address for a in ip_command.list_addresses()]
            for ip_address in ip_addresses:
                if expected_address in ip_address:
                    return True
            return False
        # Set NIC with IPv6 to be UP and wait until IPv6 address
        # will be configured on this NIC
        turn_nic6_on(ssh_client, ipv6_port, False)
        # And check if IPv6 address will be properly configured
        # on this NIC
        try:
            utils.wait_until_true(
                lambda: guest_has_address(ipv6_address),
                timeout=60)
        except utils.WaitTimeout:
            LOG.debug('Timeout without NM configuration')
        except (lib_exc.SSHTimeout,
                ssh_exc.AuthenticationException) as ssh_e:
            LOG.debug(ssh_e)
            self._log_console_output([vm])
            self._log_local_network_status()
            raise

        if not guest_has_address(ipv6_address):
            try:
                # Set NIC with IPv6 to be UP and wait until IPv6 address
                # will be configured on this NIC
                turn_nic6_on(ssh_client, ipv6_port)
                # And check if IPv6 address will be properly configured
                # on this NIC
                utils.wait_until_true(
                    lambda: guest_has_address(ipv6_address),
                    timeout=90,
                    exception=RuntimeError(
                        "Timed out waiting for IP address {!r} to be "
                        "configured in the VM {!r}.".format(ipv6_address,
                        vm['id'])))
            except (lib_exc.SSHTimeout,
                    ssh_exc.AuthenticationException) as ssh_e:
                LOG.debug(ssh_e)
                self._log_console_output([vm])
                self._log_local_network_status()
                raise
示例#6
0
def turn_nic6_on(ssh, ipv6_port, config_nic=True):
    """Turns the IPv6 vNIC on

    Required because guest images usually set only the first vNIC on boot.
    Searches for the IPv6 vNIC's MAC and brings it up.
    # NOTE(slaweq): on RHEL based OS ifcfg file for new interface is
    # needed to make IPv6 working on it, so if
    # /etc/sysconfig/network-scripts directory exists ifcfg-%(nic)s file
    # should be added in it

    @param ssh: RemoteClient ssh instance to server
    @param ipv6_port: port from IPv6 network attached to the server
    """
    ip_command = ip.IPCommand(ssh)
    nic = ip_command.get_nic_name_by_mac(ipv6_port['mac_address'])

    if config_nic:
        try:
            if sysconfig_network_scripts_dir_exists(ssh):
                ssh.execute_script(
                    'echo -e "DEVICE=%(nic)s\\nNAME=%(nic)s\\nIPV6INIT=yes" | '
                    'tee /etc/sysconfig/network-scripts/ifcfg-%(nic)s; '
                    % {'nic': nic}, become_root=True)
            if nmcli_command_exists(ssh):
                ssh.execute_script('nmcli connection reload %s' % nic,
                                   become_root=True)
                ssh.execute_script('nmcli con mod %s ipv6.addr-gen-mode eui64'
                                   % nic, become_root=True)
                ssh.execute_script('nmcli connection up %s' % nic,
                                   become_root=True)

        except lib_exc.SSHExecCommandFailed as e:
            # NOTE(slaweq): Sometimes it can happen that this SSH command
            # will fail because of some error from network manager in
            # guest os.
            # But even then doing ip link set up below is fine and
            # IP address should be configured properly.
            LOG.debug("Error creating NetworkManager profile. "
                      "Error message: %(error)s",
                      {'error': e})

    ip_command.set_link(nic, "up")
示例#7
0
 def _log_local_network_status(self):
     local_routes = ip_utils.IPCommand().list_routes()
     LOG.debug('Local routes:\n%s', '\n'.join(str(r) for r in local_routes))
     arp_table = ip_utils.arp_table()
     LOG.debug('Local ARP table:\n%s', '\n'.join(str(r) for r in arp_table))
示例#8
0
 def _log_local_network_status(self):
     self._log_ns_network_status()
     for ns_name in ip_utils.IPCommand().list_namespaces():
         self._log_ns_network_status(ns_name=ns_name)