BigW Consortium Gitlab

Commit 95d2f0fb by Kamil Trzcinski

Fix CI runner version not being properly updated when asking for a build

Due to broken implementation of attribute_for_keys the runner information was not updated correctly. This MR adds test to check that such scenario will never happen again.
parent 5e0ee54c
...@@ -16,6 +16,7 @@ v 8.4.2 (unreleased) ...@@ -16,6 +16,7 @@ v 8.4.2 (unreleased)
- Bump required gitlab-workhorse version to bring in a fix for missing - Bump required gitlab-workhorse version to bring in a fix for missing
artifacts in the build artifacts browser artifacts in the build artifacts browser
- Get rid of those ugly borders on the file tree view - Get rid of those ugly borders on the file tree view
- Fix updating the runner information when asking for builds
- Bump gitlab_git version to 7.2.24 in order to bring in a performance - Bump gitlab_git version to 7.2.24 in order to bring in a performance
improvement when checking if a repository was empty improvement when checking if a repository was empty
- Add instrumentation for Gitlab::Git::Repository instance methods so we can - Add instrumentation for Gitlab::Git::Repository instance methods so we can
......
...@@ -153,10 +153,11 @@ module API ...@@ -153,10 +153,11 @@ module API
end end
def attributes_for_keys(keys, custom_params = nil) def attributes_for_keys(keys, custom_params = nil)
params_hash = custom_params || params
attrs = {} attrs = {}
keys.each do |key| keys.each do |key|
if params[key].present? or (params.has_key?(key) and params[key] == false) if params_hash[key].present? or (params_hash.has_key?(key) and params_hash[key] == false)
attrs[key] = params[key] attrs[key] = params_hash[key]
end end
end end
ActionController::Parameters.new(attrs).permit! ActionController::Parameters.new(attrs).permit!
......
...@@ -13,13 +13,13 @@ module Ci ...@@ -13,13 +13,13 @@ module Ci
post "register" do post "register" do
authenticate_runner! authenticate_runner!
update_runner_last_contact update_runner_last_contact
update_runner_info
required_attributes! [:token] required_attributes! [:token]
not_found! unless current_runner.active? not_found! unless current_runner.active?
build = Ci::RegisterBuildService.new.execute(current_runner) build = Ci::RegisterBuildService.new.execute(current_runner)
if build if build
update_runner_info
present build, with: Entities::BuildDetails present build, with: Entities::BuildDetails
else else
not_found! not_found!
......
...@@ -34,10 +34,14 @@ module Ci ...@@ -34,10 +34,14 @@ module Ci
@runner ||= Runner.find_by_token(params[:token].to_s) @runner ||= Runner.find_by_token(params[:token].to_s)
end end
def update_runner_info def get_runner_version_from_params
return unless params["info"].present? return unless params["info"].present?
info = attributes_for_keys(["name", "version", "revision", "platform", "architecture"], params["info"]) attributes_for_keys(["name", "version", "revision", "platform", "architecture"], params["info"])
current_runner.update(info) end
def update_runner_info
current_runner.assign_attributes(get_runner_version_from_params)
current_runner.save if current_runner.changed?
end end
def max_artifacts_size def max_artifacts_size
......
...@@ -47,6 +47,7 @@ module Ci ...@@ -47,6 +47,7 @@ module Ci
return forbidden! unless runner return forbidden! unless runner
if runner.id if runner.id
runner.update(get_runner_version_from_params)
present runner, with: Entities::Runner present runner, with: Entities::Runner
else else
not_found! not_found!
......
...@@ -113,6 +113,21 @@ describe Ci::API::API do ...@@ -113,6 +113,21 @@ describe Ci::API::API do
expect(json_response["depends_on_builds"].count).to eq(2) expect(json_response["depends_on_builds"].count).to eq(2)
expect(json_response["depends_on_builds"][0]["name"]).to eq("rspec") expect(json_response["depends_on_builds"][0]["name"]).to eq("rspec")
end end
%w(name version revision platform architecture).each do |param|
context "updates runner #{param}" do
let(:value) { "#{param}_value" }
subject { runner.read_attribute(param.to_sym) }
it do
post ci_api("/builds/register"), token: runner.token, info: { param => value }
expect(response.status).to eq(404)
runner.reload
is_expected.to eq(value)
end
end
end
end end
describe "PUT /builds/:id" do describe "PUT /builds/:id" do
......
...@@ -51,6 +51,20 @@ describe Ci::API::API do ...@@ -51,6 +51,20 @@ describe Ci::API::API do
expect(response.status).to eq(400) expect(response.status).to eq(400)
end end
%w(name version revision platform architecture).each do |param|
context "creates runner with #{param} saved" do
let(:value) { "#{param}_value" }
subject { Ci::Runner.first.read_attribute(param.to_sym) }
it do
post ci_api("/runners/register"), token: registration_token, info: { param => value }
expect(response.status).to eq(201)
is_expected.to eq(value)
end
end
end
end end
describe "DELETE /runners/delete" do describe "DELETE /runners/delete" 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