def build(self):
     """
     :return: com.xebialabs.overthere.ConnectionOptions
     """
     options = ConnectionOptions()
     for k, v in self.__dict__.items():
         self._set_conn_opt(options, k, v)
     return options
    def __init__(self, username, password, address, connectionType, script):
        self.options = ConnectionOptions()
        self.options.set(ConnectionOptions.USERNAME, username)
        self.options.set(ConnectionOptions.PASSWORD, password)
        self.options.set(ConnectionOptions.ADDRESS, address)
        self.options.set(ConnectionOptions.OPERATING_SYSTEM, OperatingSystemFamily.WINDOWS)

        self.script = script
        self.connectionType = connectionType

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler()
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler()
Beispiel #3
0
    def __init__(self, username, password, address, connectionType, timeout,
                 allowDelegate, cscriptExecutable, remotePath, script):
        self.options = ConnectionOptions()
        self.options.set(ConnectionOptions.USERNAME, username)
        self.options.set(ConnectionOptions.PASSWORD, password)
        self.options.set(ConnectionOptions.ADDRESS, address)
        self.options.set(ConnectionOptions.OPERATING_SYSTEM,
                         OperatingSystemFamily.WINDOWS)

        self.remotePath = remotePath
        self.script = script
        self.connectionType = connectionType
        # WINRM_NATIVE only
        self.allowDelegate = allowDelegate
        # WINRM_INTERNAL only
        self.timeout = timeout

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )
class SeleniumRunner():
    def __init__(self, script, connectionType=None, host=None, password=None):
        self.logger = getattr(__builtin__, 'logger', None)
        self.script = script

        self.connectionType = connectionType

        if host:
            self.options = ConnectionOptions()
            self.options.set(ConnectionOptions.USERNAME,
                             host.getProperty('username'))
            self.options.set(ConnectionOptions.PASSWORD, password)
            self.options.set(ConnectionOptions.ADDRESS,
                             host.getProperty('address'))
            self.options.set(ConnectionOptions.OPERATING_SYSTEM,
                             OperatingSystemFamily.UNIX)
            self.options.set(SshConnectionBuilder.CONNECTION_TYPE,
                             SshConnectionType.SCP)
        else:
            self.options = None

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )

    def execute(self):
        connection = None
        try:
            connection = self.getConnection()
            # upload the script and pass it to python
            exeFile = connection.getTempFile('script', '.py')
            OverthereUtils.write(String(self.script).getBytes(), exeFile)
            exeFile.setExecutable(True)
            scriptCommand = CmdLine.build('/usr/bin/python', exeFile.getPath())
            return connection.execute(self.stdout, self.stderr, scriptCommand)
        except AttributeError, e:
            self.logger.error(str(e))
        except NameError, e:
            self.logger.error(str(e))
Beispiel #5
0
class WinrmRemoteCScript():
    def __init__(self, username, password, address, connectionType, timeout,
                 allowDelegate, cscriptExecutable, remotePath, script):
        self.options = ConnectionOptions()
        self.options.set(ConnectionOptions.USERNAME, username)
        self.options.set(ConnectionOptions.PASSWORD, password)
        self.options.set(ConnectionOptions.ADDRESS, address)
        self.options.set(ConnectionOptions.OPERATING_SYSTEM,
                         OperatingSystemFamily.WINDOWS)

        self.remotePath = remotePath
        self.script = script
        self.connectionType = connectionType
        # WINRM_NATIVE only
        self.allowDelegate = allowDelegate
        # WINRM_INTERNAL only
        self.timeout = timeout

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )

    def customize(self, options):
        if self.connectionType == 'WINRM_NATIVE':
            options.set(CifsConnectionBuilder.CONNECTION_TYPE,
                        CifsConnectionType.WINRM_NATIVE)
            options.set(CifsConnectionBuilder.WINRS_ALLOW_DELEGATE,
                        allowDelegate)
        elif self.connectionType == 'WINRM_INTERNAL':
            options.set(CifsConnectionBuilder.CONNECTION_TYPE,
                        CifsConnectionType.WINRM_INTERNAL)
            options.set(CifsConnectionBuilder.WINRM_KERBEROS_USE_HTTP_SPN,
                        True)
            options.set(CifsConnectionBuilder.WINRM_TIMEMOUT, timeout)
        #print 'DEBUG: Options:', options

    def execute(self):
        self.customize(self.options)
        connection = None
        try:
            connection = Overthere.getConnection(
                CifsConnectionBuilder.CIFS_PROTOCOL, self.options)
            connection.setWorkingDirectory(connection.getFile(self.remotePath))
            # upload the script and pass it to cscript.exe
            targetFile = connection.getTempFile('uploaded-script', '.vbs')
            OverthereUtils.write(String(self.script).getBytes(), targetFile)
            targetFile.setExecutable(True)
            # run cscript in batch mode
            scriptCommand = CmdLine.build(cscriptExecutable, '//B', '//nologo',
                                          targetFile.getPath())
            return connection.execute(self.stdout, self.stderr, scriptCommand)
        except Exception, e:
            stacktrace = StringWriter()
            writer = PrintWriter(stacktrace, True)
            e.printStackTrace(writer)
            self.stderr.handleLine(stacktrace.toString())
            return 1
        finally:
