Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal network #1030

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/schema_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ def validate_networks_no_invalid_chars(self, value):
elif isinstance(value, dict):
for key, item in value.items():
self.contains_no_invalid_chars(key)
if item is not None:
self.contains_no_invalid_chars(item)
if item and 'internal' in item:
if not isinstance(item['internal'], bool):
raise SchemaError("networks modifier 'internal' must be boolean")
ArneTR marked this conversation as resolved.
Show resolved Hide resolved
else:
raise SchemaError("'networks' should be a list or a dictionary")

Expand Down
7 changes: 6 additions & 1 deletion runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,12 @@ def setup_networks(self):
print('Creating network: ', network)
# remove first if present to not get error, but do not make check=True, as this would lead to inf. loop
subprocess.run(['docker', 'network', 'rm', network], stderr=subprocess.DEVNULL, check=False)
subprocess.run(['docker', 'network', 'create', network], check=True)

if self._usage_scenario['networks'][network] and self._usage_scenario['networks'][network].get('internal', False):
subprocess.check_output(['docker', 'network', 'create', '--internal', network])
else:
subprocess.check_output(['docker', 'network', 'create', network])

self.__networks.append(network)
else:
print(TerminalColors.HEADER, '\nNo network found. Creating default network', TerminalColors.ENDC)
Expand Down
24 changes: 24 additions & 0 deletions tests/data/usage_scenarios/internal_network.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Internal network test
author: Arne Tarara
description: test
ArneTR marked this conversation as resolved.
Show resolved Hide resolved

networks:
gmt-test-network:
internal: true

services:
test-container:
type: container
image: gcb_stress
build:
context: ../stress-application
networks:
- gmt-test-network

flow:
- name: External network should fail
container: test-container
commands:
- type: console
command: curl -s --fail https://www.google.de
ArneTR marked this conversation as resolved.
Show resolved Hide resolved
ArneTR marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions tests/test_usage_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,14 @@ def test_non_git_root_supplied():
Tests.assertion_info('Supplied folder through --uri is not the root of the git repository. Please only supply the root folder and then the target directory through --filename', str(e.value))


def test_internal_network():
runner = Runner(uri=GMT_DIR, uri_type='folder', filename='tests/data/usage_scenarios/internal_network.yml', skip_system_checks=True, dev_no_metrics=True, dev_no_phase_stats=True, dev_no_sleeps=True, dev_cache_build=True)

with pytest.raises(RuntimeError) as e:
runner.run()

assert str(e.value) == "Process '['docker', 'exec', 'test-container', 'curl', '-s', '--fail', 'https://www.google.de']' had bad returncode: 126. Stderr: ; Detached process: False. Please also check the stdout in the logs and / or enable stdout logging to debug further."
ArneTR marked this conversation as resolved.
Show resolved Hide resolved


## rethink this one
def wip_test_verbose_provider_boot():
Expand Down
Loading