def test_commit_format():
    """
    Checks commit message format for the current PR's commits.

    Checks if commit messages follow the 50/72 git commit rule
    [https://www.midori-global.com/blog/2018/04/02/git-50-72-rule]
    and if commits are signed.
    """
    # Fetch the upstream repository.
    fetch_base_cmd = "git fetch {} {}".format(BASE_REPO, BASE_BRANCH)
    subprocess.run(fetch_base_cmd, shell=True, check=True)
    # Get hashes of PR's commits in their abbreviated form for
    # a prettier printing.
    shas_cmd = "git log --no-merges --pretty=%h --no-decorate " \
               "FETCH_HEAD..HEAD"
    shas = get_cmd_output(shas_cmd)

    for sha in shas.split():
        # Do not enforce the commit rules when the committer is dependabot.
        author_cmd = "git show -s --format='%ae'"
        author = get_cmd_output(author_cmd)
        if "dependabot" in author:
            continue
        message_cmd = "git show --pretty=format:%B -s " + sha
        message = get_cmd_output(message_cmd)
        message_lines = message.split("\n")
        assert len(message_lines) >= 3,\
            "The commit '{}' should contain at least 3 lines: title, " \
            "blank line and a sign-off one. Please check: " \
            "https://www.midori-global.com/blog/2018/04/02/git-50-72-rule."\
            .format(sha)
        title = message_lines[0]
        assert message_lines[1] == "",\
            "For commit '{}', title is divided into multiple lines. " \
            "Please keep it one line long and make sure you add a blank " \
            "line between title and description.".format(sha)
        assert len(title) <= COMMIT_TITLE_MAX_LEN,\
            "For commit '{}', title exceeds {} chars. " \
            "Please keep it shorter.".format(sha, COMMIT_TITLE_MAX_LEN)

        found_signed_off = False

        for line in message_lines[2:]:
            if line.startswith("Signed-off-by: "):
                found_signed_off = True
                # If we found `Signed-off-by` line, then it means
                # the commit message ended and we don't want to check
                # line lengths anymore for the current commit.
                break
            assert len(line) <= COMMIT_BODY_LINE_MAX_LEN,\
                "For commit '{}', message line '{}' exceeds {} chars. " \
                "Please keep it shorter or split it in " \
                "multiple lines.".format(sha, line,
                                         COMMIT_BODY_LINE_MAX_LEN)
        assert found_signed_off, "Commit '{}' is not signed. " \
                                 "Please run 'git commit -s --amend' " \
                                 "on it.".format(sha)
Exemple #2
0
def get_part_to_disk():
    """Function to get disk and partitions from lsblk command."""
    dict_disk_part = {}
    (lsblk, err) = utils.get_cmd_output('lsblk -bno  KNAME,TYPE | grep \'disk\|part\'')
    if err:
        collectd.error(
            'Plugin disk_stat in libdiskstat: error in lsblk command')
        return FAILURE
    disk_info = re.split('\n', lsblk)
    index = 0
    num_lines = len(disk_info)
    dname = None
    while index < num_lines:
        line = disk_info[index]
        if line:
            parts = re.split(r'\s+', line.strip())
            if parts[1] == 'disk':
                dname = parts[0]
            dict_disk_part[parts[0]] = dname
            index += 1
        else:
            break

    if not dict_disk_part:
        return FAILURE

    return dict_disk_part
Exemple #3
0
    def get_LLC_stats(self):
        LLCStats, LLCerr = utils.get_cmd_output("perf stat -a -e LLC-loads,LLC-load-misses sleep 2")

        sdlines = re.split("\n", LLCerr)
        num_lines = len(sdlines)
        index = 0
        LLCLoads = 0
        LLCLoadMisses = 0
        LLC = False
        while index < num_lines:
            line = sdlines[index]
            if line:
                if "perf not found for kernel" in line:
                    collectd.info(
                        "Plugin cpu_static: Perf is not installed for the kernel.")
                    return 0
                elif "not supported" in line:
                    collectd.info(
                        "Plugin cpu_static: LLC Statistics is hidden from Virtual machines.")
                    return 0
                elif "LLC-loads" in line:
                    LLCLoads = float(line.strip(" ").split(" ")[0].replace(",", ""))
                    LLC = True
                elif "LLC-load-misses" in line:
                    LLCLoadMisses = float(line.strip(" ").split(" ")[0].replace(",", ""))
                    LLC = True
                index += 1
            else:
                index += 1
        if LLC:
            return round(((LLCLoadMisses / LLCLoads) * 100), 2)

        return 0
