From 4e119670648b00857afb8877a05c035db41efda8 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Mon, 2 Oct 2023 12:47:08 +1300 Subject: [PATCH 01/36] Created a seperate base job --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3c923dbf0b..2d3abec1e1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -55,6 +55,8 @@ variables: # STRICT_VERSIONS is used in RSpecs to ensure exact version match for tools like "helm" and "kubectl" STRICT_VERSIONS: "true" KUBE_CRD_SCHEMA_URL: "https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/v3/apis__apiextensions.k8s.io__v1_openapi.json" + REVIEW_JOB_REGEX_PATTERN: "review_(gke[0-9]{3}|eks)" + STABLE_JOB_REGEX_PATTERN: "stable_(gke[0-9]{3}|eks)" HELM_DEFAULT_SETTINGS: | certmanager-issuer: email: support@gitlab.com @@ -519,6 +521,7 @@ stop_review_eks: # or `canary` deploys, or you simply want more control over when you deploy # to production, uncomment the `when: manual` line in the `production` job. + .stable: stage: stable extends: .source_autodevops -- GitLab From 11bf50445a29f15388fcda27b67d904dc15b1873 Mon Sep 17 00:00:00 2001 From: Vishal Patel Date: Tue, 3 Oct 2023 20:01:02 +0000 Subject: [PATCH 02/36] Removing debugging commands --- .gitlab-ci.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2d3abec1e1..af94971261 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -521,6 +521,40 @@ stop_review_eks: # or `canary` deploys, or you simply want more control over when you deploy # to production, uncomment the `when: manual` line in the `production` job. +.run_script: + extends: .source_autodevops + variables: + JOB_REGEX_PATTERN + script: + - echo $CI_ENVIRONMENT_SLUG + - echo $CI_JOB_NAME + - mkdir -p $(dirname "${VARIABLES_FILE}") + - set_context + - check_kube_domain + - > + if [[ $CI_JOB_NAME =~ $REVIEW_JOB_REGEX_PATTERN ]]; then + kubectl version + fi + - ensure_namespace + - create_secret + - deploy + - wait_for_deploy + - > + if [[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]]; then + check_domain_ip + fi + - restart_toolbox + # Setting the following env vars according the the job .stable or .review_template calling this base job + - echo "export QA_ENVIRONMENT_URL=$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "gitlab" || echo "gitlab-${HOST_SUFFIX}").$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" + - echo "export GITLAB_ROOT_DOMAIN=$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "$KUBE_INGRESS_BASE_DOMAIN" || echo "$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN")" >> "${VARIABLES_FILE}" + - > + if [[ $CI_JOB_NAME =~ $REVIEW_JOB_REGEX_PATTERN ]]; then + echo "export GITLAB_URL=gitlab-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" + echo "export REGISTRY_URL=registry-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" + fi + - echo "export S3_ENDPOINT=https://$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "minio" || echo "minio-${HOST_SUFFIX}").$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" + - kubectl wait pods -n $NAMESPACE -l app=toolbox,release=$RELEASE_NAME --for condition=Ready --timeout=60s + - echo "export QA_GITLAB_REVISION=`kubectl exec -i $(kubectl get pods -lrelease=$RELEASE_NAME,app=toolbox -o custom-columns=":metadata.name") -c toolbox -- cat /srv/gitlab/REVISION`" >> "${VARIABLES_FILE}" .stable: stage: stable -- GitLab From a82d47f7f63cd8fd2c64d7416b1db478e714158a Mon Sep 17 00:00:00 2001 From: Vishal Patel Date: Sun, 8 Oct 2023 21:32:31 +0000 Subject: [PATCH 03/36] Removing unwanted JOB_REGEX_PATTERN --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index af94971261..92d37d8125 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -524,7 +524,6 @@ stop_review_eks: .run_script: extends: .source_autodevops variables: - JOB_REGEX_PATTERN script: - echo $CI_ENVIRONMENT_SLUG - echo $CI_JOB_NAME -- GitLab From 617def90d652273b850ba97c0d599ba6f7d7f30d Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Mon, 2 Oct 2023 10:32:01 +1300 Subject: [PATCH 04/36] Added command for debugging --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 92d37d8125..738fc0a91a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -538,6 +538,7 @@ stop_review_eks: - create_secret - deploy - wait_for_deploy + - echo $CI_JOB_NAME - > if [[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]]; then check_domain_ip -- GitLab From a6913b848c1609a0764fe01a283c4896c650c611 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Mon, 16 Oct 2023 16:23:17 +1300 Subject: [PATCH 05/36] Removed echos debg --- .gitlab-ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 738fc0a91a..cfd2dcfedc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -525,8 +525,6 @@ stop_review_eks: extends: .source_autodevops variables: script: - - echo $CI_ENVIRONMENT_SLUG - - echo $CI_JOB_NAME - mkdir -p $(dirname "${VARIABLES_FILE}") - set_context - check_kube_domain @@ -538,7 +536,6 @@ stop_review_eks: - create_secret - deploy - wait_for_deploy - - echo $CI_JOB_NAME - > if [[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]]; then check_domain_ip -- GitLab From 31e3e28df6a5ede082321b16f4ec1a01837aed6c Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Mon, 16 Oct 2023 16:36:33 +1300 Subject: [PATCH 06/36] Moving to common jobs --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cfd2dcfedc..bf033c4962 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -521,13 +521,13 @@ stop_review_eks: # or `canary` deploys, or you simply want more control over when you deploy # to production, uncomment the `when: manual` line in the `production` job. + + .run_script: extends: .source_autodevops variables: script: - - mkdir -p $(dirname "${VARIABLES_FILE}") - - set_context - - check_kube_domain + - !reference [.set_up_varfile_and_kubecontext:script] - > if [[ $CI_JOB_NAME =~ $REVIEW_JOB_REGEX_PATTERN ]]; then kubectl version -- GitLab From 8e4526c3792a7cc47f35d6c7a2e5d232aa623e64 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Mon, 16 Oct 2023 16:39:44 +1300 Subject: [PATCH 07/36] Moving to common jobs --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bf033c4962..5775bba647 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -282,7 +282,7 @@ pin_image_versions: - set_context - check_kube_domain -.set_up_namespace_secret_and_deploy: +.set_up_namespace_secret_and_deploy: &set_up_namespace_secret_and_deploy script: - ensure_namespace - create_secret -- GitLab From 809e9ad64b1c144d2deff112ff1d41bbb8d2c587 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Mon, 16 Oct 2023 16:41:25 +1300 Subject: [PATCH 08/36] Moving to common jobs --- .gitlab-ci.yml | 58 +++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5775bba647..b6573a2836 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -523,35 +523,35 @@ stop_review_eks: -.run_script: - extends: .source_autodevops - variables: - script: - - !reference [.set_up_varfile_and_kubecontext:script] - - > - if [[ $CI_JOB_NAME =~ $REVIEW_JOB_REGEX_PATTERN ]]; then - kubectl version - fi - - ensure_namespace - - create_secret - - deploy - - wait_for_deploy - - > - if [[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]]; then - check_domain_ip - fi - - restart_toolbox - # Setting the following env vars according the the job .stable or .review_template calling this base job - - echo "export QA_ENVIRONMENT_URL=$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "gitlab" || echo "gitlab-${HOST_SUFFIX}").$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - - echo "export GITLAB_ROOT_DOMAIN=$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "$KUBE_INGRESS_BASE_DOMAIN" || echo "$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN")" >> "${VARIABLES_FILE}" - - > - if [[ $CI_JOB_NAME =~ $REVIEW_JOB_REGEX_PATTERN ]]; then - echo "export GITLAB_URL=gitlab-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - echo "export REGISTRY_URL=registry-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - fi - - echo "export S3_ENDPOINT=https://$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "minio" || echo "minio-${HOST_SUFFIX}").$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - - kubectl wait pods -n $NAMESPACE -l app=toolbox,release=$RELEASE_NAME --for condition=Ready --timeout=60s - - echo "export QA_GITLAB_REVISION=`kubectl exec -i $(kubectl get pods -lrelease=$RELEASE_NAME,app=toolbox -o custom-columns=":metadata.name") -c toolbox -- cat /srv/gitlab/REVISION`" >> "${VARIABLES_FILE}" +# .run_script: +# extends: .source_autodevops +# variables: +# script: +# - !reference [.set_up_varfile_and_kubecontext:script] +# - > +# if [[ $CI_JOB_NAME =~ $REVIEW_JOB_REGEX_PATTERN ]]; then +# kubectl version +# fi +# - ensure_namespace +# - create_secret +# - deploy +# - wait_for_deploy +# - > +# if [[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]]; then +# check_domain_ip +# fi +# - restart_toolbox +# # Setting the following env vars according the the job .stable or .review_template calling this base job +# - echo "export QA_ENVIRONMENT_URL=$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "gitlab" || echo "gitlab-${HOST_SUFFIX}").$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" +# - echo "export GITLAB_ROOT_DOMAIN=$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "$KUBE_INGRESS_BASE_DOMAIN" || echo "$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN")" >> "${VARIABLES_FILE}" +# - > +# if [[ $CI_JOB_NAME =~ $REVIEW_JOB_REGEX_PATTERN ]]; then +# echo "export GITLAB_URL=gitlab-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" +# echo "export REGISTRY_URL=registry-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" +# fi +# - echo "export S3_ENDPOINT=https://$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "minio" || echo "minio-${HOST_SUFFIX}").$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" +# - kubectl wait pods -n $NAMESPACE -l app=toolbox,release=$RELEASE_NAME --for condition=Ready --timeout=60s +# - echo "export QA_GITLAB_REVISION=`kubectl exec -i $(kubectl get pods -lrelease=$RELEASE_NAME,app=toolbox -o custom-columns=":metadata.name") -c toolbox -- cat /srv/gitlab/REVISION`" >> "${VARIABLES_FILE}" .stable: stage: stable -- GitLab From 368d99e50cbdb6eaccd493e925b21a49f2cbe8c8 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Tue, 17 Oct 2023 10:27:47 +1300 Subject: [PATCH 09/36] Removing script section from anchors --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b6573a2836..5bb194fe53 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -283,7 +283,6 @@ pin_image_versions: - check_kube_domain .set_up_namespace_secret_and_deploy: &set_up_namespace_secret_and_deploy - script: - ensure_namespace - create_secret - deploy -- GitLab From d36b42dcac301cd25e7da37f824f4e6cb16cafbb Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Tue, 17 Oct 2023 14:55:42 +1300 Subject: [PATCH 10/36] Checking another solution --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5bb194fe53..ba7c3f08f0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -282,7 +282,8 @@ pin_image_versions: - set_context - check_kube_domain -.set_up_namespace_secret_and_deploy: &set_up_namespace_secret_and_deploy +.set_up_namespace_secret_and_deploy: + script: - ensure_namespace - create_secret - deploy -- GitLab From dedd0a5fc927ddfff9190f4f14edb569cbcd53d2 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Tue, 17 Oct 2023 15:09:38 +1300 Subject: [PATCH 11/36] Moved common script to separate jobs --- .gitlab-ci.yml | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ba7c3f08f0..0f41a307f8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -521,38 +521,6 @@ stop_review_eks: # or `canary` deploys, or you simply want more control over when you deploy # to production, uncomment the `when: manual` line in the `production` job. - - -# .run_script: -# extends: .source_autodevops -# variables: -# script: -# - !reference [.set_up_varfile_and_kubecontext:script] -# - > -# if [[ $CI_JOB_NAME =~ $REVIEW_JOB_REGEX_PATTERN ]]; then -# kubectl version -# fi -# - ensure_namespace -# - create_secret -# - deploy -# - wait_for_deploy -# - > -# if [[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]]; then -# check_domain_ip -# fi -# - restart_toolbox -# # Setting the following env vars according the the job .stable or .review_template calling this base job -# - echo "export QA_ENVIRONMENT_URL=$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "gitlab" || echo "gitlab-${HOST_SUFFIX}").$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" -# - echo "export GITLAB_ROOT_DOMAIN=$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "$KUBE_INGRESS_BASE_DOMAIN" || echo "$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN")" >> "${VARIABLES_FILE}" -# - > -# if [[ $CI_JOB_NAME =~ $REVIEW_JOB_REGEX_PATTERN ]]; then -# echo "export GITLAB_URL=gitlab-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" -# echo "export REGISTRY_URL=registry-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" -# fi -# - echo "export S3_ENDPOINT=https://$([[ $CI_JOB_NAME =~ $STABLE_JOB_REGEX_PATTERN ]] && echo "minio" || echo "minio-${HOST_SUFFIX}").$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" -# - kubectl wait pods -n $NAMESPACE -l app=toolbox,release=$RELEASE_NAME --for condition=Ready --timeout=60s -# - echo "export QA_GITLAB_REVISION=`kubectl exec -i $(kubectl get pods -lrelease=$RELEASE_NAME,app=toolbox -o custom-columns=":metadata.name") -c toolbox -- cat /srv/gitlab/REVISION`" >> "${VARIABLES_FILE}" - .stable: stage: stable extends: .source_autodevops -- GitLab From 2295d4ccb2c1dc35c1483dbb097a5a4dcff91328 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Tue, 17 Oct 2023 15:38:48 +1300 Subject: [PATCH 12/36] Removed unused vars --- .gitlab-ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0f41a307f8..3d4762215a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -55,8 +55,6 @@ variables: # STRICT_VERSIONS is used in RSpecs to ensure exact version match for tools like "helm" and "kubectl" STRICT_VERSIONS: "true" KUBE_CRD_SCHEMA_URL: "https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/v3/apis__apiextensions.k8s.io__v1_openapi.json" - REVIEW_JOB_REGEX_PATTERN: "review_(gke[0-9]{3}|eks)" - STABLE_JOB_REGEX_PATTERN: "stable_(gke[0-9]{3}|eks)" HELM_DEFAULT_SETTINGS: | certmanager-issuer: email: support@gitlab.com -- GitLab From bcd726c847b7cb5468b93db4e0a682ff15b1d528 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 11:48:27 +1300 Subject: [PATCH 13/36] first commit --- Gemfile | 1 + Gemfile.lock | 4 ++ spec/features/backups_spec.rb | 98 +++++++++++++++++++++-------------- spec/spec_helper.rb | 1 + 4 files changed, 66 insertions(+), 38 deletions(-) diff --git a/Gemfile b/Gemfile index 03834ce616..779abd6f6e 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ group :test do gem 'knapsack' gem 'tomlrb' gem 'fugit' + gem 'net-http' end group :rubocop do diff --git a/Gemfile.lock b/Gemfile.lock index f71af222b8..fcd44ebe0c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -149,6 +149,8 @@ GEM multi_json (1.13.1) multi_xml (0.6.0) nap (1.1.0) + net-http (0.4.0) + uri no_proxy_fix (0.1.2) nokogiri (1.13.8) mini_portile2 (~> 2.8.0) @@ -274,6 +276,7 @@ GEM mprelude (~> 0.1.0) parser (>= 2.6.5) procto (~> 0.0.2) + uri (0.13.0) webrick (1.7.0) xpath (3.2.0) nokogiri (~> 1.8) @@ -293,6 +296,7 @@ DEPENDENCIES gitlab-styles (~> 9.0) hash-deep-merge knapsack + net-http pry rake rspec diff --git a/spec/features/backups_spec.rb b/spec/features/backups_spec.rb index 92e3bf1c75..efe5aaff2f 100644 --- a/spec/features/backups_spec.rb +++ b/spec/features/backups_spec.rb @@ -1,61 +1,83 @@ require 'spec_helper' require 'open-uri' +require 'net/http' describe "Restoring a backup" do - before(:all) do - stdout, status = wait_for_dependencies - fail stdout unless status.success? + # before(:all) do + # stdout, status = wait_for_dependencies + # fail stdout unless status.success? - wait_until_app_ready - ensure_backups_on_object_storage + # wait_until_app_ready + # ensure_backups_on_object_storage - stdout, status = gitaly_purge_storage - fail stdout unless status.success? + # stdout, status = gitaly_purge_storage + # fail stdout unless status.success? - stdout, status = restore_from_backup(skip: 'repositories') - fail stdout unless status.success? + # stdout, status = restore_from_backup(skip: 'repositories') + # fail stdout unless status.success? - # scale the Rails deployments to 0 - scale_rails_down - # wait for rollout to complete (change in replicas) - wait_for_rails_rollout + # # scale the Rails deployments to 0 + # scale_rails_down + # # wait for rollout to complete (change in replicas) + # wait_for_rails_rollout - # We run migrations once early to get the db into a place where we can set the runner token and restore repos - # Ignore errors, we will run the migrations again after the token - stdout, status = run_migrations - warn "WARNING: Migrations did not succeed:\n#{stdout}" unless status.success? + # # We run migrations once early to get the db into a place where we can set the runner token and restore repos + # # Ignore errors, we will run the migrations again after the token + # stdout, status = run_migrations + # warn "WARNING: Migrations did not succeed:\n#{stdout}" unless status.success? - stdout, status = restore_from_backup(skip: 'db') - fail stdout unless status.success? + # stdout, status = restore_from_backup(skip: 'db') + # fail stdout unless status.success? - stdout, status = set_runner_token - fail stdout unless status.success? + # stdout, status = set_runner_token + # fail stdout unless status.success? - stdout, status = run_migrations - fail stdout unless status.success? + # stdout, status = run_migrations + # fail stdout unless status.success? - stdout, status = enforce_root_password(ENV['GITLAB_PASSWORD']) if ENV['GITLAB_PASSWORD'] - fail stdout unless status.success? + # stdout, status = enforce_root_password(ENV['GITLAB_PASSWORD']) if ENV['GITLAB_PASSWORD'] + # fail stdout unless status.success? - # scale the Rails code deployments up - scale_rails_up - # wait for rollout to complete (change in replicas) - wait_for_rails_rollout + # # scale the Rails code deployments up + # scale_rails_up + # # wait for rollout to complete (change in replicas) + # wait_for_rails_rollout - # Wait for the site to come up after the restore/migrations - wait_until_app_ready + # # Wait for the site to come up after the restore/migrations + # wait_until_app_ready - # Have the gitlab-runner re-register after the restore - restart_gitlab_runner - end + # # Have the gitlab-runner re-register after the restore + # restart_gitlab_runner + # end describe 'Restored gitlab instance' do - before { sign_in } + # before { sign_in } it 'Home page should show projects' do - visit '/' - expect(page).to have_content 'Projects' - expect(page).to have_content 'Administrator / testproject1' + uri = URI.parse("http://gdk.test:3000/api/v4/search?scope=projects&search=testing") + uri = URI.parse("http://gdk.test:3000/api/v4/search?scope=projects&search=testing") + + request = Net::HTTP::Get.new(uri) + request["Authorization"] = Base64.strict_encode64('root:Thorndon@123') + + response=ApiHelper.invoke_http_request(uri, request) + # # request["Authorization"] = "Bearer glpat-Wy2CzMzBsRhru5rEoQ8K" + # puts "INSIDE" + # puts uri.hostname + # puts uri.port + # puts uri.path + # puts uri.scheme + # res = Net::HTTP.start(uri.hostname, uri.port) {|http| + # http.request(request)} + request.each_header do |header_name, header_value| + puts "#{header_name} : #{header_value}" + end + vishal = JSON.parse(response.body) + puts vishal + #puts vishal.collect {|item| item["name"]} + # visit '/' + # expect(page).to have_content 'Projects' + # expect(page).to have_content 'Administrator / testproject1' end it 'Navigating to testproject1 repo should work' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 83a30fb4f1..c4fc8ea9c1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,6 +6,7 @@ require 'capybara-screenshot/rspec' require 'selenium-webdriver' require 'rspec/retry' require 'gitlab_test_helper' +require 'api_helper' require 'rspec-parameterized' require 'pry' -- GitLab From de83b42cdf8da239157a12d10827a904f3272438 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 12:18:58 +1300 Subject: [PATCH 14/36] adding api helper --- spec/api_helper.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 spec/api_helper.rb diff --git a/spec/api_helper.rb b/spec/api_helper.rb new file mode 100644 index 0000000000..b4612c1a55 --- /dev/null +++ b/spec/api_helper.rb @@ -0,0 +1,11 @@ +require 'net/http' + +module ApiHelper + + def self.invoke_http_request(uri, request) + response = Net::HTTP.start(uri.hostname, uri.port) {|http| + http.request(request) + } + end + +end \ No newline at end of file -- GitLab From c15660bcf7a4504f17a537367fc7a5f24900839b Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 12:21:14 +1300 Subject: [PATCH 15/36] reverted change to gitlab-ci.yml --- .gitlab-ci.yml | 78 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3d4762215a..f6a8d2ff0c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -78,7 +78,6 @@ stages: - specs - qa-manual - qa - - qa-report - staging-release - package - release-package @@ -95,12 +94,8 @@ include: - project: 'gitlab-org/quality/pipeline-common' file: - '/ci/danger-review.yml' - - '/ci/allure-report.yml' rules: - - if: '$CI_SERVER_HOST == "gitlab.com"' - - local: '/gitlab-ci-config/gitlab-com.yml' - rules: - - if: '$CI_SERVER_HOST == "gitlab.com"' + - if: $CI_SERVER_HOST == "gitlab.com" dependency_scanning: needs: [] @@ -302,16 +297,22 @@ pin_image_versions: dependencies: - pin_image_versions script: - - !reference [.set_up_varfile_and_kubecontext, script] + - mkdir -p $(dirname "${VARIABLES_FILE}") + - set_context + - check_kube_domain - kubectl version - - !reference [.set_up_namespace_secret_and_deploy, script] + - ensure_namespace + - create_secret + - deploy + - wait_for_deploy - restart_toolbox - echo "export QA_ENVIRONMENT_URL=gitlab-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - echo "export GITLAB_ROOT_DOMAIN=$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - echo "export GITLAB_URL=gitlab-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - echo "export REGISTRY_URL=registry-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - echo "export S3_ENDPOINT=https://minio-$HOST_SUFFIX.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - - !reference [.get_qa_revision, script] + - kubectl wait pods -n $NAMESPACE -l app=toolbox,release=$RELEASE_NAME --for condition=Ready --timeout=60s + - echo "export QA_GITLAB_REVISION=`kubectl exec -i $(kubectl get pods -lrelease=$RELEASE_NAME,app=toolbox -o custom-columns=":metadata.name") -c toolbox -- cat /srv/gitlab/REVISION`" >> "${VARIABLES_FILE}" artifacts: when: always paths: @@ -485,14 +486,18 @@ review_eks: stop_review_gke122: extends: .stop_review_template variables: - <<: *review_gke122_common_vars + AGENT_NAME: "gke122-ci-cluster" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v122.helm-charts.win" + KUBE_NAMESPACE: "helm-charts-win" environment: name: gke122_review/$REVIEW_REF_PREFIX$CI_COMMIT_REF_SLUG action: stop stop_review_gke125: variables: - <<: *review_gke125_common_vars + AGENT_NAME: "gke125-ci-cluster" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v125.helm-charts.win" + KUBE_NAMESPACE: "helm-charts-win" extends: .stop_review_template environment: name: gke125_review/$REVIEW_REF_PREFIX$CI_COMMIT_REF_SLUG @@ -525,14 +530,18 @@ stop_review_eks: dependencies: - pin_image_versions script: - - !reference [.set_up_varfile_and_kubecontext, script] - - !reference [.set_up_namespace_secret_and_deploy, script] + - mkdir -p $(dirname "${VARIABLES_FILE}") + - set_context + - check_kube_domain + - ensure_namespace + - create_secret + - deploy + - wait_for_deploy - check_domain_ip - restart_toolbox - echo "export QA_ENVIRONMENT_URL=gitlab.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - echo "export GITLAB_ROOT_DOMAIN=$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - echo "export S3_ENDPOINT=https://minio.$KUBE_INGRESS_BASE_DOMAIN" >> "${VARIABLES_FILE}" - - !reference [.get_qa_revision, script] artifacts: paths: - variables @@ -548,8 +557,10 @@ stable_gke122: name: gke122_production url: https://gitlab.$KUBE_INGRESS_BASE_DOMAIN variables: - <<: *review_gke122_common_vars VARIABLES_FILE: "variables/stable_gke122" + AGENT_NAME: "gke122-ci-cluster" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v122.helm-charts.win" + KUBE_NAMESPACE: "helm-charts-win" resource_group: "gke122-production" stable_gke125: @@ -558,8 +569,10 @@ stable_gke125: name: gke125_production url: https://gitlab.$KUBE_INGRESS_BASE_DOMAIN variables: - <<: *review_gke125_common_vars VARIABLES_FILE: "variables/stable_gke125" + AGENT_NAME: "gke125-ci-cluster" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v125.helm-charts.win" + KUBE_NAMESPACE: "helm-charts-win" resource_group: "gke125-production" stable_gke126: @@ -578,14 +591,15 @@ stable_eks: name: eks_production url: https://gitlab.$KUBE_INGRESS_BASE_DOMAIN variables: - <<: *review_eks_common_vars VARIABLES_FILE: "variables/stable_eks" resource_group: "eks-production" review_helm_test_gke122: stage: qa variables: - <<: *review_gke122_common_vars + AGENT_NAME: "gke122-ci-cluster" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v122.helm-charts.win" + KUBE_NAMESPACE: "helm-charts-win" environment: name: gke122_review/$REVIEW_REF_PREFIX$CI_COMMIT_REF_SLUG url: https://gitlab-$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN @@ -604,7 +618,9 @@ review_helm_test_gke122: production_helm_test_gke122: stage: qa variables: - <<: *review_gke122_common_vars + AGENT_NAME: "gke122-ci-cluster" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v122.helm-charts.win" + KUBE_NAMESPACE: "helm-charts-win" environment: name: gke122_production url: https://gitlab.$KUBE_INGRESS_BASE_DOMAIN @@ -633,10 +649,11 @@ debug_review_gke122: url: https://gitlab-$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN on_stop: stop_review_gke122 variables: - <<: *review_gke122_common_vars HOST_SUFFIX: "$CI_ENVIRONMENT_SLUG" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v122.helm-charts.win" DOMAIN: "-$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN" - + AGENT_NAME: "gke122-ci-cluster" + KUBE_NAMESPACE: "helm-charts-win" rules: - !reference [.rule:skip_if_no_cluster] - if: '$PIPELINE_TYPE =~ /MR_PIPELINE$/' @@ -791,9 +808,11 @@ review-docs-cleanup: review_specs_gke122: extends: .specs variables: - <<: *review_gke122_common_vars VARIABLES_FILE: "variables/review_gke122" RSPEC_TAGS: type:feature + AGENT_NAME: "gke122-ci-cluster" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v122.helm-charts.win" + KUBE_NAMESPACE: "helm-charts-win" environment: name: gke122_review/$REVIEW_REF_PREFIX$CI_COMMIT_REF_SLUG url: https://gitlab-$CI_ENVIRONENMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN @@ -807,9 +826,11 @@ review_specs_gke122: review_specs_gke125: extends: .specs variables: - <<: *review_gke125_common_vars VARIABLES_FILE: "variables/review_gke125" RSPEC_TAGS: type:feature + AGENT_NAME: "gke125-ci-cluster" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v125.helm-charts.win" + KUBE_NAMESPACE: "helm-charts-win" environment: name: gke125_review/$REVIEW_REF_PREFIX$CI_COMMIT_REF_SLUG url: https://gitlab-$CI_ENVIRONENMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN @@ -839,7 +860,6 @@ review_specs_gke126: review_specs_eks: extends: .specs variables: - <<: *review_eks_common_vars VARIABLES_FILE: "variables/review_eks" RSPEC_TAGS: type:feature environment: @@ -882,9 +902,11 @@ production_specs_without_cluster: production_specs_gke122: extends: .production_specs variables: - <<: *review_gke122_common_vars VARIABLES_FILE: "variables/stable_gke122" RSPEC_TAGS: type:feature + AGENT_NAME: "gke122-ci-cluster" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v122.helm-charts.win" + KUBE_NAMESPACE: "helm-charts-win" environment: name: gke122_production url: https://gitlab.$KUBE_INGRESS_BASE_DOMAIN @@ -894,9 +916,11 @@ production_specs_gke122: production_specs_gke125: extends: .production_specs variables: - <<: *review_gke125_common_vars VARIABLES_FILE: "variables/stable_gke125" RSPEC_TAGS: type:feature + AGENT_NAME: "gke125-ci-cluster" + KUBE_INGRESS_BASE_DOMAIN: "cloud-native-v125.helm-charts.win" + KUBE_NAMESPACE: "helm-charts-win" environment: name: gke125_production url: https://gitlab.$KUBE_INGRESS_BASE_DOMAIN @@ -919,7 +943,6 @@ production_specs_eks: extends: .production_specs allow_failure: true variables: - <<: *review_eks_common_vars VARIABLES_FILE: "variables/stable_eks" RSPEC_TAGS: type:feature environment: @@ -934,7 +957,6 @@ production_specs_eks: services: - docker:${DOCKER_VERSION}-dind variables: - QA_GENERATE_ALLURE_REPORT: "true" DOCKER_HOST: tcp://docker:2375 QA_ARTIFACTS_DIR: $CI_PROJECT_DIR QA_CAN_TEST_PRAEFECT: "false" -- GitLab From 0fdafd2140f5a94ac3eb7fea7b2134993b9fa575 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 12:44:32 +1300 Subject: [PATCH 16/36] removed unwanted --- spec/features/backups_spec.rb | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/spec/features/backups_spec.rb b/spec/features/backups_spec.rb index efe5aaff2f..fb89fdd5a2 100644 --- a/spec/features/backups_spec.rb +++ b/spec/features/backups_spec.rb @@ -54,27 +54,19 @@ describe "Restoring a backup" do # before { sign_in } it 'Home page should show projects' do - uri = URI.parse("http://gdk.test:3000/api/v4/search?scope=projects&search=testing") - uri = URI.parse("http://gdk.test:3000/api/v4/search?scope=projects&search=testing") + uri = URI.parse("http://gdk.test:3000/api/v4/search?scope=projects&search=Helloworld") request = Net::HTTP::Get.new(uri) - request["Authorization"] = Base64.strict_encode64('root:Thorndon@123') - - response=ApiHelper.invoke_http_request(uri, request) - # # request["Authorization"] = "Bearer glpat-Wy2CzMzBsRhru5rEoQ8K" - # puts "INSIDE" - # puts uri.hostname - # puts uri.port - # puts uri.path - # puts uri.scheme - # res = Net::HTTP.start(uri.hostname, uri.port) {|http| - # http.request(request)} - request.each_header do |header_name, header_value| + # request["Authorization"] = Base64.strict_encode64('root:Thorndon@123') + + response=ApiHelper.invoke_http_request(uri, request) + request["Authorization"] = "Bearer glpat-Wy2CzMzBsRhru5rEoQ8K" + request.each_header do |header_name, header_value| puts "#{header_name} : #{header_value}" end vishal = JSON.parse(response.body) puts vishal - #puts vishal.collect {|item| item["name"]} + # puts vishal.collect {|item| item["name"]} # visit '/' # expect(page).to have_content 'Projects' # expect(page).to have_content 'Administrator / testproject1' -- GitLab From dc56cf6fe3b2970ff5bae18130cbc40c514e0252 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 12:48:58 +1300 Subject: [PATCH 17/36] Removed trailing spaces --- spec/features/backups_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/backups_spec.rb b/spec/features/backups_spec.rb index fb89fdd5a2..15f75ec596 100644 --- a/spec/features/backups_spec.rb +++ b/spec/features/backups_spec.rb @@ -62,8 +62,8 @@ describe "Restoring a backup" do response=ApiHelper.invoke_http_request(uri, request) request["Authorization"] = "Bearer glpat-Wy2CzMzBsRhru5rEoQ8K" request.each_header do |header_name, header_value| - puts "#{header_name} : #{header_value}" - end + puts "#{header_name} : #{header_value}" + end vishal = JSON.parse(response.body) puts vishal # puts vishal.collect {|item| item["name"]} -- GitLab From 6a5b8357701a42578c1c1b9e4b8d669224d7c7c1 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 12:51:15 +1300 Subject: [PATCH 18/36] Removed trailing spaces --- spec/api_helper.rb | 14 ++++++-------- spec/features/backups_spec.rb | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index b4612c1a55..65d4ab39eb 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -1,11 +1,9 @@ require 'net/http' module ApiHelper - - def self.invoke_http_request(uri, request) - response = Net::HTTP.start(uri.hostname, uri.port) {|http| - http.request(request) - } - end - -end \ No newline at end of file + def self.invoke_http_request(uri, request) + response = Net::HTTP.start(uri.hostname, uri.port) {|http| + http.request(request) + } + end +end diff --git a/spec/features/backups_spec.rb b/spec/features/backups_spec.rb index 15f75ec596..7ed3d9064e 100644 --- a/spec/features/backups_spec.rb +++ b/spec/features/backups_spec.rb @@ -59,7 +59,7 @@ describe "Restoring a backup" do request = Net::HTTP::Get.new(uri) # request["Authorization"] = Base64.strict_encode64('root:Thorndon@123') - response=ApiHelper.invoke_http_request(uri, request) + response = ApiHelper.invoke_http_request(uri, request) request["Authorization"] = "Bearer glpat-Wy2CzMzBsRhru5rEoQ8K" request.each_header do |header_name, header_value| puts "#{header_name} : #{header_value}" -- GitLab From dbb0d638131bd92fb1864ae735b1ba15204f78e9 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 13:08:53 +1300 Subject: [PATCH 19/36] added space --- spec/api_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index 65d4ab39eb..e692daf4ff 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -2,7 +2,7 @@ require 'net/http' module ApiHelper def self.invoke_http_request(uri, request) - response = Net::HTTP.start(uri.hostname, uri.port) {|http| + response = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(request) } end -- GitLab From 91373b984cad40d07790d2b5ef3d349f895ec117 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 13:12:14 +1300 Subject: [PATCH 20/36] added space --- spec/api_helper.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index e692daf4ff..8ea29bb0f9 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -1,9 +1,8 @@ require 'net/http' module ApiHelper - def self.invoke_http_request(uri, request) - response = Net::HTTP.start(uri.hostname, uri.port) { |http| - http.request(request) - } - end + def self.invoke_http_request(uri, request) + Net::HTTP.start(uri.hostname, uri.port) |http| + http.request(request) + end end -- GitLab From f214af5919c0c13de7ed5d023d8797e3e97a4e54 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 13:23:36 +1300 Subject: [PATCH 21/36] added space --- spec/api_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index 8ea29bb0f9..78437e69ab 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -2,7 +2,7 @@ require 'net/http' module ApiHelper def self.invoke_http_request(uri, request) - Net::HTTP.start(uri.hostname, uri.port) |http| + Net::HTTP.start(uri.hostname, uri.port) | http | http.request(request) end end -- GitLab From 1d67c9683a529ff2b8f100dbd5ed2a90bcf65ec0 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 16:23:32 +1300 Subject: [PATCH 22/36] removed net-http from Gemfile --- Gemfile | 1 - Gemfile.lock | 4 ---- spec/api_helper.rb | 5 +++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 779abd6f6e..03834ce616 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,6 @@ group :test do gem 'knapsack' gem 'tomlrb' gem 'fugit' - gem 'net-http' end group :rubocop do diff --git a/Gemfile.lock b/Gemfile.lock index fcd44ebe0c..f71af222b8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -149,8 +149,6 @@ GEM multi_json (1.13.1) multi_xml (0.6.0) nap (1.1.0) - net-http (0.4.0) - uri no_proxy_fix (0.1.2) nokogiri (1.13.8) mini_portile2 (~> 2.8.0) @@ -276,7 +274,6 @@ GEM mprelude (~> 0.1.0) parser (>= 2.6.5) procto (~> 0.0.2) - uri (0.13.0) webrick (1.7.0) xpath (3.2.0) nokogiri (~> 1.8) @@ -296,7 +293,6 @@ DEPENDENCIES gitlab-styles (~> 9.0) hash-deep-merge knapsack - net-http pry rake rspec diff --git a/spec/api_helper.rb b/spec/api_helper.rb index 78437e69ab..cbf740d7c0 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -2,7 +2,8 @@ require 'net/http' module ApiHelper def self.invoke_http_request(uri, request) - Net::HTTP.start(uri.hostname, uri.port) | http | - http.request(request) + Net::HTTP.start(uri.hostname, uri.port) do | http | + response=http.request(request) + end end end -- GitLab From 98458b86fa0ce1aa804d770c708eebbb56c5071e Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 20 Dec 2023 16:39:10 +1300 Subject: [PATCH 23/36] removed spaces and unwanted var --- spec/api_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index cbf740d7c0..a4f664e742 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -2,8 +2,8 @@ require 'net/http' module ApiHelper def self.invoke_http_request(uri, request) - Net::HTTP.start(uri.hostname, uri.port) do | http | - response=http.request(request) + Net::HTTP.start(uri.hostname, uri.port) do |http| + http.request(request) end end end -- GitLab From 9a005789c95498c3bbc18e0eaebd6ee35131cd12 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Thu, 21 Dec 2023 11:03:20 +1300 Subject: [PATCH 24/36] Changed it to run on CI --- spec/api_helper.rb | 2 +- spec/features/backups_spec.rb | 75 +++++++++++++++++------------------ 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index a4f664e742..5bb2ec9da5 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -2,7 +2,7 @@ require 'net/http' module ApiHelper def self.invoke_http_request(uri, request) - Net::HTTP.start(uri.hostname, uri.port) do |http| + Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http| http.request(request) end end diff --git a/spec/features/backups_spec.rb b/spec/features/backups_spec.rb index 7ed3d9064e..80f28fcfbd 100644 --- a/spec/features/backups_spec.rb +++ b/spec/features/backups_spec.rb @@ -3,64 +3,63 @@ require 'open-uri' require 'net/http' describe "Restoring a backup" do - # before(:all) do - # stdout, status = wait_for_dependencies - # fail stdout unless status.success? + before(:all) do + stdout, status = wait_for_dependencies + fail stdout unless status.success? - # wait_until_app_ready - # ensure_backups_on_object_storage + wait_until_app_ready + ensure_backups_on_object_storage - # stdout, status = gitaly_purge_storage - # fail stdout unless status.success? + stdout, status = gitaly_purge_storage + fail stdout unless status.success? - # stdout, status = restore_from_backup(skip: 'repositories') - # fail stdout unless status.success? + stdout, status = restore_from_backup(skip: 'repositories') + fail stdout unless status.success? - # # scale the Rails deployments to 0 - # scale_rails_down - # # wait for rollout to complete (change in replicas) - # wait_for_rails_rollout + # scale the Rails deployments to 0 + scale_rails_down + # wait for rollout to complete (change in replicas) + wait_for_rails_rollout - # # We run migrations once early to get the db into a place where we can set the runner token and restore repos - # # Ignore errors, we will run the migrations again after the token - # stdout, status = run_migrations - # warn "WARNING: Migrations did not succeed:\n#{stdout}" unless status.success? + # We run migrations once early to get the db into a place where we can set the runner token and restore repos + # Ignore errors, we will run the migrations again after the token + stdout, status = run_migrations + warn "WARNING: Migrations did not succeed:\n#{stdout}" unless status.success? - # stdout, status = restore_from_backup(skip: 'db') - # fail stdout unless status.success? + stdout, status = restore_from_backup(skip: 'db') + fail stdout unless status.success? - # stdout, status = set_runner_token - # fail stdout unless status.success? + stdout, status = set_runner_token + fail stdout unless status.success? - # stdout, status = run_migrations - # fail stdout unless status.success? + stdout, status = run_migrations + fail stdout unless status.success? - # stdout, status = enforce_root_password(ENV['GITLAB_PASSWORD']) if ENV['GITLAB_PASSWORD'] - # fail stdout unless status.success? + stdout, status = enforce_root_password(ENV['GITLAB_PASSWORD']) if ENV['GITLAB_PASSWORD'] + fail stdout unless status.success? - # # scale the Rails code deployments up - # scale_rails_up - # # wait for rollout to complete (change in replicas) - # wait_for_rails_rollout + # scale the Rails code deployments up + scale_rails_up + # wait for rollout to complete (change in replicas) + wait_for_rails_rollout - # # Wait for the site to come up after the restore/migrations - # wait_until_app_ready + # Wait for the site to come up after the restore/migrations + wait_until_app_ready - # # Have the gitlab-runner re-register after the restore - # restart_gitlab_runner - # end + # Have the gitlab-runner re-register after the restore + restart_gitlab_runner + end describe 'Restored gitlab instance' do # before { sign_in } it 'Home page should show projects' do - uri = URI.parse("http://gdk.test:3000/api/v4/search?scope=projects&search=Helloworld") + # uri = URI.parse("https://gitlab-gke122-review-tes-oetv01.cloud-native-v122.helm-charts.win//api/v4/search?scope=projects&search=Helloworld") + uri = URI.parse("https://gitlab-$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN//api/v4/projects") request = Net::HTTP::Get.new(uri) - # request["Authorization"] = Base64.strict_encode64('root:Thorndon@123') - + request["Authorization"] = Base64.strict_encode64('root:$ROOT_PASSWORD') response = ApiHelper.invoke_http_request(uri, request) - request["Authorization"] = "Bearer glpat-Wy2CzMzBsRhru5rEoQ8K" request.each_header do |header_name, header_value| puts "#{header_name} : #{header_value}" end -- GitLab From fc47ee987ecb29d4a7ab196d305badb0df448b89 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Thu, 21 Dec 2023 11:07:38 +1300 Subject: [PATCH 25/36] Changed hash to new syntax --- spec/api_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index 5bb2ec9da5..e77c1ec5fd 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -2,7 +2,7 @@ require 'net/http' module ApiHelper def self.invoke_http_request(uri, request) - Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http| + Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end end -- GitLab From 0f9d9570d6acba9e3de4d7091907f32eab063281 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Tue, 2 Jan 2024 15:39:38 +1300 Subject: [PATCH 26/36] Updated UI tests to Api --- Gemfile | 1 + Gemfile.lock | 14 ++++++++ spec/api_helper.rb | 22 +++++++++--- spec/features/backups_spec.rb | 65 ++++++++++++++--------------------- spec/gitlab_test_helper.rb | 14 ++++++++ 5 files changed, 72 insertions(+), 44 deletions(-) diff --git a/Gemfile b/Gemfile index 03834ce616..6f14c94672 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ group :test do gem 'knapsack' gem 'tomlrb' gem 'fugit' + gem 'rest-client' end group :rubocop do diff --git a/Gemfile.lock b/Gemfile.lock index f71af222b8..76ae9cae5e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,6 +84,7 @@ GEM docker-api (1.34.2) excon (>= 0.47.0) multi_json + domain_name (0.6.20231109) e2mmap (0.1.0) equalizer (0.0.11) et-orbi (1.2.7) @@ -115,6 +116,9 @@ GEM rubocop-rails (~> 2.15) rubocop-rspec (~> 2.12) hash-deep-merge (0.1.1) + http-accept (1.7.0) + http-cookie (1.0.5) + domain_name (~> 0.5) httparty (0.21.0) mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) @@ -136,6 +140,9 @@ GEM memoizable (0.4.2) thread_safe (~> 0.3, >= 0.3.1) method_source (1.0.0) + mime-types (3.5.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2023.1205) mini_mime (1.0.2) mini_portile2 (2.8.0) minitest (5.16.3) @@ -149,6 +156,7 @@ GEM multi_json (1.13.1) multi_xml (0.6.0) nap (1.1.0) + netrc (0.11.0) no_proxy_fix (0.1.2) nokogiri (1.13.8) mini_portile2 (~> 2.8.0) @@ -178,6 +186,11 @@ GEM rake (13.0.1) rchardet (1.8.0) regexp_parser (1.8.2) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) reverse_markdown (2.1.1) nokogiri rexml (3.2.5) @@ -295,6 +308,7 @@ DEPENDENCIES knapsack pry rake + rest-client rspec rspec-parameterized rspec-retry diff --git a/spec/api_helper.rb b/spec/api_helper.rb index e77c1ec5fd..f1c9ae253b 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -1,9 +1,21 @@ -require 'net/http' +require 'rest-client' +require 'json' module ApiHelper - def self.invoke_http_request(uri, request) - Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| - http.request(request) - end + BASE_URL = "https://gitlab-${CI_ENVIRONMENT_SLUG}.${KUBE_INGRESS_BASE_DOMAIN}/api/v4/" + # BASE_URL = "https://gitlab-gke122-review-tes-oetv01.cloud-native-v122.helm-charts.win/api/v4/" + def self.invoke_get_request(uri) + default_args = { + method: :get, + url: "#{BASE_URL}#{uri}", + verify_ssl: true, + headers: { + # "Authorization" => "Bearer gplat-XXXX" + "Authorization" => "#{GITLAB_ADMIN_TOKEN}" + } + } + response = RestClient::Request.execute(default_args) + puts response.to_s + json_response = JSON.parse(response.body) end end diff --git a/spec/features/backups_spec.rb b/spec/features/backups_spec.rb index 80f28fcfbd..c4eece79a4 100644 --- a/spec/features/backups_spec.rb +++ b/spec/features/backups_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper' require 'open-uri' -require 'net/http' describe "Restoring a backup" do before(:all) do @@ -38,6 +37,9 @@ describe "Restoring a backup" do stdout, status = enforce_root_password(ENV['GITLAB_PASSWORD']) if ENV['GITLAB_PASSWORD'] fail stdout unless status.success? + stdout, status = set_admin_token + fail stdout unless status.success? + # scale the Rails code deployments up scale_rails_up # wait for rollout to complete (change in replicas) @@ -51,52 +53,37 @@ describe "Restoring a backup" do end describe 'Restored gitlab instance' do - # before { sign_in } - - it 'Home page should show projects' do - # uri = URI.parse("https://gitlab-gke122-review-tes-oetv01.cloud-native-v122.helm-charts.win//api/v4/search?scope=projects&search=Helloworld") - uri = URI.parse("https://gitlab-$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN//api/v4/projects") - request = Net::HTTP::Get.new(uri) - request["Authorization"] = Base64.strict_encode64('root:$ROOT_PASSWORD') - response = ApiHelper.invoke_http_request(uri, request) - request.each_header do |header_name, header_value| - puts "#{header_name} : #{header_value}" - end - vishal = JSON.parse(response.body) - puts vishal - # puts vishal.collect {|item| item["name"]} - # visit '/' - # expect(page).to have_content 'Projects' - # expect(page).to have_content 'Administrator / testproject1' + it 'testproject1 project should exist' do + uri = "search?scope=projects&search=testproject1" + response = ApiHelper.invoke_get_request(uri) + expect(response.collect {|item| item["name_with_namespace"]}).to have_content 'Administrator / testproject1' end - it 'Navigating to testproject1 repo should work' do - visit '/root/testproject1' - expect(find('[data-testid="file-tree-table"]')) - .to have_content('Dockerfile') + it 'Issue under testproject1 should exist' do + uri = "search?scope=issues&search=test" + response = ApiHelper.invoke_get_request(uri) + expect(response.collect {|item| item["title"]}).to have_content 'This is a test issue with attachment' end - it 'Should have runner registered' do - visit '/admin/runners' - expect(page).to have_css('#content-body [data-testid^="runner-row-"],[data-qa-selector^="runner-row-"]', minimum: 1) + it 'Issue contains attachment in the description' do + uri = "issues" + response = ApiHelper.invoke_get_request(uri) + expect(response.collect {|item| item["description"]}).to have_content '![Screen_Shot_2018-05-01_at_2.53.34_PM](/uploads/90701344e9ebb53fa9ebac83d43afdcc/Screen_Shot_2018-05-01_at_2.53.34_PM.png)' end - it 'Issue attachments should load correctly' do - visit '/root/testproject1/-/issues/1' - - image_selector = 'div.md > p > a > img.js-lazy-loaded' - - # Image has additional classes added by JS async - wait(reload: false) do - has_selector?(image_selector) - end + it 'Test repo should have Dockerfile' do + uri = "projects/1/repository/tree" + response = ApiHelper.invoke_get_request(uri) + expect(response.collect {|item| item["name"]}) + .to have_content('Dockerfile') + end - expect(page).to have_selector(image_selector) - image_src = page.all(image_selector)[0][:src] - URI.open(image_src) do |f| - expect(f.status[0]).to eq '200' - end + it 'Should have atleast 1 runner registered' do + uri = "runners/all" + response = ApiHelper.invoke_get_request(uri) + expect(response.collect {|item| item["status"]}).to have_content('online', minimum: 1) + expect(response.collect {|item| item["online"]}).to have_content('true', minimum: 1) end it 'Could pull image from registry' do diff --git a/spec/gitlab_test_helper.rb b/spec/gitlab_test_helper.rb index a778fb07dc..f272af10df 100644 --- a/spec/gitlab_test_helper.rb +++ b/spec/gitlab_test_helper.rb @@ -99,6 +99,20 @@ module Gitlab return [stdout, status] end + def set_admin_token + cmd = full_command( + "gitlab-rails runner \"" \ + "unless PersonalAccessToken.find_by_token('#{ENV['GITLAB_ADMIN_TOKEN']}')" \ + "user = User.find_by_username('root')" \ + "token = user.personal_access_tokens.create(scopes: ['api'], name: 'vishaltest token', expires_at: 365.days.from_now)" \ + "token.set_token('#{ENV['GITLAB_ADMIN_TOKEN']}')" \ + "token.save!" \ + "end\"") + + stdout, status = Open3.capture2e(cmd) + return [stdout, status] + end + def gitlab_url protocol = ENV['PROTOCOL'] || 'https' instance_url = ENV['GITLAB_URL'] || "gitlab.#{ENV['GITLAB_ROOT_DOMAIN']}" -- GitLab From 07cdd47e6c24dfc2f3abf4500e1f0679737a062b Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Tue, 2 Jan 2024 15:59:46 +1300 Subject: [PATCH 27/36] Fixed indentations --- spec/api_helper.rb | 3 ++- spec/features/backups_spec.rb | 12 ++++++------ spec/gitlab_test_helper.rb | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index f1c9ae253b..4bfa340f2b 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -2,7 +2,7 @@ require 'rest-client' require 'json' module ApiHelper - BASE_URL = "https://gitlab-${CI_ENVIRONMENT_SLUG}.${KUBE_INGRESS_BASE_DOMAIN}/api/v4/" + BASE_URL = "https://gitlab-${CI_ENVIRONMENT_SLUG}.${KUBE_INGRESS_BASE_DOMAIN}/api/v4/".freeze # BASE_URL = "https://gitlab-gke122-review-tes-oetv01.cloud-native-v122.helm-charts.win/api/v4/" def self.invoke_get_request(uri) default_args = { @@ -17,5 +17,6 @@ module ApiHelper response = RestClient::Request.execute(default_args) puts response.to_s json_response = JSON.parse(response.body) + return json_response end end diff --git a/spec/features/backups_spec.rb b/spec/features/backups_spec.rb index c4eece79a4..54d7a15d57 100644 --- a/spec/features/backups_spec.rb +++ b/spec/features/backups_spec.rb @@ -57,33 +57,33 @@ describe "Restoring a backup" do it 'testproject1 project should exist' do uri = "search?scope=projects&search=testproject1" response = ApiHelper.invoke_get_request(uri) - expect(response.collect {|item| item["name_with_namespace"]}).to have_content 'Administrator / testproject1' + expect(response.collect { |item| item["name_with_namespace"] }).to have_content 'Administrator / testproject1' end it 'Issue under testproject1 should exist' do uri = "search?scope=issues&search=test" response = ApiHelper.invoke_get_request(uri) - expect(response.collect {|item| item["title"]}).to have_content 'This is a test issue with attachment' + expect(response.collect { |item| item["title"] }).to have_content 'This is a test issue with attachment' end it 'Issue contains attachment in the description' do uri = "issues" response = ApiHelper.invoke_get_request(uri) - expect(response.collect {|item| item["description"]}).to have_content '![Screen_Shot_2018-05-01_at_2.53.34_PM](/uploads/90701344e9ebb53fa9ebac83d43afdcc/Screen_Shot_2018-05-01_at_2.53.34_PM.png)' + expect(response.collect { |item| item["description"] }).to have_content '![Screen_Shot_2018-05-01_at_2.53.34_PM](/uploads/90701344e9ebb53fa9ebac83d43afdcc/Screen_Shot_2018-05-01_at_2.53.34_PM.png)' end it 'Test repo should have Dockerfile' do uri = "projects/1/repository/tree" response = ApiHelper.invoke_get_request(uri) - expect(response.collect {|item| item["name"]}) + expect(response.collect { |item| item["name"] }) .to have_content('Dockerfile') end it 'Should have atleast 1 runner registered' do uri = "runners/all" response = ApiHelper.invoke_get_request(uri) - expect(response.collect {|item| item["status"]}).to have_content('online', minimum: 1) - expect(response.collect {|item| item["online"]}).to have_content('true', minimum: 1) + expect(response.collect { |item| item["status"] }).to have_content('online', minimum: 1) + expect(response.collect { |item| item["online"] }).to have_content('true', minimum: 1) end it 'Could pull image from registry' do diff --git a/spec/gitlab_test_helper.rb b/spec/gitlab_test_helper.rb index f272af10df..85232c6889 100644 --- a/spec/gitlab_test_helper.rb +++ b/spec/gitlab_test_helper.rb @@ -109,8 +109,8 @@ module Gitlab "token.save!" \ "end\"") - stdout, status = Open3.capture2e(cmd) - return [stdout, status] + stdout, status = Open3.capture2e(cmd) + return [stdout, status] end def gitlab_url -- GitLab From 8ebd30e4514a7d7fbdb5df569bb0c52d92b1652a Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Tue, 2 Jan 2024 16:02:17 +1300 Subject: [PATCH 28/36] Fixed redundant command --- spec/api_helper.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index 4bfa340f2b..4f1a5f7954 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -11,12 +11,11 @@ module ApiHelper verify_ssl: true, headers: { # "Authorization" => "Bearer gplat-XXXX" - "Authorization" => "#{GITLAB_ADMIN_TOKEN}" + "Authorization" => "#{GITLAB_ADMIN_TOKEN.to_s}" } } response = RestClient::Request.execute(default_args) puts response.to_s - json_response = JSON.parse(response.body) - return json_response + JSON.parse(response.body) end end -- GitLab From 51b988156114c439f554cc71d47ebc8a52380462 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Tue, 2 Jan 2024 16:05:48 +1300 Subject: [PATCH 29/36] Fixed redundant command --- spec/api_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index 4f1a5f7954..0882d52a28 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -11,7 +11,7 @@ module ApiHelper verify_ssl: true, headers: { # "Authorization" => "Bearer gplat-XXXX" - "Authorization" => "#{GITLAB_ADMIN_TOKEN.to_s}" + "Authorization" => "#{ENV['GITLAB_ADMIN_TOKEN']}" } } response = RestClient::Request.execute(default_args) -- GitLab From 18566c1df62d29da8db8479dfbd82d8b9806b084 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Tue, 2 Jan 2024 16:09:48 +1300 Subject: [PATCH 30/36] Fixed redundant command --- spec/api_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index 0882d52a28..33fb4c42b1 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -11,7 +11,7 @@ module ApiHelper verify_ssl: true, headers: { # "Authorization" => "Bearer gplat-XXXX" - "Authorization" => "#{ENV['GITLAB_ADMIN_TOKEN']}" + "Authorization" => ENV['GITLAB_ADMIN_TOKEN'].to_s } } response = RestClient::Request.execute(default_args) -- GitLab From ec68b1e54d59ba05b84df6049202bbd10d25c289 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Wed, 3 Jan 2024 12:28:30 +1300 Subject: [PATCH 31/36] Fixed redundant command --- spec/gitlab_test_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/gitlab_test_helper.rb b/spec/gitlab_test_helper.rb index 85232c6889..cd7c3d6b04 100644 --- a/spec/gitlab_test_helper.rb +++ b/spec/gitlab_test_helper.rb @@ -107,7 +107,9 @@ module Gitlab "token = user.personal_access_tokens.create(scopes: ['api'], name: 'vishaltest token', expires_at: 365.days.from_now)" \ "token.set_token('#{ENV['GITLAB_ADMIN_TOKEN']}')" \ "token.save!" \ - "end\"") + "end" \ + "\"" + ) stdout, status = Open3.capture2e(cmd) return [stdout, status] -- GitLab From 88b62bb67b8206a4e4e64271407a215d1428f0ef Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Thu, 4 Jan 2024 13:44:43 +1300 Subject: [PATCH 32/36] Updating command --- spec/gitlab_test_helper.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/gitlab_test_helper.rb b/spec/gitlab_test_helper.rb index cd7c3d6b04..ea5b529a32 100644 --- a/spec/gitlab_test_helper.rb +++ b/spec/gitlab_test_helper.rb @@ -100,17 +100,17 @@ module Gitlab end def set_admin_token - cmd = full_command( - "gitlab-rails runner \"" \ - "unless PersonalAccessToken.find_by_token('#{ENV['GITLAB_ADMIN_TOKEN']}')" \ - "user = User.find_by_username('root')" \ - "token = user.personal_access_tokens.create(scopes: ['api'], name: 'vishaltest token', expires_at: 365.days.from_now)" \ - "token.set_token('#{ENV['GITLAB_ADMIN_TOKEN']}')" \ - "token.save!" \ - "end" \ - "\"" - ) - + # cmd = full_command( + # "gitlab-rails runner \"" \ + # "unless PersonalAccessToken.find_by_token('#{ENV['GITLAB_ADMIN_TOKEN']}')" \ + # "user = User.find_by_username('root')" \ + # "token = user.personal_access_tokens.create(scopes: ['api'], name: 'vishaltest token', expires_at: 365.days.from_now)" \ + # "token.set_token('#{ENV['GITLAB_ADMIN_TOKEN']}')" \ + # "token.save!" \ + # "end" \ + # "\"" + # ) + cmd = full_command("gitlab-rails runner \"unless PersonalAccessToken.find_by_token('#{ENV['GITLAB_ADMIN_TOKEN']}'); user = User.find_by_username('root'); token = user.personal_access_tokens.create(scopes: ['api'], name: 'vishaltest token', expires_at: 365.days.from_now); token.set_token('#{ENV['GITLAB_ADMIN_TOKEN']}'); token.save! end;\"" stdout, status = Open3.capture2e(cmd) return [stdout, status] end -- GitLab From d5267604c1be53f141a7526499c891ae930fecc5 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Thu, 4 Jan 2024 13:52:04 +1300 Subject: [PATCH 33/36] Updating command --- spec/gitlab_test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/gitlab_test_helper.rb b/spec/gitlab_test_helper.rb index ea5b529a32..c96af80c3c 100644 --- a/spec/gitlab_test_helper.rb +++ b/spec/gitlab_test_helper.rb @@ -110,7 +110,7 @@ module Gitlab # "end" \ # "\"" # ) - cmd = full_command("gitlab-rails runner \"unless PersonalAccessToken.find_by_token('#{ENV['GITLAB_ADMIN_TOKEN']}'); user = User.find_by_username('root'); token = user.personal_access_tokens.create(scopes: ['api'], name: 'vishaltest token', expires_at: 365.days.from_now); token.set_token('#{ENV['GITLAB_ADMIN_TOKEN']}'); token.save! end;\"" + cmd = full_command("gitlab-rails runner \"unless PersonalAccessToken.find_by_token('#{ENV['GITLAB_ADMIN_TOKEN']}'); user = User.find_by_username('root'); token = user.personal_access_tokens.create(scopes: ['api'], name: 'vishaltest token', expires_at: 365.days.from_now); token.set_token('#{ENV['GITLAB_ADMIN_TOKEN']}'); token.save! end;\"") stdout, status = Open3.capture2e(cmd) return [stdout, status] end -- GitLab From da1e5b592384883cb3e3a01a88e0941d32eff48a Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Thu, 4 Jan 2024 13:56:35 +1300 Subject: [PATCH 34/36] Updating command --- spec/gitlab_test_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/gitlab_test_helper.rb b/spec/gitlab_test_helper.rb index c96af80c3c..d045cdfbc7 100644 --- a/spec/gitlab_test_helper.rb +++ b/spec/gitlab_test_helper.rb @@ -110,7 +110,8 @@ module Gitlab # "end" \ # "\"" # ) - cmd = full_command("gitlab-rails runner \"unless PersonalAccessToken.find_by_token('#{ENV['GITLAB_ADMIN_TOKEN']}'); user = User.find_by_username('root'); token = user.personal_access_tokens.create(scopes: ['api'], name: 'vishaltest token', expires_at: 365.days.from_now); token.set_token('#{ENV['GITLAB_ADMIN_TOKEN']}'); token.save! end;\"") + cmd = full_command("gitlab-rails runner \"unless PersonalAccessToken.find_by_token('#{ENV['GITLAB_ADMIN_TOKEN']}'); user = User.find_by_username('root'); token = user.personal_access_tokens.create(scopes: ['api'], name: 'vishaltest token', expires_at: 365.days.from_now); \\ + token.set_token('#{ENV['GITLAB_ADMIN_TOKEN']}'); token.save! end;\"") stdout, status = Open3.capture2e(cmd) return [stdout, status] end -- GitLab From 55bad394bcabe1d82dcf76e2fbd50d605d566a43 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Thu, 4 Jan 2024 18:01:30 +1300 Subject: [PATCH 35/36] Updating command --- spec/api_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index 33fb4c42b1..03bdcab641 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -2,7 +2,7 @@ require 'rest-client' require 'json' module ApiHelper - BASE_URL = "https://gitlab-${CI_ENVIRONMENT_SLUG}.${KUBE_INGRESS_BASE_DOMAIN}/api/v4/".freeze + BASE_URL = "https://gitlab-#{ENV['CI_ENVIRONMENT_SLUG']}.#{ENV['KUBE_INGRESS_BASE_DOMAIN']}/api/v4/".freeze # BASE_URL = "https://gitlab-gke122-review-tes-oetv01.cloud-native-v122.helm-charts.win/api/v4/" def self.invoke_get_request(uri) default_args = { -- GitLab From 624a6720b01f1b38ddc96d2d4c63a940fe742a95 Mon Sep 17 00:00:00 2001 From: "vishal.s.patel" Date: Thu, 4 Jan 2024 21:46:21 +1300 Subject: [PATCH 36/36] Updating authroization header --- spec/api_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api_helper.rb b/spec/api_helper.rb index 03bdcab641..830544d46a 100644 --- a/spec/api_helper.rb +++ b/spec/api_helper.rb @@ -11,7 +11,7 @@ module ApiHelper verify_ssl: true, headers: { # "Authorization" => "Bearer gplat-XXXX" - "Authorization" => ENV['GITLAB_ADMIN_TOKEN'].to_s + "Authorization" => "Bearer #{ENV['GITLAB_ADMIN_TOKEN']}" } } response = RestClient::Request.execute(default_args) -- GitLab