Example #1
0
def fix_multipath_1():
    """Installs multipath tooling packages"""
    vprint("Fixing multipath settings")
    if get_os() == UBUNTU:
        exe("apt-get install multipath-tools -y")
    else:
        exe("yum install device-mapper-multipath -y")
Example #2
0
def fix_block_devices_1():
    """Updates GRUB with noop scheduling, requires restart"""
    vprint("Fixing block device settings")
    grub = "/etc/default/grub"
    bgrub = "/etc/default/grub.bak.{}".format(str(uuid.uuid4())[:4])
    vprint("Backing up grub default file to {}".format(bgrub))
    shutil.copyfile(grub, bgrub)
    vprint("Writing new grub default file")
    data = []
    with io.open(grub, "r+") as f:
        for line in f.readlines():
            if ("GRUB_CMDLINE_LINUX_DEFAULT=" in line and
                    "elevator=noop" not in line):
                i = line.rindex("\"")
                lline = list(line)
                if lline[i-1] == "\"":
                    lline.insert(i, "elevator=noop")
                else:
                    lline.insert(i, " elevator=noop")
                line = "".join(lline)
            data.append(line)
    with io.open(grub, "w+") as f:
        print(data)
        f.writelines(data)
    if get_os() == UBUNTU:
        exe("update-grub2")
    else:
        exe("grub2-mkconfig -o /boot/grub2/grub.cfg")
Example #3
0
def fix_multipath_2():
    """Enables multipathd service"""
    if get_os() == UBUNTU:
        exe("systemctl start multipath-tools")
        exe("systemctl enable multipath-tools")
    else:
        exe("systemctl start multipathd")
        exe("systemctl enable multipathd")
Example #4
0
def fix_cpufreq_1():
    """Installs cpufreq tooling packages"""
    if get_os() == UBUNTU:
        # Install necessary headers and utils
        exe("apt-get install linux-tools-$(uname -r) "
            "linux-cloud-tools-$(uname -r) linux-tools-common -y")
        # Install cpufrequtils package
        exe("apt-get install cpufrequtils -y")
    else:
        # Install packages
        exe("yum install kernel-tools -y")
Example #5
0
def fix_cpufreq_2():
    """Updates governer to performance via cpufreq"""
    # Update governor
    exe("cpupower frequency-set --governor performance")
    # Restart service
    if get_os() == UBUNTU:
        exe("service cpufrequtils restart")
    else:
        exe("service cpupower restart")
        exe("systemctl daemon-reload")
    # Remove ondemand rc.d files
    exe("rm -f /etc/rc?.d/*ondemand")
Example #6
0
  def execute(self):
    platform   = common.get_os()
    module     = os.path.split(os.path.abspath(""))[1]
    test       = self.test_dir
    start_time = time.strftime("%Y.%m.%d %H:%M:%S")

    return_value = self.perform_test();
    
    end_time = time.strftime("%Y.%m.%d %H:%M:%S")
    
    self.record_results(platform, module, test, start_time, end_time, return_value[0])
    
    self.failIf(return_value[0] != 0, return_value[1])
Example #7
0
def fix_multipath_conf_1():
    """Writes completely new multipath.conf based off of template"""
    mfile = "/etc/multipath.conf"
    bfile = "/etc/multipath.conf.bak.{}".format(str(uuid.uuid4())[:4])
    if os.path.exists(mfile):
        vprint("Found existing multipath.conf, moving to {}".format(bfile))
        shutil.copyfile(mfile, bfile)
    with io.open("/etc/multipath.conf", "w+") as f:
        if get_os() == UBUNTU:
            f.write(MULTIPATH_CONF.replace("REPLACEME", "timer"))
        else:
            mconf = MULTIPATH_CONF.replace("REPLACEME", "timeout")
            # filter out getuid line which is deprecated in RHEL
            mconf = "\n".join((line for line in mconf.split("\n")
                               if "getuid" not in line))
            f.write(mconf)
Example #8
0
def check_cpufreq(config):
    vprint("Checking cpufreq settings")
    if not exe_check("which cpupower"):
        if get_os() == UBUNTU:
            version = exe("uname -r").strip()
            fix = "apt-get install linux-tools-{}".format(version)
        else:
            # RHEL puts this stuff in kernel-tools
            fix = "yum install kernel-tools"
        return ff("cpupower is not installed", "20CEE732", fix=fix)
    if not exe_check(
            "cpupower frequency-info --governors | "
            "grep performance", err=False):
        fix = ("No-fix -- if this system is a VM governors might not be "
               "available and this check can be ignored")
        return ff("No 'performance' governor found for system",
                  "333FBD45",
                  fix=fix)
