From 9141616fe65820a6c19b0f5a71003f0e59d75e59 Mon Sep 17 00:00:00 2001 From: Svetoslav Neykov Date: Tue, 10 May 2016 13:20:27 +0300 Subject: [PATCH] Fix installed files permissions, add packaging tests Also use maven dependency mechanism for using cross-module files. --- deb-packaging/pom.xml | 69 ++++- pom.xml | 1 + rpm-packaging/pom.xml | 73 +++-- shared-packaging/pom.xml | 44 +++ .../src/main/resources}/conf/brooklyn.conf | 0 .../src/main/resources}/conf/logback.xml | 0 .../service/systemd/brooklyn.service | 0 .../service/upstart/deb/brooklyn.conf | 2 +- .../service/upstart/rpm/brooklyn.conf | 3 +- .../src/test/yaml/package-apps.yaml | 103 +++++++ shared-packaging/src/test/yaml/package.bom | 273 ++++++++++++++++++ 11 files changed, 535 insertions(+), 33 deletions(-) create mode 100644 shared-packaging/pom.xml rename {src => shared-packaging/src/main/resources}/conf/brooklyn.conf (100%) rename {src => shared-packaging/src/main/resources}/conf/logback.xml (100%) rename {src => shared-packaging/src/main/resources}/service/systemd/brooklyn.service (100%) rename {src => shared-packaging/src/main/resources}/service/upstart/deb/brooklyn.conf (99%) rename {src => shared-packaging/src/main/resources}/service/upstart/rpm/brooklyn.conf (94%) create mode 100644 shared-packaging/src/test/yaml/package-apps.yaml create mode 100644 shared-packaging/src/test/yaml/package.bom diff --git a/deb-packaging/pom.xml b/deb-packaging/pom.xml index fea43b66d8..c96a8fd88c 100644 --- a/deb-packaging/pom.xml +++ b/deb-packaging/pom.xml @@ -20,6 +20,7 @@ 4.0.0 deb-packaging + pom Brooklyn DEB Package Brooklyn DEB Package for Debian and Ubuntu operating systems @@ -38,9 +39,46 @@ brooklyn-dist ${project.version} + + org.apache.brooklyn + shared-packaging + ${project.version} + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack + package + + unpack + + + + + org.apache.brooklyn + brooklyn-dist + ${project.version} + dist + tar.gz + ${project.build.directory}/deps + + + org.apache.brooklyn + shared-packaging + ${project.version} + jar + ${project.build.directory}/deps/shared-packaging + + + + + + jdeb org.vafer @@ -52,36 +90,38 @@ jdeb - true + false + false ${project.build.directory}/apache-brooklyn_${project.version}_all.deb ${basedir}/deb/control - ../dist/target/brooklyn-dist + ${project.build.directory}/deps/brooklyn-dist-${project.version} directory perm - /opt + /opt/brooklyn brooklyn brooklyn - ../src/service/upstart/deb/brooklyn.conf + ${project.build.directory}/deps/shared-packaging/service/upstart/deb/brooklyn.conf file perm /etc/init - 755 + 644 - ../src/service/systemd/brooklyn.service + + ${project.build.directory}/deps/shared-packaging/service/systemd/brooklyn.service file perm /etc/systemd/system/multi-user.target.wants - 755 + 644 @@ -89,16 +129,27 @@ etc/brooklyn var/lib/brooklyn + + + perm + brooklyn + brooklyn + + + + template + var/log/brooklyn perm brooklyn brooklyn + 700 - ../src/conf/brooklyn.conf + ${project.build.directory}/deps/shared-packaging/conf/brooklyn.conf file true @@ -110,7 +161,7 @@ - ../src/conf/logback.xml + ${project.build.directory}/deps/shared-packaging/conf/logback.xml file true diff --git a/pom.xml b/pom.xml index bd8bc94ada..74b5564602 100644 --- a/pom.xml +++ b/pom.xml @@ -121,6 +121,7 @@ dist vagrant archetypes/quickstart + shared-packaging diff --git a/rpm-packaging/pom.xml b/rpm-packaging/pom.xml index 02d2cf6eca..eba5163acd 100644 --- a/rpm-packaging/pom.xml +++ b/rpm-packaging/pom.xml @@ -39,9 +39,46 @@ brooklyn-dist ${project.version} + + org.apache.brooklyn + shared-packaging + ${project.version} + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack + package + + unpack + + + + + org.apache.brooklyn + brooklyn-dist + ${project.version} + dist + tar.gz + ${project.build.directory}/deps + + + org.apache.brooklyn + shared-packaging + ${project.version} + jar + ${project.build.directory}/deps/shared-packaging + + + + + + org.codehaus.mojo rpm-maven-plugin @@ -67,15 +104,14 @@ _binaries_in_noarch_packages_terminate_build 0 + 755 + 644 + brooklyn + brooklyn /etc/brooklyn true - - - ../src/conf - - /etc/brooklyn @@ -85,39 +121,30 @@ brooklyn - ../src/conf/brooklyn.conf + ${project.build.directory}/deps/shared-packaging/conf/brooklyn.conf /etc/brooklyn true - 644 - brooklyn - brooklyn - ../src/conf/logback.xml + ${project.build.directory}/deps/shared-packaging/conf/logback.xml /opt/brooklyn - 755 - brooklyn - brooklyn - ../dist/target/brooklyn-dist/brooklyn + ${project.build.directory}/deps/brooklyn-dist-${project.version} /var/lib/brooklyn true - 755 - brooklyn - brooklyn /var/log/brooklyn @@ -128,23 +155,25 @@ /etc/systemd/system/multi-user.target.wants - 755 + false + 644 root root - ../src/service/systemd + ${project.build.directory}/deps/shared-packaging/service/systemd - /etc/init/ - 755 + /etc/init + false + 644 root root - ../src/service/upstart/rpm/ + ${project.build.directory}/deps/shared-packaging/service/upstart/rpm/ diff --git a/shared-packaging/pom.xml b/shared-packaging/pom.xml new file mode 100644 index 0000000000..8e00f6e38d --- /dev/null +++ b/shared-packaging/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + shared-packaging + jar + Brooklyn Shared Package Files + + Brooklyn shared files for creating RPM and DEB packages + + + + org.apache.brooklyn + brooklyn-dist-root + 0.10.0-SNAPSHOT + ../pom.xml + + + + + + org.testng + testng + test + + + diff --git a/src/conf/brooklyn.conf b/shared-packaging/src/main/resources/conf/brooklyn.conf similarity index 100% rename from src/conf/brooklyn.conf rename to shared-packaging/src/main/resources/conf/brooklyn.conf diff --git a/src/conf/logback.xml b/shared-packaging/src/main/resources/conf/logback.xml similarity index 100% rename from src/conf/logback.xml rename to shared-packaging/src/main/resources/conf/logback.xml diff --git a/src/service/systemd/brooklyn.service b/shared-packaging/src/main/resources/service/systemd/brooklyn.service similarity index 100% rename from src/service/systemd/brooklyn.service rename to shared-packaging/src/main/resources/service/systemd/brooklyn.service diff --git a/src/service/upstart/deb/brooklyn.conf b/shared-packaging/src/main/resources/service/upstart/deb/brooklyn.conf similarity index 99% rename from src/service/upstart/deb/brooklyn.conf rename to shared-packaging/src/main/resources/service/upstart/deb/brooklyn.conf index fc7be9e1e9..63c454e742 100644 --- a/src/service/upstart/deb/brooklyn.conf +++ b/shared-packaging/src/main/resources/service/upstart/deb/brooklyn.conf @@ -26,7 +26,7 @@ respawn limit 5 10 setuid brooklyn setgid brooklyn -console output +console log pre-start script logger -i -t "$UPSTART_JOB" "[`date -u +%Y-%m-%dT%T.%3NZ`] Starting Apache Brooklyn" diff --git a/src/service/upstart/rpm/brooklyn.conf b/shared-packaging/src/main/resources/service/upstart/rpm/brooklyn.conf similarity index 94% rename from src/service/upstart/rpm/brooklyn.conf rename to shared-packaging/src/main/resources/service/upstart/rpm/brooklyn.conf index e9c5e207f7..77beb54479 100644 --- a/src/service/upstart/rpm/brooklyn.conf +++ b/shared-packaging/src/main/resources/service/upstart/rpm/brooklyn.conf @@ -18,7 +18,7 @@ description "Apache Brooklyn upstart script" author "Aleksandr Vasilev aleksandr.vasilev@cloudsoftcorp.com" -start on started networking +start on runlevel [23] stop on runlevel [016] respawn respawn limit 5 10 @@ -34,6 +34,7 @@ script JAVA_OPTS="-Dbrooklyn.location.localhost.address=127.0.0.1 -Dlogback.configurationFile=/etc/brooklyn/logback.xml -Xms256m -Xmx1g -XX:MaxPermSize=256m" CLASSPATH="/opt/brooklyn/conf:/opt/brooklyn/lib/patch/*:/opt/brooklyn/lib/brooklyn/*:/opt/brooklyn/lib/dropins/*" export BROOKLYN_HOME + # Upstart is too old on CentOS 6, at least v1.4 required to use setuid, setgid. chsh -s /bin/bash brooklyn exec su -c "java ${JAVA_OPTS} -cp $CLASSPATH org.apache.brooklyn.cli.Main launch --noGlobalBrooklynProperties --localBrooklynProperties /etc/brooklyn/brooklyn.conf --persist auto" brooklyn end script diff --git a/shared-packaging/src/test/yaml/package-apps.yaml b/shared-packaging/src/test/yaml/package-apps.yaml new file mode 100644 index 0000000000..5009e56822 --- /dev/null +++ b/shared-packaging/src/test/yaml/package-apps.yaml @@ -0,0 +1,103 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +services: +- type: test-apt-systemd-brooklyn + name: 1. apt-systemd + location: + byon: + hosts: ["172.28.128.3"] + # privateKeyFile: ~/.ssh/ + user: vagrant + brooklyn.config: + files.preinstall: + ~/.m2/repository/org/apache/brooklyn/deb-packaging/0.10.0-SNAPSHOT/deb-packaging-0.10.0-SNAPSHOT.deb: brooklyn-package.deb # BROOKLYN_VERSION + +--- + +services: +- type: test-apt-upstart-brooklyn + name: 2. apt-upstart + location: + byon: + hosts: ["172.28.128.4"] + # privateKeyFile: ~/.ssh/ + user: vagrant + brooklyn.config: + files.preinstall: + ~/.m2/repository/org/apache/brooklyn/deb-packaging/0.10.0-SNAPSHOT/deb-packaging-0.10.0-SNAPSHOT.deb: brooklyn-package.deb # BROOKLYN_VERSION + +--- + +services: +- type: test-yum-systemd-brooklyn + name: 3. yum-systemd + location: + byon: + hosts: ["172.28.128.5"] + # privateKeyFile: ~/.ssh/ + user: vagrant + brooklyn.config: + files.preinstall: + ~/.m2/repository/org/apache/brooklyn/rpm-packaging/0.10.0-SNAPSHOT/rpm-packaging-0.10.0-SNAPSHOT.rpm: brooklyn-package.rpm # BROOKLYN_VERSION + +--- + +services: +- type: test-yum-upstart-brooklyn + name: 4. yum-upstart + location: + byon: + hosts: ["172.28.128.6"] + # privateKeyFile: ~/.ssh/ + user: vagrant + brooklyn.config: + files.preinstall: + ~/.m2/repository/org/apache/brooklyn/rpm-packaging/0.10.0-SNAPSHOT/rpm-packaging-0.10.0-SNAPSHOT.rpm: brooklyn-package.rpm # BROOKLYN_VERSION + + +--- + +# Vagrantfile +Vagrant.configure(2) do |config| + config.vm.provider "virtualbox" do |vb| + vb.memory = "1024" + vb.customize ["modifyvm", :id, "--nictype1", "virtio"] + vb.customize ["modifyvm", :id, "--nictype2", "virtio"] + end + config.vm.provision "shell", privileged: false, inline: <<-SHELL + echo "" >> ~/.ssh/authorized_keys + SHELL + + config.vm.define "apt-systemd" do |config| + config.vm.box = "ubuntu/wily64" + config.vm.network "private_network", ip: "172.28.128.3" + end + config.vm.define "apt-upstart" do |config| + config.vm.box = "ubuntu/trusty64" + config.vm.network "private_network", ip: "172.28.128.4" + end + config.vm.define "yum-systemd" do |config| + config.vm.box = "centos/7" + config.vm.network "private_network", ip: "172.28.128.5" + end + config.vm.define "yum-upstart" do |config| + config.vm.box = "nrel/CentOS-6.5-x86_64" + config.vm.network "private_network", ip: "172.28.128.6" + end +end diff --git a/shared-packaging/src/test/yaml/package.bom b/shared-packaging/src/test/yaml/package.bom new file mode 100644 index 0000000000..7c951cf797 --- /dev/null +++ b/shared-packaging/src/test/yaml/package.bom @@ -0,0 +1,273 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +brooklyn.catalog: + version: 0.10.0-SNAPSHOT # BROOKLYN_VERSION +### brooklyn install entities ### + apt-config: &apt-config + install.command: | + sudo apt-get update + sudo apt-get install -y default-jre-headless + sudo dpkg -i brooklyn-package.deb + yum-config: &yum-config + install.command: | + if sudo iptables -L | grep REJECT; then + # Only for CentOS 6 + sudo iptables -I INPUT -p tcp -m tcp --dport 8081 -j ACCEPT + sudo service iptables save + fi + sudo yum -y install java-1.7.0-openjdk.x86_64 + sudo yum -y install brooklyn-package.rpm + items: + - id: systemd-brooklyn + item: + type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess + brooklyn.config: + launch.command: | + sudo systemctl start brooklyn + checkRunning.command: | + sudo systemctl status brooklyn + stop.command: | + sudo systemctl stop brooklyn + - id: upstart-brooklyn + item: + type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess + brooklyn.config: + launch.command: | + sudo status brooklyn | grep running || sudo start brooklyn + checkRunning.command: | + sudo status brooklyn | grep running + stop.command: | + sudo stop brooklyn + - id: apt-systemd-brooklyn + item: + type: systemd-brooklyn + id: brooklyn + brooklyn.config: *apt-config + - id: apt-upstart-brooklyn + item: + type: upstart-brooklyn + id: brooklyn + brooklyn.config: *apt-config + - id: yum-systemd-brooklyn + item: + type: systemd-brooklyn + id: brooklyn + brooklyn.config: *yum-config + - id: yum-upstart-brooklyn + item: + type: upstart-brooklyn + id: brooklyn + brooklyn.config: *yum-config +### Tests ### + - id: test-is-up + item: + type: org.apache.brooklyn.test.framework.TestSensor + name: Check server is up + sensor: service.isUp + assert: + - equals: true + - id: test-is-not-up + item: + type: org.apache.brooklyn.test.framework.TestSensor + name: Check server is up + sensor: service.isUp + assert: + - equals: false + - id: test-process-running + item: + type: org.apache.brooklyn.test.framework.SimpleShellCommandTest + name: Check process has started + # The brackets prevent grep from matching its own process + command: ps ax | grep "[o]rg.apache.brooklyn.cli.Main" + assertStatus: + equals: 0 + assertOut: + isEmpty: false + assertErr: + isEmpty: true + - id: test-process-not-running + item: + type: org.apache.brooklyn.test.framework.SimpleShellCommandTest + name: Check process is not started + # The brackets prevent grep from matching its own process + command: ps ax | grep "[o]rg.apache.brooklyn.cli.Main" + assertStatus: + equals: 1 + assertOut: + isEmpty: true + assertErr: + isEmpty: true + - id: test-process-user + item: + type: org.apache.brooklyn.test.framework.SimpleShellCommandTest + name: Check user the process is running under + # The brackets prevent grep from matching its own process + command: ps -fu brooklyn | grep "[o]rg.apache.brooklyn.cli.Main" + assertStatus: + equals: 0 + assertOut: + isEmpty: false + assertErr: + isEmpty: true + - id: test-port-reachable + item: + type: org.apache.brooklyn.test.framework.TestHttpCall + name: Check HTTP Response Status Code + url: + $brooklyn:formatString: + - "http://%s:8081/" + - $brooklyn:entity("brooklyn").attributeWhenReady("host.address") + applyAssertionTo: status + assert: + - isEqualTo: 401 + - id: test-path-permissions + item: + type: org.apache.brooklyn.test.framework.SimpleShellCommandTest + name: Check paths permissions + command: | + [ "$(stat -c "%A %U %G" /opt/brooklyn)" = "drwxr-xr-x brooklyn brooklyn" ] && \ + [ "$(stat -c "%A %U %G" /var/lib/brooklyn)" = "drwxr-xr-x brooklyn brooklyn" ] && \ + [ "$(stat -c "%A %U %G" /var/log/brooklyn)" = "drwx------ brooklyn brooklyn" ] && \ + [ "$(stat -c "%A %U %G" /etc/systemd/system/multi-user.target.wants)" = "drwxr-xr-x root root" ] && \ + [ "$(sudo stat -c "%A %U %G" /etc/systemd/system/multi-user.target.wants/brooklyn.service)" = "-rw-r--r-- root root" ] && \ + [ "$(stat -c "%A %U %G" /etc/init)" = "drwxr-xr-x root root" ] && \ + [ "$(stat -c "%A %U %G" /etc/init/brooklyn.conf)" = "-rw-r--r-- root root" ] && \ + [ "$(stat -c "%A %U %G" /etc/brooklyn)" = "drwxr-xr-x brooklyn brooklyn" ] && \ + [ "$(sudo stat -c "%A %U %G" /etc/brooklyn/brooklyn.conf)" = "-rw------- brooklyn brooklyn" ] && \ + [ "$(stat -c "%A %U %G" /etc/brooklyn/logback.xml)" = "-rw-r--r-- brooklyn brooklyn" ] && \ + ! find /opt/brooklyn | xargs stat -c "%A %U %G" | grep -v "drwxr-xr-x brooklyn brooklyn\|-rw-r--r-- brooklyn brooklyn" + assertStatus: + equals: 0 + - id: test-log-files-exist + item: + type: org.apache.brooklyn.test.framework.SimpleShellCommandTest + name: Check log files created at expected location + command: sudo ls /var/log/brooklyn/brooklyn.{debug,info}.log | wc -l + assertOut: + equals: "2" + - id: test-healthy + item: + type: org.apache.brooklyn.test.framework.TestCase + name: Check entity is healthy + brooklyn.children: + - type: test-is-up + name: 001. Test isUp + - type: test-process-running + name: 002. Test process is running + - type: test-port-reachable + name: 003. Test port is reachable + - id: test-start + item: + type: org.apache.brooklyn.test.framework.TestEffector + name: Invoke start Effector + effector: start + - id: test-stop + item: + type: org.apache.brooklyn.test.framework.TestEffector + name: Invoke stop Effector + effector: stop + params: + stopMachineMode: NEVER + - id: test-restart + item: + type: org.apache.brooklyn.test.framework.TestEffector + name: Invoke restart Effector + effector: restart + params: + restartMachine: false + - id: test-restart-machine + item: + type: org.apache.brooklyn.test.framework.SimpleShellCommandTest + name: Restart the machine + command: sudo shutdown -r now + assertStatus: + # Replacement for anything accepted + # Could be 0 or -1, depending on whether the socket closes before restart takes place + notNull: true + - id: packaging-asserts + item: + type: org.apache.brooklyn.test.framework.TestCase + targetId: brooklyn + brooklyn.config: + timeout: 1m + brooklyn.children: + - type: test-is-up + name: 01. Block until started + brooklyn.config: + timeout: 10m + - type: test-healthy + name: 02. Check healthy + - type: test-process-user + name: 03. Test process user + - type: test-path-permissions + name: 04. Test paths permissions + - type: test-log-files-exist + name: 05. Check log files created + - type: test-stop + name: 06. Test stop effector + - type: test-is-not-up + name: 07. Check not running + - type: test-process-not-running + name: 08. Check process not running + - type: test-start + name: 09. Test start effector + - type: test-healthy + name: 10. Check healthy + - type: test-restart + name: 11. Test restart effector + - type: test-healthy + name: 12. Check healthy + - type: test-restart-machine + name: 13. Restart machine + - type: test-is-not-up + name: 14. Check not running while restarting + - type: test-healthy + name: 15. Check healthy +### Combined tests with target entity - system specific ### + - id: test-yum-upstart-brooklyn + item: + type: org.apache.brooklyn.entity.stock.BasicApplication + brooklyn.children: + - type: yum-upstart-brooklyn + - type: packaging-asserts + - id: test-yum-systemd-brooklyn + item: + type: org.apache.brooklyn.entity.stock.BasicApplication + brooklyn.children: + - type: yum-systemd-brooklyn + - type: packaging-asserts + - id: test-apt-upstart-brooklyn + item: + type: org.apache.brooklyn.entity.stock.BasicApplication + brooklyn.children: + - type: apt-upstart-brooklyn + - type: packaging-asserts + - id: test-apt-systemd-brooklyn + item: + type: org.apache.brooklyn.entity.stock.BasicApplication + brooklyn.children: + - type: apt-systemd-brooklyn + - type: packaging-asserts +### How to use in a blueprint: +### location: xxx +### services: +### - type: test-apt-systemd-brooklyn +### brooklyn.config: +### files.preinstall: +### : brooklyn-package.{deb, rpm}