Skip to content

Commit

Permalink
Merge branch '2.2' into bugfix/3555
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj authored Feb 26, 2024
2 parents 9a5af82 + 14a6187 commit 52638a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
12 changes: 6 additions & 6 deletions gns3server/controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ def install_resource_files(dst_path, resource_name):
else:
for entry in importlib_resources.files('gns3server').joinpath(resource_name).iterdir():
full_path = os.path.join(dst_path, entry.name)
if not os.path.exists(full_path):
if entry.is_file():
log.debug(f'Installing {resource_name} resource file "{entry.name}" to "{full_path}"')
shutil.copy(str(entry), os.path.join(dst_path, entry.name))
elif entry.is_dir():
os.makedirs(full_path, exist_ok=True)
if entry.is_file() and not os.path.exists(full_path):
log.debug(f'Installing {resource_name} resource file "{entry.name}" to "{full_path}"')
shutil.copy(str(entry), os.path.join(dst_path, entry.name))
elif entry.is_dir():
os.makedirs(full_path, exist_ok=True)
Controller.install_resource_files(full_path, os.path.join(resource_name, entry.name))

def _install_base_configs(self):
"""
Expand Down
27 changes: 26 additions & 1 deletion tests/compute/docker/test_docker_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ async def test_unpause(vm):
mock.assert_called_with("POST", "containers/e90e34656842/unpause")


async def test_start(vm, manager, free_console_port):
async def test_start(vm, manager, free_console_port, tmpdir):

assert vm.status != "started"
vm.adapters = 1
Expand Down Expand Up @@ -880,6 +880,31 @@ async def test_start(vm, manager, free_console_port):
assert vm.status == "started"


async def test_resources_installed(vm, manager, tmpdir):

assert vm.status != "started"
vm.adapters = 1

docker_resources_path = os.path.join(tmpdir, "docker", "resources")
os.makedirs(docker_resources_path, exist_ok=True)
manager.resources_path = MagicMock(return_value=docker_resources_path)

with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query"):
with asyncio_patch("gns3server.compute.docker.DockerVM._start_ubridge"):
with asyncio_patch("gns3server.compute.docker.DockerVM._get_namespace", return_value=42):
with asyncio_patch("gns3server.compute.docker.DockerVM._add_ubridge_connection"):
with asyncio_patch("gns3server.compute.docker.DockerVM._start_console"):
await vm.start()

assert vm.status == "started"
assert os.path.exists(os.path.join(docker_resources_path, "init.sh"))
assert os.path.exists(os.path.join(docker_resources_path, "run-cmd.sh"))
assert os.path.exists(os.path.join(docker_resources_path, "bin", "busybox"))
assert os.path.exists(os.path.join(docker_resources_path, "bin", "udhcpc"))
assert os.path.exists(os.path.join(docker_resources_path, "etc", "udhcpc", "default.script"))


async def test_start_namespace_failed(vm, manager, free_console_port):

assert vm.status != "started"
Expand Down

0 comments on commit 52638a9

Please sign in to comment.