Commit ac9eec80 authored by Mark Lapierre's avatar Mark Lapierre Committed by Tiffany Rea

Add a test for removing runners

- When cleaning up runners after tests finish, ignore runners if
they've already been removed
parent 6c8550da
......@@ -31,7 +31,7 @@ module QA
end
def fabricate_via_api!
Service::DockerRun::GitlabRunner.new(name).tap do |runner|
@docker_container = Service::DockerRun::GitlabRunner.new(name).tap do |runner|
runner.pull
runner.token = @token ||= project.runners_token
runner.address = Runtime::Scenario.gitlab_address
......@@ -48,11 +48,20 @@ module QA
def remove_via_api!
runners = list_of_runners(tag_list: @tags)
return if runners.blank?
# If we have no runners, print the logs from the runner docker container in case they show why it isn't running.
if runners.blank?
dump_logs
return
end
this_runner = runners.find { |runner| runner[:description] == name }
# As above, but now we should have a specific runner. If not, print the logs from the runner docker container
# to see if we can find out why the runner isn't running.
unless this_runner
dump_logs
raise "Project #{project.path_with_namespace} does not have a runner with a description matching #{name} #{"or tags #{@tags}" if @tags&.any?}. Runners available: #{runners}"
end
......@@ -73,6 +82,10 @@ module QA
parse_body(response)
end
def reload!
super if method(:running?).super_method.call
end
def api_delete_path
"/runners/#{id}"
end
......@@ -86,6 +99,16 @@ module QA
def api_post_body
end
private
def dump_logs
if @docker_container.running?
@docker_container.logs { |line| QA::Runtime::Logger.debug(line) }
else
QA::Runtime::Logger.debug("No runner container found named #{name}")
end
end
end
end
end
......@@ -11,6 +11,12 @@ module QA
@runner_network = Runtime::Scenario.attributes[:runner_network] || @network
end
def logs
shell "docker logs #{@name}" do |line|
yield " #{line.chomp}"
end
end
def network
shell "docker network inspect #{@network}"
rescue CommandError
......
......@@ -43,6 +43,8 @@ module QA
#{@image} #{add_gitlab_tls_cert if @address.include? "https"} && docker exec --detach #{@name} sh -c "#{register_command}"
CMD
wait_until_running_and_configured
# Prove airgappedness
if runner_network == 'airgapped'
shell("docker exec #{@name} sh -c '#{prove_airgap}'")
......@@ -111,6 +113,10 @@ module QA
&& docker cp #{gitlab_tls_certificate.path} #{@name}:/etc/gitlab-runner/certs/gitlab.test.crt
CMD
end
def wait_until_running_and_configured
wait_until_shell_command_matches("docker logs #{@name}", /Configuration loaded/)
end
end
end
end
......
......@@ -15,15 +15,11 @@ module QA
end
end
before do
sleep 5 # Runner should register within 5 seconds
end
# Removing a runner via the UI is covered by `spec/features/runners_spec.rb``
it 'removes the runner' do
runners = runner.list_of_runners(tag_list: runner_tags)
expect(runners.size).to eq(1)
runners = nil
expect { (runners = runner.list_of_runners(tag_list: runner_tags)).size }
.to eventually_eq(1).within(max_duration: 10, sleep_interval: 1)
expect(runners.first[:description]).to eq(executor)
request = Runtime::API::Request.new(api_client, "runners/#{runners.first[:id]}")
......
......@@ -22,8 +22,6 @@ module QA
Page::Project::Menu.perform(&:go_to_ci_cd_settings)
Page::Project::Settings::CiCd.perform do |settings|
sleep 5 # Runner should register within 5 seconds
settings.expand_runners_settings do |page|
expect(page).to have_content(executor)
expect(page).to have_online_runner
......
......@@ -24,6 +24,7 @@ module QA
before do
allow(subject).to receive(:shell)
allow(subject).to receive(:wait_until_running_and_configured)
end
context 'defaults' do
......
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