| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 67ab24f commit 17c01ea
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,17 @@ def fixture_dir(test_dir): | |||
| 20 | 20 | def reset_gitlab(gl: gitlab.Gitlab) -> None: | |
| 21 | 21 | """Delete resources (such as projects, groups, users) that shouldn't | |
| 22 | 22 | exist.""" | |
| 23 | + if is_gitlab_ee(gl): | ||
| 24 | + logging.info("GitLab EE detected") | ||
| 25 | + # NOTE(jlvillal): By default in GitLab EE it will wait 7 days before | ||
| 26 | + # deleting a group. Change it to 0 days. | ||
| 27 | + settings = gl.settings.get() | ||
| 28 | + logging.info(f"deletion_adjourned_period: {settings.deletion_adjourned_period}") | ||
| 29 | + if settings.deletion_adjourned_period != 0: | ||
| 30 | + logging.info("Setting deletion_adjourned_period to 0") | ||
| 31 | + settings.deletion_adjourned_period = 0 | ||
| 32 | + settings.save() | ||
| 33 | + | ||
| 23 | 34 | for project in gl.projects.list(): | |
| 24 | 35 | for deploy_token in project.deploytokens.list(): | |
| 25 | 36 | logging.info( | |
@@ -180,6 +191,18 @@ def gl(gitlab_config): | |||
| 180 | 191 | return instance | |
| 181 | 192 | ||
| 182 | 193 | ||
| 194 | + def is_gitlab_ee(gl: gitlab.Gitlab) -> bool: | ||
| 195 | + """Determine if we are running with GitLab EE as opposed to GitLab CE""" | ||
| 196 | + try: | ||
| 197 | + license = gl.get_license() | ||
| 198 | + except gitlab.exceptions.GitlabLicenseError: | ||
| 199 | + license = None | ||
| 200 | + # If we have a license then we assume we are running on GitLab EE | ||
| 201 | + if license: | ||
| 202 | + return True | ||
| 203 | + return False | ||
| 204 | + | ||
| 205 | + | ||
| 183 | 206 | @pytest.fixture(scope="session") | |
| 184 | 207 | def gitlab_runner(gl): | |
| 185 | 208 | container = "gitlab-runner-test" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,2 +1,2 @@ | |||
| 1 | - GITLAB_IMAGE=gitlab/gitlab-ce | ||
| 2 | - GITLAB_TAG=14.9.2-ce.0 | ||
| 1 | + GITLAB_IMAGE=gitlab/gitlab-ee | ||
| 2 | + GITLAB_TAG=14.9.2-ee.0 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,51 @@ | |||
| 1 | + # NOTE: As of 2022-06-01 the GitLab Enterprise Edition License has the following | ||
| 2 | + # section: | ||
| 3 | + # Notwithstanding the foregoing, you may copy and modify the Software for development | ||
| 4 | + # and testing purposes, without requiring a subscription. | ||
| 5 | + # | ||
| 6 | + # https://gitlab.com/gitlab-org/gitlab/-/blob/29503bc97b96af8d4876dc23fc8996e3dab7d211/ee/LICENSE | ||
| 7 | + # | ||
| 8 | + # This code is strictly intended for use in the testing framework of python-gitlab | ||
| 9 | + | ||
| 10 | + # Code inspired by MIT licensed code at: https://github.com/CONIGUERO/gitlab-license.git | ||
| 11 | + | ||
| 12 | + require 'openssl' | ||
| 13 | + require 'gitlab/license' | ||
| 14 | + | ||
| 15 | + # Generate a 2048 bit key pair. | ||
| 16 | + license_encryption_key = OpenSSL::PKey::RSA.generate(2048) | ||
| 17 | + | ||
| 18 | + # Save the private key | ||
| 19 | + File.open("/.license_encryption_key", "w") { |f| f.write(license_encryption_key.to_pem) } | ||
| 20 | + # Save the public key | ||
| 21 | + public_key = license_encryption_key.public_key | ||
| 22 | + File.open("/.license_encryption_key.pub", "w") { |f| f.write(public_key.to_pem) } | ||
| 23 | + File.open("/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub", "w") { |f| f.write(public_key.to_pem) } | ||
| 24 | + | ||
| 25 | + Gitlab::License.encryption_key = license_encryption_key | ||
| 26 | + | ||
| 27 | + # Build a new license. | ||
| 28 | + license = Gitlab::License.new | ||
| 29 | + | ||
| 30 | + license.licensee = { | ||
| 31 | + "Name" => "python-gitlab-ci", | ||
| 32 | + "Company" => "python-gitlab-ci", | ||
| 33 | + "Email" => "python-gitlab-ci@example.com", | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + # The date the license starts. | ||
| 37 | + license.starts_at = Date.today | ||
| 38 | + # Want to make sure we get at least 1 day of usage. Do two days after because if CI | ||
| 39 | + # started at 23:59 we could be expired in one minute if we only did one next_day. | ||
| 40 | + license.expires_at = Date.today.next_day.next_day | ||
| 41 | + | ||
| 42 | + # Use 'ultimate' plan so that we can test all features in the CI | ||
| 43 | + license.restrictions = { | ||
| 44 | + :plan => "ultimate", | ||
| 45 | + :id => rand(1000..99999999) | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + # Export the license, which encrypts and encodes it. | ||
| 49 | + data = license.export | ||
| 50 | + | ||
| 51 | + File.open("/python-gitlab-ci.gitlab-license", 'w') { |file| file.write(data) } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,12 +31,14 @@ services: | |||
| 31 | 31 | gitlab_exporter['enable'] = false | |
| 32 | 32 | grafana['enable'] = false | |
| 33 | 33 | letsencrypt['enable'] = false | |
| 34 | + gitlab_rails['initial_license_file'] = '/python-gitlab-ci.gitlab-license' | ||
| 34 | 35 | entrypoint: | |
| 35 | 36 | - /bin/sh | |
| 36 | 37 | - -c | |
| 37 | - - chmod 644 /opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/* && /assets/wrapper | ||
| 38 | + - ruby /create_license.rb && chmod 644 /opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/* && /assets/wrapper | ||
| 38 | 39 | volumes: | |
| 39 | 40 | - ${PWD}/tests/functional/fixtures/set_token.rb:/opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/003_set_token.rb | |
| 41 | + - ${PWD}/tests/functional/fixtures/create_license.rb:/create_license.rb | ||
| 40 | 42 | ports: | |
| 41 | 43 | - '8080:80' | |
| 42 | 44 | - '2222:22' | |
| Back | FazBrowse Home | New Git URL |
0 commit comments