ohai 15.3.1 → 15.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -6
  3. data/lib/ohai/mixin/{network_constants.rb → network_helper.rb} +8 -1
  4. data/lib/ohai/plugins/aix/network.rb +3 -8
  5. data/lib/ohai/plugins/darwin/network.rb +6 -4
  6. data/lib/ohai/plugins/filesystem.rb +166 -0
  7. data/lib/ohai/plugins/network.rb +5 -5
  8. data/lib/ohai/plugins/openstack.rb +2 -1
  9. data/lib/ohai/plugins/solaris2/network.rb +6 -4
  10. data/lib/ohai/version.rb +1 -1
  11. data/ohai.gemspec +1 -1
  12. metadata +3 -162
  13. data/Rakefile +0 -42
  14. data/lib/ohai/plugins/windows/filesystem.rb +0 -147
  15. data/spec/data/plugins/dpkg-query.output +0 -4
  16. data/spec/data/plugins/lslpp.output +0 -50
  17. data/spec/data/plugins/pacman.output +0 -51
  18. data/spec/data/plugins/pkg-query.output +0 -58
  19. data/spec/data/plugins/pkginfo.output +0 -50
  20. data/spec/data/plugins/pkglist.output +0 -24
  21. data/spec/data/plugins/rpmquery.output +0 -7
  22. data/spec/functional/application_spec.rb +0 -107
  23. data/spec/functional/loader_spec.rb +0 -53
  24. data/spec/functional/plugins/powershell_spec.rb +0 -88
  25. data/spec/functional/plugins/root_group_spec.rb +0 -41
  26. data/spec/functional/plugins/windows/uptime_spec.rb +0 -51
  27. data/spec/ohai_spec.rb +0 -27
  28. data/spec/rcov.opts +0 -2
  29. data/spec/spec.opts +0 -2
  30. data/spec/spec_helper.rb +0 -124
  31. data/spec/support/integration_helper.rb +0 -61
  32. data/spec/support/platform_helpers.rb +0 -38
  33. data/spec/unit/application_spec.rb +0 -96
  34. data/spec/unit/config_spec.rb +0 -57
  35. data/spec/unit/dsl/plugin_spec.rb +0 -634
  36. data/spec/unit/hints_spec.rb +0 -65
  37. data/spec/unit/loader_spec.rb +0 -195
  38. data/spec/unit/mixin/azure_metadata_spec.rb +0 -72
  39. data/spec/unit/mixin/command_spec.rb +0 -151
  40. data/spec/unit/mixin/dmi_decode.rb +0 -75
  41. data/spec/unit/mixin/ec2_metadata_spec.rb +0 -88
  42. data/spec/unit/mixin/softlayer_metadata_spec.rb +0 -72
  43. data/spec/unit/plugin_config_spec.rb +0 -117
  44. data/spec/unit/plugins/abort_spec.rb +0 -69
  45. data/spec/unit/plugins/aix/cpu_spec.rb +0 -127
  46. data/spec/unit/plugins/aix/filesystem_spec.rb +0 -238
  47. data/spec/unit/plugins/aix/hostname_spec.rb +0 -33
  48. data/spec/unit/plugins/aix/kernel_spec.rb +0 -61
  49. data/spec/unit/plugins/aix/memory_spec.rb +0 -49
  50. data/spec/unit/plugins/aix/network_spec.rb +0 -313
  51. data/spec/unit/plugins/aix/platform_spec.rb +0 -44
  52. data/spec/unit/plugins/aix/uptime_spec.rb +0 -42
  53. data/spec/unit/plugins/aix/virtualization_spec.rb +0 -319
  54. data/spec/unit/plugins/azure_spec.rb +0 -243
  55. data/spec/unit/plugins/bsd/filesystem_spec.rb +0 -138
  56. data/spec/unit/plugins/bsd/virtualization_spec.rb +0 -145
  57. data/spec/unit/plugins/c_spec.rb +0 -341
  58. data/spec/unit/plugins/chef_spec.rb +0 -44
  59. data/spec/unit/plugins/cloud_spec.rb +0 -484
  60. data/spec/unit/plugins/darwin/cpu_spec.rb +0 -124
  61. data/spec/unit/plugins/darwin/filesystem_spec.rb +0 -140
  62. data/spec/unit/plugins/darwin/hardware_spec.rb +0 -105
  63. data/spec/unit/plugins/darwin/hardware_system_profiler_output.rb +0 -1110
  64. data/spec/unit/plugins/darwin/hostname_spec.rb +0 -43
  65. data/spec/unit/plugins/darwin/kernel_spec.rb +0 -65
  66. data/spec/unit/plugins/darwin/memory_spec.rb +0 -64
  67. data/spec/unit/plugins/darwin/network_spec.rb +0 -849
  68. data/spec/unit/plugins/darwin/platform_spec.rb +0 -71
  69. data/spec/unit/plugins/darwin/virtualization_spec.rb +0 -156
  70. data/spec/unit/plugins/digital_ocean_spec.rb +0 -106
  71. data/spec/unit/plugins/dmi_spec.rb +0 -156
  72. data/spec/unit/plugins/docker_spec.rb +0 -100
  73. data/spec/unit/plugins/ec2_spec.rb +0 -452
  74. data/spec/unit/plugins/elixir_spec.rb +0 -55
  75. data/spec/unit/plugins/erlang_spec.rb +0 -71
  76. data/spec/unit/plugins/eucalyptus_spec.rb +0 -109
  77. data/spec/unit/plugins/fail_spec.rb +0 -260
  78. data/spec/unit/plugins/freebsd/cpu_spec.rb +0 -129
  79. data/spec/unit/plugins/freebsd/hostname_spec.rb +0 -35
  80. data/spec/unit/plugins/freebsd/kernel_spec.rb +0 -36
  81. data/spec/unit/plugins/freebsd/platform_spec.rb +0 -38
  82. data/spec/unit/plugins/gce_spec.rb +0 -81
  83. data/spec/unit/plugins/go_spec.rb +0 -48
  84. data/spec/unit/plugins/groovy_spec.rb +0 -66
  85. data/spec/unit/plugins/haskell_spec.rb +0 -231
  86. data/spec/unit/plugins/hostname_spec.rb +0 -162
  87. data/spec/unit/plugins/init_package_spec.rb +0 -60
  88. data/spec/unit/plugins/java_spec.rb +0 -230
  89. data/spec/unit/plugins/joyent_spec.rb +0 -100
  90. data/spec/unit/plugins/kernel_spec.rb +0 -38
  91. data/spec/unit/plugins/linode_spec.rb +0 -135
  92. data/spec/unit/plugins/linux/block_device_spec.rb +0 -75
  93. data/spec/unit/plugins/linux/cpu_spec.rb +0 -441
  94. data/spec/unit/plugins/linux/filesystem_spec.rb +0 -550
  95. data/spec/unit/plugins/linux/fips_spec.rb +0 -60
  96. data/spec/unit/plugins/linux/hostname_spec.rb +0 -52
  97. data/spec/unit/plugins/linux/hostnamectl_spec.rb +0 -59
  98. data/spec/unit/plugins/linux/kernel_spec.rb +0 -71
  99. data/spec/unit/plugins/linux/lsb_spec.rb +0 -147
  100. data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
  101. data/spec/unit/plugins/linux/machineid_spec.rb +0 -46
  102. data/spec/unit/plugins/linux/mdadm_spec.rb +0 -170
  103. data/spec/unit/plugins/linux/memory_spec.rb +0 -256
  104. data/spec/unit/plugins/linux/network_spec.rb +0 -1392
  105. data/spec/unit/plugins/linux/platform_spec.rb +0 -812
  106. data/spec/unit/plugins/linux/sessions_spec.rb +0 -98
  107. data/spec/unit/plugins/linux/sysctl_spec.rb +0 -53
  108. data/spec/unit/plugins/linux/systemd_paths_spec.rb +0 -122
  109. data/spec/unit/plugins/linux/uptime_spec.rb +0 -48
  110. data/spec/unit/plugins/linux/virtualization_spec.rb +0 -650
  111. data/spec/unit/plugins/lua_spec.rb +0 -60
  112. data/spec/unit/plugins/mono_spec.rb +0 -67
  113. data/spec/unit/plugins/netbsd/hostname_spec.rb +0 -43
  114. data/spec/unit/plugins/netbsd/kernel_spec.rb +0 -35
  115. data/spec/unit/plugins/netbsd/platform_spec.rb +0 -38
  116. data/spec/unit/plugins/network_spec.rb +0 -1078
  117. data/spec/unit/plugins/nodejs_spec.rb +0 -55
  118. data/spec/unit/plugins/ohai_spec.rb +0 -32
  119. data/spec/unit/plugins/ohai_time_spec.rb +0 -44
  120. data/spec/unit/plugins/openbsd/hostname_spec.rb +0 -43
  121. data/spec/unit/plugins/openbsd/kernel_spec.rb +0 -36
  122. data/spec/unit/plugins/openbsd/platform_spec.rb +0 -33
  123. data/spec/unit/plugins/openstack_spec.rb +0 -311
  124. data/spec/unit/plugins/os_spec.rb +0 -115
  125. data/spec/unit/plugins/packages_spec.rb +0 -353
  126. data/spec/unit/plugins/passwd_spec.rb +0 -65
  127. data/spec/unit/plugins/perl_spec.rb +0 -62
  128. data/spec/unit/plugins/php_spec.rb +0 -97
  129. data/spec/unit/plugins/platform_spec.rb +0 -65
  130. data/spec/unit/plugins/powershell_spec.rb +0 -71
  131. data/spec/unit/plugins/python_spec.rb +0 -51
  132. data/spec/unit/plugins/rackspace_spec.rb +0 -350
  133. data/spec/unit/plugins/root_group_spec.rb +0 -90
  134. data/spec/unit/plugins/ruby_spec.rb +0 -60
  135. data/spec/unit/plugins/rust_spec.rb +0 -43
  136. data/spec/unit/plugins/scala_spec.rb +0 -58
  137. data/spec/unit/plugins/scaleway_spec.rb +0 -93
  138. data/spec/unit/plugins/scsi_spec.rb +0 -69
  139. data/spec/unit/plugins/shard_spec.rb +0 -121
  140. data/spec/unit/plugins/shells_spec.rb +0 -56
  141. data/spec/unit/plugins/softlayer_spec.rb +0 -60
  142. data/spec/unit/plugins/solaris2/cpu_spec.rb +0 -2926
  143. data/spec/unit/plugins/solaris2/dmi_spec.rb +0 -153
  144. data/spec/unit/plugins/solaris2/filesystem.rb +0 -407
  145. data/spec/unit/plugins/solaris2/hostname_spec.rb +0 -37
  146. data/spec/unit/plugins/solaris2/kernel_spec.rb +0 -183
  147. data/spec/unit/plugins/solaris2/memory_spec.rb +0 -43
  148. data/spec/unit/plugins/solaris2/network_spec.rb +0 -201
  149. data/spec/unit/plugins/solaris2/platform_spec.rb +0 -108
  150. data/spec/unit/plugins/solaris2/virtualization_spec.rb +0 -97
  151. data/spec/unit/plugins/ssh_host_keys_spec.rb +0 -116
  152. data/spec/unit/plugins/sysconf_spec.rb +0 -680
  153. data/spec/unit/plugins/timezone_spec.rb +0 -30
  154. data/spec/unit/plugins/vbox_host_spec.rb +0 -14
  155. data/spec/unit/plugins/virtualbox_spec.rb +0 -375
  156. data/spec/unit/plugins/vmware_spec.rb +0 -81
  157. data/spec/unit/plugins/windows/cpu_spec.rb +0 -118
  158. data/spec/unit/plugins/windows/filesystem_spec.rb +0 -226
  159. data/spec/unit/plugins/windows/fips_spec.rb +0 -60
  160. data/spec/unit/plugins/windows/kernel_spec.rb +0 -79
  161. data/spec/unit/plugins/windows/memory_spec.rb +0 -52
  162. data/spec/unit/plugins/windows/network_spec.rb +0 -137
  163. data/spec/unit/plugins/windows/system_enclosure_spec.rb +0 -45
  164. data/spec/unit/plugins/windows/uptime_spec.rb +0 -38
  165. data/spec/unit/plugins/windows/virtualization_spec.rb +0 -63
  166. data/spec/unit/plugins/zpools_spec.rb +0 -244
  167. data/spec/unit/provides_map_spec.rb +0 -208
  168. data/spec/unit/runner_spec.rb +0 -422
  169. data/spec/unit/system_spec.rb +0 -416
  170. data/spec/unit/util/file_helper_spec.rb +0 -47
  171. data/spec/unit/util/ip_helper_spec.rb +0 -128
