def enter_winterfell():
    """
        Function that is used when we are doing ISUG in a branch and not in trunk.
        It fetches a revision file from winterfell machine and opens to examine the
        green tag that was built the ISO.
        If branches  use the real commited revisions in their ISOs in the future we can skip this call

    """

    log.info('SSH to winterfell for %s.txt' % options.src_build_rev)
    print 'SSH to winterfell for %s.txt' % options.src_build_rev
    django = pexpect.spawn(ssh_winterfell)
    django.expect_exact('$')
    c = pexpect.spawn('scp [email protected]:/home/django/lvnproject/Weblvn/my_media/svnhistory/' +
                      options.src_build_rev + '.txt'' /home/' + username() + '/')
    c.expect(pexpect.EOF, timeout=None)
    c.terminate()
    django.terminate()
    if os.path.exists('/home/' + username() + '/' + options.src_build_rev + '.txt'):
        log.info('Fetched revision file %s.txt' % options.src_build_rev)
        print 'Fetched revision file %s.txt' % options.src_build_rev
        print 'Done\n'
    else:
        log.error('Did not succeed to fetch %s.txt from winterfell' %
                  options.src_build_rev)

        sys.exit(14)
def enter_winterfell():
    """
        Function that is used when we are doing ISUG in a branch and not in trunk.
        It fetches a revision file from winterfell machine and opens to examine the
        green tag that was built the ISO.
        If branches  use the real commited revisions in their ISOs in the future we can skip this call

    """

    log.info('SSH to winterfell for %s.txt' % options.src_build_rev)
    print 'SSH to winterfell for %s.txt' % options.src_build_rev
    django = pexpect.spawn(ssh_winterfell)
    django.expect_exact('$')
    c = pexpect.spawn(
        'scp [email protected]:/home/django/lvnproject/Weblvn/my_media/svnhistory/'
        + options.src_build_rev + '.txt'
        ' /home/' + username() + '/')
    c.expect(pexpect.EOF, timeout=None)
    c.terminate()
    django.terminate()
    if os.path.exists('/home/' + username() + '/' + options.src_build_rev +
                      '.txt'):
        log.info('Fetched revision file %s.txt' % options.src_build_rev)
        print 'Fetched revision file %s.txt' % options.src_build_rev
        print 'Done\n'
    else:
        log.error('Did not succeed to fetch %s.txt from winterfell' %
                  options.src_build_rev)

        sys.exit(14)
Exemple #3
0
    def execute(self, command, write_in_file=""):

        if write_in_file != PIPE:

            if write_in_file.closed:
                log.error('file %s is not open for reading/writing' %
                          write_in_file)
                sys.exit(3)

            else:
                p = Popen(command, shell=True,
                          stdout=write_in_file, stderr=STDOUT)
                self.stdOut, self.stdErr = p.communicate()

        else:
            p = Popen(command, shell=True, stdout=write_in_file, stderr=STDOUT)
            self.stdOut, self.stdErr = p.communicate()
def examine_ipc_scheme(ipc_file):
    """
        Function that is used along with the above generator function 
        Scope is the same.
        On success from the generator it returns the message.
        On failure it returns a notification that the message is not found in the 
        scheme.
        If the number of failures is 3 it aborts.

        @rtype  file object
        @rvalue string


    """

    cnt = 0
    try:
        with open(ipc_file) as f:
            for message_found in ipc_message_gen(f):
                if message_found[0] == True:
                    log.info('%s is found in ipc scheme.Try to modify this',
                             ' '.join(message_found[1].split()))
                    break
                else:
                    cnt += 1
                    log.warning(
                        '%s is not found in ipc scheme.Try next candidate',
                        ' '.join(message_found[1].split()))

            if cnt == len(ipc_message_db):
                log.error(
                    'ipc message db is examined and no candidate found for editing'
                )
                sys.exit(3)
            else:
                log.info('Will change now %s in ipc file' %
                         message_found[1].split()[0])

    except IOError:
        #: if we get here then something is really messed up... :#
        log.error('ipc encoding scheme seems that does not exist')
        sys.exit(4)

    return message_found[1]
