mirror of
https://github.com/Cian-H/I-Form_Server_Node_Deployer.git
synced 2025-12-24 07:02:01 +00:00
Housekeeping and polish based on test discoveries
This commit is contained in:
@@ -76,7 +76,7 @@ def convert_json_via_fuelignition(
|
||||
image_file = container.exec_run("ls /home/seluser/Downloads/").output.decode().split()[0]
|
||||
# Finally, fetch the image file from the container
|
||||
client_image_path = f"/home/seluser/Downloads/{image_file}"
|
||||
host_image_path = config.SRC_DIR / img_path
|
||||
host_image_path = config.PROJECT_ROOT / img_path
|
||||
if host_image_path.exists():
|
||||
host_image_path.unlink()
|
||||
filestream = container.get_archive(client_image_path)[0]
|
||||
@@ -211,6 +211,8 @@ def json_to_img(
|
||||
config.CWD_MOUNT,
|
||||
],
|
||||
)
|
||||
while config.SELENIUM_INIT_MESSAGE not in selenium_container.logs().decode():
|
||||
time.sleep(0.1)
|
||||
fuelignition_image = build_fuelignition()
|
||||
fuelignition_container = config.CLIENT.containers.run(
|
||||
fuelignition_image,
|
||||
@@ -218,11 +220,7 @@ def json_to_img(
|
||||
remove=True,
|
||||
network_mode=f"container:{selenium_container.id}",
|
||||
)
|
||||
# Wait for the containers to finish starting up
|
||||
while config.SELENIUM_INIT_MESSAGE not in selenium_container.logs().decode():
|
||||
time.sleep(0.1)
|
||||
for event in config.CLIENT.events(decode=True):
|
||||
print(event)
|
||||
# Wait for the container to finish starting up
|
||||
while not fnmatch(
|
||||
fuelignition_container.logs().decode().strip().split("\n")[-1].strip(),
|
||||
config.FUELIGNITION_INIT_MESSAGE,
|
||||
|
||||
@@ -47,7 +47,10 @@ def validation_result() -> str:
|
||||
path=".",
|
||||
dockerfile=str(dockerfile),
|
||||
tag="validate",
|
||||
buildargs={"CWD_MOUNTDIR": str(config.CWD_MOUNTDIR)},
|
||||
buildargs={
|
||||
"CWD_MOUNTDIR": str(config.CWD_MOUNTDIR),
|
||||
"BUILD_DIR": str(config.BUILD_DIR.relative_to(config.PROJECT_ROOT)),
|
||||
},
|
||||
rm=config.CLEANUP_IMAGES,
|
||||
pull=True,
|
||||
quiet=True,
|
||||
@@ -57,7 +60,7 @@ def validation_result() -> str:
|
||||
mounts=[
|
||||
config.CWD_MOUNT,
|
||||
],
|
||||
remove=True,
|
||||
remove=config.CLEANUP_IMAGES,
|
||||
)
|
||||
if config.CLEANUP_IMAGES:
|
||||
image.remove(force=True)
|
||||
|
||||
@@ -31,7 +31,7 @@ def apply_ignition_settings(
|
||||
template: dict,
|
||||
hostname: str,
|
||||
password: str,
|
||||
swarm_config: str,
|
||||
swarm_config: dict,
|
||||
) -> dict:
|
||||
"""Applies the specified ignition settings to the given template
|
||||
|
||||
@@ -46,8 +46,8 @@ def apply_ignition_settings(
|
||||
"""
|
||||
ignition_config = template.copy()
|
||||
ignition_config["hostname"] = hostname
|
||||
ignition_config["login"]["users"][0]["passwd"] = password
|
||||
if password:
|
||||
ignition_config["login"]["users"][0]["passwd"] = password
|
||||
ignition_config["login"]["users"][0]["hash_type"] = "bcrypt"
|
||||
elif not config.TESTING:
|
||||
raise ValueError("Password must be specified")
|
||||
@@ -66,7 +66,7 @@ def apply_ignition_settings(
|
||||
"source_type": "data",
|
||||
"mode": 420,
|
||||
"overwrite": True,
|
||||
"data_content": swarm_config,
|
||||
"data_content": json.dumps(swarm_config),
|
||||
},
|
||||
{
|
||||
"path": "/root/join_swarm.sh",
|
||||
@@ -197,13 +197,11 @@ def create_img(
|
||||
password = ""
|
||||
|
||||
# get swarm configuration as JSON
|
||||
swarm_config = json.dumps(
|
||||
{
|
||||
"SWITCH_IP_ADDRESS": str(switch_ip),
|
||||
"SWITCH_PORT": switch_port,
|
||||
"SWARM_TOKEN": swarm_token,
|
||||
}
|
||||
)
|
||||
swarm_config = {
|
||||
"SWITCH_IP_ADDRESS": str(switch_ip),
|
||||
"SWITCH_PORT": switch_port,
|
||||
"SWARM_TOKEN": swarm_token,
|
||||
}
|
||||
|
||||
# Create ignition configuration
|
||||
ignition_config = apply_ignition_settings(
|
||||
|
||||
@@ -7,6 +7,11 @@ import typer
|
||||
from .config import config
|
||||
|
||||
|
||||
def get_debug_f(f: Callable) -> Callable:
|
||||
import snoop # type: ignore
|
||||
return wraps(f)(snoop.snoop(**config.snoop["snoop"])(f))
|
||||
|
||||
|
||||
def debug_guard(f: Callable) -> Callable:
|
||||
"""A decorator that contextually enables debug mode for the decorated function
|
||||
|
||||
@@ -35,9 +40,10 @@ def debug_guard(f: Callable) -> Callable:
|
||||
**kwargs,
|
||||
) -> Callable:
|
||||
typer.echo(f"Debug mode enabled: {inspect.stack()[1].filename}")
|
||||
debug_f = get_debug_f(f)
|
||||
if kwargs.get("debug", False):
|
||||
# Snoop depth is set to compensate for wrapper stack frames
|
||||
return snoop.snoop(**config.snoop["snoop"])(f)(*args, **kwargs) # noqa: F821 #* ss is installed in debug_mode
|
||||
return debug_f(*args, **kwargs) # noqa: F821 #* ss is installed in debug_mode
|
||||
else:
|
||||
return f(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from functools import wraps
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
import docker
|
||||
|
||||
from .config import config
|
||||
|
||||
@@ -51,14 +52,22 @@ def next_free_tcp_port(port: int) -> int:
|
||||
Returns:
|
||||
int: The next free port
|
||||
"""
|
||||
containers = config.CLIENT.containers.list(all=True)
|
||||
ports = []
|
||||
for container in containers:
|
||||
port_values = container.ports.values()
|
||||
if not port_values:
|
||||
continue
|
||||
for x in list(container.ports.values())[0]:
|
||||
ports.append(int(x["HostPort"]))
|
||||
try:
|
||||
containers = config.CLIENT.containers.list(all=True)
|
||||
ports = []
|
||||
for container in containers:
|
||||
port_values = container.ports.values()
|
||||
if not port_values:
|
||||
continue
|
||||
for x in list(container.ports.values())[0]:
|
||||
ports.append(int(x["HostPort"]))
|
||||
except docker.errors.NotFound: # type: ignore
|
||||
#* This error is raised if container list changes between getting the list and
|
||||
#* getting the ports. If this happens, just try again
|
||||
return next_free_tcp_port(port)
|
||||
if not ports:
|
||||
return port
|
||||
ports = set(ports)
|
||||
while port in ports:
|
||||
port += 1
|
||||
|
||||
Reference in New Issue
Block a user