コード例 #1
0
    def migrate(self, fromversion, toversion, **kwds):
        from comoonics.cdsl.ComCdsl import ComoonicsCdsl
        import os.path
        from comoonics import XmlTools
        root = kwds.get("root", "/")
        mountpoint = kwds.get("mountpoint", "")
        toresource = kwds.get("toresource",
                              ComoonicsCdslRepository.default_resources[0])
        fromresource = kwds.get("fromresource",
                                ComoonicsCdslRepository.default_resources[1])

        if os.path.exists(fromresource):
            fromdoc = XmlTools.parseXMLFile(fromresource, False)
            fromelement = fromdoc.documentElement
            if fromelement.tagName != ComoonicsCdslRepository.cdsls_element:
                raise ConfigfileFormatException(
                    "Config file \"%s\"does not start with an cdsls element. Wrong format."
                    % fromresource)

            defaults = fromelement.getElementsByTagName("defaults")
            if defaults:
                defaults = defaults[0]

            defaultkeys = self.getDefaultKeys(defaults)
            defaultkeys["root"] = root
            defaultkeys["mountpoint"] = mountpoint
            defaultkeys["resource"] = toresource
            self.logger.debug("defaults: %s" % defaultkeys)
            torepository = ComoonicsCdslRepository(**defaultkeys)
            cdsls = fromelement.getElementsByTagName("cdsl")
            if cdsls and len(cdsls) > 0:
                for i in range(len(cdsls)):
                    nodes = []
                    nodeselement = cdsls[i].getElementsByTagName("nodes")
                    if nodeselement:
                        nodeselement = nodeselement[0]
                        noderefs = nodeselement.getElementsByTagName("noderef")
                        if noderefs and len(noderefs) > 0:
                            for j in range(len(noderefs)):
                                nodes.append(noderefs[j].getAttribute("ref"))
                    cdsl = ComoonicsCdsl(cdsls[i].getAttribute("src"),
                                         cdsls[i].getAttribute("type"),
                                         torepository, None, nodes,
                                         cdsls[i].getAttribute("timestamp"),
                                         kwds.get("ignoreerrors", True))
                    torepository.commit(cdsl)
            return torepository
        else:
            raise IOError(
                2, "Could not find cdsl inventory file %s in %s" %
                (fromresource, os.getcwd()))
コード例 #2
0
 def testVersionException(self):
     from comoonics.cdsl.ComCdslRepository import CdslVersionException, ComoonicsCdslRepository
     try:
         setupCDSLRepository.cdslRepository7 = ComoonicsCdslRepository(
             clusterinfo=setupCluster.clusterinfo,
             root=os.path.join(baseSetup.tmppath, "repo7"))
         self.assert_("CdslVersionException not risn. Error")
     except CdslVersionException:
         pass
コード例 #3
0
 def migrate(self, fromversion, toversion, **kwds):
     from comoonics.cdsl.ComCdslRepository import ComoonicsCdslRepository
     from comoonics.cdsl.ComCdsl import ComoonicsCdsl
     import os.path
     from comoonics import XmlTools
     root=kwds.get("root", "/")
     mountpoint=kwds.get("mountpoint", "")
     toresource=kwds.get("toresource", ComoonicsCdslRepository.default_resources[0])
     fromresource=kwds.get("fromresource", ComoonicsCdslRepository.default_resources[1])
     
     if os.path.exists(fromresource):
         fromdoc=XmlTools.parseXMLFile(fromresource, False)
         fromelement=fromdoc.documentElement
         if fromelement.tagName != ComoonicsCdslRepository.cdsls_element:
             raise ConfigfileFormatException("Config file \"%s\"does not start with an cdsls element. Wrong format." %fromresource)
         
         defaults=fromelement.getElementsByTagName("defaults")
         if defaults:
             defaults=defaults[0]
         
         defaultkeys=self.getDefaultKeys(defaults)
         defaultkeys["root"]=root
         defaultkeys["mountpoint"]=mountpoint
         defaultkeys["resource"]=toresource
         self.logger.debug("defaults: %s" %defaultkeys)
         torepository=ComoonicsCdslRepository(**defaultkeys)
         cdsls=fromelement.getElementsByTagName("cdsl")
         if cdsls and len(cdsls)>0:
             for i in range(len(cdsls)):
                 nodes=[]
                 nodeselement=cdsls[i].getElementsByTagName("nodes")
                 if nodeselement:
                     nodeselement=nodeselement[0]
                     noderefs=nodeselement.getElementsByTagName("noderef")
                     if noderefs and len(noderefs) > 0:
                         for j in range(len(noderefs)):
                             nodes.append(noderefs[j].getAttribute("ref"))
                 cdsl=ComoonicsCdsl(cdsls[i].getAttribute("src"), cdsls[i].getAttribute("type"), torepository, None, nodes, cdsls[i].getAttribute("timestamp"), kwds.get("ignoreerrors", True))
                 torepository.commit(cdsl)
         return torepository
     else:
         raise IOError(2, "Could not find cdsl inventory file %s in %s" %(fromresource, os.getcwd()))
