Do not install server files on DUT

For files that are only used on Umpire server, let's not install them on
DUTs. This is needed to fit the factory toolkit into devices with
limited disk space.

BUG=chrome-os-partner:32341
TEST=Install toolkit on a test image and check the resulting image.

Change-Id: I5161c0dfaf632fa1252316ff47cbb28b0c748425
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/221413
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
diff --git a/py/toolkit/installer.py b/py/toolkit/installer.py
index 53980f7..43801a1 100755
--- a/py/toolkit/installer.py
+++ b/py/toolkit/installer.py
@@ -84,6 +84,18 @@
 # Override this for unit testing.
 _in_cros_device = utils.in_cros_device
 
+SERVER_FILE_MASK = [
+    # Exclude Umpire server but keep Umpire client
+    '--include', 'py/umpire/__init__.*',
+    '--include', 'py/umpire/common.*',
+    '--include', 'py/umpire/client',
+    '--include', 'py/umpire/client/**',
+    '--exclude', 'py/umpire/**',
+
+    # Lumberjack is only used on Umpire server
+    '--exclude', 'py/lumberjack'
+]
+
 
 class FactoryToolkitInstaller():
   """Factory toolkit installer.
@@ -212,8 +224,9 @@
           Spawn(['chmod', '-R', 'go+rX', src],
                 sudo=True, log=True, check_call=True)
         print '***   %s -> %s' % (src, dest)
-        Spawn(['rsync', '-a', '--force', src + '/', dest],
-              sudo=self._sudo, log=True, check_output=True)
+        Spawn(['rsync', '-a', '--force', ] + SERVER_FILE_MASK +
+              [src + '/', dest], sudo=self._sudo, log=True,
+              check_output=True, cwd=src)
       finally:
         # Need to change the source directory back to the original user, or the
         # script in makeself will fail to remove the temporary source directory.
diff --git a/py/toolkit/installer_unittest.py b/py/toolkit/installer_unittest.py
index bca1db7..1699f98 100755
--- a/py/toolkit/installer_unittest.py
+++ b/py/toolkit/installer_unittest.py
@@ -8,6 +8,7 @@
 """Unittest for installer.py."""
 
 
+from __future__ import print_function
 import factory_common  # pylint: disable=W0611
 import logging
 import os
@@ -20,14 +21,25 @@
 
 class ToolkitInstallerTest(unittest.TestCase):
   """Test factory toolkit installer."""
+  FILES = [
+      ('usr/local/file1', 'install me!'),
+      ('var/log1', 'I am a log file!'),
+      ('usr/local/factory/py/umpire/__init__.py', 'This goes to DUT!'),
+      ('usr/local/factory/py/umpire/client/umpire_client.py',
+       'This goes to DUT, too!'),
+      ('usr/local/factory/py/umpire/archiver.py',
+       'I only run on Umpire server!'),
+  ]
+
   def setUp(self):
     self.src = tempfile.mkdtemp(prefix='ToolkitInstallerTest.')
     os.makedirs(os.path.join(self.src, 'usr/local/factory/init'))
     os.makedirs(os.path.join(self.src, 'var/factory/state'))
-    with open(os.path.join(self.src, 'usr/local', 'file1'), 'w') as f:
-      f.write('install me!')
-    with open(os.path.join(self.src, 'var', 'log1'), 'w') as f:
-      f.write('I am a log file!')
+    os.makedirs(os.path.join(self.src, 'usr/local/factory/py/umpire/client'))
+
+    for install_file in self.FILES:
+      with open(os.path.join(self.src, install_file[0]), 'w') as f:
+        f.write(install_file[1])
 
     self.dest = tempfile.mkdtemp(prefix='ToolkitInstallerTest.')
     self._installer = None
@@ -84,6 +96,13 @@
         os.path.join(self.dest, 'usr/local/factory/init/run_goofy_device')))
     self.assertEquals('../factory/bin/gooftool',
         os.readlink(os.path.join(self.dest, 'usr/local/bin/gooftool')))
+    self.assertTrue(os.path.exists(
+        os.path.join(self.dest, 'usr/local/factory/py/umpire/__init__.py')))
+    self.assertTrue(os.path.exists(
+        os.path.join(self.dest,
+                     'usr/local/factory/py/umpire/client/umpire_client.py')))
+    self.assertFalse(os.path.exists(
+        os.path.join(self.dest, 'usr/local/factory/py/umpire/archiver.py')))
 
   def testDeviceOnly(self):
     self.makeLiveDevice()