示例#1
0
    def Launch(self):
        # Unbinding PCI device
        dbg.print_info("Unbinding VF @%s" % self.bdf)
        cmd = "sudo modprobe vfio-pci"
        rv = ex.executeCmdBlockReturnCode(cmd, self.flog, "localhost",
                                          self.remote_script_name)
        if rv != 0:
            dbg.print_info("'%s' failed on machine '%s'" % (cmd, self.name))
            return rv

        sys_path = "/sys/bus/pci/devices/%s/driver/unbind" % self.bdf
        sys_path = sys_path.replace(':', '\\:')
        cmd = "sudo sh -c \"echo '%s' > %s\"" % (self.bdf, sys_path)
        ex.executeCmdCheckReturnCode(cmd, self.flog, "localhost",
                                     self.remote_script_name)

        sys_path = "/sys/bus/pci/drivers/vfio-pci/new_id"
        sys_path = sys_path.replace(':', '\\:')
        vendor_device = self.syscfg.getVFVendorDevice()
        cmd = "sudo sh -c \"echo '%x %x' > %s\"" % (vendor_device[0],
                                                    vendor_device[1], sys_path)
        ex.executeCmdCheckReturnCode(cmd, self.flog, "localhost",
                                     self.remote_script_name)

        super(BareVM, self).Launch()
示例#2
0
文件: testlib.py 项目: minmit/tonic
    def Run(self):
        # Build simulation model
        dbg.print_info("Building simulation model for '%s'" % self.name)
        flog = open(self.buildsim_log, 'w')
        rv = sim.buildSim(self.name, self.tb_dir, self.tb_name_l,
                          self.GetParams(), self.GetSpecs(), self.build_dir,
                          flog)
        flog.close()
        if rv != 0:
            dbg.print_error("Failed to build a simulation model for '%s'" %
                            self.name)
            dbg.print_error("Check log: %s" % self.buildsim_log)
            return 1

        # Run Simulation
        dbg.print_info("Running simulation for '%s'" % self.name)
        flog = open(self.runsim_log, 'w')
        sim.runSim(self.name, self.build_dir, flog)
        flog.close()

        # Check if test passed
        if sim.isTestPassed(self.runsim_log):
            dbg.print_success("Test for '%s' passed" % self.name)
        else:
            dbg.print_error("Test for '%s' failed" % self.name)

        return 0
示例#3
0
文件: testlib.py 项目: minmit/tonic
    def Run(self):
        # Build simulation model
        dbg.print_info("Building simulation model for '%s'" % self.name)
        flog = open(self.buildsim_log, 'w')

        if self.NeedsReceiver():
            rv = sim.buildSimWithVPI(self.name, self.tb_dir, self.tb_name_l,
                                     self.GetParams(), self.GetSpecs(),
                                     self.build_dir, flog)
        else:
            rv = sim.buildSim(self.name, self.tb_dir, self.tb_name_l,
                              self.GetParams(), self.GetSpecs(),
                              self.build_dir, flog)

        flog.close()
        if rv != 0:
            dbg.print_error("Failed to build a simulation model for '%s'" %
                            self.name)
            dbg.print_error("Check log: %s" % self.buildsim_log)
            return 1

        # Run Simulation
        dbg.print_info("Running simulation for '%s'" % self.name)
        flog = open(self.runsim_log, 'w')
        sim.runSim(self.name, self.build_dir, flog)
        flog.close()

        # Check if test passed
        dbg.print_success("Simulation for '%s' finished" % self.name)

        return 0
