Ray Milkey | b46b11b | 2016-11-29 10:35:51 -0800 | [diff] [blame^] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | # Spot checks some published artifacts to be sure that they uploaded correctly |
| 4 | # to the release repository |
| 5 | |
| 6 | import requests |
| 7 | import sys |
| 8 | import sha |
| 9 | import os |
| 10 | |
| 11 | |
| 12 | from requests.auth import HTTPBasicAuth |
| 13 | |
| 14 | if len(sys.argv) != 4: |
| 15 | print "usage: check-uploaded-maven-artifact version buildRoot repoRoot" |
| 16 | sys.exit(1) |
| 17 | |
| 18 | version = sys.argv[1] |
| 19 | buildRoot = sys.argv[2] |
| 20 | repoRoot = sys.argv[3] |
| 21 | |
| 22 | def checkArtifact(localPath, remoteUrl): |
| 23 | |
| 24 | repoResponse = requests.head(remoteUrl) |
| 25 | |
| 26 | if repoResponse.status_code != 200: |
| 27 | print 'Cannot find jar file artifact' |
| 28 | print repoResponse.text |
| 29 | sys.exit(1) |
| 30 | |
| 31 | remoteSize = int(repoResponse.headers['content-length']) |
| 32 | etag = repoResponse.headers['etag'] |
| 33 | |
| 34 | localSize = os.path.getsize(localPath) |
| 35 | |
| 36 | localArtifact = open(localPath) |
| 37 | localArtifactSha = sha.new(localArtifact.read()) |
| 38 | expectedSha1 = localArtifactSha.hexdigest() |
| 39 | |
| 40 | if localSize != remoteSize: |
| 41 | print 'Size is wrong local ' + str(localSize) + ' but found remote ' + str(remoteSize) |
| 42 | sys.exit(1) |
| 43 | |
| 44 | sha1 = '' |
| 45 | if '{SHA1{' in etag: |
| 46 | # this is a sonatype style artifact |
| 47 | sha1 = etag[7:len(etag)-3] |
| 48 | else: |
| 49 | sha1 = repoResponse.headers['x-checksum-sha1'] |
| 50 | |
| 51 | if sha1 != expectedSha1: |
| 52 | print 'SHA1 hash is wrong expected ' + expectedSha1 + ' but found ' + sha1 |
| 53 | sys.exit(1) |
| 54 | |
| 55 | def checkArtifactsForComponent(version, name, component, buildRoot, repoRoot): |
| 56 | localArtifactRootPath = buildRoot + '/buck-out/gen/' + component |
| 57 | localArtifactJarPath = localArtifactRootPath + '/lib__' + name + '__output/' + name + '.jar' |
| 58 | localArtifactJavadocPath = localArtifactRootPath + '/' + name + '#javadoc,maven-sources.jar' |
| 59 | localArtifactSourcesPath = localArtifactRootPath + '/' + name + '#maven,src-sources.jar' |
| 60 | |
| 61 | remoteArtifactBaseUrl = repoRoot + '/org/onosproject/' + name + '/' + version + '/' + name + '-' + version |
| 62 | remoteArtifactJarUrl = remoteArtifactBaseUrl + '.jar' |
| 63 | remoteArtifactJavadocUrl = remoteArtifactBaseUrl + '-javadoc.jar' |
| 64 | remoteArtifactSourcesUrl = remoteArtifactBaseUrl + '-sources.jar' |
| 65 | |
| 66 | checkArtifact(localArtifactJarPath, remoteArtifactJarUrl) |
| 67 | checkArtifact(localArtifactJavadocPath, remoteArtifactJavadocUrl) |
| 68 | checkArtifact(localArtifactSourcesPath, remoteArtifactSourcesUrl) |
| 69 | |
| 70 | checkArtifactsForComponent(version, 'onos-api', 'core/api', buildRoot, repoRoot) |
| 71 | checkArtifactsForComponent(version, 'onos-protocols-openflow-api', 'protocols/openflow/api', buildRoot, repoRoot) |
| 72 | checkArtifactsForComponent(version, 'onos-drivers-ciena', 'drivers/ciena', buildRoot, repoRoot) |
| 73 | checkArtifactsForComponent(version, 'onos-providers-lldp', 'providers/lldp', buildRoot, repoRoot) |
| 74 | checkArtifactsForComponent(version, 'onos-apps-bgprouter', 'apps/bgprouter', buildRoot, repoRoot) |
| 75 | |