Cleanup patch-export bugs
[armband.git] / patches / fuel-plugin-opendaylight / 0001-arm64-support-for-OpenDaylight-Fuel-Plugin.patch
1 From: Florin Dumitrascu <florin.dumitrascu@enea.com>
2 Date: Thu, 17 Mar 2016 18:15:42 +0100
3 Subject: [PATCH] arm64 support for OpenDaylight Fuel Plugin
4
5 ODL depends on a native library (leveldb).
6 ODL Beryllium version is still using a native x86 version of
7 this library (wrapped in leveldbjni). There is no upstream version
8 of leveldbjni supporting arm64 leveldb, so we need to compile it
9 when deploying ODL. This is done when running odl-install puppet manifest.
10 For more info about this ODL limitation, read here:
11 https://bugs.opendaylight.org/show_bug.cgi?id=3973
12
13 Signed-off-by: Florin Dumitrascu <florin.dumitrascu@enea.com>
14 ---
15  .../modules/opendaylight/files/leveldb-arm64.patch |  35 +++++
16  .../opendaylight/files/leveldbjni-native.patch     |  23 ++++
17  .../puppet/modules/opendaylight/manifests/init.pp  |   8 ++
18  .../modules/opendaylight/manifests/install.pp      |  12 +-
19  .../modules/opendaylight/manifests/leveldbjni.pp   | 150 +++++++++++++++++++++
20  deployment_tasks.yaml                              |   2 +-
21  odl_package/ubuntu/opendaylight                    |   4 +-
22  pre_build_hook                                     |   9 +-
23  8 files changed, 234 insertions(+), 9 deletions(-)
24  create mode 100644 deployment_scripts/puppet/modules/opendaylight/files/leveldb-arm64.patch
25  create mode 100644 deployment_scripts/puppet/modules/opendaylight/files/leveldbjni-native.patch
26  create mode 100644 deployment_scripts/puppet/modules/opendaylight/manifests/leveldbjni.pp
27
28 diff --git a/deployment_scripts/puppet/modules/opendaylight/files/leveldb-arm64.patch b/deployment_scripts/puppet/modules/opendaylight/files/leveldb-arm64.patch
29 new file mode 100644
30 index 0000000..e0824ca
31 --- /dev/null
32 +++ b/deployment_scripts/puppet/modules/opendaylight/files/leveldb-arm64.patch
33 @@ -0,0 +1,35 @@
34 +diff --git a/port/atomic_pointer.h b/port/atomic_pointer.h
35 +index e17bf43..78cb6b3 100644
36 +--- a/port/atomic_pointer.h
37 ++++ b/port/atomic_pointer.h
38 +@@ -36,6 +36,8 @@
39 + #define ARCH_CPU_X86_FAMILY 1
40 + #elif defined(__ARMEL__)
41 + #define ARCH_CPU_ARM_FAMILY 1
42 ++#elif defined(__aarch64__)
43 ++#define ARCH_CPU_ARM64_FAMILY 1
44 + #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
45 + #define ARCH_CPU_PPC_FAMILY 1
46 + #endif
47 +@@ -93,6 +95,13 @@ inline void MemoryBarrier() {
48 + }
49 + #define LEVELDB_HAVE_MEMORY_BARRIER
50 +
51 ++// ARM64
52 ++#elif defined(ARCH_CPU_ARM64_FAMILY)
53 ++inline void MemoryBarrier() {
54 ++ asm volatile("dmb sy" : : : "memory");
55 ++}
56 ++#define LEVELDB_HAVE_MEMORY_BARRIER
57 ++
58 + // PPC
59 + #elif defined(ARCH_CPU_PPC_FAMILY) && defined(__GNUC__)
60 + inline void MemoryBarrier() {
61 +@@ -216,6 +225,7 @@ class AtomicPointer {
62 + #undef LEVELDB_HAVE_MEMORY_BARRIER
63 + #undef ARCH_CPU_X86_FAMILY
64 + #undef ARCH_CPU_ARM_FAMILY
65 ++#undef ARCH_CPU_ARM64_FAMILY
66 + #undef ARCH_CPU_PPC_FAMILY
67 +
68 + }  // namespace port
69 diff --git a/deployment_scripts/puppet/modules/opendaylight/files/leveldbjni-native.patch b/deployment_scripts/puppet/modules/opendaylight/files/leveldbjni-native.patch
70 new file mode 100644
71 index 0000000..08a528b
72 --- /dev/null
73 +++ b/deployment_scripts/puppet/modules/opendaylight/files/leveldbjni-native.patch
74 @@ -0,0 +1,23 @@
75 +diff --git a/leveldbjni-all/pom.xml b/leveldbjni-all/pom.xml
76 +index 426f2a6..c4a2a16 100755
77 +--- a/leveldbjni-all/pom.xml
78 ++++ b/leveldbjni-all/pom.xml
79 +@@ -41,7 +41,7 @@
80 +
81 +   <groupId>org.fusesource.leveldbjni</groupId>
82 +   <artifactId>leveldbjni-all</artifactId>
83 +-  <version>1.8</version>
84 ++  <version>1.8-odl</version>
85 +   <packaging>bundle</packaging>
86 +
87 +   <name>${project.artifactId}</name>
88 +@@ -119,7 +119,8 @@
89 +               META-INF/native/osx/libleveldbjni.jnilib;osname=macosx;processor=x86,
90 +               META-INF/native/osx/libleveldbjni.jnilib;osname=macosx;processor=x86-64,
91 +               META-INF/native/linux32/libleveldbjni.so;osname=Linux;processor=x86,
92 +-              META-INF/native/linux64/libleveldbjni.so;osname=Linux;processor=x86-64
93 ++              META-INF/native/linux64/libleveldbjni.so;osname=Linux;processor=x86-64,
94 ++              META-INF/native/linux64/libleveldbjni.so;osname=Linux;processor=aarch64
95 +             </Bundle-NativeCode>
96 +          </instructions>
97 +         </configuration>
98 diff --git a/deployment_scripts/puppet/modules/opendaylight/manifests/init.pp b/deployment_scripts/puppet/modules/opendaylight/manifests/init.pp
99 index 8dfb213..95b3de7 100644
100 --- a/deployment_scripts/puppet/modules/opendaylight/manifests/init.pp
101 +++ b/deployment_scripts/puppet/modules/opendaylight/manifests/init.pp
102 @@ -8,4 +8,12 @@ class opendaylight {
103    $manager_ip_address = $odl_controller_hash[0]['internal_address']
104    $node_private_address = $node[0]['private_address']
105    $node_internal_address = $node[0]['internal_address']
106 +
107 +  $arch = $::architecture ? {
108 +    'aarch64' => $::osfamily ? {
109 +      'Debian' => 'arm64',
110 +      default  => 'aarch64',
111 +    },
112 +    default => $::architecture,
113 +  }
114  }
115 diff --git a/deployment_scripts/puppet/modules/opendaylight/manifests/install.pp b/deployment_scripts/puppet/modules/opendaylight/manifests/install.pp
116 index 7a3bf3f..f9bba56 100644
117 --- a/deployment_scripts/puppet/modules/opendaylight/manifests/install.pp
118 +++ b/deployment_scripts/puppet/modules/opendaylight/manifests/install.pp
119 @@ -19,6 +19,12 @@ class opendaylight::install (
120      ensure  => installed,
121    }
122  
123 +  if ($::osfamily == 'Debian' and $::opendaylight::arch == 'arm64') {
124 +    class { 'opendaylight::leveldbjni':
125 +      require => Package['opendaylight'],
126 +    }
127 +  }
128 +
129    package {'opnfv-quagga':
130      ensure => installed,
131    }
132 @@ -36,7 +42,8 @@ class opendaylight::install (
133  
134    debug("Set odl rest api port to ${rest_port}")
135  
136 -  file { "${conf_dir}/jetty.xml":
137 +  file { 'jetty.xml':
138 +    path    => "${conf_dir}/jetty.xml",
139      ensure  => file,
140      owner   => 'odl',
141      content => template('opendaylight/jetty.xml.erb')
142 @@ -72,6 +79,7 @@ class opendaylight::install (
143    Package['opendaylight'] ->
144    Ini_setting <||> ->
145    Firewall <||> ->
146 -  File <||> ->
147 +  File['jetty.xml'] ->
148 +  Class['opendaylight::leveldbjni'] ->
149    Service['opendaylight']
150  }
151 diff --git a/deployment_scripts/puppet/modules/opendaylight/manifests/leveldbjni.pp b/deployment_scripts/puppet/modules/opendaylight/manifests/leveldbjni.pp
152 new file mode 100644
153 index 0000000..c599370
154 --- /dev/null
155 +++ b/deployment_scripts/puppet/modules/opendaylight/manifests/leveldbjni.pp
156 @@ -0,0 +1,150 @@
157 +# == Class opendaylight::leveldbjni
158 +#
159 +# Manages compilation of JNI for leveldb.
160 +#
161 +# It compiles the leveldbjni from sources and patches it so that it's properly
162 +# detected by maven on arm64 system.
163 +#
164 +class opendaylight::leveldbjni(
165 +  $target = '/opt/opendaylight',
166 +  $user    = 'odl',
167 +  $branch  = 'leveldbjni-1.8',
168 +) {
169 +  case $::osfamily {
170 +    'Debian', 'Ubuntu': {}
171 +    default: {
172 +      fail('Not supported on OS other than Debian based.')
173 +    }
174 +  }
175 +
176 +  $libsnappy_dir = '/usr/lib'
177 +  $leveldb_dir = "${target}/leveldb"
178 +  $leveldbjni_dir = "${target}/leveldbjni"
179 +  $environment = ["SNAPPY_HOME=${libsnappy_dir}", "LEVELDB_HOME=${leveldb_dir}", "LEVELDBJNI_HOME=${leveldbjni_dir}", "LIBRARY_PATH=${libsnappy_dir}", "C_INCLUDE_PATH=${libsnappy_dir}", "CPLUS_INCLUDE_PATH=${libsnappy_dir}","JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-${::opendaylight::arch}"]
180 +  $parallel_jobs = ($processorcount + 1)/2
181 +
182 +  if ! defined(Package['git']) {
183 +    package { 'git':
184 +      ensure => 'present',
185 +    }
186 +  }
187 +  if ! defined(Package['build-essential']) {
188 +    package { 'build-essential':
189 +      ensure => 'present',
190 +    }
191 +  }
192 +  if ! defined(Package['automake']) {
193 +    package { 'automake':
194 +      ensure => 'present',
195 +    }
196 +  }
197 +  if ! defined(Package['make']) {
198 +    package { 'make':
199 +      ensure => 'present',
200 +    }
201 +  }
202 +  if ! defined(Package['libsnappy-dev']) {
203 +    package { 'libsnappy-dev':
204 +      ensure => 'present',
205 +    }
206 +  }
207 +  if ! defined(Package['patch']) {
208 +    package { 'patch':
209 +      ensure => 'present',
210 +    }
211 +  }
212 +  if ! defined(Package['maven']) {
213 +    package { 'maven':
214 +      ensure => 'present',
215 +    }
216 +  }
217 +  if ! defined(Package['openjdk-7-jdk']) {
218 +    package { 'openjdk-7-jdk':
219 +      ensure => 'present',
220 +    }
221 +  }
222 +
223 +  exec { 'leveldb-fetch':
224 +    path    => ['/usr/bin'],
225 +    command => "git clone git://github.com/chirino/leveldb.git ${leveldb_dir}",
226 +    creates => "${leveldb_dir}/.git",
227 +    user    => $user,
228 +    require => [Package['git']],
229 +  } ->
230 +  exec { 'leveldbjni-fetch':
231 +    path    => ['/usr/bin'],
232 +    command => "git clone https://github.com/fusesource/leveldbjni.git -b ${branch} ${leveldbjni_dir}",
233 +    creates => "${leveldbjni_dir}/.git",
234 +    user    => $user,
235 +    require => [Package['git']],
236 +  } ->
237 +  exec { 'leveldb-merge-google':
238 +    path    => ['/usr/bin', '/bin'],
239 +    command => "git config user.name odl && git config user.email 'o@d.l' && git remote add google https://github.com/google/leveldb.git && git fetch google master && git fetch --tags google && git merge --no-edit v1.18",
240 +    unless  => "git remote | grep google",
241 +    cwd     => $leveldb_dir,
242 +    user    => $user,
243 +    require => [Package['git']],
244 +  } ->
245 +  exec { 'leveldb-patch':
246 +    path    => ['/usr/bin'],
247 +    command => "patch -p1 < ${leveldbjni_dir}/leveldb.patch",
248 +    unless  => "patch -p1 -R -N --dry-run < ${leveldbjni_dir}/leveldb.patch",
249 +    cwd     => $leveldb_dir,
250 +    user    => $user,
251 +    require => [Package['patch']],
252 +  } ->
253 +  file { "${leveldb_dir}/leveldb-arm64.patch":
254 +    ensure => "file",
255 +    source => "puppet:///modules/opendaylight/leveldb-arm64.patch",
256 +    owner  => $user,
257 +  } ->
258 +  exec { 'leveldb-patch-for-arm64':
259 +    path    => ['/usr/bin'],
260 +    command => "patch -p1 < ${leveldb_dir}/leveldb-arm64.patch",
261 +    unless  => "patch -p1 -R -N --dry-run < ${leveldb_dir}/leveldb-arm64.patch",
262 +    cwd     => $leveldb_dir,
263 +    user    => $user,
264 +    require => [Package['patch']],
265 +  } ->
266 +  exec { 'leveldb-build':
267 +    command => "/usr/bin/make libleveldb.a -j${parallel_jobs}",
268 +    creates => "${leveldb_dir}/libleveldb.a",
269 +    environment => $environment,
270 +    cwd     => $leveldb_dir,
271 +    user    => $user,
272 +    require => [Package['git'], Package['make'], Package['build-essential']],
273 +  } ->
274 +  file { "${leveldbjni_dir}/leveldbjni.patch":
275 +    ensure => "file",
276 +    source => "puppet:///modules/opendaylight/leveldbjni-native.patch",
277 +    owner  => $user,
278 +  } ->
279 +  exec { 'leveldbjni-patch':
280 +    path    => ['/usr/bin'],
281 +    command => "patch -p1 < ${leveldbjni_dir}/leveldbjni.patch",
282 +    unless  => "patch -p1 -R -N --dry-run < ${leveldbjni_dir}/leveldbjni.patch",
283 +    cwd     => $leveldbjni_dir,
284 +    user    => $user,
285 +    require => [Package['patch']],
286 +  } ->
287 +  exec { 'leveldbjni-build':
288 +    command     => "/usr/bin/mvn clean install -P download -P linux64 -P all",
289 +    # Creates requires a fully qualified path which we don't have
290 +    unless      => "/usr/bin/test -d ~${user}/.m2/repository/org/fusesource/leveldbjni/leveldbjni-all",
291 +    environment => $environment,
292 +    cwd         => $leveldbjni_dir,
293 +    user        => $user,
294 +    timeout     => 1200,
295 +    require     => [Package['maven']],
296 +  } ->
297 +  # Can't do this with 'file' type because we need to purge existing package
298 +  # and at the same time don't perform the copy if we've already copied our
299 +  # package.
300 +  exec { 'leveldbjni-copy':
301 +    path    => ['/bin'],
302 +    command => "rm -rf ${target}/system/org/fusesource/leveldbjni && cp -r ~${user}/.m2/repository/org/fusesource/leveldbjni $target/system/org/fusesource/",
303 +    creates => "${target}/system/org/fusesource/leveldbjni/leveldbjni-linux64",
304 +    user    => $user,
305 +  }
306 +}
307 diff --git a/deployment_tasks.yaml b/deployment_tasks.yaml
308 index 6588db3..0fe77af 100644
309 --- a/deployment_tasks.yaml
310 +++ b/deployment_tasks.yaml
311 @@ -17,7 +17,7 @@
312    parameters:
313      puppet_manifest: puppet/manifests/odl-install.pp
314      puppet_modules: puppet/modules:/etc/puppet/modules
315 -    timeout: 720
316 +    timeout: 3600
317  - id: netconfig
318    type: skipped
319  - id: odl-netconfig
320 diff --git a/odl_package/ubuntu/opendaylight b/odl_package/ubuntu/opendaylight
321 index c7f5082..6e5ff7b 100644
322 --- a/odl_package/ubuntu/opendaylight
323 +++ b/odl_package/ubuntu/opendaylight
324 @@ -9,7 +9,7 @@ setgid odl
325  setuid odl
326  
327  env KARAF_HOME="/opt/opendaylight"
328 -env JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
329 +env JAVA_HOME="/usr/lib/jvm/java-7-openjdk-arm64"
330  env JAVA_OPTS="-server -Xms256M -Xmx2048M -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass -XX:MaxPermSize=512M -Dcom.sun.management.jmxremote"
331  env OPTS="-Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true"
332  env MAIN="org.apache.karaf.main.Main"
333 @@ -34,6 +34,6 @@ script
334          fi
335      done
336  
337 -    exec /usr/bin/java $JAVA_OPTS -Djava.endorsed.dirs="${JAVA_ENDORSED_DIRS}" -Djava.ext.dirs="${JAVA_EXT_DIRS}" -Dkaraf.instances="${KARAF_HOME}/instances" -Dkaraf.home="$KARAF_HOME" -Dkaraf.base="$KARAF_BASE" -Dkaraf.data="$KARAF_DATA" -Dkaraf.etc="$KARAF_ETC" -Djava.io.tmpdir="$KARAF_DATA/tmp" -Djava.util.logging.config.file="$KARAF_BASE/etc/java.util.logging.properties" $KARAF_OPTS $OPTS -classpath "$CLASSPATH" $MAIN
338 +    exec ${JAVA_HOME}/bin/java $JAVA_OPTS -Djava.endorsed.dirs="${JAVA_ENDORSED_DIRS}" -Djava.ext.dirs="${JAVA_EXT_DIRS}" -Dkaraf.instances="${KARAF_HOME}/instances" -Dkaraf.home="$KARAF_HOME" -Dkaraf.base="$KARAF_BASE" -Dkaraf.data="$KARAF_DATA" -Dkaraf.etc="$KARAF_ETC" -Djava.io.tmpdir="$KARAF_DATA/tmp" -Djava.util.logging.config.file="$KARAF_BASE/etc/java.util.logging.properties" $KARAF_OPTS $OPTS -classpath "$CLASSPATH" $MAIN
339  
340  end script
341 diff --git a/pre_build_hook b/pre_build_hook
342 index db64e80..b2b97b3 100755
343 --- a/pre_build_hook
344 +++ b/pre_build_hook
345 @@ -41,7 +41,7 @@ fi
346  
347  function cleanup {
348    rm -rf "${TMP_DIR}"
349 -  sed -i -e "s/java-8-openjdk-amd64/java-7-openjdk-amd64/" "${DIR}/odl_package/ubuntu/opendaylight"
350 +  sed -i -e "s/java-8-openjdk-arm64/java-7-openjdk-arm64/" "${DIR}/odl_package/ubuntu/opendaylight"
351  }
352  
353  function download {
354 @@ -87,11 +87,12 @@ function build_pkg {
355        ;;
356      ubuntu)
357        pushd "${DIR}/repositories/${1}/"
358 -      fpm --force -s dir -t deb -m 'mskalski@mirantis.com' --version "${ODL_VERSION_NUMBER}" --description "${ODL_DESCRIPTION}" --prefix /opt/opendaylight --deb-upstart "${DIR}/odl_package/${1}/opendaylight" --after-install "${DIR}/odl_package/${1}/opendaylight-post" --name opendaylight -d "${JAVA_VERSION}" -C "${TMP_DIR}/opendaylight_src"
359 +      fpm --force -s dir -t deb -a arm64 -m 'mskalski@mirantis.com' --version "${ODL_VERSION_NUMBER}" --description "${ODL_DESCRIPTION}" --prefix /opt/opendaylight --deb-upstart "${DIR}/odl_package/${1}/opendaylight" --after-install "${DIR}/odl_package/${1}/opendaylight-post" --name opendaylight -d "${JAVA_VERSION}" -C "${TMP_DIR}/opendaylight_src"
360        fpm --force -s python -t deb -m 'mskalski@mirantis.com' --python-install-lib /usr/lib/python2.7/dist-packages ${TMP_DIR}/networking_odl/setup.py
361        download_dependencies ${1}
362        popd
363 -      add_opnfv_quagga "${DIR}/repositories/${1}/"
364 +      # We are adding arm64 opnfv quagga in our local repository
365 +      #add_opnfv_quagga "${DIR}/repositories/${1}/"
366        ;;
367      *) echo "Not supported system"; exit 1;;
368    esac
369 @@ -103,7 +104,7 @@ cleanup
370  
371  if [ "$USE_JAVA8" = true ]
372  then
373 -  sed -i -e "s/java-7-openjdk-amd64/java-8-openjdk-amd64/" "${DIR}/odl_package/ubuntu/opendaylight"
374 +  sed -i -e "s/java-7-openjdk-arm64/java-8-openjdk-arm64/" "${DIR}/odl_package/ubuntu/opendaylight"
375  fi
376  
377  mkdir -p "${TMP_DIR}"