Make sandbox container nodes usable for other projects (#4767)

This commit is contained in:
Andrew Jeffery 2022-12-16 22:04:49 +00:00 коммит произвёл GitHub
Родитель 6c8e0e49c6
Коммит 68881c5e7e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 17 добавлений и 10 удалений

Просмотреть файл

@ -284,6 +284,7 @@ install(
)
install(PROGRAMS tests/sandbox/sandbox.sh DESTINATION bin)
install(PROGRAMS tests/docker_wrap.sh DESTINATION bin)
install(FILES samples/constitutions/default/actions.js DESTINATION bin)
install(FILES samples/constitutions/default/validate.js DESTINATION bin)
install(FILES samples/constitutions/sandbox/resolve.js DESTINATION bin)

Просмотреть файл

@ -359,7 +359,7 @@ class SSHRemote(CmdMixin):
self.proc_client.close()
return errors, fatal_errors
def setup(self):
def setup(self, **kwargs):
"""
Connect to the remote host, empty the temporary directory if it exsits,
and populate it with the initial set of files.
@ -414,6 +414,7 @@ class LocalRemote(CmdMixin):
common_dir,
env=None,
pid_file=None,
binary_dir=".",
):
"""
Local Equivalent to the SSHRemote
@ -443,13 +444,16 @@ class LocalRemote(CmdMixin):
else:
assert self._rc("cp {} {}".format(src_path, dst_path)) == 0
def _setup_files(self):
def _setup_files(self, use_links: bool):
assert self._rc("rm -rf {}".format(self.root)) == 0
assert self._rc("mkdir -p {}".format(self.root)) == 0
for path in self.exe_files:
dst_path = os.path.normpath(os.path.join(self.root, os.path.basename(path)))
src_path = os.path.normpath(os.path.join(os.getcwd(), path))
assert self._rc("ln -s {} {}".format(src_path, dst_path)) == 0
if use_links:
assert self._rc("ln -s {} {}".format(src_path, dst_path)) == 0
else:
assert self._rc("cp {} {}".format(src_path, dst_path)) == 0
for path in self.data_files:
if len(path) > 0:
dst_path = os.path.join(self.root, os.path.basename(path))
@ -529,12 +533,12 @@ class LocalRemote(CmdMixin):
self.stderr.close()
return self.get_logs(ignore_error_patterns=ignore_error_patterns)
def setup(self):
def setup(self, use_links=True):
"""
Empty the temporary directory if it exists,
and populate it with the initial set of files.
"""
self._setup_files()
self._setup_files(use_links)
def get_cmd(self, include_dir=True):
cmd = f"cd {self.root} && " if include_dir else ""
@ -973,10 +977,11 @@ class CCFRemote(object):
common_dir,
env,
pid_file=node_pid_file,
binary_dir=binary_dir,
)
def setup(self):
self.remote.setup()
def setup(self, **kwargs):
self.remote.setup(**kwargs)
def start(self):
self.remote.start()

Просмотреть файл

@ -76,6 +76,7 @@ class DockerShim(infra.remote.CCFRemote):
label = kwargs.get("label")
local_node_id = kwargs.get("local_node_id")
ccf_version = kwargs.get("version")
self.binary_dir = kwargs.get("binary_dir")
# Sanitise container name, replacing illegal characters with underscores
self.container_name = f"{label}_{local_node_id}"
@ -177,9 +178,9 @@ class DockerShim(infra.remote.CCFRemote):
self.network.connect(self.container)
LOG.debug(f"Created container {self.container_name} [{image_name}]")
def setup(self):
src_path = os.path.join(".", NODE_STARTUP_WRAPPER_SCRIPT)
self.remote.setup()
def setup(self, **kwargs):
src_path = os.path.join(self.binary_dir, NODE_STARTUP_WRAPPER_SCRIPT)
self.remote.setup(use_links=False)
self.remote.cp(src_path, self.remote.root)
def start(self):