Skip to content

Commit 78db9cf

Browse files
authored
Enabling host and port config for nodes (#1152)
1 parent d8996c3 commit 78db9cf

File tree

12 files changed

+165
-36
lines changed

12 files changed

+165
-36
lines changed

NodeBase/start-selenium-node.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ if [[ -z "${SE_EVENT_BUS_SUBSCRIBE_PORT}" ]]; then
2727
exit 1
2828
fi
2929

30-
CONFIG_TOML_FILE=/opt/selenium/config.toml
31-
32-
/opt/bin/generate_config >${CONFIG_TOML_FILE}
30+
/opt/bin/generate_config
3331

3432
echo "Starting Selenium Grid Node with configuration: "
35-
cat ${CONFIG_TOML_FILE}
33+
cat /opt/selenium/config.toml
3634

3735
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar node \
38-
--config ${CONFIG_TOML_FILE} \
36+
--config /opt/selenium/config.toml \
3937
${SE_OPTS}

NodeChrome/Dockerfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ RUN if [ -z "$CHROME_DRIVER_VERSION" ]; \
5050
COPY generate_config /opt/bin/generate_config
5151

5252
# Generating a default config during build time
53-
RUN /opt/bin/generate_config > /opt/selenium/config.toml
53+
RUN /opt/bin/generate_config

NodeChrome/generate_config

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@
22

33
# CHROME_VERSION=$(/usr/bin/google-chrome -version | awk '{ print $3 }')
44

5-
cat <<_EOF
6-
[node]
5+
echo "[node]
76
max-concurrent-sessions = ${SE_NODE_MAX_CONCURRENT_SESSIONS}
8-
97
[events]
10-
publish = "tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_PUBLISH_PORT}"
11-
subscribe = "tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_SUBSCRIBE_PORT}"
8+
publish = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_PUBLISH_PORT}\"
9+
subscribe = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_SUBSCRIBE_PORT}\"
10+
" > /opt/selenium/config.toml
11+
12+
13+
if [[ -z "${SE_NODE_HOST}" ]] || [[ -z "${SE_NODE_PORT}" ]]; then
14+
echo "SE_NODE_HOST and SE_NODE_PORT not found."
15+
else
16+
echo "[server]" >> /opt/selenium/config.toml
17+
fi
18+
19+
if [[ -z "${SE_NODE_HOST}" ]] || [[ -z "${SE_NODE_PORT}" ]]; then
20+
echo "SE_NODE_HOST and SE_NODE_PORT not found."
21+
else
22+
echo "[server]" >> /opt/selenium/config.toml
23+
fi
24+
25+
if [[ -z "${SE_NODE_HOST}" ]]; then
26+
echo "Using default SE_NODE_HOST."
27+
else
28+
echo "hostname = \"${SE_NODE_HOST}\"" >> /opt/selenium/config.toml
29+
fi
1230

13-
_EOF
31+
if [[ -z "${SE_NODE_PORT}" ]]; then
32+
echo "Using default SE_NODE_PORT."
33+
else
34+
echo "port = \"${SE_NODE_PORT}\"" >> /opt/selenium/config.toml
35+
fi

NodeDocker/config.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,17 @@ configs = [
1313
# To have Docker listening through tcp on macOS, install socat and run the following command
1414
# socat -4 TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock
1515
host = "tcp://host.docker.internal:2375"
16+
# Docker imagee used for video recording
17+
video-image = "selenium/video:ffmpeg-4.3.1-20201127"
18+
# Absolute path where test assets will be stored (this path must exist on the host)
19+
assets-path = "/assets/path/on/your/host/machine"
20+
# Absolute path where test assets will be stored inside the container
21+
# "/opt/selenium/assets" already exists inside the containers
22+
# If you want to use another one, be sure it exists.
23+
container-assets-path = "/opt/selenium/assets"
24+
25+
# Uncomment the following section if you are running the node on a separate VM
26+
# Fill out the placeholders with appropriate values
27+
#[server]
28+
#hostname = <ip-from-node-machine>
29+
#port = <port-from-node-machine>

NodeDocker/start-selenium-grid-node-docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ fi
2323
java ${JAVA_OPTS} -jar /opt/selenium/selenium-server.jar node \
2424
--publish-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_PUBLISH_PORT} \
2525
--subscribe-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_SUBSCRIBE_PORT} \
26-
--detect-drivers false \
27-
--config /opt/bin/config.toml \
26+
--detect-drivers false \
27+
--config /opt/bin/config.toml \
2828
${SE_OPTS}

NodeFirefox/Dockerfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ USER 1200
3535
COPY generate_config /opt/bin/generate_config
3636

