def test_executions__day_executions__multiple_clients__first_client_with_last_day_empty(self): a_project = Project('project name') a_client = Client('a_client') a_client2 = Client('a_client2') listener1 = ServerListener( client=a_client, project=a_project ) listener1.current_time = lambda : "2006-04-29-12-12-00" listener2 = ServerListener( client=a_client2, project=a_project ) listener2.current_time = lambda : "2006-04-29-12-00-00" generator = WebGenerator(project_name= a_project.name) task = Task(a_project, a_client, 'task') task.add_subtask('subtask1', []) Runner(task, testinglisteners=[listener1]) task = Task(a_project, a_client2, 'task') task.add_subtask('subtask1', []) Runner(task, testinglisteners=[listener2]) listener2.current_time = lambda : "2006-04-30-12-00-00" Runner(task, testinglisteners=[listener2]) self.assertEquals( {'2006-04-30': {'a_client2': [('2006-04-30-12-00-00', '2006-04-30-12-00-00', 'task', 'stable')]}, '2006-04-29': {'a_client2': [('2006-04-29-12-00-00', '2006-04-29-12-00-00', 'task', 'stable')], 'a_client': [('2006-04-29-12-12-00', '2006-04-29-12-12-00', 'task', 'stable')] } }, generator.day_executions(generator.get_executions()) )
def test_stats_single_client_multiple_key(self): a_project = Project('project name') a_client = Client('a_client') listener = ServerListener( client=a_client, project=a_project ) generator = WebGenerator(project_name= a_project.name) listener.current_time = lambda : "2006-04-04-00-00-00" task = Task(a_project, a_client, 'task') task.add_subtask("subtask", [{STATS:lambda x: {'key1':5, 'key2':0} }] ) Runner(task, testinglisteners=[listener]) listener.current_time = lambda : "2006-04-05-00-00-00" task = Task(a_project, a_client, 'task') task.add_subtask("subtask", [{STATS:lambda x: {'key1':-1, 'key2':4} }] ) Runner(task, testinglisteners=[listener]) self.assertEquals( { 'a_client': { 'subtask': [ ('2006-04-04-00-00-00', {'key2': 0, 'key1': 5}), ('2006-04-05-00-00-00', {'key2': 4, 'key1': -1}) ] } }, generator.collect_stats() )
def test_two_clients(self): a_project = Project('project name') a_client = Client('client 1') a_client2 = Client('client 2') listener1 = ServerListener( client=a_client, logs_base_dir='/tmp/clients_testdir', project=a_project) listener2 = ServerListener( client=a_client2, logs_base_dir='/tmp/clients_testdir', project=a_project) listener1.current_time = lambda : "some date" listener2.current_time = lambda : "some other date" generator = WebGenerator(logs_base_dir='/tmp/clients_testdir', project_name= a_project.name) task = Task(a_project, a_client, 'task') task.add_subtask('subtask1', []) Runner(task, testinglisteners=[listener1]) task = Task(a_project, a_client2, 'task') task.add_subtask('subtask1', []) Runner(task, testinglisteners=[listener2]) self.assertEquals( {'client 1':[('some date', 'some date', 'task', 'stable')], 'client 2':[('some other date', 'some other date', 'task', 'stable')]}, generator.get_executions() ) listener1.clean_log_files() listener2.clean_log_files()
def test_purged_details(self): a_project = Project('project name') a_client = Client('a_client') listener = ServerListener( client=a_client, project=a_project ) generator = WebGenerator(project_name= a_project.name) listener.current_time = lambda : "1999-99-99-99-99-99" listener.listen_begin_task("we want this one") listener.listen_begin_subtask("subtask") listener.listen_begin_command("a command") listener.listen_end_command("a command", False, "some output", "some info", {'a':1}) listener.listen_begin_command("a command") listener.listen_end_command("a command", False, "some more output", "some more info", {'a':1}) listener.listen_end_subtask("subtask") listener.current_time = lambda : "2000-00-00-00-00-00" listener.listen_end_task("we want this one", False) expected = [ ('BEGIN_TASK', 'we want this one', '1999-99-99-99-99-99'), ('BEGIN_SUBTASK', 'subtask'), ('BEGIN_CMD', 'a command'), ('END_CMD', 'a command', False, 'some output', 'some info', {'a':1}), ('BEGIN_CMD', 'a command'), ('END_CMD', 'a command', False, 'some more output','some more info', {'a':1}), ('END_SUBTASK', 'subtask'), ('END_TASK', 'we want this one', '2000-00-00-00-00-00', 'False'), ] generator.purge_client_logfile('a_client','1999-99-99-99-99-99') self.assertEquals( expected, generator.single_execution_details('a_client', '1999-99-99-99-99-99') )
def test_executions__one_green_execution(self): a_project = Project('project name') listener = ServerListener( project = a_project) listener.current_time = lambda : "a date" generator = WebGenerator(project_name= a_project.name) a_client = Client('client name') task = Task(a_project, a_client, 'task') task.add_subtask('subtask1', []) Runner(task, testinglisteners=[listener]) self.assertEquals( {'testing_client' : [('a date', 'a date', 'task', 'stable')]}, generator.get_executions() )
def test_no_stats(self): a_project = Project('project name') a_client = Client('a_client') listener = ServerListener( client=a_client, project=a_project ) generator = WebGenerator(project_name= a_project.name) listener.current_time = lambda : "2006-04-04-00-00-00" task = Task(a_project, a_client, 'task') task.add_subtask("subtask", ["echo no stats"] ) Runner(task, testinglisteners=[listener]) self.assertEquals( {'a_client': {} }, generator.collect_stats() )
def test_project_info__more_info(self): a_project = Project('project name') a_client = Client('client name') a_project.brief_description = "a brief description" a_project.set_attribute('one more attribute', 'one_more_value') a_project.set_attribute('another_attribute', 'another value') listener = ServerListener( client = a_client, project = a_project) generator = WebGenerator(project_name = a_project.name) self.assertEquals( [('Brief description', 'a brief description'), ('another_attribute', 'another value'), ('one more attribute', 'one_more_value')] , generator.load_project_info())
def test_idles(self): a_project = Project('project name') a_client = Client('a_client') listener = ServerListener( client=a_client, project=a_project ) listener.current_time = lambda : "a date" generator = WebGenerator(project_name= a_project.name) task = Task(a_project, a_client, 'task') task.set_check_for_new_commits( checking_cmd="echo P patched_file | grep ^[UP]", minutes_idle=1 ) Runner(task, testinglisteners=[listener]) self.assertEquals( {'a_client' : {'date':'a date', 'new_commits_found': True, 'next_run_in_seconds':60 } }, generator.idle() )
def test_executions__day_executions__single_client(self): a_project = Project('project name') listener = ServerListener( project = a_project) listener.current_time = lambda : "2006-04-29-12-00-00" a_project = Project('project name') generator = WebGenerator(project_name= a_project.name) a_client = Client('client name') task = Task(a_project, a_client, 'task') task.add_subtask('subtask1', []) Runner(task, testinglisteners=[listener]) listener.current_time = lambda : "2006-04-30-12-00-00" Runner(task, testinglisteners=[listener]) self.assertEquals( {'2006-04-30': {'testing_client': [('2006-04-30-12-00-00', '2006-04-30-12-00-00', 'task', 'stable')]}, '2006-04-29': {'testing_client': [('2006-04-29-12-00-00', '2006-04-29-12-00-00', 'task', 'stable')]} }, generator.day_executions(generator.get_executions()) )
def test_send_task_info(self): a_project = Project('project name') a_client = Client('client name') listener = ServerListener( client = a_client, project = a_project) generator = WebGenerator(project_name = a_project.name) task = Task(a_project, a_client, 'task') task.add_subtask('subtask1', ["echo subtask1"]) task.add_subtask('subtask2', [{CMD:"echo something echoed", INFO: lambda x:x}]) listener.listen_task_info(task) self.assertEquals( [('BEGIN_TASK', 'task'), ('BEGIN_SUBTASK', 'subtask1'), ('CMD', 'echo subtask1'), ('END_SUBTASK', 'subtask1'), ('BEGIN_SUBTASK', 'subtask2'), ('CMD', 'echo something echoed'), ('END_SUBTASK', 'subtask2'), ('END_TASK', 'task'),] , generator.load_task_info(a_client.name))#, task.name))
def test_plot_data_file(self): a_project = Project('project name') a_client = Client('client1') a_client2 = Client('client2') listener1 = ServerListener( client=a_client, project=a_project ) listener2 = ServerListener( client=a_client2, project=a_project ) generator = WebGenerator(project_name= a_project.name) listener1.current_time = lambda : "2006-04-04-00-00-00" task = Task(a_project, a_client, 'task') task.add_subtask("subtask", [{STATS:lambda x: {'key':5} }] ) Runner(task, testinglisteners=[listener1]) listener1.current_time = lambda : "2006-04-05-00-00-00" task = Task(a_project, a_client, 'task') task.add_subtask("subtask", [{STATS:lambda x: {'kk':3} }, {STATS:lambda x: {'key':1, 'key2':2} }] ) Runner(task, testinglisteners=[listener1]) listener2.current_time = lambda : "2000-01-01-12-54-00" task = Task(a_project, a_client, 'task') task.add_subtask("subtask", [{STATS:lambda x: {'clau 1':0, 'clau 2':10} }] ) task.add_subtask("another subtask", [{STATS:lambda x: {'clau 1':2, 'clau 2':13} }] ) Runner(task, testinglisteners=[listener2]) generator.plot_stats() self.assertEquals('''\ time kk key2 key 2006/04/04.00:00 - - 5 2006/04/05.00:00 3 - - 2006/04/05.00:00 - 2 1 ''', open("%s/%s/client1_1.plot" % (generator.logs_base_dir, generator.project_name)).read() ) self.assertEquals('''\ time clau_1 clau_2 2000/01/01.12:54 0 10 ''', open("%s/%s/client2_1.plot" % (generator.logs_base_dir, generator.project_name)).read() ) self.assertEquals('''\ time clau_1 clau_2 2000/01/01.12:54 2 13 ''', open("%s/%s/client2_2.plot" % (generator.logs_base_dir, generator.project_name)).read() )
def test_stats_multiple_client_single_key(self): a_project = Project('project name') a_client = Client('client1') a_client2 = Client('client2') listener1 = ServerListener( client=a_client, project=a_project ) listener2 = ServerListener( client=a_client2, project=a_project ) generator = WebGenerator(project_name= a_project.name) listener1.current_time = lambda : "2006-04-04-00-00-00" task = Task(a_project, a_client, 'task') task.add_subtask("subtask", [{STATS:lambda x: {'key':5} }] ) Runner(task, testinglisteners=[listener1]) listener1.current_time = lambda : "2006-04-05-00-00-00" task = Task(a_project, a_client, 'task') task.add_subtask("subtask", [{STATS:lambda x: {'key':1} }] ) Runner(task, testinglisteners=[listener1]) listener2.current_time = lambda : "1000-00-00-00-00-00" task = Task(a_project, a_client, 'task') task.add_subtask("subtask", [{STATS:lambda x: {'clau':0} }] ) Runner(task, testinglisteners=[listener2]) self.assertEquals( { 'client1': { 'subtask': [ ('2006-04-04-00-00-00', {'key': 5}), ('2006-04-05-00-00-00', {'key': 1}) ] }, 'client2': {'subtask': [ ('1000-00-00-00-00-00', {'clau': 0}) ] } }, generator.collect_stats() )
def __init__(self, task, continuous=False, first_run_always=True, local_base_dir = None, remote_server_url = None, verbose = False, testinglisteners = [], extra_listeners = [], ) : "Runs a task defined in user's script" self.listeners = [ ConsoleResultListener() ] serverlistener = None # for keyboard interrupt purpose if remote_server_url: listenerproxy = ServerListenerProxy( client=task.client, service_url=remote_server_url, project=task.project ) self.listeners.append( listenerproxy ) if local_base_dir : serverlistener = ServerListener( client=task.client, logs_base_dir=local_base_dir + "/logs", project=task.project ) self.listeners.append( serverlistener ) server_to_push = WebGenerator( logs_base_dir=local_base_dir + "/logs", html_base_dir=local_base_dir + "/html", project_name=task.project.name) else: server_to_push = None if testinglisteners: self.listeners = testinglisteners self.listeners += extra_listeners try : #do_subtasks at least one time new_commits_found = task.do_checking_for_new_commits( self.listeners, verbose=verbose ) #this creates a valid .idle file print "first_run_always ",first_run_always print "new commits_found ", new_commits_found if first_run_always or new_commits_found : task.do_subtasks( self.listeners, server_to_push = server_to_push, verbose=verbose ) while continuous : new_commits_found = task.do_checking_for_new_commits( self.listeners, verbose=verbose ) if new_commits_found: time.sleep(2) #avoid having executions with the same time task.do_subtasks( self.listeners, server_to_push = server_to_push, verbose=verbose ) else: if server_to_push: #update idle time display server_to_push.update_static_html_files() time.sleep( task.seconds_idle ) except KeyboardInterrupt : task.stop_execution_gently(self.listeners, server_to_push = server_to_push)
def test_project_info__only_name(self): a_project = Project('project name') a_client = Client('client name') listener = ServerListener( client = a_client, project = a_project) generator = WebGenerator(project_name = a_project.name) self.assertEquals(None, generator.load_project_info())
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # from webgenerator import WebGenerator import os, time _logs_base_dir = '/var/www/testfarm_logs' _html_base_dir = '/var/www/testfarm_html' webgenerator = WebGenerator(logs_base_dir=_logs_base_dir, html_base_dir=_html_base_dir) def update_projects_static_html_files(): "Updates all projects's html files" list_dir = os.listdir(_html_base_dir) print list_dir for entry in list_dir: entry_path = os.path.join(_html_base_dir, entry) if os.path.isdir(entry_path): webgenerator.project_name = entry webgenerator.write_missing_details_static_html() webgenerator.update_static_html_files() update_projects_static_html_files()