def check_branch_existence():
    """
        Function that will make a precheck to the user's environment.
        It looks for the branch in question,and if the user has already cloned it
        it passes.Error is logged on failure to find a cloned branch.

    """

    #: Check if the branch(case insensitive) is cloned :#
    os.chdir(working_copy)
    #: utilize git object :#
    git.show_branches()
    available_branches = git.stdOut
    #: trunk is already cloned as master :#
    if re.search(options.branch, available_branches, re.I):
        pass
    else:
        log.error('%s is not cloned.Exit', options.branch)
        sys.exit(3)
def check_branch_existence():
    """
        Function that will make a precheck to the user's environment.
        It looks for the branch in question,and if the user has already cloned it
        it passes.Error is logged on failure to find a cloned branch.

    """

#: Check if the branch(case insensitive) is cloned :#
    os.chdir(working_copy)
    #: utilize git object :#
    git.show_branches()
    available_branches = git.stdOut
    #: trunk is already cloned as master :#
    if re.search(options.branch, available_branches, re.I):
        pass
    else:
        log.error('%s is not cloned.Exit', options.branch)
        sys.exit(3)
Exemple #7
0
    def execute(self, command, write_in_file=""):

        if write_in_file != PIPE:

            if write_in_file.closed:
                log.error('file %s is not open for reading/writing' %
                          write_in_file)
                sys.exit(3)

            else:
                p = Popen(command,
                          shell=True,
                          stdout=write_in_file,
                          stderr=STDOUT)
                self.stdOut, self.stdErr = p.communicate()

        else:
            p = Popen(command, shell=True, stdout=write_in_file, stderr=STDOUT)
            self.stdOut, self.stdErr = p.communicate()
def examine_ipc_scheme(ipc_file):
    """
        Function that is used along with the above generator function 
        Scope is the same.
        On success from the generator it returns the message.
        On failure it returns a notification that the message is not found in the 
        scheme.
        If the number of failures is 3 it aborts.

        @rtype  file object
        @rvalue string


    """

    cnt = 0
    try:
        with open(ipc_file) as f:
            for message_found in ipc_message_gen(f):
                if message_found[0] == True:
                    log.info('%s is found in ipc scheme.Try to modify this',
                             ' '.join(message_found[1].split()))
                    break
                else:
                    cnt += 1
                    log.warning('%s is not found in ipc scheme.Try next candidate', ' '.join(
                        message_found[1].split()))

            if cnt == len(ipc_message_db):
                log.error(
                    'ipc message db is examined and no candidate found for editing')
                sys.exit(3)
            else:
                log.info('Will change now %s in ipc file' %
                         message_found[1].split()[0])

    except IOError:
        #: if we get here then something is really messed up... :#
        log.error('ipc encoding scheme seems that does not exist')
        sys.exit(4)

    return message_found[1]
def find_commited_revision():
    """
        Function that will be used to retrieve the revision in svn terms
        of the 2nd commit we made.
        This should be the revision from which the ISO will be built.

    """

    print 'Find the commited revision'
    print '==========================='
    git.log(supported_file)
    if re.search(username(), git.stdOut):
        hashvalue = re.search(r'(?<=commit )(\w{10})', git.stdOut).group(1)
        cmd.run('git svn find-rev ' + hashvalue)
        com_revision = cmd.stdOut.strip('\n')
        print 'Commited revision is: ', com_revision
        log.info('Commited revision is %s: ' % com_revision)
        print '==========================='
        print 'Done\n'
    else:
        log.error('Unable to find %s in %s.Check manually' %
                  (username(), git.stdOut))
        sys.exit(3)
    return com_revision
