Skip to content

Commit

Permalink
blackbox-testing install and uninstall (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
jancajthaml authored Mar 18, 2019
1 parent a376b60 commit 74380d1
Show file tree
Hide file tree
Showing 21 changed files with 239 additions and 108 deletions.
3 changes: 3 additions & 0 deletions bbtest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ RUN \
exit 1 ; \
fi

RUN find . /etc/bbtest/packages -type f -name 'lake_*_amd64.deb' | \
xargs -I {} mv {} /etc/bbtest/packages/lake.deb

RUN apt-get update && \
apt-get install -y \
init-system-helpers>=1.18~ \
Expand Down
13 changes: 3 additions & 10 deletions bbtest/features/configuration.feature
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
Feature: Service can be configured

Scenario: properly installed debian package
Given lake is running
Then systemctl contains following
"""
lake.service
"""

Scenario: configure log level
Given lake is reconfigured with
"""
LOG_LEVEL=DEBUG
"""
Then journalctl of "lake.service" contains following
Then journalctl of "lake-relay.service" contains following
"""
Log level set to DEBUG
"""
Expand All @@ -21,7 +14,7 @@ Feature: Service can be configured
"""
LOG_LEVEL=ERROR
"""
Then journalctl of "lake.service" contains following
Then journalctl of "lake-relay.service" contains following
"""
Log level set to ERROR
"""
Expand All @@ -30,7 +23,7 @@ Feature: Service can be configured
"""
LOG_LEVEL=INFO
"""
Then journalctl of "lake.service" contains following
Then journalctl of "lake-relay.service" contains following
"""
Log level set to INFO
"""
11 changes: 11 additions & 0 deletions bbtest/features/install.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@install
Feature: Install package

Scenario: install
Given package "lake.deb" is installed
Then systemctl contains following
"""
lake-relay.service
lake.service
lake.path
"""
13 changes: 7 additions & 6 deletions bbtest/features/management.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ Feature: Bootstrap shared
Given lake is running
And systemctl contains following
"""
lake-relay.service
lake.service
"""

When stop unit "lake.service"
Given unit "lake.service" is not running
When stop unit "lake-relay.service"
Given unit "lake-relay.service" is not running

When start unit "lake.service"
Given unit "lake.service" is running
When start unit "lake-relay.service"
Given unit "lake-relay.service" is running

When restart unit "lake.service"
Given unit "lake.service" is running
When restart unit "lake-relay.service"
Given unit "lake-relay.service" is running

Then lake is running
11 changes: 11 additions & 0 deletions bbtest/features/uninstall.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@uninstall
Feature: Unnstall package

Scenario: uninstall
Given package "lake" is uninstalled
Then systemctl does not contains following
"""
lake-relay.service
lake.service
lake.path
"""
42 changes: 14 additions & 28 deletions bbtest/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
RSpec.configure do |config|
config.raise_error_for_unimplemented_steps = true
config.color = true
config.fail_fast = true

Dir.glob("./helpers/*_helper.rb") { |f| load f }
config.include EventuallyHelper, :type => :feature
Dir.glob("./steps/*_steps.rb") { |f| load f, true }

config.register_ordering(:global) do |items|
(install, others) = items.partition { |spec| spec.metadata[:install] }
(uninstall, others) = others.partition { |spec| spec.metadata[:uninstall] }

install + others.shuffle + uninstall
end

config.before(:suite) do |_|
print "[ suite starting ]\n"

Expand All @@ -22,42 +30,20 @@
%x(rm -rf #{folder}/*)
}

print "[ installing package ]\n"

%x(find /etc/bbtest/packages -type f -name 'lake_*_amd64.deb')
.split("\n")
.map(&:strip)
.reject { |x| x.empty? }
.each { |package|
IO.popen("apt-get -y install -f #{package}") do |io|
while (line = io.gets) do
puts line
end
end
}

print "[ suite started ]\n"
end

config.after(:suite) do |_|
print "\n[ suite ending ]\n"

ids = %x(systemctl -a -t service --no-legend | awk '{ print $1 }')

if $?
ids = ids.split("\n").map(&:strip).reject { |x|
x.empty? || !x.start_with?("lake")
}.map { |x| x.chomp(".service") }
else
ids = []
end

ids.each { |e|
%x(journalctl -o short-precise -u #{e} --no-pager > /reports/#{e}.log 2>&1)
[
"lake",
].each { |e|
%x(journalctl -o short-precise -u #{e}.service --no-pager > /reports/#{e}.log 2>&1)
%x(systemctl stop #{e} 2>&1)
%x(systemctl disable #{e} 2>&1)
%x(journalctl -o short-precise -u #{e} --no-pager > /reports/#{e}.log 2>&1)
} unless ids.empty?
%x(journalctl -o short-precise -u #{e}.service --no-pager > /reports/#{e}.log 2>&1)
}

ZMQHelper.stop()

Expand Down
20 changes: 17 additions & 3 deletions bbtest/steps/debian_steps.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@

step "package :package is installed" do |package|
out = %x(apt-get -y install -f /etc/bbtest/packages/#{package})
expect($?).to be_success, out

expect(File.file?("/etc/init/lake.conf")).to be(true)
end

step "package :package is uninstalled" do |package|
out = %x(apt-get -y remove #{package})
expect($?).to be_success, out

expect(File.file?("/etc/init/lake.conf")).to be(false)
end

step "systemctl contains following" do |packages|
items = packages.split("\n").map(&:strip).reject(&:empty?)

eventually() {
items.each { |item|
units = %x(systemctl -a -t service --no-legend | awk '{ print $1 }')
units = %x(systemctl list-units --no-legend | awk '{ print $1 }')
units = units.split("\n").map(&:strip).reject(&:empty?)
subset = units.reject { |x| !x.include?(item) }
expect(subset).not_to be_empty, "\"#{item}\" was not found in #{units}"
Expand All @@ -16,10 +30,10 @@
items = packages.split("\n").map(&:strip).reject(&:empty?)

items.each { |item|
units = %x(systemctl -a -t service --no-legend | awk '{ print $1 }')
units = %x(systemctl list-units --no-legend | awk '{ print $1 }')
units = units.split("\n").map(&:strip).reject(&:empty?)
subset = units.reject { |x| !x.include?(item) }
expect(subset).to be_empty, "#{item} was found not found in #{units}"
expect(subset).to be_empty, "\"#{item}\" was found in #{units}"
}
end

Expand Down
10 changes: 5 additions & 5 deletions bbtest/steps/orchestration_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
expect($?).to be_success, ids

ids = ids.split("\n").map(&:strip).reject { |x|
x.empty? || !x.start_with?("lake")
x.empty? || !x.start_with?("lake-")
}.map { |x| x.chomp(".service") }

expect(ids).not_to be_empty
Expand All @@ -22,7 +22,7 @@

step "lake is running" do ||
eventually() {
out = %x(systemctl show -p SubState lake 2>&1 | sed 's/SubState=//g')
out = %x(systemctl show -p SubState lake-relay 2>&1 | sed 's/SubState=//g')
expect(out.strip).to eq("running")
}

Expand All @@ -32,7 +32,7 @@
end

step "lake is reconfigured with" do |configuration|
params = Hash[configuration.split("\n").map(&:strip).reject(&:empty?).map {|el| el.split '='}]
params = Hash[configuration.split("\n").map(&:strip).reject(&:empty?).map { |el| el.split '=' }]
defaults = {
"LOG_LEVEL" => "DEBUG",
"PORT_PULL" => "5562",
Expand All @@ -47,10 +47,10 @@
%x(mkdir -p /etc/init)
%x(echo '#{config}' > /etc/init/lake.conf)

%x(systemctl restart lake 2>&1)
%x(systemctl restart lake-relay 2>&1)

eventually() {
out = %x(systemctl show -p SubState lake 2>&1 | sed 's/SubState=//g')
out = %x(systemctl show -p SubState lake-relay 2>&1 | sed 's/SubState=//g')
expect(out.strip).to eq("running")
}

Expand Down
2 changes: 1 addition & 1 deletion packaging/debian_amd64/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: lake
Version: 1.1.4+lint-fixes
Version: 1.1.4+test-install-uninstall
Architecture: amd64
Maintainer: Jan Cajthaml <jan.cajthaml@gmail.com>
Depends: init-system-helpers (>= 1.18~), libzmq5 (>= 4.2.1~)
Expand Down
1 change: 0 additions & 1 deletion packaging/debian_amd64/DEBIAN/displace
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/etc/init/lake.conf
/opt/lake/metrics/metrics.json
14 changes: 12 additions & 2 deletions packaging/debian_amd64/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ case "$1" in

configure)
if [ -f "/etc/init/lake.conf" ] ; then
systemctl unmask lake.service >/dev/null
systemctl enable lake.service >/dev/null
systemctl unmask \
lake.path \
lake.service \
lake-relay.service \
>/dev/null

systemctl enable \
lake.path \
lake.service \
lake-relay.service \
>/dev/null

(systemctl start lake.service >/dev/null || :)
else
(>&2 echo "/etc/init/lake.conf file not found")
Expand Down
56 changes: 41 additions & 15 deletions packaging/debian_amd64/DEBIAN/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,50 @@

set -e

delete_service_files() {
if [ -f "/lib/systemd/system/lake-relay.service" ] ; then
rm /lib/systemd/system/lake-relay.service
fi

if [ -f "/lib/systemd/system/lake.service" ] ; then
rm /lib/systemd/system/lake.service
fi

if [ -f "/lib/systemd/system/lake.path" ] ; then
rm /lib/systemd/system/lake.path
fi
}

delete_displace_files() {
if [ -f "/etc/init/lake.conf" ] ; then
rm /etc/init/lake.conf
fi
}

case "$1" in

purge)
systemctl stop lake.service
systemctl disable lake.service
(rm /lib/systemd/system/lake.service || :)
(rm /lib/systemd/system/lake.service || :)
(rm /etc/init/lake.conf || :)
(rm /opt/lake/metrics/metrics.json || :)
systemctl daemon-reload
systemctl reset-failed
;;

remove)
systemctl mask lake.service
;;

upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
# userdel openbank || :

delete_service_files
delete_displace_files

(systemctl daemon-reload || :)
(systemctl reset-failed || :)
;;

remove)
(systemctl -a -t service --no-legend | awk '$1 ~ /lake/ { print $1 }' | xargs -I {} systemctl stop {} 2> /dev/null || :)
(systemctl daemon-reload || :)

delete_displace_files
;;

upgrade|deconfigure)
systemctl stop lake 2> /dev/null || :
;;

remove|failed-upgrade|abort-install|abort-upgrade|disappear)
;;

*)
Expand Down
21 changes: 21 additions & 0 deletions packaging/debian_amd64/lib/systemd/system/lake-relay.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Unit]
Description=openbank lake message relay
PartOf=lake.service
After=lake.service

[Service]
Type=notify
EnvironmentFile=/etc/init/lake.conf
StartLimitBurst=0
ExecStart=/openbank/services/lake/lake
StandardInput=null
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
Restart=on-failure
RestartSec=1
TimeoutStartSec=0
KillMode=process

[Install]
WantedBy=lake.service
9 changes: 9 additions & 0 deletions packaging/debian_amd64/lib/systemd/system/lake.path
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=openbank lake services namespace
PartOf=lake.service

[Path]
PathChanged=/etc/init/lake.conf

[Install]
WantedBy=lake.service
15 changes: 3 additions & 12 deletions packaging/debian_amd64/lib/systemd/system/lake.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@ Description=openbank lake message relay
After=inetd.service

[Service]
Type=notify
EnvironmentFile=/etc/init/lake.conf
StartLimitBurst=0
ExecStart=/openbank/services/lake/lake
StandardInput=null
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
Restart=on-failure
RestartSec=1
TimeoutStartSec=0
KillMode=process
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
1 change: 0 additions & 1 deletion packaging/debian_armhf/DEBIAN/displace
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/etc/init/lake.conf
/opt/lake/metrics/metrics.json
Loading

0 comments on commit 74380d1

Please sign in to comment.