Exemple #1
0
 def make(self, params = []):
   print color.INFO(nametag), "Building test service with 'make' (params=" + str(params) + ")"
   make = ["make"]
   make.extend(params)
   res = subprocess.check_output(make)
   print color.SUBPROC(res)
   return self
Exemple #2
0
  def boot(self, timeout = None, multiboot = True, kernel_args = "booted with vmrunner"):

    # Check for sudo access, needed for tap network devices and the KVM module
    if os.getuid() is not 0:
        print color.FAIL("Call the script with sudo access")
        sys.exit(1)

    # Start the timeout thread
    if (timeout):
      self._timer = threading.Timer(timeout, self._on_timeout)
      self._timer.start()

    # Boot via hypervisor
    try:
      self._hyper.boot(multiboot, kernel_args + "/" + self._hyper.name())
    except Exception as err:
      print color.WARNING("Exception raised while booting ")
      if (timeout): self._timer.cancel()
      raise err

    # Start analyzing output
    while self._hyper.poll() == None and not self._exit_status:
      line = self._hyper.readline()
      print color.SUBPROC("<VM> "+line.rstrip())
      # Look for event-triggers
      for pattern, func in self._on_output.iteritems():
        if re.search(pattern, line):
          try:
            res = func()
          except Exception as err:
            print color.WARNING("Exception raised in event callback: ")
            print_exception()
            res = False
            self.stop().wait()

          #NOTE: It can be 'None' without problem
          if res == False:
            self._exit_status = exit_codes["OUTSIDE_FAIL"]
            self.exit(self._exit_status, color.FAIL(nametag + " VM-external test failed"))

    # Now we either have an exit status from timer thread, or an exit status
    # from the subprocess, or the VM was powered off by the external test.
    # If the process didn't exit we need to stop it.
    if (self.poll() == None):
      self.stop()

    self.wait()

    if self._exit_status:
      print color.WARNING(nametag + "Found non-zero exit status but process didn't end. ")
      print color.FAIL(nametag + "Tests failed or program error")
      print color.INFO(nametag),"Done running VM. Exit status: ", self._exit_status
      sys.exit(self._exit_status)
    else:
      print color.SUCCESS(nametag + " VM exited with 0 exit status.")
      print color.INFO(nametag), "Subprocess finished. Exiting with ", self._hyper.poll()
      sys.exit(self._hyper.poll())

    raise Exception("Unexpected termination")
Exemple #3
0
def cmd(cmdlist):
    res = subprocess.check_output(cmdlist)
    for line in res.rstrip().split("\n"):
        print color.SUBPROC(line)