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

Allow services to be omitted in usage_scenario #556

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions lib/schema_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ def check_usage_scenario(self, usage_scenario):
if 'networks' in usage_scenario:
self.validate_networks_no_invalid_chars(usage_scenario['networks'])

for service_name in usage_scenario.get('services'):
service = usage_scenario['services'][service_name]
if 'image' not in service and 'build' not in service:
raise SchemaError("The 'image' key under services is required when 'build' key is not present.")
if 'services' in usage_scenario:
for service_name in usage_scenario.get('services'):
service = usage_scenario['services'][service_name]
if 'image' not in service and 'build' not in service:
raise SchemaError("The 'image' key under services is required when 'build' key is not present.")

usage_scenario_schema.validate(usage_scenario)

Expand Down
13 changes: 6 additions & 7 deletions runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ def merge_dicts(dict1, dict2):
# creating benchmarking scripts and you want to have all options in the compose but not in each benchmark.
# The cleaner way would be to handle an empty service key throughout the code but would make it quite messy
# so we chose to remove it right at the start.
for key in [sname for sname, content in yml_obj['services'].items() if content is None]:
del yml_obj['services'][key]
if 'services' in yml_obj:
for key in [sname for sname, content in yml_obj['services'].items() if content is None]:
del yml_obj['services'][key]

self._usage_scenario = yml_obj

Expand Down Expand Up @@ -379,7 +380,7 @@ def check_running_containers(self):
raise PermissionError(f"Container '{container_name}' is already running on system. Please close it before running the tool.")

def populate_image_names(self):
for service_name, service in self._usage_scenario.get('services', []).items():
for service_name, service in self._usage_scenario.get('services', {}).items():
if not service.get('image', None): # image is a non essential field. But we need it, so we tmp it
if self._dev_repeat_run:
service['image'] = f"{service_name}"
Expand Down Expand Up @@ -541,7 +542,7 @@ def build_docker_images(self):

# technically the usage_scenario needs no services and can also operate on an empty list
# This use case is when you have running containers on your host and want to benchmark some code running in them
for _, service in self._usage_scenario.get('services', []).items():
for _, service in self._usage_scenario.get('services', {}).items():
# minimal protection from possible shell escapes.
# since we use subprocess without shell we should be safe though
if re.findall(r'(\.\.|\$|\'|"|`|!)', service['image']):
Expand Down Expand Up @@ -640,16 +641,14 @@ def setup_networks(self):
def setup_services(self):
# technically the usage_scenario needs no services and can also operate on an empty list
# This use case is when you have running containers on your host and want to benchmark some code running in them
for service_name in self._usage_scenario.get('services', []):
for service_name, service in self._usage_scenario.get('services', {}).items():
print(TerminalColors.HEADER, '\nSetting up containers', TerminalColors.ENDC)

if 'container_name' in self._usage_scenario['services'][service_name]:
container_name = self._usage_scenario['services'][service_name]['container_name']
else:
container_name = service_name

service = self._usage_scenario['services'][service_name]

print('Resetting container')
# By using the -f we return with 0 if no container is found
# we always reset container without checking if something is running, as we expect that a user understands
Expand Down
Loading