@@ -1,1392 +0,0 @@
1
- #
2
- # Author:: Caleb Tennis <caleb.tennis@gmail.com>
3
- # Author:: Chris Read <chris.read@gmail.com>
4
- # Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require "spec_helper"
21
- require "ipaddress"
22
-
23
- describe Ohai::System, "Linux Network Plugin" do
24
- let(:plugin) { get_plugin("linux/network") }
25
-
26
- let(:linux_ifconfig) do
27
- <<~EOM
28
- eth0 Link encap:Ethernet HWaddr 12:31:3D:02:BE:A2
29
- inet addr:10.116.201.76 Bcast:10.116.201.255 Mask:255.255.255.0
30
- inet6 addr: fe80::1031:3dff:fe02:bea2/64 Scope:Link
31
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
32
- RX packets:2659966 errors:0 dropped:0 overruns:0 frame:0
33
- TX packets:1919690 errors:0 dropped:0 overruns:0 carrier:0
34
- collisions:0 txqueuelen:1000
35
- RX bytes:1392844460 (1.2 GiB) TX bytes:691785313 (659.7 MiB)
36
- Interrupt:16
37
-
38
- eth0:5 Link encap:Ethernet HWaddr 00:0c:29:41:71:45
39
- inet addr:192.168.5.1 Bcast:192.168.5.255 Mask:255.255.255.0
40
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
41
-
42
- eth0.11 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
43
- inet addr:192.168.0.16 Bcast:192.168.0.255 Mask:255.255.255.0
44
- inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
45
- inet6 addr: 1111:2222:3333:4444::2/64 Scope:Global
46
- inet6 addr: 1111:2222:3333:4444::3/64 Scope:Global
47
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
48
- RX packets:1208795008 errors:0 dropped:0 overruns:0 frame:0
49
- TX packets:3269635153 errors:0 dropped:0 overruns:0 carrier:0
50
- collisions:0 txqueuelen:0
51
- RX bytes:1751940374 (1.6 GiB) TX bytes:2195567597 (2.0 GiB)
52
-
53
- eth0.151 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
54
- inet addr:10.151.0.16 Bcast:10.151.0.255 Mask:255.255.255.0
55
- inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
56
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
57
- RX packets:206553677 errors:0 dropped:0 overruns:0 frame:0
58
- TX packets:163901336 errors:0 dropped:0 overruns:0 carrier:0
59
- collisions:0 txqueuelen:0
60
- RX bytes:3190792261 (2.9 GiB) TX bytes:755086548 (720.1 MiB)
61
-
62
- eth0.152 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
63
- inet addr:10.152.1.16 Bcast:10.152.3.255 Mask:255.255.252.0
64
- inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
65
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
66
- RX packets:14016741 errors:0 dropped:0 overruns:0 frame:0
67
- TX packets:55232 errors:0 dropped:0 overruns:0 carrier:0
68
- collisions:0 txqueuelen:0
69
- RX bytes:664957462 (634.1 MiB) TX bytes:4876434 (4.6 MiB)
70
-
71
- eth0.153 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
72
- inet addr:10.153.1.16 Bcast:10.153.3.255 Mask:255.255.252.0
73
- inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
74
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
75
- RX packets:2022667595 errors:0 dropped:0 overruns:0 frame:0
76
- TX packets:1798627472 errors:0 dropped:0 overruns:0 carrier:0
77
- collisions:0 txqueuelen:0
78
- RX bytes:4047036732 (3.7 GiB) TX bytes:3451231474 (3.2 GiB)
79
-
80
- foo:veth0@eth0 Link encap:Ethernet HWaddr ca:b3:73:8b:0c:e4
81
- BROADCAST MULTICAST MTU:1500 Metric:1
82
-
83
- tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
84
- inet addr:172.16.19.39 P-t-P:172.16.19.1 Mask:255.255.255.255
85
- UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
86
- RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
87
- TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
88
- collisions:0 txqueuelen:100
89
- RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
90
-
91
- venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
92
- UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
93
- RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
94
- TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
95
- collisions:0 txqueuelen:100
96
- RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
97
-
98
- venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
99
- UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
100
- RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
101
- TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
102
- collisions:0 txqueuelen:100
103
- RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
104
-
105
- lo Link encap:Local Loopback
106
- inet addr:127.0.0.1 Mask:255.0.0.0
107
- inet6 addr: ::1/128 Scope:Host
108
- UP LOOPBACK RUNNING MTU:16436 Metric:1
109
- RX packets:524 errors:0 dropped:0 overruns:0 frame:0
110
- TX packets:524 errors:0 dropped:0 overruns:0 carrier:0
111
- collisions:0 txqueuelen:0
112
- RX bytes:35224 (34.3 KiB) TX bytes:35224 (34.3 KiB)
113
-
114
- eth3 Link encap:Ethernet HWaddr E8:39:35:C5:C8:54
115
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
116
- RX packets:13395101 errors:0 dropped:0 overruns:0 frame:0
117
- TX packets:9492909 errors:0 dropped:0 overruns:0 carrier:0
118
- collisions:0 txqueuelen:1000
119
- RX bytes:1325650573 (1.2 GiB) TX bytes:1666310189 (1.5 GiB)
120
- Interrupt:36 Memory:f4800000-f4ffffff
121
-
122
- ovs-system Link encap:Ethernet HWaddr 7A:7A:80:80:6C:24
123
- BROADCAST MULTICAST MTU:1500 Metric:1
124
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
125
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
126
- collisions:0 txqueuelen:0
127
- RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
128
-
129
- xapi1 Link encap:Ethernet HWaddr E8:39:35:C5:C8:50
130
- inet addr:192.168.13.34 Bcast:192.168.13.255 Mask:255.255.255.0
131
- UP BROADCAST RUNNING MTU:1500 Metric:1
132
- RX packets:160275 errors:0 dropped:0 overruns:0 frame:0
133
- TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
134
- collisions:0 txqueuelen:0
135
- RX bytes:21515031 (20.5 MiB) TX bytes:2052 (2.0 KiB)
136
-
137
- fwdintf Link encap:Ethernet HWaddr 00:00:00:00:00:0a
138
- inet6 addr: fe80::200:ff:fe00:a/64 Scope:Link
139
- UP RUNNING NOARP MULTICAST MTU:1496 Metric:1
140
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
141
- TX packets:2 errors:0 dropped:1 overruns:0 carrier:0
142
- collisions:0 txqueuelen:1000
143
- RX bytes:0 (0.0 B) TX bytes:140 (140.0 B)
144
- EOM
145
- # Note that ifconfig shows foo:veth0@eth0 but fails to show any address information.
146
- # This was not a mistake collecting the output and Apparently ifconfig is broken in this regard.
147
- end
148
-
149
- let(:linux_ip_route) do
150
- <<~EOM
151
- 10.116.201.0/24 dev eth0 proto kernel
152
- 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
153
- 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
154
- 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
155
- 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
156
- 10.5.4.0/24 \\ nexthop via 10.5.4.1 dev eth0 weight 1\\ nexthop via 10.5.4.2 dev eth0 weight 1
157
- default via 10.116.201.1 dev eth0
158
- EOM
159
- end
160
-
161
- let(:linux_route_n) do
162
- <<~EOM
163
- Kernel IP routing table
164
- Destination Gateway Genmask Flags Metric Ref Use Iface
165
- 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
166
- 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
167
- 0.0.0.0 10.116.201.1 0.0.0.0 UG 0 0 0 eth0
168
- EOM
169
- end
170
-
171
- let(:linux_ip_route_inet6) do
172
- <<~EOM
173
- fe80::/64 dev eth0 proto kernel metric 256
174
- fe80::/64 dev eth0.11 proto kernel metric 256
175
- 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 expires 86023sec
176
- default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
177
- EOM
178
- end
179
-
180
- let(:linux_ip_addr) do
181
- <<~EOM
182
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
183
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
184
- inet 127.0.0.1/8 scope host lo
185
- inet6 ::1/128 scope host
186
- valid_lft forever preferred_lft forever
187
- 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
188
- link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff
189
- inet 10.116.201.76/24 brd 10.116.201.255 scope global eth0
190
- inet 10.116.201.75/32 scope global eth0
191
- inet 10.116.201.74/24 scope global secondary eth0
192
- inet 192.168.5.1/24 brd 192.168.5.255 scope global eth0:5
193
- inet6 fe80::1031:3dff:fe02:bea2/64 scope link
194
- valid_lft forever preferred_lft forever
195
- inet6 2001:44b8:4160:8f00:a00:27ff:fe13:eacd/64 scope global dynamic
196
- valid_lft 6128sec preferred_lft 2526sec
197
- 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
198
- link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
199
- inet 192.168.0.16/24 brd 192.168.0.255 scope global eth0.11
200
- inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
201
- inet6 1111:2222:3333:4444::2/64 scope global
202
- valid_lft forever preferred_lft forever
203
- inet6 1111:2222:3333:4444::3/64 scope global
204
- valid_lft forever preferred_lft forever
205
- 4: eth0.151@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
206
- link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
207
- inet 10.151.0.16/24 brd 10.151.0.255 scope global eth0.151
208
- inet 10.151.1.16/24 scope global eth0.151
209
- inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
210
- valid_lft forever preferred_lft forever
211
- 5: eth0.152@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
212
- link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
213
- inet 10.152.1.16/22 brd 10.152.3.255 scope global eth0.152
214
- inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
215
- valid_lft forever preferred_lft forever
216
- 6: eth0.153@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
217
- link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
218
- inet 10.153.1.16/22 brd 10.153.3.255 scope global eth0.153
219
- inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
220
- valid_lft forever preferred_lft forever
221
- 7: foo:veth0@eth0@veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN
222
- link/ether ca:b3:73:8b:0c:e4 brd ff:ff:ff:ff:ff:ff
223
- inet 192.168.212.2/24 scope global foo:veth0@eth0
224
- 8: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
225
- link/none
226
- inet 172.16.19.39 peer 172.16.19.1 scope global tun0
227
- 9: venet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
228
- link/void
229
- inet 127.0.0.2/32 scope host venet0
230
- inet 172.16.19.48/32 scope global venet0:0
231
- 12: xapi1: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
232
- link/ether e8:39:35:c5:c8:50 brd ff:ff:ff:ff:ff:ff
233
- inet 192.168.13.34/24 brd 192.168.13.255 scope global xapi1
234
- valid_lft forever preferred_lft forever
235
- 13: fwdintf: <MULTICAST,NOARP,UP,LOWER_UP> mtu 1496 qdisc pfifo_fast state UNKNOWN group default qlen 1000
236
- link/ether 00:00:00:00:00:0a brd ff:ff:ff:ff:ff:ff
237
- 14: ip6tnl0@NONE: <NOARP,UP,LOWER_UP> mtu 1452 qdisc noqueue state UNKNOWN group default qlen 1
238
- link/tunnel6 :: brd ::
239
- inet6 fe80::f47a:2aff:fef0:c6ef/64 scope link
240
- valid_lft forever preferred_lft forever
241
- EOM
242
- end
243
-
244
- let(:linux_ip_link_s_d) do
245
- <<~EOM
246
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
247
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
248
- RX: bytes packets errors dropped overrun mcast
249
- 35224 524 0 0 0 0
250
- TX: bytes packets errors dropped carrier collsns
251
- 35224 524 0 0 0 0
252
- 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
253
- link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff
254
- RX: bytes packets errors dropped overrun mcast
255
- 1392844460 2659966 0 0 0 0
256
- TX: bytes packets errors dropped carrier collsns
257
- 691785313 1919690 0 0 0 0
258
- 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
259
- link/ether 00:0c:29:41:71:45 brd ff:ff:ff:ff:ff:ff
260
- vlan id 11 <REORDER_HDR>
261
- RX: bytes packets errors dropped overrun mcast
262
- 0 0 0 0 0 0
263
- TX: bytes packets errors dropped carrier collsns
264
- 0 0 0 0 0 0
265
- 4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100
266
- link/none
267
- RX: bytes packets errors dropped overrun mcast
268
- 1392844460 2659966 0 0 0 0
269
- TX: bytes packets errors dropped carrier collsns
270
- 691785313 1919690 0 0 0 0
271
- 5: venet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
272
- link/void
273
- RX: bytes packets errors dropped overrun mcast
274
- 1392844460 2659966 0 0 0 0
275
- TX: bytes packets errors dropped carrier collsns
276
- 691785313 1919690 0 0 0 0
277
- 10: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master ovs-system state UP mode DEFAULT qlen 1000
278
- link/ether e8:39:35:c5:c8:54 brd ff:ff:ff:ff:ff:ff
279
- RX: bytes packets errors dropped overrun mcast
280
- 1321907045 13357087 0 0 0 3126613
281
- TX: bytes packets errors dropped carrier collsns
282
- 1661526184 9467091 0 0 0 0
283
- 11: ovs-system: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT
284
- link/ether 7a:7a:80:80:6c:24 brd ff:ff:ff:ff:ff:ff
285
- RX: bytes packets errors dropped overrun mcast
286
- 0 0 0 0 0 0
287
- TX: bytes packets errors dropped carrier collsns
288
- 0 0 0 0 0 0
289
- 12: xapi1: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT
290
- link/ether e8:39:35:c5:c8:50 brd ff:ff:ff:ff:ff:ff
291
- RX: bytes packets errors dropped overrun mcast
292
- 21468183 159866 0 0 0 0
293
- TX: bytes packets errors dropped carrier collsns
294
- 2052 6 0 0 0 0
295
- 13: fwdintf: <MULTICAST,NOARP,UP,LOWER_UP> mtu 1496 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 1000
296
- link/ether 00:00:00:00:00:0a brd ff:ff:ff:ff:ff:ff promiscuity 0
297
- RX: bytes packets errors dropped overrun mcast
298
- 0 0 0 0 0 0
299
- TX: bytes packets errors dropped carrier collsns
300
- 140 2 0 1 0 0
301
- 14: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1
302
- link/tunnel6 :: brd :: promiscuity 0
303
- ip6tnl ip6ip6 remote :: local :: encaplimit 0 hoplimit 0 tclass 0x00 flowlabel 0x00000 (flowinfo 0x00000000) addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
304
- RX: bytes packets errors dropped overrun mcast
305
- 0 0 0 0 0 0
306
- TX: bytes packets errors dropped carrier collsns
307
- 0 0 0 0 0 0
308
- EOM
309
- end
310
-
311
- let(:linux_arp_an) do
312
- <<~EOM
313
- ? (10.116.201.1) at fe:ff:ff:ff:ff:ff [ether] on eth0
314
- EOM
315
- end
316
-
317
- let(:linux_ip_neighbor_show) do
318
- <<~EOM
319
- 10.116.201.1 dev eth0 lladdr fe:ff:ff:ff:ff:ff REACHABLE
320
- EOM
321
- end
322
-
323
- let(:linux_ip_inet6_neighbor_show) do
324
- <<~EOM
325
- 1111:2222:3333:4444::1 dev eth0.11 lladdr 00:1c:0e:12:34:56 router REACHABLE
326
- fe80::21c:eff:fe12:3456 dev eth0.11 lladdr 00:1c:0e:30:28:00 router REACHABLE
327
- fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE
328
- EOM
329
- end
330
-
331
- let(:linux_ethtool) do
332
- <<~EOM
333
- Settings for eth0:
334
- Supported ports: [ FIBRE ]
335
- Supported link modes: 1000baseT/Full
336
- 10000baseT/Full
337
- Supported pause frame use: No
338
- Supports auto-negotiation: Yes
339
- Advertised link modes: 1000baseT/Full
340
- 10000baseT/Full
341
- Advertised pause frame use: No
342
- Advertised auto-negotiation: Yes
343
- Speed: 10000Mb/s
344
- Duplex: Full
345
- Port: FIBRE
346
- PHYAD: 0
347
- Transceiver: external
348
- Auto-negotiation: on
349
- Supports Wake-on: d
350
- Wake-on: d
351
- Current message level: 0x00000007 (7)
352
- drv probe link
353
- Link detected: yes
354
- EOM
355
- end
356
-
357
- let(:linux_ethtool_g) do
358
- <<~EOM
359
- Ring parameters for eth0:
360
- Pre-set maximums:
361
- RX: 8192
362
- RX Mini: 0
363
- RX Jumbo: 0
364
- TX: 8192
365
- Current hardware settings:
366
- RX: 8192
367
- RX Mini: 0
368
- RX Jumbo: 0
369
- TX: 8192
370
-
371
- EOM
372
- end
373
-
374
- before do
375
- allow(plugin).to receive(:collect_os).and_return(:linux)
376
-
377
- allow(plugin).to receive(:shell_out).with("ip addr").and_return(mock_shell_out(0, linux_ip_addr, ""))
378
- allow(plugin).to receive(:shell_out).with("ip -d -s link").and_return(mock_shell_out(0, linux_ip_link_s_d, ""))
379
- allow(plugin).to receive(:shell_out).with("ip -f inet neigh show").and_return(mock_shell_out(0, linux_ip_neighbor_show, ""))
380
- allow(plugin).to receive(:shell_out).with("ip -f inet6 neigh show").and_return(mock_shell_out(0, linux_ip_inet6_neighbor_show, ""))
381
- allow(plugin).to receive(:shell_out).with("ip -o -f inet route show table main").and_return(mock_shell_out(0, linux_ip_route, ""))
382
- allow(plugin).to receive(:shell_out).with("ip -o -f inet6 route show table main").and_return(mock_shell_out(0, linux_ip_route_inet6, ""))
383
-
384
- allow(plugin).to receive(:shell_out).with("route -n").and_return(mock_shell_out(0, linux_route_n, ""))
385
- allow(plugin).to receive(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, linux_ifconfig, ""))
386
- allow(plugin).to receive(:shell_out).with("arp -an").and_return(mock_shell_out(0, linux_arp_an, ""))
387
- allow(plugin).to receive(:shell_out).with(/ethtool -g/).and_return(mock_shell_out(0, linux_ethtool_g, ""))
388
- allow(plugin).to receive(:shell_out).with(/ethtool [^\-]/).and_return(mock_shell_out(0, linux_ethtool, ""))
389
- end
390
-
391
- describe "#interface_has_no_addresses_in_family?" do
392
- context "when interface has no addresses" do
393
- let(:iface) { {} }
394
-
395
- it "returns true" do
396
- expect(plugin.interface_has_no_addresses_in_family?(iface, "inet")).to eq(true)
397
- end
398
- end
399
-
400
- context "when an interface has no addresses in family" do
401
- let(:iface) { { addresses: { "1.2.3.4" => { "family" => "inet6" } } } }
402
-
403
- it "returns true" do
404
- expect(plugin.interface_has_no_addresses_in_family?(iface, "inet")).to eq(true)
405
- end
406
- end
407
-
408
- context "when an interface has addresses in family" do
409
- let(:iface) { { addresses: { "1.2.3.4" => { "family" => "inet" } } } }
410
-
411
- it "returns false" do
412
- expect(plugin.interface_has_no_addresses_in_family?(iface, "inet")).to eq(false)
413
- end
414
- end
415
- end
416
-
417
- describe "#interface_have_address?" do
418
- context "when interface has no addresses" do
419
- let(:iface) { {} }
420
-
421
- it "returns false" do
422
- expect(plugin.interface_have_address?(iface, "1.2.3.4")).to eq(false)
423
- end
424
- end
425
-
426
- context "when interface has a matching address" do
427
- let(:iface) { { addresses: { "1.2.3.4" => {} } } }
428
-
429
- it "returns true" do
430
- expect(plugin.interface_have_address?(iface, "1.2.3.4")).to eq(true)
431
- end
432
- end
433
-
434
- context "when interface does not have a matching address" do
435
- let(:iface) { { addresses: { "4.3.2.1" => {} } } }
436
-
437
- it "returns false" do
438
- expect(plugin.interface_have_address?(iface, "1.2.3.4")).to eq(false)
439
- end
440
- end
441
- end
442
-
443
- describe "#interface_address_not_link_level?" do
444
- context "when the address scope is link" do
445
- let(:iface) { { addresses: { "1.2.3.4" => { scope: "Link" } } } }
446
-
447
- it "returns false" do
448
- expect(plugin.interface_address_not_link_level?(iface, "1.2.3.4")).to eq(false)
449
- end
450
- end
451
-
452
- context "when the address scope is global" do
453
- let(:iface) { { addresses: { "1.2.3.4" => { scope: "Global" } } } }
454
-
455
- it "returns true" do
456
- expect(plugin.interface_address_not_link_level?(iface, "1.2.3.4")).to eq(true)
457
- end
458
- end
459
- end
460
-
461
- describe "#interface_valid_for_route?" do
462
- let(:iface) { double("iface") }
463
- let(:address) { "1.2.3.4" }
464
- let(:family) { "inet" }
465
-
466
- context "when interface has no addresses" do
467
- it "returns true" do
468
- expect(plugin).to receive(:interface_has_no_addresses_in_family?).with(iface, family).and_return(true)
469
- expect(plugin.interface_valid_for_route?(iface, address, family)).to eq(true)
470
- end
471
- end
472
-
473
- context "when interface has addresses" do
474
- before do
475
- expect(plugin).to receive(:interface_has_no_addresses_in_family?).with(iface, family).and_return(false)
476
- end
477
-
478
- context "when interface contains the address" do
479
- before do
480
- expect(plugin).to receive(:interface_have_address?).with(iface, address).and_return(true)
481
- end
482
-
483
- context "when interface address is not a link-level address" do
484
- it "returns true" do
485
- expect(plugin).to receive(:interface_address_not_link_level?).with(iface, address).and_return(true)
486
- expect(plugin.interface_valid_for_route?(iface, address, family)).to eq(true)
487
- end
488
- end
489
-
490
- context "when the interface address is a link-level address" do
491
- it "returns false" do
492
- expect(plugin).to receive(:interface_address_not_link_level?).with(iface, address).and_return(false)
493
- expect(plugin.interface_valid_for_route?(iface, address, family)).to eq(false)
494
- end
495
- end
496
- end
497
-
498
- context "when interface does not contain the address" do
499
- it "returns false" do
500
- expect(plugin).to receive(:interface_have_address?).with(iface, address).and_return(false)
501
- expect(plugin.interface_valid_for_route?(iface, address, family)).to eq(false)
502
- end
503
- end
504
- end
505
- end
506
-
507
- describe "#route_is_valid_default_route?" do
508
- context "when the route destination is default" do
509
- let(:route) { { destination: "default" } }
510
- let(:default_route) { double("default_route") }
511
-
512
- it "returns true" do
513
- expect(plugin.route_is_valid_default_route?(route, default_route)).to eq(true)
514
- end
515
- end
516
-
517
- context "when the route destination is not default" do
518
- let(:route) { { destination: "10.0.0.0/24" } }
519
-
520
- context "when the default route does not have a gateway" do
521
- let(:default_route) { {} }
522
-
523
- it "returns false" do
524
- expect(plugin.route_is_valid_default_route?(route, default_route)).to eq(false)
525
- end
526
- end
527
-
528
- context "when the gateway is within the destination" do
529
- let(:default_route) { { via: "10.0.0.1" } }
530
-
531
- it "returns true" do
532
- expect(plugin.route_is_valid_default_route?(route, default_route)).to eq(true)
533
- end
534
- end
535
-
536
- context "when the gateway is not within the destination" do
537
- let(:default_route) { { via: "20.0.0.1" } }
538
-
539
- it "returns false" do
540
- expect(plugin.route_is_valid_default_route?(route, default_route)).to eq(false)
541
- end
542
- end
543
- end
544
- end
545
-
546
- %w{ifconfig iproute2}.each do |network_method|
547
- describe "gathering IP layer address info via #{network_method}" do
548
- before do
549
- allow(plugin).to receive(:which).with("ip").and_return( network_method == "iproute2" ? "/sbin/ip" : false )
550
- allow(plugin).to receive(:which).with("ethtool").and_return( "/sbin/ethtool" )
551
- plugin.run
552
- end
553
-
554
- it "completes the run" do
555
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
556
- expect(plugin["network"]).not_to be_nil
557
- end
558
-
559
- it "detects the interfaces" do
560
- if network_method == "iproute2"
561
- expect(plugin["network"]["interfaces"].keys.sort).to eq(["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "eth3", "foo:veth0@eth0", "fwdintf", "ip6tnl0", "lo", "ovs-system", "tun0", "venet0", "venet0:0", "xapi1"])
562
- else
563
- expect(plugin["network"]["interfaces"].keys.sort).to eq(["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "eth3", "foo:veth0@eth0", "fwdintf", "lo", "ovs-system", "tun0", "venet0", "venet0:0", "xapi1"])
564
- end
565
- end
566
-
567
- it "detects the layer one details of an ethernet interface" do
568
- expect(plugin["network"]["interfaces"]["eth0"]["link_speed"]).to eq(10000)
569
- expect(plugin["network"]["interfaces"]["eth0"]["duplex"]).to eq("Full")
570
- expect(plugin["network"]["interfaces"]["eth0"]["port"]).to eq("FIBRE")
571
- expect(plugin["network"]["interfaces"]["eth0"]["transceiver"]).to eq("external")
572
- expect(plugin["network"]["interfaces"]["eth0"]["auto_negotiation"]).to eq("on")
573
- expect(plugin["network"]["interfaces"]["eth0"]["mdi_x"]).to be_nil
574
- expect(plugin["network"]["interfaces"]["eth0"]["ring_params"]["max_tx"]).to eq(8192)
575
- expect(plugin["network"]["interfaces"]["eth0"]["ring_params"]["max_rx"]).to eq(8192)
576
- expect(plugin["network"]["interfaces"]["eth0"]["ring_params"]["current_tx"]).to eq(8192)
577
- expect(plugin["network"]["interfaces"]["eth0"]["ring_params"]["current_rx"]).to eq(8192)
578
- end
579
-
580
- it "detects the ipv4 addresses of the ethernet interface" do
581
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"].keys).to include("10.116.201.76")
582
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"]["10.116.201.76"]["netmask"]).to eq("255.255.255.0")
583
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"]["10.116.201.76"]["broadcast"]).to eq("10.116.201.255")
584
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"]["10.116.201.76"]["family"]).to eq("inet")
585
- end
586
-
587
- it "detects the ipv4 addresses of an ethernet subinterface" do
588
- expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"].keys).to include("192.168.0.16")
589
- expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"]["192.168.0.16"]["netmask"]).to eq("255.255.255.0")
590
- expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"]["192.168.0.16"]["broadcast"]).to eq("192.168.0.255")
591
- expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"]["192.168.0.16"]["family"]).to eq("inet")
592
- end
593
-
594
- it "detects the ipv6 addresses of the ethernet interface" do
595
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"].keys).to include("fe80::1031:3dff:fe02:bea2")
596
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"]["fe80::1031:3dff:fe02:bea2"]["scope"]).to eq("Link")
597
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"]["fe80::1031:3dff:fe02:bea2"]["prefixlen"]).to eq("64")
598
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"]["fe80::1031:3dff:fe02:bea2"]["family"]).to eq("inet6")
599
- end
600
-
601
- it "detects the ipv6 addresses of an ethernet subinterface" do
602
- %w{ 1111:2222:3333:4444::2 1111:2222:3333:4444::3 }.each do |addr|
603
- expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"].keys).to include(addr)
604
- expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"][addr]["scope"]).to eq("Global")
605
- expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"][addr]["prefixlen"]).to eq("64")
606
- expect(plugin["network"]["interfaces"]["eth0.11"]["addresses"][addr]["family"]).to eq("inet6")
607
- end
608
- end
609
-
610
- it "detects the mac addresses of the ethernet interface" do
611
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"].keys).to include("12:31:3D:02:BE:A2")
612
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"]["12:31:3D:02:BE:A2"]["family"]).to eq("lladdr")
613
- end
614
-
615
- it "detects the encapsulation type of the ethernet interface" do
616
- expect(plugin["network"]["interfaces"]["eth0"]["encapsulation"]).to eq("Ethernet")
617
- end
618
-
619
- it "detects the flags of the ethernet interface" do
620
- if network_method == "ifconfig"
621
- expect(plugin["network"]["interfaces"]["eth0"]["flags"].sort).to eq(%w{BROADCAST MULTICAST RUNNING UP})
622
- else
623
- expect(plugin["network"]["interfaces"]["eth0"]["flags"].sort).to eq(%w{BROADCAST LOWER_UP MULTICAST UP})
624
- end
625
- end
626
-
627
- it "detects the number of the ethernet interface" do
628
- expect(plugin["network"]["interfaces"]["eth0"]["number"]).to eq("0")
629
- end
630
-
631
- it "detects the mtu of the ethernet interface" do
632
- expect(plugin["network"]["interfaces"]["eth0"]["mtu"]).to eq("1500")
633
- end
634
-
635
- it "detects the ipv4 addresses of the loopback interface" do
636
- expect(plugin["network"]["interfaces"]["lo"]["addresses"].keys).to include("127.0.0.1")
637
- expect(plugin["network"]["interfaces"]["lo"]["addresses"]["127.0.0.1"]["netmask"]).to eq("255.0.0.0")
638
- expect(plugin["network"]["interfaces"]["lo"]["addresses"]["127.0.0.1"]["family"]).to eq("inet")
639
- end
640
-
641
- it "detects the ipv6 addresses of the loopback interface" do
642
- expect(plugin["network"]["interfaces"]["lo"]["addresses"].keys).to include("::1")
643
- expect(plugin["network"]["interfaces"]["lo"]["addresses"]["::1"]["scope"]).to eq("Node")
644
- expect(plugin["network"]["interfaces"]["lo"]["addresses"]["::1"]["prefixlen"]).to eq("128")
645
- expect(plugin["network"]["interfaces"]["lo"]["addresses"]["::1"]["family"]).to eq("inet6")
646
- end
647
-
648
- it "detects the encapsulation type of the loopback interface" do
649
- expect(plugin["network"]["interfaces"]["lo"]["encapsulation"]).to eq("Loopback")
650
- end
651
-
652
- it "detects the flags of the ethernet interface" do
653
- if network_method == "ifconfig"
654
- expect(plugin["network"]["interfaces"]["lo"]["flags"].sort).to eq(%w{LOOPBACK RUNNING UP})
655
- else
656
- expect(plugin["network"]["interfaces"]["lo"]["flags"].sort).to eq(%w{LOOPBACK LOWER_UP UP})
657
- end
658
- end
659
-
660
- it "detects the mtu of the loopback interface" do
661
- expect(plugin["network"]["interfaces"]["lo"]["mtu"]).to eq("16436")
662
- end
663
-
664
- it "detects the arp entries" do
665
- expect(plugin["network"]["interfaces"]["eth0"]["arp"]["10.116.201.1"]).to eq("fe:ff:ff:ff:ff:ff")
666
- end
667
-
668
- if network_method == "iproute2"
669
- it "detects the tunnel information" do
670
- expect(plugin["network"]["interfaces"]["ip6tnl0"]["tunnel_info"]).to eq(
671
- {
672
- "proto" => "ip6ip6",
673
- "remote" => "::",
674
- "local" => "::",
675
- "encaplimit" => "0",
676
- "hoplimit" => "0",
677
- "tclass" => "0x00",
678
- "flowlabel" => "0x00000",
679
- "addrgenmode" => "eui64",
680
- "numtxqueues" => "1",
681
- "numrxqueues" => "1",
682
- "gso_max_size" => "65536",
683
- "gso_max_segs" => "65535",
684
- }
685
- )
686
- end
687
- end
688
- end
689
-
690
- describe "gathering interface counters via #{network_method}" do
691
- before do
692
- allow(plugin).to receive(:which).with("ip").and_return(network_method == "iproute2" ? "/sbin/ip" : false)
693
- allow(plugin).to receive(:which).with("ethtool").and_return("/sbin/ethtool")
694
- plugin.run
695
- end
696
-
697
- it "detects the ethernet counters" do
698
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["tx"]["bytes"]).to eq("691785313")
699
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["tx"]["packets"]).to eq("1919690")
700
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["tx"]["collisions"]).to eq("0")
701
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["tx"]["queuelen"]).to eq("1000")
702
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["tx"]["errors"]).to eq("0")
703
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["tx"]["carrier"]).to eq("0")
704
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["tx"]["drop"]).to eq("0")
705
-
706
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["rx"]["bytes"]).to eq("1392844460")
707
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["rx"]["packets"]).to eq("2659966")
708
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["rx"]["errors"]).to eq("0")
709
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["rx"]["overrun"]).to eq("0")
710
- expect(plugin["counters"]["network"]["interfaces"]["eth0"]["rx"]["drop"]).to eq("0")
711
- end
712
-
713
- it "detects the loopback counters" do
714
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["tx"]["bytes"]).to eq("35224")
715
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["tx"]["packets"]).to eq("524")
716
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["tx"]["collisions"]).to eq("0")
717
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["tx"]["errors"]).to eq("0")
718
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["tx"]["carrier"]).to eq("0")
719
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["tx"]["drop"]).to eq("0")
720
-
721
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["rx"]["bytes"]).to eq("35224")
722
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["rx"]["packets"]).to eq("524")
723
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["rx"]["errors"]).to eq("0")
724
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["rx"]["overrun"]).to eq("0")
725
- expect(plugin["counters"]["network"]["interfaces"]["lo"]["rx"]["drop"]).to eq("0")
726
- end
727
- end
728
-
729
- describe "setting the node's default IP address attribute with #{network_method}" do
730
- before do
731
- allow(plugin).to receive(:which).with("ip").and_return(network_method == "iproute2" ? "/sbin/ip" : false)
732
- allow(plugin).to receive(:which).with("ethtool").and_return("/sbin/ethtool")
733
- plugin.run
734
- end
735
-
736
- describe "without a subinterface" do
737
- it "finds the default interface by asking which iface has the default route" do
738
- expect(plugin["network"]["default_interface"]).to eq("eth0")
739
- end
740
-
741
- it "finds the default gateway by asking which iface has the default route" do
742
- expect(plugin["network"]["default_gateway"]).to eq("10.116.201.1")
743
- end
744
- end
745
-
746
- describe "with a link level default route" do
747
- let(:linux_ip_route) do
748
- <<~EOM
749
- 10.116.201.0/24 dev eth0 proto kernel
750
- default dev eth0 scope link
751
- EOM
752
- end
753
-
754
- let(:linux_route_n) do
755
- <<~EOM
756
- Kernel IP routing table
757
- Destination Gateway Genmask Flags Metric Ref Use Iface
758
- 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
759
- 0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 eth0
760
- EOM
761
- end
762
-
763
- before do
764
- plugin.run
765
- end
766
-
767
- it "finds the default interface by asking which iface has the default route" do
768
- expect(plugin["network"]["default_interface"]).to eq("eth0")
769
- end
770
-
771
- it "finds the default interface by asking which iface has the default route" do
772
- expect(plugin["network"]["default_gateway"]).to eq("0.0.0.0")
773
- end
774
- end
775
-
776
- describe "with a subinterface" do
777
- let(:linux_ip_route) do
778
- <<~EOM
779
- 192.168.0.0/24 dev eth0.11 proto kernel src 192.168.0.2
780
- default via 192.168.0.15 dev eth0.11
781
- EOM
782
- end
783
-
784
- let(:linux_route_n) do
785
- <<~EOM
786
- Kernel IP routing table
787
- Destination Gateway Genmask Flags Metric Ref Use Iface
788
- 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.11
789
- 0.0.0.0 192.168.0.15 0.0.0.0 UG 0 0 0 eth0.11
790
- EOM
791
- end
792
-
793
- before do
794
- plugin.run
795
- end
796
-
797
- it "finds the default interface by asking which iface has the default route" do
798
- expect(plugin["network"]["default_interface"]).to eq("eth0.11")
799
- end
800
-
801
- it "finds the default interface by asking which iface has the default route" do
802
- expect(plugin["network"]["default_gateway"]).to eq("192.168.0.15")
803
- end
804
- end
805
- end
806
- end
807
-
808
- describe "for newer network features using iproute2 only" do
809
- before do
810
- allow(plugin).to receive(:which).with("ip").and_return("/sbin/ip")
811
- allow(plugin).to receive(:which).with("ethtool").and_return( "/sbin/ethtool" )
812
- allow(File).to receive(:exist?).with("/proc/net/if_inet6").and_return(true) # ipv6 is enabled
813
- plugin.run
814
- end
815
-
816
- it "completes the run" do
817
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
818
- expect(plugin["network"]).not_to be_nil
819
- end
820
-
821
- it "finds the default inet6 interface if there's a inet6 default route" do
822
- expect(plugin["network"]["default_inet6_interface"]).to eq("eth0.11")
823
- end
824
-
825
- it "finds the default inet6 gateway if there's a inet6 default route" do
826
- expect(plugin["network"]["default_inet6_gateway"]).to eq("1111:2222:3333:4444::1")
827
- end
828
-
829
- it "finds inet6 neighbours" do
830
- expect(plugin["network"]["interfaces"]["eth0.11"]["neighbour_inet6"]["1111:2222:3333:4444::1"]).to eq("00:1c:0e:12:34:56")
831
- end
832
-
833
- it "detects the ipv4 addresses of an ethernet interface with a crazy name" do
834
- expect(plugin["network"]["interfaces"]["foo:veth0@eth0"]["addresses"].keys).to include("192.168.212.2")
835
- expect(plugin["network"]["interfaces"]["foo:veth0@eth0"]["addresses"]["192.168.212.2"]["netmask"]).to eq("255.255.255.0")
836
- expect(plugin["network"]["interfaces"]["foo:veth0@eth0"]["addresses"]["192.168.212.2"]["family"]).to eq("inet")
837
- end
838
-
839
- it "generates a fake interface for ip aliases for backward compatibility" do
840
- expect(plugin["network"]["interfaces"]["eth0:5"]["addresses"].keys).to include("192.168.5.1")
841
- expect(plugin["network"]["interfaces"]["eth0:5"]["addresses"]["192.168.5.1"]["netmask"]).to eq("255.255.255.0")
842
- expect(plugin["network"]["interfaces"]["eth0:5"]["addresses"]["192.168.5.1"]["family"]).to eq("inet")
843
- end
844
-
845
- it "adds the vlan information of an interface" do
846
- expect(plugin["network"]["interfaces"]["eth0.11"]["vlan"]["id"]).to eq("11")
847
- expect(plugin["network"]["interfaces"]["eth0.11"]["vlan"]["flags"]).to eq([ "REORDER_HDR" ])
848
- end
849
-
850
- it "adds the state of an interface" do
851
- expect(plugin["network"]["interfaces"]["eth0.11"]["state"]).to eq("up")
852
- end
853
-
854
- it "detects interfaces only visible via ip link" do
855
- expect(plugin["network"]["interfaces"]["eth3"]["state"]).to eq("up")
856
- end
857
-
858
- it "detects tags on v6 addresses of the ethernet interface" do
859
- expect(plugin["network"]["interfaces"]["eth0"]["addresses"]["2001:44b8:4160:8f00:a00:27ff:fe13:eacd"]["tags"]).to eq(["dynamic"])
860
- end
861
-
862
- describe "when IPv6 is disabled" do
863
- before do
864
- allow(File).to receive(:exist?).with("/proc/net/if_inet6").and_return(false)
865
- plugin.run
866
- end
867
-
868
- it "doesn't set ip6address" do
869
- expect(plugin["ip6address"]).to be_nil
870
- end
871
- end
872
-
873
- describe "when dealing with routes" do
874
- it "adds routes" do
875
- plugin.run
876
- expect(plugin["network"]["interfaces"]["eth0"]["routes"]).to include Mash.new( destination: "10.116.201.0/24", proto: "kernel", family: "inet" )
877
- expect(plugin["network"]["interfaces"]["eth0"]["routes"]).to include Mash.new( destination: "10.5.4.0/24", family: "inet", via: "10.5.4.1")
878
- expect(plugin["network"]["interfaces"]["eth0"]["routes"]).to include Mash.new( destination: "10.5.4.0/24", family: "inet", via: "10.5.4.2")
879
- expect(plugin["network"]["interfaces"]["foo:veth0@eth0"]["routes"]).to include Mash.new( destination: "192.168.212.0/24", proto: "kernel", src: "192.168.212.2", family: "inet" )
880
- expect(plugin["network"]["interfaces"]["eth0"]["routes"]).to include Mash.new( destination: "fe80::/64", metric: "256", proto: "kernel", family: "inet6" )
881
- expect(plugin["network"]["interfaces"]["eth0.11"]["routes"]).to include Mash.new( destination: "1111:2222:3333:4444::/64", metric: "1024", family: "inet6" )
882
- expect(plugin["network"]["interfaces"]["eth0.11"]["routes"]).to include Mash.new( destination: "default", via: "1111:2222:3333:4444::1", metric: "1024", family: "inet6")
883
- end
884
-
885
- describe "when there isn't a source field in route entries and no ipv6 default routes" do
886
- let(:linux_ip_route_inet6) do
887
- <<~EOM
888
- fe80::/64 dev eth0 proto kernel metric 256
889
- fe80::/64 dev eth0.11 proto kernel metric 256
890
- 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 expires 86023sec
891
- EOM
892
- end
893
-
894
- before do
895
- plugin.run
896
- end
897
-
898
- it "doesn't set ipaddress" do
899
- expect(plugin["ipaddress"]).to be nil
900
- end
901
-
902
- it "doesn't set macaddress" do
903
- expect(plugin["macaddress"]).to be nil
904
- end
905
-
906
- it "doesn't set ip6address" do
907
- expect(plugin["ip6address"]).to be nil
908
- end
909
- end
910
-
911
- describe "when there's a source field in the default route entry" do
912
- let(:linux_ip_route) do
913
- <<~EOM
914
- 10.116.201.0/24 dev eth0 proto kernel
915
- 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
916
- 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
917
- 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
918
- 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
919
- default via 10.116.201.1 dev eth0 src 10.116.201.76
920
- EOM
921
- end
922
-
923
- let(:linux_ip_route_inet6) do
924
- <<~EOM
925
- fe80::/64 dev eth0 proto kernel metric 256
926
- fe80::/64 dev eth0.11 proto kernel metric 256
927
- 1111:2222:3333:4444::/64 dev eth0.11 metric 1024
928
- default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
929
- EOM
930
- end
931
-
932
- before do
933
- plugin.run
934
- end
935
-
936
- it "completes the run" do
937
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
938
- expect(plugin["network"]).not_to be_nil
939
- end
940
-
941
- it "sets ipaddress" do
942
- expect(plugin["ipaddress"]).to eq("10.116.201.76")
943
- end
944
-
945
- it "sets ip6address" do
946
- expect(plugin["ip6address"]).to eq("1111:2222:3333:4444::3")
947
- end
948
- end
949
-
950
- describe "when there're several default routes" do
951
- let(:linux_ip_route) do
952
- <<~EOM
953
- 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
954
- 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
955
- 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
956
- 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
957
- 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
958
- default via 10.116.201.1 dev eth0 metric 10
959
- default via 10.116.201.254 dev eth0 metric 9
960
- EOM
961
- end
962
-
963
- let(:linux_ip_route_inet6) do
964
- <<~EOM
965
- fe80::/64 dev eth0 proto kernel metric 256
966
- fe80::/64 dev eth0.11 proto kernel metric 256
967
- 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
968
- default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
969
- default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023
970
- EOM
971
- end
972
-
973
- before do
974
- plugin.run
975
- end
976
-
977
- it "completes the run" do
978
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
979
- expect(plugin["network"]).not_to be_nil
980
- end
981
-
982
- it "sets default ipv4 interface and gateway" do
983
- expect(plugin["network"]["default_interface"]).to eq("eth0")
984
- expect(plugin["network"]["default_gateway"]).to eq("10.116.201.254")
985
- end
986
-
987
- it "sets default ipv6 interface and gateway" do
988
- expect(plugin["network"]["default_inet6_interface"]).to eq("eth0.11")
989
- expect(plugin["network"]["default_inet6_gateway"]).to eq("1111:2222:3333:4444::ffff")
990
- end
991
- end
992
-
993
- describe "when there're a mixed setup of routes that could be used to set ipaddress" do
994
- let(:linux_ip_route) do
995
- <<~EOM
996
- 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
997
- 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
998
- 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
999
- 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
1000
- 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
1001
- default via 10.116.201.1 dev eth0 metric 10
1002
- default via 10.116.201.254 dev eth0 metric 9 src 10.116.201.74
1003
- EOM
1004
- end
1005
-
1006
- let(:linux_ip_route_inet6) do
1007
- <<~EOM
1008
- fe80::/64 dev eth0 proto kernel metric 256
1009
- fe80::/64 dev eth0.11 proto kernel metric 256
1010
- 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
1011
- default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
1012
- default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023 src 1111:2222:3333:4444::2
1013
- EOM
1014
- end
1015
-
1016
- before do
1017
- plugin.run
1018
- end
1019
-
1020
- it "completes the run" do
1021
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
1022
- expect(plugin["network"]).not_to be_nil
1023
- end
1024
-
1025
- it "sets ipaddress" do
1026
- expect(plugin["ipaddress"]).to eq("10.116.201.74")
1027
- end
1028
-
1029
- it "sets ip6address" do
1030
- expect(plugin["ip6address"]).to eq("1111:2222:3333:4444::2")
1031
- end
1032
- end
1033
-
1034
- describe "when there's a source field in a local route entry but it isnt in the default route" do
1035
- let(:linux_ip_route) do
1036
- <<~EOM
1037
- 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
1038
- 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
1039
- 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
1040
- 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
1041
- 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
1042
- default via 10.116.201.1 dev eth0
1043
- EOM
1044
- end
1045
-
1046
- let(:linux_ip_route_inet6) do
1047
- <<~EOM
1048
- fe80::/64 dev eth0 proto kernel metric 256
1049
- fe80::/64 dev eth0.11 proto kernel metric 256
1050
- 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
1051
- default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
1052
- EOM
1053
- end
1054
-
1055
- it "completes the run" do
1056
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
1057
- plugin.run
1058
- expect(plugin["network"]).not_to be_nil
1059
- end
1060
-
1061
- it "sets ipaddress" do
1062
- plugin.run
1063
- expect(plugin["ipaddress"]).to eq("10.116.201.76")
1064
- end
1065
-
1066
- # without a source address on the default route we cannot pick the an ipv6 address from the interface
1067
- # In the future an RFC6724 compliant process should choose ip6address in the network plugin
1068
- it "does not set ip6address" do
1069
- plugin.run
1070
- expect(plugin["ip6address"]).to eq(nil)
1071
- end
1072
-
1073
- context "with only ipv6 routes" do
1074
- let(:linux_ip_route) { "" }
1075
-
1076
- it "sets macaddress to the mac address of the ip6 default interface" do
1077
- expect(plugin["macaddress"]).to eq("00:AA:BB:CC:DD:EE")
1078
- end
1079
- end
1080
-
1081
- describe "when about to set macaddress" do
1082
- it "sets macaddress" do
1083
- plugin.run
1084
- expect(plugin["macaddress"]).to eq("12:31:3D:02:BE:A2")
1085
- end
1086
-
1087
- context "when then ipv4 interface has the NOARP flag and no ipv6 routes exist" do
1088
- let(:linux_ip_route) do
1089
- <<~EOM
1090
- 10.118.19.1 dev tun0 proto kernel src 10.118.19.39
1091
- default via 172.16.19.1 dev tun0
1092
- EOM
1093
- end
1094
- let(:linux_ip_route_inet6) { "" }
1095
-
1096
- it "completes the run" do
1097
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
1098
- plugin.run
1099
- expect(plugin["network"]).not_to be_nil
1100
- end
1101
-
1102
- it "doesn't set macaddress" do
1103
- plugin.run
1104
- expect(plugin["macaddress"]).to be_nil
1105
- end
1106
- end
1107
- end
1108
- end
1109
-
1110
- describe "with a link level default route" do
1111
- let(:linux_ip_route) do
1112
- <<~EOM
1113
- default dev venet0 scope link
1114
- EOM
1115
- end
1116
-
1117
- before do
1118
- plugin.run
1119
- end
1120
-
1121
- it "completes the run" do
1122
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
1123
- expect(plugin["network"]).not_to be_nil
1124
- end
1125
-
1126
- it "doesn't set ipaddress" do
1127
- expect(plugin["ipaddress"]).to be_nil
1128
- end
1129
- end
1130
-
1131
- describe "with a link level default route to an unaddressed int" do
1132
- let(:linux_ip_route) do
1133
- <<~EOM
1134
- default dev eth3 scope link
1135
- EOM
1136
- end
1137
-
1138
- before do
1139
- plugin.run
1140
- end
1141
-
1142
- it "completes the run" do
1143
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
1144
- expect(plugin["network"]).not_to be_nil
1145
- end
1146
-
1147
- it "sets default_interface" do
1148
- expect(plugin["network"]["default_interface"]).to eq("eth3")
1149
- end
1150
-
1151
- it "doesn't set ipaddress" do
1152
- expect(plugin["ipaddress"]).to be_nil
1153
- end
1154
- end
1155
-
1156
- describe "with a link level default route with a source" do
1157
- let(:linux_ip_route) do
1158
- <<~EOM
1159
- default dev fwdintf scope link src 2.2.2.2
1160
- EOM
1161
- end
1162
-
1163
- before do
1164
- plugin.run
1165
- end
1166
-
1167
- it "completes the run" do
1168
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
1169
- expect(plugin["network"]).not_to be_nil
1170
- end
1171
-
1172
- it "sets default_interface" do
1173
- expect(plugin["network"]["default_interface"]).to eq("fwdintf")
1174
- end
1175
-
1176
- it "sets ipaddress" do
1177
- expect(plugin["ipaddress"]).to eq("2.2.2.2")
1178
- end
1179
- end
1180
-
1181
- describe "when not having a global scope ipv6 address" do
1182
- let(:linux_ip_route_inet6) do
1183
- <<~EOM
1184
- fe80::/64 dev eth0 proto kernel metric 256
1185
- default via fe80::21c:eff:fe12:3456 dev eth0.153 src fe80::2e0:81ff:fe2b:48e7 metric 1024
1186
- EOM
1187
- end
1188
-
1189
- before do
1190
- plugin.run
1191
- end
1192
-
1193
- it "completes the run" do
1194
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
1195
- expect(plugin["network"]).not_to be_nil
1196
- end
1197
-
1198
- it "doesn't set ip6address" do
1199
- expect(plugin["ip6address"]).to be_nil
1200
- end
1201
-
1202
- end
1203
-
1204
- describe "with no default route" do
1205
- let(:linux_ip_route) do
1206
- <<~EOM
1207
- 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
1208
- 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
1209
- 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
1210
- 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
1211
- 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
1212
- EOM
1213
- end
1214
-
1215
- let(:linux_ip_route_inet6) do
1216
- <<~EOM
1217
- fe80::/64 dev eth0 proto kernel metric 256
1218
- fe80::/64 dev eth0.11 proto kernel metric 256
1219
- 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
1220
- EOM
1221
- end
1222
-
1223
- before do
1224
- plugin.run
1225
- end
1226
-
1227
- it "completes the run" do
1228
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
1229
- expect(plugin["network"]).not_to be_nil
1230
- end
1231
-
1232
- it "doesn't set ipaddress" do
1233
- expect(plugin["ipaddress"]).to be_nil
1234
- end
1235
-
1236
- it "doesn't set ip6address" do
1237
- expect(plugin["ip6address"]).to be_nil
1238
- end
1239
- end
1240
-
1241
- describe "with openvz setup" do
1242
- let(:linux_ip_route) { "default dev venet0 scope link" }
1243
- let(:linux_ip_addr) do
1244
- <<~EOM
1245
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
1246
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
1247
- inet 127.0.0.1/8 scope host lo
1248
- inet6 ::1/128 scope host
1249
- valid_lft forever preferred_lft forever
1250
- 2: venet0: <BROADCAST,POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
1251
- link/void
1252
- inet 127.0.0.2/32 scope host venet0
1253
- inet 10.116.201.76/24 brd 10.116.201.255 scope global venet0:0
1254
- inet6 2001:44b8:4160:8f00:a00:27ff:fe13:eacd/64 scope global dynamic
1255
- valid_lft 6128sec preferred_lft 2526sec
1256
- EOM
1257
- end
1258
- # We don't have the corresponding ipv6 data for these tests
1259
- let(:linux_ip_route_inet6) { "" }
1260
- let(:linux_ip_inet6_neighbor_show) { "" }
1261
-
1262
- before do
1263
- allow(plugin).to receive(:is_openvz?).and_return true
1264
- allow(plugin).to receive(:is_openvz_host?).and_return false
1265
- plugin.run
1266
- end
1267
-
1268
- it "completes the run" do
1269
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
1270
- expect(plugin["network"]).not_to be_nil
1271
- end
1272
-
1273
- it "sets default ipv4 interface and gateway" do
1274
- expect(plugin["network"]["default_interface"]).to eq("venet0:0")
1275
- expect(plugin["network"]["default_gateway"]).to eq("0.0.0.0")
1276
- end
1277
-
1278
- it "sets correct routing information" do
1279
- expect(plugin["network"]["interfaces"]["venet0:0"]["routes"]).to eq([Mash.new( destination: "default", family: "inet", scope: "link" )])
1280
- end
1281
-
1282
- it "sets correct address information" do
1283
- expect(plugin["network"]["interfaces"]["venet0:0"]["addresses"]).to eq("10.116.201.76" => Mash.new(family: "inet", prefixlen: "24", netmask: "255.255.255.0", broadcast: "10.116.201.255", scope: "Global"))
1284
- end
1285
- end
1286
-
1287
- describe "with irrelevant routes (container setups)" do
1288
- let(:linux_ip_route) do
1289
- <<~EOM
1290
- 10.116.201.0/26 dev eth0 proto kernel src 10.116.201.39
1291
- 10.116.201.0/26 dev if4 proto kernel src 10.116.201.45
1292
- 10.118.19.0/26 dev eth0 proto kernel src 10.118.19.39
1293
- 10.118.19.0/26 dev if5 proto kernel src 10.118.19.45
1294
- default via 10.116.201.1 dev eth0 src 10.116.201.99
1295
- EOM
1296
- end
1297
-
1298
- let(:linux_ip_route_inet6) do
1299
- <<~EOM
1300
- fe80::/64 dev eth0 proto kernel metric 256
1301
- fe80::/64 dev eth0.11 proto kernel metric 256
1302
- 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::FFFF:2
1303
- default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
1304
- EOM
1305
- end
1306
-
1307
- before do
1308
- plugin.run
1309
- end
1310
-
1311
- it "completes the run" do
1312
- expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
1313
- expect(plugin["network"]).not_to be_nil
1314
- end
1315
-
1316
- it "doesn't add bogus routes" do
1317
- expect(plugin["network"]["interfaces"]["eth0"]["routes"]).not_to include Mash.new( destination: "10.116.201.0/26", proto: "kernel", family: "inet", via: "10.116.201.39" )
1318
- expect(plugin["network"]["interfaces"]["eth0"]["routes"]).not_to include Mash.new( destination: "10.118.19.0/26", proto: "kernel", family: "inet", via: "10.118.19.39" )
1319
- expect(plugin["network"]["interfaces"]["eth0"]["routes"]).not_to include Mash.new( destination: "1111:2222:3333:4444::/64", family: "inet6", metric: "1024" )
1320
- end
1321
-
1322
- it "doesn't set ipaddress" do
1323
- expect(plugin["ipaddress"]).to be_nil
1324
- end
1325
-
1326
- it "doesn't set ip6address" do
1327
- expect(plugin["ip6address"]).to be_nil
1328
- end
1329
- end
1330
-
1331
- # This should never happen in the real world.
1332
- describe "when encountering a surprise interface" do
1333
- let(:linux_ip_route) do
1334
- <<~EOM
1335
- 192.168.122.0/24 dev virbr0 proto kernel src 192.168.122.1
1336
- EOM
1337
- end
1338
-
1339
- it "logs a message and skips previously unseen interfaces in 'ip route show'" do
1340
- expect(plugin.logger).to receive(:trace).with(/Skipping previously unseen interface from 'ip route show': virbr0/).once
1341
- allow(plugin.logger).to receive(:trace) # Catches the 'Loading plugin network' type messages
1342
- plugin.run
1343
- end
1344
- end
1345
-
1346
- describe "when running with ip version ss131122" do
1347
- let(:linux_ip_link_s_d) do
1348
- <<~EOM
1349
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN mode DEFAULT group default
1350
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0
1351
- RX: bytes packets errors dropped overrun mcast
1352
- 35224 524 0 0 0 0
1353
- TX: bytes packets errors dropped carrier collsns
1354
- 35224 524 0 0 0 0
1355
- 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
1356
- link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff promiscuity 0
1357
- RX: bytes packets errors dropped overrun mcast
1358
- 1392844460 2659966 0 0 0 0
1359
- TX: bytes packets errors dropped carrier collsns
1360
- 691785313 1919690 0 0 0 0
1361
- 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
1362
- link/ether 00:0c:29:41:71:45 brd ff:ff:ff:ff:ff:ff promiscuity 0
1363
- vlan protocol 802.1Q id 11 <REORDER_HDR>
1364
- RX: bytes packets errors dropped overrun mcast
1365
- 0 0 0 0 0 0
1366
- TX: bytes packets errors dropped carrier collsns
1367
- 0 0 0 0 0 0
1368
- 4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 100
1369
- link/none promiscuity 0
1370
- RX: bytes packets errors dropped overrun mcast
1371
- 1392844460 2659966 0 0 0 0
1372
- TX: bytes packets errors dropped carrier collsns
1373
- 691785313 1919690 0 0 0 0
1374
- 5: venet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
1375
- link/void promiscuity 0
1376
- RX: bytes packets errors dropped overrun mcast
1377
- 1392844460 2659966 0 0 0 0
1378
- TX: bytes packets errors dropped carrier collsns
1379
- 691785313 1919690 0 0 0 0
1380
- EOM
1381
- end
1382
-
1383
- it "adds the vlan information of an interface" do
1384
- plugin.run
1385
- expect(plugin["network"]["interfaces"]["eth0.11"]["vlan"]["id"]).to eq("11")
1386
- expect(plugin["network"]["interfaces"]["eth0.11"]["vlan"]["protocol"]).to eq("802.1Q")
1387
- expect(plugin["network"]["interfaces"]["eth0.11"]["vlan"]["flags"]).to eq([ "REORDER_HDR" ])
1388
- end
1389
- end
1390
- end
1391
- end
1392
- end