File: network_interfaces_test.rb

package info (click to toggle)
vagrant 2.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,072 kB
  • sloc: ruby: 80,731; sh: 369; makefile: 9; lisp: 1
file content (108 lines) | stat: -rw-r--r-- 4,916 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require_relative "../../../../base"

describe "VagrantPlugins::GuestLinux::Cap::NetworkInterfaces" do
  let(:caps) do
    VagrantPlugins::GuestLinux::Plugin
      .components
      .guest_capabilities[:linux]
  end

  let(:machine) { double("machine") }
  let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }

  before do
    allow(machine).to receive(:communicate).and_return(comm)
  end

  after do
    comm.verify_expectations!
  end

  describe ".network_interfaces" do
    let(:cap){ caps.get(:network_interfaces) }

    it "sorts discovered classic interfaces" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "eth1\neth2\neth0")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["eth0", "eth1", "eth2"])
    end

    it "sorts discovered classic interfaces and handles trailing newline" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "eth1\neth2\neth0\n")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["eth0", "eth1", "eth2"])
    end

    it "filters out lo interface" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "lo\neth0")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["eth0"])
    end

    it "sorts discovered predictable network interfaces" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "enp0s8\nenp0s3\nenp0s5")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["enp0s3", "enp0s5", "enp0s8"])
    end

    it "sorts discovered classic interfaces naturally" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "eth1\neth2\neth12\neth0\neth10")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["eth0", "eth1", "eth2", "eth10", "eth12"])
    end

    it "sorts discovered predictable network interfaces naturally" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "enp0s8\nenp0s3\nenp0s5\nenp0s10\nenp1s3")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["enp0s3", "enp0s5", "enp0s8", "enp0s10", "enp1s3"])
    end

    it "sorts ethernet devices discovered with classic naming first in list" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "eth1\neth2\ndocker0\nbridge0\neth0")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["eth0", "eth1", "eth2", "bridge0", "docker0"])
    end

    it "sorts ethernet devices discovered with predictable network interfaces naming first in list" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "enp0s8\ndocker0\nenp0s3\nbridge0\nenp0s5")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["enp0s3", "enp0s5", "enp0s8", "bridge0", "docker0"])
    end

    it "sorts ethernet devices discovered with predictable network interfaces naming first in list with less" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "enp0s3\nenp0s8\ndocker0")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["enp0s3", "enp0s8", "docker0"])
    end

    it "does not include ethernet devices aliases within prefix device listing" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "eth1\neth2\ndocker0\nbridge0\neth0\ndocker1\neth0:0")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["eth0", "eth1", "eth2", "bridge0", "docker0", "docker1", "eth0:0"])
    end

    it "does not include ethernet devices aliases within prefix device listing with dot separators" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "eth1\neth2\ndocker0\nbridge0\neth0\ndocker1\neth0.1@eth0")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["eth0", "eth1", "eth2", "bridge0", "docker0", "docker1", "eth0.1@eth0"])
    end

    it "properly sorts non-consistent device name formats" do
      expect(comm).to receive(:sudo).twice.and_yield(:stdout, "eth0\neth1\ndocker0\nveth437f7f9\nveth06b3e44\nveth8bb7081")
      expect(comm).to receive(:sudo).and_yield(:stdout, "lo")
      result = cap.network_interfaces(machine)
      expect(result).to eq(["eth0", "eth1", "docker0", "veth8bb7081", "veth437f7f9", "veth06b3e44"])
    end
  end
end