def _main():
    debug('command:' + str(sys.argv))
    repos = sys.argv[1]
    txn = sys.argv[2]
    conf_filename = sys.argv[3]
    
    # read the configuration file.
    Conf conf;
    conf.read(conf_filename)

    svnlook = make_svnlook_cmd('changed', repos, txn)
    changed = get_cmd_output(svnlook)
    debug("main: "+changed)

    if is_ignorable(changed, conf.IGNORE_PATH):
        debug("All commit is ignorabled.")
        return

    if not conf.REVIEW_PATH:
        debug("not REVIEW_PATH return true")
        check_rb(repos, txn)
        return 

    for line in changed.split('\n'):
        f = line[4:]
        for review_path in REVIEW_PATH:
            if review_path in f:
                debug("Find ["+review_path +"] in line:"+f)
                check_rb(repos, txn)
                return
def get_review_id(repos, txn):
    svnlook = make_svnlook_cmd('log', repos, txn)
    log = get_cmd_output(svnlook)
    debug("get_review_id:"+log)
    rid = re.search(r'review:([0-9]+)', log, re.M | re.I)
    if rid:
        return rid.group(1)
    raise SvnError('No review id.')
Exemple #6
0
    def get_disk_info(self):
        """Function to get name, type, size and mountpoint info of disk and partition."""
        (lsblk, err) = utils.get_cmd_output(
            'lsblk -bno  KNAME,TYPE,SIZE,MOUNTPOINT | grep \'disk\|part\'')
        if err:
            collectd.error('Plugin disk_stat: error in lsblk command')
            return None

        disk_info = re.split('\n', lsblk)
        return disk_info
Exemple #7
0
 def grab(self, keys):
     '''Grab specific keys'''
     root_window = self.__display.screen().root
     keycode = 0
     xset_cmd = which("xset")
     xmodmap_cmd = which("xmodmap")
     if not xset_cmd:
         logging.warn(
             "xset not found, you might experience some bad key-repeat problems"
         )
     for key in keys:
         keycode = get_keycode(key)
         if not keycode:
             continue
         if xset_cmd:
             # FIXME: revert on exit
             os.system("%s -r %d" % (xset_cmd, keycode))
         if xmodmap_cmd:
             cmd_status, cmd_stdout = get_cmd_output("%s -pm" % xmodmap_cmd)
             if cmd_status == 0 and cmd_stdout:
                 lines = cmd_stdout.splitlines()
             else:
                 lines = []
             lock_line = [
                 l.strip().split() for l in lines if l.startswith("lock")
             ]
             num_line = [
                 l.strip().split() for l in lines if "Num_Lock" in l
             ]
             key_line = [l.strip().split() for l in lines if key in l]
             if lock_line:
                 parts = lock_line[0]
                 if len(parts) > 1:
                     self.__caps_lock = parts[1]
             if num_line:
                 parts = num_line[0]
                 if len(parts) > 1:
                     self.__num_lock_mod = parts[0]
             if key_line:
                 parts = key_line[0]
                 if len(parts) > 1:
                     self.__key_mod = parts[0]
         if key == "Caps_Lock":
             if not self.__caps_lock:
                 logging.debug("Caps Lock already disabled!")
             else:
                 self.disable_caps_lock()
                 atexit.register(self.enable_caps_lock)
         ownev = not self.__parent.getModality()
         root_window.grab_key(keycode, X.AnyModifier, ownev,
                              X.GrabModeAsync, X.GrabModeAsync)
         return key, keycode
     logging.critical("Couldn't find quasimode key")
     self.__parent.stop()
     return None, None
Exemple #8
0
    def get_iostat_data(self):
        """Returns dictionary with values avgqu_sz  """
        (iodata, err) = utils.get_cmd_output('iostat -d -x')
        if err:
            collectd.error(
                'Plugin disk_stat: error in iostat command or sysstat is not installed'
            )
            return None

        iodata_info = re.split('\n', iodata)
        iodata = {}
        for statline in iodata_info[3:]:
            if statline:
                iodata[statline.split()[0]] = statline.split()[8]
        return iodata
    def get_virtual_interfaces(self):
        """Function to get all virtual nics."""
        virt_if_list = []
        (virt_dev, err) = utils.get_cmd_output(
            'ls -l /sys/class/net/ | grep devices/virtual')
        if err:
            return virt_if_list

        virt_dev = virt_dev.splitlines()
        for device in virt_dev:
            # At the end of each line we have "/" followed by interface name
            index = device.rfind("/")
            if index != -1:
                ifname = device[index + 1:]
                virt_if_list.append(ifname)

        return virt_if_list
