Browse Source

Fix post-deployment pxe interface detection

W/o this fix node do not respond with proper PUT for pxe interface
as the pxe interface gets plugged into br-fw-admin bridge and
it is not reported as pxe-related one.

We should check if the interface is a part of bond and/or bridge
configuration and respond correctly.

Change-Id: Ifc1c396b0945fc5a42165b969b6924dcff5975b2
Closes-bug: #1581517
Vladimir Kuklin 2 years ago
parent
commit
5fa721206b
1 changed files with 55 additions and 7 deletions
  1. 55
    7
      agent

+ 55
- 7
agent View File

@@ -329,6 +329,59 @@ class NodeAgent
329 329
     nil
330 330
   end
331 331
 
332
+  def _is_in_bond(iface_name)
333
+    File.exist? "/sys/class/net/#{iface_name}/master" rescue False
334
+  end
335
+
336
+  def _is_in_bridge(iface_name)
337
+    File.exist? "/sys/class/net/#{iface_name}/brport" rescue False
338
+  end
339
+
340
+  def _get_iface_bridge_name(iface_name)
341
+    File.basename(File.readlink("/sys/class/net/#{iface_name}/brport/bridge"))
342
+  end
343
+
344
+  def _get_iface_bond_name(iface_name)
345
+    File.basename(File.readlink("/sys/class/net/#{iface_name}/master"))
346
+  end
347
+
348
+  def _get_interface_mac(iface_name, swaddr)
349
+    # Get original mac excluding case with empty EEPROM data
350
+    mac = "00:00:00:00:00:00"
351
+    # It is a virtual device, lets read address file in sysfs
352
+    if File.exist? "/sys/devices/virtual/net/#{iface_name}"
353
+      File.open("/sys/devices/virtual/net/#{iface_name}/address") do
354
+      |file|
355
+        mac = file.readlines[0].chomp.downcase
356
+      end
357
+      return mac
358
+    end
359
+    # It is not a virtual device, lets ask ethtool first
360
+    perm_addr = `ethtool -P #{iface_name}`
361
+    begin
362
+      re = eval '/(?<=Permanent address: )(?!00(:00){5}).+/'
363
+    rescue SyntaxError
364
+      re = perm_addr.match(/(00(:00){5})+/).nil? ? /[0-9a-f]+(:[0-9a-f]+){5}$/ : nil
365
+    end
366
+    mac = perm_addr.match(re)[0] rescue swaddr
367
+    mac.downcase
368
+  end
369
+
370
+  def _get_parent_interface(iface_name)
371
+    if _is_in_bond(iface_name)
372
+      bond_name = _get_iface_bond_name(iface_name)
373
+      if _is_in_bridge(bond_name)
374
+        return _get_iface_bridge_name(bond_name)
375
+      else
376
+        return bond_name
377
+      end
378
+    elsif _is_in_bridge(iface_name)
379
+      return _get_iface_bridge_name(iface_name)
380
+    else
381
+      iface_name
382
+    end
383
+  end
384
+
332 385
   def _detailed
333 386
     detailed_meta = {
334 387
       :system => _system_info,
@@ -366,13 +419,8 @@ class NodeAgent
366 419
           if (addrinfo[:family] rescue nil) =~ /lladdr/
367 420
             # Get original mac excluding case with empty EEPROM data
368 421
             perm_addr = `ethtool -P #{int}`
369
-            begin
370
-              re = eval '/(?<=Permanent address: )(?!00(:00){5}).+/'
371
-            rescue SyntaxError
372
-              re = perm_addr.match(/(00(:00){5})+/).nil? ? /[0-9a-f]+(:[0-9a-f]+){5}$/ : nil
373
-            end
374
-            int_meta[:mac] = perm_addr.match(re)[0] rescue addr
375
-            int_meta[:pxe] = admin_mac == int_meta[:mac]
422
+            int_meta[:mac] = _get_interface_mac(int_meta[:name], addr)
423
+            int_meta[:pxe] = _get_interface_mac(_get_parent_interface(int_meta[:name]), addr) == admin_mac.downcase
376 424
             begin
377 425
               int_info = Rethtool::InterfaceSettings.new(int)
378 426
               int_meta[:driver] = int_info.driver

Loading…
Cancel
Save