Пример #1
0
def _extractMetadataInfos(manifestRootElement):
    manifestElements = manifestRootElement.findall('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}RDF')
    manifests = []
    infos = []
    for e in manifestElements:
	manifest = ManifestInfo()
	manifest.parseManifestFromXmlTree(e)
	print manifest
	if len(manifest.locations)>0:
	    info = {'md5': manifest.md5, 'os': manifest.os, 'os-version':manifest.osversion,'os-arch':manifest.arch, 'location':manifest.locations[0], 'creator':manifest.creator, 'valid':manifest.valid.replace("T"," "), 'description':manifest.comment, 'publisher':manifest.publisher, 'identifier':manifest.identifier}
	    #parse extra attributes
	    requires = getattr(e.find('.//{%s}requires' % NS_DCTERMS), 'text','')
	    if requires:
		info['requires'] = requires
		# now is assumed that if network and storage info is the same, so system
		# is openstack else is opennebula, this is done only for demo in Technical Forum
		# for future this info should be taked from LDAP info
		if manifest.locations[0] == requires:
		    # if is a OpenStack machine identifier is not more used, because it doesn't publish it
		    # so we use to identify it from another possible machines running in site
		    # i use the template name https://site:port/template
		    pat = re.compile(r'http[s]{0,1}://[a-z].[a-z][a-z\.\-0-9]*:[0-9]+[a-z.0-9/\-]')
		    domain = re.findall(pat,manifest.locations[0])
		    info['identifier'] = manifest.locations[0].replace(domain[0],"").replace("/","")
		    info['cloud'] = "openstack"
		else:
		    info['cloud'] = "opennebula"
		infos.append(info)
    return infos
Пример #2
0
 def _extractManifestInfos(self, manifestRootElement):
     manifestElements = manifestRootElement.findall('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}RDF')
     manifests = []
     for e in manifestElements:
         manifest = ManifestInfo()
         manifest.parseManifestFromXmlTree(e)
         manifests.append(manifest)
     return manifests
Пример #3
0
    def testMissingElements(self):

        info = ManifestInfo()
        info._template = self.template
        self.failUnlessRaises(ExecutionException, info.parseManifest, 
                              ManifestInfoTest.manifestDcMissingElemsMandatory)

        info = ManifestInfo()
        info._template = self.template
        self.failUnlessRaises(ExecutionException, info.parseManifest, 
                              ManifestInfoTest.manifestDcMissingElems)
Пример #4
0
    def testNonEmtpyLocations(self):
        info = ManifestInfo()
        info._template = self.template
        info.locations = ['location.foo']
        manifest = info.tostring()

        dom = etree.fromstring(manifest)
        locations = dom.findall('.//{%s}location' % ManifestInfo.NS_SLTERMS)
        location = getattr(locations[0], 'text', '')

        self.failUnlessEqual('location.foo', location,
                             "Failure in setting location element on ManifestInfo.")
Пример #5
0
    def testListOfManifests(self):
        metadata = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<metadata>
%s
%s
</metadata>
""" % (self.rdfFull1, self.rdfFull2)
        info = ManifestInfo()
        info.parseManifest(metadata)
        
        self.failUnlessEqual(info.publisher, self._publisher1, "Failure in parsing list of manifests.")
        self.failUnlessEqual(info.locations, [self._location1_1, self._location1_2,
                                             self._location2_1, self._location2_2],
                                             "Failure in parsing list of manifests.")
Пример #6
0
    def _registerInvalidImageInMarketplace(self):
        manifest_file = Util.get_resources_file(["manifest-invalid-sha1.xml"])

        manifestInfo = ManifestInfo()
        manifestInfo.parseManifestFromFile(manifest_file)

        image_id = manifestInfo.identifier

        configHolder = ConfigHolder()
        configHolder.set("marketplaceEndpoint", self.marketplaceEndpoint)
        uploader = marketplaceUploader(configHolder)
        uploader.upload(manifest_file)

        return image_id
Пример #7
0
    def testUpdateManifest(self):

        info = ManifestInfo()
        info._template = self.template
        info.parseManifest(ManifestInfoTest.manifestDcFull)

        self.assertEqual('machine', info.type)
        info.type = 'disk'

        xml = info.tostring()
        info = ManifestInfo()
        info.template = self.template
        info.parseManifest(xml)

        self.assertEqual('disk', info.type)
Пример #8
0
    def __getManifest(self, url):
        errorMessage = 'Failed to find metadata entry: %s' % url
        try:
            manifest = self._download(url)
        except urllib2.HTTPError:
            raise InputException(errorMessage)

        if manifest is not None:
            manifestInfo = ManifestInfo(self.configHolder)
        else:
            raise InputException(errorMessage)

        try:
            manifestInfo.parseManifestFromXmlTree(manifest)
        except ExecutionException, ex:
            raise InputException('Error parsing the metadata corresponding to url %s, with detail %s' % (url, ex))
Пример #9
0
 def testTostringWithListOfLocations(self):
     info1 = ManifestInfo()
     info1._template = self.template
     info1.parseManifest(self.rdfFull1)
     manifest = info1.tostring()
     
     info2 = ManifestInfo()
     info2.parseManifest(manifest)
     
     self.failUnlessEqual(info1.locations, info2.locations, 
                          "Lists of locations don't match. Serialization failed.")
Пример #10
0
    def upload(self, manifestFilename):
        client = HttpClient(self.confHolder)
        if not os.path.exists(manifestFilename):
            raise InputException('Can\'t find metadata file: %s' % manifestFilename)

        manifest = open(manifestFilename).read()

        info = ManifestInfo(self.confHolder)
        info.parseManifest(manifest)

        url = MarketplaceUtil.metadataEndpointUrl(self.marketplaceEndpoint)
        try:
            client.post(url, manifest)
        except ClientException, ex:
            error = ''
            try:
                error = etree_from_text(ex.content).text
            except: pass
            raise ExecutionException("Failed to upload: %s: %s" % (ex.reason, error))
Пример #11
0
    def download(self, uri):
        """uri is the full resource uri uniquely identifying a single manifest entry"""
        tempMetadataFilename = tempfile.mktemp()
        ManifestDownloader(self.configHolder).getManifestAsFile(uri, tempMetadataFilename)
        manifestInfo = ManifestInfo(self.configHolder)

        manifestInfo.parseManifestFromFile(tempMetadataFilename)

        tempImageFilename = self._downloadFromLocations(manifestInfo)
        self._verifySignature(tempImageFilename, tempMetadataFilename)

        tempImageFilename = self._inflateImage(tempImageFilename)
        if not os.path.exists(tempImageFilename):
            raise InputException('Failed to find image matching image resource uri: %s' % uri)

        self._verifyHash(tempImageFilename, manifestInfo.sha1)

        shutil.copy2(tempImageFilename, self.localImageFilename)

        os.remove(tempImageFilename)
        os.remove(tempMetadataFilename)

        return self.localImageFilename
Пример #12
0
    def testGenerateManifest(self):
        manifest_info = ManifestInfo()
        manifest_info.parseManifest(self.TEST_MANIFEST)
        ManifestDownloader.getManifestInfo = Mock(return_value=manifest_info)

        PDISK_ENDPOINT = 'pdisk:0.0.0.0:8445'

        TMSaveCache._getAttachedVolumeURIs = Mock(
            return_value=[PDISK_ENDPOINT + ':48ac4190-9a11-4a06-8bef-03fd97080eba'])

        tm = TMSaveCache({TMSaveCache._ARG_SRC_POS: 'foo:/bar/1'},
                         conf_filename=self.conf_filename)
        tm._parseArgs()
        tm._retrieveAttachedVolumeInfo()
        tm.createImageInfo = {VmManager.CREATE_IMAGE_KEY_CREATOR_EMAIL: '*****@*****.**',
                              VmManager.CREATE_IMAGE_KEY_CREATOR_NAME: 'Jay Random',
                              VmManager.CREATE_IMAGE_KEY_NEWIMAGE_COMMENT: 'test',
                              VmManager.CREATE_IMAGE_KEY_NEWIMAGE_VERSION: '0.0',
                              VmManager.CREATE_IMAGE_KEY_NEWIMAGE_MARKETPLACE: 'http://new.markeplace.org'}
        tm.imageSha1 = 'ea7d0ddf7af4e2ea431db89639feb7036fb23062'
        tm.createdPDiskId = 'foo-bar-baz'

        try:
            tm._generateP12Cert()
            self.failUnless(os.path.exists(tm.p12cert))

            tm._generateP12Cert()
            tm._retrieveManifestsPath()
            tm.pdiskPathNew = tm._buildPDiskPath(tm.createdPDiskId)
            tm._buildAndSaveManifest()
            self.failUnless(os.path.exists(tm.manifestNotSignedPath))

            minfo = ManifestInfo()
            minfo.parseManifestFromFile(tm.manifestNotSignedPath)
            assert minfo.comment == 'test'
            assert minfo.creator == 'Jay Random'
            assert minfo.version == '0.0'
            assert minfo.sha1 == tm.imageSha1
            assert minfo.locations == ['pdisk:' + Util.getHostnamePortFromUri(tm.persistentDiskPublicBaseUrl) + ':foo-bar-baz']

            self.failUnless('foo-bar-baz' in str(tm._emailText()))

            if not Signator.findJar():
                print "Skipping signature sub-test as Signator jar can not be found."
                return
            tm._signManifest()
            self.failUnless(os.path.exists(tm.manifestPath))
        finally:
            tm._cleanup()
Пример #13
0
 def _parseManifest(self):
     manifestInfo = ManifestInfo()
     manifestInfo.parseManifestFromFile(self.manifestFile)
Пример #14
0
 def _addLocationToManifest(self):
     ManifestInfo.addElementToManifestFile(self.manifestFile,
                                           'location', self.imageUrl)
Пример #15
0
    def doWork(self):
        self._calculateCheckSums()

        configHolder = ConfigHolder(self.options.__dict__)
        manifest = ManifestInfo(configHolder)
        manifest.buildAndSave()
Пример #16
0
    def testGetInfo(self):
        infoDC = ManifestInfo()
        infoDC.parseManifest(ManifestInfoTest.manifestDcFull)

        self.assertEqual('2011-01-24T09:59:42Z', infoDC.created)
Пример #17
0
 def _addCompressionFormatToManifest(self):
     if self.compressionFormat.lower() != 'none':
         ManifestInfo.addElementToManifestFile(self.manifestFile,
                                               'compression', self.compressionFormat)
     else:
         Util.printWarning("'none' specified for compression; manifest compression element NOT updated")