Exemple #10
0
    def add_agg_usage(self):
        """Function to get total usage."""
        (df_out, err) = utils.get_cmd_output(
            "df -kl |awk '/^\/dev\//' | awk '{print $3}'")
        if err:
            collectd.error('Plugin disk_stat: error in df command')
            return None

        splines = re.split('\n', df_out)
        unum_lines = len(splines)
        uindex = 0
        usage_sum = 0
        while uindex < unum_lines:
            line = splines[uindex]
            if line:
                usage_sum += int(line)  # usage_sum is in Kb
                uindex += 1
            else:
                uindex += 1
        return round(
            float((usage_sum * FACTOR)) / (FACTOR * FACTOR * FACTOR),
            FLOATING_FACTOR)
Exemple #11
0
    def add_agg_capacity(self):
        """Function to get total capacity."""
        lsblk, err = utils.get_cmd_output(
            "lsblk -nbo KNAME,TYPE,SIZE | grep disk | grep -v fd | awk '{print $3}'"
        )
        if err:
            collectd.error("Plugin disk_stat : error in lsblk command")
            return None

        sdlines = re.split("\n", lsblk)
        num_lines = len(sdlines)
        index = 0
        total_sum = 0
        while index < num_lines:
            line = sdlines[index]
            if line:
                total_sum += int(line)
                index += 1
            else:
                index += 1
        return round(
            float(total_sum) / (FACTOR * FACTOR * FACTOR), FLOATING_FACTOR)
 def get_svnlook():
     platform = sys.platform
     if platform.startswith('win'):
         return get_cmd_output(['where svnlook']).split('\n')[0].strip()
     return 'svnlook'
Exemple #13
0
def test_commit_format():
    """
    Checks commit message format for the current PR's commits.

    Checks if commit messages follow the 60/75 commit rule (a maximum
    60 characters for the title and 75 characters for description
    lines) and if commits are signed.
    """
    # Newer versions of git check the ownership of directories.
    # We need to add an exception for /workdir which is shared, so that
    # the git commands don't fail.
    config_cmd = "git config --global --add safe.directory /workdir"
    subprocess.run(config_cmd, shell=True, check=True)
    # Fetch the upstream repository.
    fetch_base_cmd = "git fetch {} {}".format(REMOTE, BASE_BRANCH)
    try:
        subprocess.run(fetch_base_cmd, shell=True, check=True)
    except subprocess.CalledProcessError:
        raise NameError("The name of the base branch or remote is invalid. "
                        "See test documentation for more details.") from None
    # Get hashes of PR's commits in their abbreviated form for
    # a prettier printing.
    shas_cmd = "git log --no-merges --pretty=%h --no-decorate " \
               "FETCH_HEAD..HEAD"
    shas = get_cmd_output(shas_cmd)

    for sha in shas.split():
        # Do not enforce the commit rules when the committer is dependabot.
        author_cmd = "git show -s --format='%ae' " + sha
        author = get_cmd_output(author_cmd)
        if "dependabot" in author:
            continue
        message_cmd = "git show --pretty=format:%B -s " + sha
        message = get_cmd_output(message_cmd)
        message_lines = message.split("\n")
        assert len(message_lines) >= 3,\
            "The commit '{}' should contain at least 3 lines: title, " \
            "blank line and a sign-off one." \
            .format(sha)
        title = message_lines[0]
        assert message_lines[1] == "",\
            "For commit '{}', title is divided into multiple lines. " \
            "Please keep it one line long and make sure you add a blank " \
            "line between title and description.".format(sha)
        assert len(title) <= COMMIT_TITLE_MAX_LEN,\
            "For commit '{}', title exceeds {} chars. " \
            "Please keep it shorter.".format(sha, COMMIT_TITLE_MAX_LEN)

        found_signed_off = False

        for line in message_lines[2:]:
            if line.startswith("Signed-off-by: "):
                found_signed_off = True
                # If we found `Signed-off-by` line, then it means
                # the commit message ended and we don't want to check
                # line lengths anymore for the current commit.
                break
            assert len(line) <= COMMIT_BODY_LINE_MAX_LEN,\
                "For commit '{}', message line '{}' exceeds {} chars. " \
                "Please keep it shorter or split it in " \
                "multiple lines.".format(sha, line,
                                         COMMIT_BODY_LINE_MAX_LEN)
        assert found_signed_off, "Commit '{}' is not signed. " \
                                 "Please run 'git commit -s --amend' " \
                                 "on it.".format(sha)