class WinrmRemotePowerShellScript:
    def __init__(self, username, password, address, connectionType, timeout, allowDelegate, remotePath, script):
        self.options = ConnectionOptions()
        self.options.set(ConnectionOptions.USERNAME, username)
        self.options.set(ConnectionOptions.PASSWORD, password)
        self.options.set(ConnectionOptions.ADDRESS, address)
        self.options.set(ConnectionOptions.OPERATING_SYSTEM, OperatingSystemFamily.WINDOWS)

        self.remotePath = remotePath
        self.script = script
        self.connectionType = connectionType
        # WINRM_NATIVE only
        self.allowDelegate = allowDelegate
        # WINRM_INTERNAL only
        self.timeout = timeout

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler()
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler()

    def customize(self, options):
        if self.connectionType == "WINRM_NATIVE":
            options.set(CifsConnectionBuilder.CONNECTION_TYPE, CifsConnectionType.WINRM_NATIVE)
            options.set(CifsConnectionBuilder.WINRS_ALLOW_DELEGATE, allowDelegate)
        elif self.connectionType == "WINRM_INTERNAL":
            options.set(CifsConnectionBuilder.CONNECTION_TYPE, CifsConnectionType.WINRM_INTERNAL)
            options.set(CifsConnectionBuilder.WINRM_KERBEROS_USE_HTTP_SPN, True)
            options.set(CifsConnectionBuilder.WINRM_TIMEMOUT, timeout)
        # print 'DEBUG: Options:', options

    def execute(self):
        self.customize(self.options)
        connection = None
        try:
            connection = Overthere.getConnection(CifsConnectionBuilder.CIFS_PROTOCOL, self.options)
            connection.setWorkingDirectory(connection.getFile(self.remotePath))
            # upload the script and pass it to powershell
            targetFile = connection.getTempFile("uploaded-powershell-script", ".ps1")
            OverthereUtils.write(String(self.script).getBytes(), targetFile)
            targetFile.setExecutable(True)
            scriptCommand = CmdLine.build(
                "powershell",
                "-NoLogo",
                "-NonInteractive",
                "-InputFormat",
                "None",
                "-ExecutionPolicy",
                "Unrestricted",
                "-Command",
                targetFile.getPath(),
            )
            return connection.execute(self.stdout, self.stderr, scriptCommand)
        except Exception, e:
            stacktrace = StringWriter()
            writer = PrintWriter(stacktrace, True)
            e.printStackTrace(writer)
            self.stderr.handleLine(stacktrace.toString())
            return 1
        finally:
    def __init__(self, script, connectionType=None, host=None, password=None):
        self.logger = logger
        # self.logger.debug("In Selenium Runner init")
        self.script = script

        self.connectionType = connectionType

        if host:
            self.options = ConnectionOptions()
            self.options.set(ConnectionOptions.USERNAME, host.get("username"))
            self.options.set(ConnectionOptions.PASSWORD, password)
            self.options.set(ConnectionOptions.ADDRESS, host.get("address"))
            self.options.set(ConnectionOptions.OPERATING_SYSTEM,
                             OperatingSystemFamily.UNIX)
            self.options.set(SshConnectionBuilder.CONNECTION_TYPE,
                             SshConnectionType.SCP)
        else:
            self.options = None

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )
    def __init__(self, script, connectionType=None, host=None, password=None):
        self.logger = getattr(__builtin__, 'logger', None)
        self.script = script

        self.connectionType = connectionType

        if host:
            self.options = ConnectionOptions()
            self.options.set(ConnectionOptions.USERNAME,
                             host.getProperty('username'))
            self.options.set(ConnectionOptions.PASSWORD, password)
            self.options.set(ConnectionOptions.ADDRESS,
                             host.getProperty('address'))
            self.options.set(ConnectionOptions.OPERATING_SYSTEM,
                             OperatingSystemFamily.UNIX)
            self.options.set(SshConnectionBuilder.CONNECTION_TYPE,
                             SshConnectionType.SCP)
        else:
            self.options = None

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler(
        )
    def __init__(self, username, password, address, connectionType, timeout, allowDelegate, remotePath, script):
        self.options = ConnectionOptions()
        self.options.set(ConnectionOptions.USERNAME, username)
        self.options.set(ConnectionOptions.PASSWORD, password)
        self.options.set(ConnectionOptions.ADDRESS, address)
        self.options.set(ConnectionOptions.OPERATING_SYSTEM, OperatingSystemFamily.WINDOWS)

        self.remotePath = remotePath
        self.script = script
        self.connectionType = connectionType
        # WINRM_NATIVE only
        self.allowDelegate = allowDelegate
        # WINRM_INTERNAL only
        self.timeout = timeout

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler()
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler()
class WinrmRemoteHpTools():
    def __init__(self, username, password, address, connectionType, timeout, allowDelegate, remotePath, script):
        self.options = ConnectionOptions()
        self.options.set(ConnectionOptions.USERNAME, username)
        self.options.set(ConnectionOptions.PASSWORD, password)
        self.options.set(ConnectionOptions.ADDRESS, address)
        self.options.set(ConnectionOptions.OPERATING_SYSTEM, OperatingSystemFamily.WINDOWS)

        self.remotePath = remotePath
        self.script = script
        self.connectionType = connectionType
        # WINRM_NATIVE only
        self.allowDelegate = allowDelegate
        # WINRM_INTERNAL only
        self.timeout = timeout

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler()
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler()

    def customize(self, options):
        if self.connectionType == 'WINRM_NATIVE':
            options.set(CifsConnectionBuilder.CONNECTION_TYPE, CifsConnectionType.WINRM_NATIVE)
            options.set(CifsConnectionBuilder.WINRS_ALLOW_DELEGATE, allowDelegate)
        elif self.connectionType == 'WINRM_INTERNAL':
            options.set(CifsConnectionBuilder.CONNECTION_TYPE, CifsConnectionType.WINRM_INTERNAL)
            options.set(CifsConnectionBuilder.WINRM_KERBEROS_USE_HTTP_SPN, True)
            options.set(CifsConnectionBuilder.WINRM_TIMEMOUT, timeout);
        #print 'DEBUG: Options:', options

    def execute(self):
        self.customize(self.options)
        connection = None
        try:
            connection = Overthere.getConnection(CifsConnectionBuilder.CIFS_PROTOCOL, self.options)
            connection.setWorkingDirectory(connection.getFile(self.remotePath))
            # upload the script and pass it to cscript.exe
            targetFile = connection.getTempFile('parameters', '.txt')
            OverthereUtils.write(String(self.script).getBytes(), targetFile)
            targetFile.setExecutable(True)
            exeFile = connection.getTempFile('HpToolsLauncher', '.exe')
            sysloader = ClassLoader.getSystemClassLoader()
            OverthereUtils.write(sysloader.getResourceAsStream("HpTools/HpToolsLauncher.exe"), exeFile)
            exeFile.setExecutable(True)
            # run cscript in batch mode
            scriptCommand = CmdLine.build(exeFile.getPath(), '-paramfile', targetFile.getPath())
            return connection.execute(self.stdout, self.stderr, scriptCommand)
        except Exception, e:
            stacktrace = StringWriter()
            writer = PrintWriter(stacktrace, True)
            e.printStackTrace(writer)
            self.stderr.handleLine(stacktrace.toString())
            return 1
        finally:
