summaryrefslogtreecommitdiff
path: root/qa/qa/resource
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 14:22:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 14:22:11 +0000
commit0c872e02b2c822e3397515ec324051ff540f0cd5 (patch)
treece2fb6ce7030e4dad0f4118d21ab6453e5938cdd /qa/qa/resource
parentf7e05a6853b12f02911494c4b3fe53d9540d74fc (diff)
downloadgitlab-ce-f7d6ced4f57b4920a666336f5a44d098faade2ea.tar.gz
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'qa/qa/resource')
-rw-r--r--qa/qa/resource/api_fabricator.rb4
-rw-r--r--qa/qa/resource/base.rb6
-rw-r--r--qa/qa/resource/bulk_import_group.rb8
-rw-r--r--qa/qa/resource/group.rb10
-rw-r--r--qa/qa/resource/group_base.rb1
-rw-r--r--qa/qa/resource/issuable.rb3
-rw-r--r--qa/qa/resource/merge_request.rb4
-rw-r--r--qa/qa/resource/protected_branch.rb4
-rw-r--r--qa/qa/resource/reusable.rb4
-rw-r--r--qa/qa/resource/runner.rb166
-rw-r--r--qa/qa/resource/sandbox.rb2
-rw-r--r--qa/qa/resource/ssh_key.rb4
-rw-r--r--qa/qa/resource/user.rb2
13 files changed, 131 insertions, 87 deletions
diff --git a/qa/qa/resource/api_fabricator.rb b/qa/qa/resource/api_fabricator.rb
index d1cfdfbc16c..d82109c1d54 100644
--- a/qa/qa/resource/api_fabricator.rb
+++ b/qa/qa/resource/api_fabricator.rb
@@ -170,9 +170,7 @@ module QA
end
def api_client
- @api_client ||= begin
- Runtime::API::Client.new(:gitlab, is_new_session: !current_url.start_with?('http'), user: api_user)
- end
+ @api_client ||= Runtime::API::Client.new(:gitlab, is_new_session: !current_url.start_with?('http'), user: api_user)
end
def process_api_response(parsed_response)
diff --git a/qa/qa/resource/base.rb b/qa/qa/resource/base.rb
index 4a1a60f4da1..00c002cae9c 100644
--- a/qa/qa/resource/base.rb
+++ b/qa/qa/resource/base.rb
@@ -23,7 +23,7 @@ module QA
end
def fabricate_via_api_unless_fips!
- if QA::Support::FIPS.enabled?
+ if Runtime::Env.personal_access_tokens_disabled?
fabricate!
else
fabricate_via_api!
@@ -31,7 +31,7 @@ module QA
end
def fabricate!(*args, &prepare_block)
- if QA::Support::FIPS.enabled?
+ if Runtime::Env.personal_access_tokens_disabled?
fabricate_via_browser_ui!(*args, &prepare_block)
else
fabricate_via_api!(*args, &prepare_block)
@@ -107,7 +107,7 @@ module QA
Support::FabricationTracker.save_fabrication(:"#{fabrication_method}_fabrication", fabrication_time)
- unless resource.retrieved_from_cache || QA::Support::FIPS.enabled?
+ unless resource.retrieved_from_cache || Runtime::Env.personal_access_tokens_disabled?
Tools::TestResourceDataProcessor.collect(
resource: resource,
info: resource.identifier,
diff --git a/qa/qa/resource/bulk_import_group.rb b/qa/qa/resource/bulk_import_group.rb
index 31db8ae4cc6..19ad5f1faf2 100644
--- a/qa/qa/resource/bulk_import_group.rb
+++ b/qa/qa/resource/bulk_import_group.rb
@@ -11,7 +11,7 @@ module QA
api_client.personal_access_token
end
- attribute :gitlab_address do
+ attribute :source_gitlab_address do
QA::Runtime::Scenario.gitlab_address
end
@@ -28,7 +28,7 @@ module QA
Page::Group::New.perform do |group|
group.switch_to_import_tab
- group.connect_gitlab_instance(gitlab_address, import_access_token)
+ group.connect_gitlab_instance(source_gitlab_address, import_access_token)
end
Page::Group::BulkImport.perform do |import_page|
@@ -50,7 +50,7 @@ module QA
def api_post_body
{
configuration: {
- url: gitlab_address,
+ url: source_gitlab_address,
access_token: import_access_token
},
entities: [
@@ -93,7 +93,7 @@ module QA
# override transformation only for /bulk_imports endpoint which doesn't have web_url in response and
# ignore others so import_id is not overwritten incorrectly
- api_resource[:web_url] = "#{gitlab_address}/#{full_path}"
+ api_resource[:web_url] = "#{QA::Runtime::Scenario.gitlab_address}/#{full_path}"
api_resource[:import_id] = api_resource[:id]
api_resource
end
diff --git a/qa/qa/resource/group.rb b/qa/qa/resource/group.rb
index 9d1a6868562..f53bb531d9a 100644
--- a/qa/qa/resource/group.rb
+++ b/qa/qa/resource/group.rb
@@ -18,7 +18,7 @@ module QA
end
attribute :sandbox do
- if QA::Support::FIPS.enabled?
+ if Runtime::Env.personal_access_tokens_disabled?
Resource::Sandbox.fabricate! do |sandbox|
sandbox.path = Runtime::Namespace.sandbox_name
end
@@ -40,9 +40,7 @@ module QA
sandbox.visit!
Page::Group::Show.perform do |group_show|
- if group_show.has_subgroup?(path)
- group_show.click_subgroup(path)
- else
+ unless group_show.has_subgroup?(path)
group_show.go_to_new_subgroup
Page::Group::New.perform do |group_new|
@@ -56,7 +54,11 @@ module QA
group_show.has_text?(path) &&
group_show.has_new_project_and_new_subgroup_buttons?
end
+ sandbox.visit!
end
+
+ group_show.click_subgroup(path)
+ @id = group_show.group_id
end
end
diff --git a/qa/qa/resource/group_base.rb b/qa/qa/resource/group_base.rb
index f6d1aacca0a..c5b1a4ecea0 100644
--- a/qa/qa/resource/group_base.rb
+++ b/qa/qa/resource/group_base.rb
@@ -24,6 +24,7 @@ module QA
def projects
parse_body(api_get_from("#{api_get_path}/projects")).map do |project|
Project.init do |resource|
+ resource.add_name_uuid = false
resource.api_client = api_client
resource.group = self
resource.id = project[:id]
diff --git a/qa/qa/resource/issuable.rb b/qa/qa/resource/issuable.rb
index 6ebdaac8298..5aee27b46d4 100644
--- a/qa/qa/resource/issuable.rb
+++ b/qa/qa/resource/issuable.rb
@@ -3,6 +3,8 @@
module QA
module Resource
class Issuable < Base
+ using Rainbow
+
# Commentes (notes) path
#
# @return [String]
@@ -14,6 +16,7 @@ module QA
#
# @return [Array]
def comments(auto_paginate: false, attempts: 0)
+ Runtime::Logger.debug("Fetching comments for #{self.class.name.black.bg(:white)} with path '#{api_get_path}'")
return parse_body(api_get_from(api_comments_path)) unless auto_paginate
auto_paginated_response(
diff --git a/qa/qa/resource/merge_request.rb b/qa/qa/resource/merge_request.rb
index fcfda106523..d1d99393ca2 100644
--- a/qa/qa/resource/merge_request.rb
+++ b/qa/qa/resource/merge_request.rb
@@ -199,6 +199,10 @@ module QA
:source_project_id,
:target_project_id,
:merge_status,
+ # we consider mr to still be the same even if users changed
+ :author,
+ :reviewers,
+ :assignees,
# these can differ depending on user fetching mr
:user,
:subscribed,
diff --git a/qa/qa/resource/protected_branch.rb b/qa/qa/resource/protected_branch.rb
index 7b6a3d296c4..879c3a4282c 100644
--- a/qa/qa/resource/protected_branch.rb
+++ b/qa/qa/resource/protected_branch.rb
@@ -51,8 +51,8 @@ module QA
page.select_allowed_to_merge(allowed_to_merge)
page.select_allowed_to_push(allowed_to_push)
page.protect_branch
- else
- page.require_code_owner_approval(branch_name) if require_code_owner_approval
+ elsif require_code_owner_approval
+ page.require_code_owner_approval(branch_name)
end
end
end
diff --git a/qa/qa/resource/reusable.rb b/qa/qa/resource/reusable.rb
index 6a9d0392ba2..536f70b50b4 100644
--- a/qa/qa/resource/reusable.rb
+++ b/qa/qa/resource/reusable.rb
@@ -37,8 +37,8 @@ module QA
resource: self
}
- self.class.resources[reuse_as][:attributes] ||= all_attributes.each_with_object({}) do |attribute_name, attributes|
- attributes[attribute_name] = instance_variable_get("@#{attribute_name}")
+ self.class.resources[reuse_as][:attributes] ||= all_attributes.index_with do |attribute_name|
+ instance_variable_get("@#{attribute_name}")
end
self.class.resources[reuse_as][:tests] << Runtime::Example.location
end
diff --git a/qa/qa/resource/runner.rb b/qa/qa/resource/runner.rb
index da4021f89b7..3c74d8de21a 100644
--- a/qa/qa/resource/runner.rb
+++ b/qa/qa/resource/runner.rb
@@ -3,10 +3,22 @@
module QA
module Resource
class Runner < Base
- attr_writer :name, :tags, :image, :executor, :executor_image
- attr_accessor :config, :token, :run_untagged
+ attributes :id,
+ :active,
+ :paused,
+ :runner_type,
+ :online,
+ :status,
+ :ip_address,
+ :token,
+ :tags,
+ :config,
+ :run_untagged,
+ :name, # This attribute == runner[:description]
+ :image,
+ :executor,
+ :executor_image
- attribute :id
attribute :project do
Project.fabricate_via_api! do |resource|
resource.name = 'project-with-ci-cd'
@@ -14,81 +26,47 @@ module QA
end
end
- def name
- @name || "qa-runner-#{SecureRandom.hex(4)}"
+ def initialize
+ @tags = nil
+ @config = nil
+ @run_untagged = nil
+ @name = "qa-runner-#{SecureRandom.hex(4)}"
+ @image = 'registry.gitlab.com/gitlab-org/gitlab-runner:alpine'
+ @executor = :shell
+ @executor_image = 'registry.gitlab.com/gitlab-org/gitlab-build-images:gitlab-qa-alpine-ruby-2.7'
end
- def image
- @image || 'registry.gitlab.com/gitlab-org/gitlab-runner:alpine'
- end
-
- def executor
- @executor || :shell
- end
-
- def executor_image
- @executor_image || 'registry.gitlab.com/gitlab-org/gitlab-build-images:gitlab-qa-alpine-ruby-2.7'
+ # Initially we only support fabricate
+ # via API
+ def fabricate!
+ fabricate_via_api!
end
+ # Start container and register runner
+ # Fetch via API and populate attributes
+ #
def fabricate_via_api!
- @docker_container = Service::DockerRun::GitlabRunner.new(name).tap do |runner|
- QA::Support::Retrier.retry_on_exception(sleep_interval: 5) do
- runner.pull
- end
-
- runner.token = @token ||= project.runners_token
- runner.address = Runtime::Scenario.gitlab_address
- runner.tags = @tags if @tags
- runner.image = image
- runner.config = config if config
- runner.executor = executor
- runner.executor_image = executor_image if executor == :docker
- runner.run_untagged = run_untagged if run_untagged
- runner.register!
- end
+ start_container_and_register
+ populate_runner_attributes
end
def remove_via_api!
- runners = list_of_runners(tag_list: @tags)
-
- # 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 }
-
- # 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
- 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}"
- end
-
- @id = this_runner[:id]
-
super
ensure
- 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
- auto_paginated_response(request_url(url))
+ @docker_container.remove!
end
def reload!
- super if method(:running?).super_method.call
+ populate_runner_attributes
end
def api_delete_path
"/runners/#{id}"
end
- def api_get_path; end
+ def api_get_path
+ "/runners"
+ end
def api_post_path
"/runners"
@@ -96,15 +74,75 @@ module QA
def api_post_body; end
+ def not_found_by_tags?
+ url = "#{api_get_path}?tag_list=#{tags.compact.join(',')}"
+ auto_paginated_response(request_url(url)).empty?
+ end
+
+ def runners_list
+ runners_list = nil
+ url = tags ? "#{api_get_path}?tag_list=#{tags.compact.join(',')}" : api_get_path
+ Runtime::Logger.info('Looking for list of runners via API...')
+ Support::Retrier.retry_until(max_duration: 60, sleep_interval: 1) do
+ runners_list = auto_paginated_response(request_url(url))
+ runners_list.present?
+ end
+
+ runners_list
+ end
+
+ def wait_until_online
+ Runtime::Logger.info('Waiting for runner to come online...')
+ Support::Retrier.retry_until(max_duration: 60, sleep_interval: 1) do
+ this_runner[:status] == 'online'
+ end
+ end
+
+ def restart
+ Runtime::Logger.info("Restarting runner container #{name}...")
+ @docker_container.restart
+ wait_until_online
+ end
+
private
- def dump_logs
- if @docker_container.running?
- @docker_container.logs
- else
- QA::Runtime::Logger.debug("No runner container found named #{name}")
+ def start_container_and_register
+ @docker_container = Service::DockerRun::GitlabRunner.new(name).tap do |runner|
+ Support::Retrier.retry_on_exception(sleep_interval: 5) do
+ runner.pull
+ end
+
+ runner.token = @token ||= project.runners_token
+ runner.address = Runtime::Scenario.gitlab_address
+ runner.tags = tags if tags
+ runner.image = image
+ runner.config = config if config
+ runner.executor = executor
+ runner.executor_image = executor_image if executor == :docker
+ runner.run_untagged = run_untagged if run_untagged
+ runner.register!
end
end
+
+ def this_runner
+ runner = nil
+ Support::Retrier.retry_until(max_duration: 60, sleep_interval: 1) do
+ runner = runners_list.find { |runner| runner[:description] == name }
+ !runner.nil?
+ end
+ runner
+ end
+
+ def populate_runner_attributes
+ runner = this_runner
+ @id = runner[:id]
+ @active = runner[:active]
+ @paused = runner[:paused]
+ @runner_type = runner[:typed]
+ @online = runner[:online]
+ @status = runner[:status]
+ @ip_address = runner[:ip_address]
+ end
end
end
end
diff --git a/qa/qa/resource/sandbox.rb b/qa/qa/resource/sandbox.rb
index 18526448b00..f5cd51bf9cf 100644
--- a/qa/qa/resource/sandbox.rb
+++ b/qa/qa/resource/sandbox.rb
@@ -10,7 +10,7 @@ module QA
class << self
# Force top level group creation via UI if test is executed on dot_com environment
def fabricate!(*args, &prepare_block)
- if Specs::Helpers::ContextSelector.dot_com? || QA::Support::FIPS.enabled?
+ if Specs::Helpers::ContextSelector.dot_com? || Runtime::Env.personal_access_tokens_disabled?
return fabricate_via_browser_ui!(*args, &prepare_block)
end
diff --git a/qa/qa/resource/ssh_key.rb b/qa/qa/resource/ssh_key.rb
index dd475d7fa66..1c142058908 100644
--- a/qa/qa/resource/ssh_key.rb
+++ b/qa/qa/resource/ssh_key.rb
@@ -3,14 +3,12 @@
module QA
module Resource
class SSHKey < Base
- extend Forwardable
-
attr_reader :title
attr_accessor :expires_at
attribute :id
- def_delegators :key, :private_key, :public_key, :md5_fingerprint, :sha256_fingerprint
+ delegate :private_key, :public_key, :md5_fingerprint, :sha256_fingerprint, to: :key
def initialize
self.title = Time.now.to_f
diff --git a/qa/qa/resource/user.rb b/qa/qa/resource/user.rb
index c8babbc0b16..0398509396f 100644
--- a/qa/qa/resource/user.rb
+++ b/qa/qa/resource/user.rb
@@ -155,7 +155,7 @@ module QA
end
def self.fabricate_or_use(username = nil, password = nil)
- if Runtime::Env.signup_disabled? || !QA::Support::FIPS.enabled?
+ if Runtime::Env.signup_disabled? && !Runtime::Env.personal_access_tokens_disabled?
fabricate_via_api! do |user|
user.username = username
user.password = password