コード例 #4
0
 def createDefaultRepository(clusterInfo, **keys):
     from comoonics.cdsl.ComCdslRepository import ComoonicsCdslRepository
     repository = keys.get("repository", None)
     if repository:
         keys["resource"] = keys.get("resource", repository.getResource())
         keys["root"] = keys.get("root", repository.root)
         keys["mountpoint"] = keys.get("mountpoint",
                                       repository.getMountpoint())
         keys["cdsltree"] = keys.get("cdsltree", repository.getTreePath())
         keys["cdsltreeshared"] = keys.get("cdsltreeshared",
                                           repository.getSharedTreepath())
         keys["cdsllink"] = keys.get("cdsllink", repository.getLinkPath())
         keys["defaultdir"] = keys.get("defaultdir",
                                       repository.getDefaultDir())
         keys["maxnodeidnum"] = keys.get("maxnodeidnum",
                                         repository.getMaxnodeidnum())
         keys["nodeprefix"] = keys.get("nodeprefix",
                                       repository.getNodePrefix())
         keys["usenodeids"] = keys.get("usenodeids",
                                       repository.getUseNodeids())
         keys["expandstring"] = keys.get("expandstring",
                                         repository.getExpandString())
     return ComoonicsCdslRepository(clusterinfo=clusterInfo, **keys)
コード例 #5
0
    def test_Z_CdslsDelete(self):
        from comoonics.cdsl import cmpbysubdirs
        from comoonics.ComPath import Path
        _cdslsrev=repository.getCdsls()
        _cdslsrev.sort(cmpbysubdirs)
        _cdslsrev.reverse()
        for _cdsl in _cdslsrev:
#            print "- %s\n" %_cdsl.src
            _cdsl.delete(True, True)
            self.assertFalse(_cdsl.exists(), "%s CDSL %s exists although it was removed before." %(_cdsl.type, _cdsl))
            for __cdsl in  repository.getCdsls():
                self.assertTrue(__cdsl.exists(), "The still existant %s cdsl %s does not exist any more." %(__cdsl.type, __cdsl))

from comoonics.cdsl.ComCdslRepository import ComoonicsCdslRepository
import os
#import sys;sys.argv = ['', 'Test.testName']
olddir=os.path.realpath(os.curdir)
os.chdir(setup.tmppath)
setupCluster=setup.SetupCluster()        
repository=ComoonicsCdslRepository(clusterinfo=setupCluster.clusterinfo, root=setup.tmppath, usenodeids="True")  
setupCdsls=setup.SetupCDSLs(repository)
repository.buildInfrastructure(setupCluster.clusterinfo)
setupCdsls.setupCDSLInfrastructure(setup.tmppath, repository, setupCluster.clusterinfo)
if __name__ == "__main__":
    module=setup.MyTestProgram(module=test_Cdsl(methodName='run'))
    if module.result.wasSuccessful():
        setupCdsls.cleanUpInfrastructure(setup.tmppath, repository, setupCluster.clusterinfo)
        setup.cleanup()
    os.chdir(olddir)
    sys.exit(module.result.wasSuccessful())    
コード例 #6
0
 def __init__(self, clusterinfo):
     super(SetupCDSLRepository, self).__init__()
     from comoonics.cdsl.ComCdslRepository import ComoonicsCdslRepository
     from comoonics.ComPath import Path
     import shutil
     os.mkdir(os.path.join(tmppath, "repo2"))
     os.mkdir(os.path.join(tmppath, "repo2/repo3"))
     os.mkdir(os.path.join(tmppath, "repo4"))
     os.mkdir(os.path.join(tmppath, "repo4/repo5"))
     os.mkdir(os.path.join(tmppath, "repo4/repo5/repo6"))
     os.mkdir(os.path.join(tmppath, "repo7"))
     os.mkdir(os.path.join(tmppath, "repo8"))
     # Need for testing migration!!
     os.makedirs(os.path.join(tmppath, "repo7", "var/lib/cdsl"))
     shutil.copyfile(os.path.join(testpath, "cdsl4.xml"), os.path.join(tmppath, "repo7", ComoonicsCdslRepository.default_resources[1]))
     
     wpath=Path()
     wpath.pushd(tmppath)
     self.cdslRepository1 = ComoonicsCdslRepository(clusterinfo=clusterinfo, root=tmppath, usenodeids="True")
     self.cdslRepository2 = ComoonicsCdslRepository(clusterinfo=clusterinfo, root=tmppath, mountpoint="repo2", usenodeids="True")
     self.cdslRepository1.addRepository(self.cdslRepository2)
     self.cdslRepository3 = ComoonicsCdslRepository(clusterinfo=clusterinfo, root=os.path.join(tmppath,"repo2"), mountpoint="repo3", usenodeids="True")
     self.cdslRepository2.addRepository(self.cdslRepository3)
     
     self.cdslRepository4 = ComoonicsCdslRepository(root=tmppath, mountpoint="repo4", usenodeids="True", maxnodeidnum="4")
     self.cdslRepository5 = ComoonicsCdslRepository(root=os.path.join(tmppath, "repo4"), mountpoint="repo5", usenodeids="True", maxnodeidnum="4")
     self.cdslRepository4.addRepository(self.cdslRepository5)
     self.cdslRepository6 = ComoonicsCdslRepository(root=os.path.join(tmppath, "repo4", "repo5"), mountpoint="repo6", usenodeids="True", maxnodeidnum="4")
     self.cdslRepository5.addRepository(self.cdslRepository6)
     
     wpath.popd()