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

Commit5e43c37

Browse files
chore: enable using GitLab EE in functional tests
Enable using GitLab Enterprise Edition (EE) in the functional tests.This will allow us to add functional tests for EE only features in thefunctional tests.
1 parentd65ce36 commit5e43c37

File tree

7 files changed

+123
-5
lines changed

7 files changed

+123
-5
lines changed

‎tests/functional/conftest.py‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ def fixture_dir(test_dir):
1515

1616

1717
defreset_gitlab(gl):
18+
if_is_gitlab_ee(gl):
19+
# NOTE(jlvillal): By default in GitLab EE it will wait 7 days before
20+
# deleting a group. Change it to 0 days.
21+
settings=gl.settings.get()
22+
ifsettings.deletion_adjourned_period!=0:
23+
settings.deletion_adjourned_period=0
24+
settings.save()
1825
# previously tools/reset_gitlab.py
1926
forprojectingl.projects.list():
2027
fordeploy_tokeninproject.deploytokens.list():
@@ -29,6 +36,7 @@ def reset_gitlab(gl):
2936
foruseringl.users.list():
3037
ifuser.username!="root":
3138
user.delete(hard_delete=True)
39+
_wait_for_sidekiq(gl=gl)(timeout=60)
3240

3341

3442
defset_token(container,fixture_dir):
@@ -106,7 +114,16 @@ def _check(container):
106114

107115

108116
@pytest.fixture
109-
defwait_for_sidekiq(gl):
117+
defwait_for_sidekiq(gl:gitlab.Gitlab):
118+
"""
119+
Return a helper function to wait until there are no busy sidekiq processes.
120+
121+
Use this with asserts for slow tasks (group/project/user creation/deletion).
122+
"""
123+
return_wait_for_sidekiq(gl=gl)
124+
125+
126+
def_wait_for_sidekiq(gl:gitlab.Gitlab):
110127
"""
111128
Return a helper function to wait until there are no busy sidekiq processes.
112129
@@ -134,7 +151,7 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_
134151
port=docker_services.port_for("gitlab",80)
135152

136153
docker_services.wait_until_responsive(
137-
timeout=200,pause=5,check=lambda:check_is_alive("gitlab-test")
154+
timeout=300,pause=5,check=lambda:check_is_alive("gitlab-test")
138155
)
139156

140157
token=set_token("gitlab-test",fixture_dir=fixture_dir)
@@ -164,6 +181,25 @@ def gl(gitlab_config):
164181
returninstance
165182

166183

184+
@pytest.fixture(scope="session")
185+
defis_gitlab_ee(gl)->bool:
186+
"""Fixture to determine if we are running with GitLab EE as opposed to
187+
GitLab CE"""
188+
return_is_gitlab_ee(gl=gl)
189+
190+
191+
def_is_gitlab_ee(gl:gitlab.Gitlab)->bool:
192+
"""Determine if we are running with GitLab EE as opposed to GitLab CE"""
193+
try:
194+
license=gl.get_license()
195+
exceptgitlab.exceptions.GitlabLicenseError:
196+
license=None
197+
# If we have a license then we assume we are running on GitLab EE
198+
iflicense:
199+
returnTrue
200+
returnFalse
201+
202+
167203
@pytest.fixture(scope="session")
168204
defgitlab_runner(gl):
169205
container="gitlab-runner-test"

‎tests/functional/fixtures/.env‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
GITLAB_IMAGE=gitlab/gitlab-ce
2-
GITLAB_TAG=14.5.2-ce.0
1+
GITLAB_IMAGE=gitlab/gitlab-ee
2+
GITLAB_TAG=14.5.2-ee.0
3+
4+
GITLAB_CI_IMAGE=localhost/gitlab-ci
5+
GITLAB_CI_TAG=latest
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ARG GITLAB_IMAGE=get_this_from_env
2+
ARG GITLAB_TAG=get_this_from_env
3+
FROM ${GITLAB_IMAGE}:${GITLAB_TAG}
4+
5+
COPY create_license.rb /
6+
RUN ruby /create_license.rb
7+
8+
CMD ["/assets/wrapper"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -u
4+
set -e
5+
6+
TOP_DIR=$(cd"$(dirname"${BASH_SOURCE[0]}")"&& pwd)
7+
8+
cd"${TOP_DIR}"||exit 1
9+
10+
source .env
11+
12+
docker build \
13+
-t"${GITLAB_CI_IMAGE}:${GITLAB_CI_TAG}" \
14+
--build-arg GITLAB_IMAGE="${GITLAB_IMAGE}" \
15+
--build-arg GITLAB_TAG="${GITLAB_TAG}" \
16+
--no-cache \
17+
"${TOP_DIR}"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# NOTE: As of 2021-12-26 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/master/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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ networks:
66

77
services:
88
gitlab:
9-
image:'${GITLAB_IMAGE}:${GITLAB_TAG}'
9+
image:'${GITLAB_CI_IMAGE}:${GITLAB_CI_TAG}'
1010
container_name:'gitlab-test'
1111
hostname:'gitlab.test'
1212
privileged:true# Just in case https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/1350
@@ -31,6 +31,7 @@ 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
ports:
3536
-'8080:80'
3637
-'2222:22'

‎tox.ini‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ exclude_lines =
9595
[testenv:cli_func_v4]
9696
deps = -r{toxinidir}/requirements-docker.txt
9797
commands =
98+
{toxinidir}/tests/functional/fixtures/build-dockerfile.sh
9899
pytest --script-launch-mode=subprocess --cov --cov-report xml tests/functional/cli {posargs}
99100

100101
[testenv:py_func_v4]
101102
deps = -r{toxinidir}/requirements-docker.txt
102103
commands =
104+
{toxinidir}/tests/functional/fixtures/build-dockerfile.sh
103105
pytest --cov --cov-report xml tests/functional/api {posargs}
104106

105107
[testenv:smoke]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp