Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make install_files invoked automatically for Driver object startup #1099

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/newsfragments/2878_changed.driver_install_files.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Users can now use :py:meth:`install_files <testplan.testing.multitest.driver.base.Driver.install_files>` method with Driver objects to copy files over to a specified location during environment startup.
25 changes: 9 additions & 16 deletions testplan/testing/multitest/driver/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,6 @@ def hostname(self) -> str:
"""
return socket.gethostname()

def pre_start(self) -> None:
"""
Create mandatory directories and install files from given templates
using the drivers context before starting the application binary.
"""
super(App, self).pre_start()

self._make_dirs()
makedirs(self.app_path)
self.std = StdFiles(self.app_path)

if self.cfg.install_files:
self.install_files()

def starting(self) -> None:
"""Starts the application binary."""
super(App, self).starting()
Expand Down Expand Up @@ -411,13 +397,20 @@ def stopping(self) -> None:
)
raise RuntimeError(err_msg)

def _make_dirs(self) -> None:
def make_runpath_dirs(self) -> None:
"""
Create mandatory directories and install files from given templates
using the drivers context before starting the application binary.
"""
super(App, self).make_runpath_dirs()

bin_dir = os.path.join(self.runpath, "bin")
etc_dir = os.path.join(self.runpath, "etc")
for directory in (bin_dir, etc_dir):
for directory in (bin_dir, etc_dir, self.app_path):
makedirs(directory)
self._binpath = bin_dir
self._etcpath = etc_dir
self.std = StdFiles(self.app_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Std files are not dirs, it might could go back to pre_start

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, but we have a circular dependency here, because we need self.std to be defined for install_files() to work properly and also cannot be executed before make_runpath_dirs() as it needs the directories being created here.
So another solution would be to rename make_runpath_dirs function to a better describing name, but does it worth the hassle?


def _install_target(self) -> str:
return self.etcpath
Expand Down
3 changes: 3 additions & 0 deletions testplan/testing/multitest/driver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def pre_start(self) -> None:
"""Steps to be executed right before resource starts."""
self.make_runpath_dirs()

if self.cfg.install_files:
self.install_files()

@property
def started_check_interval(self) -> PollInterval:
"""
Expand Down