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 ...@@ -31,7 +31,7 @@ module QA
end end
def fabricate_via_api! 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.pull
runner.token = @token ||= project.runners_token runner.token = @token ||= project.runners_token
runner.address = Runtime::Scenario.gitlab_address runner.address = Runtime::Scenario.gitlab_address
...@@ -48,11 +48,20 @@ module QA ...@@ -48,11 +48,20 @@ module QA
def remove_via_api! def remove_via_api!
runners = list_of_runners(tag_list: @tags) 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 } 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 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}" 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 end
...@@ -73,6 +82,10 @@ module QA ...@@ -73,6 +82,10 @@ module QA
parse_body(response) parse_body(response)
end end
def reload!
super if method(:running?).super_method.call
end
def api_delete_path def api_delete_path
"/runners/#{id}" "/runners/#{id}"
end end
...@@ -86,6 +99,16 @@ module QA ...@@ -86,6 +99,16 @@ module QA
def api_post_body def api_post_body
end 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 end
end end
...@@ -11,6 +11,12 @@ module QA ...@@ -11,6 +11,12 @@ module QA
@runner_network = Runtime::Scenario.attributes[:runner_network] || @network @runner_network = Runtime::Scenario.attributes[:runner_network] || @network
end end
def logs
shell "docker logs #{@name}" do |line|
yield " #{line.chomp}"
end
end
def network def network
shell "docker network inspect #{@network}" shell "docker network inspect #{@network}"
rescue CommandError rescue CommandError
......
...@@ -43,6 +43,8 @@ module QA ...@@ -43,6 +43,8 @@ module QA
#{@image} #{add_gitlab_tls_cert if @address.include? "https"} && docker exec --detach #{@name} sh -c "#{register_command}" #{@image} #{add_gitlab_tls_cert if @address.include? "https"} && docker exec --detach #{@name} sh -c "#{register_command}"
CMD CMD
wait_until_running_and_configured
# Prove airgappedness # Prove airgappedness
if runner_network == 'airgapped' if runner_network == 'airgapped'
shell("docker exec #{@name} sh -c '#{prove_airgap}'") shell("docker exec #{@name} sh -c '#{prove_airgap}'")
...@@ -111,6 +113,10 @@ module QA ...@@ -111,6 +113,10 @@ module QA
&& docker cp #{gitlab_tls_certificate.path} #{@name}:/etc/gitlab-runner/certs/gitlab.test.crt && docker cp #{gitlab_tls_certificate.path} #{@name}:/etc/gitlab-runner/certs/gitlab.test.crt
CMD CMD
end end
def wait_until_running_and_configured
wait_until_shell_command_matches("docker logs #{@name}", /Configuration loaded/)
end
end end
end end
end end
......
...@@ -15,15 +15,11 @@ module QA ...@@ -15,15 +15,11 @@ module QA
end end
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`` # Removing a runner via the UI is covered by `spec/features/runners_spec.rb``
it 'removes the runner' do it 'removes the runner' do
runners = runner.list_of_runners(tag_list: runner_tags) runners = nil
expect { (runners = runner.list_of_runners(tag_list: runner_tags)).size }
expect(runners.size).to eq(1) .to eventually_eq(1).within(max_duration: 10, sleep_interval: 1)
expect(runners.first[:description]).to eq(executor) expect(runners.first[:description]).to eq(executor)
request = Runtime::API::Request.new(api_client, "runners/#{runners.first[:id]}") request = Runtime::API::Request.new(api_client, "runners/#{runners.first[:id]}")
......
...@@ -22,8 +22,6 @@ module QA ...@@ -22,8 +22,6 @@ module QA
Page::Project::Menu.perform(&:go_to_ci_cd_settings) Page::Project::Menu.perform(&:go_to_ci_cd_settings)
Page::Project::Settings::CiCd.perform do |settings| Page::Project::Settings::CiCd.perform do |settings|
sleep 5 # Runner should register within 5 seconds
settings.expand_runners_settings do |page| settings.expand_runners_settings do |page|
expect(page).to have_content(executor) expect(page).to have_content(executor)
expect(page).to have_online_runner expect(page).to have_online_runner
......
...@@ -24,6 +24,7 @@ module QA ...@@ -24,6 +24,7 @@ module QA
before do before do
allow(subject).to receive(:shell) allow(subject).to receive(:shell)
allow(subject).to receive(:wait_until_running_and_configured)
end end
context 'defaults' do 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