Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb661003

Browse files
authored
Merge pull request#1778 from python-gitlab/jlvillal/gitlab-ee
chore: enable using GitLab EE in functional tests
2 parents67ab24f +10987b3 commitb661003

File tree

5 files changed

+89
-7
lines changed

5 files changed

+89
-7
lines changed

‎tests/functional/api/test_groups.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ def test_group_subgroups_projects(gl, user):
218218
group4.delete()
219219

220220

221-
@pytest.mark.skip
222-
deftest_group_wiki(group):
221+
deftest_group_wiki(gitlab_ee,group):
222+
ifnotgitlab_ee:
223+
pytest.skip("Requires GitLab EE to run")
223224
content="Group Wiki page content"
224225
wiki=group.wikis.create({"title":"groupwikipage","content":content})
225226
assertwikiingroup.wikis.list()
@@ -234,8 +235,9 @@ def test_group_wiki(group):
234235
assertwikinotingroup.wikis.list()
235236

236237

237-
@pytest.mark.skip(reason="EE feature")
238-
deftest_group_hooks(group):
238+
deftest_group_hooks(gitlab_ee,group):
239+
ifnotgitlab_ee:
240+
pytest.skip("Requires GitLab EE to run")
239241
hook=group.hooks.create({"url":"http://hook.url"})
240242
asserthookingroup.hooks.list()
241243

‎tests/functional/conftest.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ def fixture_dir(test_dir):
2020
defreset_gitlab(gl:gitlab.Gitlab)->None:
2121
"""Delete resources (such as projects, groups, users) that shouldn't
2222
exist."""
23+
ifis_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+
ifsettings.deletion_adjourned_period!=0:
29+
logging.info("Setting deletion_adjourned_period to 0")
30+
settings.deletion_adjourned_period=0
31+
settings.save()
32+
2333
forprojectingl.projects.list():
2434
fordeploy_tokeninproject.deploytokens.list():
2535
logging.info(
@@ -180,6 +190,23 @@ def gl(gitlab_config):
180190
returninstance
181191

182192

193+
defis_gitlab_ee(gl:gitlab.Gitlab)->bool:
194+
"""Determine if we are running with GitLab EE as opposed to GitLab CE"""
195+
try:
196+
license=gl.get_license()
197+
exceptgitlab.exceptions.GitlabLicenseError:
198+
license=None
199+
# If we have a license then we assume we are running on GitLab EE
200+
iflicense:
201+
returnTrue
202+
returnFalse
203+
204+
205+
@pytest.fixture(scope="session")
206+
defgitlab_ee(gl)->bool:
207+
returnis_gitlab_ee(gl=gl)
208+
209+
183210
@pytest.fixture(scope="session")
184211
defgitlab_runner(gl):
185212
container="gitlab-runner-test"

‎tests/functional/fixtures/.env‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff 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)}

‎tests/functional/fixtures/docker-compose.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ services:
3131
gitlab_exporter['enable'] =false
3232
grafana['enable'] =false
3333
letsencrypt['enable'] =false
34+
gitlab_rails['initial_license_file'] = '/python-gitlab-ci.gitlab-license'
3435
entrypoint:
3536
-/bin/sh
3637
--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
3839
volumes:
3940
-${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
4042
ports:
4143
-'8080:80'
4244
-'2222:22'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp