def setUp(self): """ Setup the test saturn host (where the storage is provisioned) Assuming a VG exists on that host, run VGscan This means that the SSH key should be on that host already """ print "Here is where we can set some state" #Dummy super user for interfaces test self.config = ConfigReader('saturn.ini') self.saturnringip = self.config.get('tests', 'saturnringip') self.saturnringport = self.config.get('tests', 'saturnringport') self.iscsiserver = self.config.get('tests', 'saturniscsiserver') my_admin = User.objects.create_superuser('myuser', '*****@*****.**', 'password') testhost = StorageHost(dnsname=self.iscsiserver, ipaddress=self.iscsiserver, storageip1=self.iscsiserver) testhost.save() outStr = check_output([ "curl", "-X", "GET", "http://" + self.saturnringip + ":" + self.saturnringport + "/api/vgscan/", "-d", "saturnserver=" + self.iscsiserver ]) for eachElement in literal_eval(outStr): vguuid = eachElement['vguuid'] vg = VG(vghost=testhost, vguuid=vguuid, vgpesize=1.0, vgtotalpe=10.0, vgsize=1.0) vg.save() self.host = literal_eval(outStr)[0]['vghost'] self.psrvr = PollServer(self.host)
def ChangeInitiatorHelper(requestDic,owner): ''' Change the initiator for SCST (do not change it in the saturnring DB though) ''' logger = getLogger(__name__) try: user = User.objects.get(username=owner); iqntar = requestDic['iqntar'] newini = requestDic['newini'] target = Target.objects.get(owner=user,iqntar=iqntar); except: errorstring = format_exc() logger.error(errorstring) return (-1,errorstring) config = ConfigReader() numqueues = config.get('saturnring','numqueues') queuename = 'queue'+str(hash(target.targethost)%int(numqueues)) queue = get_queue(queuename) job = queue.enqueue(ExecChangeInitiator,args=(iqntar,newini),timeout=45,ttl=60) while (job.result != 0) and (job.result != -1) : sleep(1) logger.info("...Working on changing target %s initiator name to %s" %(iqntar,newini)) #logger.info(str(job)) return (job.result,str(job))
def DeleteTarget(requestDic,owner): ''' Delete iSCSI target This function dispatches a request to the worker queue of the Saturn host to delete the object (iSCSI target object). R: RequestDic - which may contain one of the following iqntarget name, initiator name (all targets provisioned for that initiator), targethost (DNS name of Saturn server). ''' logger = getLogger(__name__) queryset = None if 'iqntar' in requestDic: queryset=Target.objects.filter(iqntar=requestDic['iqntar'],owner=owner) if 'iqnini' in requestDic: if queryset is None: queryset=Target.objects.filter(iqnini=requestDic['iqnini'],owner=owner) else: queryset=queryset.objects.filter(iqnini=requestDic['iqnini']) if 'targethost' in requestDic: if queryset is None: queryset=Target.objects.filter(targethost=requestDic['targethost'],owner=owner) else: queryset=queryset.objects.filter(targethost=requestDic['targethost']) if queryset is None: return (1,"No targets to delete, or check delete API call") config = ConfigReader() numqueues = config.get('saturnring','numqueues') jobs =[] logger.info("DeleteTarget has %d targets to delete" % (queryset.count())) for obj in queryset: logger.info("DeleteTarget Working on deleting target %s" % (obj.iqntar,)) queuename = 'queue'+str(hash(obj.targethost)%int(numqueues)) queue = get_queue(queuename) jobs = [] jobs.append( (queue.enqueue(DeleteTargetObject,obj), obj.iqntar) ) logger.info("Using queue %s for deletion" %(queuename,)) rtnStatus= {} rtnFlag=0 numDone=0 while numDone < len(jobs): ii=0 sleep(1) for ii in range(0,len(jobs)): if jobs[ii] == 0: continue (job,target) = jobs[ii] if (job.result == 0) or (job.result == 1) or job.is_failed: if job.result==1 or job.is_failed: logger.error("Failed deletion of " + target) rtnStatus[target] = "Failed deletion of " + target rtnFlag=rtnFlag + job.result + int(job.is_failed) jobs[ii]=0 numDone=numDone+1 else: logger.info('...Working on deleting target '+target) break return (rtnFlag,str(rtnStatus))
def DeleteTarget(requestDic,owner): ''' Delete iSCSI target This function dispatches a request to the worker queue of the Saturn host to delete the object (iSCSI target object). R: RequestDic - which may contain one of the following iqntarget name, initiator name (all targets provisioned for that initiator), targethost (DNS name of Saturn server). ''' logger = getLogger(__name__) queryset = None if 'iqntar' in requestDic: queryset=Target.objects.filter(iqntar=requestDic['iqntar'],owner=owner) if 'iqnini' in requestDic: if queryset is None: queryset=Target.objects.filter(iqnini=requestDic['iqnini'],owner=owner) else: queryset=queryset.objects.filter(iqnini=requestDic['iqnini']) if 'targethost' in requestDic: if queryset is None: queryset=Target.objects.filter(targethost=requestDic['targethost'],owner=owner) else: queryset=queryset.objects.filter(targethost=requestDic['targethost']) if queryset is None: return (1,"No targets to delete, or check delete API call") config = ConfigReader() numqueues = config.get('saturnring','numqueues') jobs =[] logger.info("DeleteTarget has %d targets to delete" % (queryset.count())) for obj in queryset: logger.info("DeleteTarget Working on deleting target %s" % (obj.iqntar,)) queuename = 'queue'+str(hash(obj.targethost)%int(numqueues)) queue = get_queue(queuename) jobs = [] jobs.append( (queue.enqueue(DeleteTargetObject,args=(obj.iqntar,),timeout=45,ttl=60), obj.iqntar) ) logger.info("Using queue %s for deletion" %(queuename,)) rtnStatus= {} rtnFlag=0 numDone=0 while numDone < len(jobs): ii=0 sleep(1) for ii in range(0,len(jobs)): if jobs[ii] == 0: continue (job,target) = jobs[ii] if (job.result == 0) or (job.result == 1) or job.is_failed: if job.result==1 or job.is_failed: logger.error("Failed deletion of " + target) rtnStatus[target] = "Failed deletion of " + target rtnFlag=rtnFlag + job.result + int(job.is_failed) jobs[ii]=0 numDone=numDone+1 else: logger.info('...Working on deleting target '+target) break return (rtnFlag,str(rtnStatus))
def get(self, request): config = ConfigReader() numqueues = config.get('saturnring', 'numqueues') allhosts = StorageHost.objects.filter(enabled=True) for eachhost in allhosts: queuename = 'queue' + str(hash(eachhost) % int(numqueues)) queue = get_queue(queuename) queue.enqueue(UpdateOneState, eachhost) return Response("Ok, enqueued state update request")
def get(self, request ): logger = getLogger(__name__) logger.info("Raw request data is "+str(request.data)) serializer = ProvisionerSerializer(data=request.data) rtnDict = {} if serializer.is_valid(): (flag,statusStr) = MakeTarget(request.data,request.user) if flag==-1: rtnDict = {} rtnDict['error']=1 rtnDict['detail']=statusStr return Response(rtnDict, status=status.HTTP_400_BAD_REQUEST) if (flag==0 or flag==1): tar = Target.objects.filter(iqntar=statusStr) if (tar[0].owner != request.user): return Response({'error':1,'detail':'Not authorized'},status=status.HTTP_401_UNAUTHORIZED) #if (flag != 1): #Dont run this code if this is a pre-existing LUN #Check and update state on the Saturn node config = ConfigReader() numqueues = config.get('saturnring','numqueues') queuename = 'queue'+str(hash(tar[0].targethost)%int(numqueues)) queue = get_queue(queuename) job = queue.enqueue(UpdateOneState,args=(tar[0].targethost.dnsname,), timeout=45,ttl=60) while not ( (job.result == 0) or (job.result == 1) or job.is_failed): sleep(0.5) if (job.result == 1) or (job.is_failed): rtnDict['error'] = 1 rtnDict['detail'] = "Saturn server %s on which the target %s is provisioned is not healthy/responding, contact admin" %(tar[0].targethost,tar[0].iqntar) logger.error("Error while provisioning/returning target %s" %(tar[0].iqntar,)) return Response(rtnDict, status=status.HTTP_500_INTERNAL_SERVER_ERROR) data = tar.values('iqnini','iqntar','sizeinGB','targethost','storageip1','storageip2','aagroup__name','clumpgroup__name','sessionup','isencrypted','pin') rtnDict = ValuesQuerySetToDict(data)[0] rtnDict['targethost__storageip1']=rtnDict.pop('storageip1') #in order to not change the user interface if rtnDict['targethost__storageip1']=='127.0.0.1': rtnDict['targethost__storageip1']= tar[0].targethost.storageip1 rtnDict['targethost__storageip2']=rtnDict.pop('storageip2') if rtnDict['targethost__storageip2']=='127.0.0.1': rtnDict['targethost__storageip2']= tar[0].targethost.storageip2 rtnDict['already_existed']=flag rtnDict['error']=0 return Response(rtnDict, status=status.HTTP_201_CREATED) else: rtnDict['error']=1 rtnDict['detail'] = 'Problem provisioning, contact admin' return Response(rtnDict, status=status.HTTP_500_INTERNAL_SERVER_ERROR) else: logger.warn("Invalid provisioner serializer data: "+str(request.data)) rtnDict={} rtnDict['error']=1 rtnDict['detail']=serializer.errors return Response(rtnDict, status=status.HTTP_400_BAD_REQUEST)
def setUp(self): """ Setup the test saturn host (where the storage is provisioned) Assuming a VG exists on that host, run VGscan This means that the SSH key should be on that host already """ print "Here is where we can set some state" #Dummy super user for interfaces test self.config = ConfigReader('saturn.ini') self.saturnringip = self.config.get('tests','saturnringip') self.saturnringport = self.config.get('tests','saturnringport') self.iscsiserver = self.config.get('tests','saturniscsiserver') my_admin = User.objects.create_superuser('myuser', '*****@*****.**', 'password') testhost = StorageHost(dnsname = self.iscsiserver, ipaddress=self.iscsiserver, storageip1=self.iscsiserver ) testhost.save() outStr = check_output(["curl","-X","GET","http://"+self.saturnringip+":"+self.saturnringport+"/api/vgscan/","-d","saturnserver="+self.iscsiserver]) for eachElement in literal_eval(outStr): vguuid = eachElement['vguuid'] vg = VG(vghost=testhost, vguuid = vguuid, vgpesize = 1.0, vgtotalpe = 10.0, vgsize = 1.0) vg.save() self.host = literal_eval(outStr)[0]['vghost'] self.psrvr = PollServer(self.host)
def setUp(self): #rows = sys.path #for row in rows: # print row cfg = ConfigReader() cfg.read("../config.xml") Database.Open(cfg.GetPath(), cfg.GetUsername(), cfg.GetPassword())
def get(self, request): logger = getLogger(__name__) try: error = StatMaker() if error != 0: logger.error('Stat creation returned'+str(error)) raise IOError config = ConfigReader() thefile = join(config.get('saturnring','iscsiconfigdir'),config.get('saturnring','clustername')+'.xls') filename = basename(thefile) response = HttpResponse(FileWrapper(open(thefile)),content_type=guess_type(thefile)[0]) response['Content-Length'] = getsize(thefile) response['Content-Disposition'] = "attachment; filename=%s" % filename return response except: var = format_exc() logger.warn("Stat error: %s" % (var,)) return Response(strftime('%c')+": Stat creation error: contact administrator")
def get(self, request): timeoutValue = 30 logger = getLogger(__name__) config = ConfigReader() numqueues = config.get('saturnring','numqueues') allhosts=StorageHost.objects.all() jobs = {} rtnStr = strftime("%Y-%m-%d %H:%M:%S", gmtime()) for eachhost in allhosts: queuename = 'queue'+str(hash(eachhost)%int(numqueues)) queue = get_queue(queuename) jobs[str(eachhost)]=queue.enqueue(UpdateOneState,args=(eachhost.dnsname,), timeout=timeoutValue) for eachhost in allhosts: while( jobs[str(eachhost)].is_queued or jobs[str(eachhost)].is_started): sleep(0.5) rtnStr = rtnStr + " ||| <hostname> : Host enabled boolean : Update returns (0 is good) : Job failed (False is good) " for eachhost in allhosts: rtnStr = rtnStr + "|||" + " : ".join([str(eachhost),str(eachhost.enabled),str(jobs[str(eachhost)].result),str(jobs[str(eachhost)].is_failed)]) logger.info("Updatestate status: %s " %(rtnStr,)) return Response(config.get('saturnring','clustername')+" state at "+rtnStr)
def OnInit(self): if os.name == 'posix': print os.environ['PWD'] cfg = ConfigReader() cfg.read("../main/config.xml") Database.Open(cfg.GetPath(), cfg.GetUsername(), cfg.GetPassword()) frame = MainFrame(None, title="The Main Frame") self.SetTopWindow(frame) frame.Show(True) return True
def get(self, request): try: error = StatMaker() if error != 0: logger.error('Stat creation returned' + str(error)) raise IOError config = ConfigReader() thefile = join(config.get('saturnring', 'iscsiconfigdir'), config.get('saturnring', 'clustername') + '.xls') filename = basename(thefile) response = HttpResponse(FileWrapper(open(thefile)), content_type=guess_type(thefile)[0]) response['Content-Length'] = getsize(thefile) response[ 'Content-Disposition'] = "attachment; filename=%s" % filename return response except: var = format_exc() logger.warn("Stat error: %s" % (var, )) return Response( strftime('%c') + ": Stat creation error: contact administrator")
def __init__(self,serverDNS): """ The init script for the class """ self.serverDNS = str(serverDNS) BASE_DIR = dirname(dirname(__file__)) config = ConfigReader() self.userName = config.get('saturnnode','user') self.keyFile = join(BASE_DIR,config.get('saturnring','privatekeyfile')) self.rembashpath = config.get('saturnnode','bashpath') self.rempypath = config.get('saturnnode','pythonpath') self.iscsiconfdir = join(BASE_DIR,config.get('saturnring','iscsiconfigdir')) self.remoteinstallLoc = config.get('saturnnode','install_location') self.localbashscripts = join(BASE_DIR,config.get('saturnring','bashscripts')) try: self.srv = Connection(self.serverDNS,self.userName,self.keyFile) except: logger.critical("Failed SSH-exec connection on Saturn server %s; possible cause: %s" % (self.serverDNS,format_exc()) )
def __init__(self, serverDNS): """ The init script for the class """ self.serverDNS = str(serverDNS) BASE_DIR = dirname(dirname(__file__)) config = ConfigReader() self.userName = config.get('saturnnode', 'user') self.keyFile = join(BASE_DIR, config.get('saturnring', 'privatekeyfile')) self.rembashpath = config.get('saturnnode', 'bashpath') self.rempypath = config.get('saturnnode', 'pythonpath') self.iscsiconfdir = join(BASE_DIR, config.get('saturnring', 'iscsiconfigdir')) self.remoteinstallLoc = config.get('saturnnode', 'install_location') self.localbashscripts = join(BASE_DIR, config.get('saturnring', 'bashscripts')) try: self.srv = Connection(self.serverDNS, self.userName, self.keyFile) except: logger.critical( "Failed SSH-exec connection on Saturn server %s; possible cause: %s" % (self.serverDNS, format_exc()))
class GSMTestCase (TestCase): """ Test cases for GlobalStatemanager Test GetLVs Test GetVGs """ def setUp(self): """ Setup the test saturn host (where the storage is provisioned) Assuming a VG exists on that host, run VGscan This means that the SSH key should be on that host already """ print "Here is where we can set some state" #Dummy super user for interfaces test self.config = ConfigReader('saturn.ini') self.saturnringip = self.config.get('tests','saturnringip') self.saturnringport = self.config.get('tests','saturnringport') self.iscsiserver = self.config.get('tests','saturniscsiserver') my_admin = User.objects.create_superuser('myuser', '*****@*****.**', 'password') testhost = StorageHost(dnsname = self.iscsiserver, ipaddress=self.iscsiserver, storageip1=self.iscsiserver ) testhost.save() outStr = check_output(["curl","-X","GET","http://"+self.saturnringip+":"+self.saturnringport+"/api/vgscan/","-d","saturnserver="+self.iscsiserver]) for eachElement in literal_eval(outStr): vguuid = eachElement['vguuid'] vg = VG(vghost=testhost, vguuid = vguuid, vgpesize = 1.0, vgtotalpe = 10.0, vgsize = 1.0) vg.save() self.host = literal_eval(outStr)[0]['vghost'] self.psrvr = PollServer(self.host) def test_GetLVs(self): """ Test if LVs are being read off the test server """ allvgs = VG.objects.all() for eachvg in allvgs: lvs = self.psrvr.GetLVs(eachvg.vguuid) pprint(lvs) self.assertNotEqual(len(lvs),0) def test_InstallScripts(self): """ Test if SCP installation of scripts works Tests via comparing directory listing of the remote install directory before and after InstallScripts """ installLoc = join(self.config.get('saturnnode','install_location'),'saturn-bashscripts') BASE_DIR = dirname(dirname(__file__)) localLoc = join(BASE_DIR,self.config.get('saturnring','bashscripts')) fH = open(join(localLoc,'test_InstallScript.txt'),'w') fH.write('Test started' ) fH.close() dirlistcmd = 'ls -al '+installLoc b4installdirout = self.psrvr.Exec(dirlistcmd) print "BEFORE" pprint (b4installdirout) self.psrvr.InstallScripts() afterinstalldirout = self.psrvr.Exec(dirlistcmd) print "AFTER" pprint (afterinstalldirout) self.assertNotEqual(str(b4installdirout),str(afterinstalldirout)) remove(join(localLoc,'test_InstallScript.txt')) rmfilecmd = 'rm '+join(installLoc,'test_InstallScript.txt') self.psrvr.Exec(rmfilecmd) def test_Exec(self): """ Test if SSH/Exec works """ rtnStr = self.psrvr.Exec("uptime") self.assertIn("load average",str(rtnStr)) def test_GetInterfaces(self): """ Test if the interface scanning works """ oldEntries = Interface.objects.all() oldEntries.delete() self.psrvr.GetInterfaces() interfaces = Interface.objects.all() for eachInterface in interfaces: print eachInterface.ip self.assertNotEqual(len(interfaces), 0)
sizer.Add(btnSizer) self.SetSizer(sizer) self.SetInitialSize() def OnOpenDlg(self, event): wizard = NewWizard(self) wizard.Create() wizard.Run() class PatentEditPanel(wx.Panel): def __init__(self, parent): super(PatentEditPanel, self).__init__(parent, style=wx.LB_BOTTOM) class TestApp(wx.App): def OnInit(self): patentEditDialog = PatentEditDialog() patentEditDialog.ShowModal() return True from access.database import Database from utils.configreader import ConfigReader if __name__ == "__main__": cfg = ConfigReader() cfg.read("/home/wzw7yn/workspace/pms/main/config.xml") Database.Open(cfg.GetPath(), cfg.GetUsername(), cfg.GetPassword()) app = TestApp(False) app.MainLoop()
def get_clustername(): try: config = ConfigReader() return config.get('saturnring','clustername') except: return 'undefined'
def MakeTarget(requestDic,owner): """ Actual maketarget orchestrator """ logger = getLogger(__name__) clientiqn = requestDic['clientiqn'] serviceName = requestDic['serviceName'] storageSize = requestDic['sizeinGB'] aagroup ='' subnet='' if 'clumpgroup' not in requestDic: clumpgroup = "noclump" else: clumpgroup = requestDic['clumpgroup'] if 'aagroup' not in requestDic: aagroup = "random" else: aagroup = requestDic['aagroup'] if 'subnet' in requestDic: subnet = requestDic['subnet'] else: subnet = "public" if 'storemedia' in requestDic: storemedia = requestDic['storemedia'] else: storemedia = 'randommedia' if 'provisiontype' in requestDic: provisiontype = requestDic['provisiontype'] else: provisiontype = 'any' logger.info("Provisioner - request received: ClientIQN: %s, Service: %s, Size(GB) %s, AAGroup: %s, Clumpgroup: %s, Subnet: %s, Storemedia: %s, ProvisionType: %s " %(clientiqn, serviceName, str(storageSize), aagroup, clumpgroup, subnet, storemedia, provisiontype)) try: while 1: globallock = Lock.objects.get(lockname='allvglock') if globallock.locked==False: globallock.locked=True globallock.save() break else: sleep(0.2) except: #This is to create the lock the first time globallock = Lock(lockname='allvglock',locked=True) globallock.save() globallock = Lock.objects.get(lockname='allvglock') try: chosenVG = VGFilter(storageSize,aagroup,owner,clumpgroup,subnet,storemedia,provisiontype) except: logger.error("VGFilter broke") logger.error(format_exc()) chosenVG = -1 if chosenVG != -1: chosenVG.is_locked = True chosenVG.save(update_fields=['is_locked']) sleep(0.1) #Safety net to make sure the save did complete on the DB globallock.locked=False globallock.save() targetHost = str(chosenVG.vghost) targetvguuid = str(chosenVG.vguuid) config = ConfigReader() numqueues = config.get('saturnring','numqueues') queuename = 'queue'+str(hash(targetHost)%int(numqueues)) queue = get_queue(queuename) logger.info("Launching create target job into queue %s" %(queuename,) ) storemedia = chosenVG.storemedia job = queue.enqueue(ExecMakeTarget,storemedia,targetvguuid,targetHost,clientiqn,serviceName,storageSize,aagroup,clumpgroup,subnet,owner) while 1: if job.result or job.is_failed: chosenVG.is_locked = False chosenVG.save(update_fields=['is_locked']) if job.is_failed: return (-1,"Provisioner failed, check syntax or contact admin") return job.result else: sleep(0.25) else: globallock.locked=False globallock.save() try: clientiqnHash = hashlib.sha1(clientiqn).hexdigest()[:8] targets = Target.objects.filter(iqntar__contains="".join([serviceName,":",clientiqnHash])) if len(targets) != 0: for t in targets: iqnComponents = t.iqntar.split(':') if ((serviceName==iqnComponents[1]) and (clientiqnHash==iqnComponents[2])): logger.info('Target already exists for (serviceName=%s,clientiqn=%s) tuple' % (serviceName,clientiqn)) return (1,t.iqntar) except: logger.warn("Something went wrong while checking for pre-existing target") logger.warn('VG filtering did not return a choice') return (-1, "Are Saturnservers online and adequate, contact admin")
appName = wx.GetApp().GetAppName() assert appName, "No App Name Set" config = wx.Config(appName) perspective = config.Read("perspective") if perspective: self._mgr.LoadPerspective(perspective) def Quit(self): self._mgr.UnInit() self.Destroy() class IAPanel(wx.Panel): def __init__(self, *args, **keys): wx.Panel.__init__(self, *args, **keys) self.test1 = wx.TextCtrl(self, wx.ID_ANY, 'Pane 1 - simple text') if __name__ == "__main__": #str=os.path.curdir #new if os.name == 'posix': print os.environ['PWD'] print platform.system() cfg = ConfigReader() cfg.read("config.xml") #Database.Open(cfg.GetPath(), cfg.GetUsername(), cfg.GetPassword()) # end new app = MyApp(False) app.MainLoop()
class GSMTestCase(TestCase): """ Test cases for GlobalStatemanager Test GetLVs Test GetVGs """ def setUp(self): """ Setup the test saturn host (where the storage is provisioned) Assuming a VG exists on that host, run VGscan This means that the SSH key should be on that host already """ print "Here is where we can set some state" #Dummy super user for interfaces test self.config = ConfigReader('saturn.ini') self.saturnringip = self.config.get('tests', 'saturnringip') self.saturnringport = self.config.get('tests', 'saturnringport') self.iscsiserver = self.config.get('tests', 'saturniscsiserver') my_admin = User.objects.create_superuser('myuser', '*****@*****.**', 'password') testhost = StorageHost(dnsname=self.iscsiserver, ipaddress=self.iscsiserver, storageip1=self.iscsiserver) testhost.save() outStr = check_output([ "curl", "-X", "GET", "http://" + self.saturnringip + ":" + self.saturnringport + "/api/vgscan/", "-d", "saturnserver=" + self.iscsiserver ]) for eachElement in literal_eval(outStr): vguuid = eachElement['vguuid'] vg = VG(vghost=testhost, vguuid=vguuid, vgpesize=1.0, vgtotalpe=10.0, vgsize=1.0) vg.save() self.host = literal_eval(outStr)[0]['vghost'] self.psrvr = PollServer(self.host) def test_GetLVs(self): """ Test if LVs are being read off the test server """ allvgs = VG.objects.all() for eachvg in allvgs: lvs = self.psrvr.GetLVs(eachvg.vguuid) pprint(lvs) self.assertNotEqual(len(lvs), 0) def test_InstallScripts(self): """ Test if SCP installation of scripts works Tests via comparing directory listing of the remote install directory before and after InstallScripts """ installLoc = join(self.config.get('saturnnode', 'install_location'), 'saturn-bashscripts') BASE_DIR = dirname(dirname(__file__)) localLoc = join(BASE_DIR, self.config.get('saturnring', 'bashscripts')) fH = open(join(localLoc, 'test_InstallScript.txt'), 'w') fH.write('Test started') fH.close() dirlistcmd = 'ls -al ' + installLoc b4installdirout = self.psrvr.Exec(dirlistcmd) print "BEFORE" pprint(b4installdirout) self.psrvr.InstallScripts() afterinstalldirout = self.psrvr.Exec(dirlistcmd) print "AFTER" pprint(afterinstalldirout) self.assertNotEqual(str(b4installdirout), str(afterinstalldirout)) remove(join(localLoc, 'test_InstallScript.txt')) rmfilecmd = 'rm ' + join(installLoc, 'test_InstallScript.txt') self.psrvr.Exec(rmfilecmd) def test_Exec(self): """ Test if SSH/Exec works """ rtnStr = self.psrvr.Exec("uptime") self.assertIn("load average", str(rtnStr)) def test_GetInterfaces(self): """ Test if the interface scanning works """ oldEntries = Interface.objects.all() oldEntries.delete() self.psrvr.GetInterfaces() interfaces = Interface.objects.all() for eachInterface in interfaces: print eachInterface.ip self.assertNotEqual(len(interfaces), 0)
def MakeTarget(requestDic,owner): """ Actual maketarget orchestrator """ logger = getLogger(__name__) clientiqn = requestDic['clientiqn'] serviceName = requestDic['serviceName'] storageSize = requestDic['sizeinGB'] aagroup ='' subnet='' if 'clumpgroup' not in requestDic: clumpgroup = "noclump" else: clumpgroup = requestDic['clumpgroup'] if 'aagroup' not in requestDic: aagroup = "random" else: aagroup = requestDic['aagroup'] if 'subnet' in requestDic: subnet = requestDic['subnet'] else: subnet = "public" if 'storemedia' in requestDic: storemedia = requestDic['storemedia'] else: storemedia = 'randommedia' if 'provisiontype' in requestDic: provisiontype = requestDic['provisiontype'] else: provisiontype = 'any' if 'isencrypted' in requestDic: isencrypted = requestDic['isencrypted'] else: isencrypted = '1' #1 means encryption is opt-out - should be explicity specified as 0 to prevent logger.info("Provisioner - request received from user %s: \nClientIQN: %s, Service: %s, Size(GB) %s, AAGroup: %s, Clumpgroup: %s, Subnet: %s, Storemedia: %s, ProvisionType: %s, isEncrypted: %s " %(str(owner.username),clientiqn, serviceName, str(storageSize), aagroup, clumpgroup, subnet, storemedia, provisiontype, isencrypted)) try: clientiqnHash = hashlib.sha1(clientiqn).hexdigest()[:8] targets = Target.objects.filter(iqntar__contains="".join([serviceName,":",clientiqnHash])) if len(targets) != 0: for t in targets: iqnComponents = t.iqntar.split(':') if ((serviceName==iqnComponents[1]) and (clientiqnHash==iqnComponents[2])): logger.info('Target already exists for (serviceName=%s,clientiqn=%s) tuple' % (serviceName,clientiqn)) return (1,t.iqntar) except: logger.error("Something went wrong while checking for pre-existing target") logger.error(format_exc()) return (-1,"Pre-existing target check error, contact admin") try: while 1: globallock = Lock.objects.get(lockname='allvglock') if globallock.locked==False: globallock.locked=True globallock.save() break else: sleep(0.2) except: #This is to create the lock the very first time globallock = Lock(lockname='allvglock',locked=True) globallock.save() globallock = Lock.objects.get(lockname='allvglock') try: chosenVG = VGFilter(storageSize,aagroup,owner,clumpgroup,subnet,storemedia,provisiontype) except: logger.error("VGFilter broke") logger.error(format_exc()) chosenVG = -1 if chosenVG != -1: chosenVG.is_locked = True chosenVG.save(update_fields=['is_locked']) sleep(0.1) #Safety net to make sure the save did complete on the DB globallock.locked=False globallock.save() targetHost = str(chosenVG.vghost) targetvguuid = str(chosenVG.vguuid) config = ConfigReader() numqueues = config.get('saturnring','numqueues') queuename = 'queue'+str(hash(targetHost)%int(numqueues)) queue = get_queue(queuename) logger.info("Launching create target job into queue %s" %(queuename,) ) storemedia = chosenVG.storemedia job = queue.enqueue(ExecMakeTarget,args=(storemedia,targetvguuid,targetHost,clientiqn,serviceName,storageSize,aagroup,clumpgroup,subnet,owner.username,isencrypted,),timeout=45,ttl=60) while 1: if job.result or job.is_failed: chosenVG.is_locked = False chosenVG.save(update_fields=['is_locked']) if job.is_failed: return (-1,"Provisioner failed, check syntax or contact admin") return job.result else: sleep(0.25) else: globallock.locked=False globallock.save() logger.warn('VG filtering did not return a choice') return (-1, "Are Saturnservers online and adequate, contact admin")
def get_clustername(): try: config = ConfigReader() return config.get('saturnring', 'clustername') except: return 'undefined'
def setUp(self): print "Here is where we can set some state" config = ConfigReader('saturn.ini') self.saturnringip = config.get('tests','saturnringip') self.saturnringport = config.get('tests','saturnringport') self.iscsiserver = config.get('tests','saturniscsiserver')
appName = wx.GetApp().GetAppName() assert appName, "No App Name Set" config = wx.Config(appName) perspective = config.Read("perspective") if perspective: self._mgr.LoadPerspective(perspective) def Quit(self): self._mgr.UnInit() self.Destroy() class IAPanel(wx.Panel): def __init__(self, *args, **keys): wx.Panel.__init__(self, *args, **keys) self.test1 = wx.TextCtrl(self, wx.ID_ANY, 'Pane 1 - simple text') if __name__ == "__main__": #str=os.path.curdir #new if os.name == 'posix': print os.environ['PWD'] print platform.system() cfg = ConfigReader() cfg.read("config.xml") Database.Open(cfg.GetPath(), cfg.GetUsername(), cfg.GetPassword()) # end new app = MyApp(False) app.MainLoop()
def ChangeTargetHelper(requestDic,owner): ''' Helper function to change the targetname ''' logger = getLogger(__name__) try: rtnVal = -1 user = User.objects.get(username=owner) oldtar = requestDic['iqntar'] if 'newserviceName' not in requestDic: newserviceName = 'useoldservicename' else: newserviceName = requestDic['newserviceName'] if 'newini' not in requestDic: newini = Target.objects.get(iqntar=oldtar).iqnini else: newini = requestDic['newini'] target = Target.objects.get(iqntar=oldtar); newtar = GenerateTargetName(newini,target.targethost,newserviceName) if (Target.objects.filter(iqntar=newtar).count() != 0): #New target name already exists rtnVal = -2 raise Exception('The new target name %s already exists: %s' %(newtar,str(requestDic))) challengepin = requestDic['pin'] if (challengepin != target.pin): #Pin error rtnVal = -3 raise Exception('Incorrect pin %s specified for target %s in request %s' %(challengepin,oldtar,str(requestDic))) if 'portalrange' in requestDic: iprange = requestDic['portalrange'] ipr = IPRange.objects.get(iprange=iprange) if ((ipr.owner != user) and (ipr.owner != User.objects.get(username='******'))): rtnVal = -4 raise Exception("IPrange error, user %s specified ip range: %s belonging to %s" %(user.username,iprange,ipr.owner.username)) portal = str(Interface.objects.get(storagehost=target.targethost,iprange=ipr)) else: portal = str(target.storageip1) #Default - if not specified, do not change except: errorstring = format_exc() logger.error(errorstring) return (rtnVal,errorstring) try: config = ConfigReader() numqueues = config.get('saturnring','numqueues') queuename = 'queue'+str(hash(target.targethost)%int(numqueues)) queue = get_queue(queuename) job = queue.enqueue(ExecChangeTarget,args=(oldtar,newtar,newini,portal,owner.username),timeout=45,ttl=60) while ((job.result != 0) and (job.result != -1)): sleep(1) logger.info("...Working on changing target %s to %s " %(oldtar,newtar)) if job.result == 0: return (0,newtar) else: raise Exception("ExecChangeTarget could not complete, contact admin: %s" %str(job)) except: errorString = format_exc() logger.error(errorString) return (-1, "ExecChangeTarget job may have timed out or thrown an error, contact admin: %s" % errorString)
def setUp(self): print "Here is where we can set some state" config = ConfigReader('saturn.ini') self.saturnringip = config.get('tests', 'saturnringip') self.saturnringport = config.get('tests', 'saturnringport') self.iscsiserver = config.get('tests', 'saturniscsiserver')