예제 #1
0
def StepMain(Framework):
    AgentUtils.prepareFrameworkForShellOrAgentConnect(Framework)

    InventoryUtils.executeStep(Framework, connectToRemoteNode, InventoryUtils.STEP_REQUIRES_CONNECTION, InventoryUtils.STEP_DOESNOT_REQUIRES_LOCK)
예제 #2
0
def StepMain(Framework):
    AgentUtils.prepareFrameworkForShellOrAgentConnect(Framework)

    InventoryUtils.executeStep(Framework, connectToRemoteNode,
                               InventoryUtils.STEP_REQUIRES_CONNECTION,
                               InventoryUtils.STEP_DOESNOT_REQUIRES_LOCK)
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())