Verified Commit fb277725 authored by Karel Koci's avatar Karel Koci 🤘
Browse files

nsfarm/lxd/container: fix invalid name of container

The '-' is invalid so this replaces it with 'x'. For consistency this
also changes it in such a way that it is always appended so the hidden
issue like this won't happen again. It also makes the naming scheme
parent eee7b93c
......@@ -74,12 +74,13 @@ class Container:
logger.debug("Container prepared: %s",
def _container_name(self, prefix="nsfarm"):
# Warning: the other parts of this project rely on this naming convention to identify containers (such as
# cleanup algorithm). Make sure that you update them when you do changes in this code.
name = f"{prefix}-{}-{os.getpid()}"
if self._lxd.local.containers.exists(name):
i = 1
while self._lxd.local.containers.exists(f"{name}.{i}"):
i += 1
name = f"{name}.{i}"
i = 1
while self._lxd.local.containers.exists(f"{name}x{i}"):
i += 1
name = f"{name}x{i}"
return name
def cleanup(self):
......@@ -73,7 +73,7 @@ def clean_containers(dry_run=False):
# Container have PID of process they are spawned by in the name. We can't safely remove any container
# without running owner process.
pid = int('-')[-1].split('.')[0])
pid = int('-')[-1].split('x')[0])
os.kill(pid, 0)
except OSError as err:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment