Exemplo n.º 1
0
 def run_machine(self, machine):
     # Check if machine is in accepting state.
     assert machine.current_state == VM_IS_LAUNCHED
     # Bake a shell command to spawn the machine.
     shell_command = self.get_kvm_call(machine)
     logger.debug('Running VM with shell command:\n%s' % shell_command)
     report_filepath = self.get_report_file(machine)
     pid_filepath = self.get_pid_file(machine)
     if ProcessUtil.process_runs(pid_filepath):
         logging.warning('Apparently, VM process is already running. '
                         'Check %s ' % pid_filepath)
         machine.change_state(VM_HAS_FAILED)
         # TODO: kill the VM?
         return
     ProcessUtil.exec_process(shell_command, report_filepath, pid_filepath)
     # Update state.
     machine.change_state(VM_IS_RUNNING)
     # Put info into vnc target file.
     vnc_target_path = self.get_vnc_target_path(machine)
     with open(vnc_target_path, 'w+') as vnc_target:
         try:
             cmd = get_cmd_from_ps(needle=machine.disk_filename)
         except KeyError as error:
             logger.error('Failed to find VNC port of the vm: %s' % machine)
             logger.exception(error)
             return
         match = re.search(r'-vnc localhost:(\d+)', cmd, re.MULTILINE)
         local_vnc_port = 5900 + int(match.group(1))
         # e.g 'test: localhost:5901'
         vnc_info = '%s: localhost:%s' % (machine.name, local_vnc_port)
         logger.info('Writing into VNC target file: %s' % vnc_info)
         vnc_target.write(vnc_info + "\n")
Exemplo n.º 2
0
 def run_machine(self, machine):
     # Check if machine is in accepting state.
     assert machine.current_state == VM_IS_LAUNCHED
     # Bake a shell command to spawn the machine.
     shell_command = self.get_kvm_call(machine)
     logger.debug('Running VM with shell command:\n%s' % shell_command)
     report_filepath = self.get_report_file(machine)
     pid_filepath = self.get_pid_file(machine)
     if ProcessUtil.process_runs(pid_filepath):
         logging.warning('Apparently, VM process is already running. '
                         'Check %s ' % pid_filepath)
         machine.change_state(VM_HAS_FAILED)
         # TODO: kill the VM?
         return
     ProcessUtil.exec_process(shell_command, report_filepath, pid_filepath)
     # Update state.
     machine.change_state(VM_IS_RUNNING)
     # Put info into vnc target file.
     vnc_target_path = self.get_vnc_target_path(machine)
     with open(vnc_target_path, 'w+') as vnc_target:
         try:
             cmd = get_cmd_from_ps(needle=machine.disk_filename)
         except KeyError as error:
             logger.error('Failed to find VNC port of the vm: %s' % machine)
             logger.exception(error)
             return
         match = re.search(r'-vnc localhost:(\d+)', cmd, re.MULTILINE)
         local_vnc_port = 5900 + int(match.group(1))
         # e.g 'test: localhost:5901'
         vnc_info = '%s: localhost:%s' % (machine.name, local_vnc_port)
         logger.info('Writing into VNC target file: %s' % vnc_info)
         vnc_target.write(vnc_info + "\n")
Exemplo n.º 3
0
 def run_machine(self, machine):
     # Check if machine is in accepting state.
     assert machine.current_state == VM_IS_LAUNCHED
     # Bake a shell command to spawn the machine.
     shell_command = self.get_kvm_call(machine)
     logger.debug('Running VM with shell command:\n%s' % shell_command)
     #output = invoke(command)
     report_filepath = self.get_report_file(machine)
     pid_filepath = self.get_pid_file(machine)
     assert not ProcessUtil.process_runs(pid_filepath)
     ProcessUtil.exec_process(shell_command, report_filepath, pid_filepath)
     # Update state.
     machine.change_state(VM_IS_RUNNING)
Exemplo n.º 4
0
 def run_machine(self, machine):
     # Check if machine is in accepting state.
     assert machine.current_state == VM_IS_LAUNCHED
     # Bake a shell command to spawn the machine.
     shell_command = self.get_kvm_call(machine)
     logger.debug('Running VM with shell command:\n%s' % shell_command)
     #output = invoke(command)
     report_filepath = self.get_report_file(machine)
     pid_filepath = self.get_pid_file(machine)
     if ProcessUtil.process_runs(pid_filepath):
         logging.warning('Apparently, VM process is already running. '
                         'Check %s ' % pid_filepath)
         machine.change_state(VM_HAS_FAILED)
         # TODO: kill the VM?
         return
     ProcessUtil.exec_process(shell_command, report_filepath, pid_filepath)
     # Update state.
     machine.change_state(VM_IS_RUNNING)