obmc-phosphor-systemd: allow systemd unit from repo

If a recipe inherits obmc-phosphor-systemd, all the systemd units
defined in the recipe shall exist in the code tree, otherwise it reports
"Did not find unit file" error.

This commit changes the behavior, and do not report the error if a unit
does not exist in code tree. This allows the system unit to be installed
from repo, as long as the repo does install the systemd unit to expected
path.

Tested: Verify the below case passes the build and the unit is installed
        correctly in the built image:
           * Put a systemd unit in repo;
           * In repo, install the unit into /lib/systemd/system
           * The repo's recipe defines SYSTEMD_SERVICE_${PN} without
             putting the unit in openbmc tree
        And verify if the systemd unit in repo is not installed, the
        build fails due to missing the unit.

Change-Id: I41842798dc93a2c4fa4b6ec212554487a941b9bf
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/classes/obmc-phosphor-systemd.bbclass b/classes/obmc-phosphor-systemd.bbclass
index 3a3234f..e892302 100644
--- a/classes/obmc-phosphor-systemd.bbclass
+++ b/classes/obmc-phosphor-systemd.bbclass
@@ -110,7 +110,9 @@
         searchpaths = d.getVar('FILESPATH', True)
         path = bb.utils.which(searchpaths, '%s' % unit.name)
         if not os.path.isfile(path):
-            bb.fatal('Did not find unit file "%s"' % unit.name)
+            # Unit does not exist in tree. Allow it to install from repo.
+            # Return False here to indicate it does not exist.
+            return False
 
         parser = systemd_parse_unit(d, path)
         inhibit = listvar_to_list(d, 'INHIBIT_SYSTEMD_RESTART_POLICY_WARNING')
@@ -120,6 +122,7 @@
                 not parser.has_option('Service', 'Restart'):
             bb.warn('Systemd unit \'%s\' does not '
                 'have a restart policy defined.' % unit.name)
+        return True
 
 
     def add_default_subs(d, file):
@@ -134,7 +137,12 @@
                 '%s:%s:%s' % (x, d.getVar(x, True), file))
 
 
-    def add_sd_unit(d, unit, pkg):
+    def add_sd_unit(d, unit, pkg, unit_exist):
+        # Do not add unit if it does not exist in tree.
+        # It will be installed from repo.
+        if not unit_exist:
+            return
+
         name = unit.name
         unit_dir = d.getVar('systemd_system_unitdir', True)
         set_append(d, 'SRC_URI', 'file://%s' % name)
@@ -216,8 +224,8 @@
         svc = [x for x in svc if not x.is_instance]
 
         for unit in tmpl + svc:
-            check_sd_unit(d, unit)
-            add_sd_unit(d, unit, pkg)
+            unit_exist = check_sd_unit(d, unit)
+            add_sd_unit(d, unit, pkg, unit_exist)
             add_sd_user(d, unit.name, pkg)
         for name in listvar_to_list(d, 'SYSTEMD_ENVIRONMENT_FILE_%s' % pkg):
             add_env_file(d, name, pkg)