def find_commited_revision():
    """
        Function that will be used to retrieve the revision in svn terms
        of the 2nd commit we made.
        This should be the revision from which the ISO will be built.

    """

    print'Find the commited revision'
    print'==========================='
    git.log(supported_file)
    if re.search(username(), git.stdOut):
        hashvalue = re.search(r'(?<=commit )(\w{10})', git.stdOut).group(1)
        cmd.run('git svn find-rev ' + hashvalue)
        com_revision = cmd.stdOut.strip('\n')
        print 'Commited revision is: ', com_revision
        log.info('Commited revision is %s: ' % com_revision)
        print '==========================='
        print'Done\n'
    else:
        log.error('Unable to find %s in %s.Check manually' %
                  (username(), git.stdOut))
        sys.exit(3)
    return com_revision
def get_src_lvn():
    """ Function that retrieves the source lvn from vevak file 
        It also returns apart from the source lvn,the latest lvn in the
        vevak file.It is used for calculating the target lvn.

    """

    try:
        response = urllib2.urlopen(vevak_url).readlines()
    except urllib2.HTTPError:
        log.error('url %s from vevak not found' % vevak_url)
        sys.exit(5)
    else:
        if not options.branch.startswith('cat'):
            try:
                src_lvn = filter(
                    lambda line: re.search(
                        '\\b' + options.src_build_rev + '\\b', line),
                    response)[0].split('|')[7].strip()
                #src_lvn=re.search(r'(?<= )(\d{1,3})(?= )',filter(lambda line:re.search('\\b'+options.src_build_rev+'\\b',line),response)[0]).group(1)
                #latest_LVN = re.search(r'(?<= )(\d{1,3})(?= )',response[-1]).group(1)
                latest_LVN = response[-1].split('|')[7].strip()
            except IndexError:
                log.error('Requested wrong revision %s against %s',
                          options.src_build_rev, options.branch)
                sys.exit(3)
        else:
            try:
                enter_winterfell()
                file_desc = open(
                    '/home/' + username() + '/' + options.src_build_rev +
                    '.txt', 'r')
                green_tag = cat_regex.search(file_desc.readlines()[2]).group(2)
            except AttributeError:
                log.error('Requested wrong revision %s against %s',
                          options.src_build_rev, options.branch)
                sys.exit(4)
            else:
                log.info('green tag is:%s ', green_tag)
                #: LVN in branches are most of the times 2-digit string :#
                src_lvn = filter(
                    lambda line: re.search('\\b' + green_tag + '\\b', line),
                    response)[0].split('|')[7].strip()
                #src_lvn=re.search(r'(?<= )(\d{1,2})(?= )',filter(lambda line:re.search('\\b'+green_tag+'\\b',line),response)[0]).group(1)
                #latest_LVN = re.search(r'(?<= )(\d{1,2})(?= )',response[-1]).group(1)
                latest_LVN = response[-1].split('|')[7].strip()
    print '================================'
    print 'You requested %s as source lvn' % src_lvn
    log.info('You requested %s as source lvn' % src_lvn)
    print 'Latest LVN in %s is %s ' % (options.branch, latest_LVN)
    log.info('Latest LVN in %s is %s ' % (options.branch, latest_LVN))
    print '================================'
    print 'Done\n'
    log.info('Done')
    return (src_lvn, latest_LVN)
