def execute(self,State):
        """
        install linux build
        """
        self.init(State)
        if self.logflag == True:
            self.logger.log(self.info)

        # 1.connect to Linux machine
        self = Command.getClient(self)
        if self.stat == self.FAILED:
            return self.FAILED
        
        #2. get official build path
        copyToPath = Command.checkPath(self.buildLocation)+self.buildNo+"/"+self.buildVersion+"/BIN/"
        print "version:"+self.buildVersion
        print "copyto path:" +copyToPath
        targetPath = Command.checkPath(self.buildInstallPath)+self.buildNo+"/"+self.buildVersion+"/"     
        
        #3. check if copytopath and installpath exist
        if Command.checkPathExist(copyToPath,self.client) == False:
            self.stat = self.FAILED
            self.info = "can not open build folder, the test build may not be ready"
            if self.logflag == True:
                self.logger.log(self.info)
            return self.FAILED
        
        if Command.checkPathExist(self.buildInstallPath,self.client) == False:
            self.stat = self.FAILED
            self.info = "can not open build folder, please provide the right install path"
            if self.logflag == True:
                self.logger.log(self.info)
            return self.FAILED
        
        #4. Check if there are enough disk
        self = Command.getUnixOS(self) 
        buildsize = Command.getFolderSize(self.client,copyToPath+self.OS);
        diskspace = Command.getDiskSpace(self.client,self.buildInstallPath) 
        if int(diskspace) < int(buildsize):
            self.stat = self.FAILED
            self.info = "there is not enough disk space to install build, please clean the disk space"
            if self.logflag == True:
                self.logger.log(self.info)
            return self.FAILED
        
        #2. install build.
        cmd = "perl "+copyToPath+"copyto.pl "+targetPath
        result = Command.executeSsh(cmd, self.client)
        if result.lower().find("command not found") != -1:
            self.stat = self.FAILED
            self.info = "target build not found, please check if the build ready is ready"
            if self.logflag == True:
                self.logger.log(self.info)
            return self.FAILED
        else:
            self.stat = self.PASS
            self.info ="build install success: "+targetPath
            if self.logflag == True:
                self.logger.log(self.info)
            return self.PASS
 def getProjectIDList(self, sourcetype):       
     proj_ID = []
     if sourcetype == "Cache":
         if not Command.checkPathExist(self.sourcepath+"Caches/", self.client):
             return proj_ID
         res = Command.executeSsh("ls "+self.sourcepath+"Caches/", self.client)
     elif sourcetype == "Cube":
         if not Command.checkPathExist(self.sourcepath+"Cube/", self.client):
             return proj_ID
         res = Command.executeSsh("ls "+self.sourcepath+"Cube/", self.client)
     elif sourcetype == "Inbox":
         if not Command.checkPathExist(self.sourcepath+"Inbox/", self.client):
             return proj_ID
         res = Command.executeSsh("ls "+self.sourcepath+"Inbox/", self.client)
     else:
         return proj_ID
     
     proj_ID = res.split(" ")
     return proj_ID