Example #9
0
def check_multipath_conf(config):
    dist = get_os()
    vfile = CONFS.get(dist)
    if not vfile:
        wf("No supported multipath.conf file for: {}".format(dist), "381CE248")
    mfile = "/etc/multipath.conf"
    if not os.path.exists(mfile):
        if not vfile:
            fix = "copy a multipath.conf file from the Datera Deployment Guide"
        else:
            fix = "copy {} to /etc/multipath.conf".format(vfile)
        return ff("/etc/multipath.conf file not found", "1D506D89", fix=fix)
    with io.open(mfile, 'r') as f:
        mconf = parse_mconf(f.read())

    # Check defaults section
    defaults = filter(lambda x: x[0] == 'defaults', mconf)
    fix = ("check the example multipath.conf file from Datera deployment"
           "guide")
    if not defaults:
        ff("Missing defaults section", "1D8C438C", fix=fix)

    else:
        defaults = defaults[0]
        ct = False
        for d in defaults[1]:
            if 'checker_timeout' in d:
                ct = True
        if not ct:
            ff("defaults section missing 'checker_timeout'",
               "70191A9A",
               fix=fix)

    # Check devices section
    devices = filter(lambda x: x[0] == 'devices', mconf)
    if not devices:
        ff("Missing devices section", "797A6031", fix=fix)
    else:
        devices = devices[0][1]
        dat_block = None
        for _, device in devices:
            ddict = {}
            for entry in device:
                ddict[entry[0]] = entry[1]
            if ddict['vendor'] == 'DATERA':
                dat_block = ddict
        if not dat_block:
            return ff("No DATERA device section found", "99B9D136", fix=fix)

        if not dat_block['product'] == "IBLOCK":
            ff("Datera 'product' entry should be \"IBLOCK\"",
               "A9DF3F8C",
               fix=fix)

    # Blacklist exceptions
    be = filter(lambda x: x[0] == 'blacklist_exceptions', mconf)
    if not be:
        ff("Missing blacklist_exceptions section", "B8C8A19C")
    else:
        be = be[0][1]
        dat_block = None
        for _, device in be:
            bdict = {}
            for entry in device:
                bdict[entry[0]] = entry[1]
            if bdict['vendor'] == 'DATERA.*':
                dat_block = bdict
        if not dat_block:
            ff("No Datera blacklist_exceptions section found",
               "09E37E51",
               fix=fix)
        if dat_block['vendor'] != 'DATERA.*':
            ff("Datera blacklist_exceptions vendor entry malformed",
               "9990F32F",
               fix=fix)
        if dat_block['product'] != 'IBLOCK.*':
            ff("Datera blacklist_exceptions product entry malformed",
               "642753A0",
               fix=fix)
Example #10
0
  def perform_test(self):
    
    self.execution_path = os.path.abspath("")
    
    test_path = self.get_test_path()

    if (os.path.isdir(test_path) == 0):
      return (3, 'Could not find directory %s' % test_path)
    
    # Get the current directory and apply any relative pathing to it

    curr_path = os.path.abspath(self.relative_path)

    os.chdir(test_path)

    # - Execute test program.
    #


    test_return = os.system('%s/%s' % (curr_path, self.cmd))

    # - Test for success or failure appropriately
    #
    if (self.success_expected):
      if(test_return != 0):
        return (1, 'Test program execution failure.')
    else:
      if(test_return == 0):
        return (2, 'Test program execution non-failure.')
      
    # - Diff result outputs of test program against expected results.
    #
    redirect = '>'

    os.system('rm brokenfiles 2>/dev/null')

    for idx in range(len(self.file_names)):
      if idx != 0:
        redirect = '>>'

      file_name = self.file_names[idx]

      # Determine the expected file name - This is either the file name
      # with '.exp' appended or '.<OS>.exp' appended if there is an OS
      # specific version of the expected file

      OS = common.get_os()

      exp_file_name = '%s.%s.exp' % (file_name, OS)
      exp_file_path = './%s' % exp_file_name

      if os.access(exp_file_path, os.F_OK) == 0 :
        exp_file_name = '%s.exp' % file_name
        exp_file_path = './%s' % exp_file_name

      if(os.path.exists(exp_file_path) == 0):
        return (4, 'File %s not found.' % exp_file_name)

      # - Create a copy of the file as <file>.stripped that can be compared
      #   against the .exp file.  This is to preserve the existing file.
      #
      strip(file_name, STRIP_LIST)

      # - Make 'NANQ' and 'INF' uniform across platforms.
      #

      sed_run_cmd = 'sed -f %s/sed_script %s > %s/temp' % (seddir, file_name + ".stripped", seddir)
      os.system(sed_run_cmd)
      mv_cmd = 'mv %s/temp ./%s' % (seddir, file_name + ".stripped")
      os.system(mv_cmd)

      # do the diffing.

      command = "numdiff -d%s -e%s " % (self.delta, self.epsilon)

      ret_type = os.system('%s %s %s %s testdiffs' % \
            (command, exp_file_name, file_name + ".stripped", redirect))

      if ret_type == 0:
        # If there are no diffs, we can delete the .stripped file
        os.system('rm ' + file_name + '.stripped')

        if self.keep_files == 0:
          os.system('rm ' + file_name)
      else:
        os.system('echo ' + file_name + ' >>brokenfiles')


    results = os.stat('testdiffs')
    if(results[stat.ST_SIZE] != 0):
      return (5, 'Test Failure.  See %s/testdiffs for details.' % test_path)
    else:
      os.system('rm testdiffs')
      
    return (0, "Success")
Example #11
0
 def get_OS(self):
     self.OS = get_os()
Example #12
0
def check_os(config):
    os = get_os()
    if os not in SUPPORTED_OS_TYPES:
        return ff(
            "Unsupported Operating System. Supported operating systems: "
            "{}".format(list(SUPPORTED_OS_TYPES)), "3C47368")