def get_src_lvn():
    """ Function that retrieves the source lvn from vevak file 
        It also returns apart from the source lvn,the latest lvn in the
        vevak file.It is used for calculating the target lvn.

    """

    try:
        response = urllib2.urlopen(vevak_url).readlines()
    except urllib2.HTTPError:
        log.error('url %s from vevak not found' % vevak_url)
        sys.exit(5)
    else:
        if not options.branch.startswith('cat'):
            try:
                src_lvn = filter(lambda line: re.search(
                    '\\b' + options.src_build_rev + '\\b', line), response)[0].split('|')[7].strip()
                #src_lvn=re.search(r'(?<= )(\d{1,3})(?= )',filter(lambda line:re.search('\\b'+options.src_build_rev+'\\b',line),response)[0]).group(1)
                #latest_LVN = re.search(r'(?<= )(\d{1,3})(?= )',response[-1]).group(1)
                latest_LVN = response[-1].split('|')[7].strip()
            except IndexError:
                log.error('Requested wrong revision %s against %s',
                          options.src_build_rev, options.branch)
                sys.exit(3)
        else:
            try:
                enter_winterfell()
                file_desc = open('/home/' + username() + '/' +
                                 options.src_build_rev + '.txt', 'r')
                green_tag = cat_regex.search(file_desc.readlines()[2]).group(2)
            except AttributeError:
                log.error('Requested wrong revision %s against %s',
                          options.src_build_rev, options.branch)
                sys.exit(4)
            else:
                log.info('green tag is:%s ', green_tag)
                #: LVN in branches are most of the times 2-digit string :#
                src_lvn = filter(lambda line: re.search(
                    '\\b' + green_tag + '\\b', line), response)[0].split('|')[7].strip()
                #src_lvn=re.search(r'(?<= )(\d{1,2})(?= )',filter(lambda line:re.search('\\b'+green_tag+'\\b',line),response)[0]).group(1)
                #latest_LVN = re.search(r'(?<= )(\d{1,2})(?= )',response[-1]).group(1)
                latest_LVN = response[-1].split('|')[7].strip()
    print'================================'
    print 'You requested %s as source lvn' % src_lvn
    log.info('You requested %s as source lvn' % src_lvn)
    print 'Latest LVN in %s is %s ' % (options.branch, latest_LVN)
    log.info('Latest LVN in %s is %s ' % (options.branch, latest_LVN))
    print'================================'
    print'Done\n'
    log.info('Done')
    return (src_lvn, latest_LVN)
def edit_supported(source_lvn, current_lvn):
    """
        Function that edits the supported_versions.conf.
        It opens the file and inserts a line of this form:

        Adaptation:  bfr_<src_lvn>  <===> bfr_<trg_lvn>

        It calculates the target lvn itself by examining what is the
        latest lvn in the vevak file,and adds 2.The latest lvn should
        normally be always the same as the src_lvn...

        @rtype  None

    """

    print 'Going to edit supported_versions.conf file\n'
    log.info('Going to edit supported_versions.conf file')
    print 'Calculating target LVN'
    log.info('Calculating target LVN')

    print '======================'
    if int(current_lvn) != int(source_lvn):
        log.critical(
            'It seems that source lvn:%s differs from current lvn:%s in %s.Usually they need to be equal.'
            % (source_lvn, current_lvn, options.branch))

    trg_lvn = str(int(current_lvn) + 2)
    print 'Target lvn will be :', trg_lvn
    log.info('Target lvn will be :%s' % trg_lvn)
    print '======================='

    S = open(supported_file, 'r+')
    supported_list = S.readlines()
    for i, line in enumerate(supported_list):
        if re.search('End of file', line, re.I):
            #            print 'Found End of file at line : ',i
            break

    if options.branch == 'trunk':
        bfr = '1'
    else:
        #: 1st way to retrieve BFR :#
        bfr_lvn = re.findall('\d+' + '_' + '\d+', '\n'.join(supported_list))
        bfrs = [line.split('_')[0] for line in bfr_lvn]
        c = Counter(bfrs)
        bfr_1 = c.most_common()[0][0]
        #: 2nd backup way to retrieve BFR :#
        try:
            f = open('Makefile.inc')
        except IOError:
            log.error('Unable to open Makefile.inc to retrieve the BFR')
            sys.exit(12)
        else:
            for line in f:
                if (re.search('BFR', line) and re.search(
                        '\d{6}', line)) and not re.search('9{4,}', line):
                    bfr_2 = re.search('(\d{6})', line).group(1)
        if int(bfr_1) == int(bfr_2):
            bfr = bfr_2
        else:
            print 'Collected BFRs that were retrieved with 2 methods are different'
            print '%s != %s' % (str(bfr_1), str(bfr_2))
            log.critical(
                'Collected BFRs that were retrieved with 2 methods are different,but will proceed with %s'
                % str(bfr_2))
            log.critical('%s != %s', str(bfr_1), str(bfr_2))
            bfr = bfr_2
            # sys.exit(2)
    supported_list.insert(
        i, 'Adaptation:  ' + str(bfr) + '_' + source_lvn + ' <===> ' +
        str(bfr) + '_' + trg_lvn + '\n')
    S.seek(0)
    S.write(''.join(supported_list))
    S.close()
    git.diff()
    log.info(
        'supported versions edited.This is the diff:  ================= \n\n\n %s ==============',
        git.stdOut)
    print 'Done\n'
    log.info('Done')
