-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DPE-5028] restart continuous writes (#236)
* Bump libs * Try to use stop event * Restart continuous writes on start hook * Integration test * Wrong on start check * Defer restart if db connection is not available yet * Typo
- Loading branch information
Showing
6 changed files
with
298 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
import logging | ||
import subprocess | ||
|
||
from pytest_operator.plugin import OpsTest | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
async def run_command_on_unit(ops_test: OpsTest, unit_name: str, command: str) -> str: | ||
"""Run a command on a specific unit. | ||
Args: | ||
ops_test: The ops test framework instance | ||
unit_name: The name of the unit to run the command on | ||
command: The command to run | ||
Returns: | ||
the command output if it succeeds, otherwise raises an exception. | ||
""" | ||
complete_command = ["exec", "--unit", unit_name, "--", *command.split()] | ||
return_code, stdout, _ = await ops_test.juju(*complete_command) | ||
if return_code != 0: | ||
logger.error(stdout) | ||
raise Exception( | ||
f"Expected command '{command}' to succeed instead it failed: {return_code}" | ||
) | ||
return stdout | ||
|
||
|
||
async def get_machine_from_unit(ops_test: OpsTest, unit_name: str) -> str: | ||
"""Get the name of the machine from a specific unit. | ||
Args: | ||
ops_test: The ops test framework instance | ||
unit_name: The name of the unit to get the machine | ||
Returns: | ||
The name of the machine. | ||
""" | ||
raw_hostname = await run_command_on_unit(ops_test, unit_name, "hostname") | ||
return raw_hostname.strip() | ||
|
||
|
||
async def restart_machine(ops_test: OpsTest, unit_name: str) -> None: | ||
"""Restart the machine where a unit run on. | ||
Args: | ||
ops_test: The ops test framework instance | ||
unit_name: The name of the unit to restart the machine | ||
""" | ||
raw_hostname = await get_machine_from_unit(ops_test, unit_name) | ||
restart_machine_command = f"lxc restart {raw_hostname}" | ||
subprocess.check_call(restart_machine_command.split()) |
Oops, something went wrong.