def print_cmd_line(cmd_line, ctx):
    print_args = []
    for item in cmd_line:
        if StringUtils.contains(item, "--password"):
            print_args.append("--password=******")
        else:
            print_args.append(item)
    ctx.logOutput("Executing command:")
    ctx.logOutput(StringUtils.concat(print_args, " "))
Exemple #2
0
def local_execute(session, cmd):
    """
    Executes the command on the remote system and returns the result
    :param session: checks the return code is 0. On failure the output is printed to stdout and a system exit is performed
    :param cmd: Command line as an Array of Strings or String.  A String is split by space.
    :return: CommandResponse
    """
    if isinstance(cmd, basestring):
        cmd = cmd.split()

    cmdline = CmdLine.build(cmd)
    capture_so_handler = CapturingOverthereExecutionOutputHandler.capturingHandler(
    )
    capture_se_handler = CapturingOverthereExecutionOutputHandler.capturingHandler(
    )

    console_so_handler = PyLoggerExecutionOutputHandler.sysoutHandler(
        session.logger)
    console_se_handler = PyLoggerExecutionOutputHandler.syserrHandler(
        session.logger)
    so_handler = MultipleOverthereExecutionOutputHandler.multiHandler(
        [capture_so_handler, console_so_handler])
    se_handler = MultipleOverthereExecutionOutputHandler.multiHandler(
        [capture_se_handler, console_se_handler])

    rc = session.get_conn().execute(so_handler, se_handler, cmdline)
    # wait for output to drain
    time.sleep(1)

    response = CommandResponse(rc=rc,
                               stdout=capture_so_handler.outputLines,
                               stderr=capture_se_handler.outputLines)

    if response.rc != 0:
        session.logger.error(StringUtils.concat(response.stdout))
        session.logger.error(StringUtils.concat(response.stderr))
        session.logger.error("Exit code {0}".format(response.rc))
        sys.exit(response.rc)
    return response
    def execute(self, xmlaccessscript, config_uri=None):
        session = OverthereHostSession(self.host, stream_command_output=False, execution_context=self.exec_context)
        with session:
            request_file = session.upload_text_content_to_work_dir(xmlaccessscript, "request.xml")
            response_file = session.work_dir_file("response.xml")
            fs = session.os.fileSeparator
            executable = "%s%sbin%sxmlaccess%s" % (self.wp_home, fs, fs, session.os.scriptExtension)
            wp_url = self.resolve_config_url(config_uri)
            cmd_line = [executable, "-user", self.wp_user, "-password", self.wp_password, "-url", wp_url]
            cmd_line.extend(["-in", request_file.path, "-out", response_file.path])
            resp = session.execute(cmd_line, check_success=False)
            response_xml = ""
            if response_file.exists():
                response_xml = session.read_file(response_file.path)

            if resp.rc != 0:
                self.exec_context.logError("XML Access failed!!!")
                self.log_with_header("XML Access response:", response_xml, True)
                self.log_with_header("Standard out", StringUtils.concat(resp.stdout))
                self.log_with_header("Standard error", StringUtils.concat(resp.stderr))
                cmd_line[4] = '******'  # Password is 5th element in array
                self.log_with_header("Executed command line", StringUtils.concat(cmd_line, " "))
                sys.exit(1)
            return response_xml
    def execute(self, xmlaccessscript, config_uri=None):
        session = OverthereHostSession(self.host,
                                       stream_command_output=False,
                                       execution_context=self.exec_context)
        with session:
            request_file = session.upload_text_content_to_work_dir(
                xmlaccessscript, "request.xml")
            response_file = session.work_dir_file("response.xml")
            fs = session.os.fileSeparator
            executable = "%s%sbin%sxmlaccess%s" % (self.wp_home, fs, fs,
                                                   session.os.scriptExtension)
            wp_url = self.resolve_config_url(config_uri)
            cmd_line = [
                executable, "-user", self.wp_user, "-password",
                self.wp_password, "-url", wp_url
            ]
            cmd_line.extend(
                ["-in", request_file.path, "-out", response_file.path])
            resp = session.execute(cmd_line, check_success=False)
            response_xml = ""
            if response_file.exists():
                response_xml = session.read_file(response_file.path)

            if resp.rc != 0:
                self.exec_context.logError("XML Access failed!!!")
                self.log_with_header("XML Access response:", response_xml,
                                     True)
                self.log_with_header("Standard out",
                                     StringUtils.concat(resp.stdout))
                self.log_with_header("Standard error",
                                     StringUtils.concat(resp.stderr))
                cmd_line[4] = '******'  # Password is 5th element in array
                self.log_with_header("Executed command line",
                                     StringUtils.concat(cmd_line, " "))
                sys.exit(1)
            return response_xml
