Beispiel #1
0
def start_jenkins():
    try:
        execfile(JENKINS_ENV, dict(__file__=JENKINS_ENV))
        print "Virtual environment activated successfully."
    except Exception as ex:
        print 'Could not activate virtual environment at "%s": %s.' % (
            JENKINS_ENV, str(ex))
        sys.exit(1)

    # do imports here because it requires the virtualenv to b activated
    from mozdownload import DirectScraper
    from mozprocess.processhandler import ProcessHandler

    # Download the Jenkins WAR file
    scraper = DirectScraper(url=JENKINS_URL, destination=JENKINS_WAR)
    scraper.download()

    # TODO: Start Jenkins as daemon
    print "Starting Jenkins"
    os.environ['JENKINS_HOME'] = os.path.join(HERE, 'jenkins-master')
    args = [
        'java', '-Xms2g', '-Xmx2g', '-XX:MaxPermSize=512M', '-Xincgc', '-jar',
        JENKINS_WAR
    ]
    proc = ProcessHandler(args)
    proc.run()
    return proc
Beispiel #2
0
def start_jenkins():
    try:
        execfile(JENKINS_ENV, dict(__file__=JENKINS_ENV))
        logger.info('Virtual environment activated successfully.')
    except Exception:
        logger.exception('Could not activate virtual environment at "%s"' % JENKINS_ENV)
        sys.exit(1)

    # do imports here because it requires the virtualenv to b activated
    from mozprocess.processhandler import ProcessHandler

    # Download the Jenkins WAR file if necessary
    if not os.path.exists(JENKINS_WAR):
        download_args = ['wget', JENKINS_URL, '-x', '-O', JENKINS_WAR]
        proc = ProcessHandler(download_args)
        proc.run()
        retval = proc.wait()

        if retval != 0:
            raise Exception('Failure downloading file "%s"' % JENKINS_URL)

    # TODO: Start Jenkins as daemon
    logger.info('Starting Jenkins')
    os.environ['JENKINS_HOME'] = os.path.join(HERE, 'jenkins-master')
    args = ['java', '-Xms2g', '-Xmx2g', '-XX:MaxPermSize=512M',
            '-Xincgc', '-jar', JENKINS_WAR]
    proc = ProcessHandler(args)
    proc.run()
    return proc
Beispiel #3
0
def compile_executables():
    '''Function compiles all assets connected to tests'''
    here = os.path.abspath(os.path.dirname(__file__))

    executable = os.path.join(here, 'firefox.exe')
    stub_example_c = os.path.join(here, 'firefox.c')
    stub_example_rc = os.path.join(here, 'firefox.rc')
    stub_example_res = os.path.join(here, 'firefox.res')
    stub_example_obj = os.path.join(here, 'firefox.obj')

    if os.path.exists(executable):
        print "Removing existing browser stub: %s" % executable
        mozfile.remove(executable)

    commands = [
        # For browser we need to generate resource file
        # because is_installer needs to check PE Headers
        ['rc.exe', stub_example_rc],

        # And then we compile next version of browser file which
        # contains tested PE Header ('BuildID')
        ['cl.exe', stub_example_c, stub_example_res],
    ]

    for command in commands:
        print "Executing command: %s" % (' '.join(command),)
        try:
            process = ProcessHandler(command)
            process.run(timeout=20)
            returncode = process.wait()
            if returncode:
                raise subprocess.CalledProcessError(returncode, command, output)

        except OSError, e:
            if e.errno == errno.ENOENT:
                print "Missing %s" % command[0]
                print  "Visual C++ and Windows Platform SDK are required."
                sys.exit(e.errno)
            raise
Beispiel #4
0
def start_jenkins():
    try:
        execfile(JENKINS_ENV, dict(__file__=JENKINS_ENV))
        print "Virtual environment activated successfully."
    except Exception as ex:
        print 'Could not activate virtual environment at "%s": %s.' % (JENKINS_ENV, str(ex))
        sys.exit(1)

    # do imports here because it requires the virtualenv to b activated
    from mozdownload import DirectScraper
    from mozprocess.processhandler import ProcessHandler

    # Download the Jenkins WAR file
    scraper = DirectScraper(url=JENKINS_URL, destination=JENKINS_WAR)
    scraper.download()

    # TODO: Start Jenkins as daemon
    print "Starting Jenkins"
    os.environ['JENKINS_HOME'] = os.path.join(HERE, 'jenkins-master')
    args = ['java', '-Xms2g', '-Xmx2g', '-XX:MaxPermSize=512M',
            '-Xincgc', '-jar', JENKINS_WAR]
    proc = ProcessHandler(args)
    proc.run()
    return proc