Exemple #3
0
 def execute(self, State):
     #init the variables.
     self.init(State)
     if self.logflag == True:
         self.logger.log(self.info)
     pass
     
     if self.OS == "Linux":
         # 1.connect to Linux machine
         self = Command.getClient(self)
         if self.stat == self.FAILED:
             return self.FAILED
         
         # 2.check Iserver path
         buildpath = Command.checkPath(self.buildInstallPath)+self.buildno+"/"+self.buildversion+"/"
         if not Command.checkPathExist(buildpath, self.client):
             self.info = "directory "+buildpath+" does not exist."
             self.stat = self.ABORT
             return self.ABORT
         
         # 3.stop Iserver if it is running
         cmd = buildpath+"BIN/Linux/bin/mstrctl -s IntelligenceServer gs"
         result = Command.executeSsh(cmd, self.client)
         serverStatus = re.search(r">\w+<\/state>", result).group(0)
         if serverStatus[1:-8] == "running":
             cmd = buildpath + "BIN/Linux/bin/mstrctl -s IntelligenceServer stop"
             Command.executeSsh(cmd, self.client)
             time.sleep(120)
                     
         # 4.delete Iserver build
         cmd = buildpath+"BIN/Linux/bin/mstrctl -s IntelligenceServer gs"
         result = Command.executeSsh(cmd, self.client)
         serverStatus = re.search(r">\w+<\/state>", result).group(0)
         if (serverStatus[1:-8] == "stopped" or serverStatus[1:-8] == "terminated"):
             cmd = "rm -rf "+Command.checkPath(self.buildInstallPath)+self.buildno
             result = Command.executeSsh(cmd, self.client)
             if result != "":
                 self.info = "Error in delete directory "+Command.checkPath(self.buildInstallPath)+self.buildno
                 self.stat = self.FAILED
             else:
                 self.info = "Successfully delete directory "+Command.checkPath(self.buildInstallPath)+self.buildno
                 self.stat = self.PASS
         else:
             self.info = "Cannot delete build when IServer is not stopped."
             self.stat = self.FAILED
             
     else:
         # if os is windows.
         c = rpyc.classic.connect(State.get("server"))
 def execute(self, State):
     '''
     this method copies all caches/cube/inbox from backup location.
     '''
     #init the variables.
     self.init(State)
     if self.logflag == True:
         self.logger.log(self.info)
     pass
     
     if self.OS == "Linux":
         # 1.connect to Linux machine
         self = Command.getClient(self)
         if self.stat == self.FAILED:
             return self.FAILED
         
         # 2.check cache source path existing
         if not Command.checkPathExist(self.sourcepath, self.client):
             self.info = "source directory "+self.sourcepath+" does not exist. Please check inputs in config.ini."
             self.stat = self.ABORT
             return self.ABORT
         else:
             res = Command.executeSsh("ls "+self.sourcepath, self.client)
             if res == "":
                 self.info = "no caches/cube/inbox directory in "+self.sourcepath+". Please check if it's mounted."
                 self.stat = self.ABORT
                 return self.ABORT
         
         # 3.copy cache/cube/inbox accordingly
         buildpath = Command.checkPath(self.buildInstallPath)+self.buildno+"/"+self.buildversion+"/BIN/"+self.OS +"/"
         localcachepath = buildpath+"Caches/"+self.serverdef+"/"
         localcubepath = buildpath+"Cube/"+self.serverdef+"/"
         localinboxpath =buildpath+"Inbox/"+self.serverdef+"/"
         
         projIDlist = self.getProjectIDList("Cache")
         if not projIDlist:
             print "No caches to copy."
         else:
             if Command.checkPathExist(localcachepath, self.client):
                 for id in projIDlist:
                     cachesourcepath = self.sourcepath+"Caches/"+id+"/*"
                     localcacheprojectpath = localcachepath+"Server"+self.server+"_P"+id+"/"
                     if not Command.checkPathExist(localcacheprojectpath, self.client):
                         Command.executeSsh("mkdir "+localcacheprojectpath, self.client)
                     result = Command.executeSsh("cp -fr "+cachesourcepath+" "+localcacheprojectpath, self.client)
                     if result != "":
                         print "something wrong when copy cache of project "+id
             else:
                 print "local cache path does not exist. Please check if IServer is installed correctly."
         
         projIDlist = self.getProjectIDList("Cube")
         if not projIDlist:
             print "No cube to copy."
         else:
             if  Command.checkPathExist(localcubepath, self.client):    
                 for id in projIDlist:
                     cubesourcepath = self.sourcepath+"Cube/"+id+"/*"
                     localcubeprojectpath = localcubepath+"Server_"+self.server+"_P"+id+"/"
                     if not Command.checkPathExist(localcubeprojectpath, self.client):
                         Command.executeSsh("mkdir "+localcubeprojectpath, self.client)
                     result = Command.executeSsh("cp -fr "+cubesourcepath+" "+localcubeprojectpath, self.client)
                     if result != "":
                         print "something wrong when copy cube of project "+id
             else:
                 print "local cube path does not exist. Please check if IServer is installed correctly."
             
         projIDlist = self.getProjectIDList("Inbox")
         if not projIDlist:
             print "No inbox to copy."
         else:
             if Command.checkPathExist(localinboxpath, self.client):
                 for id in projIDlist:
                     inboxsourcepath = self.sourcepath+"Inbox/"+id+"/*"
                     #localinboxprojectpath = localinboxpath+"Server_"+self.server+"_P"+id+"/"
                     localinboxprojectpath = localinboxpath
                     if not Command.checkPathExist(localinboxprojectpath, self.client):
                         Command.executeSsh("mkdir "+localinboxprojectpath, self.client)
                     result = Command.executeSsh("cp -fr "+inboxsourcepath+" "+localinboxprojectpath, self.client)
                     if result != "":
                         print "something wrong when copy inbox of project "+id
             else:
                 print "local inbox path does not exist. Please check if IServer is installed correctly."
         
         self.info = "copy cache task is completed."
         self.stat = self.PASS
     
     else:
         # if os is windows.
         c = rpyc.classic.connect(State.get("server"))  
         rsub = c.modules.subprocess
         # copy caches on windows iserver