3737
# Generating a default config during build time
38-
RUN /opt/bin/generate_config > /opt/selenium/config.toml
38+
RUN /opt/bin/generate_config
3939

4040
#==========
4141
# Relaxing permissions for OpenShift and other non-sudo environments

NodeFirefox/generate_config

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,34 @@
33
#FIREFOX_VERSION=$( firefox -version | cut -d " " -f 3 )
44
#DRIVER_LOGLEVEL=${DRIVER_LOGLEVEL:-info}
55

6-
cat <<_EOF
7-
[node]
6+
echo "[node]
87
max-concurrent-sessions = ${SE_NODE_MAX_CONCURRENT_SESSIONS}
9-
108
[events]
11-
publish = "tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_PUBLISH_PORT}"
12-
subscribe = "tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_SUBSCRIBE_PORT}"
9+
publish = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_PUBLISH_PORT}\"
10+
subscribe = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_SUBSCRIBE_PORT}\"
11+
" > /opt/selenium/config.toml
12+
13+
14+
if [[ -z "${SE_NODE_HOST}" ]] || [[ -z "${SE_NODE_PORT}" ]]; then
15+
echo "SE_NODE_HOST and SE_NODE_PORT not found."
16+
else
17+
echo "[server]" >> /opt/selenium/config.toml
18+
fi
19+
20+
if [[ -z "${SE_NODE_HOST}" ]] || [[ -z "${SE_NODE_PORT}" ]]; then
21+
echo "SE_NODE_HOST and SE_NODE_PORT not found."
22+
else
23+
echo "[server]" >> /opt/selenium/config.toml
24+
fi
25+
26+
if [[ -z "${SE_NODE_HOST}" ]]; then
27+
echo "Using default SE_NODE_HOST."
28+
else
29+
echo "hostname = \"${SE_NODE_HOST}\"" >> /opt/selenium/config.toml
30+
fi
1331

14-
_EOF
32+
if [[ -z "${SE_NODE_PORT}" ]]; then
33+
echo "Using default SE_NODE_PORT."
34+
else
35+
echo "port = \"${SE_NODE_PORT}\"" >> /opt/selenium/config.toml
36+
fi

NodeOpera/Dockerfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ RUN LATEST_VERSION=$(curl -s https://api.github.com/repos/operasoftware/operachr
5555
COPY generate_config /opt/bin/generate_config
5656

5757
# Generating a default config during build time
58-
RUN /opt/bin/generate_config > /opt/selenium/config.toml
58+
RUN /opt/bin/generate_config

NodeOpera/generate_config

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@
22

33
# OPERA_VERSION=$(opera -version)
44

5-
cat <<_EOF
6-
[node]
5+
echo "[node]
76
max-concurrent-sessions = ${SE_NODE_MAX_CONCURRENT_SESSIONS}
8-
97
[events]
10-
publish = "tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_PUBLISH_PORT}"
11-
subscribe = "tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_SUBSCRIBE_PORT}"
8+
publish = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_PUBLISH_PORT}\"
9+
subscribe = \"tcp://${SE_EVENT_BUS_HOST}:${SE_EVENT_BUS_SUBSCRIBE_PORT}\"
10+
" > /opt/selenium/config.toml
11+
12+
13+
if [[ -z "${SE_NODE_HOST}" ]] || [[ -z "${SE_NODE_PORT}" ]]; then
14+
echo "SE_NODE_HOST and SE_NODE_PORT not found."
15+
else
16+
echo "[server]" >> /opt/selenium/config.toml
17+
fi
18+
19+
if [[ -z "${SE_NODE_HOST}" ]] || [[ -z "${SE_NODE_PORT}" ]]; then
20+
echo "SE_NODE_HOST and SE_NODE_PORT not found."
21+
else
22+
echo "[server]" >> /opt/selenium/config.toml
23+
fi
24+
25+
if [[ -z "${SE_NODE_HOST}" ]]; then
26+
echo "Using default SE_NODE_HOST."
27+
else
28+
echo "hostname = \"${SE_NODE_HOST}\"" >> /opt/selenium/config.toml
29+
fi
1230

