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: |
Ray Milkey | f3aba5f | 2017-01-09 16:47:14 -0800 | [diff] [blame] | 27 | print 'Cannot find jar file artifact at ' + remoteUrl |
Ray Milkey | b46b11b | 2016-11-29 10:35:51 -0800 | [diff] [blame] | 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: |
Ray Milkey | 3ac0079 | 2016-12-01 14:28:15 -0800 | [diff] [blame] | 41 | print 'Size for ' + remoteUrl + ' is wrong local ' + str(localSize) + ' but found remote ' + str(remoteSize) |
Ray Milkey | b46b11b | 2016-11-29 10:35:51 -0800 | [diff] [blame] | 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: |
Ray Milkey | f4eefc4 | 2017-08-29 13:57:13 -0700 | [diff] [blame] | 52 | print 'SHA1 hash is wrong for ' + remoteUrl + ' expected ' + \ |
| 53 | expectedSha1 + ' but found ' + sha1 |
Ray Milkey | b46b11b | 2016-11-29 10:35:51 -0800 | [diff] [blame] | 54 | sys.exit(1) |
| 55 | |
| 56 | def checkArtifactsForComponent(version, name, component, buildRoot, repoRoot): |
| 57 | localArtifactRootPath = buildRoot + '/buck-out/gen/' + component |
| 58 | localArtifactJarPath = localArtifactRootPath + '/lib__' + name + '__output/' + name + '.jar' |
| 59 | localArtifactJavadocPath = localArtifactRootPath + '/' + name + '#javadoc,maven-sources.jar' |
| 60 | localArtifactSourcesPath = localArtifactRootPath + '/' + name + '#maven,src-sources.jar' |
| 61 | |
| 62 | remoteArtifactBaseUrl = repoRoot + '/org/onosproject/' + name + '/' + version + '/' + name + '-' + version |
| 63 | remoteArtifactJarUrl = remoteArtifactBaseUrl + '.jar' |
| 64 | remoteArtifactJavadocUrl = remoteArtifactBaseUrl + '-javadoc.jar' |
| 65 | remoteArtifactSourcesUrl = remoteArtifactBaseUrl + '-sources.jar' |
| 66 | |
| 67 | checkArtifact(localArtifactJarPath, remoteArtifactJarUrl) |
| 68 | checkArtifact(localArtifactJavadocPath, remoteArtifactJavadocUrl) |
| 69 | checkArtifact(localArtifactSourcesPath, remoteArtifactSourcesUrl) |
| 70 | |
| 71 | checkArtifactsForComponent(version, 'onos-api', 'core/api', buildRoot, repoRoot) |
| 72 | checkArtifactsForComponent(version, 'onos-protocols-openflow-api', 'protocols/openflow/api', buildRoot, repoRoot) |
Ray Milkey | f3aba5f | 2017-01-09 16:47:14 -0800 | [diff] [blame] | 73 | checkArtifactsForComponent(version, 'onos-core-serializers', 'core/store/serializers', buildRoot, repoRoot) |
| 74 | checkArtifactsForComponent(version, 'onos-cli', 'cli', buildRoot, repoRoot) |
| 75 | checkArtifactsForComponent(version, 'onos-apps-optical-model', 'apps/optical-model', buildRoot, repoRoot) |
| 76 | |
| 77 | |
| 78 | |
Ray Milkey | b46b11b | 2016-11-29 10:35:51 -0800 | [diff] [blame] | 79 | |