<s> import sys <EOL> import os <EOL> import subprocess <EOL> import time <EOL> import fcntl <EOL> import select <EOL> import errno <EOL> import datetime <EOL> import signal <EOL> import json <EOL> import testing <EOL> COVERAGE_DIR = "<STR_LIT>" <EOL> def setnonblocking ( fd ) : <EOL> fcntl . fcntl ( fd , fcntl . F_SETFL , fcntl . fcntl ( fd , fcntl . F_GETFL ) | os . O_NONBLOCK ) <EOL> class HostCommandError ( testing . CommandError ) : <EOL> pass <EOL> class GuestCommandError ( testing . CommandError ) : <EOL> pass <EOL> class Instance ( testing . Instance ) : <EOL> def __init__ ( self , arguments , install_commit = None , upgrade_commit = None , <EOL> frontend = None ) : <EOL> super ( Instance , self ) . __init__ ( ) <EOL> self . arguments = arguments <EOL> self . vboxhost = getattr ( arguments , "<STR_LIT>" , "<STR_LIT:host>" ) <EOL> self . identifier = arguments . vm_identifier <EOL> self . snapshot = arguments . vm_snapshot <EOL> self . hostname = arguments . vm_hostname or self . identifier <EOL> self . ssh_port = arguments . vm_ssh_port <EOL> if install_commit : <EOL> self . install_commit , self . install_commit_description = install_commit <EOL> self . tested_commit = self . install_commit <EOL> if upgrade_commit : <EOL> self . upgrade_commit , self . upgrade_commit_description = upgrade_commit <EOL> if self . upgrade_commit : <EOL> self . tested_commit = self . upgrade_commit <EOL> self . frontend = frontend <EOL> self . strict_fs_permissions = getattr ( arguments , "<STR_LIT>" , False ) <EOL> self . coverage = getattr ( arguments , "<STR_LIT>" , False ) <EOL> self . mailbox = None <EOL> self . etc_dir = "<STR_LIT>" <EOL> output = subprocess . check_output ( <EOL> [ "<STR_LIT>" , "<STR_LIT:list>" , "<STR_LIT>" ] , <EOL> stderr = subprocess . STDOUT ) <EOL> if not self . __isincluded ( output ) : <EOL> raise testing . Error ( "<STR_LIT>" % self . identifier ) <EOL> count = self . count_snapshots ( self . snapshot ) <EOL> if count == <NUM_LIT:0> : <EOL> raise testing . Error ( "<STR_LIT>" <EOL> % self . snapshot ) <EOL> elif count > <NUM_LIT:1> : <EOL> raise testing . Error ( "<STR_LIT>" <EOL> % self . snapshot ) <EOL> state = self . state ( ) <EOL> if state != "<STR_LIT>" : <EOL> raise testing . Error ( "<STR_LIT>" <EOL> % state ) <EOL> self . __reset ( ) <EOL> def __reset ( self ) : <EOL> self . __started = False <EOL> self . __installed = False <EOL> self . __upgraded = False <EOL> self . resetusers ( ) <EOL> self . registeruser ( "<STR_LIT>" ) <EOL> def __enter__ ( self ) : <EOL> return self <EOL> def __exit__ ( self , * args ) : <EOL> if self . __started : <EOL> self . stop ( ) <EOL> self . __reset ( ) <EOL> return False <EOL> def __vmcommand ( self , command , * arguments ) : <EOL> argv = [ "<STR_LIT>" , command , self . identifier ] + list ( arguments ) <EOL> try : <EOL> testing . logger . debug ( "<STR_LIT>" + "<STR_LIT:U+0020>" . join ( argv ) ) <EOL> return subprocess . check_output ( argv , stderr = subprocess . STDOUT ) <EOL> except subprocess . CalledProcessError as error : <EOL> raise HostCommandError ( argv , error . output ) <EOL> def __isincluded ( self , output ) : <EOL> name = '<STR_LIT>' % self . identifier <EOL> uuid = '<STR_LIT>' % self . identifier <EOL> for line in output . splitlines ( ) : <EOL> if name in line or uuid in line : <EOL> return True <EOL> else : <EOL> return False <EOL> def isrunning ( self ) : <EOL> output = subprocess . check_output ( <EOL> [ "<STR_LIT>" , "<STR_LIT:list>" , "<STR_LIT>" ] , <EOL> stderr = subprocess . STDOUT ) <EOL> return self . __isincluded ( output ) <EOL> def state ( self ) : <EOL> output = self . __vmcommand ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> for line in output . splitlines ( ) : <EOL> if line . startswith ( "<STR_LIT>" ) : <EOL> return eval ( line [ len ( "<STR_LIT>" ) : ] ) <EOL> return "<STR_LIT>" <EOL> def count_snapshots ( self , identifier ) : <EOL> try : <EOL> output = subprocess . check_output ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , self . identifier , "<STR_LIT:list>" ] , <EOL> stderr = subprocess . STDOUT ) <EOL> except subprocess . CalledProcessError : <EOL> return <NUM_LIT:0> <EOL> else : <EOL> name = "<STR_LIT>" % identifier <EOL> uuid = "<STR_LIT>" % identifier <EOL> count = <NUM_LIT:0> <EOL> for line in output . splitlines ( ) : <EOL> if name in line or uuid in line : <EOL> count += <NUM_LIT:1> <EOL> return count <EOL> def wait ( self ) : <EOL> testing . logger . debug ( "<STR_LIT>" ) <EOL> while True : <EOL> try : <EOL> self . execute ( [ "<STR_LIT:true>" ] , timeout = <NUM_LIT:1> ) <EOL> except GuestCommandError : <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> else : <EOL> break <EOL> def start ( self ) : <EOL> testing . logger . debug ( "<STR_LIT>" % self . identifier ) <EOL> self . __vmcommand ( "<STR_LIT>" , "<STR_LIT>" , self . snapshot ) <EOL> self . __vmcommand ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . __started = True <EOL> self . wait ( ) <EOL> now = datetime . datetime . utcnow ( ) . strftime ( "<STR_LIT>" ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT:date>" , "<STR_LIT>" , now ] ) <EOL> testing . logger . info ( "<STR_LIT>" % self . identifier ) <EOL> def stop ( self ) : <EOL> testing . logger . debug ( "<STR_LIT>" % self . identifier ) <EOL> self . __vmcommand ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> while self . state ( ) != "<STR_LIT>" : <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> testing . logger . info ( "<STR_LIT>" % self . identifier ) <EOL> def retake_snapshot ( self , name ) : <EOL> index = <NUM_LIT:1> <EOL> while True : <EOL> temporary_name = "<STR_LIT>" % ( name , index ) <EOL> if self . count_snapshots ( temporary_name ) == <NUM_LIT:0> : <EOL> break <EOL> index += <NUM_LIT:1> <EOL> self . __vmcommand ( "<STR_LIT>" , "<STR_LIT>" , temporary_name , "<STR_LIT>" ) <EOL> self . __vmcommand ( "<STR_LIT>" , "<STR_LIT>" , name ) <EOL> self . __vmcommand ( "<STR_LIT>" , "<STR_LIT>" , temporary_name , "<STR_LIT>" , name ) <EOL> def execute ( self , argv , cwd = None , timeout = None , interactive = False , <EOL> as_user = None , log_stdout = True , log_stderr = True ) : <EOL> guest_argv = list ( argv ) <EOL> if cwd is not None : <EOL> guest_argv [ : <NUM_LIT:0> ] = [ "<STR_LIT>" , cwd , "<STR_LIT>" ] <EOL> host_argv = [ "<STR_LIT>" ] <EOL> if self . ssh_port != <NUM_LIT> : <EOL> host_argv . extend ( [ "<STR_LIT>" , str ( self . ssh_port ) ] ) <EOL> if timeout is not None : <EOL> host_argv . extend ( [ "<STR_LIT>" , "<STR_LIT>" % timeout ] ) <EOL> if not interactive : <EOL> host_argv . append ( "<STR_LIT>" ) <EOL> if as_user is not None : <EOL> host_argv . extend ( [ "<STR_LIT>" , as_user ] ) <EOL> host_argv . append ( self . hostname ) <EOL> testing . logger . debug ( "<STR_LIT>" + "<STR_LIT:U+0020>" . join ( host_argv + guest_argv ) ) <EOL> process = subprocess . Popen ( <EOL> host_argv + guest_argv , <EOL> stdout = subprocess . PIPE if not interactive else None , <EOL> stderr = subprocess . PIPE if not interactive else None ) <EOL> class BufferedLineReader ( object ) : <EOL> def __init__ ( self , source ) : <EOL> self . source = source <EOL> self . buffer = "<STR_LIT>" <EOL> def readline ( self ) : <EOL> try : <EOL> while self . source is not None : <EOL> try : <EOL> line , self . buffer = self . buffer . split ( "<STR_LIT:\n>" , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> return line + "<STR_LIT:\n>" <EOL> data = self . source . read ( <NUM_LIT> ) <EOL> if not data : <EOL> self . source = None <EOL> break <EOL> self . buffer += data <EOL> line = self . buffer <EOL> self . buffer = "<STR_LIT>" <EOL> return line <EOL> except IOError as error : <EOL> if error . errno == errno . EAGAIN : <EOL> return None <EOL> raise <EOL> stdout_data = "<STR_LIT>" <EOL> stdout_reader = BufferedLineReader ( process . stdout ) <EOL> stderr_data = "<STR_LIT>" <EOL> stderr_reader = BufferedLineReader ( process . stderr ) <EOL> if not interactive : <EOL> setnonblocking ( process . stdout ) <EOL> setnonblocking ( process . stderr ) <EOL> poll = select . poll ( ) <EOL> poll . register ( process . stdout ) <EOL> poll . register ( process . stderr ) <EOL> stdout_done = False <EOL> stderr_done = False <EOL> while not ( stdout_done and stderr_done ) : <EOL> poll . poll ( ) <EOL> while not stdout_done : <EOL> line = stdout_reader . readline ( ) <EOL> if line is None : <EOL> break <EOL> elif not line : <EOL> poll . unregister ( process . stdout ) <EOL> stdout_done = True <EOL> break <EOL> else : <EOL> stdout_data += line <EOL> if log_stdout : <EOL> testing . logger . log ( testing . STDOUT , line . rstrip ( "<STR_LIT:\n>" ) ) <EOL> while not stderr_done : <EOL> line = stderr_reader . readline ( ) <EOL> if line is None : <EOL> break <EOL> elif not line : <EOL> poll . unregister ( process . stderr ) <EOL> stderr_done = True <EOL> break <EOL> else : <EOL> stderr_data += line <EOL> if log_stderr : <EOL> testing . logger . log ( testing . STDERR , line . rstrip ( "<STR_LIT:\n>" ) ) <EOL> process . wait ( ) <EOL> if process . returncode != <NUM_LIT:0> : <EOL> raise GuestCommandError ( argv , stdout_data , stderr_data ) <EOL> return stdout_data <EOL> def copyto ( self , source , target , as_user = None ) : <EOL> target = "<STR_LIT>" % ( self . hostname , target ) <EOL> if as_user : <EOL> target = "<STR_LIT>" % ( as_user , target ) <EOL> argv = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , str ( self . ssh_port ) , source , target ] <EOL> try : <EOL> testing . logger . debug ( "<STR_LIT>" + "<STR_LIT:U+0020>" . join ( argv ) ) <EOL> return subprocess . check_output ( argv , stderr = subprocess . STDOUT ) <EOL> except subprocess . CalledProcessError as error : <EOL> raise GuestCommandError ( argv , error . output ) <EOL> def copyfrom ( self , source , target , as_user = None ) : <EOL> source = "<STR_LIT>" % ( self . hostname , source ) <EOL> if as_user : <EOL> source = "<STR_LIT>" % ( as_user , source ) <EOL> argv = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , str ( self . ssh_port ) , source , target ] <EOL> try : <EOL> testing . logger . debug ( "<STR_LIT>" + "<STR_LIT:U+0020>" . join ( argv ) ) <EOL> return subprocess . check_output ( argv , stderr = subprocess . STDOUT ) <EOL> except subprocess . CalledProcessError as error : <EOL> raise GuestCommandError ( argv , error . output ) <EOL> def criticctl ( self , argv ) : <EOL> try : <EOL> return self . execute ( [ "<STR_LIT>" , "<STR_LIT>" ] + argv ) <EOL> except GuestCommandError as error : <EOL> raise testing . CriticctlError ( error . command , error . stdout , error . stderr ) <EOL> def adduser ( self , name , email = None , fullname = None , password = None ) : <EOL> if email is None : <EOL> email = "<STR_LIT>" % name <EOL> if fullname is None : <EOL> fullname = "<STR_LIT>" % name . capitalize ( ) <EOL> if password is None : <EOL> password = "<STR_LIT>" <EOL> self . execute ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , name , "<STR_LIT>" , email , <EOL> "<STR_LIT>" , "<STR_LIT>" % fullname , "<STR_LIT>" , password , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , name ] ) <EOL> self . execute ( [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , name , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , name , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" % fullname , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , name , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> email ] , <EOL> cwd = "<STR_LIT>" % name ) <EOL> self . registeruser ( name ) <EOL> def has_flag ( self , flag ) : <EOL> if self . upgrade_commit and self . __upgraded : <EOL> check_commit = self . upgrade_commit <EOL> else : <EOL> check_commit = self . install_commit <EOL> return testing . has_flag ( check_commit , flag ) <EOL> def repository_path ( self , repository = "<STR_LIT>" ) : <EOL> return "<STR_LIT>" % repository <EOL> def repository_url ( self , name = None , repository = "<STR_LIT>" ) : <EOL> if name is None : <EOL> user_prefix = "<STR_LIT>" <EOL> else : <EOL> user_prefix = name + "<STR_LIT:@>" <EOL> return "<STR_LIT>" % ( user_prefix , self . hostname , repository ) <EOL> def restrict_access ( self ) : <EOL> if not self . strict_fs_permissions : <EOL> return <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def install ( self , repository , override_arguments = { } , other_cwd = False , <EOL> quick = False , interactive = False ) : <EOL> testing . logger . debug ( "<STR_LIT>" ) <EOL> if not interactive : <EOL> use_arguments = { "<STR_LIT>" : True , <EOL> "<STR_LIT>" : self . hostname , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : self . vboxhost , <EOL> "<STR_LIT>" : str ( self . mailbox . port ) , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : True } <EOL> if self . mailbox . credentials : <EOL> use_arguments [ "<STR_LIT>" ] = self . mailbox . credentials [ "<STR_LIT:username>" ] <EOL> use_arguments [ "<STR_LIT>" ] = self . mailbox . credentials [ "<STR_LIT:password>" ] <EOL> if self . coverage : <EOL> use_arguments [ "<STR_LIT>" ] = COVERAGE_DIR <EOL> if self . has_flag ( "<STR_LIT>" ) : <EOL> use_arguments [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> else : <EOL> use_arguments = { "<STR_LIT>" : "<STR_LIT>" } <EOL> if self . has_flag ( "<STR_LIT>" ) : <EOL> use_arguments [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> if self . has_flag ( "<STR_LIT>" ) : <EOL> use_arguments [ "<STR_LIT>" ] = True <EOL> if self . has_flag ( "<STR_LIT>" ) and self . arguments . vm_web_server : <EOL> use_arguments [ "<STR_LIT>" ] = self . arguments . vm_web_server <EOL> for name , value in override_arguments . items ( ) : <EOL> if value is None : <EOL> if name in use_arguments : <EOL> del use_arguments [ name ] <EOL> else : <EOL> use_arguments [ name ] = value <EOL> arguments = [ ] <EOL> for name , value in use_arguments . items ( ) : <EOL> arguments . append ( name ) <EOL> if value is not True : <EOL> arguments . append ( value ) <EOL> try : <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> except GuestCommandError : <EOL> testing . logger . debug ( "<STR_LIT>" ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> testing . logger . info ( "<STR_LIT>" % self . execute ( [ "<STR_LIT>" , "<STR_LIT>" ] ) . strip ( ) ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , repository . url , "<STR_LIT>" ] ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , self . install_commit ] , <EOL> cwd = "<STR_LIT>" ) <EOL> if self . upgrade_commit : <EOL> output = subprocess . check_output ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , self . install_commit , "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> for line in output . splitlines ( ) : <EOL> sha1 , subject = line . split ( "<STR_LIT:U+0020>" , <NUM_LIT:1> ) <EOL> if subject == "<STR_LIT>" : <EOL> self . restrict_access ( ) <EOL> break <EOL> else : <EOL> self . restrict_access ( ) <EOL> if other_cwd and self . has_flag ( "<STR_LIT>" ) : <EOL> install_py = "<STR_LIT>" <EOL> cwd = None <EOL> else : <EOL> install_py = "<STR_LIT>" <EOL> cwd = "<STR_LIT>" <EOL> self . execute ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , install_py ] + arguments , <EOL> cwd = cwd , interactive = "<STR_LIT>" not in use_arguments ) <EOL> if not quick : <EOL> try : <EOL> testmail = self . mailbox . pop ( <EOL> testing . mailbox . WithSubject ( "<STR_LIT>" ) ) <EOL> if not testmail : <EOL> testing . expect . check ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> else : <EOL> testing . expect . check ( "<STR_LIT>" , <EOL> testmail . header ( "<STR_LIT>" ) ) <EOL> testing . expect . check ( "<STR_LIT>" , <EOL> "<STR_LIT:\n>" . join ( testmail . lines ) ) <EOL> self . mailbox . check_empty ( ) <EOL> self . check_service_logs ( ) <EOL> except testing . TestFailure as error : <EOL> if error . message : <EOL> testing . logger . error ( "<STR_LIT>" % error . message ) <EOL> raise testing . InstanceError <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> for name in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . adduser ( name ) <EOL> self . adduser ( "<STR_LIT>" ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> try : <EOL> self . frontend . run_basic_tests ( ) <EOL> self . mailbox . check_empty ( ) <EOL> except testing . TestFailure as error : <EOL> if error . message : <EOL> testing . logger . error ( "<STR_LIT>" % error . message ) <EOL> raise testing . InstanceError <EOL> testing . logger . info ( "<STR_LIT>" % self . install_commit_description ) <EOL> self . __installed = True <EOL> self . current_commit = self . install_commit <EOL> def check_upgrade ( self ) : <EOL> if not self . upgrade_commit : <EOL> raise testing . NotSupported ( "<STR_LIT>" ) <EOL> def upgrade ( self , override_arguments = { } , other_cwd = False , quick = False , <EOL> interactive = False , is_after_test = False ) : <EOL> if self . upgrade_commit and self . upgrade_commit != self . current_commit and ( is_after_test or not self . arguments . upgrade_after ) : <EOL> testing . logger . debug ( "<STR_LIT>" ) <EOL> self . restrict_access ( ) <EOL> if not interactive : <EOL> use_arguments = { "<STR_LIT>" : True } <EOL> else : <EOL> use_arguments = { } <EOL> if not self . has_flag ( "<STR_LIT>" ) : <EOL> use_arguments [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> if not self . has_flag ( "<STR_LIT>" ) : <EOL> use_arguments [ "<STR_LIT>" ] = True <EOL> if not self . has_flag ( "<STR_LIT>" ) : <EOL> use_arguments [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> for name , value in override_arguments . items ( ) : <EOL> if value is None : <EOL> if name in use_arguments : <EOL> del use_arguments [ name ] <EOL> else : <EOL> use_arguments [ name ] = value <EOL> arguments = [ ] <EOL> for name , value in use_arguments . items ( ) : <EOL> arguments . append ( name ) <EOL> if value is not True : <EOL> arguments . append ( value ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , self . upgrade_commit ] , cwd = "<STR_LIT>" ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , cwd = "<STR_LIT>" ) <EOL> self . __upgraded = True <EOL> if other_cwd and self . has_flag ( "<STR_LIT>" ) : <EOL> upgrade_py = "<STR_LIT>" <EOL> cwd = None <EOL> else : <EOL> upgrade_py = "<STR_LIT>" <EOL> cwd = "<STR_LIT>" <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , upgrade_py ] + arguments , <EOL> cwd = cwd , interactive = "<STR_LIT>" not in use_arguments ) <EOL> if not quick : <EOL> self . frontend . run_basic_tests ( ) <EOL> testing . logger . info ( "<STR_LIT>" % self . upgrade_commit_description ) <EOL> self . current_commit = self . upgrade_commit <EOL> def check_extend ( self , repository , pre_upgrade = False ) : <EOL> commit = self . install_commit if pre_upgrade else self . tested_commit <EOL> if not testing . exists_at ( commit , "<STR_LIT>" ) : <EOL> raise testing . NotSupported ( "<STR_LIT>" ) <EOL> if not self . arguments . test_extensions : <EOL> raise testing . NotSupported ( "<STR_LIT>" ) <EOL> if not repository . v8_jsshell_path : <EOL> raise testing . NotSupported ( "<STR_LIT>" ) <EOL> def extend ( self , repository ) : <EOL> self . check_extend ( repository ) <EOL> testing . logger . debug ( "<STR_LIT>" ) <EOL> def internal ( action , extra_argv = None ) : <EOL> argv = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" % action ] <EOL> if extra_argv : <EOL> argv . extend ( extra_argv ) <EOL> self . execute ( argv , cwd = "<STR_LIT>" ) <EOL> internal ( "<STR_LIT>" , [ "<STR_LIT>" ] ) <EOL> submodule_path = "<STR_LIT>" <EOL> v8_jsshell_sha1 = testing . repository . submodule_sha1 ( <EOL> os . getcwd ( ) , self . current_commit , submodule_path ) <EOL> cached_executable = os . path . join ( self . arguments . cache_dir , <EOL> self . identifier , "<STR_LIT>" , <EOL> v8_jsshell_sha1 + "<STR_LIT>" ) <EOL> if self . upgrade_commit is not None and self . install_commit == self . current_commit and self . upgrade_commit != self . current_commit : <EOL> upgraded_v8_jsshell_sha1 = testing . repository . submodule_sha1 ( <EOL> os . getcwd ( ) , self . upgrade_commit , submodule_path ) <EOL> if upgraded_v8_jsshell_sha1 != v8_jsshell_sha1 : <EOL> testing . logger . debug ( "<STR_LIT>" ) <EOL> cached_executable = None <EOL> if cached_executable and os . path . isfile ( cached_executable ) : <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" ] , cwd = "<STR_LIT>" ) <EOL> self . copyto ( cached_executable , <EOL> "<STR_LIT>" ) <EOL> testing . logger . debug ( "<STR_LIT>" ) <EOL> else : <EOL> if repository . v8_url : <EOL> extra_argv = [ "<STR_LIT>" % repository . v8_url ] <EOL> else : <EOL> extra_argv = None <EOL> internal ( "<STR_LIT>" , extra_argv ) <EOL> v8_sha1 = subprocess . check_output ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> cwd = "<STR_LIT>" ) . split ( ) [ <NUM_LIT:2> ] <EOL> cached_v8deps = os . path . join ( self . arguments . cache_dir , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" % v8_sha1 ) <EOL> if os . path . isfile ( cached_v8deps ) : <EOL> self . copyto ( cached_v8deps , "<STR_LIT>" ) <EOL> internal ( "<STR_LIT>" ) <EOL> else : <EOL> internal ( "<STR_LIT>" ) <EOL> if not os . path . isdir ( os . path . dirname ( cached_v8deps ) ) : <EOL> os . makedirs ( os . path . dirname ( cached_v8deps ) ) <EOL> self . copyfrom ( "<STR_LIT>" , cached_v8deps ) <EOL> internal ( "<STR_LIT>" ) <EOL> if cached_executable : <EOL> if not os . path . isdir ( os . path . dirname ( cached_executable ) ) : <EOL> os . makedirs ( os . path . dirname ( cached_executable ) ) <EOL> self . copyfrom ( "<STR_LIT>" , <EOL> cached_executable ) <EOL> testing . logger . debug ( "<STR_LIT>" ) <EOL> internal ( "<STR_LIT>" ) <EOL> internal ( "<STR_LIT>" ) <EOL> self . frontend . run_basic_tests ( ) <EOL> testing . logger . info ( "<STR_LIT>" ) <EOL> def restart ( self ) : <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def uninstall ( self ) : <EOL> self . execute ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> cwd = "<STR_LIT>" ) <EOL> for name in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , name ] ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . __installed = False <EOL> self . __upgraded = False <EOL> def finish ( self ) : <EOL> if not self . __started : <EOL> return <EOL> if self . __installed : <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> if self . coverage : <EOL> sys . stdout . write ( self . execute ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , COVERAGE_DIR , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] , <EOL> cwd = "<STR_LIT>" ) ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def run_unittest ( self , args ) : <EOL> if self . coverage : <EOL> args = [ "<STR_LIT>" ] + args <EOL> return self . execute ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] + args , <EOL> log_stderr = False ) <EOL> def gc ( self , repository ) : <EOL> self . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> cwd = os . path . join ( "<STR_LIT>" , repository ) , <EOL> as_user = "<STR_LIT>" ) <EOL> def synchronize_service ( self , service_name , force_maintenance = False , timeout = <NUM_LIT:30> ) : <EOL> helper = "<STR_LIT>" <EOL> if not ( self . __upgraded or testing . exists_at ( self . install_commit , helper ) ) : <EOL> testing . logger . debug ( "<STR_LIT>" <EOL> % ( service_name , timeout ) ) <EOL> time . sleep ( timeout ) <EOL> return <EOL> testing . logger . debug ( "<STR_LIT>" % service_name ) <EOL> pidfile_path = os . path . join ( "<STR_LIT>" , service_name + "<STR_LIT>" ) <EOL> if force_maintenance : <EOL> signum = signal . SIGUSR2 <EOL> else : <EOL> signum = signal . SIGUSR1 <EOL> before = time . time ( ) <EOL> self . execute ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + helper , <EOL> pidfile_path , str ( signum ) , str ( timeout ) ] ) <EOL> after = time . time ( ) <EOL> testing . logger . debug ( "<STR_LIT>" <EOL> % ( service_name , after - before ) ) <EOL> def filter_service_logs ( self , level , service_names ) : <EOL> helper = "<STR_LIT>" <EOL> if not ( self . __upgraded or testing . exists_at ( self . install_commit , helper ) ) : <EOL> return <EOL> logfile_paths = { <EOL> os . path . join ( "<STR_LIT>" , service_name + "<STR_LIT>" ) : service_name <EOL> for service_name in service_names } <EOL> try : <EOL> data = json . loads ( self . execute ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + helper , level ] + logfile_paths . keys ( ) , <EOL> log_stdout = False ) ) <EOL> return { logfile_paths [ logfile_path ] : entries <EOL> for logfile_path , entries in sorted ( data . items ( ) ) } <EOL> except GuestCommandError : <EOL> return None </s>