示例#4
0
    def Launch(self, flog):
        if socket.gethostname() != cfg.L1_VM_NAME:
            dbg.print_error(
                "L2 VM can be launched only from inside of '%s' machine")
            return False
        else:
            # Unbinding PCI device
            cmd = "modprobe vfio-pci"
            rv = ex.executeCmdBlockReturnCode(cmd, flog, "localhost",
                                              self.remote_script_name)
            if rv != 0:
                dbg.print_info("'%s' failed on machine '%s'" %
                               (cmd, self.name))
                return rv

            cmd = "echo '\"%s\"' > /sys/bus/pci/devices/%s/driver/unbind" % (
                self.bdf, self.bdf)
            rv = ex.executeCmdBlockReturnCode(cmd, flog, "localhost",
                                              self.remote_script_name)
            if rv != 0:
                dbg.print_error("'%s' failed on machine '%s'" %
                                (cmd, self.name))
                return rv

            cmd = "echo '\"8086 100e\"' > /sys/bus/pci/drivers/vfio-pci/new_id"
            rv = ex.executeCmdBlockReturnCode(cmd, flog, "localhost",
                                              self.remote_script_name)
            if rv != 0:
                dbg.print_error("'%s' failed on machine '%s'" %
                                (cmd, self.name))
                return rv

            super(L2VM, self).Launch(flog)
示例#5
0
def leaveSwarm(h_cfg):
    cmd = "docker swarm leave -f"
    valid_error_str = "This node is not part of a swarm"
    rv = tryExecute(cmd, h_cfg.host_name, valid_error_str)
    if rv == 0:
        dbg.print_info("%s: left a previous swarm" % h_cfg.host_name)

    return rv
示例#6
0
 def Launch(self):
     if self.flog == None:
         self.flog = open(self.flog_path, 'w')
     dbg.print_info("Launching '%s'" % self.name)
     cmd = self.GetLaunchCmd()
     common.logCmd(self.flog, cmd)
     proc = ex.executeCmd(cmd, self.flog, self.host_machine,
                          self.remote_script_name)
     self.vm_proc = proc
示例#7
0
def removeNetwork(h_cfg):
    cmd = "docker network rm %s" % h_cfg.nw_name
    valid_error_str = "No such network"
    rv = tryExecute(cmd, h_cfg.host_name, valid_error_str)
    if rv == 0:
        dbg.print_info("%s: removed network '%s'" % \
                        (h_cfg.host_name, h_cfg.nw_name))

    return rv
示例#8
0
def removeContainer(container_cfg):
    cmd = "docker rm %s" % container_cfg.name
    valid_error_str = "No such container"
    rv = tryExecute(cmd, container_cfg.host_name, valid_error_str)
    if rv == 0:
        dbg.print_info("%s: removed container '%s'" % \
                       (container_cfg.host_name, container_cfg.name))

    return rv
示例#9
0
 def WaitForBoot(self):
     dbg.print_info("Waiting for '%s' to boot" % self.name)
     retry_interval = 2
     retry_num = self.max_boot_time / retry_interval
     rv = ex.executeCmdBlockWithRetry("hostname", retry_num, retry_interval,
                                      self.flog, self.ssh_name,
                                      self.remote_script_name)
     if rv != 0:
         dbg.print_error("Waiting for boot failed for '%s'" % self.name)
     return rv
示例#10
0
def executeCmdBlockWithRetry(cmd, max_retries, interval, flog, hostname,
                             script_name):
    rv = executeCmdBlockReturnCode(cmd, flog, hostname, script_name)
    retry_cnt = 1
    while (rv != 0) and (retry_cnt <= max_retries):
        time.sleep(interval)
        dbg.print_info("Retry # %d" % retry_cnt)
        rv = executeCmdBlockReturnCode(cmd, flog, hostname, script_name)
        retry_cnt += 1
    return rv
示例#11
0
文件: testlib.py 项目: minmit/tonic
    def Run(self):
        # Generate src/snk files
        dbg.print_info("Generating SRC/SNK files for '%s'" % self.name)
        rv = self.genSrcSnk()
        if rv != 0:
            dbg.print_error("Failed to generate SRC/SNK files for '%s'" %
                            self.name)
            dbg.print_error("Check log: %s" % self.gen_ss_log)
            return 1

        super(UnitTest, self).Run()
