def _config_file_build(self, applicationGroup): ''' Builds the expected configuration file or command output for later comparison. ''' self.configurationFileSettings = {} ## Clears the dictionary for use # Create the output folder to store the generated files generatedFilesPath = _utils._setup_output_folders(os.path.join(GLOBAL_VARIABLES['${OUTPUTDIR}'], "generatedFiles_%s" % self.environment, applicationGroup)) if not os.path.exists(generatedFilesPath): os.makedirs(generatedFilesPath) for configFile in self.environmentData['applicationGroups'][applicationGroup]['configurationFiles']: # Only run if there are variables to replace in the config file. for server in self.environmentData['applicationGroups'][applicationGroup]['servers']: self.configurationFileSettings = {} # Clears the dictionary for use for key, value in self.templateData[configFile].items(): # Adds the variables from the template configuration file to the main settings dict self.configurationFileSettings[key] = value self._config_file_build_helper(("environment:%s") % (configFile)) # Add the variables from the environment configuration file to the main settings dict self._config_file_build_helper(("applicationGroups:%s:%s") % (applicationGroup, configFile)) self._config_file_build_helper(("applicationGroups:%s:servers:%s:%s") % (applicationGroup, server, configFile)) self._config_file_build_check(applicationGroup, configFile, server) # Checks to ensure all variables defined in the template have some type of value set. self._config_file_build_write(generatedFilesPath, configFile, server) # Writes the generated file return generatedFilesPath
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_build(self, applicationGroup): ''' Builds the expected configuration file or command output for later comparison. ''' self.configurationFileSettings = {} ## Clears the dictionary for use # Create the output folder to store the generated files generatedFilesPath = _utils._setup_output_folders( os.path.join(GLOBAL_VARIABLES['${OUTPUTDIR}'], "generatedFiles_%s" % self.environment, applicationGroup)) if not os.path.exists(generatedFilesPath): os.makedirs(generatedFilesPath) for configFile in self.environmentData['applicationGroups'][ applicationGroup]['configurationFiles']: # Only run if there are variables to replace in the config file. for server in self.environmentData['applicationGroups'][ applicationGroup]['servers']: self.configurationFileSettings = { } # Clears the dictionary for use for key, value in self.templateData[configFile].items( ): # Adds the variables from the template configuration file to the main settings dict self.configurationFileSettings[key] = value self._config_file_build_helper( ("environment:%s") % (configFile) ) # Add the variables from the environment configuration file to the main settings dict self._config_file_build_helper(("applicationGroups:%s:%s") % (applicationGroup, configFile)) self._config_file_build_helper( ("applicationGroups:%s:servers:%s:%s") % (applicationGroup, server, configFile)) self._config_file_build_check( applicationGroup, configFile, server ) # Checks to ensure all variables defined in the template have some type of value set. self._config_file_build_write( generatedFilesPath, configFile, server) # Writes the generated file return generatedFilesPath
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