moblab_setup page: Save config diff to shadow_config.ini

Updates the moblab_setup page to only save the changed settings
to the shadow_config and not the whole config which eliminated
our ability to AU config changes. Now that only the changed settings
are saved we can properly toggle on/off features remotely.

BUG=chromium:487415
TEST=local moblab setup and unittests.

Change-Id: Ie75de09d196673f14908519a228e9bc0b18c0095
Reviewed-on: https://chromium-review.googlesource.com/271171
Reviewed-by: Simran Basi <sbasi@chromium.org>
Tested-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Simran Basi <sbasi@chromium.org>
diff --git a/frontend/afe/site_rpc_interface.py b/frontend/afe/site_rpc_interface.py
index 863ee55..dd991a8 100644
--- a/frontend/afe/site_rpc_interface.py
+++ b/frontend/afe/site_rpc_interface.py
@@ -7,6 +7,7 @@
 __author__ = 'cmasone@chromium.org (Chris Masone)'
 
 import common
+import ConfigParser
 import datetime
 import logging
 import os
@@ -251,14 +252,22 @@
 
     @param config_values: See get_moblab_settings().
     """
+    original_config = global_config.global_config_class()
+    original_config.set_config_files(shadow_file='')
+    new_shadow = ConfigParser.RawConfigParser()
     for section, config_value_list in config_values.iteritems():
         for key, value in config_value_list:
-            _CONFIG.override_config_value(section, key, value)
+            if original_config.get_config_value(section, key,
+                                                default='',
+                                                allow_blank=True) != value:
+                if not new_shadow.has_section(section):
+                    new_shadow.add_section(section)
+                new_shadow.set(section, key, value)
     if not _CONFIG.shadow_file or not os.path.exists(_CONFIG.shadow_file):
         raise error.RPCException('Shadow config file does not exist.')
 
     with open(_CONFIG.shadow_file, 'w') as config_file:
-        _CONFIG.config.write(config_file)
+        new_shadow.write(config_file)
     # TODO (sbasi) crbug.com/403916 - Remove the reboot command and
     # instead restart the services that rely on the config values.
     os.system('sudo reboot')