13-
_EOF
31+
if [[ -z "${SE_NODE_PORT}" ]]; then
32+
echo "Using default SE_NODE_PORT."
33+
else
34+
echo "port = \"${SE_NODE_PORT}\"" >> /opt/selenium/config.toml
35+
fi

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,48 @@ When you are done using the Grid, and the containers have exited, the network ca
110110
$ docker network rm grid
111111
```
112112

113+
### Using different machines/VMs
114+
The Hub and Nodes will be created on different machines/VMs, they need to know each other's IPs to
115+
communicate properly.
116+
117+
Hub - Machine/VM 1
118+
``` bash
119+
$ docker run -d -p 4442-4444:4442-4444 --name selenium-hub selenium/hub:4.0.0-prerelease-beta-1-prerelease-20201127
120+
```
121+
122+
Node Chrome - Machine/VM 2
123+
``` bash
124+
$ docker run -d -p 5555:5555
125+
-e SE_EVENT_BUS_HOST=<ip-from-machine-1> \
126+
-e SE_EVENT_BUS_PUBLISH_PORT=4442 \
127+
-e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
128+
-e SE_NODE_HOST=<ip-from-machine-2> \
129+
-v /dev/shm:/dev/shm \
130+
selenium/node-chrome:4.0.0-prerelease-beta-1-prerelease-20201127
131+
```
132+
133+
Node Firefox - Machine/VM 3
134+
``` bash
135+
$ docker run -d -p 5555:5555
136+
-e SE_EVENT_BUS_HOST=<ip-from-machine-1> \
137+
-e SE_EVENT_BUS_PUBLISH_PORT=4442 \
138+
-e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
139+
-e SE_NODE_HOST=<ip-from-machine-3> \
140+
-v /dev/shm:/dev/shm \
141+
selenium/node-firefox:4.0.0-prerelease-beta-1-prerelease-20201127
142+
```
143+
144+
Node Opera - Machine/VM 4
145+
``` bash
146+
$ docker run -d -p 5555:5555
147+
-e SE_EVENT_BUS_HOST=<ip-from-machine-1> \
148+
-e SE_EVENT_BUS_PUBLISH_PORT=4442 \
149+
-e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
150+
-e SE_NODE_HOST=<ip-from-machine-4> \
151+
-v /dev/shm:/dev/shm \
152+
selenium/node-opera:4.0.0-prerelease-beta-1-prerelease-20201127
153+
```
154+
113155
### Docker Compose
114156
[Docker Compose](https://docs.docker.com/compose/) is the simplest way to start a Grid. Use the
115157
linked resources below, save them locally, and check the execution instructions on top of each file.
@@ -216,6 +258,12 @@ assets-path = "/assets/path/on/your/host/machine"
216258
# "/opt/selenium/assets" already exists inside the containers
217259
# If you want to use another one, be sure it exists.
218260
container-assets-path = "/opt/selenium/assets"
261+
262+
# Uncomment the following section if you are running the node on a separate VM
263+
# Fill out the placeholders with appropriate values
264+
#[server]
265+
#hostname = <ip-from-node-machine>
266+
#port = <port-from-node-machine>
219267
```
220268

221269
### Execution with Hub & Node roles

tests/K8sSmokeTest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
import time
31
import json
42
import sys
53
import time
@@ -13,6 +11,7 @@
1311
max_attempts = 6
1412
sleep_interval = 10
1513

14+
1615
def get_grid_status():
1716
try:
1817
response = urlopen('%s/status1' % (SELENIUM_GRID_URL))
@@ -26,6 +25,7 @@ def get_grid_status():
2625
except Exception as e:
2726
return False
2827

28+
2929
def wait_for_grid_to_get_ready():
3030
result = get_grid_status()
3131
ctr=0
@@ -41,4 +41,5 @@ def wait_for_grid_to_get_ready():
4141
print("Grid Status: " + str(result))
4242
print("Grid is in Ready state now")
4343

44+
4445
wait_for_grid_to_get_ready()

tests/test.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import os
2-
import docker
3-
import unittest
41
import logging
5-
import sys
2+
import os
63
import random
4+
import sys
5+
import unittest
76

7+
import docker
88
from docker.errors import NotFound
99

1010
# LOGGING #
@@ -79,9 +79,11 @@ def launch_hub(network_name):
7979

8080
grid_ports = {'4442': 4442, '4443': 4443, '4444': 4444}
8181
if use_random_user_id:
82-
hub_container_id = launch_container('Hub', network=network_name, name="selenium-hub", ports=grid_ports, user=random_user_id)
82+
hub_container_id = launch_container('Hub', network=network_name, name="selenium-hub",
83+
ports=grid_ports, user=random_user_id)
8384
else:
84-
hub_container_id = launch_container('Hub', network=network_name, name="selenium-hub", ports=grid_ports)
85+
hub_container_id = launch_container('Hub', network=network_name, name="selenium-hub",
86+
ports=grid_ports)
8587

8688
logger.info("Hub Launched")
8789
return hub_container_id

0 commit comments

Comments
 (0)