Skip to content

Commit

Permalink
Merge pull request #209 from SUSE/integration-tests
Browse files Browse the repository at this point in the history
CLI integration tests
  • Loading branch information
Sergeykot committed Aug 23, 2018
2 parents 756bfda + 393ac0a commit 8c9e669
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
tmp/*
!tmp/.keep
log/*
!log/.keep
.git
Dockerfile
Dockerfile.test
Jenkinsfile
.codeclimate.yml
.travis.yml
Expand Down
62 changes: 62 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM registry.scc.suse.de/suse/sles15:ga

RUN useradd --no-log-init --create-home scc

ARG REGCODE
ARG OBS_USER
ARG OBS_PASSWORD
ARG MYSQL_HOST
ARG MYSQL_USER
ARG MYSQL_PASSWORD
ARG MYSQL_DATABASE
ARG SCC_USERNAME
ARG SCC_PASSWORD

RUN SUSEConnect -r $REGCODE
RUN zypper --non-interactive ar http://download.opensuse.org/repositories/openSUSE:/Tools/SLE_15/openSUSE:Tools.repo
RUN zypper --non-interactive --gpg-auto-import-keys ref
RUN zypper --non-interactive up
RUN zypper --non-interactive in -t pattern devel_osc_build
RUN zypper --non-interactive install --no-recommend wget curl timezone \
gcc-c++ libffi-devel git-core zlib-devel libxml2-devel libxslt-devel libmariadb-devel \
mariadb-client ruby2.5-rubygem-bundler make build sudo ruby-devel


ENV DOCKERIZE_VERSION v0.6.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

RUN printf "[general]\n\
build-root = /oscbuild/%(repo)s-%(arch)s\n\
packagecachedir = /oscbuild/packagecache\n\
[https://api.suse.de]\n\
user=$OBS_USER\n\
pass=$OBS_PASSWORD\n\
sslcertck = 0\n\
trusted_prj=SLE_12 SUSE:SLE-12:GA\n\
[https://api.opensuse.org]\n\
user=$OBS_USER\n\
pass=$OBS_PASSWORD\n\
sslcertck = 0\n\
trusted_prj=SLE_12 SUSE:SLE-12:GA\n\
" >> ~/.oscrc

RUN mkdir /tmp/rmt-server
WORKDIR /tmp/rmt-server
ADD . /tmp/rmt-server
RUN chown -R scc /tmp/rmt-server
RUN mkdir /etc/rmt
RUN printf "database:\n\
host: $MYSQL_HOST\n\
username: $MYSQL_USER\n\
password: $MYSQL_PASSWORD\n\
database: $MYSQL_DATABASE\n\
scc:\n\
username: $SCC_USERNAME\n\
password: $SCC_PASSWORD\n\
" >> /etc/rmt.conf

RUN bundle

CMD dockerize -wait tcp://$MYSQL_HOST:3306 -timeout 60s true
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ group :development do
end

group :test do
gem 'rspec-command', '1.0.3'
gem 'rspec-rails', '~> 3.5'
gem 'factory_girl_rails', '4.8.0'
gem 'ffaker'
Expand Down
10 changes: 8 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ GEM
faraday (~> 0.8)
fast_gettext (1.6.0)
ffaker (2.8.1)
ffi (1.9.21)
ffi (1.9.25)
formatador (0.2.5)
fuubar (2.3.1)
rspec-core (~> 3.0)
Expand Down Expand Up @@ -169,6 +169,7 @@ GEM
method_source (0.9.0)
mini_portile2 (2.3.0)
minitest (5.11.3)
mixlib-shellout (2.4.0)
multipart-post (2.0.0)
mustache (1.0.5)
mysql2 (0.4.10)
Expand Down Expand Up @@ -223,6 +224,10 @@ GEM
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-command (1.0.3)
mixlib-shellout (~> 2.0)
rspec (~> 3.2)
rspec-its (~> 1.2)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
Expand Down Expand Up @@ -337,6 +342,7 @@ DEPENDENCIES
railties (~> 5.1.3)
responders
ronn
rspec-command (= 1.0.3)
rspec-its
rspec-rails (~> 3.5)
ruby_parser
Expand All @@ -356,4 +362,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
1.16.1
1.16.2
3 changes: 1 addition & 2 deletions bin/rmt-cli
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ end
relative_load_paths = %w[lib lib/rmt app/models app/services].map { |dir| File.join(rmt_path, dir) }
ActiveSupport::Dependencies.autoload_paths += relative_load_paths

# FIXME: this check (or its message) is not correct. It already complains when the folder does just not exist, even-though it is perfectly writeable by my user.
unless File.writable?(RMT::DEFAULT_MIRROR_DIR)
if File.exist?(RMT::DEFAULT_MIRROR_DIR) && !File.writable?(RMT::DEFAULT_MIRROR_DIR)
warn "Mirroring base directory (#{RMT::DEFAULT_MIRROR_DIR}) is not writable by user '#{Etc.getpwuid(Process.euid).name}'"
warn 'Run as root or adjust the permissions.'
exit RMT::CLI::Error::ERROR_OTHER
Expand Down
44 changes: 44 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '2'
volumes:
db_storage:
driver: local
networks:
default:
driver: bridge
driver_opts:
com.docker.network.driver.mtu: 1350

services:
db:
image: mariadb:10.2
restart: always
volumes:
- db_storage:/var/lib/mysql
extends:
service: base
file: docker-compose-base.yml

rmt_test:
privileged: true
build:
context: .
dockerfile: Dockerfile.test
args:
REGCODE: ${REGCODE}
OBS_USER: ${OBS_USER}
OBS_PASSWORD: ${OBS_PASSWORD}
SCC_USERNAME: ${SCC_USERNAME}
SCC_PASSWORD: ${SCC_PASSWORD}
MYSQL_HOST: ${MYSQL_HOST}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
environment:
- MYSQL_HOST=db
- SECRET_KEY_BASE=8ea53ad3bc6c03923e376c8bdd85059c1885524947a7efe53d5e9c9d4e39861106ffd6a2ece82b803072ed701e6c960bade91644979e679416c5f255007237ae
depends_on:
- db
extends:
service: base
file: docker-compose-base.yml
command: /bin/bash -c 'bundle.ruby2.5 exec rails db:migrate'
17 changes: 17 additions & 0 deletions features/lockfile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require File.expand_path('../support/command_rspec_helper', __FILE__)

describe 'rmt-cli' do
before { `/usr/bin/rmt-cli sync > /dev/null &` }
# kill running process to let further specs pass
after { `kill -9 $(cat /tmp/rmt.lock)` }

describe 'lockfile' do
command '/usr/bin/rmt-cli sync', allow_error: true

its(:stderr) { is_expected.to eq("Process is locked by the application with \
pid #{File.read('/tmp/rmt.lock')}. Close this application or wait for it \
to finish before trying again\n") }

its(:exitstatus) { is_expected.to eq 1 }
end
end
23 changes: 23 additions & 0 deletions features/mirror_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require File.expand_path('../support/command_rspec_helper', __FILE__)

describe 'mirror' do
let(:files) { %w'repomd.xml repomd.xml.asc repomd.xml.key *-primary.xml.gz *-filelists.xml.gz *-other.xml.gz' }

before do
`/usr/bin/rmt-cli repos enable 3114`
`/usr/bin/rmt-cli mirror`
end

after do
`/usr/bin/rmt-cli repos disable 3114`

# cleanup files
FileUtils.rm_r('/var/lib/rmt/public/repo/SUSE/Updates/SLE-Product-SLES/15')
end

it do
files.each do |filename_pattern|
expect(`find /var/lib/rmt/public/ -name \'#{filename_pattern}\'`).to include(filename_pattern.gsub('*', ''))
end
end
end
19 changes: 19 additions & 0 deletions features/repos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe 'enable repos' do
let(:repos) { [3114, 3115, 3116, 2705, 2707] }

before do
repos.each do |repo_id|
`/usr/bin/rmt-cli repos enable #{repo_id}`
end
end

after do
repos.each do |repo_id|
`/usr/bin/rmt-cli repos disable #{repo_id}`
end
end

it do
expect(`/usr/bin/rmt-cli repos list --csv | wc -l`.strip&.to_i ).to eq(5)
end
end
5 changes: 5 additions & 0 deletions features/support/command_rspec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rspec_command'

RSpec.configure do |config|
config.include RSpecCommand
end
13 changes: 13 additions & 0 deletions features/sync_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require File.expand_path('../support/command_rspec_helper', __FILE__)

describe 'rmt-cli' do
describe 'sync' do
command '/usr/bin/rmt-cli sync'
its(:exitstatus) { is_expected.to eq 0 }

it do
expect(`/usr/bin/rmt-cli products list --all | wc -l`.strip&.to_i ).to be >= 361
expect(`/usr/bin/rmt-cli repos list --all | wc -l`.strip&.to_i ).to be >= 839
end
end
end
14 changes: 14 additions & 0 deletions integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh -xe
make dist
mkdir ~/obs
cd ~/obs
osc co systemsmanagement:SCC:RMT rmt-server
cd /tmp/rmt-server/package
cp * ~/obs/systemsmanagement:SCC:RMT/rmt-server
cd ~/obs/systemsmanagement:SCC:RMT/rmt-server && osc build SLE_15 x86_64 --no-verify --trust-all-projects && cd .. &&
zypper --non-interactive --no-gpg-checks in /oscbuild/SLE_15-x86_64/home/abuild/rpmbuild/RPMS/x86_64/*
cd /usr/share/rmt
RAILS_ENV=production /usr/share/rmt/bin/rails db:create db:migrate
/usr/bin/rmt-cli sync
cd /tmp/rmt-server/
NO_COVERAGE=true rspec features/
34 changes: 34 additions & 0 deletions integration/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pipeline {
agent {
label 'scc-happy-customer'
}

stages {
stage('checkout') {
steps {
script {
currentBuild.displayName = "#${BUILD_NUMBER}: ${branch}"
}

git url: 'git@github.com:SUSE/rmt.git', branch: "${branch}"
}
}
stage('docker-compose build') {
steps {
sh 'docker-compose -f docker-compose-test.yml build'
}
}

stage('rmt integration tests') {
steps {
sh 'docker-compose -f docker-compose-test.yml run rmt_test ./integration.sh'
}
}
}
post {
always {
sh 'docker-compose down'
sh 'docker system prune -f'
}
}
}
2 changes: 1 addition & 1 deletion lib/suse/connect/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Api

class InvalidCredentialsError < StandardError; end
CONNECT_API_URL = 'https://scc.suse.com/connect'.freeze
UUID_FILE_LOCATION = "/var/lib/rmt/system_uuid".freeze
UUID_FILE_LOCATION = '/var/lib/rmt/system_uuid'.freeze

def initialize(username, password)
@username = username
Expand Down
5 changes: 5 additions & 0 deletions package/rmt-server.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Wed Aug 15 13:41:49 UTC 2018 - skotov@suse.com

- Change file permissions for rmt.conf

-------------------------------------------------------------------
Thu Aug 2 16:19:35 UTC 2018 - fschnizlein@suse.com

Expand Down
12 changes: 7 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require 'simplecov'

SimpleCov.minimum_coverage 100
SimpleCov.start do
add_filter '/spec/'
unless ENV['NO_COVERAGE']
SimpleCov.minimum_coverage 100
SimpleCov.start do
add_filter '/spec/'

track_files('app/**/*.rb')
track_files('lib/**/*.rb')
track_files('app/**/*.rb')
track_files('lib/**/*.rb')
end
end

if ENV['TRAVIS']
Expand Down

0 comments on commit 8c9e669

Please sign in to comment.