Commit 6ba68036 authored by Alessio Caiazza's avatar Alessio Caiazza Committed by Sean McGivern

Fix gitaly version check in case of autodeploy

Gitaly::Server#up_to_date? now can detect gitaly version based on SHA,
this will ensure an autodeployed gitaly will be correctly identified as
up to date
parent abe86568
......@@ -2,6 +2,8 @@
module Gitaly
class Server
SHA_VERSION_REGEX = /\A\d+\.\d+\.\d+-\d+-g([a-f0-9]{8})\z/.freeze
class << self
def all
Gitlab.config.repositories.storages.keys.map { |s| Gitaly::Server.new(s) }
......@@ -30,9 +32,10 @@ module Gitaly
info.git_version
end
def up_to_date?
server_version == Gitlab::GitalyClient.expected_server_version
def expected_version?
server_version == Gitlab::GitalyClient.expected_server_version || matches_sha?
end
alias_method :up_to_date?, :expected_version?
def read_writeable?
readable? && writeable?
......@@ -62,6 +65,13 @@ module Gitaly
@storage_status ||= info.storage_statuses.find { |s| s.storage_name == storage }
end
def matches_sha?
match = server_version.match(SHA_VERSION_REGEX)
return false unless match
Gitlab::GitalyClient.expected_server_version.start_with?(match[1])
end
def info
@info ||=
begin
......
......@@ -65,4 +65,26 @@ describe Gitaly::Server do
end
end
end
describe '#expected_version?' do
using RSpec::Parameterized::TableSyntax
where(:expected_version, :server_version, :result) do
'1.1.1' | '1.1.1' | true
'1.1.2' | '1.1.1' | false
'1.73.0' | '1.73.0-18-gf756ebe2' | false
'594c3ea3e0e5540e5915bd1c49713a0381459dd6' | '1.55.6-45-g594c3ea3' | true
'594c3ea3e0e5540e5915bd1c49713a0381459dd6' | '1.55.6-46-gabc123ff' | false
'594c3ea3e0e5540e5915bd1c49713a0381459dd6' | '1.55.6' | false
end
with_them do
it do
allow(Gitlab::GitalyClient).to receive(:expected_server_version).and_return(expected_version)
allow(server).to receive(:server_version).and_return(server_version)
expect(server.expected_version?).to eq(result)
end
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