Skip to content

Commit

Permalink
Merge branch 'master' into 'master'
Browse files Browse the repository at this point in the history
Fix case where 'up' wasn't seeing already running foreground host component

See merge request te/devlab!16
  • Loading branch information
Dan Farnsworth committed Nov 30, 2020
2 parents 248c795 + a36931c commit ac75184
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ All Keys that are in **bold** are required
| run_opts | List of Strings | Additional options to pass to `docker run`. Each CLI arg must be it's own element. For example: `[ '--ip', '172.30.255.2' ]` would become `docker run --ip 172.30.255.2 IMAGE COMMAND` etc... |
| pre_scripts | List of Strings | Scripts to run *before* starting the component's container. These are only executed the first time a component is started, and are part of the 'provisioning' steps. The string follows the [Script Runner Syntax](#script-runner-syntax) |
| scripts | List of Strings | Scripts to run *after* starting the component's container. These are only excecuted the first time a component is started, and are part of the 'provisioning' steps. The string follows the [Script Runner Syntax](#script-runner-syntax) |
| post_up_scripts | List of Strings | Scripts to run *after* the component has been started and provisioned. These are executed ***EVERY*** single time the component is started |
| post_up_scripts | List of Strings | Scripts to run *after* the component has been started and provisioned. These are executed ***EVERY*** single time the component is started. The string follows the [Script Runner Syntax](#script-runner-syntax) |
| status_script | String | Script to run for the component as part of the devlab [status](#status-action) action. The string follows the [Script Runner Syntax](#script-runner-syntax). The output must conform to the [Status Command API](#status-command-api) |
| shell | String | The path to the shell inside the container that will be the default command when using the devlab [sh](#sh-action) action |
| ordinal | Hash | This is used indicate the order of the components. When parallel execution is supported, the `group` key indicates the components that can be brought up at the same time, `number` indicates the order inside the group to start up |
Expand Down
40 changes: 21 additions & 19 deletions devlab_bench/actions/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ def action(**kwargs):
for comp in components:
if comp == foreground_comp_name:
comp_type = config['foreground_component'].get('type', 'container')
comp_config = config['foreground_component']
else:
comp_type = config['components'][comp].get('type', 'container')
comp_config = config['components'][comp]
if comp_type == 'host':
if up_env.get('{}_PID'.format(comp.upper()), None):
comp_pid = up_env.get('{}_PID'.format(comp.upper()), None)
comp_config['pid'] = comp_pid
if comp_pid:
log.debug('Found pid in devlab up environemnt file for comp: %s, pid: %s', comp, comp_pid)
try:
Expand Down Expand Up @@ -140,17 +143,19 @@ def action(**kwargs):
status_ports = []
if comp == foreground_comp_name:
comp_type = config['foreground_component'].get('type', 'container')
comp_config = config['foreground_component']
else:
comp_type = config['components'][comp].get('type', 'container')
comp_config = config['components'][comp]
if comp in existing_components:
status_row['container_name'] = '{}-devlab'.format(comp)
format_fillers['container_name'] = status_row['container_name']
if comp in running_components:
if comp_type == 'host':
status_row['container_name'] = 'N/A (cmd on host)'
status_row['container_name'] = 'N/A (pid={})'.format(comp_config.get('pid', '???'))
try:
first_port = True
for port in config['components'][comp]['ports']:
for port in comp_config['ports']:
local_port = parse_docker_local_ports(port)
if first_port:
status_row['local_port'] = local_port
Expand All @@ -169,26 +174,23 @@ def action(**kwargs):
status_row['status'] = 'up'
status_script = ''
try:
status_script = config['components'][comp]['status_script']
status_script = comp_config['status_script']
if status_script:
log.debug("Found status script: '%s'", status_script)
except KeyError:
try:
status_script = config['foreground_component']['status_script']
except KeyError:
log.debug("Skipping status script for component: '%s' as none is defined", comp)
if format_fillers['local_port']:
status_row['health'] = 'healthy'
for port in config['components'][comp]['ports']:
if 'udp' in port:
continue
port = parse_docker_local_ports(port)
log.debug("Performing basic port check on '%s', port '%s', for health check", comp, port)
if not port_check('127.0.0.1', format_fillers['local_port'].split('-')[0].split('(')[0]):
log.warning("Basic port status check failed for '%s', port '%s'", comp, port)
status_row['health'] = 'degraded'
else:
log.debug("Basic port status check successful for '%s', port '%s'", comp, port)
log.debug("Skipping status script for component: '%s' as none is defined", comp)
if format_fillers['local_port']:
status_row['health'] = 'healthy'
for port in comp_config['ports']:
if 'udp' in port:
continue
port = parse_docker_local_ports(port)
log.debug("Performing basic port check on '%s', port '%s', for health check", comp, port)
if not port_check('127.0.0.1', format_fillers['local_port'].split('-')[0].split('(')[0]):
log.warning("Basic port status check failed for '%s', port '%s'", comp, port)
status_row['health'] = 'degraded'
else:
log.debug("Basic port status check successful for '%s', port '%s'", comp, port)
if status_script:
script_ret = script_runner(status_script, name=status_row['container_name'], interactive=False, log_output=False)
if script_ret[0] != 0:
Expand Down
8 changes: 5 additions & 3 deletions devlab_bench/actions/up.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def action(components='*', skip_provision=False, bind_to_host=False, keep_up_on_
os.mkdir('{}/{}'.format(devlab_bench.PROJ_ROOT, config['paths']['component_persistence']))
if os.path.isfile(devlab_bench.UP_ENV_FILE):
prev_env = get_env_from_file(devlab_bench.UP_ENV_FILE)
if prev_env['BIND_TO_HOST'] != up_env['BIND_TO_HOST']:
cur_bind = up_env['BIND_TO_HOST']
up_env.update(prev_env)
if prev_env['BIND_TO_HOST'] != cur_bind:
log.warning("Previous devlab environment was stood up with --bind-to-host set to: %s. Starting with the --bind-to-host set to: %s anyway", prev_env['BIND_TO_HOST'], prev_env['BIND_TO_HOST'])
up_env['BIND_TO_HOST'] = prev_env['BIND_TO_HOST']
else:
Expand Down Expand Up @@ -211,13 +213,13 @@ def component_up(name, comp_config, skip_provision=False, keep_up_on_error=False
log.debug("Component: '%s' is of type 'host'", comp)
#Look up to see if there is a PID for the 'host' component
if os.path.isfile(devlab_bench.UP_ENV_FILE):
log.debug("Found devlab_up.env file, loading vars from it for component '%s' to see if this 'host' type component has a PID", name)
log.debug("Found devlab_up.env file, loading vars from it for component '%s' to see if this 'host' type component has a PID", comp)
up_env = get_env_from_file(devlab_bench.UP_ENV_FILE)
comp_pid = int(up_env.get('{}_PID'.format(comp.upper()), False))
if up_env.get('{}_PID'.format(comp.upper()), None):
log.debug("Found component PID: %s", comp_pid)
else:
log.error("Component: '%s' is of unknown type '%s'", name, comp_type)
log.error("Component: '%s' is of unknown type '%s'", comp, comp_type)
return False
while True:
if comp_type == 'host':
Expand Down

0 comments on commit ac75184

Please sign in to comment.