def _config_file_get_server_files(self, applicationGroup):
        ''' Function that gets the configuration file for diffing or runs the remote command and saves the output to a file.
        '''
        # Create the output folder to store the generated files
        serverFilesPath = _utils._setup_output_folders(
            os.path.join(GLOBAL_VARIABLES['${OUTPUTDIR}'],
                         "serverFiles_%s" % self.environment,
                         applicationGroup))
        if not os.path.exists(serverFilesPath):
            os.makedirs(serverFilesPath)

        for configFile in self.environmentData['applicationGroups'][
                applicationGroup]['configurationFiles']:
            for server in self.environmentData['applicationGroups'][
                    applicationGroup]['servers']:

                # Creates the connection to the remote server
                self.robotBuiltIn.run_keyword("Open Connection", server)
                returnValues = self.robotBuiltIn.run_keyword(
                    "RSA Get Key Locations")
                self.robotBuiltIn.run_keyword(
                    "Login With Public Key",
                    self.environmentData['environment']['auditUsername'],
                    returnValues['privateKey'].replace("/", "\\\\").replace(
                        "\\", "\\\\"), returnValues['privateKeyPass'].replace(
                            "/", "\\\\").replace("\\", "\\\\"))

                # Creates the file destination name
                destFileName = os.path.join(serverFilesPath,
                                            (("%s_%s") % (server, configFile)))

                if self.templateData[configFile]['configuration'][
                        'type'] == "file":
                    sourceFileName = self.templateData[configFile][
                        'configuration']['fileLocation']
                    returnResult = self.robotBuiltIn.run_keyword_and_ignore_error(
                        "Get File", sourceFileName,
                        destFileName.replace("\\", "\\\\"))
                    if returnResult[0] == "FAIL":
                        _utils._result_logger(self.resultFile, server,
                                              configFile, "Fail",
                                              sourceFileName)
                        raise Exception(
                            ("There were no files matching %s on server %s") %
                            (sourceFileName, server))

                if self.templateData[configFile]['configuration'][
                        'type'] == "command":
                    cmd = self.templateData[configFile]['configuration'][
                        'command']
                    actualResult = self.robotBuiltIn.run_keyword(
                        'Execute Command', cmd)
                    _utils._write_file(destFileName, actualResult)

                # Disconnect ssh session
                self.robotBuiltIn.run_keyword("Close Connection")

        return serverFilesPath
 def _config_file_compare(self, applicationGroup, generatedFilesPath, serverFilesPath):
     ''' Builds the diff options that have been defined & transverses the directory structure compare the files.
     '''
     for configFile in self.environmentData['applicationGroups'][applicationGroup]['configurationFiles']:
         # Only run if there are variables to replace in the config file.
         if self.templateData[configFile]["configuration"].get('ignore-matching-lines') is not None:
             diffOptions = "-i -w -B --ignore-matching-lines=" + " --ignore-matching-lines=".join(self.templateData[configFile]["configuration"]['ignore-matching-lines'])
         else:
             diffOptions = "-i -w -B"
             
     dc = filecmp.dircmp(generatedFilesPath, serverFilesPath)
     
     for fileCommon in dc.common:
         fileServer = fileCommon.split("_")[0]
         returnResult = self.robotBuiltIn.run_keyword_and_ignore_error("diff_files", os.path.join(generatedFilesPath, fileCommon).replace("\\", "\\\\"), os.path.join(serverFilesPath, fileCommon).replace("\\", "\\\\"), diffOptions)
         if returnResult[0] == "FAIL":
             _utils._result_logger(self.resultFile, fileServer, fileCommon, "Fail", str(returnResult[1]))
             self.robotBuiltIn.log((("Bad news: File %s on server %s with %s") % (fileCommon, fileServer, returnResult[1])), "WARN")
         else:
             _utils._result_logger(self.resultFile, fileServer, fileCommon, "Pass", str(returnResult[1]))
             self.robotBuiltIn.log((("Good news: File %s on server %s with %s") % (fileCommon, fileServer, returnResult[1])), "INFO")
    def _config_file_get_server_files(self, applicationGroup):
        ''' Function that gets the configuration file for diffing or runs the remote command and saves the output to a file.
        '''
        # Create the output folder to store the generated files
        serverFilesPath = _utils._setup_output_folders(os.path.join(GLOBAL_VARIABLES['${OUTPUTDIR}'], "serverFiles_%s" % self.environment, applicationGroup))
        if not os.path.exists(serverFilesPath):
            os.makedirs(serverFilesPath)
                    
        for configFile in self.environmentData['applicationGroups'][applicationGroup]['configurationFiles']:
            for server in self.environmentData['applicationGroups'][applicationGroup]['servers']:
                
                # Creates the connection to the remote server
                self.robotBuiltIn.run_keyword("Open Connection", server)
                returnValues = self.robotBuiltIn.run_keyword("RSA Get Key Locations")
                self.robotBuiltIn.run_keyword("Login With Public Key", 
                                              self.environmentData['environment']['auditUsername'],
                                              returnValues['privateKey'].replace("/", "\\\\").replace("\\", "\\\\"),
                                              returnValues['privateKeyPass'].replace("/", "\\\\").replace("\\", "\\\\"))

                # Creates the file destination name
                destFileName = os.path.join(serverFilesPath, (("%s_%s") % (server, configFile)))
                
                if self.templateData[configFile]['configuration']['type'] == "file":
                    sourceFileName =  self.templateData[configFile]['configuration']['fileLocation']                
                    returnResult = self.robotBuiltIn.run_keyword_and_ignore_error("Get File", sourceFileName, destFileName.replace("\\", "\\\\"))
                    if returnResult[0] == "FAIL":
                        _utils._result_logger(self.resultFile, server, configFile, "Fail", sourceFileName)
                        raise Exception (("There were no files matching %s on server %s") % (sourceFileName, server))                
                
                if self.templateData[configFile]['configuration']['type'] == "command":
                    cmd = self.templateData[configFile]['configuration']['command']
                    actualResult = self.robotBuiltIn.run_keyword('Execute Command', cmd)
                    _utils._write_file(destFileName, actualResult)
                
                # Disconnect ssh session
                self.robotBuiltIn.run_keyword("Close Connection")

        return serverFilesPath
    def _config_file_compare(self, applicationGroup, generatedFilesPath,
                             serverFilesPath):
        ''' Builds the diff options that have been defined & transverses the directory structure compare the files.
        '''
        for configFile in self.environmentData['applicationGroups'][
                applicationGroup]['configurationFiles']:
            # Only run if there are variables to replace in the config file.
            if self.templateData[configFile]["configuration"].get(
                    'ignore-matching-lines') is not None:
                diffOptions = "-i -w -B --ignore-matching-lines=" + " --ignore-matching-lines=".join(
                    self.templateData[configFile]["configuration"]
                    ['ignore-matching-lines'])
            else:
                diffOptions = "-i -w -B"

        dc = filecmp.dircmp(generatedFilesPath, serverFilesPath)

        for fileCommon in dc.common:
            fileServer = fileCommon.split("_")[0]
            returnResult = self.robotBuiltIn.run_keyword_and_ignore_error(
                "diff_files",
                os.path.join(generatedFilesPath,
                             fileCommon).replace("\\", "\\\\"),
                os.path.join(serverFilesPath,
                             fileCommon).replace("\\", "\\\\"), diffOptions)
            if returnResult[0] == "FAIL":
                _utils._result_logger(self.resultFile, fileServer, fileCommon,
                                      "Fail", str(returnResult[1]))
                self.robotBuiltIn.log(
                    (("Bad news: File %s on server %s with %s") %
                     (fileCommon, fileServer, returnResult[1])), "WARN")
            else:
                _utils._result_logger(self.resultFile, fileServer, fileCommon,
                                      "Pass", str(returnResult[1]))
                self.robotBuiltIn.log(
                    (("Good news: File %s on server %s with %s") %
                     (fileCommon, fileServer, returnResult[1])), "INFO")