Skip to content
Snippets Groups Projects
Commit 80049bfe authored by Will Meek's avatar Will Meek :floppy_disk:
Browse files

Remove Sanity Version

No longer needed for nightlies
parent de097b18
No related branches found
No related tags found
1 merge request!1328Remove Sanity Version
......@@ -55,7 +55,6 @@ Metrics/AbcSize:
- 'lib/gitlab/qa/scenario/test/integration/registry_with_cdn.rb'
- 'lib/gitlab/qa/scenario/test/integration/smtp.rb'
- 'lib/gitlab/qa/scenario/test/integration/suggested_reviewer.rb'
- 'lib/gitlab/qa/scenario/test/sanity/version.rb'
# Offense count: 2
# Configuration parameters: CheckIdentifiers, CheckConstants, CheckVariables, CheckStrings, CheckSymbols, CheckComments, CheckFilepaths, FlaggedTerms.
......
# frozen_string_literal: true
require 'json'
require 'net/http'
require 'cgi'
require 'time'
module Gitlab
module QA
module Scenario
module Test
module Sanity
# This test checks that the sha_version of a GitLab was authored in
# the window defined by the `weekday_hours` method.
# We perform a single API call to get the commit
class Version < Scenario::Template
SOURCE_MAP = {
'git@dev.gitlab.org:gitlab/gitlab-ee.git' => {
host: 'dev.gitlab.org',
project: 'gitlab/gitlab-ee'
},
'git@dev.gitlab.org:gitlab/gitlabhq.git' => {
host: 'dev.gitlab.org',
project: 'gitlab/gitlabhq'
},
'git@gitlab.com:gitlab-org/gitlab.git' => {
host: 'gitlab.com',
project: 'gitlab-org/gitlab'
},
'git@gitlab.com:gitlab-org/gitlab-foss.git' => {
host: 'gitlab.com',
project: 'gitlab-org/gitlab-foss'
}
}.freeze
def perform(release = 'ce')
version = Component::Gitlab.perform do |gitlab|
gitlab.release = release
gitlab.act do
pull
rails_version
end
end
project = SOURCE_MAP[version[:source]][:project]
host = SOURCE_MAP[version[:source]][:host]
sha = version[:sha]
commit = api_commit_detail(host, project, sha)
if commit_within_hours?(commit['created_at'], weekday_hours(commit['created_at']))
puts "Found commit #{sha} in recent history of #{project} on #{host}"
else
puts "Did not find #{sha} in recent history of #{project} on #{host}"
exit 1
end
end
private
def weekday_hours(date_string)
case Date.parse(date_string).wday
# Sunday
when 0
48
# Monday
when 1
72
else
24
end
end
def commit_within_hours?(commit_time_string, hours)
Time.at(Time.parse(commit_time_string).utc).to_datetime > Time.at((Time.now - (hours * 60 * 60)).utc).to_datetime
end
def api_commit_detail(host, project, sha)
url = "https://#{host}/api/v4/projects/#{CGI.escape(project)}/repository/commits/#{sha}"
if host == 'dev.gitlab.org'
Runtime::Env.require_qa_dev_access_token!
url = "#{url}?private_token=#{Runtime::Env.qa_dev_access_token}"
end
JSON.parse(Net::HTTP.get(URI(url)))
end
end
end
end
end
end
end
# frozen_string_literal: true
require 'json'
module Gitlab
module QA
module Scenario
module Test
module Sanity
RSpec.describe Version do
let(:mock_sha) { 'abcde12345' }
let(:twenty_three_hours_ago) { (Time.now - (23 * 60 * 60)).strftime('%FT%T') }
let(:twenty_five_hours_ago) { (Time.now - (25 * 60 * 60)).strftime('%FT%T') }
let(:twenty_three_hours_ago_json) { { 'created_at' => twenty_three_hours_ago } }
let(:twenty_five_hours_ago_json) { { 'created_at' => twenty_five_hours_ago } }
let(:ce_string) { 'gitlab-org/gitlab-foss' }
let(:ee_string) { 'gitlab-org/gitlab' }
let(:dev_ee_string) { 'gitlab/gitlab-ee' }
let(:main_ee_repo) { 'git@gitlab.com:gitlab-org/gitlab.git' }
let(:main_ce_repo) { 'git@gitlab.com:gitlab-org/gitlab-foss.git' }
let(:dev_ee_repo) { 'git@dev.gitlab.org:gitlab/gitlab-ee.git' }
let(:host) { 'gitlab.com' }
let(:dev_host) { 'dev.gitlab.org' }
before do
QA::Runtime::Scenario.define(:omnibus_configuration, QA::Runtime::OmnibusConfiguration.new)
Runtime::Scenario.define(:seed_db, false)
Runtime::Scenario.define(:seed_admin_token, true)
Runtime::Scenario.define(:omnibus_exec_commands, [])
Runtime::Scenario.define(:skip_server_hooks, false)
end
RSpec.shared_examples "weekday_hours" do |weekday_string, hours_int|
let(:component_under_test) { described_class.new }
context "with #{weekday_string}" do
subject { component_under_test.send(:weekday_hours, weekday_string) }
it { is_expected.to eq(hours_int) }
end
end
describe '#perform' do
it 'throws an error with incorrect version specified' do
expect { described_class.perform('foo') }.to raise_error(
Gitlab::QA::Release::InvalidImageNameError,
"The release image name 'foo' does not have the expected format."
)
end
context 'with a version' do
before do
allow(Gitlab::QA::Component::Gitlab).to receive(:perform).and_return(version)
end
context 'with a ce release' do
let(:version) { { source: main_ce_repo, sha: mock_sha } }
it 'defaults to foss when no release specified' do
expect_any_instance_of(described_class).to receive(:api_commit_detail).with(host, ce_string,
mock_sha).and_return(twenty_three_hours_ago_json)
described_class.perform
end
it 'passes when commit is less than 24 hours old' do
expect_any_instance_of(described_class).to receive(:api_commit_detail).with(host, ce_string,
mock_sha).and_return(twenty_three_hours_ago_json)
expect_any_instance_of(described_class).to receive(:weekday_hours).with(twenty_three_hours_ago_json['created_at']).and_return(24)
expect do
described_class.perform('ce')
end.to output("Found commit #{mock_sha} in recent history of #{ce_string} on #{host}\n").to_stdout
end
end
context 'with an ee release' do
let(:version) { { source: main_ee_repo, sha: mock_sha } }
it 'fails when commit is more than 24 hours old' do
expect_any_instance_of(described_class).to receive(:api_commit_detail).with(host, ee_string,
mock_sha).and_return(twenty_five_hours_ago_json)
expect_any_instance_of(described_class).to receive(:weekday_hours).with(twenty_five_hours_ago_json['created_at']).and_return(24)
expect do
expect do
described_class.perform('ee')
end.to output("Did not find #{mock_sha} in recent history of #{ee_string}\n").to_stdout
end.to raise_error(SystemExit)
end
end
context 'with a dev source' do
let(:mock_sha) { '12345abcde' }
let(:version) { { source: dev_ee_repo, sha: mock_sha } }
it 'finds commits from the dev repo' do
expect_any_instance_of(described_class).to receive(:api_commit_detail).with(dev_host,
dev_ee_string, mock_sha).and_return(twenty_three_hours_ago_json)
expect_any_instance_of(described_class).to receive(:weekday_hours).with(twenty_three_hours_ago_json['created_at']).and_return(24)
expect do
described_class.perform('ee')
end.to output("Found commit #{mock_sha} in recent history of #{dev_ee_string} on #{dev_host}\n").to_stdout
end
end
end
end
describe '#weekday_hours' do
# Monday to Sunday
# This date is a Monday, returns 72 hours
it_behaves_like "weekday_hours", "2021-02-01", 72
# Tuesday to Saturday, return 24 hours
it_behaves_like "weekday_hours", "2021-02-02", 24
it_behaves_like "weekday_hours", "2021-02-03", 24
it_behaves_like "weekday_hours", "2021-02-04", 24
it_behaves_like "weekday_hours", "2021-02-05", 24
it_behaves_like "weekday_hours", "2021-02-06", 24
# This date is a Sunday, returns 48 hours
it_behaves_like "weekday_hours", "2021-02-07", 48
end
describe '#api_commit_detail' do
let(:component_under_test) { described_class.new }
it 'performs a single API call' do
test_uri = URI("https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/repository/commits/#{mock_sha}")
expect(Net::HTTP).to receive(:get).once.with(test_uri).and_return(JSON.generate(twenty_three_hours_ago_json))
component_under_test.send(:api_commit_detail, 'gitlab.com', ee_string, mock_sha)
end
end
describe '#commit_within_hours?' do
let(:component_under_test) { described_class.new }
it 'twenty three hours with 24 hours returns true' do
expect(component_under_test.send(:commit_within_hours?, twenty_three_hours_ago, 24)).to be(true)
end
it 'twenty three hours with 22 hours returns false' do
expect(component_under_test.send(:commit_within_hours?, twenty_three_hours_ago, 22)).to be(false)
end
it 'twenty five hours with 24 hours returns false' do
expect(component_under_test.send(:commit_within_hours?, twenty_five_hours_ago, 24)).to be(false)
end
it 'twenty five hours with 26 hours returns true' do
expect(component_under_test.send(:commit_within_hours?, twenty_five_hours_ago, 26)).to be(true)
end
end
end
end
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment