Commit 0cf136b6 authored by Tanya Pazitny's avatar Tanya Pazitny Committed by Mark Lapierre

Add test support for airgapped environments

Use airgapped network for runner

This will allow the runner to run in an airgapped network
that is shared with the main GitLab container

Add an Instance scenario for Airgapped

Add an airgap check of an initial wget to prove that DNS is
functioning, ping commands to show initial connectivity and
then airgap, and a netcat check of port 80
parent bcbb02dd
...@@ -137,6 +137,7 @@ module QA ...@@ -137,6 +137,7 @@ module QA
module Instance module Instance
autoload :All, 'qa/scenario/test/instance/all' autoload :All, 'qa/scenario/test/instance/all'
autoload :Smoke, 'qa/scenario/test/instance/smoke' autoload :Smoke, 'qa/scenario/test/instance/smoke'
autoload :Airgapped, 'qa/scenario/test/instance/airgapped'
end end
module Integration module Integration
......
# frozen_string_literal: true
module QA
module Scenario
module Test
module Instance
class Airgapped < Template
include Bootable
include SharedAttributes
def perform(address, *rspec_options)
Runtime::Scenario.define(:runner_network, 'airgapped')
super
end
end
end
end
end
end
...@@ -8,6 +8,7 @@ module QA ...@@ -8,6 +8,7 @@ module QA
def initialize def initialize
@network = Runtime::Scenario.attributes[:network] || 'test' @network = Runtime::Scenario.attributes[:network] || 'test'
@runner_network = Runtime::Scenario.attributes[:runner_network] || @network
end end
def network def network
...@@ -18,6 +19,14 @@ module QA ...@@ -18,6 +19,14 @@ module QA
@network @network
end end
def runner_network
shell "docker network inspect #{@runner_network}"
rescue CommandError
network
else
@runner_network
end
def pull def pull
shell "docker pull #{@image}" shell "docker pull #{@image}"
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require 'resolv'
require 'securerandom' require 'securerandom'
module QA module QA
...@@ -38,11 +39,16 @@ module QA ...@@ -38,11 +39,16 @@ module QA
def register! def register!
shell <<~CMD.tr("\n", ' ') shell <<~CMD.tr("\n", ' ')
docker run -d --rm --entrypoint=/bin/sh docker run -d --rm --entrypoint=/bin/sh
--network #{network} --name #{@name} --network #{runner_network} --name #{@name}
#{'-v /var/run/docker.sock:/var/run/docker.sock' if @executor == :docker} #{'-v /var/run/docker.sock:/var/run/docker.sock' if @executor == :docker}
--privileged --privileged
#{@image} -c "#{register_command}" #{@image} -c "#{register_command}"
CMD CMD
# Prove airgappedness
if runner_network == 'airgapped'
shell("docker exec #{@name} sh -c '#{prove_airgap}'")
end
end end
def tags=(tags) def tags=(tags)
...@@ -85,6 +91,17 @@ module QA ...@@ -85,6 +91,17 @@ module QA
gitlab-runner run gitlab-runner run
CMD CMD
end end
# Ping CloudFlare DNS, should fail
# Ping Registry, should fail to resolve
def prove_airgap
gitlab_ip = Resolv.getaddress 'registry.gitlab.com'
<<~CMD
echo "Checking airgapped connectivity..."
nc -zv -w 10 #{gitlab_ip} 80 && (echo "Airgapped network faulty. Connectivity netcat check failed." && exit 1) || (echo "Connectivity netcat check passed." && exit 0)
wget --retry-connrefused --waitretry=1 --read-timeout=15 --timeout=10 -t 2 http://registry.gitlab.com > /dev/null 2>&1 && (echo "Airgapped network faulty. Connectivity wget check failed." && exit 1) || (echo "Airgapped network confirmed. Connectivity wget check passed." && exit 0)
CMD
end
end end
end end
end end
......
...@@ -16,7 +16,9 @@ module QA ...@@ -16,7 +16,9 @@ module QA
end end
def host_name def host_name
return 'localhost' unless QA::Runtime::Env.running_in_ci? if !QA::Runtime::Env.running_in_ci? && !runner_network.equal?('airgapped')
'localhost'
end
super super
end end
...@@ -33,7 +35,9 @@ module QA ...@@ -33,7 +35,9 @@ module QA
#{@image} #{@image}
CMD CMD
command.gsub!("--network #{network} ", '') unless QA::Runtime::Env.running_in_ci? if !QA::Runtime::Env.running_in_ci? && !runner_network.equal?('airgapped')
command.gsub!("--network #{network} ", '')
end
shell command shell command
end end
......
# frozen_string_literal: true
describe QA::Scenario::Test::Instance::Airgapped do
describe '#perform' do
it_behaves_like 'a QA scenario class' do
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment