Skip to content

Commit 1e2ca59

Browse files
committed
Running tests with random user, to check that containers can also run
in OpenShift or non-sudo envs.
1 parent 193a17d commit 1e2ca59

File tree

3 files changed

+56
-20
lines changed

3 files changed

+56
-20
lines changed

.travis.yml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ services:
66
- docker
77

88
notifications:
9-
slack: seleniumhq:Kx5MB7T51SPMpbBMYfvxNW4q
9+
slack: seleniumhq:Kx5MB7T51SPMpbBMYfvxNW4q
1010

11-
before_install:
12-
- docker info
13-
- VERSION="$TRAVIS_BRANCH" make build
14-
15-
script:
16-
- VERSION="$TRAVIS_BRANCH" make test
17-
18-
# only push up tags
19-
after_success:
20-
- if [ "$TRAVIS_TAG" != "" ]; then
21-
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
22-
VERSION="$TRAVIS_TAG" make release;
23-
VERSION="$TRAVIS_TAG" make tag_latest;
24-
VERSION="latest" make release_latest;
25-
fi
11+
jobs:
12+
include:
13+
- stage: Build and integration tests
14+
env: step=build_and_test
15+
script:
16+
- docker info
17+
- VERSION="$TRAVIS_BRANCH" make ci
18+
- env: step=build_and_test_random_user
19+
script:
20+
- docker info
21+
- USE_RANDOM_USER_ID=true VERSION="$TRAVIS_BRANCH" make ci
22+
- stage: Release
23+
if: branch = master AND type != pull_request AND tag IS present
24+
script:
25+
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
26+
- VERSION="${TRAVIS_TAG}" make build
27+
- VERSION="${TRAVIS_TAG}" make release
28+
- VERSION="${TRAVIS_TAG}" make tag_latest
29+
- VERSION="${TRAVIS_TAG}" make release_latest

tests/bootstrap.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
#!/usr/bin/env bash
22
cd tests
3-
pip install selenium===3.14.0 \
3+
4+
if [ "${TRAVIS:-false}" = "false" ]; then
5+
pip install virtualenv | grep -v 'Requirement already satisfied'
6+
virtualenv docker-selenium-tests
7+
source docker-selenium-tests/bin/activate
8+
fi
9+
10+
11+
pip install selenium===3.14.1 \
412
docker===3.5.0 \
513
| grep -v 'Requirement already satisfied'
614

715
python test.py $1 $2
16+
17+
if [ "${TRAVIS:-false}" = "false" ]; then
18+
deactivate
19+
fi

tests/test.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44
import logging
55
import sys
6+
import random
67

78
from docker.errors import NotFound
89

@@ -15,6 +16,7 @@
1516

1617
NAMESPACE = os.environ.get('NAMESPACE')
1718
VERSION = os.environ.get('VERSION')
19+
USE_RANDOM_USER_ID = os.environ.get('USE_RANDOM_USER_ID')
1820

1921
IMAGE_NAME_MAP = {
2022
# Hub
@@ -70,7 +72,13 @@ def launch_hub():
7072
logger.debug("hub killed")
7173
existing_hub.remove()
7274
logger.debug("hub removed")
73-
hub_container_id = launch_container('Hub', ports={'4444': 4444})
75+
76+
77+
if use_random_user_id:
78+
hub_container_id = launch_container('Hub', ports={'4444': 4444}, user=random_user_id)
79+
else:
80+
hub_container_id = launch_container('Hub', ports={'4444': 4444})
81+
7482
logger.info("Hub Launched")
7583
return hub_container_id
7684

@@ -101,6 +109,12 @@ def launch_container(container, **kwargs):
101109
# The container to test against
102110
image = sys.argv[1]
103111

112+
use_random_user_id = USE_RANDOM_USER_ID == 'true'
113+
random_user_id = random.randint(100000,2147483647)
114+
115+
if use_random_user_id:
116+
logger.info("Running tests with a random user ID -> %s" % random_user_id)
117+
104118
standalone = 'standalone' in image.lower()
105119

106120
# Flag for failure (for posterity)
@@ -113,14 +127,20 @@ def launch_container(container, **kwargs):
113127
Standalone Configuration
114128
"""
115129
smoke_test_class = 'StandaloneTest'
116-
test_container_id = launch_container(image, ports={'4444': 4444})
130+
if use_random_user_id:
131+
test_container_id = launch_container(image, ports={'4444': 4444}, user=random_user_id)
132+
else:
133+
test_container_id = launch_container(image, ports={'4444': 4444})
117134
else:
118135
"""
119136
Hub / Node Configuration
120137
"""
121138
smoke_test_class = 'NodeTest'
122139
hub_id = launch_hub()
123-
test_container_id = launch_container(image, links={hub_id: 'hub'}, ports={'5555': 5555})
140+
if use_random_user_id:
141+
test_container_id = launch_container(image, links={hub_id: 'hub'}, ports={'5555': 5555}, user=random_user_id)
142+
else:
143+
test_container_id = launch_container(image, links={hub_id: 'hub'}, ports={'5555': 5555})
124144

125145
logger.info('========== / Containers ready to go ==========')
126146

0 commit comments

Comments
 (0)