Skip to content

Commit 412913b

Browse files
committed
Added dev_no_sleep, dev_no_metrics, dev_no_build
1 parent 6389d09 commit 412913b

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

runner.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self,
8989
name, uri, uri_type, filename='usage_scenario.yml', branch=None,
9090
debug_mode=False, allow_unsafe=False, no_file_cleanup=False, skip_system_checks=False,
9191
skip_unsafe=False, verbose_provider_boot=False, full_docker_prune=False,
92-
dry_run=False, dev_repeat_run=False, docker_prune=False, job_id=None):
92+
dev_no_sleeps=False, dev_no_build=False, dev_no_metrics=False, docker_prune=False, job_id=None):
9393

9494
if skip_unsafe is True and allow_unsafe is True:
9595
raise RuntimeError('Cannot specify both --skip-unsafe and --allow-unsafe')
@@ -104,8 +104,9 @@ def __init__(self,
104104
self._verbose_provider_boot = verbose_provider_boot
105105
self._full_docker_prune = full_docker_prune
106106
self._docker_prune = docker_prune
107-
self._dry_run = dry_run
108-
self._dev_repeat_run = dev_repeat_run
107+
self._dev_no_sleeps = dev_no_sleeps
108+
self._dev_no_build = dev_no_build
109+
self._dev_no_metrics = dev_no_metrics
109110
self._uri = uri
110111
self._uri_type = uri_type
111112
self._original_filename = filename
@@ -145,7 +146,7 @@ def __init__(self,
145146
# self.__filename = self._original_filename # this can be changed later if working directory changes
146147

147148
def custom_sleep(self, sleep_time):
148-
if not self._dry_run:
149+
if not self._dev_no_sleeps:
149150
print(TerminalColors.HEADER, '\nSleeping for : ', sleep_time, TerminalColors.ENDC)
150151
time.sleep(sleep_time)
151152

@@ -387,13 +388,13 @@ def check_running_containers(self):
387388
def populate_image_names(self):
388389
for service_name, service in self._usage_scenario.get('services', []).items():
389390
if not service.get('image', None): # image is a non-mandatory field. But we need it, so we tmp it
390-
if self._dev_repeat_run:
391+
if self._dev_no_build:
391392
service['image'] = f"{service_name}"
392393
else:
393394
service['image'] = f"{service_name}_{random.randint(500000,10000000)}"
394395

395396
def remove_docker_images(self):
396-
if self._dev_repeat_run:
397+
if self._dev_no_build:
397398
return
398399

399400
print(TerminalColors.HEADER, '\nRemoving all temporary GMT images', TerminalColors.ENDC)
@@ -477,6 +478,10 @@ def update_and_insert_specs(self):
477478
)
478479

479480
def import_metric_providers(self):
481+
if self._dev_no_metrics:
482+
print(TerminalColors.HEADER, '\nSkipping import of metric providers', TerminalColors.ENDC)
483+
return
484+
480485
config = GlobalConfig().config
481486

482487
print(TerminalColors.HEADER, '\nImporting metric providers', TerminalColors.ENDC)
@@ -517,6 +522,10 @@ def import_metric_providers(self):
517522
self.__metric_providers.sort(key=lambda item: 'rapl' not in item.__class__.__name__.lower())
518523

519524
def download_dependencies(self):
525+
if self._dev_no_build:
526+
print(TerminalColors.HEADER, '\nSkipping downloading dependencies', TerminalColors.ENDC)
527+
return
528+
520529
print(TerminalColors.HEADER, '\nDownloading dependencies', TerminalColors.ENDC)
521530
subprocess.run(['docker', 'pull', 'gcr.io/kaniko-project/executor:latest'], check=True)
522531

@@ -564,6 +573,7 @@ def build_docker_images(self):
564573
encoding='UTF-8',
565574
check=True)
566575
# The image exists so exit and don't build
576+
print(f"Image {service['image']} exists in build cache. Skipping build ...")
567577
continue
568578
except subprocess.CalledProcessError:
569579
pass
@@ -940,6 +950,9 @@ def add_to_log(self, container_name, message, cmd=''):
940950

