Best Python code snippet using autotest_python
job_unittest.py
Source:job_unittest.py  
1#!/usr/bin/python -u2#3# Copyright 2008 Google Inc. All Rights Reserved.4"""Tests for job."""5# pylint: disable=missing-docstring6import copy, getpass, unittest, sys7import common8from autotest_lib.cli import cli_mock, job9from autotest_lib.client.common_lib.test_utils import mock10from autotest_lib.client.common_lib import control_data11from autotest_lib.client.common_lib import priorities12CLIENT = control_data.CONTROL_TYPE_NAMES.CLIENT13SERVER = control_data.CONTROL_TYPE_NAMES.SERVER14class job_unittest(cli_mock.cli_unittest):15    def setUp(self):16        super(job_unittest, self).setUp()17        self.values = copy.deepcopy(self.values_template)18    results = [{u'status_counts': {u'Aborted': 1},19                u'control_file':20                u"job.run_test('sleeptest')\n",21                u'name': u'test_job0',22                u'control_type': SERVER,23                u'priority':24                priorities.Priority.DEFAULT,25                u'owner': u'user0',26                u'created_on':27                u'2008-07-08 17:45:44',28                u'synch_count': 2,29                u'id': 180},30               {u'status_counts': {u'Queued': 1},31                u'control_file':32                u"job.run_test('sleeptest')\n",33                u'name': u'test_job1',34                u'control_type': CLIENT,35                u'priority':36                priorities.Priority.DEFAULT,37                u'owner': u'user0',38                u'created_on':39                u'2008-07-08 12:17:47',40                u'synch_count': 1,41                u'id': 338}]42    values_template = [{u'id': 180,          # Valid job43                        u'priority': priorities.Priority.DEFAULT,44                        u'name': u'test_job0',45                        u'owner': u'Cringer',46                        u'invalid': False,47                        u'created_on': u'2008-07-02 13:02:40',48                        u'control_type': SERVER,49                        u'status_counts': {u'Queued': 1},50                        u'synch_count': 2},51                       {u'id': 338,          # Valid job52                        u'priority': priorities.Priority.DEFAULT,53                        u'name': u'test_job1',54                        u'owner': u'Fisto',55                        u'invalid': False,56                        u'created_on': u'2008-07-06 14:05:33',57                        u'control_type': CLIENT,58                        u'status_counts': {u'Queued': 1},59                        u'synch_count': 1},60                       {u'id': 339,          # Valid job61                        u'priority': priorities.Priority.DEFAULT,62                        u'name': u'test_job2',63                        u'owner': u'Roboto',64                        u'invalid': False,65                        u'created_on': u'2008-07-07 15:33:18',66                        u'control_type': SERVER,67                        u'status_counts': {u'Queued': 1},68                        u'synch_count': 1},69                       {u'id': 340,          # Invalid job priority70                        u'priority': priorities.Priority.DEFAULT,71                        u'name': u'test_job3',72                        u'owner': u'Panthor',73                        u'invalid': True,74                        u'created_on': u'2008-07-04 00:00:01',75                        u'control_type': SERVER,76                        u'status_counts': {u'Queued': 1},77                        u'synch_count': 2},78                       {u'id': 350,          # Invalid job created_on79                        u'priority': priorities.Priority.DEFAULT,80                        u'name': u'test_job4',81                        u'owner': u'Icer',82                        u'invalid': True,83                        u'created_on': u'Today',84                        u'control_type': CLIENT,85                        u'status_counts': {u'Queued': 1},86                        u'synch_count': 1},87                       {u'id': 420,          # Invalid job control_type88                        u'priority': 'Urgent',89                        u'name': u'test_job5',90                        u'owner': u'Spikor',91                        u'invalid': True,92                        u'created_on': u'2012-08-08 18:54:37',93                        u'control_type': u'Child',94                        u'status_counts': {u'Queued': 1},95                        u'synch_count': 2}]96class job_list_unittest(job_unittest):97    def test_job_list_jobs(self):98        self.god.stub_function(getpass, 'getuser')99        getpass.getuser.expect_call().and_return('user0')100        self.run_cmd(argv=['atest', 'job', 'list'],101                     rpcs=[('get_jobs_summary', {'owner': 'user0',102                                                 'running': None},103                            True, self.values)],104                     out_words_ok=['test_job0', 'test_job1', 'test_job2'],105                     out_words_no=['Uber', 'Today', 'Child'])106    def test_job_list_jobs_only_user(self):107        values = [item for item in self.values if item['owner'] == 'Cringer']108        self.run_cmd(argv=['atest', 'job', 'list', '-u', 'Cringer'],109                     rpcs=[('get_jobs_summary', {'owner': 'Cringer',110                                                 'running': None},111                            True, values)],112                     out_words_ok=['Cringer'],113                     out_words_no=['Fisto', 'Roboto', 'Panthor', 'Icer',114                                   'Spikor'])115    def test_job_list_jobs_all(self):116        self.run_cmd(argv=['atest', 'job', 'list', '--all'],117                     rpcs=[('get_jobs_summary', {'running': None},118                            True, self.values)],119                     out_words_ok=['Fisto', 'Roboto', 'Panthor',120                                   'Icer', 'Spikor', 'Cringer'],121                     out_words_no=['Created', 'Priority'])122    def test_job_list_jobs_id(self):123        self.run_cmd(argv=['atest', 'job', 'list', '5964'],124                     rpcs=[('get_jobs_summary', {'id__in': ['5964'],125                                                 'running': None},126                            True,127                            [{u'status_counts': {u'Completed': 1},128                              u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n    job.next_step([step_test])\n\ndef step_test():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "Autotest Team"\n    NAME = "Sleeptest"\n    TIME = "SHORT"\n    TEST_CATEGORY = "Functional"\n    TEST_CLASS = "General"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    This test simply sleeps for 1 second by default.  It\'s a good way to test\n    profilers and double check that autotest is working.\n    The seconds argument can also be modified to make the machine sleep for as\n    long as needed.\n    """\n    \n    job.run_test(\'sleeptest\',                             seconds = 1)',129                              u'name': u'mytest',130                              u'control_type': CLIENT,131                              u'run_verify': 1,132                              u'priority': priorities.Priority.DEFAULT,133                              u'owner': u'user0',134                              u'created_on': u'2008-07-28 12:42:52',135                              u'timeout': 144,136                              u'synch_count': 1,137                              u'id': 5964}])],138                     out_words_ok=['user0', 'Completed', '1', '5964'],139                     out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])140    def test_job_list_jobs_id_verbose(self):141        self.run_cmd(argv=['atest', 'job', 'list', '5964', '-v'],142                     rpcs=[('get_jobs_summary', {'id__in': ['5964'],143                                                 'running': None},144                            True,145                            [{u'status_counts': {u'Completed': 1},146                              u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n    job.next_step([step_test])\n\ndef step_test():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "Autotest Team"\n    NAME = "Sleeptest"\n    TIME = "SHORT"\n    TEST_CATEGORY = "Functional"\n    TEST_CLASS = "General"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    This test simply sleeps for 1 second by default.  It\'s a good way to test\n    profilers and double check that autotest is working.\n    The seconds argument can also be modified to make the machine sleep for as\n    long as needed.\n    """\n    \n    job.run_test(\'sleeptest\',                             seconds = 1)',147                              u'name': u'mytest',148                              u'control_type': CLIENT,149                              u'run_verify': 1,150                              u'priority': priorities.Priority.DEFAULT,151                              u'owner': u'user0',152                              u'created_on': u'2008-07-28 12:42:52',153                              u'timeout': 144,154                              u'synch_count': 1,155                              u'id': 5964}])],156                     out_words_ok=['user0', 'Completed', '1', '5964',157                                   CLIENT, '2008', 'Priority'],158                     out_words_no=['sleeptest'])159    def test_job_list_jobs_name(self):160        self.run_cmd(argv=['atest', 'job', 'list', 'myt*'],161                     rpcs=[('get_jobs_summary', {'name__startswith': 'myt',162                                                 'running': None},163                            True,164                            [{u'status_counts': {u'Completed': 1},165                              u'control_file': u'kernel = \'8210088647656509311.kernel-smp-2.6.18-220.5.x86_64.rpm\'\ndef step_init():\n    job.next_step([step_test])\n\ndef step_test():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "Autotest Team"\n    NAME = "Sleeptest"\n    TIME = "SHORT"\n    TEST_CATEGORY = "Functional"\n    TEST_CLASS = "General"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    This test simply sleeps for 1 second by default.  It\'s a good way to test\n    profilers and double check that autotest is working.\n    The seconds argument can also be modified to make the machine sleep for as\n    long as needed.\n    """\n    \n    job.run_test(\'sleeptest\',                             seconds = 1)',166                              u'name': u'mytest',167                              u'control_type': CLIENT,168                              u'run_verify': 1,169                              u'priority': priorities.Priority.DEFAULT,170                              u'owner': u'user0',171                              u'created_on': u'2008-07-28 12:42:52',172                              u'timeout': 144,173                              u'synch_count': 1,174                              u'id': 5964}])],175                     out_words_ok=['user0', 'Completed', '1', '5964'],176                     out_words_no=['sleeptest', 'Priority', CLIENT, '2008'])177    def test_job_list_jobs_all_verbose(self):178        self.run_cmd(argv=['atest', 'job', 'list', '--all', '--verbose'],179                     rpcs=[('get_jobs_summary', {'running': None},180                            True, self.values)],181                     out_words_ok=['Fisto', 'Spikor', 'Cringer', 'Priority',182                                   'Created'])183class job_list_jobs_all_and_user_unittest(cli_mock.cli_unittest):184    def test_job_list_jobs_all_and_user(self):185        testjob = job.job_list()186        sys.argv = ['atest', 'job', 'list', '-a', '-u', 'user0']187        self.god.mock_io()188        (sys.exit.expect_call(mock.anything_comparator())189         .and_raises(cli_mock.ExitException))190        self.assertRaises(cli_mock.ExitException, testjob.parse)191        self.god.unmock_io()192        self.god.check_playback()193class job_stat_unittest(job_unittest):194    def test_job_stat_job(self):195        results = copy.deepcopy(self.results)196        self.run_cmd(argv=['atest', 'job', 'stat', '180'],197                     rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,198                            [results[0]]),199                           ('get_host_queue_entries', {'job__in': ['180']},200                            True,201                            [{u'status': u'Failed',202                              u'complete': 1,203                              u'host': {u'status': u'Repair Failed',204                                        u'locked': False,205                                        u'hostname': u'host0',206                                        u'invalid': True,207                                        u'id': 4432},208                              u'priority': 1,209                              u'meta_host': None,210                              u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",211                                       u'name': u'test_sleep',212                                       u'control_type': SERVER,213                                       u'synchronizing': 0,214                                       u'priority': priorities.Priority.DEFAULT,215                                       u'owner': u'user0',216                                       u'created_on': u'2008-03-18 11:27:29',217                                       u'synch_count': 1,218                                       u'id': 180},219                              u'active': 0,220                              u'id': 101084}])],221                     out_words_ok=['test_job0', 'host0', 'Failed',222                                   'Aborted'])223    def test_job_stat_list_unassigned_host(self):224        self.run_cmd(argv=['atest', 'job', 'stat', '6761',225                           '--list-hosts'],226                     rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,227                            [{u'status_counts': {u'Queued': 1},228                              u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',229                              u'name': u'test_on_meta_hosts',230                              u'control_type': CLIENT,231                              u'run_verify': 1,232                              u'priority': priorities.Priority.DEFAULT,233                              u'owner': u'user0',234                              u'created_on': u'2008-07-30 22:15:43',235                              u'timeout': 144,236                              u'synch_count': 1,237                              u'id': 6761}]),238                           ('get_host_queue_entries', {'job__in': ['6761']},239                            True,240                            [{u'status': u'Queued',241                              u'complete': 0,242                              u'deleted': 0,243                              u'host': None,244                              u'priority': 1,245                              u'meta_host': u'Xeon',246                              u'job': {u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',247                                       u'name': u'test_on_meta_hosts',248                                       u'control_type': CLIENT,249                                       u'run_verify': 1,250                                       u'priority': priorities.Priority.DEFAULT,251                                       u'owner': u'user0',252                                       u'created_on': u'2008-07-30 22:15:43',253                                       u'timeout': 144,254                                       u'synch_count': 1,255                                       u'id': 6761},256                              u'active': 0,257                              u'id': 193166} ])],258                     err_words_ok=['unassigned', 'meta-hosts'],259                     out_words_no=['Xeon'])260    def test_job_stat_list_hosts(self):261        self.run_cmd(argv=['atest', 'job', 'stat', '6761',262                           '--list-hosts'],263                     rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,264                            [{u'status_counts': {u'Queued': 1},265                              u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',266                              u'name': u'test_on_meta_hosts',267                              u'control_type': CLIENT,268                              u'run_verify': 1,269                              u'priority': priorities.Priority.DEFAULT,270                              u'owner': u'user0',271                              u'created_on': u'2008-07-30 22:15:43',272                              u'timeout': 144,273                              u'synch_count': 1,274                              u'id': 6761}]),275                           ('get_host_queue_entries', {'job__in': ['6761']},276                            True,277                            [{u'status': u'Queued',278                              u'complete': 0,279                              u'deleted': 0,280                              u'host': {u'status': u'Running',281                                        u'lock_time': None,282                                        u'hostname': u'host41',283                                        u'locked': False,284                                        u'locked_by': None,285                                        u'invalid': False,286                                        u'id': 4833,287                                        u'protection': u'Repair filesystem only'},288                              u'priority': 1,289                              u'meta_host': u'Xeon',290                              u'job': {u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',291                                       u'name': u'test_on_meta_hosts',292                                       u'control_type': CLIENT,293                                       u'run_verify': 1,294                                       u'priority': priorities.Priority.DEFAULT,295                                       u'owner': u'user0',296                                       u'created_on': u'2008-07-30 22:15:43',297                                       u'timeout': 144,298                                       u'synch_count': 1,299                                       u'id': 6761},300                              u'active': 0,301                              u'id': 193166},302                            {u'status': u'Running',303                              u'complete': 0,304                              u'deleted': 0,305                              u'host': {u'status': u'Running',306                                        u'lock_time': None,307                                        u'hostname': u'host42',308                                        u'locked': False,309                                        u'locked_by': None,310                                        u'invalid': False,311                                        u'id': 4833,312                                        u'protection': u'Repair filesystem only'},313                              u'priority': 1,314                              u'meta_host': u'Xeon',315                              u'job': {u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',316                                       u'name': u'test_on_meta_hosts',317                                       u'control_type': CLIENT,318                                       u'run_verify': 1,319                                       u'priority': priorities.Priority.DEFAULT,320                                       u'owner': u'user0',321                                       u'created_on': u'2008-07-30 22:15:43',322                                       u'timeout': 144,323                                       u'synch_count': 1,324                                       u'id': 6761},325                              u'active': 0,326                              u'id': 193166} ])],327                     out_words_ok=['host41', 'host42'],328                     out_words_no=['Xeon', 'Running', 'Queued'],329                     err_words_no=['unassigned'])330    def test_job_stat_list_hosts_status(self):331        self.run_cmd(argv=['atest', 'job', 'stat', '6761',332                           '--list-hosts-status', 'Running,Queued'],333                     rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,334                            [{u'status_counts': {u'Queued': 1, u'Running': 1},335                              u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',336                              u'name': u'test',337                              u'control_type': CLIENT,338                              u'run_verify': 1,339                              u'priority': priorities.Priority.DEFAULT,340                              u'owner': u'user0',341                              u'created_on': u'2008-07-30 22:15:43',342                              u'timeout': 144,343                              u'synch_count': 1,344                              u'id': 6761}]),345                           ('get_host_queue_entries', {'job__in': ['6761']},346                            True,347                            [{u'status': u'Queued',348                              u'complete': 0,349                              u'deleted': 0,350                              u'host': {u'status': u'Queued',351                                        u'lock_time': None,352                                        u'hostname': u'host41',353                                        u'locked': False,354                                        u'locked_by': None,355                                        u'invalid': False,356                                        u'id': 4833,357                                        u'protection': u'Repair filesystem only'},358                              u'priority': 1,359                              u'meta_host': None,360                              u'job': {u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',361                                       u'name': u'test',362                                       u'control_type': CLIENT,363                                       u'run_verify': 1,364                                       u'priority': priorities.Priority.DEFAULT,365                                       u'owner': u'user0',366                                       u'created_on': u'2008-07-30 22:15:43',367                                       u'timeout': 144,368                                       u'synch_count': 1,369                                       u'id': 6761},370                              u'active': 0,371                              u'id': 193166},372                            {u'status': u'Running',373                              u'complete': 0,374                              u'deleted': 0,375                              u'host': {u'status': u'Running',376                                        u'lock_time': None,377                                        u'hostname': u'host42',378                                        u'locked': False,379                                        u'locked_by': None,380                                        u'invalid': False,381                                        u'id': 4833,382                                        u'protection': u'Repair filesystem only'},383                              u'priority': 1,384                              u'meta_host': None,385                              u'job': {u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',386                                       u'name': u'test',387                                       u'control_type': CLIENT,388                                       u'run_verify': 1,389                                       u'priority': priorities.Priority.DEFAULT,390                                       u'owner': u'user0',391                                       u'created_on': u'2008-07-30 22:15:43',392                                       u'timeout': 144,393                                       u'synch_count': 1,394                                       u'id': 6761},395                              u'active': 0,396                              u'id': 193166} ])],397                     out_words_ok=['Queued', 'Running', 'host41', 'host42'],398                     out_words_no=['Xeon'],399                     err_words_no=['unassigned'])400    def test_job_stat_job_multiple_hosts(self):401        self.run_cmd(argv=['atest', 'job', 'stat', '6761'],402                     rpcs=[('get_jobs_summary', {'id__in': ['6761']}, True,403                            [{u'status_counts': {u'Running': 1,404                                                 u'Queued': 4},405                              u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',406                              u'name': u'test_on_meta_hosts',407                              u'control_type': CLIENT,408                              u'run_verify': 1,409                              u'priority': priorities.Priority.DEFAULT,410                              u'owner': u'user0',411                              u'created_on': u'2008-07-30 22:15:43',412                              u'timeout': 144,413                              u'synch_count': 1,414                              u'id': 6761}]),415                           ('get_host_queue_entries', {'job__in': ['6761']},416                            True,417                            [{u'status': u'Queued',418                              u'complete': 0,419                              u'deleted': 0,420                              u'host': None,421                              u'priority': 1,422                              u'meta_host': u'Xeon',423                              u'job': {u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',424                                       u'name': u'test_on_meta_hosts',425                                       u'control_type': CLIENT,426                                       u'run_verify': 1,427                                       u'priority': priorities.Priority.DEFAULT,428                                       u'owner': u'user0',429                                       u'created_on': u'2008-07-30 22:15:43',430                                       u'timeout': 144,431                                       u'synch_count': 1,432                                       u'id': 6761},433                              u'active': 0,434                              u'id': 193166},435                             {u'status': u'Queued',436                              u'complete': 0,437                              u'deleted': 0,438                              u'host': None,439                              u'priority': 1,440                              u'meta_host': u'Xeon',441                              u'job': {u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',442                                       u'name': u'test_on_meta_hosts',443                                       u'control_type': CLIENT,444                                       u'run_verify': 1,445                                       u'priority': priorities.Priority.DEFAULT,446                                       u'owner': u'user0',447                                       u'created_on': u'2008-07-30 22:15:43',448                                       u'timeout': 144,449                                       u'synch_count': 1,450                                       u'id': 6761},451                              u'active': 0,452                              u'id': 193167},453                             {u'status': u'Queued',454                              u'complete': 0,455                              u'deleted': 0,456                              u'host': None,457                              u'priority': 1,458                              u'meta_host': u'Athlon',459                              u'job': {u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',460                                       u'name': u'test_on_meta_hosts',461                                       u'control_type': CLIENT,462                                       u'run_verify': 1,463                                       u'priority': priorities.Priority.DEFAULT,464                                       u'owner': u'user0',465                                       u'created_on': u'2008-07-30 22:15:43',466                                       u'timeout': 144,467                                       u'synch_count': 1,468                                       u'id': 6761},469                              u'active': 0,470                              u'id': 193168},471                             {u'status': u'Queued',472                              u'complete': 0,473                              u'deleted': 0,474                              u'host': None,475                              u'priority': 1,476                              u'meta_host': u'x286',477                              u'job': {u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',478                                       u'name': u'test_on_meta_hosts',479                                       u'control_type': CLIENT,480                                       u'run_verify': 1,481                                       u'priority': priorities.Priority.DEFAULT,482                                       u'owner': u'user0',483                                       u'created_on': u'2008-07-30 22:15:43',484                                       u'timeout': 144,485                                       u'synch_count': 1,486                                       u'id': 6761},487                              u'active': 0,488                              u'id': 193169},489                             {u'status': u'Running',490                              u'complete': 0,491                              u'deleted': 0,492                              u'host': {u'status': u'Running',493                                        u'lock_time': None,494                                        u'hostname': u'host42',495                                        u'locked': False,496                                        u'locked_by': None,497                                        u'invalid': False,498                                        u'id': 4833,499                                        u'protection': u'Repair filesystem only'},500                              u'priority': 1,501                              u'meta_host': u'Athlon',502                              u'job': {u'control_file': u'def step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "mbligh@google.com (Martin Bligh)"\n    NAME = "Kernbench"\n    TIME = "SHORT"\n    TEST_CLASS = "Kernel"\n    TEST_CATEGORY = "Benchmark"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    A standard CPU benchmark. Runs a kernel compile and measures the performance.\n    """\n    \n    job.run_test(\'kernbench\')',503                                       u'name': u'test_on_meta_hosts',504                                       u'control_type': CLIENT,505                                       u'run_verify': 1,506                                       u'priority': priorities.Priority.DEFAULT,507                                       u'owner': u'user0',508                                       u'created_on': u'2008-07-30 22:15:43',509                                       u'timeout': 144,510                                       u'synch_count': 1,511                                       u'id': 6761},512                              u'active': 1,513                              u'id': 193170} ])],514                     out_words_ok=['test_on_meta_hosts',515                                   'host42', 'Queued', 'Running'],516                     out_words_no=['Athlon', 'Xeon', 'x286'])517    def test_job_stat_job_no_host_in_qes(self):518        results = copy.deepcopy(self.results)519        self.run_cmd(argv=['atest', 'job', 'stat', '180'],520                     rpcs=[('get_jobs_summary', {'id__in': ['180']}, True,521                            [results[0]]),522                           ('get_host_queue_entries', {'job__in': ['180']},523                            True,524                            [{u'status': u'Failed',525                              u'complete': 1,526                              u'host': None,527                              u'priority': 1,528                              u'meta_host': None,529                              u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",530                                       u'name': u'test_sleep',531                                       u'control_type': SERVER,532                                       u'priority': priorities.Priority.DEFAULT,533                                       u'owner': u'user0',534                                       u'created_on': u'2008-03-18 11:27:29',535                                       u'synch_count': 1,536                                       u'id': 180},537                              u'active': 0,538                              u'id': 101084}])],539                     err_words_ok=['unassigned', 'meta-hosts'])540    def test_job_stat_multi_jobs(self):541        results = copy.deepcopy(self.results)542        self.run_cmd(argv=['atest', 'job', 'stat', '180', '338'],543                     rpcs=[('get_jobs_summary', {'id__in': ['180', '338']},544                            True, results),545                           ('get_host_queue_entries',546                            {'job__in': ['180', '338']},547                            True,548                            [{u'status': u'Failed',549                              u'complete': 1,550                              u'host': {u'status': u'Repair Failed',551                                        u'locked': False,552                                        u'hostname': u'host0',553                                        u'invalid': True,554                                        u'id': 4432},555                              u'priority': 1,556                              u'meta_host': None,557                              u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",558                                       u'name': u'test_sleep',559                                       u'control_type': SERVER,560                                       u'priority': priorities.Priority.DEFAULT,561                                       u'owner': u'user0',562                                       u'created_on': u'2008-03-18 11:27:29',563                                       u'synch_count': 1,564                                       u'id': 180},565                              u'active': 0,566                              u'id': 101084},567                             {u'status': u'Failed',568                              u'complete': 1,569                              u'host': {u'status': u'Repair Failed',570                                        u'locked': False,571                                        u'hostname': u'host10',572                                        u'invalid': True,573                                        u'id': 4432},574                              u'priority': 1,575                              u'meta_host': None,576                              u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",577                                       u'name': u'test_sleep',578                                       u'control_type': SERVER,579                                       u'priority': priorities.Priority.DEFAULT,580                                       u'owner': u'user0',581                                       u'created_on': u'2008-03-18 11:27:29',582                                       u'synch_count': 1,583                                       u'id': 338},584                              u'active': 0,585                              u'id': 101084}])],586                     out_words_ok=['test_job0', 'test_job1'])587    def test_job_stat_multi_jobs_name_id(self):588        self.run_cmd(argv=['atest', 'job', 'stat', 'mytest', '180'],589                     rpcs=[('get_jobs_summary', {'id__in': ['180']},590                            True,591                            [{u'status_counts': {u'Aborted': 1},592                             u'control_file':593                             u"job.run_test('sleeptest')\n",594                             u'name': u'job0',595                             u'control_type': SERVER,596                             u'priority':597                             priorities.Priority.DEFAULT,598                             u'owner': u'user0',599                             u'created_on':600                             u'2008-07-08 17:45:44',601                             u'synch_count': 2,602                             u'id': 180}]),603                           ('get_jobs_summary', {'name__in': ['mytest']},604                            True,605                            [{u'status_counts': {u'Queued': 1},606                             u'control_file':607                             u"job.run_test('sleeptest')\n",608                             u'name': u'mytest',609                             u'control_type': CLIENT,610                             u'priority':611                             priorities.Priority.DEFAULT,612                             u'owner': u'user0',613                             u'created_on': u'2008-07-08 12:17:47',614                             u'synch_count': 1,615                             u'id': 338}]),616                           ('get_host_queue_entries',617                            {'job__in': ['180']},618                            True,619                            [{u'status': u'Failed',620                              u'complete': 1,621                              u'host': {u'status': u'Repair Failed',622                                        u'locked': False,623                                        u'hostname': u'host0',624                                        u'invalid': True,625                                        u'id': 4432},626                              u'priority': 1,627                              u'meta_host': None,628                              u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",629                                       u'name': u'test_sleep',630                                       u'control_type': SERVER,631                                       u'synchronizing': 0,632                                       u'priority': priorities.Priority.DEFAULT,633                                       u'owner': u'user0',634                                       u'created_on': u'2008-03-18 11:27:29',635                                       u'synch_count': 1,636                                       u'id': 180},637                              u'active': 0,638                              u'id': 101084}]),639                           ('get_host_queue_entries',640                            {'job__name__in': ['mytest']},641                            True,642                            [{u'status': u'Failed',643                              u'complete': 1,644                              u'host': {u'status': u'Repair Failed',645                                        u'locked': False,646                                        u'hostname': u'host10',647                                        u'invalid': True,648                                        u'id': 4432},649                              u'priority': 1,650                              u'meta_host': None,651                              u'job': {u'control_file': u"def run(machine):\n\thost = hosts.create_host(machine)\n\tat = autotest.Autotest(host)\n\tat.run_test('sleeptest')\n\nparallel_simple(run, machines)",652                                       u'name': u'test_sleep',653                                       u'control_type': SERVER,654                                       u'synchronizing': 0,655                                       u'priority': priorities.Priority.DEFAULT,656                                       u'owner': u'user0',657                                       u'created_on': u'2008-03-18 11:27:29',658                                       u'synch_count': 1,659                                       u'id': 338},660                              u'active': 0,661                              u'id': 101084}])],662                     out_words_ok=['job0', 'mytest', 'Aborted', 'Queued',663                                   'Failed', str(priorities.Priority.DEFAULT)])664class job_create_unittest(cli_mock.cli_unittest):665    ctrl_file = '\ndef step_init():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "Autotest Team"\n    NAME = "Sleeptest"\n  TIME =\n    "SHORT"\n    TEST_CATEGORY = "Functional"\n    TEST_CLASS = "General"\n\n    TEST_TYPE = "client"\n \n    DOC = """\n    This test simply sleeps for 1\n    second by default.  It\'s a good way to test\n    profilers and double check\n    that autotest is working.\n The seconds argument can also be modified to\n    make the machine sleep for as\n    long as needed.\n    """\n   \n\n    job.run_test(\'sleeptest\', seconds = 1)'666    kernel_ctrl_file = 'kernel = \'kernel\'\ndef step_init():\n    job.next_step([step_test])\n\ndef step_test():\n    job.next_step(\'step0\')\n\ndef step0():\n    AUTHOR = "Autotest Team"\n    NAME = "Sleeptest"\n    TIME = "SHORT"\n    TEST_CATEGORY = "Functional"\n    TEST_CLASS = "General"\n    TEST_TYPE = "client"\n    \n    DOC = """\n    This test simply sleeps for 1 second by default.  It\'s a good way to test\n    profilers and double check that autotest is working.\n    The seconds argument can also be modified to make the machine sleep for as\n    long as needed.\n    """\n    \n    job.run_test(\'sleeptest\', seconds = 1)'667    trivial_ctrl_file = 'print "Hello"\n'668    data = {'priority': priorities.Priority.DEFAULT, 'control_file': ctrl_file,669            'hosts': ['host0'],670            'name': 'test_job0', 'control_type': CLIENT, 'email_list': '',671            'meta_hosts': [], 'synch_count': 1, 'dependencies': [],672            'require_ssp': False}673    def test_execute_create_job(self):674        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',675                           'test_job0', '-m', 'host0'],676                     rpcs=[('generate_control_file',677                            {'tests': ['sleeptest']},678                            True,679                            {'control_file' : self.ctrl_file,680                             'synch_count' : 1,681                             'is_server' : False,682                             'dependencies' : []}),683                           ('create_job', self.data, True, 180)],684                     out_words_ok=['test_job0', 'Created'],685                     out_words_no=['Uploading', 'Done'])686    def test_execute_create_job_with_control(self):687        file_temp = cli_mock.create_file(self.ctrl_file)688        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,689                           'test_job0', '-m', 'host0'],690                     rpcs=[('create_job', self.data, True, 42)],691                     out_words_ok=['test_job0', 'Created'],692                     out_words_no=['Uploading', 'Done'])693        file_temp.clean()694    def test_execute_create_job_with_control_and_email(self):695        data = self.data.copy()696        data['email_list'] = 'em'697        file_temp = cli_mock.create_file(self.ctrl_file)698        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,699                           'test_job0', '-m', 'host0', '-e', 'em'],700                     rpcs=[('create_job', data, True, 42)],701                     out_words_ok=['test_job0', 'Created'],702                     out_words_no=['Uploading', 'Done'])703        file_temp.clean()704    def test_execute_create_job_with_control_and_dependencies(self):705        data = self.data.copy()706        data['dependencies'] = ['dep1', 'dep2']707        file_temp = cli_mock.create_file(self.ctrl_file)708        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,709                           'test_job0', '-m', 'host0', '-d', 'dep1, dep2 '],710                     rpcs=[('create_job', data, True, 42)],711                     out_words_ok=['test_job0', 'Created'],712                     out_words_no=['Uploading', 'Done'])713        file_temp.clean()714    def test_execute_create_job_with_control_and_comma_dependencies(self):715        data = self.data.copy()716        data['dependencies'] = ['dep2,False', 'dep1,True']717        file_temp = cli_mock.create_file(self.ctrl_file)718        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,719                           'test_job0', '-m', 'host0', '-d',720                           'dep1\,True, dep2\,False '],721                     rpcs=[('create_job', data, True, 42)],722                     out_words_ok=['test_job0', 'Created'],723                     out_words_no=['Uploading', 'Done'])724        file_temp.clean()725    def test_execute_create_job_with_synch_count(self):726        data = self.data.copy()727        data['synch_count'] = 2728        file_temp = cli_mock.create_file(self.ctrl_file)729        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,730                           'test_job0', '-m', 'host0', '-y', '2'],731                     rpcs=[('create_job', data, True, 42)],732                     out_words_ok=['test_job0', 'Created'],733                     out_words_no=['Uploading', 'Done'])734        file_temp.clean()735    def test_execute_create_job_with_test_and_dependencies(self):736        data = self.data.copy()737        data['dependencies'] = ['dep1', 'dep2', 'dep3']738        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',739                           'test_job0', '-m', 'host0', '-d', 'dep1, dep2 '],740                     rpcs=[('generate_control_file',741                            {'tests': ['sleeptest']},742                            True,743                            {'control_file' : self.ctrl_file,744                             'synch_count' : 1,745                             'is_server' : False,746                             'dependencies' : ['dep3']}),747                           ('create_job', data, True, 42)],748                     out_words_ok=['test_job0', 'Created'],749                     out_words_no=['Uploading', 'Done'])750    def test_execute_create_job_with_test_and_comma_dependencies(self):751        data = self.data.copy()752        data['dependencies'] = ['dep1,True', 'dep2,False', 'dep3,123']753        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',754                           'test_job0', '-m', 'host0', '-d',755                           'dep1\,True dep2\,False '],756                     rpcs=[('generate_control_file',757                            {'tests': ['sleeptest']},758                            True,759                            {'control_file' : self.ctrl_file,760                             'synch_count' : 1,761                             'is_server' : False,762                             'dependencies' : ['dep3,123']}),763                           ('create_job', data, True, 42)],764                     out_words_ok=['test_job0', 'Created'],765                     out_words_no=['Uploading', 'Done'])766    def test_execute_create_job_no_args(self):767        testjob = job.job_create()768        sys.argv = ['atest', 'job', 'create']769        self.god.mock_io()770        (sys.exit.expect_call(mock.anything_comparator())771         .and_raises(cli_mock.ExitException))772        self.assertRaises(cli_mock.ExitException, testjob.parse)773        self.god.unmock_io()774        self.god.check_playback()775    def test_execute_create_job_no_hosts(self):776        testjob = job.job_create()777        file_temp = cli_mock.create_file(self.ctrl_file)778        sys.argv = ['atest', '-f', file_temp.name, 'test_job0']779        self.god.mock_io()780        (sys.exit.expect_call(mock.anything_comparator())781         .and_raises(cli_mock.ExitException))782        self.assertRaises(cli_mock.ExitException, testjob.parse)783        self.god.unmock_io()784        self.god.check_playback()785        file_temp.clean()786    def test_execute_create_job_cfile_and_tests(self):787        testjob = job.job_create()788        sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-f',789                    'control_file', 'test_job0', '-m', 'host0']790        self.god.mock_io()791        (sys.exit.expect_call(mock.anything_comparator())792         .and_raises(cli_mock.ExitException))793        self.assertRaises(cli_mock.ExitException, testjob.parse)794        self.god.unmock_io()795        self.god.check_playback()796    def test_execute_create_job_bad_cfile(self):797        testjob = job.job_create()798        sys.argv = ['atest', 'job', 'create', '-f', 'control_file',799                    'test_job0', '-m', 'host0']800        self.god.mock_io()801        (sys.exit.expect_call(mock.anything_comparator())802         .and_raises(IOError))803        self.assertRaises(IOError, testjob.parse)804        self.god.unmock_io()805    def test_execute_create_job_bad_priority(self):806        testjob = job.job_create()807        sys.argv = ['atest', 'job', 'create', '-t', 'sleeptest', '-p', 'Uber',808                    '-m', 'host0', 'test_job0']809        self.god.mock_io()810        (sys.exit.expect_call(mock.anything_comparator())811         .and_raises(cli_mock.ExitException))812        self.assertRaises(cli_mock.ExitException, testjob.parse)813        self.god.unmock_io()814        self.god.check_playback()815    def test_execute_create_job_with_mfile(self):816        data = self.data.copy()817        data['hosts'] = ['host3', 'host2', 'host1', 'host0']818        ctemp = cli_mock.create_file(self.ctrl_file)819        file_temp = cli_mock.create_file('host0\nhost1\nhost2\nhost3')820        self.run_cmd(argv=['atest', 'job', 'create', '--mlist', file_temp.name,821                           '-f', ctemp.name, 'test_job0'],822                     rpcs=[('create_job', data, True, 42)],823                     out_words_ok=['test_job0', 'Created'])824        ctemp.clean()825        file_temp.clean()826    def test_execute_create_job_with_timeout(self):827        data = self.data.copy()828        data['timeout_mins'] = '13320'829        file_temp = cli_mock.create_file(self.ctrl_file)830        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,831                           'test_job0', '-m', 'host0', '-o', '13320'],832                     rpcs=[('create_job', data, True, 42)],833                     out_words_ok=['test_job0', 'Created'],)834        file_temp.clean()835    def test_execute_create_job_with_max_runtime(self):836        data = self.data.copy()837        data['max_runtime_mins'] = '13320'838        file_temp = cli_mock.create_file(self.ctrl_file)839        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,840                           'test_job0', '-m', 'host0', '--max_runtime',841                           '13320'],842                     rpcs=[('create_job', data, True, 42)],843                     out_words_ok=['test_job0', 'Created'],)844        file_temp.clean()845    def test_execute_create_job_with_noverify(self):846        data = self.data.copy()847        data['run_verify'] = False848        file_temp = cli_mock.create_file(self.ctrl_file)849        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,850                           'test_job0', '-m', 'host0', '-n'],851                     rpcs=[('create_job', data, True, 42)],852                     out_words_ok=['test_job0', 'Created'],)853        file_temp.clean()854    def test_execute_create_job_oth(self):855        data = self.data.copy()856        data['hosts'] = []857        data['one_time_hosts'] = ['host0']858        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',859                           'test_job0', '--one-time-hosts', 'host0'],860                     rpcs=[('generate_control_file',861                            {'tests': ['sleeptest']},862                            True,863                            {'control_file' : self.ctrl_file,864                             'synch_count' : 1,865                             'is_server' : False,866                             'dependencies' : []}),867                           ('create_job', data, True, 180)],868                     out_words_ok=['test_job0', 'Created'],869                     out_words_no=['Uploading', 'Done'])870    def test_execute_create_job_multi_oth(self):871        data = self.data.copy()872        data['hosts'] = []873        data['one_time_hosts'] = ['host1', 'host0']874        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',875                           'test_job0', '--one-time-hosts', 'host0,host1'],876                     rpcs=[('generate_control_file',877                            {'tests': ['sleeptest']},878                            True,879                            {'control_file' : self.ctrl_file,880                             'synch_count' : 1,881                             'is_server' : False,882                             'dependencies' : []}),883                           ('create_job', data, True, 180)],884                     out_words_ok=['test_job0', 'Created'],885                     out_words_no=['Uploading', 'Done'])886    def test_execute_create_job_oth_exists(self):887        data = self.data.copy()888        data['hosts'] = []889        data['one_time_hosts'] = ['host0']890        self.run_cmd(argv=['atest', 'job', 'create', '-t', 'sleeptest',891                           'test_job0', '--one-time-hosts', 'host0'],892                     rpcs=[('generate_control_file',893                            {'tests': ['sleeptest']},894                            True,895                            {'control_file' : self.ctrl_file,896                             'synch_count' : 1,897                             'is_server' : False,898                             'dependencies' : []}),899                           ('create_job', data, False,900                            '''ValidationError: {'hostname': 'host0 '''901                            '''already exists in the autotest DB.  '''902                            '''Select it rather than entering it as '''903                            '''a one time host.'}''')],904                     out_words_no=['test_job0', 'Created'],905                     err_words_ok=['failed', 'already exists'])906    def test_execute_create_job_with_control_and_labels(self):907        data = self.data.copy()908        data['hosts'] = ['host0', 'host1', 'host2']909        file_temp = cli_mock.create_file(self.ctrl_file)910        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,911                           'test_job0', '-m', 'host0', '-b', 'label1,label2'],912                     rpcs=[('get_hosts', {'multiple_labels': ['label1',913                            'label2']}, True,914                            [{u'status': u'Running', u'lock_time': None,915                              u'hostname': u'host1', u'locked': False,916                              u'locked_by': None, u'invalid': False, u'id': 42,917                              u'labels': [u'label1'], u'platform':918                              u'Warp18_Diskfull', u'protection':919                              u'Repair software only', u'dirty': True},920                             {u'status': u'Running', u'lock_time': None,921                              u'hostname': u'host2', u'locked': False,922                              u'locked_by': None, u'invalid': False, u'id': 43,923                              u'labels': [u'label2'], u'platform':924                              u'Warp18_Diskfull', u'protection':925                              u'Repair software only', u'dirty': True}]),926                            ('create_job', data, True, 42)],927                     out_words_ok=['test_job0', 'Created'],928                     out_words_no=['Uploading', 'Done'])929        file_temp.clean()930    def test_execute_create_job_with_label_and_duplicate_hosts(self):931        data = self.data.copy()932        data['hosts'] = ['host1', 'host0']933        file_temp = cli_mock.create_file(self.ctrl_file)934        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,935                           'test_job0', '-m', 'host0,host1', '-b', 'label1'],936                     rpcs=[('get_hosts', {'multiple_labels': ['label1']}, True,937                            [{u'status': u'Running', u'lock_time': None,938                              u'hostname': u'host1', u'locked': False,939                              u'locked_by': None, u'invalid': False, u'id': 42,940                              u'labels': [u'label1'], u'platform':941                              u'Warp18_Diskfull', u'protection':942                              u'Repair software only', u'dirty': True}]),943                            ('create_job', data, True, 42)],944                     out_words_ok=['test_job0', 'Created'],945                     out_words_no=['Uploading', 'Done'])946        file_temp.clean()947    def test_execute_create_job_with_label_commas_and_duplicate_hosts(self):948        data = self.data.copy()949        data['hosts'] = ['host1', 'host0']950        file_temp = cli_mock.create_file(self.ctrl_file)951        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,952                           'test_job0', '-m', 'host0,host1', '-b',953                           'label1,label\\,2'],954                     rpcs=[('get_hosts', {'multiple_labels': ['label1',955                            'label,2']}, True,956                            [{u'status': u'Running', u'lock_time': None,957                              u'hostname': u'host1', u'locked': False,958                              u'locked_by': None, u'invalid': False, u'id': 42,959                              u'labels': [u'label1', u'label,2'], u'platform':960                              u'Warp18_Diskfull', u'protection':961                              u'Repair software only', u'dirty': True}]),962                            ('create_job', data, True, 42)],963                     out_words_ok=['test_job0', 'Created'],964                     out_words_no=['Uploading', 'Done'])965        file_temp.clean()966    def test_execute_create_job_with_label_escaping_and_duplicate_hosts(self):967        data = self.data.copy()968        data['hosts'] = ['host1', 'host0']969        file_temp = cli_mock.create_file(self.ctrl_file)970        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,971                           'test_job0', '-m', 'host0,host1', '-b',972                           'label1,label\\,2\\\\,label3'],973                     rpcs=[('get_hosts', {'multiple_labels': ['label,2\\',974                            'label1', 'label3']}, True,975                            [{u'status': u'Running', u'lock_time': None,976                              u'hostname': u'host1', u'locked': False,977                              u'locked_by': None, u'invalid': False, u'id': 42,978                              u'labels': [u'label1', u'label,2\\', u'label3'],979                              u'platform': u'Warp18_Diskfull', u'protection':980                              u'Repair software only', u'dirty': True}]),981                            ('create_job', data, True, 42)],982                     out_words_ok=['test_job0', 'Created'],983                     out_words_no=['Uploading', 'Done'])984        file_temp.clean()985    def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]):986        testjob = job.job_create_or_clone()987        (hosts, meta_hosts) = testjob._parse_hosts(args)988        self.assertEqualNoOrder(hosts, exp_hosts)989        self.assertEqualNoOrder(meta_hosts, exp_meta_hosts)990    def test_parse_hosts_regular(self):991        self._test_parse_hosts(['host0'], ['host0'])992    def test_parse_hosts_regulars(self):993        self._test_parse_hosts(['host0', 'host1'], ['host0', 'host1'])994    def test_parse_hosts_meta_one(self):995        self._test_parse_hosts(['*meta0'], [], ['meta0'])996    def test_parse_hosts_meta_five(self):997        self._test_parse_hosts(['5*meta0'], [], ['meta0']*5)998    def test_parse_hosts_metas_five(self):999        self._test_parse_hosts(['5*meta0', '2*meta1'], [],1000                               ['meta0']*5 + ['meta1']*2)1001    def test_parse_hosts_mix(self):1002        self._test_parse_hosts(['5*meta0', 'host0', '2*meta1', 'host1',1003                                '*meta2'], ['host0', 'host1'],1004                               ['meta0']*5 + ['meta1']*2 + ['meta2'])1005class job_clone_unittest(cli_mock.cli_unittest):1006    job_data = {'control_file': u'NAME = \'Server Sleeptest\'\nAUTHOR = \'mbligh@google.com (Martin Bligh)\'\nTIME = \'SHORT\'\nTEST_CLASS = \'Software\'\nTEST_CATEGORY = \'Functional\'\nTEST_TYPE = \'server\'\nEXPERIMENTAL = \'False\'\n\nDOC = """\nruns sleep for one second on the list of machines.\n"""\n\ndef run(machine):\n    host = hosts.create_host(machine)\n    job.run_test(\'sleeptest\')\n\njob.parallel_simple(run, machines)\n',1007                    'control_type': SERVER,1008                    'dependencies': [],1009                    'email_list': u'',1010                    'max_runtime_mins': 28800,1011                    'parse_failed_repair': True,1012                    'priority': priorities.Priority.DEFAULT,1013                    'reboot_after': u'Always',1014                    'reboot_before': u'If dirty',1015                    'run_verify': True,1016                    'synch_count': 1,1017                    'timeout_mins': 480}1018    local_hosts = [{u'acls': [u'acl0'],1019                    u'attributes': {},1020                    u'dirty': False,1021                    u'hostname': u'host0',1022                    u'id': 8,1023                    u'invalid': False,1024                    u'labels': [u'label0', u'label1'],1025                    u'lock_time': None,1026                    u'locked': False,1027                    u'locked_by': None,1028                    u'other_labels': u'label0, label1',1029                    u'platform': u'plat0',1030                    u'protection': u'Repair software only',1031                    u'status': u'Ready'},1032                   {u'acls': [u'acl0'],1033                    u'attributes': {},1034                    u'dirty': False,1035                    u'hostname': u'host1',1036                    u'id': 9,1037                    u'invalid': False,1038                    u'labels': [u'label0', u'label1'],1039                    u'lock_time': None,1040                    u'locked': False,1041                    u'locked_by': None,1042                    u'other_labels': u'label0, label1',1043                    u'platform': u'plat0',1044                    u'protection': u'Repair software only',1045                    u'status': u'Ready'}]1046    def setUp(self):1047        super(job_clone_unittest, self).setUp()1048        self.job_data_clone_info = copy.deepcopy(self.job_data)1049        self.job_data_clone_info['created_on'] = '2009-07-23 16:21:29'1050        self.job_data_clone_info['name'] = 'testing_clone'1051        self.job_data_clone_info['id'] = 421052        self.job_data_clone_info['owner'] = 'user0'1053        self.job_data_cloned = copy.deepcopy(self.job_data)1054        self.job_data_cloned['name'] = 'cloned'1055        self.job_data_cloned['hosts'] = [u'host0']1056        self.job_data_cloned['meta_hosts'] = []1057    def test_backward_compat(self):1058        self.run_cmd(argv=['atest', 'job', 'create', '--clone', '42',1059                           '-r', 'cloned'],1060                     rpcs=[('get_info_for_clone', {'id': '42',1061                                                   'preserve_metahosts': True},1062                            True,1063                            {u'hosts': [{u'acls': [u'acl0'],1064                                         u'attributes': {},1065                                         u'dirty': False,1066                                         u'hostname': u'host0',1067                                         u'id': 4378,1068                                         u'invalid': False,1069                                         u'labels': [u'label0', u'label1'],1070                                         u'lock_time': None,1071                                         u'locked': False,1072                                         u'locked_by': None,1073                                         u'other_labels': u'label0, label1',1074                                         u'platform': u'plat0',1075                                         u'protection': u'Repair software only',1076                                         u'status': u'Ready'}],1077                             u'job': self.job_data_clone_info,1078                             u'meta_host_counts': {}}),1079                           ('create_job', self.job_data_cloned, True, 43)],1080                     out_words_ok=['Created job', '43'])1081    def test_clone_reuse_hosts(self):1082        self.job_data_cloned['hosts'] = [u'host0', 'host1']1083        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',1084                           '-r', 'cloned'],1085                     rpcs=[('get_info_for_clone', {'id': '42',1086                                                   'preserve_metahosts': True},1087                            True,1088                            {u'hosts': self.local_hosts,1089                             u'job': self.job_data_clone_info,1090                             u'meta_host_counts': {}}),1091                           ('create_job', self.job_data_cloned, True, 43)],1092                     out_words_ok=['Created job', '43'])1093    def test_clone_reuse_metahosts(self):1094        self.job_data_cloned['hosts'] = []1095        self.job_data_cloned['meta_hosts'] = ['type1']*4 +  ['type0']1096        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',1097                           '-r', 'cloned'],1098                     rpcs=[('get_info_for_clone', {'id': '42',1099                                                   'preserve_metahosts': True},1100                            True,1101                            {u'hosts': [],1102                             u'job': self.job_data_clone_info,1103                             u'meta_host_counts': {u'type0': 1,1104                                                   u'type1': 4}}),1105                           ('create_job', self.job_data_cloned, True, 43)],1106                     out_words_ok=['Created job', '43'])1107    def test_clone_reuse_both(self):1108        self.job_data_cloned['hosts'] = [u'host0', 'host1']1109        self.job_data_cloned['meta_hosts'] = ['type1']*4 +  ['type0']1110        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',1111                           '-r', 'cloned'],1112                     rpcs=[('get_info_for_clone', {'id': '42',1113                                                   'preserve_metahosts': True},1114                            True,1115                            {1116                             u'hosts': self.local_hosts,1117                             u'job': self.job_data_clone_info,1118                             u'meta_host_counts': {u'type0': 1,1119                                                   u'type1': 4}}),1120                           ('create_job', self.job_data_cloned, True, 43)],1121                     out_words_ok=['Created job', '43'])1122    def test_clone_no_hosts(self):1123        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42', 'cloned'],1124                     exit_code=1,1125                     out_words_ok=['usage'],1126                     err_words_ok=['machine'])1127    def test_clone_reuse_and_hosts(self):1128        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',1129                           '-r', '-m', 'host5', 'cloned'],1130                     exit_code=1,1131                     out_words_ok=['usage'],1132                     err_words_ok=['specify'])1133    def test_clone_new_multiple_hosts(self):1134        self.job_data_cloned['hosts'] = [u'host5', 'host4', 'host3']1135        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',1136                           '-m', 'host5,host4,host3', 'cloned'],1137                     rpcs=[('get_info_for_clone', {'id': '42',1138                                                   'preserve_metahosts': False},1139                            True,1140                            {u'hosts': self.local_hosts,1141                             u'job': self.job_data_clone_info,1142                             u'meta_host_counts': {}}),1143                           ('create_job', self.job_data_cloned, True, 43)],1144                     out_words_ok=['Created job', '43'])1145    def test_clone_oth(self):1146        self.job_data_cloned['hosts'] = []1147        self.job_data_cloned['one_time_hosts'] = [u'host5']1148        self.run_cmd(argv=['atest', 'job', 'clone', '--id', '42',1149                           '--one-time-hosts', 'host5', 'cloned'],1150                     rpcs=[('get_info_for_clone', {'id': '42',1151                                                   'preserve_metahosts': False},1152                            True,1153                            {u'hosts': self.local_hosts,1154                             u'job': self.job_data_clone_info,1155                             u'meta_host_counts': {}}),1156                           ('create_job', self.job_data_cloned, True, 43)],1157                     out_words_ok=['Created job', '43'])1158class job_abort_unittest(cli_mock.cli_unittest):1159    results = [{u'status_counts': {u'Aborted': 1}, u'control_file':1160                u"job.run_test('sleeptest')\n", u'name': u'test_job0',1161                u'control_type': SERVER, u'priority':1162                priorities.Priority.DEFAULT, u'owner': u'user0', u'created_on':1163                u'2008-07-08 17:45:44', u'synch_count': 2, u'id': 180}]1164    def test_execute_job_abort(self):1165        self.run_cmd(argv=['atest', 'job', 'abort', '180'],1166                     rpcs=[('abort_host_queue_entries',1167                            {'job__id__in': ['180']}, True, None)],1168                     out_words_ok=['Aborting', '180'])1169if __name__ == '__main__':...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