Exemple #14
0
    def wrapper(self, *args):

        try:
            f(self, *args)
        except Exception as e:
            log.error('Exception happened!!! %s', e)
def edit_supported(source_lvn, current_lvn):
    """
        Function that edits the supported_versions.conf.
        It opens the file and inserts a line of this form:

        Adaptation:  bfr_<src_lvn>  <===> bfr_<trg_lvn>

        It calculates the target lvn itself by examining what is the
        latest lvn in the vevak file,and adds 2.The latest lvn should
        normally be always the same as the src_lvn...

        @rtype  None

    """

    print 'Going to edit supported_versions.conf file\n'
    log.info('Going to edit supported_versions.conf file')
    print 'Calculating target LVN'
    log.info('Calculating target LVN')

    print '======================'
    if int(current_lvn) != int(source_lvn):
        log.critical('It seems that source lvn:%s differs from current lvn:%s in %s.Usually they need to be equal.' % (
            source_lvn, current_lvn, options.branch))

    trg_lvn = str(int(current_lvn) + 2)
    print 'Target lvn will be :', trg_lvn
    log.info('Target lvn will be :%s' % trg_lvn)
    print'======================='

    S = open(supported_file, 'r+')
    supported_list = S.readlines()
    for i, line in enumerate(supported_list):
        if re.search('End of file', line, re.I):
            #            print 'Found End of file at line : ',i
            break

    if options.branch == 'trunk':
        bfr = '1'
    else:
        #: 1st way to retrieve BFR :#
        bfr_lvn = re.findall('\d+' + '_' + '\d+', '\n'.join(supported_list))
        bfrs = [line.split('_')[0] for line in bfr_lvn]
        c = Counter(bfrs)
        bfr_1 = c.most_common()[0][0]
        #: 2nd backup way to retrieve BFR :#
        try:
            f = open('Makefile.inc')
        except IOError:
            log.error('Unable to open Makefile.inc to retrieve the BFR')
            sys.exit(12)
        else:
            for line in f:
                if (re.search('BFR', line) and re.search('\d{6}', line)) and not re.search('9{4,}', line):
                    bfr_2 = re.search('(\d{6})', line).group(1)
        if int(bfr_1) == int(bfr_2):
            bfr = bfr_2
        else:
            print 'Collected BFRs that were retrieved with 2 methods are different'
            print '%s != %s' % (str(bfr_1), str(bfr_2))
            log.critical(
                'Collected BFRs that were retrieved with 2 methods are different,but will proceed with %s' % str(bfr_2))
            log.critical('%s != %s', str(bfr_1), str(bfr_2))
            bfr = bfr_2
            # sys.exit(2)
    supported_list.insert(i, 'Adaptation:  ' + str(bfr) + '_' +
                          source_lvn + ' <===> ' + str(bfr) + '_' + trg_lvn + '\n')
    S.seek(0)
    S.write(''.join(supported_list))
    S.close()
    git.diff()
    log.info('supported versions edited.This is the diff:  ================= \n\n\n %s ==============', git.stdOut)
    print 'Done\n'
    log.info('Done')