941951

942952
def start_metric_providers(self, allow_container=True, allow_other=True):
953+
if self._dev_no_metrics:
954+
return
955+
943956
print(TerminalColors.HEADER, '\nStarting metric providers', TerminalColors.ENDC)
944957

945958
for metric_provider in self.__metric_providers:
@@ -1092,6 +1105,9 @@ def run_flows(self):
10921105

10931106
# this function should never be called twice to avoid double logging of metrics
10941107
def stop_metric_providers(self):
1108+
if self._dev_no_metrics:
1109+
return
1110+
10951111
print(TerminalColors.HEADER, 'Stopping metric providers and parsing measurements', TerminalColors.ENDC)
10961112
errors = []
10971113
for metric_provider in self.__metric_providers:
@@ -1419,8 +1435,9 @@ def run(self):
14191435
parser.add_argument('--verbose-provider-boot', action='store_true', help='Boot metric providers gradually')
14201436
parser.add_argument('--full-docker-prune', action='store_true', help='Stop and remove all containers, build caches, volumes and images on the system')
14211437
parser.add_argument('--docker-prune', action='store_true', help='Prune all unassociated build caches, networks volumes and stopped containers on the system')
1422-
parser.add_argument('--dry-run', action='store_true', help='Removes all sleeps. Resulting measurement data will be skewed.')
1423-
parser.add_argument('--dev-repeat-run', action='store_true', help='Checks if a docker image is already in the local cache and will then not build it. Also doesn\'t clear the images after a run')
1438+
parser.add_argument('--dev-no-metrics', action='store_true', help='Skips loading the metric providers. Runs will be faster, but you will have no metric')
1439+
parser.add_argument('--dev-no-sleeps', action='store_true', help='Removes all sleeps. Resulting measurement data will be skewed.')
1440+
parser.add_argument('--dev-no-build', action='store_true', help='Checks if a container images are already in the local cache and will then not build it. Also doesn\'t clear the images after a run. Please note that skipping builds only works the second time you make a run.')
14241441
parser.add_argument('--print-logs', action='store_true', help='Prints the container and process logs to stdout')
14251442

14261443
args = parser.parse_args()
@@ -1435,9 +1452,9 @@ def run(self):
14351452
error_helpers.log_error('--allow-unsafe and skip--unsafe in conjuction is not possible')
14361453
sys.exit(1)
14371454

1438-
if args.dev_repeat_run and (args.docker_prune or args.full_docker_prune):
1455+
if args.dev_no_build and (args.docker_prune or args.full_docker_prune):
14391456
parser.print_help()
1440-
error_helpers.log_error('--dev-repeat-run blocks pruning docker images. Combination is not allowed')
1457+
error_helpers.log_error('--dev-no-build blocks pruning docker images. Combination is not allowed')
14411458
sys.exit(1)
14421459

14431460
if args.full_docker_prune and GlobalConfig().config['postgresql']['host'] == 'green-coding-postgres-container':
@@ -1480,8 +1497,8 @@ def run(self):
14801497
branch=args.branch, debug_mode=args.debug, allow_unsafe=args.allow_unsafe,
14811498
no_file_cleanup=args.no_file_cleanup, skip_system_checks=args.skip_system_checks,
14821499
skip_unsafe=args.skip_unsafe,verbose_provider_boot=args.verbose_provider_boot,
1483-
full_docker_prune=args.full_docker_prune, dry_run=args.dry_run,
1484-
dev_repeat_run=args.dev_repeat_run, docker_prune=args.docker_prune)
1500+
full_docker_prune=args.full_docker_prune, dev_no_sleeps=args.dev_no_sleeps,
1501+
dev_no_build=args.dev_no_build, dev_no_metrics=args.dev_no_metrics, docker_prune=args.docker_prune)
14851502

14861503
# Using a very broad exception makes sense in this case as we have excepted all the specific ones before
14871504
#pylint: disable=broad-except

0 commit comments

Comments
 (0)