[autotest] Get atest to list the shard a host is on.

TEST=Ran atest host list.
BUG=chromium:438858

Change-Id: I0ec46f1d3f8068c0f2144a8a0e5a769cf81a0c96
Reviewed-on: https://chromium-review.googlesource.com/235545
Reviewed-by: Prashanth B <[email protected]>
Tested-by: Prashanth B <[email protected]>
Commit-Queue: Prashanth B <[email protected]>
Trybot-Ready: Prashanth B <[email protected]>
diff --git a/cli/host.py b/cli/host.py
index 95b676f..be1f318 100644
--- a/cli/host.py
+++ b/cli/host.py
@@ -194,8 +194,9 @@
         if self.hostnames_only:
             self.print_list(results, key='hostname')
         else:
-            super(host_list, self).output(results, keys=['hostname', 'status',
-                                          'locked', 'platform', 'labels'])
+            keys = ['hostname', 'status',
+                    'shard', 'locked', 'platform', 'labels']
+            super(host_list, self).output(results, keys=keys)
 
 
 class host_stat(host):
diff --git a/cli/host_unittest.py b/cli/host_unittest.py
index 166f3fd..33a2103 100755
--- a/cli/host_unittest.py
+++ b/cli/host_unittest.py
@@ -127,6 +127,7 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': None,
+                              u'shard': None,
                               u'id': 1},
                              {u'status': u'Ready',
                               u'hostname': u'host1',
@@ -137,9 +138,10 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': u'plat1',
+                              u'shard': None,
                               u'id': 2}])],
                      out_words_ok=['host0', 'host1', 'Ready',
-                                   'plat1', 'False', 'True'])
+                                   'plat1', 'False', 'True', 'None'])
 
 
     def test_execute_list_all_with_labels(self):
@@ -155,6 +157,7 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': None,
+                              u'shard': None,
                               u'id': 1},
                              {u'status': u'Ready',
                               u'hostname': u'host1',
@@ -164,11 +167,12 @@
                               u'labels': [u'label2', u'label3', u'plat1'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat1',
                               u'id': 2}])],
                      out_words_ok=['host0', 'host1', 'Ready', 'plat1',
                                    'label0', 'label1', 'label2', 'label3',
-                                   'False', 'True'])
+                                   'False', 'True', 'None'])
 
 
     def test_execute_list_filter_one_host(self):
@@ -185,9 +189,10 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': u'plat1',
+                              u'shard': None,
                               u'id': 2}])],
                      out_words_ok=['host1', 'Ready', 'plat1',
-                                   'label2', 'label3', 'True'],
+                                   'label2', 'label3', 'True', 'None'],
                      out_words_no=['host0', 'host2',
                                    'label1', 'label4', 'False'])
 
@@ -208,6 +213,7 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': u'plat1',
+                              u'shard': None,
                               u'id': 2},
                              {u'status': u'Ready',
                               u'hostname': u'host2',
@@ -217,11 +223,12 @@
                               u'labels': [u'label3', u'label4', u'plat1'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat1',
                               u'id': 3}])],
                      out_words_ok=['host1', 'Ready', 'plat1',
                                    'label2', 'label3', 'True',
-                                   'host2', 'label4'],
+                                   'host2', 'label4', 'None'],
                      out_words_no=['host0', 'label1', 'False'])
         mfile.clean()
 
@@ -241,10 +248,11 @@
                               u'labels': [u'label3', u'label4', u'plat1'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat1',
                               u'id': 3}])],
                      out_words_ok=['Ready', 'plat1',
-                                   'label3', 'label4', 'True'],
+                                   'label3', 'label4', 'True', 'None'],
                      out_words_no=['host1', 'False'],
                      err_words_ok=['host1'])
         mfile.clean()
@@ -276,6 +284,7 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': u'plat1',
+                              u'shard': None,
                               u'id': 2},
                              {u'status': u'Ready',
                               u'hostname': u'host2',
@@ -284,12 +293,13 @@
                               u'lock_time': u'2008-07-23 12:54:15',
                               u'labels': [u'label3', u'label4', u'plat1'],
                               u'invalid': False,
+                              u'shard': None,
                               u'synch_id': None,
                               u'platform': u'plat1',
                               u'id': 3}])],
                      out_words_ok=['host1', 'Ready', 'plat1',
                                    'label2', 'label3', 'True',
-                                   'host2', 'label4'],
+                                   'host2', 'label4', 'None'],
                      out_words_no=['host0', 'label1', 'False'])
 
 
@@ -307,6 +317,7 @@
                               u'labels': [u'label2', u'label3', u'plat0'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat0',
                               u'id': 2},
                              {u'status': u'Ready',
@@ -317,10 +328,11 @@
                               u'labels': [u'label3', u'label2', u'plat2'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat2',
                               u'id': 4}])],
                      out_words_ok=['host1', 'host3', 'Ready', 'plat0',
-                                   'label2', 'label3', 'plat2'],
+                                   'label2', 'label3', 'plat2', 'None'],
                      out_words_no=['host2', 'label4', 'False', 'plat1'])
 
 
@@ -342,9 +354,10 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': u'plat1',
+                              u'shard': None,
                               u'id': 3}])],
                      out_words_ok=['host2', 'plat1',
-                                   'label2', 'label3', 'label4'],
+                                   'label2', 'label3', 'label4', 'None'],
                      out_words_no=['host1', 'host3'])
 
 
@@ -358,6 +371,7 @@
                             [{u'status': u'Ready',
                               u'hostname': u'host2',
                               u'locked': 1,
+                              u'shard': None,
                               u'locked_by': 'user0',
                               u'lock_time': u'2008-07-23 12:54:15',
                               u'labels': [u'label3', u'label2', u'label4',
@@ -367,7 +381,7 @@
                               u'platform': u'plat1',
                               u'id': 3}])],
                      out_words_ok=['host2', 'plat1',
-                                   'label2', 'label3', 'label4'],
+                                   'label2', 'label3', 'label4', 'None'],
                      out_words_no=['host1', 'host3'])
 
 
@@ -398,6 +412,7 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': u'plat1',
+                              u'shard': None,
                               u'id': 2},
                              {u'status': u'Ready',
                               u'hostname': u'host2',
@@ -407,11 +422,12 @@
                               u'labels': [u'label3', u'label4', u'plat1'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat1',
                               u'id': 3}])],
                      out_words_ok=['host1', 'Ready', 'plat1',
                                    'label2', 'label3', 'True',
-                                   'host2', 'label4'],
+                                   'host2', 'label4', 'None'],
                      out_words_no=['host0', 'label1', 'False'])
 
 
@@ -441,6 +457,7 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': u'plat1',
+                              u'shard': None,
                               u'id': 2},
                              {u'status': u'Ready',
                               u'hostname': u'host2',
@@ -450,11 +467,12 @@
                               u'labels': [u'label3', u'label4', u'plat1'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat1',
                               u'id': 3}])],
                      out_words_ok=['host1', 'Ready', 'plat1',
                                    'label2', 'label3', 'True',
-                                   'host2', 'label4'],
+                                   'host2', 'label4', 'None'],
                      out_words_no=['host0', 'label1', 'False'])
 
 
@@ -474,6 +492,7 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': u'plat1',
+                              u'shard': None,
                               u'id': 2},
                              {u'status': u'Ready',
                               u'hostname': u'host2',
@@ -483,11 +502,12 @@
                               u'labels': [u'label3', u'label4', u'plat1'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat1',
                               u'id': 3}])],
                      out_words_ok=['host1', 'Ready', 'plat1',
                                    'label2', 'label3', 'True',
-                                   'host2', 'label4'],
+                                   'host2', 'label4', 'None'],
                      out_words_no=['host0', 'label1', 'False'])
 
 
@@ -532,6 +552,7 @@
                               u'invalid': False,
                               u'synch_id': None,
                               u'platform': u'plat1',
+                              u'shard': None,
                               u'id': 2},
                              {u'status': u'Ready',
                               u'hostname': u'host2',
@@ -541,11 +562,12 @@
                               u'labels': [u'label3', u'label4', u'plat1'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat1',
                               u'id': 3}])],
                      out_words_ok=['host1', 'Ready', 'plat1',
                                    'label2', 'label3', 'True',
-                                   'host2', 'label4'],
+                                   'host2', 'label4', 'None'],
                      out_words_no=['host0', 'label1', 'False'])
 
 
@@ -562,6 +584,7 @@
                               u'labels': [u'label2', u'label3', u'plat1'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat1',
                               u'id': 2},
                              {u'status': u'Ready',
@@ -571,12 +594,13 @@
                               u'lock_time': u'2008-07-23 12:54:15',
                               u'labels': [u'label3', u'label4', u'plat1'],
                               u'invalid': False,
+                              u'shard': None,
                               u'synch_id': None,
                               u'platform': u'plat1',
                               u'id': 3}])],
                      out_words_ok=['host1', 'Ready', 'plat1',
                                    'label2', 'label3', 'False',
-                                   'host2', 'label4'],
+                                   'host2', 'label4', 'None'],
                      out_words_no=['host0', 'label1', 'True'])
 
 
@@ -596,6 +620,7 @@
                               u'labels': [u'label3', u'label4', u'plat1'],
                               u'invalid': False,
                               u'synch_id': None,
+                              u'shard': None,
                               u'platform': u'plat1',
                               u'id': 3}]),
                            ('get_hosts', {'hostname': 'host0'},
@@ -608,6 +633,7 @@
                               u'protection': u'No protection',
                               u'labels': [u'label0', u'plat0'],
                               u'invalid': False,
+                              u'shard': None,
                               u'synch_id': None,
                               u'platform': u'plat0',
                               u'id': 2}]),
diff --git a/cli/topic_common.py b/cli/topic_common.py
index f4cb0ba..c9c0a7f 100644
--- a/cli/topic_common.py
+++ b/cli/topic_common.py
@@ -108,6 +108,7 @@
                     'max_number_of_machines': 'Max. hosts to use',
                     'parse_failed_repair': 'Include failed repair results',
                     'atomic_group.name': 'Atomic Group Name',
+                    'shard': 'Shard',
                     }
 
 # In the failure, tag that will replace the item.
@@ -138,7 +139,8 @@
                 'invalid': lambda flag: str(bool(not flag)),
                 'only_if_needed': _int_2_bool_string,
                 'platform': __convert_platform,
-                'labels': lambda labels: ', '.join(labels)}
+                'labels': lambda labels: ', '.join(labels),
+                'shards': lambda shard: shard.hostname if shard else ''}
 
 
 def _get_item_key(item, key):