geo.rb 4.93 KB
Newer Older
1 2 3 4 5 6
module Gitlab
  module QA
    module Scenario
      module Test
        module Integration
          class Geo < Scenario::Template
7
            include Scenario::CLICommands
8
            ##
Rémy Coutable's avatar
Rémy Coutable committed
9
            # rubocop:disable Lint/MissingCopEnableDirective
10 11
            # rubocop:disable Metrics/AbcSize
            #
12
            def perform(release, *rspec_args)
13
              release = QA::Release.new(release)
14

15
              raise ArgumentError, 'Geo is EE only!' unless release.ee?
16 17

              Runtime::Env.require_license!
18

19 20
              Component::Gitlab.perform do |primary|
                primary.release = release
21
                primary.name = 'gitlab-primary'
22 23
                primary.network = 'geo'
                primary.omnibus_config = <<~OMNIBUS
Grzegorz Bizon's avatar
Grzegorz Bizon committed
24
                  gitlab_rails['db_key_base'] = '4dd58204865eb41bca93bd38131d51cc';
Ash McKenzie's avatar
Ash McKenzie committed
25 26
                  geo_primary_role['enable'] = true;
                  gitlab_rails['db_password'] = 'mypass';
27
                  gitlab_rails['db_pool'] = 5;
28
                  gitlab_rails['geo_node_name'] = '#{primary.name}';
29
                  gitlab_rails['monitoring_whitelist'] = ['0.0.0.0/0'];
30
                  gitlab_rails['packages_enabled'] = true;
Ash McKenzie's avatar
Ash McKenzie committed
31 32 33
                  postgresql['listen_address'] = '0.0.0.0';
                  postgresql['max_replication_slots'] = 1;
                  postgresql['md5_auth_cidr_addresses'] = ['0.0.0.0/0'];
Ash McKenzie's avatar
Ash McKenzie committed
34
                  postgresql['sql_user_password'] = 'e1d1469ec5f533651918b4567a3ed1ae';
Ash McKenzie's avatar
Ash McKenzie committed
35
                  postgresql['trust_auth_cidr_addresses'] = ['0.0.0.0/0','0.0.0.0/0'];
36
                  sidekiq['concurrency'] = 2;
37
                  puma['worker_processes'] = 2;
Grzegorz Bizon's avatar
Grzegorz Bizon committed
38
                OMNIBUS
39
                primary.exec_commands = fast_ssh_key_lookup_commands + git_lfs_install_commands
40

41 42 43
                primary.instance do
                  Component::Gitlab.perform do |secondary|
                    secondary.release = release
44
                    secondary.name = 'gitlab-secondary'
45 46
                    secondary.network = 'geo'
                    secondary.omnibus_config = <<~OMNIBUS
Ash McKenzie's avatar
Ash McKenzie committed
47
                      geo_secondary['db_fdw'] = true;
48 49
                      geo_secondary_role['enable'] = true;
                      gitlab_rails['db_key_base'] = '4dd58204865eb41bca93bd38131d51cc';
Ash McKenzie's avatar
Ash McKenzie committed
50
                      gitlab_rails['db_password'] = 'mypass';
51
                      gitlab_rails['db_pool'] = 5;
52
                      gitlab_rails['geo_node_name'] = '#{secondary.name}';
Ash McKenzie's avatar
Ash McKenzie committed
53
                      gitlab_rails['monitoring_whitelist'] = ['0.0.0.0/0'];
54
                      gitlab_rails['packages_enabled'] = true;
Ash McKenzie's avatar
Ash McKenzie committed
55 56 57
                      postgresql['listen_address'] = '0.0.0.0';
                      postgresql['md5_auth_cidr_addresses'] = ['0.0.0.0/0'];
                      postgresql['sql_user_password'] = 'e1d1469ec5f533651918b4567a3ed1ae';
58
                      sidekiq['concurrency'] = 2;
59
                      puma['worker_processes'] = 2;
60
                    OMNIBUS
61
                    secondary.exec_commands = fast_ssh_key_lookup_commands + git_lfs_install_commands
62

63 64 65 66 67
                    secondary.act do
                      # TODO, we do not wait for secondary to start because of
                      # https://gitlab.com/gitlab-org/gitlab-ee/issues/3999
                      #
                      # rubocop:disable Style/Semicolon
68
                      prepare; start; reconfigure; process_exec_commands
69 70 71 72

                      # shellout to instance specs
                      puts 'Running Geo primary / secondary specs!'

73
                      Component::Specs.perform do |specs|
74
                        specs.suite = 'QA::EE::Scenario::Test::Geo'
75 76 77 78 79 80
                        specs.release = release
                        specs.network = 'geo'
                        specs.args = [
                          '--primary-address', primary.address,
                          '--primary-name', primary.name,
                          '--secondary-address', secondary.address,
81 82
                          '--secondary-name', secondary.name,
                          *rspec_args
83 84 85
                        ]
                      end

86
                      teardown
87 88
                    end
                  end
89 90 91
                end
              end
            end
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

            private

            def fast_ssh_key_lookup_content
              @fast_ssh_key_lookup_content ||= <<~CONTENT
              # Enable fast SSH key lookup - https://docs.gitlab.com/ee/administration/operations/fast_ssh_key_lookup.html
              AuthorizedKeysCommand /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell-authorized-keys-check git %u %k
              AuthorizedKeysCommandUser git
              CONTENT
            end

            def fast_ssh_key_lookup_commands
              @fast_ssh_key_lookup_commands ||= [
                %(echo -e "\n#{fast_ssh_key_lookup_content.chomp}" >> /assets/sshd_config),
                'gitlab-ctl restart sshd'
              ]
            end
109 110 111 112 113 114
          end
        end
      end
    end
  end
end