mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Merge pull request #1908 from GNS3/busybox-docker
Use a stock BusyBox for the Docker Integration
This commit is contained in:
commit
9ac6bd1e59
@ -574,14 +574,9 @@ class DockerVM(BaseNode):
|
|||||||
# https://github.com/GNS3/gns3-gui/issues/1039
|
# https://github.com/GNS3/gns3-gui/issues/1039
|
||||||
try:
|
try:
|
||||||
process = await asyncio.subprocess.create_subprocess_exec(
|
process = await asyncio.subprocess.create_subprocess_exec(
|
||||||
"docker",
|
|
||||||
"exec",
|
|
||||||
"-i",
|
|
||||||
self._cid,
|
|
||||||
"/gns3/bin/busybox",
|
|
||||||
"script",
|
"script",
|
||||||
"-qfc",
|
"-qfc",
|
||||||
"while true; do TERM=vt100 /gns3/bin/busybox sh; done",
|
f"docker exec -i -t {self._cid} /gns3/bin/busybox sh -c 'while true; do TERM=vt100 /gns3/bin/busybox sh; done'",
|
||||||
"/dev/null",
|
"/dev/null",
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.STDOUT,
|
stderr=asyncio.subprocess.STDOUT,
|
||||||
|
Binary file not shown.
15
gns3server/compute/docker/resources/bin/udhcpc
Normal file
15
gns3server/compute/docker/resources/bin/udhcpc
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/gns3/bin/busybox sh
|
||||||
|
|
||||||
|
SCRIPT="/gns3/etc/udhcpc/default.script"
|
||||||
|
|
||||||
|
if [ "$(cat "/proc/$PPID/comm" 2>/dev/null)" = ifup ]; then
|
||||||
|
# remove "-n" argument
|
||||||
|
for arg do
|
||||||
|
shift
|
||||||
|
[ "$arg" = "-n" ] || set -- "$@" "$arg"
|
||||||
|
done
|
||||||
|
# add default parameters
|
||||||
|
set -- -t 3 -T 2 -A 1 -b "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec /tmp/gns3/bin/udhcpc -s "$SCRIPT" "$@"
|
26
setup.py
26
setup.py
@ -16,6 +16,10 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
from setuptools.command.test import test as TestCommand
|
from setuptools.command.test import test as TestCommand
|
||||||
|
|
||||||
@ -39,6 +43,28 @@ class PyTest(TestCommand):
|
|||||||
sys.exit(errcode)
|
sys.exit(errcode)
|
||||||
|
|
||||||
|
|
||||||
|
BUSYBOX_PATH = "gns3server/compute/docker/resources/bin/busybox"
|
||||||
|
|
||||||
|
|
||||||
|
def copy_busybox():
|
||||||
|
if not sys.platform.startswith("linux"):
|
||||||
|
return
|
||||||
|
if os.path.isfile(BUSYBOX_PATH):
|
||||||
|
return
|
||||||
|
for bb_cmd in ("busybox-static", "busybox.static", "busybox"):
|
||||||
|
bb_path = shutil.which(bb_cmd)
|
||||||
|
if bb_path:
|
||||||
|
if subprocess.call(["ldd", bb_path],
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL):
|
||||||
|
shutil.copy2(bb_path, BUSYBOX_PATH, follow_symlinks=True)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise SystemExit("No static busybox found")
|
||||||
|
|
||||||
|
|
||||||
|
copy_busybox()
|
||||||
dependencies = open("requirements.txt", "r").read().splitlines()
|
dependencies = open("requirements.txt", "r").read().splitlines()
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
|
@ -1449,7 +1449,15 @@ async def test_start_aux(vm):
|
|||||||
|
|
||||||
with asyncio_patch("asyncio.subprocess.create_subprocess_exec", return_value=MagicMock()) as mock_exec:
|
with asyncio_patch("asyncio.subprocess.create_subprocess_exec", return_value=MagicMock()) as mock_exec:
|
||||||
await vm._start_aux()
|
await vm._start_aux()
|
||||||
mock_exec.assert_called_with('docker', 'exec', '-i', 'e90e34656842', '/gns3/bin/busybox', 'script', '-qfc', 'while true; do TERM=vt100 /gns3/bin/busybox sh; done', '/dev/null', stderr=asyncio.subprocess.STDOUT, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE)
|
mock_exec.assert_called_with(
|
||||||
|
"script",
|
||||||
|
"-qfc",
|
||||||
|
"docker exec -i -t e90e34656842 /gns3/bin/busybox sh -c 'while true; do TERM=vt100 /gns3/bin/busybox sh; done'",
|
||||||
|
"/dev/null",
|
||||||
|
stderr=asyncio.subprocess.STDOUT,
|
||||||
|
stdin=asyncio.subprocess.PIPE,
|
||||||
|
stdout=asyncio.subprocess.PIPE
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
Loading…
Reference in New Issue
Block a user