Beispiel #1
0
 def __init__(self, testClient, logFileDir):
     self._testClient = testClient
     curTimestamp = getCurrentTimestamp()
     logFileName = "%s.%s" % (self.DEFAULT_VISTA_LOG_FILENAME, curTimestamp)
     self._logFileName = os.path.join(logFileDir, logFileName)
     self._testClient.setLogFile(self._logFileName)
     self._patchOrderGen = PatchOrderGenerator()
     self._vistaPatchInfo = VistAPackageInfoFetcher(testClient)
     self._outPatchList = []
     self._patchSet = set()
     initFileLogging(os.path.join(logFileDir, self.DEFAULT_OUTPUT_FILE_LOG))
Beispiel #2
0
 def runInstallation(self, vistATestClient, vistATestClient2=None, reinst=False):
   connection = vistATestClient.getConnection()
   self.__setupLogFile__(connection)
   infoFetcher = VistAPackageInfoFetcher(vistATestClient)
   installStatus = infoFetcher.getInstallationStatus(self._kidsInstallName)
   """ select KIDS installation workflow based on install status """
   if infoFetcher.isInstallCompleted(installStatus):
     logger.warn("install %s is already completed!" %
                  self._kidsInstallName)
     if not reinst:
       return True
   # run pre-installation preparation
   self.preInstallationWork(vistATestClient)
   if infoFetcher.isInstallStarted(installStatus):
     return self.restartInstallation(vistATestClient)
   return self.normalInstallation(vistATestClient,vistATestClient2, reinst)
Beispiel #3
0
 def _autoRecover(self):
     """
   private method to recover the right cache.dat based on the patch
   installed in the running VistA instance.
 """
     from GitUtils import getCommitInfo
     mExtractConfig = self._config['M_Extract']
     mRepo = mExtractConfig['M_repo']
     mRepoBranch = mExtractConfig.get('M_repo_branch', None)
     if not mRepoBranch:
         mRepoBranch = 'master'  # default is the master branch
     commitInfo = getCommitInfo(mRepo, mRepoBranch)
     if not commitInfo:
         logger.error("Can not read commit info from %s branch %s" %
                      (mRepo, mRepoBranch))
         return -1
     logger.debug(commitInfo)
     """ convert datetime to VistA T- format """
     from datetime import datetime
     commitDate = datetime.fromtimestamp(int(commitInfo['%ct']))
     timeDiff = datetime.now() - commitDate
     days = timeDiff.days + 30  # extra 30 days
     logger.debug("Totol dates to query is %s" % days)
     installNames = None
     idx = commitInfo['%s'].find('Install: ')
     if idx >= 0:
         installNames = commitInfo['%s'][len('Install: '):].split(', ')
     logger.info("installNames is %s" % installNames)
     if installNames is None:
         logger.error("Can not find patch installed after")
         return -1
     """ check to see what and when is the last patch installed """
     testClient = self._createTestClient()
     """ make sure cache instance is up and running """
     startCache(self._instance, self._useSudo)
     with testClient:
         patchInfoFetch = VistAPackageInfoFetcher(testClient)
         output = patchInfoFetch.getAllPatchInstalledAfterByTime("T-%s" %
                                                                 days)
     if not output:  # must be an error or something, skip backup
         logger.error(
             "Can not get patch installation information from VistA")
         return -1
     logger.debug(output)
     """ logic to check if we need to recover from cache backup data """
     found = False
     for idx in xrange(0, len(output)):
         if output[idx][0] == installNames[-1]:
             found = True
             break
     if found and idx == len(output) - 1:
         """ last patch is the same as last in the commit """
         logger.info("No need to recover.")
         return 0
     if not found or idx < len(output) - 1:
         """ check to see if cache.dat exist in the backup dir"""
         backupConfig = self._config.get('Backup')
         backupDir = backupConfig['backup_dir']
         if not os.path.exists(backupDir):
             logger.error("%s does not exist" % backupDir)
             return -4
         cacheDir = backupConfig['cache_dat_dir']
         origDir = os.path.join(cacheDir, "CACHE.DAT")
         """ identify the exists of backup file in the right format """
         commitHash = commitInfo['%H']
         cacheBackupFile = os.path.join(
             backupDir, getCacheBackupNameByHash(commitHash))
         if not os.path.exists(cacheBackupFile):
             logger.error("backup file %s does not exist" % cacheBackupFile)
             return -5
         logger.info("Need to restore from backup data %s" %
                     cacheBackupFile)
         restoreCacheData(self._instance, cacheBackupFile, cacheDir,
                          self._useSudo)
         startCache(self._instance, self._useSudo)
         return 0
     return -1