skeleton: v1.0-stable: Read mac from u-boot instead of net settings

The system mac should be read from u-boot, not from the network
settings, since the network settings one can be the random mac
set by the system, and if the random mac happens to have the
locally managed bit turned on, it'll prevent the mac from vpd
from being written into the system.

Fixes openbmc/openbmc#627

Change-Id: I13df59b210f43632547a8a257ccb5575162c5296
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/pyinventorymgr/sync_inventory_items.py b/pyinventorymgr/sync_inventory_items.py
index 8f265ab..03201e4 100644
--- a/pyinventorymgr/sync_inventory_items.py
+++ b/pyinventorymgr/sync_inventory_items.py
@@ -55,11 +55,14 @@
     return value
 
 
-# Get the value of the mac on the system without ':' separators
+# Get the value of the mac on the system (from u-boot) without ':' separators
 def get_sys_mac(obj):
     sys_mac = ''
-    dbus_method = obj.get_dbus_method("GetHwAddress", NET_DBUS_NAME)
-    sys_mac = dbus_method("eth0")
+    try:
+        sys_mac = subprocess.check_output(["fw_printenv", "-n", "ethaddr"])
+    except:
+        # Handle when mac does not exist in u-boot
+        return sys_mac
     sys_mac = sys_mac.replace(":", "")
     return sys_mac
 
@@ -68,8 +71,12 @@
 # MAC if the system MAC is not locally administered because this means
 # the system admin has purposely set the MAC
 def sync_mac(obj, inv_mac, sys_mac):
-    # Convert sys MAC to int to perform bitwise '&'
-    int_sys_mac = int(sys_mac, 16)
+    if sys_mac:
+        # Convert sys MAC to int to perform bitwise '&'
+        int_sys_mac = int(sys_mac, 16)
+    else:
+        # Set mac to 0 for when u-boot mac is not present
+        int_sys_mac = 0
     if not int_sys_mac & MAC_LOCALLY_ADMIN_MASK:
         # Sys MAC is not locally administered, go replace it with inv value
         # Add the ':' separators