def TEST( deployed ):
   logger.error("======== TEST Diffs ===========")
   ci = repositoryService.read( deployed )
   for d in ci.deployeds:
       dtype = str(d.type)

       logger.error("dtype = " + dtype)
       if dtype == "file.DeployedFile" or dtype == "file.Folder":
           
           logger.error("Found a file object we can diff")
           if dtype == "file.DeployedFile":
               logger.error("Deal with files")
               targetPath=str(d.targetPath)
               logger.error("TargetPath = " + targetPath)
               fileName=str(d.name)
               logger.error("FileName = " + fileName)
               logger.error( "%s/%s " % (targetPath, fileName) )
               remote_path = "%s/%s" % (targetPath, fileName)
           else:
               logger.error("Deal with directories")
               targetPath=repositoryService.read(d).targetPath
               print "%s/ " % (targetPath)
               remote_path = targetPath
           # End if
           logger.error("Connect to overthere host @ " + str(d.container) )
           with OverthereHostSession(d.container) as session:
               diff_lines = remote_diff(session, fileName, remote_path)
               logger.error("+--------------------------------------------")
               logger.error("|         %s on %s" % (d.name, d.container))
               logger.error("+--------------------------------------------")
           if len(diff_lines) > 0:
               print "%s" % (diff_lines)
               logger.error(StringUtils.concat(diff_lines))
               print StringUtils.concat(diff_lines)
           # End if
           logger.error("+--------------------------------------------")
def TEST(deployed):
    logger.error("======== TEST Diffs ===========")
    ci = repositoryService.read(deployed)
    for d in ci.deployeds:
        dtype = str(d.type)

        logger.error("dtype = " + dtype)
        if dtype == "file.DeployedFile" or dtype == "file.Folder":

            logger.error("Found a file object we can diff")
            if dtype == "file.DeployedFile":
                logger.error("Deal with files")
                targetPath = str(d.targetPath)
                logger.error("TargetPath = " + targetPath)
                fileName = str(d.name)
                logger.error("FileName = " + fileName)
                logger.error("%s/%s " % (targetPath, fileName))
                remote_path = "%s/%s" % (targetPath, fileName)
            else:
                logger.error("Deal with directories")
                targetPath = repositoryService.read(d).targetPath
                print "%s/ " % (targetPath)
                remote_path = targetPath
            # End if
            logger.error("Connect to overthere host @ " + str(d.container))
            with OverthereHostSession(d.container) as session:
                diff_lines = remote_diff(session, fileName, remote_path)
                logger.error("+--------------------------------------------")
                logger.error("|         %s on %s" % (d.name, d.container))
                logger.error("+--------------------------------------------")
            if len(diff_lines) > 0:
                print "%s" % (diff_lines)
                logger.error(StringUtils.concat(diff_lines))
                print StringUtils.concat(diff_lines)
            # End if
            logger.error("+--------------------------------------------")
def none_or_empty(s):
    return StringUtils.empty(s)
for d in thisCi.deployeds:
    dtype = str(d.deployable.type)
    if dtype == "file.File" or dtype == "file.Folder":
        if dtype == "file.File":
            #print "%s/%s " % (d.targetPath, d.name)
            remote_path = "%s/%s" % (d.targetPath, d.name)
        else:
            #print "%s/ " % (d.targetPath)
            remote_path = d.targetPath
        # End if
        targets = parameters["targets"]
        if len(targets) > 0 :
            hostA = targets.pop()
            hostB = targets.pop()
            diff_lines = server_diff(hostA, hostB, d.name, remote_path)
            context.logOutput("+-------------------------------------------------")
            context.logOutput("| compare ")
            context.logOutput("| %s @ %s " % (d.name, hostA))
            context.logOutput("| to ")
            context.logOutput("| %s @ %s " % (d.name, hostB))
            context.logOutput("+-------------------------------------------------")
            if len(diff_lines) > 0:
                #context.logOutput("%s" % (diff_lines))
                context.logOutput(StringUtils.concat(diff_lines))
            # End if
            context.logOutput("+-------------------------------------------------")
        # End if
    # End if  
# End for
Exemple #9
0
        if dtype == "file.File":
            #print "%s/%s " % (d.targetPath, d.name)
            remote_path = "%s/%s" % (d.targetPath, d.name)
        else:
            #print "%s/ " % (d.targetPath)
            remote_path = d.targetPath
        # End if
        targets = parameters["targets"]
        if len(targets) > 0:
            hostA = targets.pop()
            hostB = targets.pop()
            diff_lines = server_diff(hostA, hostB, d.name, remote_path)
            context.logOutput(
                "+-------------------------------------------------")
            context.logOutput("| compare ")
            context.logOutput("| %s @ %s " % (d.name, hostA))
            context.logOutput("| to ")
            context.logOutput("| %s @ %s " % (d.name, hostB))
            context.logOutput(
                "+-------------------------------------------------")
            if len(diff_lines) > 0:
                #context.logOutput("%s" % (diff_lines))
                context.logOutput(StringUtils.concat(diff_lines))
            # End if
            context.logOutput(
                "+-------------------------------------------------")
        # End if
    # End if
    break
# End for