Example #1
0
 def extract_binary(pth_to_pkg, dest_pth=None):
     cpio_command = runCmd("which cpio")
     rpm2cpio_command = runCmd("ls /usr/bin/rpm2cpio")
     if (cpio_command.status != 0) and (rpm2cpio_command.status != 0):
         bb.fatal("Either \"rpm2cpio\" or \"cpio\" tools are not available on your system."
                 "All binaries extraction processes will not be available, crashing all related tests."
                 "Please install them according to your OS recommendations") # will exit here
     if dest_pth:
         os.chdir(dest_pth)
     else:
         os.chdir("%s" % os.sep)# this is for native package
     extract_bin_command = runCmd("%s %s | %s -idm" % (rpm2cpio_command.output, pth_to_pkg, cpio_command.output)) # semi-hardcoded because of a bug on poky's rpm2cpio
     return extract_bin_command
Example #2
0
def runvtl_commands(username, password, ip, serviceset_id):
    """
    run vtl commands and print performance data
    :param username: username
    :param password: password
    :param ip: ip
    :param serviceset_id:
    :return:
    """
    cmd_throughput_hour = "curl  -s --insecure --user '%s:%s' \"https://%s/storeonceservices/cluster/servicesets/%s/services/vtl/parametrics/throughput/reports/hour/libraries?media=txt\"" % (
        username, password, ip, serviceset_id)
    tmpCmd = "curl -s  --insecure --user '%s:%s' \"https://%s/storeonceservices" % (
        username, password, ip)

    timeout = 300

    [retcode, stdout, stderr] = runCmd(cmd_throughput_hour, timeout)
    content = ''
    if retcode == 0:

        lib_list = printvtl_libInfo(stdout)
        for x in lib_list:
            current_date_time = datetime.datetime.now()
            my_time = current_date_time - timedelta(minutes=60)

            timestamp = my_time.strftime('%Y-%m-%dT%H:%M:%SZ')
            cmd_throughput = tmpCmd + x + "?startTime=" + timestamp + "&media=txt" + "\""
            [libretcode, libstdout, libstderr] = runCmd(cmd_throughput, 300)
            lib = x[x.find('/libraries/') + 1:]
            content += lib + "\n"
            for line in libstdout.split("\n"):
                if "readThroughput" in line:
                    content += line
                if "writeThroughput" in line:
                    content += line
                    content += "\n"
        if content == "":
            print "WARNING | No VTL Libraries Configured"
            sys.exit(1)
        else:
            print "OK | %s" % content
            sys.exit(0)
    else:
        if content == "":
            print "WARNING | No VTL Libraries Configured"
            sys.exit(1)
        else:
            print "ERROR - unable to retrieve VTL throughput information"
            print "%s" % stdout
            sys.exit(3)
Example #3
0
def get_docker_token(repo):
  print "Getting docker.io token ...."
  e, o = runCmd('curl --silent --request "GET" "https://auth.docker.io/token?service=registry.docker.io&scope=repository:%s:pull"' % repo)
  if e:
    print o
    exit(1)
  return loads(o)['token']
Example #4
0
def main():
    """
    parses the command line arguments and does some sanity checks on them, runs curl commands
    :return:
    """
    total = len(sys.argv)
    if total <= 3:
        print("Invalid Input, please pass the IP, username and password")
        exit(1)

    ip = sys.argv[1]
    username = sys.argv[2]
    password = sys.argv[3]

    timeout = 300

    serviceset_cmd = "curl  -s --insecure --user '%s:%s' \"https://%s/storeonceservices/cluster/servicesets?media=txt\"" % (
        username, password, ip)

    [retcode, stdout, stderr] = runCmd(serviceset_cmd, timeout)
    if stdout == "":
        print "WARNING - No Service Sets returned"
        sys.exit(1)
    serviceset_list = get_servicesets(stdout)

    for i in serviceset_list:
        runvtl_commands(username, password, ip, i)
Example #5
0
def get_docker_manifest(repo, tag):
  token = get_docker_token(repo)
  print "Getting manifest for %s/%s" % (repo, tag)
  e, o = runCmd('curl --silent --request "GET" --header "Authorization: Bearer %s" "https://registry-1.docker.io/v2/%s/manifests/%s"' % (get_docker_token(repo), repo, tag))
  if e:
    print o
    exit(1)
  return loads(o)
Example #6
0
 def extract_binary(pth_to_pkg, dest_pth=None):
     cpio_command = runCmd("which cpio")
     rpm2cpio_command = runCmd("ls /usr/bin/rpm2cpio")
     if (cpio_command.status != 0) and (rpm2cpio_command.status != 0):
         bb.fatal(
             "Either \"rpm2cpio\" or \"cpio\" tools are not available on your system."
             "All binaries extraction processes will not be available, crashing all related tests."
             "Please install them according to your OS recommendations"
         )  # will exit here
     if dest_pth:
         os.chdir(dest_pth)
     else:
         os.chdir("%s" % os.sep)  # this is for native package
     extract_bin_command = runCmd(
         "%s %s | %s -idm" %
         (rpm2cpio_command.output, pth_to_pkg, cpio_command.output)
     )  # semi-hardcoded because of a bug on poky's rpm2cpio
     return extract_bin_command