示例#12
0
def createSwarm(h1_cfg, h2_cfg):
    # Create swarm on server's host
    dbg.print_info("%s: initializing swarm" % h1_cfg.host_name)
    join_cmd = initSwarm(h1_cfg)
    if join_cmd == None:
        return 1

    # Join to a swarm on client's host
    dbg.print_info("%s: joining swarm" % h2_cfg.host_name)
    rv = joinSwarm(h2_cfg, join_cmd)
    return rv
示例#13
0
def runContainer(container_cfg, flog):
    rv = removeContainer(container_cfg)
    if rv != 0:
        return 1

    cmd = container_cfg.getRunCmd()
    p = ex.executeCmd(cmd, flog, container_cfg.host_name,
                      container_cfg.sh_script)
    dbg.print_info("%s: container '%s' is running" % \
                  (container_cfg.host_name, container_cfg.name))
    return p
示例#14
0
def validateTrace(trace_path):
    max_line_w = 200

    flog = open(trace_path, 'r')

    cnt = 0
    for l in flog:
        if len(l) > max_line_w:
            dbg.print_error("Encountered a line longer than %d characters in %s" % (max_line_w, trace_path))
        cnt += 1

    dbg.print_info("Number of lines in %s: %d" % (trace_path, cnt))
    flog.close()
示例#15
0
 def ReplicateForWorkloads(self, workload_cfg):
     new_cfg_l = list()
     for tnt_num in workload_cfg.tenant_num_l:
         for bw in workload_cfg.link_gbps_l:
             for test_name in workload_cfg.test_name_l:
                 new_cfg = copy.deepcopy(self)
                 new_cfg.did_order = workload_cfg.tenant_order
                 new_cfg.tnt_num = tnt_num
                 new_cfg.testname = test_name
                 new_cfg.consec_transl = workload_cfg.consec_transl
                 new_cfg.link_gbps = bw
                 new_cfg_l.append(new_cfg)
     dbg.print_info("Replicated HW Configuration for %d SW configuration" %
                    len(new_cfg_l))
     return new_cfg_l
示例#16
0
    def ExecuteAllBlock(self, cmd):
        pid_vmname_d = dict()
        proc_l = list()
        for v in self.vm_l:
            proc = v.ExecuteNonBlock(cmd, subp.PIPE)
            proc_l.append(proc)
            pid_vmname_d[proc.pid] = v.name

        err_proc_l = ex.waitProcGroupAndCheckExitCode(proc_l)
        if len(err_proc_l) > 0:
            for proc in err_proc_l:
                dbg.print_error("'%s' failed on %s" %
                                (cmd, pid_vmname_d[proc.pid]))
                output, error = proc.communicate()
                dbg.print_error(error)
        else:
            dbg.print_info("'%s' was executed successfully on %d machines!" %
                           (cmd, len(self.vm_l)))
示例#17
0
def createOverlayNetwork(h_cfg):
    if removeNetwork(h_cfg) != 0:
        return None

    dbg.print_info("%s: creating overlay network '%s'" % \
                   (h_cfg.host_name, h_cfg.nw_name))
    cmd = "docker network create --driver=overlay --attachable %s" % h_cfg.nw_name
    nw_id = None
    p = ex.executeCmd(cmd, subprocess.PIPE, h_cfg.host_name, "create_nw.sh")
    output, error = p.communicate()
    if p.returncode != 0:
        dbg.print_error("Can not create network '%s' on host '%s'" % \
                        (h_cfg.nw_name, h_cfg.host_name))
        dbg.print_error(error)
        return None
    else:
        nw_id = output

    return nw_id
