Commit f3573254 authored by Richard Chong's avatar Richard Chong Committed by Mark Lapierre

Update to different way to fetch list of runners

parent bfb5bc88
......@@ -295,13 +295,6 @@ module QA
merge_requests.find { |mr| mr[:title] == title }
end
def runners(tag_list: nil)
url = tag_list ? "#{api_runners_path}?tag_list=#{tag_list.compact.join(',')}" : api_runners_path
response = get(request_url(url, per_page: '100'))
parse_body(response)
end
def registry_repositories
response = get(request_url(api_registry_repositories_path))
parse_body(response)
......
......@@ -46,11 +46,12 @@ module QA
end
def remove_via_api!
runners = project.runners(tag_list: @tags)
runners = list_of_runners(tag_list: @tags)
return if runners.blank?
this_runner = runners.find { |runner| runner[:description] == name }
unless this_runner
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
......@@ -62,6 +63,16 @@ module QA
Service::DockerRun::GitlabRunner.new(name).remove!
end
def list_of_runners(tag_list: nil)
url = tag_list ? "#{api_post_path}?tag_list=#{tag_list.compact.join(',')}" : api_post_path
response = get(request_url(url, per_page: '100'))
# Capturing 500 error code responses to log this issue better. We can consider cleaning it up once https://gitlab.com/gitlab-org/gitlab/-/issues/331753 is addressed.
raise "Response returned a #{response.code} error code. #{response.body}" if response.code == Support::API::HTTP_STATUS_SERVER_ERROR
parse_body(response)
end
def api_delete_path
"/runners/#{id}"
end
......@@ -70,6 +81,7 @@ module QA
end
def api_post_path
"/runners"
end
def api_post_body
......
......@@ -7,7 +7,7 @@ module QA
let(:api_client) { Runtime::API::Client.new(:gitlab) }
let(:executor) { "qa-runner-#{Time.now.to_i}" }
let(:runner_tags) { ['runner-registration-e2e-test'] }
let(:runner_tags) { ["runner-registration-e2e-test-#{Faker::Alphanumeric.alphanumeric(number: 8)}"] }
let!(:runner) do
Resource::Runner.fabricate! do |runner|
runner.name = executor
......@@ -20,16 +20,18 @@ module QA
end
# Removing a runner via the UI is covered by `spec/features/runners_spec.rb``
it 'removes the runner', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/355302', type: :investigating }, testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/354828' do
expect(runner.project.runners.size).to eq(1)
expect(runner.project.runners.first[:description]).to eq(executor)
it 'removes the runner' do
runners = runner.list_of_runners(tag_list: runner_tags)
request = Runtime::API::Request.new(api_client, "runners/#{runner.project.runners.first[:id]}")
expect(runners.size).to eq(1)
expect(runners.first[:description]).to eq(executor)
request = Runtime::API::Request.new(api_client, "runners/#{runners.first[:id]}")
response = delete(request.url)
expect(response.code).to eq(Support::API::HTTP_STATUS_NO_CONTENT)
expect(response.body).to be_empty
expect(runner.project.runners).to be_empty
expect(runner.list_of_runners(tag_list: runner_tags)).to be_empty
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