summaryrefslogtreecommitdiff
path: root/qa
diff options
context:
space:
mode:
Diffstat (limited to 'qa')
-rw-r--r--qa/.gitignore1
-rw-r--r--qa/qa.rb1
-rw-r--r--qa/qa/resource/api_fabricator.rb2
-rw-r--r--qa/qa/resource/group.rb4
-rw-r--r--qa/qa/runtime/ip_address.rb33
-rw-r--r--qa/qa/support/api.rb1
6 files changed, 41 insertions, 1 deletions
diff --git a/qa/.gitignore b/qa/.gitignore
index b0ae074ac07..7bc4effd8a8 100644
--- a/qa/.gitignore
+++ b/qa/.gitignore
@@ -1,3 +1,4 @@
tmp/
.ruby-version
+.ruby-gemset
urls.yml
diff --git a/qa/qa.rb b/qa/qa.rb
index 178771a0275..249736fc8b0 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -35,6 +35,7 @@ module QA
autoload :Logger, 'qa/runtime/logger'
autoload :GPG, 'qa/runtime/gpg'
autoload :MailHog, 'qa/runtime/mail_hog'
+ autoload :IPAddress, 'qa/runtime/ip_address'
module API
autoload :Client, 'qa/runtime/api/client'
diff --git a/qa/qa/resource/api_fabricator.rb b/qa/qa/resource/api_fabricator.rb
index 3862bd68c40..e6057433b55 100644
--- a/qa/qa/resource/api_fabricator.rb
+++ b/qa/qa/resource/api_fabricator.rb
@@ -100,7 +100,7 @@ module QA
url = Runtime::API::Request.new(api_client, api_delete_path).url
response = delete(url)
- unless response.code == HTTP_STATUS_NO_CONTENT
+ unless [HTTP_STATUS_NO_CONTENT, HTTP_STATUS_ACCEPTED].include? response.code
raise ResourceNotDeletedError, "Resource at #{url} could not be deleted (#{response.code}): `#{response}`."
end
diff --git a/qa/qa/resource/group.rb b/qa/qa/resource/group.rb
index 7511396251d..c12e9dd146b 100644
--- a/qa/qa/resource/group.rb
+++ b/qa/qa/resource/group.rb
@@ -70,6 +70,10 @@ module QA
}
end
+ def api_delete_path
+ "/groups/#{id}"
+ end
+
def full_path
sandbox.path + ' / ' + path
end
diff --git a/qa/qa/runtime/ip_address.rb b/qa/qa/runtime/ip_address.rb
new file mode 100644
index 00000000000..f370882e5c7
--- /dev/null
+++ b/qa/qa/runtime/ip_address.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+require 'socket'
+
+module QA
+ module Runtime
+ module IPAddress
+ include Support::Api
+ HostUnreachableError = Class.new(StandardError)
+
+ LOOPBACK_ADDRESS = '127.0.0.1'
+ PUBLIC_IP_ADDRESS_API = "https://api.ipify.org"
+
+ def fetch_current_ip_address
+ # When running on CI against a live environment such as staging.gitlab.com,
+ # we use the public facing IP address
+ ip_address = if Env.running_in_ci? && !URI.parse(Scenario.gitlab_address).host.include?('test')
+ response = get(PUBLIC_IP_ADDRESS_API)
+ raise HostUnreachableError, "#{PUBLIC_IP_ADDRESS_API} is unreachable" unless response.code == Support::Api::HTTP_STATUS_OK
+
+ response.body
+ elsif page.current_host.include?('localhost')
+ LOOPBACK_ADDRESS
+ else
+ Socket.ip_address_list.detect { |intf| intf.ipv4_private? }.ip_address
+ end
+
+ QA::Runtime::Logger.info "Current IP address: #{ip_address}"
+
+ ip_address
+ end
+ end
+ end
+end
diff --git a/qa/qa/support/api.rb b/qa/qa/support/api.rb
index cd496efb4db..90924ffd40e 100644
--- a/qa/qa/support/api.rb
+++ b/qa/qa/support/api.rb
@@ -6,6 +6,7 @@ module QA
HTTP_STATUS_OK = 200
HTTP_STATUS_CREATED = 201
HTTP_STATUS_NO_CONTENT = 204
+ HTTP_STATUS_ACCEPTED = 202
def post(url, payload)
RestClient::Request.execute(