Represent a group of machines with either the atomic group label name,
if a specific label was used, or the atomic group name in the results
database when parsing.

Adds an optional host_group_name= to the server side group job keyval
file.  The scheduler choses the most appropriate name for this and adds
it to the group keyvals file.

Changes the TKO results parser to use host_group_name= as the machine name
instead of hostname= when hostname= is a comma separated list of hostnames
rather than a single name.

Also fixes atomic group scheduling to be able to use up to the atomic group's
max_number_of_machines when launching the job;  This is still unlikely to
happen as the code still launches the job as soon as at least the sync count
have exited Verify.

Signed-off-by: Gregory Smith <gps@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3103 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/parsers/version_0_unittest.py b/tko/parsers/version_0_unittest.py
index 6ca7df8..884989a 100644
--- a/tko/parsers/version_0_unittest.py
+++ b/tko/parsers/version_0_unittest.py
@@ -3,9 +3,68 @@
 import unittest
 
 import common
+from autotest_lib.client.common_lib.test_utils import mock
+from autotest_lib.tko import models
 from autotest_lib.tko.parsers import version_0
 
 
+class test_job_load_from_dir(unittest.TestCase):
+    def setUp(self):
+        self.god = mock.mock_god()
+        self.god.stub_function(models.job, 'read_keyval')
+
+    def tearDown(self):
+        self.god.unstub_all()
+
+    keyval_return = {'job_queued': 1234567890,
+                     'job_started': 1234567891,
+                     'job_finished': 1234567892,
+                     'user': 'janet',
+                     'label': 'steeltown',
+                     'hostname': 'abc123'}
+
+    def test_load_from_dir_simple(self):
+        models.job.read_keyval.expect_call('.').and_return(
+                dict(self.keyval_return))
+        job = version_0.job.load_from_dir('.')
+        self.assertEqual('janet', job['user'])
+        self.assertEqual('steeltown', job['label'])
+        self.assertEqual('abc123', job['machine'])
+        self.god.check_playback()
+
+    def test_load_from_dir_one_machine_group_name(self):
+        raw_keyval = dict(self.keyval_return)
+        raw_keyval['host_group_name'] = 'jackson five'
+        models.job.read_keyval.expect_call('.').and_return(raw_keyval)
+        job = version_0.job.load_from_dir('.')
+        self.assertEqual('janet', job['user'])
+        self.assertEqual('abc123', job['machine'])
+        self.god.check_playback()
+
+    def test_load_from_dir_multi_machine_group_name(self):
+        raw_keyval = dict(self.keyval_return)
+        raw_keyval['user'] = 'michael'
+        raw_keyval['hostname'] = 'abc123,dancingmachine'
+        raw_keyval['host_group_name'] = 'jackson five'
+        models.job.read_keyval.expect_call('.').and_return(raw_keyval)
+        job = version_0.job.load_from_dir('.')
+        self.assertEqual('michael', job['user'])
+        # The host_group_name is used instead because machine appeared to be
+        # a comma separated list.
+        self.assertEqual('jackson five', job['machine'])
+        self.god.check_playback()
+
+    def test_load_from_dir_no_machine_group_name(self):
+        raw_keyval = dict(self.keyval_return)
+        del raw_keyval['hostname']
+        raw_keyval['host_group_name'] = 'jackson five'
+        models.job.read_keyval.expect_call('.').and_return(raw_keyval)
+        job = version_0.job.load_from_dir('.')
+        # The host_group_name is used because there is no machine.
+        self.assertEqual('jackson five', job['machine'])
+        self.god.check_playback()
+
+
 class test_status_line(unittest.TestCase):
     statuses = ["GOOD", "WARN", "FAIL", "ABORT"]