def main():
    """ parses the command line arguments and does some sanity checks on them, runs curl commands
        and displays the output
    """

    total = len(sys.argv)
    if total <= 3:
        print("Invalid Input, please pass the IP, username and password")
        exit(1)

    ip = sys.argv[1]
    username = sys.argv[2]
    password = sys.argv[3]

    command_serviceset_health = "curl -s --insecure --user '%s:%s' \"https://%s/storeonceservices/cluster/servicesets?view=info&media=txt\"" % (
        username, password, ip)
    timeout = 300
    [retcode, stdout, stderr] = runCmd(command_serviceset_health, 300)

    for line in stdout.split("\n"):
        if line.find("Timeout") != -1:
            print "WARNING - Timeout while trying to reach the server"
            sys.exit(1)
    if stdout == "":
        print "WARNING - No Service Sets returned"
        sys.exit(1)

    if retcode == 0:
        servcieSetoutput = getServciesetoutput(stdout)
        status = getStatusServicesetInfo(stdout)
        if status == "Running":
            print "OK - Serviceset Status: Running\n"
            print servcieSetoutput
            sys.exit(0)
        elif status == "Fault":
            print " WARNING - ServiceSet Status: %s\n" % status
            print servcieSetoutput
            sys.exit(1)
        else:
            print
            "UNKNOWN ERROR: Unknown Status: %s\n" % status
            print servcieSetoutput
            sys.exit(3)
    else:
        print "UNKNOWN ERROR - Unable to retrieve Servcieset Information"
        print stdout
        sys.exit(3)
def main():
    """
    parses the command line arguments and does some sanity checks on them, runs curl commands
    and displays the output
    :return:
    """
    total = len(sys.argv)
    if total <= 3:
        print("Invalid Input, please pass the IP, username and password")
        exit(1)

    IP = sys.argv[1]
    username = sys.argv[2]
    password = sys.argv[3]

    command_systemhealth_capacity = "curl -s --insecure --user '%s:%s' \"https://%s/d2dservices/storagesets?view=info&media=txt\"" % (
        username, password, IP)

    timeout = 300
    [retcode, stdout, stderr] = runCmd(command_systemhealth_capacity, timeout)
    retStatus = 0

    for line in stdout.split("\n"):
        if line.find("Timeout") != -1:
            print "WARNING - Timeout while trying to reach the server"
            sys.exit(1)

    for line in stdout.split("\n"):
        if line.find("Status") != -1:
            retStatus = 1

    if retcode == 0:
        if retStatus == 1:
            print "OK - Successfully retrieved System Health and Capacity Information\n"
            print stdout
            sys.exit(0)
        else:
            print "Warning - %s" % stdout
            sys.exit(1)
    else:
        print "ERROR - unable to retrieve System Health and Capacity Information "
        print stdout
        sys.exit(3)
Example #9
0
def cleanup_exit(msg, tmpdirs=[], image_hash="", exit_code=1):
  if msg:    print msg
  for tdir in tmpdir: runCmd("rm -rf %s" % tdir)
  if image_hash: runCmd("docker rm -f %s" % image_hash)
  exit(exit_code)
Example #10
0
def process(image, outdir):  
  container = image.split(":",1)[0]
  tag = image.split(":",1)[-1]
  if container==tag: tag="latest"

  e, image_hash = runCmd("docker pull %s 2>&1 >/dev/null; docker images %s | grep '^%s \|/%s ' | grep ' %s ' | sed 's|  *|:|g' | cut -d: -f3" % (image, container, container, container, tag))
  if e:
    print image_hash
    exit(1)

  img_sdir = join(".images", image_hash[0:2], image_hash)
  img_dir = join(outdir, img_sdir)
  if exists(img_dir): return

  print "Starting Container %s" % image
  tmpdir = join(outdir, ".images", "tmp")
  e, o = runCmd('docker run --name %s %s echo OK' % (image_hash,image))
  if e: cleanup_exit(o, [tmpdir], image_hash)

  print "Getting Container Id"
  e, o = runCmd('docker ps -aq --filter name=%s' % image_hash)
  if e: cleanup_exit(o, [tmpdir], image_hash)
  container_id = o

  print "Exporting Container ",container_id
  e, o = runCmd('rm -rf %s; mkdir -p %s; cd %s; docker export -o %s.tar %s' % (tmpdir, tmpdir, tmpdir,image_hash, container_id))
  if e: cleanup_exit(o, [tmpdir], image_hash)

  print "Cleaning up container ",image_hash
  runCmd('docker rm -f %s' % image_hash)

  print "Unpacking exported container ...."
  e, o = runCmd('mkdir -p %s; cd %s; tar -xf %s/%s.tar' % (img_dir, img_dir, tmpdir, image_hash))
  if e: cleanup_exit(o, [tmpdir, img_dir])
  runCmd('rm -rf %s' % tmpdir)

  for xdir in [ "srv", "cvmfs", "dev", "proc", "sys", "build", "data", "pool" ]:
    sdir = join(img_dir, xdir)
    if not exists(sdir): runCmd('mkdir %s' % sdir)
  
  print "Fixing file modes ...."
  fix_modes (img_dir)
Example #11
0
 def dump_host(self, dump_dir=""):
     if dump_dir:
         self.dump_dir = dump_dir
     for cmd in self.cmds:
         result = runCmd(cmd, ignore_status=True)
         self._write_dump(cmd.split()[0], result.output)
Example #12
0
 def dump_host(self, dump_dir=""):
     if dump_dir:
         self.dump_dir = dump_dir
     for cmd in self.cmds:
         result = runCmd(cmd, ignore_status=True)
         self._write_dump(cmd.split()[0], result.output)