Add --user and --password options

Bug: b/132983488
Test: ran acloud with --user --password and checked that metadata showed
up

Change-Id: I1b975e11803b9610146bce20dc75f02bf64fd493
diff --git a/create/avd_spec.py b/create/avd_spec.py
index 8ede5a4..98ca69d 100644
--- a/create/avd_spec.py
+++ b/create/avd_spec.py
@@ -86,6 +86,7 @@
     return _RE_ANSI_ESCAPE.sub('', line)
 
 
+# pylint: disable=too-many-public-methods
 class AVDSpec(object):
     """Class to store data on the type of AVD to create."""
 
@@ -120,6 +121,10 @@
         self._gpu = None
         self._emulator_build_id = None
 
+        # username and password only used for cheeps type.
+        self._username = None
+        self._password = None
+
         self._ProcessArgs(args)
 
     def __repr__(self):
@@ -263,6 +268,9 @@
         self._emulator_build_id = args.emulator_build_id
         self._gpu = args.gpu
 
+        self._username = args.username
+        self._password = args.password
+
     @staticmethod
     def _GetFlavorFromString(flavor_string):
         """Get flavor name from flavor string.
@@ -602,3 +610,13 @@
     def client_adb_port(self):
         """Return the client adb port."""
         return self._client_adb_port
+
+    @property
+    def username(self):
+        """Return username."""
+        return self._username
+
+    @property
+    def password(self):
+        """Return password."""
+        return self._password
diff --git a/create/create_args.py b/create/create_args.py
index a1d618d..7032b74 100644
--- a/create/create_args.py
+++ b/create/create_args.py
@@ -237,6 +237,22 @@
         help="'goldfish only' Emulator build used to run the images. "
         "e.g. 4669466.")
 
+    # Arguments for cheeps type.
+    create_parser.add_argument(
+        "--user",
+        type=str,
+        dest="username",
+        required=False,
+        default=None,
+        help="'cheeps only' username to log in to Chrome OS as.")
+    create_parser.add_argument(
+        "--password",
+        type=str,
+        dest="password",
+        required=False,
+        default=None,
+        help="'cheeps only' password to log in to Chrome OS with.")
+
     AddCommonCreateArgs(create_parser)
     return create_parser
 
@@ -277,3 +293,9 @@
             raise errors.InvalidHWPropertyError(
                 "[%s] is an invalid hw property, supported values are:%s. "
                 % (key, constants.HW_PROPERTIES))
+
+    if (args.username or args.password) and args.avd_type != constants.TYPE_CHEEPS:
+        raise ValueError("--username and --password are only valid with avd_type == %s"
+                         % constants.TYPE_CHEEPS)
+    if (args.username or args.password) and not (args.username and args.password):
+        raise ValueError("--username and --password must both be set")
diff --git a/internal/lib/cheeps_compute_client.py b/internal/lib/cheeps_compute_client.py
index 98e249b..2909ff7 100644
--- a/internal/lib/cheeps_compute_client.py
+++ b/internal/lib/cheeps_compute_client.py
@@ -89,6 +89,10 @@
                 avd_spec.hw_property[constants.HW_Y_RES],
                 avd_spec.hw_property[constants.HW_ALIAS_DPI]))
 
+            if avd_spec.username:
+                metadata["user"] = avd_spec.username
+                metadata["password"] = avd_spec.password
+
         # Add per-instance ssh key
         if self._ssh_public_key_path:
             rsa = self._LoadSshPublicKey(self._ssh_public_key_path)
diff --git a/internal/lib/cheeps_compute_client_test.py b/internal/lib/cheeps_compute_client_test.py
index f80c0c4..bb157b7 100644
--- a/internal/lib/cheeps_compute_client_test.py
+++ b/internal/lib/cheeps_compute_client_test.py
@@ -40,6 +40,8 @@
     DPI = 320
     X_RES = 720
     Y_RES = 1280
+    USER = "test_user"
+    PASSWORD = "test_password"
 
     def _GetFakeConfig(self):
         """Create a fake configuration object.
@@ -88,7 +90,10 @@
             'display': "%sx%s (%s)"%(
                 str(self.X_RES),
                 str(self.Y_RES),
-                str(self.DPI))}
+                str(self.DPI)),
+            'user': self.USER,
+            'password': self.PASSWORD,
+        }
         expected_metadata.update(self.METADATA)
         expected_labels = {'created_by': "fake_user"}
 
@@ -96,6 +101,8 @@
         avd_spec.hw_property = {constants.HW_X_RES: str(self.X_RES),
                                 constants.HW_Y_RES: str(self.Y_RES),
                                 constants.HW_ALIAS_DPI: str(self.DPI)}
+        avd_spec.username = self.USER
+        avd_spec.password = self.PASSWORD
 
         self.cheeps_compute_client.CreateInstance(
             self.INSTANCE,