cbuildbot_launch: Generate improved fields for all metrics.

With this, all launcher metrics have the fields:
  branch_name:   String with branch name.
  build_config:  String with build config being built.
  tryjob:        Boolean flag showing if this is a tryjob.

I audited the cbuildbot command line parsing code, and found no side
effects other than calling 'Die' in a variety of cases. So... I
simplified main to just parse command line options before creating the
metrics fields instead of updating them on the fly.

While touching commandline parsing, I redid the way we filer command
line options before invoking cbuildbot to be slightly less coupled to
cbuildbot's internals.

BUG=chromium:726065
TEST=Unittest + localbuilds.

Change-Id: I4c7da7917acfd60ac5bd69285de0d25addad0e6a
Reviewed-on: https://chromium-review.googlesource.com/535054
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
diff --git a/scripts/cbuildbot_launch_unittest.py b/scripts/cbuildbot_launch_unittest.py
index ef6b7fe..3e6f75b 100644
--- a/scripts/cbuildbot_launch_unittest.py
+++ b/scripts/cbuildbot_launch_unittest.py
@@ -99,13 +99,11 @@
 
   def verifyRunCbuildbot(self, args, expected_cmd, version):
     """Ensure we invoke cbuildbot correctly."""
-    options = cbuildbot_launch.PreParseArguments(args)
-
     self.PatchObject(
         cros_build_lib, 'GetTargetChromiteApiVersion', autospec=True,
         return_value=version)
 
-    cbuildbot_launch.RunCbuildbot('/cbuildbot_buildroot', options)
+    cbuildbot_launch.RunCbuildbot('/cbuildbot_buildroot', args)
 
     self.assertCommandCalled(
         expected_cmd, cwd='/cbuildbot_buildroot', error_code_ok=True)
@@ -158,7 +156,12 @@
 
     # Ensure we clean, as expected.
     self.assertEqual(mock_clean.mock_calls, [
-        mock.call('/root', mock_repo, {'branch_name': 'master'})])
+        mock.call('/root', mock_repo,
+                  {
+                      'branch_name': 'master',
+                      'tryjob': False,
+                      'build_config': 'config',
+                  })])
 
     # Ensure we checkout, as expected.
     self.assertEqual(mock_checkout.mock_calls,
@@ -191,6 +194,7 @@
     cbuildbot_launch._main(['--buildroot', '/root',
                             '--branch', 'branch',
                             '--git-cache-dir', '/git-cache',
+                            '--remote-trybot',
                             'config'])
 
     # Did we create the repo instance correctly?
@@ -200,7 +204,13 @@
 
     # Ensure we clean, as expected.
     self.assertEqual(mock_clean.mock_calls, [
-        mock.call('/root', mock_repo, {'branch_name': 'branch'})])
+        mock.call('/root',
+                  mock_repo,
+                  {
+                      'branch_name': 'branch',
+                      'tryjob': True,
+                      'build_config': 'config',
+                  })])
 
     # Ensure we checkout, as expected.
     self.assertEqual(mock_checkout.mock_calls,
@@ -212,7 +222,8 @@
          'config',
          '--buildroot', '/root/repository',
          '--branch', 'branch',
-         '--git-cache-dir', '/git-cache'],
+         '--git-cache-dir', '/git-cache',
+         '--remote-trybot'],
         cwd='/root/repository',
         error_code_ok=True)