Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vagrant incorrectly detects the name of network interface for bridged interface #7858

Closed
aston-r opened this issue Oct 3, 2016 · 4 comments · Fixed by #7866
Closed

vagrant incorrectly detects the name of network interface for bridged interface #7858

aston-r opened this issue Oct 3, 2016 · 4 comments · Fixed by #7866
Assignees
Milestone

Comments

@aston-r
Copy link

aston-r commented Oct 3, 2016

Hi,

After upgrading to the new version of vagrant 1.8.6. I faced the issue that Vagrant tries to bring up the interface and uses the name of vlan on my virtual machine. Vagrant 1.8.5 works as expected and uses eth1 for bridge interface

Here is a part of log from vagrant 1.8.6

DEBUG guest: Searching for cap: network_interfaces
DEBUG guest: Checking in: redhat
DEBUG guest: Checking in: linux
DEBUG guest: Found cap: network_interfaces in linux
 INFO guest: Execute capability: network_interfaces [#<Vagrant::Machine: rhel-72 (VagrantPlugins::ProviderVirtualBox::Provider)>] (redhat)
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: /sbin/ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://' (sudo=true)
DEBUG ssh: Exit status: 0
DEBUG network_interfaces: Unsorted list: ["eth0", "eth1", "eth0.1@eth0"]
DEBUG network_interfaces: Sorted list: ["eth0", "eth0.1@eth0", "eth1"]
DEBUG ssh: Uploading: /tmp/vagrant-redhat-configure-networks20161003-15716-179yymx to /tmp/vagrant-network-entry-eth0.1@eth0-1475481833-0
DEBUG ssh: Re-using SSH connection.
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: # Down the interface before munging the config file. This might
# fail if the interface is not actually set up yet so ignore
# errors.
/sbin/ifdown 'eth0.1@eth0' || true

# Move new config into place
mv '/tmp/vagrant-network-entry-eth0.1@eth0-1475481833-0' '/etc/sysconfig/network-scripts/ifcfg-eth0.1@eth0'

# Bring the interface up
ARPCHECK=no /sbin/ifup 'eth0.1@eth0'
 (sudo=true)
DEBUG ssh: stderr: usage: ifdown <configuration>

DEBUG ssh: stderr: Error: Connection activation failed: No suitable device found for this connection.

DEBUG ssh: Exit status: 4
ERROR warden: Error occurred: The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

# Down the interface before munging the config file. This might
# fail if the interface is not actually set up yet so ignore
# errors.
/sbin/ifdown 'eth0.1@eth0' || true

# Move new config into place
mv '/tmp/vagrant-network-entry-eth0.1@eth0-1475481833-0' '/etc/sysconfig/network-scripts/ifcfg-eth0.1@eth0'

# Bring the interface up
ARPCHECK=no /sbin/ifup 'eth0.1@eth0'

Here is a part of log from vagrant 1.8.5

DEBUG guest: Found cap: network_interfaces in linux
 INFO guest: Execute capability: network_interfaces [#<Vagrant::Machine: rhel-72 (VagrantPlugins::ProviderVirtualBox::Provider)>] (redhat)
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: /sbin/ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://' (sudo=true)
DEBUG ssh: stdout: eth0
eth1
eth0.1@eth0

DEBUG ssh: Exit status: 0
DEBUG ssh: Uploading: /tmp/vagrant-redhat-configure-networks20161003-9343-6cujsp to /tmp/vagrant-network-entry-eth1-1475480742-0
DEBUG ssh: Re-using SSH connection.
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: # Down the interface before munging the config file. This might
# fail if the interface is not actually set up yet so ignore
# errors.
/sbin/ifdown 'eth1' || true

# Move new config into place
mv '/tmp/vagrant-network-entry-eth1-1475480742-0' '/etc/sysconfig/network-scripts/ifcfg-eth1'

# Bring the interface up
ARPCHECK=no /sbin/ifup 'eth1'
 (sudo=true)

Just in case I have the following configuration:

config.vm.network :public_network, :adapter => 2, :bridge => "Broadcom NetLink (TM) Gigabit Ethernet", :mac => "xxxxxxxxxxx", :nic_type => "virtio"

Could you please advice? Why vagrant 1.8.6 does not use eth1 as interface name for bridged interface?

@chrisroberts chrisroberts added this to the 1.8.7 milestone Oct 3, 2016
@chrisroberts chrisroberts self-assigned this Oct 3, 2016
@chrisroberts
Copy link
Member

Slightly related: #7848.

@aston-r
Copy link
Author

aston-r commented Oct 3, 2016

Hi chrisroberts,

Just in case the issue appears after fix in GH-7705 (I tried to revert and all is ok)

--- a/plugins/guests/linux/cap/network_interfaces.rb
+++ b/plugins/guests/linux/cap/network_interfaces.rb
@@ -2,6 +2,8 @@ module VagrantPlugins
   module GuestLinux
     module Cap
       class NetworkInterfaces
+        @@logger = Log4r::Logger.new("vagrant::guest::linux::network_interfaces")
+
         # Get network interfaces as a list. The result will be something like:
         #
         #   eth0\nenp0s8\nenp0s9
@@ -12,7 +14,21 @@ module VagrantPlugins
           machine.communicate.sudo("#{path} -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |type, data|
             s << data if type == :stdout
           end
-          s.split("\n")
+          ifaces = s.split("\n")
+          @@logger.debug("Unsorted list: #{ifaces.inspect}")
+          # Break out integers from strings and sort the arrays to provide
+          # a natural sort for the interface names
+          ifaces = ifaces.map do |iface|
+            iface.scan(/(.+?)(\d+)/).flatten.map do |iface_part|
+              if iface_part.to_i.to_s == iface_part
+                iface_part.to_i
+              else
+                iface_part
+              end
+            end
+          end.sort.map(&:join)
+          @@logger.debug("Sorted list: #{ifaces.inspect}")
+          ifaces
         end
       end
     end

@matrixik
Copy link

matrixik commented Oct 4, 2016

Hi, I have similar problem after updating from 1.8.5 to 1.8.6:

DEBUG network_interfaces: Unsorted list: ["enp0s3", "enp0s8", "ovs-system", "br-int", "br-ex", "br-tun"]
DEBUG network_interfaces: Sorted list: ["", "", "", "", "enp0s3", "enp0s8"]
DEBUG ssh: Uploading: /tmp/zybortd/vagrant-redhat-configure-networks20161004-12217-1uqqpqv to /tmp/vagrant-network-entry--1475584803-0
DEBUG ssh: Re-using SSH connection.
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: # Down the interface before munging the config file. This might
# fail if the interface is not actually set up yet so ignore
# errors.
/sbin/ifdown '' || true

# Move new config into place
mv '/tmp/vagrant-network-entry--1475584803-0' '/etc/sysconfig/network-scripts/ifcfg-'

# Bring the interface up
ARPCHECK=no /sbin/ifup ''
 (sudo=true)
DEBUG ssh: stderr: usage: ifdown <configuration>

DEBUG ssh: stderr: Usage: ifup <configuration>

DEBUG ssh: Exit status: 1
ERROR warden: Error occurred: The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

# Down the interface before munging the config file. This might
# fail if the interface is not actually set up yet so ignore
# errors.
/sbin/ifdown '' || true

# Move new config into place
mv '/tmp/vagrant-network-entry--1475584803-0' '/etc/sysconfig/network-scripts/ifcfg-'

# Bring the interface up
ARPCHECK=no /sbin/ifup ''


Stdout from the command:



Stderr from the command:

usage: ifdown <configuration>
Usage: ifup <configuration>

When Sorted list: ["", "", "", "", "enp0s3", "enp0s8"] Vagrant try to run /sbin/ifdown with empty interface.

Host operating system
Ubuntu 16.04
Guest operating system
CentOS 7

# ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'
enp0s3
enp0s8
ovs-system
br-int
br-ex
br-tun

@ghost
Copy link

ghost commented Apr 3, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants