meta-google: gbmc-ncsi-config: Support migrating old configs

Sometimes we have machines that switch between interface names when
upgrading versions, we want to keep the configs to the best of our
ability when migrating forward.

Change-Id: I58fb962b19431114dc342a3252ce2f834c160194
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-old.service.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-old.service.in
new file mode 100644
index 0000000..dceeea1
--- /dev/null
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-old.service.in
@@ -0,0 +1,10 @@
+[Unit]
+Before=systemd-networkd.service
+ConditionFileNotEmpty=/etc/systemd/network/00-bmc-@OLD_IF@.network
+
+[Service]
+Type=oneshot
+ExecStart=mv -v /etc/systemd/network/00-bmc-@OLD_IF@.network /etc/systemd/network/00-bmc-@NCSI_IF@.network
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-google/recipes-google/ncsi/gbmc-ncsi-config.bb b/meta-google/recipes-google/ncsi/gbmc-ncsi-config.bb
index 3ae1c72..cb547b1 100644
--- a/meta-google/recipes-google/ncsi/gbmc-ncsi-config.bb
+++ b/meta-google/recipes-google/ncsi/gbmc-ncsi-config.bb
@@ -5,6 +5,8 @@
 
 inherit systemd
 
+GBMC_NCSI_IF_OLD ??= ""
+
 SRC_URI += " \
   file://-bmc-gbmcbrncsidhcp.netdev \
   file://-bmc-gbmcbrncsidhcp.network \
@@ -23,6 +25,7 @@
   file://gbmc-ncsi-set-nicenabled.service.in \
   file://gbmc-ncsi-alias.service.in \
   file://50-gbmc-ncsi-clear-ip.sh.in \
+  file://gbmc-ncsi-old.service.in \
   "
 
 S = "${WORKDIR}"
@@ -50,6 +53,7 @@
   gbmc-ncsi-sslh.socket \
   gbmc-ncsi-set-nicenabled.service \
   gbmc-ncsi-ip-from-ra.service \
+  ${@'' if d.getVar('GBMC_NCSI_IF_OLD') == '' else 'gbmc-ncsi-old.service'} \
   "
 
 do_install:append() {
@@ -128,6 +132,11 @@
   sed "s,@NCSI_IF@,$if_name,g" ${WORKDIR}/gbmc-ncsi-dhcrelay.service.in \
     >${D}${systemd_system_unitdir}/gbmc-ncsi-dhcrelay.service
 
+  if [ -n "${GBMC_NCSI_IF_OLD}" ]; then
+    sed -e "s,@NCSI_IF@,$if_name,g" -e "s,@OLD_IF@,${GBMC_NCSI_IF_OLD},g" ${WORKDIR}/gbmc-ncsi-old.service.in \
+      >${D}${systemd_system_unitdir}/gbmc-ncsi-old.service
+  fi
+
   sed "s,@NCSI_IF@,$if_name,g" ${WORKDIR}/gbmc-ncsi-ip-from-ra.service.in \
     >${WORKDIR}/gbmc-ncsi-ip-from-ra.service
   install -m0644 ${WORKDIR}/gbmc-ncsi-ip-from-ra.service ${D}${systemd_system_unitdir}