Committed by
Gerrit Code Review
ONOS-4344 Fixes to onos_stage.py to fix Buck onos-package
Change-Id: I807a3cf66f15c60adb5790bdb54d4b68ea7f953d
Showing
3 changed files
with
67 additions
and
49 deletions
... | @@ -2,56 +2,70 @@ | ... | @@ -2,56 +2,70 @@ |
2 | #FIXME Add license | 2 | #FIXME Add license |
3 | 3 | ||
4 | import re | 4 | import re |
5 | +import os | ||
5 | from zipfile import ZipFile | 6 | from zipfile import ZipFile |
7 | +from tarfile import TarFile, TarInfo | ||
8 | +from cStringIO import StringIO | ||
9 | + | ||
10 | +VERSION = '1.6.0' #FIXME version, and maybe git commit hash | ||
11 | +BASE = 'onos-%s/' % VERSION | ||
12 | + | ||
13 | + | ||
14 | +written_files = set() | ||
15 | + | ||
16 | +def addFile(tar, dest, file, file_size): | ||
17 | + if dest not in written_files: | ||
18 | + info = TarInfo(dest) | ||
19 | + info.size = file_size | ||
20 | + tar.addfile(info, fileobj=file) | ||
21 | + written_files.add(dest) | ||
22 | + | ||
23 | +def addString(tar, dest, string): | ||
24 | + if dest not in written_files: | ||
25 | + print dest, string | ||
26 | + info = TarInfo(dest) | ||
27 | + info.size = len(string) | ||
28 | + file = StringIO(string) | ||
29 | + tar.addfile(info, fileobj=file) | ||
30 | + file.close() | ||
31 | + written_files.add(dest) | ||
6 | 32 | ||
7 | def stageOnos(output, files=[]): | 33 | def stageOnos(output, files=[]): |
8 | # Note this is not a compressed zip | 34 | # Note this is not a compressed zip |
9 | - with ZipFile(output, 'a') as output: | 35 | + with TarFile(output, 'a') as output: |
10 | - written_files = set(output.namelist()) | 36 | + written_files = set(output.getnames()) |
11 | for file in files: | 37 | for file in files: |
12 | if '.zip' in file: | 38 | if '.zip' in file: |
13 | with ZipFile(file, 'r') as zip_part: | 39 | with ZipFile(file, 'r') as zip_part: |
14 | - for f in zip_part.namelist(): | 40 | + for f in zip_part.infolist(): |
15 | - dest = 'apache-karaf-3.0.5/system/' + f | 41 | + dest = BASE + 'apache-karaf-3.0.5/system/' + f.filename |
16 | - if dest not in written_files: | 42 | + addFile(output, dest, zip_part.open(f), f.file_size) |
17 | - output.writestr(dest, zip_part.open(f).read()) | ||
18 | - written_files.add(dest) | ||
19 | elif '.oar' in file: | 43 | elif '.oar' in file: |
20 | with ZipFile(file, 'r') as oar: | 44 | with ZipFile(file, 'r') as oar: |
21 | app_xml = oar.open('app.xml').read() | 45 | app_xml = oar.open('app.xml').read() |
22 | app_name = re.search('name="([^"]+)"', app_xml).group(1) | 46 | app_name = re.search('name="([^"]+)"', app_xml).group(1) |
23 | - dest = 'apps/%(name)s/%(name)s.oar' % { 'name': app_name} | 47 | + dest = BASE + 'apps/%(name)s/%(name)s.oar' % { 'name': app_name} |
24 | - output.write(file, dest) | 48 | + addFile(output, dest, open(file), os.stat(file).st_size) |
25 | - dest = 'apps/%s/app.xml' % app_name | 49 | + dest = BASE + 'apps/%s/app.xml' % app_name |
26 | - output.writestr(dest, app_xml) | 50 | + addString(output, dest, app_xml) |
27 | - for f in oar.namelist(): | 51 | + for f in oar.infolist(): |
28 | - if 'm2' in f: | 52 | + filename = f.filename |
29 | - dest = 'apache-karaf-3.0.5/system/' + f[3:] | 53 | + if 'm2' in filename: |
54 | + dest = BASE + 'apache-karaf-3.0.5/system/' + filename[3:] | ||
30 | if dest not in written_files: | 55 | if dest not in written_files: |
31 | - output.writestr(dest, oar.open(f).read()) | 56 | + addFile(output, dest, oar.open(f), f.file_size) |
32 | written_files.add(dest) | 57 | written_files.add(dest) |
33 | elif 'features.xml' in file: | 58 | elif 'features.xml' in file: |
34 | - dest = 'apache-karaf-3.0.5/system/org/onosproject/onos-features/1.6.0-SNAPSHOT/' | 59 | + dest = BASE + 'apache-karaf-3.0.5/system/org/onosproject/onos-features/1.6.0-SNAPSHOT/' |
35 | dest += 'onos-features-1.6.0-SNAPSHOT-features.xml' | 60 | dest += 'onos-features-1.6.0-SNAPSHOT-features.xml' |
36 | with open(file) as f: | 61 | with open(file) as f: |
37 | - output.writestr(dest, f.read()) | 62 | + addFile(output, dest, f, os.stat(file).st_size) |
38 | - # filename = file.split('/')[-1] | 63 | + # FIXME figure out "active" apps |
39 | - # if mvnCoords == 'APP': | 64 | + addString(output, BASE + 'apps/org.onosproject.drivers/active', '') |
40 | - # dest = filename | 65 | + addString(output, BASE + 'apps/org.onosproject.openflow-base/active', '') |
41 | - # else: | 66 | + addString(output, BASE + 'apps/org.onosproject.lldp/active', '') |
42 | - # groupId, artifactId, version = mvnCoords.split(':') | 67 | + addString(output, BASE + 'apps/org.onosproject.host/active', '') |
43 | - # groupId = groupId.replace('.', '/') | 68 | + addString(output, BASE + 'VERSION', VERSION) |
44 | - # extension = filename.split('.')[-1] | ||
45 | - # if extension == 'jar': | ||
46 | - # filename = '%s-%s.jar' % ( artifactId, version ) | ||
47 | - # elif 'features.xml' in filename: | ||
48 | - # filename = '%s-%s-features.xml' % ( artifactId, version ) | ||
49 | - # dest = 'system/%s/%s/%s/%s' % ( groupId, artifactId, version, filename ) | ||
50 | - # zip.write(file, dest) | ||
51 | - output.writestr('apps/org.onosproject.drivers/active', '') | ||
52 | - output.writestr('apps/org.onosproject.openflow-base/active', '') | ||
53 | - output.writestr('apps/org.onosproject.lldp/active', '') | ||
54 | - output.writestr('apps/org.onosproject.host/active', '') | ||
55 | 69 | ||
56 | if __name__ == '__main__': | 70 | if __name__ == '__main__': |
57 | import sys | 71 | import sys |
... | @@ -63,9 +77,4 @@ if __name__ == '__main__': | ... | @@ -63,9 +77,4 @@ if __name__ == '__main__': |
63 | output = sys.argv[1] | 77 | output = sys.argv[1] |
64 | args = sys.argv[2:] | 78 | args = sys.argv[2:] |
65 | 79 | ||
66 | - # if len(args) % 2 != 0: | ||
67 | - # print 'There must be an even number of args: file mvn_coords' | ||
68 | - # sys.exit(2) | ||
69 | - | ||
70 | - #files = zip(*[iter(args)]*2) | ||
71 | stageOnos(output, args) | 80 | stageOnos(output, args) | ... | ... |
... | @@ -99,7 +99,7 @@ sources += staged_repos + staged_apps | ... | @@ -99,7 +99,7 @@ sources += staged_repos + staged_apps |
99 | 99 | ||
100 | genrule( | 100 | genrule( |
101 | name = 'onos-package', | 101 | name = 'onos-package', |
102 | - out = 'onos.zip', | 102 | + out = 'onos.tar.gz', |
103 | bash = 'cp $(location :onos-karaf) $OUT && $(exe //buck-tools:onos-stage) $OUT ' + ' '.join(sources), | 103 | bash = 'cp $(location :onos-karaf) $OUT && $(exe //buck-tools:onos-stage) $OUT ' + ' '.join(sources), |
104 | visibility = [ 'PUBLIC' ], | 104 | visibility = [ 'PUBLIC' ], |
105 | ) | 105 | ) |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -9,6 +9,10 @@ OUT=$1 | ... | @@ -9,6 +9,10 @@ OUT=$1 |
9 | KARAF_TAR=$2 | 9 | KARAF_TAR=$2 |
10 | ONOS_VERSION=$3 | 10 | ONOS_VERSION=$3 |
11 | BRANDING=$4 | 11 | BRANDING=$4 |
12 | +#FIXME karaf version | ||
13 | +KARAF_VERSION="3.0.5" | ||
14 | + | ||
15 | +PREFIX="onos-1.6.0" | ||
12 | 16 | ||
13 | # Unroll the Apache Karaf bits, prune them and make ONOS top-level directories. | 17 | # Unroll the Apache Karaf bits, prune them and make ONOS top-level directories. |
14 | tar xf $KARAF_TAR | 18 | tar xf $KARAF_TAR |
... | @@ -27,27 +31,32 @@ sed -i '' "s/apache-karaf-\$KARAF_VERSION/$KARAF_DIR/g" bin/onos-client | ... | @@ -27,27 +31,32 @@ sed -i '' "s/apache-karaf-\$KARAF_VERSION/$KARAF_DIR/g" bin/onos-client |
27 | mv bin/onos-client bin/onos | 31 | mv bin/onos-client bin/onos |
28 | chmod a+x bin/onos-service bin/onos | 32 | chmod a+x bin/onos-service bin/onos |
29 | 33 | ||
30 | -# Stage the ONOS admin scripts and patch in Karaf service wrapper extras | 34 | +export BOOT_FEATURES="standard,ssh,scr,war,webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui" |
31 | -cp -r bin $KARAF_DIR | ||
32 | -cp -r init $KARAF_DIR | ||
33 | -cp -r etc $KARAF_DIR | ||
34 | - | ||
35 | -export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui" | ||
36 | #FIXME | 35 | #FIXME |
37 | #[ "$ONOS_SECURITY_MODE" = true ] && enable_security_mode | 36 | #[ "$ONOS_SECURITY_MODE" = true ] && enable_security_mode |
38 | 37 | ||
39 | # Patch the Apache Karaf distribution file to add ONOS features repository | 38 | # Patch the Apache Karaf distribution file to add ONOS features repository |
40 | -perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_VERSION/xml/features|" \ | 39 | +perl -pi.old -e "s|^(featuresRepositories=).*|\1mvn:org.apache.karaf.features/standard/$KARAF_VERSION/xml/features,mvn:org.onosproject/onos-features/$ONOS_VERSION/xml/features|" \ |
41 | $KARAF_DIR/etc/org.apache.karaf.features.cfg | 40 | $KARAF_DIR/etc/org.apache.karaf.features.cfg |
42 | 41 | ||
43 | # Patch the Apache Karaf distribution file to load default ONOS boot features | 42 | # Patch the Apache Karaf distribution file to load default ONOS boot features |
44 | -perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \ | 43 | +perl -pi.old -e "s|^(featuresBoot=).*|\1$BOOT_FEATURES|" \ |
45 | $KARAF_DIR/etc/org.apache.karaf.features.cfg | 44 | $KARAF_DIR/etc/org.apache.karaf.features.cfg |
46 | 45 | ||
46 | + | ||
47 | # Patch the Apache Karaf distribution with ONOS branding bundle | 47 | # Patch the Apache Karaf distribution with ONOS branding bundle |
48 | cp $BRANDING $KARAF_DIR/lib | 48 | cp $BRANDING $KARAF_DIR/lib |
49 | 49 | ||
50 | -zip -q -0 -r $OUT $KARAF_DIR | 50 | +# **** Moving karaf to subdirectory **** |
51 | +mkdir $PREFIX | ||
52 | +mv $KARAF_DIR $PREFIX | ||
53 | + | ||
54 | +# Stage the ONOS admin scripts and patch in Karaf service wrapper extras | ||
55 | +cp -r bin $PREFIX | ||
56 | +cp -r init $PREFIX | ||
57 | +cp -r etc $PREFIX/$KARAF_DIR/etc/ | ||
58 | + | ||
59 | +tar czf $OUT $PREFIX | ||
51 | 60 | ||
52 | #FIXME | 61 | #FIXME |
53 | # Stage all builtin ONOS apps for factory install | 62 | # Stage all builtin ONOS apps for factory install | ... | ... |
-
Please register or login to post a comment