Beispiel #5
0
    def start(self):
        """Run self.command in the proper environment."""

        # ensure you are stopped
        self.stop()

        # run once to register any extensions
        # see:
        # - http://hg.mozilla.org/releases/mozilla-1.9.2/file/915a35e15cde/build/automation.py.in#l702
        # - http://mozilla-xp.com/mozilla.dev.apps.firefox/Rules-for-when-firefox-bin-restarts-it-s-process
        # This run just calls through processhandler to popen directly as we 
        # are not particuarly cared in tracking this process
        firstrun = ProcessHandler.Process(self.command+['-silent', '-foreground'], env=self.env, **self.kp_kwargs)
        firstrun.wait()

        # now run for real, this run uses the managed processhandler
        self.process_handler = ProcessHandler(self.command+self.cmdargs, env=self.env, **self.kp_kwargs)
        self.process_handler.run()
Beispiel #6
0
class Runner(object):
    """Handles all running operations. Finds bins, runs and kills the process."""

    @classmethod
    def create(cls, binary=None, cmdargs=None, env=None, kp_kwargs=None, profile_args=None, clean_profile=True):
        profile = cls.profile_class(**(profile_args or {}))
        return cls(profile, binary=binary, cmdargs=cmdargs, env=env, kp_kwargs=kp_kwargs, clean_profile=clean_profile)

    def __init__(self, profile, binary=None, cmdargs=None, env=None, kp_kwargs=None, clean_profile=True):
        self.process_handler = None
        self.profile = profile
        self.clean_profile = clean_profile

        # find the binary
        self.binary = self.__class__.get_binary(binary)
        if not os.path.exists(self.binary):
            raise OSError("Binary path does not exist: %s" % self.binary)

        self.cmdargs = cmdargs or []
        _cmdargs = [i for i in self.cmdargs
                    if i != '-foreground']
        if len(_cmdargs) != len(self.cmdargs):
            # foreground should be last; see
            # - https://bugzilla.mozilla.org/show_bug.cgi?id=625614
            # - https://bugzilla.mozilla.org/show_bug.cgi?id=626826
            self.cmdargs = _cmdargs
            self.cmdargs.append('-foreground')

        # process environment
        if env is None:
            self.env = os.environ.copy()
        else:
            self.env = env.copy()
        # allows you to run an instance of Firefox separately from any other instances
        self.env['MOZ_NO_REMOTE'] = '1'
        # keeps Firefox attached to the terminal window after it starts
        self.env['NO_EM_RESTART'] = '1'

        # set the library path if needed on linux
        if sys.platform == 'linux2' and self.binary.endswith('-bin'):
            dirname = os.path.dirname(self.binary)
            if os.environ.get('LD_LIBRARY_PATH', None):
                self.env['LD_LIBRARY_PATH'] = '%s:%s' % (os.environ['LD_LIBRARY_PATH'], dirname)
            else:
                self.env['LD_LIBRARY_PATH'] = dirname

        # arguments for ProfessHandler.Process
        self.kp_kwargs = kp_kwargs or {}

    @classmethod
    def get_binary(cls, binary=None):
        """determine the binary"""
        if binary is None:
            return cls.find_binary()
        elif mozinfo.isMac and binary.find('Contents/MacOS/') == -1:
            return os.path.join(binary, 'Contents/MacOS/%s-bin' % cls.names[0])
        else:
            return binary
        
    @classmethod
    def find_binary(cls):
        """Finds the binary for class names if one was not provided."""

        binary = None
        if mozinfo.isUnix:
            for name in reversed(cls.names):
                binary = findInPath(name)
        elif mozinfo.isWin:

            # find the default executable from the windows registry
            try:
                # assumes cls.app_name is defined, as it should be for implementors
                import _winreg
                app_key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"Software\Mozilla\Mozilla %s" % cls.app_name)
                version, _type = _winreg.QueryValueEx(app_key, "CurrentVersion")
                version_key = _winreg.OpenKey(app_key, version + r"\Main")
                path, _ = _winreg.QueryValueEx(version_key, "PathToExe")
                return path
            except: # XXX not sure what type of exception this should be
                pass

            # search for the binary in the path
            for name in reversed(cls.names):
                binary = findInPath(name)
                if sys.platform == 'cygwin':
                    program_files = os.environ['PROGRAMFILES']
                else:
                    program_files = os.environ['ProgramFiles']

                if binary is None:
                    for bin in [(program_files, 'Mozilla Firefox', 'firefox.exe'),
                                (os.environ.get("ProgramFiles(x86)"),'Mozilla Firefox', 'firefox.exe'),
                                (program_files,'Minefield', 'firefox.exe'),
                                (os.environ.get("ProgramFiles(x86)"),'Minefield', 'firefox.exe')
                                ]:
                        path = os.path.join(*bin)
                        if os.path.isfile(path):
                            binary = path
                            break
        elif mozinfo.isMac:
            for name in reversed(cls.names):
                appdir = os.path.join('Applications', name.capitalize()+'.app')
                if os.path.isdir(os.path.join(os.path.expanduser('~/'), appdir)):
                    binary = os.path.join(os.path.expanduser('~/'), appdir,
                                          'Contents/MacOS/'+name+'-bin')
                elif os.path.isdir('/'+appdir):
                    binary = os.path.join("/"+appdir, 'Contents/MacOS/'+name+'-bin')

                if binary is not None:
                    if not os.path.isfile(binary):
                        binary = binary.replace(name+'-bin', 'firefox-bin')
                    if not os.path.isfile(binary):
                        binary = None
        if binary is None:
            raise Exception('Mozrunner could not locate your binary, you will need to set it.')
        return binary

    @property
    def command(self):
        """Returns the command list to run."""
        return [self.binary, '-profile', self.profile.profile]

    def get_repositoryInfo(self):
        """Read repository information from application.ini and platform.ini."""

        config = ConfigParser.RawConfigParser()
        dirname = os.path.dirname(self.binary)
        repository = { }

        for file, section in [('application', 'App'), ('platform', 'Build')]:
            config.read(os.path.join(dirname, '%s.ini' % file))

            for key, id in [('SourceRepository', 'repository'),
                            ('SourceStamp', 'changeset')]:
                try:
                    repository['%s_%s' % (file, id)] = config.get(section, key);
                except:
                    repository['%s_%s' % (file, id)] = None

        return repository

    def is_running(self):
        return self.process_handler is not None

    def start(self):
        """Run self.command in the proper environment."""

        # ensure you are stopped
        self.stop()

        # run once to register any extensions
        # see:
        # - http://hg.mozilla.org/releases/mozilla-1.9.2/file/915a35e15cde/build/automation.py.in#l702
        # - http://mozilla-xp.com/mozilla.dev.apps.firefox/Rules-for-when-firefox-bin-restarts-it-s-process
        # This run just calls through processhandler to popen directly as we 
        # are not particuarly cared in tracking this process
        firstrun = ProcessHandler.Process(self.command+['-silent', '-foreground'], env=self.env, **self.kp_kwargs)
        firstrun.wait()

        # now run for real, this run uses the managed processhandler
        self.process_handler = ProcessHandler(self.command+self.cmdargs, env=self.env, **self.kp_kwargs)
        self.process_handler.run()
 
    def wait(self, timeout=None):
        """Wait for the app to exit."""
        if self.process_handler is None:
            return
        self.process_handler.waitForFinish(timeout=timeout)
        self.process_handler = None

    def stop(self):
        """Kill the app"""
        if self.process_handler is None:
            return
        self.process_handler.kill()
        self.process_handler = None

    def reset(self):
        """
        reset the runner between runs
        currently, only resets the profile, but probably should do more
        """
        self.profile.reset()

    def cleanup(self):
        self.stop()
        if self.clean_profile:
            self.profile.cleanup()

    __del__ = cleanup