def __init__(self, host, bundle_dir, sb_cfg):
        self.host = host
        self.bundle_dir = bundle_dir
        self.sb_cfg = sb_cfg

        self.machinecfg = VirtualMachineConfig(sb_cfg, 'Machine')
        self.error_fname = os.path.join(bundle_dir, 'vmchecker-stderr.vmr')
        self.shell = self.machinecfg.guest_shell_path()

        self.username = self.machinecfg.guest_user()
        self.password = self.machinecfg.guest_pass()
示例#2
0
    def __init__(self, host, vm):
        self.host = host
        self.vm = vm
        self.bundle_dir = vm.bundle_dir
        self.sb_cfg = vm.sb_cfg
        self.logger = logging.getLogger('vm_executor.' +
                                        self.__class__.__name__)

        self.machine = self.sb_cfg.get('Assignment', 'Machine')
        self.machinecfg = VirtualMachineConfig(self.sb_cfg, 'Machine')
    def __init__(self, host, bundle_dir, sb_cfg):
        self.host = host
        self.bundle_dir = bundle_dir
        self.sb_cfg = sb_cfg

        self.machinecfg = VirtualMachineConfig(sb_cfg, 'Machine')
        self.error_fname = os.path.join(bundle_dir, 'vmchecker-stderr.vmr')
        self.shell = self.machinecfg.guest_shell_path()

        self.username = self.machinecfg.guest_user()
        self.password = self.machinecfg.guest_pass()
class VM(object):
    host = None
    path = None
    username = None
    password = None
    IP = None

    def __init__(self, host, bundle_dir, sb_cfg):
        self.host = host
        self.bundle_dir = bundle_dir
        self.sb_cfg = sb_cfg

        self.machinecfg = VirtualMachineConfig(sb_cfg, 'Machine')
        self.error_fname = os.path.join(bundle_dir, 'vmchecker-stderr.vmr')
        self.shell = self.machinecfg.guest_shell_path()

        self.username = self.machinecfg.guest_user()
        self.password = self.machinecfg.guest_pass()

    def executeCommand(self, cmd):
        # host.executeCommand(...)
        pass

    def executeNativeCommand(self, cmd):
        # there is no default need for native commands
        return self.executeCommand(cmd)

    def hasStarted(self):
        return False

    def hasStopped(self):
        return False

    def start(self):
        pass

    def stop(self):
        pass

    def revert(self, number=None):
        pass

    def copyTo(self, targetDir, sourceDir, files):
        pass

    def copyFrom(self, targetDir, sourceDir, files):
        pass

    def run(self, shell, executable_file, timeout):
        pass

    def runTest(self, bundle_dir, machinecfg, test):
        """Return False if an exception is thrown or the tests timeout."""
        try:
            files_to_copy = test['input'] + test['script']
            guest_dest_dir = machinecfg.guest_base_path()
            self.copyTo(bundle_dir, guest_dest_dir, files_to_copy)
            for script in test['script']:
                shell = machinecfg.guest_shell_path()
                dest_in_guest_shell = machinecfg.guest_home_in_shell()
                script_in_guest_shell = dest_in_guest_shell + script
                timedout = self.run(shell, script_in_guest_shell,
                                    test['timeout'])
                self.copyFrom(guest_dest_dir, bundle_dir, test['output'])
                if timedout:
                    return False

            return True
        except Exception as e:
            _logger.exception('Exception thrown in runTest(): ' +
                              type(e).__name__ + "\n" + ", ".join(e.args) +
                              "\n" + e.__str__())
            return False

    def try_power_on_vm_and_login(self, revertSnapshot=None):
        if revertSnapshot == True or \
           (revertSnapshot == None and self.sb_cfg.get('Assignment', 'RevertToSnapshot')):
            self.revert()

        self.start()
        return True
class VM():
    host 	= None
    path 	= None
    username	= None
    password	= None
    IP	= None
    def __init__(self, host, bundle_dir, sb_cfg):
        self.host = host
        self.bundle_dir = bundle_dir
        self.sb_cfg = sb_cfg

        self.machinecfg = VirtualMachineConfig(sb_cfg, 'Machine')
        self.error_fname = os.path.join(bundle_dir, 'vmchecker-stderr.vmr')
        self.shell = self.machinecfg.guest_shell_path()

        self.username = self.machinecfg.guest_user()
        self.password = self.machinecfg.guest_pass()

    def executeCommand(self, cmd):
        # host.executeCommand(...)
        pass

    def executeNativeCommand(self, cmd):
        # there is no default need for native commands
        return self.executeCommand(cmd)

    def hasStarted(self):
        return False

    def hasStopped(self):
        return False

    def start(self):
        pass
        
    def stop(self):
        pass
        
    def revert(self, number = None):
        pass
        
    def copyTo(self, targetDir, sourceDir, files):
        pass

    def copyFrom(self, targetDir, sourceDir, files):
        pass
        
    def run(self, shell, executable_file, timeout):
        pass
        
    def runTest(self, bundle_dir, machinecfg, test):
        """Return False if an exception is thrown or the tests timeout."""
        try:
            files_to_copy = test['input'] + test['script']
            guest_dest_dir = machinecfg.guest_base_path()
            self.copyTo(bundle_dir,guest_dest_dir,files_to_copy)
            for script in test['script']:
                shell = machinecfg.guest_shell_path()
                dest_in_guest_shell = machinecfg.guest_home_in_shell()
                script_in_guest_shell = dest_in_guest_shell  + script
                timedout = self.run(shell,script_in_guest_shell,test['timeout'])
                self.copyFrom(guest_dest_dir,bundle_dir,test['output'])
                if timedout:
                    return False

            return True
        except Exception as e:
            _logger.exception('Exception thrown in runTest(): ' + type(e).__name__ + "\n" + ", ".join(e.args) + "\n" + e.__str__())
            return False
        
    def try_power_on_vm_and_login(self, revertSnapshot=None):
        if revertSnapshot == True or \
           (revertSnapshot == None and self.sb_cfg.get('Assignment', 'RevertToSnapshot')):
            self.revert()

        self.start()
        return True