def CheckInstallErrorCode(Framework): if AgentUtils.isUpgradeProcess(Framework): if AgentUtils.isUpgradeByUDAgent(Framework): client = Framework.getConnectedClient() agentVersion = client.getVersion() logger.debug("The current agent version is:", agentVersion) connectedUDACredentialId = client.getCredentialId() logger.debug('Credential id on remote:', connectedUDACredentialId) installCredentialId = Framework.getParameter(AgentUtils.UDAGENT_CONNECT_CREDENTIAL_ID_PARAM) logger.debug('Credential id for upgrade:', installCredentialId) if not AgentUtils.versionsEqual(Framework, agentVersion) or (installCredentialId and installCredentialId != connectedUDACredentialId): logger.debug("Notice: The connected client is still old UDA.") errorCode = AgentUtils.getUpgradeErrorCode(Framework) else: errorCode = AgentUtils.getInstallErrorCode(Framework) if errorCode: if errorCode.isSuccess(): Framework.setProperty(CheckAgentInstalled.FIRST_TRY_INSTALL_AGENT, CheckAgentInstalled.FIRST_TRY_INSTALL_AGENT) Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS) elif errorCode.isInProgress(): logger.debug('UDA install command is in progress, will check after parking') Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) else: logger.debug('Failed to install UDA according to install error code.') Framework.reportError("Install/Upgrade UDA failed. Reason is:%s" % errorCode.getMessage()) Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE) else: logger.debug('Can not get error code now, will check after parking') Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
def connectToRemoteNode(Framework): Framework.setProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR, Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_CONFIGURED_BASEDIR)) Framework.getConnectedClient().setOptionsDirectory(Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR)) if AgentUtils.isUpgradeProcess(Framework): # we here means that destination data shows version different from OOTB installer version. # need to recheck with real agent logger.debug('Checking if real version of agent differs from OOTB installer version') agentVersion = None connectedUDACredentialId = None installCredentialId = Framework.getParameter(AgentUtils.UDAGENT_CONNECT_CREDENTIAL_ID_PARAM) logger.debug('Credential id will be used:', installCredentialId) client = Framework.getConnectedClient() if AgentUtils.isUpgradeByUDAgent(Framework): agentVersion = client.getVersion() connectedUDACredentialId = client.getCredentialId() logger.debug('Credential id on remote:', connectedUDACredentialId) AgentUtils.updateCallHomeParams(Framework) AgentUtils.updateSWUtilization(Framework) InventoryUtils.setConnectedClientIdentifier(Framework, client) #Same version and same credential, skip upgrade if AgentUtils.versionsEqual(Framework, agentVersion) and (not installCredentialId or installCredentialId == connectedUDACredentialId): logger.debug('Installed agent version equals to local installer version, skipping upgrade') Framework.setProperty(InventoryUtils.STEP_SKIP_ALL_STEPS_PROPERTY, 'Upgrade not required, real installed agent version equals to the local installer version') client.close() elif Framework.getParameter("UpgradeAgent") == 'false': logger.debug("Upgrade is not required because the job parameter 'UpgradeAgent' is false") Framework.setProperty(InventoryUtils.STEP_SKIP_ALL_STEPS_PROPERTY, "Upgrade is not required because the job parameter 'UpgradeAgent' is false") client.close() else: logger.debug('Installed agent version does not equal to local installer version, Going to execute agent upgrade') Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def connectToRemoteNode(Framework): Framework.setProperty( InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR, Framework.getProperty( InventoryUtils.STATE_PROPERTY_RESOLVED_CONFIGURED_BASEDIR)) Framework.getConnectedClient().setOptionsDirectory( Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR)) if AgentUtils.isUpgradeProcess(Framework): # we here means that destination data shows version different from OOTB installer version. # need to recheck with real agent logger.debug( 'Checking if real version of agent differs from OOTB installer version' ) agentVersion = None connectedUDACredentialId = None installCredentialId = Framework.getParameter( AgentUtils.UDAGENT_CONNECT_CREDENTIAL_ID_PARAM) logger.debug('Credential id will be used:', installCredentialId) client = Framework.getConnectedClient() if AgentUtils.isUpgradeByUDAgent(Framework): agentVersion = client.getVersion() connectedUDACredentialId = client.getCredentialId() logger.debug('Credential id on remote:', connectedUDACredentialId) AgentUtils.updateCallHomeParams(Framework) AgentUtils.updateSWUtilization(Framework) InventoryUtils.setConnectedClientIdentifier(Framework, client) #Same version and same credential, skip upgrade if AgentUtils.versionsEqual(Framework, agentVersion) and ( not installCredentialId or installCredentialId == connectedUDACredentialId): logger.debug( 'Installed agent version equals to local installer version, skipping upgrade' ) Framework.setProperty( InventoryUtils.STEP_SKIP_ALL_STEPS_PROPERTY, 'Upgrade not required, real installed agent version equals to the local installer version' ) client.close() elif Framework.getParameter("UpgradeAgent") == 'false': logger.debug( "Upgrade is not required because the job parameter 'UpgradeAgent' is false" ) Framework.setProperty( InventoryUtils.STEP_SKIP_ALL_STEPS_PROPERTY, "Upgrade is not required because the job parameter 'UpgradeAgent' is false" ) client.close() else: logger.debug( 'Installed agent version does not equal to local installer version, Going to execute agent upgrade' ) Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def ensureUninstall(Framework): # this is placeholder step - to ensure that uninstall process finished # As uninstall can tale time and just failure in connect does not ensure that # uninstall process already finished we give 2 minutes for uninstall during upgrade process process if AgentUtils.isUpgradeByUDAgent(Framework): Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS) return unintallEnsured = Framework.getProperty(ENSURE_UNINSTALL_PROPERTY) if not unintallEnsured: logger.debug('Going to give chance for agent uninstaller') Framework.setProperty(ENSURE_UNINSTALL_PROPERTY, ENSURE_UNINSTALL_PROPERTY) Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) else: Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def CheckInstallErrorCode(Framework): if AgentUtils.isUpgradeProcess(Framework): if AgentUtils.isUpgradeByUDAgent(Framework): client = Framework.getConnectedClient() agentVersion = client.getVersion() logger.debug("The current agent version is:", agentVersion) connectedUDACredentialId = client.getCredentialId() logger.debug('Credential id on remote:', connectedUDACredentialId) installCredentialId = Framework.getParameter( AgentUtils.UDAGENT_CONNECT_CREDENTIAL_ID_PARAM) logger.debug('Credential id for upgrade:', installCredentialId) if not AgentUtils.versionsEqual(Framework, agentVersion) or ( installCredentialId and installCredentialId != connectedUDACredentialId): logger.debug("Notice: The connected client is still old UDA.") errorCode = AgentUtils.getUpgradeErrorCode(Framework) else: errorCode = AgentUtils.getInstallErrorCode(Framework) if errorCode: if errorCode.isSuccess(): Framework.setProperty(CheckAgentInstalled.FIRST_TRY_INSTALL_AGENT, CheckAgentInstalled.FIRST_TRY_INSTALL_AGENT) Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS) elif errorCode.isInProgress(): logger.debug( 'UDA install command is in progress, will check after parking') Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) else: logger.debug( 'Failed to install UDA according to install error code.') Framework.reportError("Install/Upgrade UDA failed. Reason is:%s" % errorCode.getMessage()) Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE) else: logger.debug('Can not get error code now, will check after parking') Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
def downloadLogsIfNeeded(Framework): platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM) logger.debug('Checking if to print install/uninstall logs') downloadMigrateLog = Framework.getProperty(AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE) downloadInstallLog = Framework.getProperty(AgentUtils.DOWNLOAD_INSTALL_LOG_FILE) downloadUnInstallLog = Framework.getProperty(AgentUtils.DOWNLOAD_UNINSTALL_LOG_FILE) if not downloadMigrateLog and not downloadInstallLog and not downloadUnInstallLog: logger.debug('Migrate/Install/UnInstall log should not be downloaded') return try: logger.debug('Releasing old connection') InventoryUtils.releaseConnection(Framework) logger.debug('Preparing framework for new connection') AgentUtils.prepareFrameworkForShellOrAgentConnect(Framework) except: errorMessage = str(sys.exc_info()[1]) logger.debugException('Failed to initialize connection for downloading agent log files' + errorMessage) return if downloadMigrateLog: # If need to download migrate log, we need to connect to DDMi agent as well Framework.setProperty(InventoryUtils.STATE_PROPERTY_IS_MIGRATE, str('true')) if not InventoryUtils.ensureConnection(Framework): logger.debug('Failed to connect to the remote machine, no logs available') else: ip_address = Framework.getTriggerCIData('ip_address') localInstallFile = None localUnInstallFile = None try: try: agentsConfigFile = Framework.getConfigFile(CollectorsConstants.AGENTSSBYPLATFORM_FILE_NAME) BASEDIR = Framework.getProperty(InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR) architecture = Framework.getProperty(InventoryUtils.STATE_PROPERTY_ARCHITECTURE) agentPlatformConfig = agentsConfigFile.getPlatformConfiguration(platform, architecture) ip_address_str = str(ip_address) if (ip_address_str.find(':') <> -1): ip_address_str = ip_address_str.replace(':','-') if downloadMigrateLog: logger.debug('Download the migrate log') installLogFile = agentPlatformConfig.getUpgradeLogFile() localInstallFile = File(AGENTS_LOGS_TEMP_DIR_FILE, ip_address_str + '-' + installLogFile) getLogFileContent(Framework, localInstallFile, str(BASEDIR) + installLogFile) if downloadInstallLog: logger.debug('Download the install/update log') if AgentUtils.isUpgradeByUDAgent(Framework): installLogFile = agentPlatformConfig.getUpgradeLogFile() else: installLogFile = agentPlatformConfig.getInstallLogFile() localInstallFile = File(AGENTS_LOGS_TEMP_DIR_FILE, ip_address_str + '-' + installLogFile) getLogFileContent(Framework, localInstallFile, str(BASEDIR) + installLogFile) if downloadUnInstallLog: logger.debug('Download the uninstall log') unInstallLogFile = agentPlatformConfig.getUnInstallLogFile() localUnInstallFile = File(AGENTS_LOGS_TEMP_DIR_FILE, ip_address_str + '-' + unInstallLogFile) getLogFileContent(Framework, localUnInstallFile, str(BASEDIR) + unInstallLogFile) except: errorMessage = str(sys.exc_info()[1]) logger.debugException(errorMessage) Framework.reportError(inventoryerrorcodes.INVENTORY_DISCOVERY_FAILED_EXECUTE_STEP, ['FinalizeAndReleaseResources', errorMessage]) finally: try: if localInstallFile and not localInstallFile.delete(): logger.debug('File was not deleted:' + localInstallFile.getCanonicalPath()) except: logger.debugException('Failed to delete ' + localInstallFile.getCanonicalPath()) try: logger.debug('Going to delete file ' + localInstallFile.getCanonicalPath()) if localUnInstallFile and not localUnInstallFile.delete(): logger.debug('File was not deleted:' + localUnInstallFile.getCanonicalPath()) except: logger.debugException('Failed to delete ' + localUnInstallFile.getCanonicalPath())
def downloadLogsIfNeeded(Framework): platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM) logger.debug('Checking if to print install/uninstall logs') downloadMigrateLog = Framework.getProperty( AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE) downloadInstallLog = Framework.getProperty( AgentUtils.DOWNLOAD_INSTALL_LOG_FILE) downloadUnInstallLog = Framework.getProperty( AgentUtils.DOWNLOAD_UNINSTALL_LOG_FILE) if not downloadMigrateLog and not downloadInstallLog and not downloadUnInstallLog: logger.debug('Migrate/Install/UnInstall log should not be downloaded') return try: logger.debug('Releasing old connection') InventoryUtils.releaseConnection(Framework) logger.debug('Preparing framework for new connection') AgentUtils.prepareFrameworkForShellOrAgentConnect(Framework) except: errorMessage = str(sys.exc_info()[1]) logger.debugException( 'Failed to initialize connection for downloading agent log files' + errorMessage) return if downloadMigrateLog: # If need to download migrate log, we need to connect to DDMi agent as well Framework.setProperty(InventoryUtils.STATE_PROPERTY_IS_MIGRATE, str('true')) if not InventoryUtils.ensureConnection(Framework): logger.debug( 'Failed to connect to the remote machine, no logs available') else: ip_address = Framework.getTriggerCIData('ip_address') localInstallFile = None localUnInstallFile = None try: try: agentsConfigFile = Framework.getConfigFile( CollectorsConstants.AGENTSSBYPLATFORM_FILE_NAME) BASEDIR = Framework.getProperty( InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR) architecture = Framework.getProperty( InventoryUtils.STATE_PROPERTY_ARCHITECTURE) agentPlatformConfig = agentsConfigFile.getPlatformConfiguration( platform, architecture) ip_address_str = str(ip_address) if (ip_address_str.find(':') <> -1): ip_address_str = ip_address_str.replace(':', '-') if downloadMigrateLog: logger.debug('Download the migrate log') installLogFile = agentPlatformConfig.getUpgradeLogFile() localInstallFile = File( AGENTS_LOGS_TEMP_DIR_FILE, ip_address_str + '-' + installLogFile) getLogFileContent(Framework, localInstallFile, str(BASEDIR) + installLogFile) if downloadInstallLog: logger.debug('Download the install/update log') if AgentUtils.isUpgradeByUDAgent(Framework): installLogFile = agentPlatformConfig.getUpgradeLogFile( ) else: installLogFile = agentPlatformConfig.getInstallLogFile( ) localInstallFile = File( AGENTS_LOGS_TEMP_DIR_FILE, ip_address_str + '-' + installLogFile) getLogFileContent(Framework, localInstallFile, str(BASEDIR) + installLogFile) if downloadUnInstallLog: logger.debug('Download the uninstall log') unInstallLogFile = agentPlatformConfig.getUnInstallLogFile( ) localUnInstallFile = File( AGENTS_LOGS_TEMP_DIR_FILE, ip_address_str + '-' + unInstallLogFile) getLogFileContent(Framework, localUnInstallFile, str(BASEDIR) + unInstallLogFile) except: errorMessage = str(sys.exc_info()[1]) logger.debugException(errorMessage) Framework.reportError( inventoryerrorcodes. INVENTORY_DISCOVERY_FAILED_EXECUTE_STEP, ['FinalizeAndReleaseResources', errorMessage]) finally: try: if localInstallFile and not localInstallFile.delete(): logger.debug('File was not deleted:' + localInstallFile.getCanonicalPath()) except: logger.debugException('Failed to delete ' + localInstallFile.getCanonicalPath()) try: logger.debug('Going to delete file ' + localInstallFile.getCanonicalPath()) if localUnInstallFile and not localUnInstallFile.delete(): logger.debug('File was not deleted:' + localUnInstallFile.getCanonicalPath()) except: logger.debugException('Failed to delete ' + localUnInstallFile.getCanonicalPath())