Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
14 changes: 9 additions & 5 deletions lib/error_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def end_error(*errors):


def format_error(*errors):
err = 'Error: '
err = ''

for error in errors:
err += str(error)
err += str(error) + "\n"

error_string = f"""
\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 0_o >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n
{err}
Error: {err}
\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 0_o >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n
{traceback.format_exc()}
\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 0_o >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n
Expand All @@ -30,11 +30,15 @@ def format_error(*errors):
def log_error(*errors):
error_log_file = GlobalConfig().config['machine']['error_log_file']

err = ''
for error in errors:
err += str(error) + "\n"

if error_log_file:
try:
with open(error_log_file, 'a', encoding='utf-8') as file:
print('\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 0_o >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n', file=file)
print('Error: ', *errors, file=file)
print('Error: ', err, file=file)
print('\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 0_o >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n', file=file)
print(traceback.format_exc(), file=file)
print('\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 0_o >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n', file=file)
Expand All @@ -46,6 +50,6 @@ def log_error(*errors):
'\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 0_o >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n', file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
print('\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 0_o >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n', file=sys.stderr)
print('Error: ', *errors, file=sys.stderr)
print('Error: ', err, file=sys.stderr)
print('\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 0_o >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n',
TerminalColors.ENDC, file=sys.stderr)
9 changes: 9 additions & 0 deletions lib/schema_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ def check_usage_scenario(self, usage_scenario):
Optional("environment"): self.single_or_list(Or(dict,str)),
Optional("ports"): self.single_or_list(Or(str, int)),
Optional("depends_on"): Or([str],dict),
Optional("healthcheck"): {
Optional('test'): Or(list, str),
Optional('interval'): str,
Optional('timeout'): str,
Optional('retries'): int,
Optional('start_period'): str,
# Optional('start_interval'): str, docker CLI does not support this atm
Optional('disable'): bool,
},
Optional("setup-commands"): [str],
Optional("volumes"): self.single_or_list(str),
Optional("folder-destination"):str,
Expand Down
144 changes: 106 additions & 38 deletions runner.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Test depends_on
author: Arne Tarara <[email protected]>
description: test

services:
test-container-1:
image: alpine
depends_on:
test-container-2:
condition: service_completed_successfully
test-container-2:
image: alpine

flow:
- name: dummy
container: test-container-1
commands:
- type: console
command: pwd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Test depends_on
name: Test depends_on long_form
author: David Kopp
description: test

Expand Down
23 changes: 23 additions & 0 deletions tests/data/usage_scenarios/healthcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Test depends_on
author: David Kopp
description: test

services:
test-container-1:
image: alpine
depends_on:
test-container-2:
condition: service_healthy
test-container-2:
image: alpine
healthcheck:
test: ls
interval: 1s

flow:
- name: dummy
container: test-container-1
commands:
- type: console
command: pwd
20 changes: 20 additions & 0 deletions tests/data/usage_scenarios/healthcheck_error_missing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Test depends_on
author: David Kopp
description: test

services:
test-container-1:
image: alpine
depends_on:
test-container-2:
condition: service_healthy
test-container-2:
image: alpine

flow:
- name: dummy
container: test-container-1
commands:
- type: console
command: pwd
50 changes: 39 additions & 11 deletions tests/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ def setup_module(module):
err = io.StringIO()
GlobalConfig(config_name='test-config.yml').config
with redirect_stdout(out), redirect_stderr(err):
uri = os.path.abspath(os.path.join(
CURRENT_DIR, 'stress-application/'))
uri = os.path.abspath(os.path.join(CURRENT_DIR, 'stress-application/'))
subprocess.run(['docker', 'compose', '-f', uri+'/compose.yml', 'build'], check=True)

# Run the application
runner = Runner(name=RUN_NAME, uri=uri, uri_type='folder', dev_repeat_run=True, skip_system_checks=True)
runner = Runner(name=RUN_NAME, uri=uri, uri_type='folder', dev_no_build=True, dev_no_sleeps=True, dev_no_metrics=False, skip_system_checks=True)
runner.run()

#pylint: disable=global-statement
Expand Down Expand Up @@ -87,6 +86,26 @@ def test_db_rows_are_written_and_presented():
if 'NetworkConnectionsProxyContainerProvider' in metric_providers:
metric_providers.remove('NetworkConnectionsProxyContainerProvider')


if 'PowermetricsProvider' in metric_providers:
# The problem here is that the powermetrics provider splits up the output of powermetrics and acts like
# there are loads of providers. This makes a lot easier in showing and processing the data but is
# not std behavior. That is also why we need to patch the imported check down below.
pm_additional_list = [
'cpu_time_powermetrics_vm',
'disk_io_bytesread_powermetrics_vm',
'disk_io_byteswritten_powermetrics_vm',
'energy_impact_powermetrics_vm',
'cores_energy_powermetrics_component',
'cpu_energy_powermetrics_component',
'gpu_energy_powermetrics_component',
'ane_energy_powermetrics_component',
]

metric_providers.extend([utils.get_pascal_case(i) + 'Provider' for i in pm_additional_list])

do_check = True

for d in data:
d_provider = utils.get_pascal_case(d[0]) + 'Provider'
d_count = d[1]
Expand All @@ -96,11 +115,20 @@ def test_db_rows_are_written_and_presented():
## Assert the number of rows for that provider is at least 1
assert d_count > 0

## Assert the information printed to std.out matches what's in the db
match = re.search(rf"Imported \S* (\d+) \S* metrics from\s*{d_provider}", run_stdout)
assert match is not None
assert int(match.group(1)) == d_count

## Assert that all the providers in the config are represented
metric_providers.remove(d_provider)
assert len(metric_providers) == 0
if do_check:
if 'PowermetricsProvider' in metric_providers:
## Assert the information printed to std.out matches what's in the db
match = re.search(r"Imported \S* (\d+) \S* metrics from PowermetricsProvider", run_stdout, re.MULTILINE)
assert match is not None
do_check = False
else:
## Assert the information printed to std.out matches what's in the db
match = re.search(rf"Imported \S* (\d+) \S* metrics from\s*{d_provider}", run_stdout)
assert match is not None
assert int(match.group(1)) == d_count

## Assert that all the providers in the config are represented
metric_providers.remove(d_provider)

if not 'PowermetricsProvider' in metric_providers:
assert len(metric_providers) == 0
8 changes: 4 additions & 4 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def replace_include_in_usage_scenario(usage_scenario_path, docker_compose_filena

def setup_runner(usage_scenario, docker_compose=None, uri='default', uri_type='folder', branch=None,
debug_mode=False, allow_unsafe=False, no_file_cleanup=False,
skip_unsafe=False, verbose_provider_boot=False, dir_name=None, dev_repeat_run=True, skip_system_checks=True,
dry_run=False):
skip_unsafe=False, verbose_provider_boot=False, dir_name=None, dev_no_build=False, skip_system_checks=True,
dev_no_sleeps=True, dev_no_metrics=True):
usage_scenario_path = os.path.join(CURRENT_DIR, 'data/usage_scenarios/', usage_scenario)
if docker_compose is not None:
docker_compose_path = os.path.join(CURRENT_DIR, 'data/docker-compose-files/', docker_compose)
Expand All @@ -53,8 +53,8 @@ def setup_runner(usage_scenario, docker_compose=None, uri='default', uri_type='f

return Runner(name=RUN_NAME, uri=uri, uri_type=uri_type, filename=usage_scenario, branch=branch,
debug_mode=debug_mode, allow_unsafe=allow_unsafe, no_file_cleanup=no_file_cleanup,
skip_unsafe=skip_unsafe, verbose_provider_boot=verbose_provider_boot, dev_repeat_run=dev_repeat_run,
skip_system_checks=skip_system_checks, dry_run=dry_run)
skip_unsafe=skip_unsafe, verbose_provider_boot=verbose_provider_boot, dev_no_build=dev_no_build,
skip_system_checks=skip_system_checks, dev_no_sleeps=dev_no_sleeps, dev_no_metrics=dev_no_metrics)

# This function runs the runner up to and *including* the specified step
# remember to catch in try:finally and do cleanup when calling this!
Expand Down
Loading