class QtpCScript():
    def __init__(self, username, password, address, connectionType, timeout, allowDelegate, WlrunExe, TestPath, ResultName):
        self.options = ConnectionOptions()
        self.options.set(ConnectionOptions.USERNAME, username)
        self.options.set(ConnectionOptions.PASSWORD, password)
        self.options.set(ConnectionOptions.ADDRESS, address)
        self.options.set(ConnectionOptions.OPERATING_SYSTEM, OperatingSystemFamily.WINDOWS)

        self.TestPath = TestPath
        self.ResultName = ResultName
        self.connectionType = connectionType
        # WINRM_NATIVE only
        self.allowDelegate = allowDelegate
        # WINRM_INTERNAL only
        self.timeout = timeout
        
        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler()
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler()

    def customize(self, options):
        if self.connectionType == 'WINRM_NATIVE':
            options.set(CifsConnectionBuilder.CONNECTION_TYPE, CifsConnectionType.WINRM_NATIVE)
            options.set(CifsConnectionBuilder.WINRS_ALLOW_DELEGATE, allowDelegate)
        elif self.connectionType == 'WINRM_INTERNAL':
            options.set(CifsConnectionBuilder.CONNECTION_TYPE, CifsConnectionType.WINRM_INTERNAL)
            options.set(CifsConnectionBuilder.WINRM_KERBEROS_USE_HTTP_SPN, True)
            options.set(CifsConnectionBuilder.WINRM_TIMEMOUT, timeout);
        #print 'DEBUG: Options:', options

    def execute(self):
        self.customize(self.options)
        connection = None
        try:
            connection = Overthere.getConnection(CifsConnectionBuilder.CIFS_PROTOCOL, self.options)
            connection.setWorkingDirectory(connection.getFile(self.TestPath))
            # upload the ResultName and pass it to csResultName.exe
            ResultNameCommand = CmdLine.build(WlrunExe, "-Run", "-TestPath", TestPath, "-ResultName", ResultName)
            return connection.execute(self.stdout, self.stderr, ResultNameCommand)
        except Exception, e:
            stacktrace = StringWriter()
            writer = PrintWriter(stacktrace, True)
            e.printStackTrace(writer)
            self.stderr.handleLine(stacktrace.toString())
            return 1
        finally:
