lager-cli 0.32.2__tar.gz → 0.32.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lager_cli-0.32.2/lager_cli.egg-info → lager_cli-0.32.3}/PKG-INFO +1 -1
- {lager_cli-0.32.2 → lager_cli-0.32.3}/__init__.py +1 -1
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/update.py +206 -22
- {lager_cli-0.32.2 → lager_cli-0.32.3/lager_cli.egg-info}/PKG-INFO +1 -1
- {lager_cli-0.32.2 → lager_cli-0.32.3}/lager_cli.egg-info/SOURCES.txt +1 -0
- lager_cli-0.32.3/tests/test_update_gate.py +164 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/LICENSE +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/MANIFEST.in +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/README.md +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/__main__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/address_utils.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/battery/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/battery/battery_tui.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/battery/websocket_client.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/box_storage.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/_host_ops.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/_mount_prep.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/_pip_validation.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/_shim_verbs.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/_ssh.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/box_group.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/boxes.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/config.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/diagnose.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/dut.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/hello.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/instruments.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/labjack_pins.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/lock.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/net_tui.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/nets.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/ssh.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/box/ssh_setup.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/communication/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/communication/ble.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/communication/blufi.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/communication/i2c.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/communication/router.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/communication/spi.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/communication/uart.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/communication/usb.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/communication/websocket_client.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/communication/wifi.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/arm.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/debug/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/debug/commands.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/debug/gdb.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/debug/net_cache.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/debug/service_client.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/debug/service_helper.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/debug/tunnel.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/devenv.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/development/python.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/measurement/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/measurement/adc.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/measurement/dac.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/measurement/energy.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/measurement/gpi.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/measurement/gpo.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/measurement/logic.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/measurement/scope.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/measurement/thermocouple.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/measurement/watt.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/power/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/power/battery.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/power/battery_model_csv.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/power/eload.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/power/solar.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/power/supply.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/binaries.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/defaults.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/exec_.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/install.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/install_wheel.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/login.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/logs.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/uninstall.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/commands/utility/webcam.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/config.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/context/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/context/ci_detection.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/context/constants.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/context/core.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/context/error_handlers.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/context/session.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/group_usage.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/matchers.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/net_group.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/net_helpers.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/net_storage.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/param_types.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/ssh_utils.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/utils.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/version_skew.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/core/ws_diagnose.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/deployment/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/deployment/scripts/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/deployment/scripts/configure_docker_dns.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/deployment/scripts/configure_docker_dns.sh +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/deployment/scripts/convert_to_sparse_checkout.sh +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/deployment/scripts/setup_and_deploy_box.sh +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/deployment/scripts/setup_ssh_key.sh +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/deployment/security/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/deployment/security/secure_box_firewall.sh +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/common/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/common/construct_utils.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/common/exceptions.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/common/py3compat.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/common/utils.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/construct/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/construct/adapters.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/construct/core.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/construct/debug.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/construct/macros.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/abbrevtable.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/aranges.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/callframe.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/compileunit.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/constants.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/descriptions.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/die.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/dwarf_expr.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/dwarfinfo.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/enums.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/lineprogram.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/locationlists.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/namelut.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/ranges.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/dwarf/structs.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/ehabi/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/ehabi/constants.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/ehabi/decoder.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/ehabi/ehabiinfo.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/ehabi/structs.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/constants.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/descriptions.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/dynamic.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/elffile.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/enums.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/gnuversions.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/hash.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/notes.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/relocation.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/sections.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/segments.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/elftools/elf/structs.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/errors.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/exceptions.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/gateway_auth.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/impl/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/impl/box_config.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/impl/measurement/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/impl/measurement/scope.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/impl/measurement/scope_stream.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/impl/power/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/impl/power/enable_disable.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/lager_cli.egg-info/dependency_links.txt +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/lager_cli.egg-info/entry_points.txt +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/lager_cli.egg-info/requires.txt +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/lager_cli.egg-info/top_level.txt +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/main.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/pyproject.toml +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/safe_unpickle.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/setup.cfg +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/setup.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/simple_hdlc.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/sort_utils.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/status.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/supply/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/supply/supply_tui.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/supply/websocket_client.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/terminal/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/terminal/core/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/terminal/core/executor.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/terminal/main.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/terminal/ui/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/terminal/ui/completer.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/terminal/ui/display.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/terminal/ui/logo.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/terminal/ui/repl.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/terminal/ui/themes.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/tests/test_box_lager_imports.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/tests/test_box_storage.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/tests/test_gateway_auth.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/tests/test_io_imports.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/update_check.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/vendor/PyCRC/CRC16.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/vendor/PyCRC/CRC16DNP.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/vendor/PyCRC/CRC16Kermit.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/vendor/PyCRC/CRC16SICK.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/vendor/PyCRC/CRC32.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/vendor/PyCRC/CRCCCITT.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/vendor/PyCRC/__init__.py +0 -0
- {lager_cli-0.32.2 → lager_cli-0.32.3}/vendor/__init__.py +0 -0
|
@@ -229,6 +229,15 @@ if test -f /etc/lager/.boxcfg-sudoers-v2 && sudo -n DEBIAN_FRONTEND=noninteracti
|
|
|
229
229
|
else
|
|
230
230
|
echo "LAGER_PROBE_BOXCFG_SUDOERS_OK=0"
|
|
231
231
|
fi
|
|
232
|
+
# Container liveness: 1 = the `lager` container is running, 0 = docker
|
|
233
|
+
# answered and it is not, empty = docker itself didn't answer (unknown;
|
|
234
|
+
# callers fail open). `docker ps` lists running containers only, and its
|
|
235
|
+
# name filter is a substring match, so exact-match the name on our side.
|
|
236
|
+
if _dps=$(docker ps --filter name=lager --format '{{.Names}}' 2>/dev/null); then
|
|
237
|
+
echo "LAGER_PROBE_LAGER_RUNNING=$(printf '%s\n' "$_dps" | grep -cx lager)"
|
|
238
|
+
else
|
|
239
|
+
echo "LAGER_PROBE_LAGER_RUNNING="
|
|
240
|
+
fi
|
|
232
241
|
echo "LAGER_PROBE_ETC_VERSION=$(cat /etc/lager/version 2>/dev/null)"
|
|
233
242
|
'''
|
|
234
243
|
return script.replace('__BUILD_HASH_CMD__', _build_hash_shell_cmd())
|
|
@@ -249,6 +258,60 @@ def _parse_probe_output(stdout):
|
|
|
249
258
|
return facts
|
|
250
259
|
|
|
251
260
|
|
|
261
|
+
def _build_hash_mismatch(new_hash, stored_hash):
|
|
262
|
+
"""True when the docker-build inputs changed relative to the last
|
|
263
|
+
successful build.
|
|
264
|
+
|
|
265
|
+
Both values must be non-empty: an empty new hash means the probe couldn't
|
|
266
|
+
measure the inputs, an empty stored hash means no successful build has
|
|
267
|
+
recorded one — in either case auto-invalidation is skipped rather than
|
|
268
|
+
guessed. A failed build stores the sentinel value 'FAILED' (never a real
|
|
269
|
+
sha256), which forces a mismatch — and therefore a clean rebuild — on the
|
|
270
|
+
next run.
|
|
271
|
+
"""
|
|
272
|
+
return bool(new_hash) and bool(stored_hash) and new_hash != stored_hash
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _rebuild_gate_verdict(facts, *, git_sync_confirmed, needs_pull,
|
|
276
|
+
needs_flatten, hash_mismatch, force):
|
|
277
|
+
"""Decide whether the update can stop before the container rebuild.
|
|
278
|
+
|
|
279
|
+
Returns:
|
|
280
|
+
'rebuild' — source state demands the full stop/build/start path.
|
|
281
|
+
'container-down' — source is in sync but the lager container is not
|
|
282
|
+
running (e.g. a previous update failed after the
|
|
283
|
+
containers were removed): rebuild so the box comes
|
|
284
|
+
back up, instead of falsely reporting success.
|
|
285
|
+
'skip' — in sync and running; safe to early-exit.
|
|
286
|
+
|
|
287
|
+
The probe's LAGER_RUNNING fact is tri-state: '1' running, '0' definitely
|
|
288
|
+
not running, ''/absent unknown (the docker probe itself failed). Only a
|
|
289
|
+
definite '0' blocks the skip — unknown fails open, same philosophy as the
|
|
290
|
+
BuildKit preflight.
|
|
291
|
+
"""
|
|
292
|
+
if not git_sync_confirmed or needs_pull or needs_flatten or hash_mismatch or force:
|
|
293
|
+
return 'rebuild'
|
|
294
|
+
if facts.get('LAGER_RUNNING', '') == '0':
|
|
295
|
+
return 'container-down'
|
|
296
|
+
return 'skip'
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def _deployed_version_stale(tree_version, etc_version_raw):
|
|
300
|
+
"""True when the box tree's version differs from the last version a
|
|
301
|
+
successful update actually deployed (/etc/lager/version, `box|cli`
|
|
302
|
+
format — written only after a successful rebuild+restart).
|
|
303
|
+
|
|
304
|
+
Catches the tree-ahead-of-deploy state: an update that pulled and then
|
|
305
|
+
exited before the container stop (BuildKit preflight failure, an
|
|
306
|
+
interrupt in the pull->stop window) leaves the container serving the
|
|
307
|
+
previous build while git reads as in sync and the container as running.
|
|
308
|
+
Unknown on either side fails open (returns False) so legacy boxes with a
|
|
309
|
+
missing/empty version file don't rebuild forever.
|
|
310
|
+
"""
|
|
311
|
+
deployed = (etc_version_raw or '').split('|', 1)[0].strip()
|
|
312
|
+
return bool(tree_version) and bool(deployed) and deployed != tree_version
|
|
313
|
+
|
|
314
|
+
|
|
252
315
|
# Progress-bar denominator. 15 steps always run; 3 are conditional (flatten,
|
|
253
316
|
# cached-image wipe, J-Link install). We use the max so the denominator never
|
|
254
317
|
# jumps mid-flight — light paths simply finish below 18/18 and `finish()`
|
|
@@ -1082,7 +1145,7 @@ def _update_logic(ctx, *, box, yes, version, verbose, check, force=False):
|
|
|
1082
1145
|
# any mutation (no git checkout, no udev install, no docker stop).
|
|
1083
1146
|
# Exit codes:
|
|
1084
1147
|
# 0 — already in sync, nothing to do
|
|
1085
|
-
# 1 — would update (code, deps, or
|
|
1148
|
+
# 1 — would update (code, deps, or a stopped container to bring back up)
|
|
1086
1149
|
# 2 — could not determine state (network error, etc.)
|
|
1087
1150
|
if check:
|
|
1088
1151
|
if progress:
|
|
@@ -1096,15 +1159,24 @@ def _update_logic(ctx, *, box, yes, version, verbose, check, force=False):
|
|
|
1096
1159
|
# reflect the tree that would be built — no extra round-trip needed.
|
|
1097
1160
|
_check_new_hash = facts.get('BUILD_HASH_NEW', '')
|
|
1098
1161
|
_check_stored_hash = facts.get('BUILD_HASH_STORED', '')
|
|
1099
|
-
deps_will_change = (
|
|
1100
|
-
|
|
1101
|
-
and _check_new_hash != _check_stored_hash
|
|
1102
|
-
)
|
|
1162
|
+
deps_will_change = _build_hash_mismatch(_check_new_hash, _check_stored_hash)
|
|
1163
|
+
container_down = facts.get('LAGER_RUNNING', '') == '0'
|
|
1103
1164
|
|
|
1104
1165
|
if not git_sync_confirmed:
|
|
1105
1166
|
click.secho('Could not determine update state (git rev-list failed).', fg='red', err=True)
|
|
1106
1167
|
ctx.exit(2)
|
|
1107
1168
|
|
|
1169
|
+
# Only worth a look when everything else reads clean — any other
|
|
1170
|
+
# divergence already forces the rebuild that would fix it. (Local
|
|
1171
|
+
# import: a later `import re` in this function makes `re` local to
|
|
1172
|
+
# the whole function, so the module-level binding is shadowed here.)
|
|
1173
|
+
deploy_stale = False
|
|
1174
|
+
if not container_down and commits_behind == 0 and commits_ahead == 0:
|
|
1175
|
+
import re
|
|
1176
|
+
_vp = re.match(r'^v?(\d+\.\d+\.\d+)$', target_version)
|
|
1177
|
+
_tree_v = _vp.group(1) if _vp else _read_box_source_version(run_ssh_command_with_output)
|
|
1178
|
+
deploy_stale = _deployed_version_stale(_tree_v, current_version_raw)
|
|
1179
|
+
|
|
1108
1180
|
if commits_behind == 0 and commits_ahead == 0:
|
|
1109
1181
|
code_status = 'in sync'
|
|
1110
1182
|
elif is_rollback:
|
|
@@ -1131,6 +1203,17 @@ def _update_logic(ctx, *, box, yes, version, verbose, check, force=False):
|
|
|
1131
1203
|
if force:
|
|
1132
1204
|
container_status = 'will restart (forced clean rebuild)'
|
|
1133
1205
|
est = '~6 min (fresh build)'
|
|
1206
|
+
elif container_down:
|
|
1207
|
+
# Code may be fully in sync, but there is nothing serving it — a
|
|
1208
|
+
# previous update likely failed after removing the containers.
|
|
1209
|
+
container_status = 'NOT RUNNING (will rebuild and restart)'
|
|
1210
|
+
est = '~6 min (fresh build possible)' if deps_will_change else '~90s (cached build)'
|
|
1211
|
+
elif deploy_stale:
|
|
1212
|
+
# In sync and running, but the container was deployed from an
|
|
1213
|
+
# older version — a prior update pulled and stopped before the
|
|
1214
|
+
# rebuild.
|
|
1215
|
+
container_status = 'running a STALE build (will rebuild and restart)'
|
|
1216
|
+
est = '~90s (cached build)'
|
|
1134
1217
|
elif commits_behind == 0 and commits_ahead == 0 and not deps_will_change:
|
|
1135
1218
|
container_status = 'no restart needed'
|
|
1136
1219
|
est = '~5s'
|
|
@@ -1153,7 +1236,10 @@ def _update_logic(ctx, *, box, yes, version, verbose, check, force=False):
|
|
|
1153
1236
|
click.echo(f' Estimated: {est}')
|
|
1154
1237
|
click.echo()
|
|
1155
1238
|
|
|
1156
|
-
will_change =
|
|
1239
|
+
will_change = (
|
|
1240
|
+
force or commits_behind != 0 or commits_ahead != 0
|
|
1241
|
+
or deps_will_change or container_down or deploy_stale
|
|
1242
|
+
)
|
|
1157
1243
|
if will_change:
|
|
1158
1244
|
click.echo('Run without --check to apply.')
|
|
1159
1245
|
ctx.exit(1)
|
|
@@ -1256,10 +1342,7 @@ def _update_logic(ctx, *, box, yes, version, verbose, check, force=False):
|
|
|
1256
1342
|
new_build_hash = _read_build_hash(run_ssh_command_with_output)
|
|
1257
1343
|
else:
|
|
1258
1344
|
new_build_hash = facts.get('BUILD_HASH_NEW', '')
|
|
1259
|
-
hash_mismatch = (
|
|
1260
|
-
bool(new_build_hash) and bool(stored_build_hash)
|
|
1261
|
-
and new_build_hash != stored_build_hash
|
|
1262
|
-
)
|
|
1345
|
+
hash_mismatch = _build_hash_mismatch(new_build_hash, stored_build_hash)
|
|
1263
1346
|
# `--force` requests a clean rebuild: wipe the cached image and the
|
|
1264
1347
|
# cargo/npm volumes so a prior failed/partial run can't leave a stale layer
|
|
1265
1348
|
# or half-installed toolchain behind on the retry.
|
|
@@ -1573,17 +1656,24 @@ def _update_logic(ctx, *, box, yes, version, verbose, check, force=False):
|
|
|
1573
1656
|
# but code is in sync); previously this branch ignored the hash and the
|
|
1574
1657
|
# rebuild silently never happened.
|
|
1575
1658
|
#
|
|
1576
|
-
#
|
|
1577
|
-
# failed
|
|
1578
|
-
#
|
|
1579
|
-
#
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1659
|
+
# Source state alone is not enough to declare success: an update that
|
|
1660
|
+
# failed after Step 8 (containers stopped and REMOVED) leaves a box that
|
|
1661
|
+
# reads as "in sync" here — git pulled fine, the stored hash predates the
|
|
1662
|
+
# failure — but has nothing running at all. Early-exiting then reports
|
|
1663
|
+
# success on a dead box, so the verdict also requires the lager container
|
|
1664
|
+
# to be running: 'container-down' falls through to the rebuild path below
|
|
1665
|
+
# and brings the box back up. `--force` still skips the early-exit
|
|
1666
|
+
# unconditionally.
|
|
1667
|
+
_gate = _rebuild_gate_verdict(
|
|
1668
|
+
facts,
|
|
1669
|
+
git_sync_confirmed=git_sync_confirmed,
|
|
1670
|
+
needs_pull=needs_pull,
|
|
1671
|
+
needs_flatten=needs_flatten,
|
|
1672
|
+
hash_mismatch=hash_mismatch,
|
|
1673
|
+
force=force,
|
|
1674
|
+
)
|
|
1675
|
+
_box_v = '' # assigned for real below whenever _gate stays 'skip'
|
|
1676
|
+
if _gate == 'skip':
|
|
1587
1677
|
import re as _re
|
|
1588
1678
|
|
|
1589
1679
|
# Prefer the box's source-declared `__version__` over the CLI
|
|
@@ -1594,10 +1684,26 @@ def _update_logic(ctx, *, box, yes, version, verbose, check, force=False):
|
|
|
1594
1684
|
_vp = _re.match(r'^v?(\d+\.\d+\.\d+)$', target_version)
|
|
1595
1685
|
if _vp:
|
|
1596
1686
|
_box_v = _vp.group(1)
|
|
1687
|
+
_tree_v = _box_v
|
|
1597
1688
|
else:
|
|
1598
1689
|
_src_v = _read_box_source_version(run_ssh_command_with_output)
|
|
1599
1690
|
_box_v = _src_v if _src_v else cli_version
|
|
1600
|
-
|
|
1691
|
+
# For the staleness check, only trust an actually-read source
|
|
1692
|
+
# version — the cli_version fallback is a display default, and
|
|
1693
|
+
# comparing it against the box would manufacture mismatches.
|
|
1694
|
+
_tree_v = _src_v
|
|
1695
|
+
|
|
1696
|
+
# Liveness alone can't tell whether the RUNNING container was built
|
|
1697
|
+
# from the code now in the tree: an update that pulled and then
|
|
1698
|
+
# exited before the container stop (BuildKit preflight failure, an
|
|
1699
|
+
# interrupt in the pull->stop window) leaves the old build serving
|
|
1700
|
+
# while git reads in sync. The deployed-version record catches that;
|
|
1701
|
+
# fall through and rebuild instead of stamping the new version onto
|
|
1702
|
+
# a box still running the old one.
|
|
1703
|
+
if _deployed_version_stale(_tree_v, facts.get('ETC_VERSION', '')):
|
|
1704
|
+
_gate = 'stale-deploy'
|
|
1705
|
+
|
|
1706
|
+
if _gate == 'skip':
|
|
1601
1707
|
# Reconcile /etc/lager/version on the box with the local cache.
|
|
1602
1708
|
# Previously this branch only updated the local ~/.lager file, so if
|
|
1603
1709
|
# the box's /etc/lager/version was stale (e.g. an earlier update
|
|
@@ -1624,6 +1730,25 @@ def _update_logic(ctx, *, box, yes, version, verbose, check, force=False):
|
|
|
1624
1730
|
click.echo()
|
|
1625
1731
|
ctx.exit(0)
|
|
1626
1732
|
|
|
1733
|
+
if _gate in ('container-down', 'stale-deploy'):
|
|
1734
|
+
if _gate == 'container-down':
|
|
1735
|
+
_fall_msg = (
|
|
1736
|
+
'Code is in sync but the lager container is not running '
|
|
1737
|
+
'(a previous update may have failed mid-rebuild) — rebuilding '
|
|
1738
|
+
'and restarting.'
|
|
1739
|
+
)
|
|
1740
|
+
else:
|
|
1741
|
+
_fall_msg = (
|
|
1742
|
+
'Code is in sync but the running container was deployed from '
|
|
1743
|
+
'a previous version (a prior update may have stopped before '
|
|
1744
|
+
'the rebuild) — rebuilding and restarting.'
|
|
1745
|
+
)
|
|
1746
|
+
if progress:
|
|
1747
|
+
progress.pause()
|
|
1748
|
+
click.echo(_fall_msg)
|
|
1749
|
+
if progress:
|
|
1750
|
+
progress.resume()
|
|
1751
|
+
|
|
1627
1752
|
# BuildKit preflight — run BEFORE the lock and the container stop below so a
|
|
1628
1753
|
# box whose Docker can't build the image fails fast WITHOUT being taken
|
|
1629
1754
|
# offline. box.Dockerfile uses a `# syntax=` directive and `RUN
|
|
@@ -1813,12 +1938,71 @@ def _update_logic(ctx, *, box, yes, version, verbose, check, force=False):
|
|
|
1813
1938
|
"`sudo apt-get install -y docker-buildx`), then re-run `lager update`.",
|
|
1814
1939
|
fg='yellow', err=True,
|
|
1815
1940
|
)
|
|
1941
|
+
elif "failed to prepare extraction snapshot" in full_output or (
|
|
1942
|
+
"parent snapshot" in full_output and "does not exist" in full_output
|
|
1943
|
+
):
|
|
1944
|
+
click.secho(
|
|
1945
|
+
"Hint: the box's Docker build cache is corrupted (a cached snapshot "
|
|
1946
|
+
"references a parent that no longer exists). Clear it with: "
|
|
1947
|
+
f"ssh {ssh_host} 'docker builder prune -af' and re-run `lager update`. "
|
|
1948
|
+
"The next build runs cold and can take 10-15 minutes.",
|
|
1949
|
+
fg='yellow', err=True,
|
|
1950
|
+
)
|
|
1816
1951
|
elif "No space left on device" in full_output:
|
|
1817
1952
|
click.secho("Hint: Disk space is full on the box. Run: ssh lagerdata@[BOX_NAME] 'docker system prune -af'", fg='yellow', err=True)
|
|
1818
1953
|
elif "network" in full_output.lower() and ("timeout" in full_output.lower() or "error" in full_output.lower()):
|
|
1819
1954
|
click.secho("Hint: Network issue during build. Check box internet connectivity.", fg='yellow', err=True)
|
|
1820
1955
|
elif "permission denied" in full_output.lower():
|
|
1821
1956
|
click.secho("Hint: Permission issue. Check Docker daemon is running and user has access.", fg='yellow', err=True)
|
|
1957
|
+
|
|
1958
|
+
# Poison the stored build-inputs hash so the next run can't read this
|
|
1959
|
+
# box as up to date: the sentinel never equals a recomputed sha256, so
|
|
1960
|
+
# hash_mismatch fires on the retry, blocking the "already at version"
|
|
1961
|
+
# early-exit and forcing a clean image wipe + rebuild. Deleting the
|
|
1962
|
+
# file would NOT do this — _build_hash_mismatch requires both values
|
|
1963
|
+
# non-empty. Best-effort: if the write fails, the liveness gate still
|
|
1964
|
+
# catches the dead-container case.
|
|
1965
|
+
try:
|
|
1966
|
+
store_build_hash('FAILED')
|
|
1967
|
+
except (subprocess.SubprocessError, OSError):
|
|
1968
|
+
pass
|
|
1969
|
+
|
|
1970
|
+
# Step 8 already stopped and removed the containers, so exiting here
|
|
1971
|
+
# would strand the box with no services — the state that previously
|
|
1972
|
+
# made the next run report "already at version" on a dead box. Unless
|
|
1973
|
+
# this run wiped the image (hash change / --force), the previous image
|
|
1974
|
+
# is still tagged `lager` and its baked-in code matches what was
|
|
1975
|
+
# running before the pull, so restart it: the box stays usable on its
|
|
1976
|
+
# prior version while the operator deals with the build failure.
|
|
1977
|
+
restarted = False
|
|
1978
|
+
if not must_wipe_image:
|
|
1979
|
+
click.echo()
|
|
1980
|
+
click.secho('Restarting the box on its previous version...', fg='yellow', err=True)
|
|
1981
|
+
try:
|
|
1982
|
+
recover = run_ssh_command_with_output(
|
|
1983
|
+
'cd ~/box && chmod +x start_box.sh && LAGER_SKIP_BUILD=1 ./start_box.sh',
|
|
1984
|
+
timeout_secs=600,
|
|
1985
|
+
)
|
|
1986
|
+
# Exit 3 = container up but post-start installs failed; the
|
|
1987
|
+
# box is serving, which is all this recovery promises.
|
|
1988
|
+
restarted = recover.returncode in (0, 3)
|
|
1989
|
+
except (subprocess.SubprocessError, OSError):
|
|
1990
|
+
restarted = False
|
|
1991
|
+
if restarted:
|
|
1992
|
+
restarted = wait_for_box_ready(resolved_box, timeout_s=60)
|
|
1993
|
+
if restarted:
|
|
1994
|
+
click.secho(
|
|
1995
|
+
'The update FAILED and was not applied. The box has been '
|
|
1996
|
+
'restarted on its previous version.',
|
|
1997
|
+
fg='yellow', err=True,
|
|
1998
|
+
)
|
|
1999
|
+
else:
|
|
2000
|
+
click.secho(
|
|
2001
|
+
'The update FAILED and the box was left with its services '
|
|
2002
|
+
'stopped. Bring it back up manually with:',
|
|
2003
|
+
fg='red', err=True,
|
|
2004
|
+
)
|
|
2005
|
+
click.echo(f' ssh {ssh_host} "cd ~/box && ./start_box.sh"', err=True)
|
|
1822
2006
|
ctx.exit(1)
|
|
1823
2007
|
if verbose:
|
|
1824
2008
|
click.secho(' Build complete', fg='green')
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Copyright 2026 Lager Data
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Tests for the update flow's rebuild gate: probe parsing, the build-hash
|
|
6
|
+
mismatch predicate, and the early-exit verdict (including container liveness).
|
|
7
|
+
"""
|
|
8
|
+
import os
|
|
9
|
+
import stat
|
|
10
|
+
import subprocess
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from cli.commands.utility.update import (
|
|
15
|
+
_build_hash_mismatch,
|
|
16
|
+
_deployed_version_stale,
|
|
17
|
+
_parse_probe_output,
|
|
18
|
+
_probe_shell_script,
|
|
19
|
+
_rebuild_gate_verdict,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
IN_SYNC = dict(
|
|
23
|
+
git_sync_confirmed=True,
|
|
24
|
+
needs_pull=False,
|
|
25
|
+
needs_flatten=False,
|
|
26
|
+
hash_mismatch=False,
|
|
27
|
+
force=False,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
SHA_A = 'a' * 64
|
|
31
|
+
SHA_B = 'b' * 64
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class TestParseProbeOutput:
|
|
35
|
+
@pytest.mark.parametrize('raw', ['1', '0', ''])
|
|
36
|
+
def test_lager_running_values_pass_through(self, raw):
|
|
37
|
+
facts = _parse_probe_output(f'LAGER_PROBE_LAGER_RUNNING={raw}\n')
|
|
38
|
+
assert facts['LAGER_RUNNING'] == raw
|
|
39
|
+
|
|
40
|
+
def test_absent_key_stays_absent(self):
|
|
41
|
+
facts = _parse_probe_output('LAGER_PROBE_ETC_VERSION=1.2.3\n')
|
|
42
|
+
assert 'LAGER_RUNNING' not in facts
|
|
43
|
+
|
|
44
|
+
def test_noise_lines_ignored(self):
|
|
45
|
+
stdout = 'Welcome to the box\nLAGER_PROBE_LAGER_RUNNING=1\nsudo lecture\n'
|
|
46
|
+
assert _parse_probe_output(stdout) == {'LAGER_RUNNING': '1'}
|
|
47
|
+
|
|
48
|
+
def test_probe_script_emits_liveness_fact(self):
|
|
49
|
+
assert 'LAGER_PROBE_LAGER_RUNNING=' in _probe_shell_script()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class TestBuildHashMismatch:
|
|
53
|
+
def test_changed_inputs_mismatch(self):
|
|
54
|
+
assert _build_hash_mismatch(SHA_A, SHA_B)
|
|
55
|
+
|
|
56
|
+
def test_matching_inputs_no_mismatch(self):
|
|
57
|
+
assert not _build_hash_mismatch(SHA_A, SHA_A)
|
|
58
|
+
|
|
59
|
+
def test_failed_sentinel_forces_mismatch(self):
|
|
60
|
+
# A failed build stores 'FAILED'; any real recomputed sha must mismatch
|
|
61
|
+
# so the retry rebuilds instead of early-exiting.
|
|
62
|
+
assert _build_hash_mismatch(SHA_A, 'FAILED')
|
|
63
|
+
|
|
64
|
+
def test_absent_stored_hash_skips_auto_invalidation(self):
|
|
65
|
+
assert not _build_hash_mismatch(SHA_A, '')
|
|
66
|
+
|
|
67
|
+
def test_unmeasurable_new_hash_skips_auto_invalidation(self):
|
|
68
|
+
assert not _build_hash_mismatch('', SHA_A)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class TestRebuildGateVerdict:
|
|
72
|
+
def test_in_sync_and_running_skips(self):
|
|
73
|
+
assert _rebuild_gate_verdict({'LAGER_RUNNING': '1'}, **IN_SYNC) == 'skip'
|
|
74
|
+
|
|
75
|
+
def test_container_down_blocks_skip(self):
|
|
76
|
+
# The reported failure: a prior update removed the containers and died
|
|
77
|
+
# mid-build; source reads as in-sync but nothing is running.
|
|
78
|
+
assert _rebuild_gate_verdict({'LAGER_RUNNING': '0'}, **IN_SYNC) == 'container-down'
|
|
79
|
+
|
|
80
|
+
@pytest.mark.parametrize('facts', [{}, {'LAGER_RUNNING': ''}])
|
|
81
|
+
def test_unknown_liveness_fails_open(self, facts):
|
|
82
|
+
assert _rebuild_gate_verdict(facts, **IN_SYNC) == 'skip'
|
|
83
|
+
|
|
84
|
+
@pytest.mark.parametrize('override', [
|
|
85
|
+
dict(git_sync_confirmed=False),
|
|
86
|
+
dict(needs_pull=True),
|
|
87
|
+
dict(needs_flatten=True),
|
|
88
|
+
dict(hash_mismatch=True),
|
|
89
|
+
dict(force=True),
|
|
90
|
+
])
|
|
91
|
+
def test_source_divergence_rebuilds_regardless_of_liveness(self, override):
|
|
92
|
+
args = {**IN_SYNC, **override}
|
|
93
|
+
for facts in ({'LAGER_RUNNING': '1'}, {'LAGER_RUNNING': '0'}, {}):
|
|
94
|
+
assert _rebuild_gate_verdict(facts, **args) == 'rebuild'
|
|
95
|
+
|
|
96
|
+
def test_failed_sentinel_feeds_through_to_rebuild(self):
|
|
97
|
+
mismatch = _build_hash_mismatch(SHA_A, 'FAILED')
|
|
98
|
+
args = {**IN_SYNC, 'hash_mismatch': mismatch}
|
|
99
|
+
assert _rebuild_gate_verdict({'LAGER_RUNNING': '1'}, **args) == 'rebuild'
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class TestDeployedVersionStale:
|
|
103
|
+
def test_matching_versions_not_stale(self):
|
|
104
|
+
assert not _deployed_version_stale('0.32.1', '0.32.1|0.32.1')
|
|
105
|
+
|
|
106
|
+
def test_tree_ahead_of_deploy_is_stale(self):
|
|
107
|
+
# The tree-ahead-of-deploy state: a prior update pulled the new code
|
|
108
|
+
# but exited before the rebuild, so the container still serves the
|
|
109
|
+
# version last recorded by a successful update.
|
|
110
|
+
assert _deployed_version_stale('0.32.1', '0.32.0|0.32.1')
|
|
111
|
+
|
|
112
|
+
def test_legacy_value_without_cli_part(self):
|
|
113
|
+
assert not _deployed_version_stale('0.31.0', '0.31.0')
|
|
114
|
+
assert _deployed_version_stale('0.32.0', '0.31.0')
|
|
115
|
+
|
|
116
|
+
@pytest.mark.parametrize('etc_raw', ['', None, ' ', '|0.32.1'])
|
|
117
|
+
def test_unknown_deployed_fails_open(self, etc_raw):
|
|
118
|
+
assert not _deployed_version_stale('0.32.1', etc_raw)
|
|
119
|
+
|
|
120
|
+
def test_unknown_tree_version_fails_open(self):
|
|
121
|
+
assert not _deployed_version_stale('', '0.32.0|0.32.0')
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class TestProbeLivenessSnippet:
|
|
125
|
+
"""Run the real probe script against a stubbed `docker` to pin the
|
|
126
|
+
liveness fact's tri-state contract at the shell level.
|
|
127
|
+
|
|
128
|
+
The script is designed to exit 0 and emit a value (possibly empty) for
|
|
129
|
+
every fact regardless of what is installed on the host, so executing it
|
|
130
|
+
verbatim also guards against a syntax error sneaking into the heredoc.
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
def _probe_facts(self, tmp_path, docker_body):
|
|
134
|
+
shim_dir = tmp_path / 'bin'
|
|
135
|
+
shim_dir.mkdir()
|
|
136
|
+
shim = shim_dir / 'docker'
|
|
137
|
+
shim.write_text(f'#!/bin/sh\n{docker_body}\n')
|
|
138
|
+
shim.chmod(shim.stat().st_mode | stat.S_IXUSR)
|
|
139
|
+
env = dict(os.environ, PATH=f'{shim_dir}:{os.environ["PATH"]}')
|
|
140
|
+
result = subprocess.run(
|
|
141
|
+
['sh'], input=_probe_shell_script(), text=True,
|
|
142
|
+
capture_output=True, env=env, timeout=30,
|
|
143
|
+
)
|
|
144
|
+
assert result.returncode == 0, result.stderr
|
|
145
|
+
return _parse_probe_output(result.stdout)
|
|
146
|
+
|
|
147
|
+
def test_running_container_reports_1(self, tmp_path):
|
|
148
|
+
facts = self._probe_facts(tmp_path, 'printf "lager\\nstout\\n"')
|
|
149
|
+
assert facts['LAGER_RUNNING'] == '1'
|
|
150
|
+
|
|
151
|
+
def test_substring_named_container_does_not_count(self, tmp_path):
|
|
152
|
+
# `docker ps --filter name=lager` matches substrings, so a container
|
|
153
|
+
# named e.g. `lagertest` comes back from the filter; only an exact
|
|
154
|
+
# `lager` row may count as the box container.
|
|
155
|
+
facts = self._probe_facts(tmp_path, 'printf "lagertest\\n"')
|
|
156
|
+
assert facts['LAGER_RUNNING'] == '0'
|
|
157
|
+
|
|
158
|
+
def test_no_rows_reports_0(self, tmp_path):
|
|
159
|
+
facts = self._probe_facts(tmp_path, ':')
|
|
160
|
+
assert facts['LAGER_RUNNING'] == '0'
|
|
161
|
+
|
|
162
|
+
def test_docker_failure_reports_unknown(self, tmp_path):
|
|
163
|
+
facts = self._probe_facts(tmp_path, 'exit 1')
|
|
164
|
+
assert facts['LAGER_RUNNING'] == ''
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|