示例#18
0
文件: commonlib.py 项目: minmit/tonic
def launchSlurmJob(job_name, cmd, slurm_dep_l, flog_path):
    slurm_file = job_name + ".slurm"
    fp = open(slurm_file, "w")
    fp.write("#!/bin/sh\n")
    fp.write("#SBATCH -N 1\n")
    fp.write("#SBATCH -c 8\n")
    fp.write("#SBATCH --mem=65536\n")
    fp.write("#SBATCH -t 24:00:00\n")
    fp.write("#SBATCH -J %s\n\n" % job_name)
    fp.write("%s > %s" % (cmd, flog_path))
    fp.close()

    os.chmod(slurm_file, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

    retry_limit = 128

    if len(slurm_dep_l) > 0:
        opt_dep = "--dependency=afterok:" + ':'.join(
            [str(job_id) for job_id in slurm_dep_l])
    else:
        opt_dep = ''

    slurm_cmd = "sbatch %s %s" % (opt_dep, slurm_file)
    dbg.print_info("Slurm command: %s" % slurm_cmd)
    proc = subprocess.Popen(shlex.split(slurm_cmd),
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    out, err = proc.communicate()
    retry_cnt = 1
    while proc.returncode != 0:
        if retry_cnt > retry_limit:
            dbg.print_error("Failed to submit command %s through slurm" % cmd)
            return None
        else:
            dbg.print_info(
                "Slurm submission failed. Retrying in 30 seconds...")
            time.sleep(30)
            dbg.print_info("Submitting slurm job")
            proc = subprocess.Popen(shlex.split(slurm_cmd),
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            out, err = proc.communicate()

    # Get job ID
    match = re.match("Submitted batch job (\d+)\n", out)
    if match != None:
        job_id = int(match.group(1))
        dbg.print_info("Submitted batch job %d" % job_id)
        return job_id
    else:
        dbg.print_error("Can't find submitted job id!")
        return None
示例#19
0
def removeNetworkOld(h_cfg):
    no_network_str = "No such network"

    # Remove network
    cmd = "docker network rm %s" % h_cfg.nw_name
    p = ex.executeCmd(cmd, subprocess.PIPE, h_cfg.host_name, "remote_nw.sh")
    output, error = p.communicate()
    if p.returncode != 0:
        if common.isStrInText(no_network_str, error):
            dbg.print_warning("%s: '%s' network does not exist!" % \
                              (h_cfg.host_name, h_cfg.nw_name))
        else:
            dbg.print_error("%s: can not remove network '%s'!" % \
                            (h_cfg.nw_name, h_cfg.host_name))
            dbg.print_error(error)
            return 1
    else:
        dbg.print_info("Removed network '%s'" % h_cfg.nw_name)

    return 0
示例#20
0
 def LaunchInParallel(self):
     dbg.print_info("Launching tasks...")
     for task in self.task_l:
         task.Launch()
#!/usr/bin/env python

import dbglib as dbg

dbg.print_info("This is info")
dbg.print_success("This is success")
dbg.print_warning("This is warning")
dbg.print_error("This is an error")
示例#22
0
 def Poweroff(self):
     self.ExecuteBlock("poweroff")
     dbg.print_info("Waiting until %s is powered off" % self.name)
     if self.vm_proc != None:
         self.vm_proc.wait()
示例#23
0
文件: testlib.py 项目: minmit/tonic
 def CreateBuildDir(self):
     if not os.path.exists(self.build_dir):
         dbg.print_info("Creating build folder: %s" % self.build_dir)
         os.makedirs(self.build_dir)
示例#24
0
 def Reboot(self):
     for v in self.vm_l:
         dbg.print_info("Rebooting %s" % v.GetName())
         v.ExecuteBlock("reboot")
         v.WaitForBoot()
     dbg.print_info("All %d VMs were rebooted" % self.vm_num)
示例#25
0
 def Launch(self):
     dbg.print_info("Launching VM group")
     print len(self.vm_l)
     for v in self.vm_l:
         v.Launch()
         v.WaitForBoot()
示例#26
0
 def WaitForAll(self):
     dbg.print_info("Waiting for tasks to finish...")
     for task in self.task_l:
         task.WaitTillFinished()
示例#27
0
 def CopyBaseImg(self):
     base_img_path = os.path.join(cfg.DRIVE_DIR[self.host_machine],
                                  cfg.BAREVM_BASEIMG)
     (src_path, dst_path) = (base_img_path, self.drive_path)
     dbg.print_info("Copying %s to %s" % (src_path, dst_path))
     shutil.copy(src_path, dst_path)