def check_sanity(commited=None):
    """ Function that checks the sanity status from buildbot 
        If sanity is red it calls itself recursively in order
        to wait until sanity is green.If it is red for 30 minutes
        it aborts.

        @rtype  tuple
        $rvalue flag that tells is sanity is green and the green revision

    """

    global retry
    is_green = False

    print 'Checking sanity status'

    #: the buildbot file shall be kept into a list in order to parse it later :#
    try:
        f = urllib2.urlopen(buildbot_url).readlines()
    except urllib2.HTTPError as e:
        print 'Unable to fetch buildbot url '
        print e
        sys.exit(3)

    #: it will be used to get the revision in the sanity box :#
    sanity_reg = re.compile(
        r'(?<=href=)"builders/SANITY/builds/\d+">(\d{6})</a><br />(\w+)<br')

    #: check the validity of the buildbot file that has now become a list ---check line 133:#

    if 'SANITY' in ' '.join(f):
        log.info(
            'SANITY string is found in the buildbot file.Proceed with parsing')
    else:
        log.error('Failed to find SANITY in buildbot file.Check manually')
        sys.exit(3)

    if not commited:
        #: we are in the case where the script calls for the first time check_sanity in order to proceed with the commits :#
        for line in f:

            if 'SANITY' in line and 'failed' in line:

                #: enter an 3min loop periodically until sanity box is green.Break the loop then. :#

                while (retry < 10):

                    #: give it some time until it tries again :#
                    #: There are some cases about sanity that need to be handled accordingly :#
                    #: 1)The sanity has left in red state and no-one is looking at this
                    #: |
                    #: |-----> the script will try for 30 minutes and abort.Before aborting it must restore
                    #:         the files that have been changed to their previous state
                    #: 2)The sanity is either red or green but it is expected by the responsible team to be fixed
                    #:   in less than 1h

                    time_period = 180
                    log.info(
                        'Sleeping for 3 mins in order to wait for sanity to be green'
                    )
                    time.sleep(time_period)
                    log.info('Retrying sanity check:%s' % retry)
                    retry += 1
                    return check_sanity()

                log.critical(
                    'Tried for 30minutes and sanity is still red.Aborting...num of retries:%s'
                    % retry)
                sys.exit(8)

            elif 'SANITY' in line and 'successful' in line:
                green_rev = sanity_reg.search(line).group(1)
                is_green = True
                print '================================================='
                print 'Green revision currently on buildbot SANITY is ', green_rev
                print '================================================='
                print 'Done\n'

                break

            else:
                pass

    #: we should get here when we call check_sanity with commited revision as parameter :#
    #: in order to verify if this revision ended with green sanity                      :#

    else:
        #: this is the case that we make sure our commits turned sanity into green :#
        for line in f:
            if 'SANITY/builds' in line:
                while sanity_reg.search(line).group(1) != commited:
                    print 'revision in buildot:', sanity_reg.search(
                        line).group(1)
                    print 'revision that commited:', commited
                    sanity_reg.search(line).group(1) != commited
                    log.info(
                        'Currently building.Wait until our commited revision is in the sanity box and turns green'
                    )
                    time.sleep(120)
                    return check_sanity(commited)
                log.info('Commited revision %s is in sanity box' % commited)
                if 'successful' in line:
                    log.info('Commited revision %s turned green.SUCCESS!!!' %
                             commited)
                    print '=========================================='
                    print '    We commited %s and is green ' % commited
                    print '=========================================='
                    green_rev = commited
                    is_green = True
                    break
                else:
                    log.error(
                        'We most probably broke sanity @ %s.Check manually' %
                        commited)
                    error = 'Hi,\n\n Commited revision %s has resulted in red sanity.\n\nCould you please check?' % commited
                    sender = find_sender(username())
                    # send_mail(error,sender)
                    sys.exit(4)

    return (is_green, green_rev)
Exemple #17
0
    def wrapper(self, *args):

        try:
            f(self, *args)
        except Exception as e:
            log.error('Exception happened!!! %s', e)
def check_sanity(commited=None):
    """ Function that checks the sanity status from buildbot 
        If sanity is red it calls itself recursively in order
        to wait until sanity is green.If it is red for 30 minutes
        it aborts.

        @rtype  tuple
        $rvalue flag that tells is sanity is green and the green revision

    """

    global retry
    is_green = False

    print'Checking sanity status'

    #: the buildbot file shall be kept into a list in order to parse it later :#
    try:
        f = urllib2.urlopen(buildbot_url).readlines()
    except urllib2.HTTPError as e:
        print 'Unable to fetch buildbot url '
        print e
        sys.exit(3)

    #: it will be used to get the revision in the sanity box :#
    sanity_reg = re.compile(
        r'(?<=href=)"builders/SANITY/builds/\d+">(\d{6})</a><br />(\w+)<br')

    #: check the validity of the buildbot file that has now become a list ---check line 133:#

    if 'SANITY' in ' '.join(f):
        log.info('SANITY string is found in the buildbot file.Proceed with parsing')
    else:
        log.error('Failed to find SANITY in buildbot file.Check manually')
        sys.exit(3)

    if not commited:
        #: we are in the case where the script calls for the first time check_sanity in order to proceed with the commits :#
        for line in f:

            if 'SANITY' in line and 'failed' in line:

                #: enter an 3min loop periodically until sanity box is green.Break the loop then. :#

                while (retry < 10):

                    #: give it some time until it tries again :#
                    #: There are some cases about sanity that need to be handled accordingly :#
                    #: 1)The sanity has left in red state and no-one is looking at this
                    #: |
                    #: |-----> the script will try for 30 minutes and abort.Before aborting it must restore
                    #:         the files that have been changed to their previous state
                    #: 2)The sanity is either red or green but it is expected by the responsible team to be fixed
                    #:   in less than 1h

                    time_period = 180
                    log.info(
                        'Sleeping for 3 mins in order to wait for sanity to be green')
                    time.sleep(time_period)
                    log.info('Retrying sanity check:%s' % retry)
                    retry += 1
                    return check_sanity()

                log.critical(
                    'Tried for 30minutes and sanity is still red.Aborting...num of retries:%s' % retry)
                sys.exit(8)

            elif 'SANITY' in line and 'successful' in line:
                green_rev = sanity_reg.search(line).group(1)
                is_green = True
                print'================================================='
                print 'Green revision currently on buildbot SANITY is ', green_rev
                print'================================================='
                print'Done\n'

                break

            else:
                pass

    #: we should get here when we call check_sanity with commited revision as parameter :#
    #: in order to verify if this revision ended with green sanity                      :#

    else:
        #: this is the case that we make sure our commits turned sanity into green :#
        for line in f:
            if 'SANITY/builds' in line:
                while sanity_reg.search(line).group(1) != commited:
                    print 'revision in buildot:', sanity_reg.search(line).group(1)
                    print 'revision that commited:', commited
                    sanity_reg.search(line).group(1) != commited
                    log.info(
                        'Currently building.Wait until our commited revision is in the sanity box and turns green')
                    time.sleep(120)
                    return check_sanity(commited)
                log.info('Commited revision %s is in sanity box' % commited)
                if 'successful' in line:
                    log.info(
                        'Commited revision %s turned green.SUCCESS!!!' % commited)
                    print'=========================================='
                    print'    We commited %s and is green ' % commited
                    print'=========================================='
                    green_rev = commited
                    is_green = True
                    break
                else:
                    log.error(
                        'We most probably broke sanity @ %s.Check manually' % commited)
                    error = 'Hi,\n\n Commited revision %s has resulted in red sanity.\n\nCould you please check?' % commited
                    sender = find_sender(username())
                    # send_mail(error,sender)
                    sys.exit(4)

    return (is_green, green_rev)