class SshRemoteScript():
    def __init__(self, username, password, address, connectionType, script):
        self.options = ConnectionOptions()
        self.options.set(ConnectionOptions.USERNAME, username)
        self.options.set(ConnectionOptions.PASSWORD, password)
        self.options.set(ConnectionOptions.ADDRESS, address)
        self.options.set(ConnectionOptions.OPERATING_SYSTEM, OperatingSystemFamily.WINDOWS)

        self.script = script
        self.connectionType = connectionType

        self.stdout = CapturingOverthereExecutionOutputHandler.capturingHandler()
        self.stderr = CapturingOverthereExecutionOutputHandler.capturingHandler()

    def customize(self, options):
        if self.connectionType == 'SFTP':
            options.set(SshConnectionBuilder.CONNECTION_TYPE, SshConnectionType.SFTP)
        elif self.connectionType == 'SCP':
            options.set(SshConnectionBuilder.CONNECTION_TYPE, SshConnectionType.SCP)
        elif self.connectionType == 'SSH':
            options.set(SshConnectionBuilder.CONNECTION_TYPE, SshConnectionType.SSH)
        #print 'DEBUG: Options:', options

    def execute(self):
        self.customize(self.options)
        connection = None
        try:
            connection = Overthere.getConnection(SshConnectionBuilder.CONNECTION_TYPE, self.options)
            # upload the script and pass it to python
            exeFile = connection.getTempFile('f5_disable', '.py')
            OverthereUtils.write(String(self.script).getBytes(), targetFile)
            exeFile.setExecutable(True)
            # run cscript in batch mode
            scriptCommand = CmdLine.build( '/usr/bin/python', exeFile.getPath() )
            return connection.execute(self.stdout, self.stderr, scriptCommand)
        except Exception, e:
            stacktrace = StringWriter()
            writer = PrintWriter(stacktrace, True)
            e.printStackTrace(writer)
            self.stderr.handleLine(stacktrace.toString())
            return 1
        finally: