Skip to content

Commit

Permalink
e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamils-iRonin committed Aug 12, 2021
1 parent b32a80c commit 3644143
Show file tree
Hide file tree
Showing 14 changed files with 550 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
REACT_APP_FOREMAN_URL=http://localhost:5000
REACT_APP_GRAPHQL_API_URL="${REACT_APP_FOREMAN_URL}/api/graphql"
REACT_APP_SETTINGS_FILE=production
115 changes: 115 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
name: CI
on: [push, pull_request]
env:
SEED_ADMIN_PASSWORD: password
SEED_LOCATION: "LAN"
SEED_ORGANIZATION: "Organization 1"
RAILS_ENV: development
DATABASE_URL: postgresql://postgres:@localhost/test
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.1
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
fail-fast: false
max-parallel: 2
matrix:
foreman-core-branch: [2.5-stable, 3.0-stable, develop]
foreman-puppet-branch: [null, master]
ruby-version: [2.7]
node-version: [12.x]
exclude:
- foreman-core-branch: 3.0-stable
foreman-puppet-branch: null
- foreman-core-branch: develop
foreman-puppet-branch: null
steps:
- uses: actions/checkout@v2
with:
path: lisa
- uses: actions/checkout@v2
with:
repository: theforeman/foreman
ref: ${{ matrix.foreman-core-branch }}
path: foreman
- uses: actions/checkout@v2
with:
repository: theforeman/foreman_puppet
ref: ${{ matrix.foreman-puppet-branch }}
path: foreman_puppet
if: ${{ matrix.foreman-puppet-branch != null }}
- name: Setup foreman_puppet
if: ${{ matrix.foreman-puppet-branch != null }}
run: |
echo "gem 'foreman_puppet', path: '../foreman_puppet'" > bundler.d/foreman_puppet.local.rb
working-directory: foreman
- name: Run Mocked Smart Proxy
run: docker run -d --env MAIN_APP_FILE='app.rb' -p 8800:80 -v /home/runner/work/lisa/lisa/lisa/e2e/smart-proxy:/usr/src/app erikap/ruby-sinatra
- uses: nanasess/setup-chromedriver@master
- run: |
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional
- run: |
sudo apt-get update
sudo apt-get install build-essential libcurl4-openssl-dev libvirt-dev ruby-libvirt zlib1g-dev libpq-dev
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Install bundler
run: gem install bundler
- name: Copy lisa settings (puppet plugin enabled)
if: ${{ matrix.foreman-puppet-branch != null }}
run: cp e2e/production.json.with_puppet_plugin src/settings/production.json
working-directory: lisa
- name: Copy lisa settings (puppet plugin disabled)
if: ${{ matrix.foreman-puppet-branch == null }}
run: cp e2e/production.json.without_puppet_plugin src/settings/production.json
working-directory: lisa
- name: Build Lisa
run: docker build -t lisa-image .
working-directory: lisa
- name: Run Lisa
run: docker run -d -p 8080:8080 lisa-image
working-directory: lisa
- name: Cache Foreman gems
uses: actions/cache@v2
with:
path: foreman/vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('foreman/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Copy the Lisa specific configs to Foreman
run: cp -r lisa/e2e/foreman ./
- name: Setup Foreman
run: |
bundle config path vendor/bundle
bundle config set without journald development console mysql2 sqlite
bundle install --jobs 4 --retry 3
bundle lock --update
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:seed
working-directory: foreman
- name: Cache gems
uses: actions/cache@v2
with:
path: foreman/vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('foreman/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Run Foreman
run: bundle exec rails server -d -p 5000
working-directory: foreman
- name: Run tests
run: |
bundle install
bundle exec rake test
working-directory: lisa/e2e
2 changes: 2 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
smart-proxy/.bundle
screenshots
8 changes: 8 additions & 0 deletions e2e/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem 'rake'
gem 'minitest'
gem 'selenium-webdriver'
gem 'pry'
28 changes: 28 additions & 0 deletions e2e/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
GEM
remote: https://rubygems.org/
specs:
childprocess (3.0.0)
coderay (1.1.3)
method_source (1.0.0)
minitest (5.14.4)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rake (13.0.3)
rubyzip (2.3.0)
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)

PLATFORMS
ruby
x86_64-darwin-18

DEPENDENCIES
minitest
pry
rake
selenium-webdriver

BUNDLED WITH
2.1.4
7 changes: 7 additions & 0 deletions e2e/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require 'rake/testtask'

Rake::TestTask.new do |t|
t.pattern = 'tests/*_test.rb'
end
51 changes: 51 additions & 0 deletions e2e/foreman/config/initializers/mock-fog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Fog.mock!

module VmwareExtensions
extend ActiveSupport::Concern

module Overrides
def client
super.tap do |c|
def c.data
@data ||= begin
super.tap do |super_data|
super_data[:networks].map do |k, v|
v['name'] = 'VM Network'
v["vlanid"] = 1
end
end.nested_under_indifferent_access
end

@data
end
end
end
end

included do
prepend Overrides
end
end

::Foreman::Model::Vmware.include(VmwareExtensions)

module CreateVmExtensions
extend ActiveSupport::Concern

module Overrides
def create_vm(attributes = {})
super.tap do |id|
data[:servers][id]['interfaces'].first['mac'] = 6.times.map { '%02x' % rand(0..255) }.join(':')
end
end
end

included do
prepend Overrides
end
end

require File.join(Gem::Specification.find_by_name('fog-vsphere').gem_dir, 'lib', 'fog', 'vsphere', 'requests', 'compute', 'create_vm.rb')

Fog::Vsphere::Compute::Mock.include(CreateVmExtensions)

3 changes: 3 additions & 0 deletions e2e/foreman/config/settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
:cors_domains:
- '*'
56 changes: 56 additions & 0 deletions e2e/foreman/db/seeds.d/200-lisa.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
all_locations = Location.all
all_organizations = Organization.all

def puppet_class_importer
ForemanPuppet::PuppetClassImporter
rescue NameError
PuppetClassImporter
end

smart_proxy = SmartProxy.create!(
name: 'SmartProxyLisa',
url: 'http://localhost:8800',
locations: all_locations,
organizations: all_organizations
).tap do |smart_proxy|
puppet_class_importer.new({ url: smart_proxy.url }).changes['new'].map do |key, value|
puppet_class_importer.new.send(:add_classes_to_foreman, key, value)
end
end

domain = Domain.create!(
name: 'development.example.com',
locations: all_locations,
organizations: all_organizations
).tap do |domain|
domain.subnets.create!(
name: 'SubnetLisa',
network: '127.0.0.1',
mask: '255.255.255.0',
vlanid: 1,
locations: all_locations,
organizations: all_organizations
)
end

ComputeResource.create!(
name: 'ComputeResourceLisa ',
provider: 'Vmware',
uuid: 'Solutions',
url: 'http://localhost:8283',
user: 'user',
password: 'password',
http_proxy_id: smart_proxy.id,
domain: domain,
caching_enabled: false,
locations: all_locations,
organizations: all_organizations
)

Operatingsystem.create!(
name: 'OSLisa',
major: 1,
media: Medium.all,
ptables: Ptable.all,
architectures: Architecture.all
)
73 changes: 73 additions & 0 deletions e2e/production.json.with_puppet_plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"form_settings": {
"default_values": {
"puppet_env_id": "MDE6Rm9yZW1hblB1cHBldDo6RW52aXJvbm1lbnQtMQ==",
"puppetclass_ids": [
"MDE6Rm9yZW1hblB1cHBldDo6UHVwcGV0Y2xhc3MtMQ=="
]
}
},
"default_configs": {
"organization_id": "MDE6T3JnYW5pemF0aW9uLTE=",
"architecture_id": "MDE6QXJjaGl0ZWN0dXJlLTE="
},
"locations": [
{
"id": "MDE6TG9jYXRpb24tMg==",
"name": "LAN",
"code": "LAN",
"location": "LAN",
"country": "de",
"domain_name": "example.com",
"label": {
"location": "Karlsruhe",
"explanation": "Datacenter 1 (LAN)",
"reduced_performance": false
},
"relations": {
"cluster": "CLUSTER",
"compute_resource_id": "MDE6Q29tcHV0ZVJlc291cmNlLTE=",
"puppet_ca_proxy_id": "MDE6U21hcnRQcm94eS0x",
"media": [
{
"id": "MDE6TWVkaXVtLTE=",
"operatingsystem_id": "MDE6T3BlcmF0aW5nc3lzdGVtLTE="
}
]
},
"datastore_types": [
{
"id": "Mirror",
"name": "Mirror",
"template": "#DC#-LAN"
}
],
"compute_attributes": {
"path_prefix": "/Datencenter/LAN/vm/Linux/"
}
}
],
"operatingsystems": [
{
"id": "MDE6T3BlcmF0aW5nc3lzdGVtLTE=",
"name": "OSLisa",
"relations": {
"guest_operatingsystem_id": "rhel7_64Guest",
"ptable_id": "MDE6UHRhYmxlLTEyOQ=="
}
}
],
"app_tiers": [
{
"name": "development",
"relations": {
"locations": [
{
"code": "LAN",
"resource_pool": "default"
}
]
}
}
]
}
Loading

0 comments on commit 3644143

Please sign in to comment.