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

NAS-131370 / 25.04 / Fix post mount actions execution on system dataset setup #14567

Merged
merged 1 commit into from
Sep 27, 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
22 changes: 13 additions & 9 deletions src/middlewared/middlewared/plugins/reporting/netdata_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess

from middlewared.service import private, Service
from middlewared.utils.filesystem.copy import copytree, CopyTreeConfig

from .utils import get_netdata_state_path

Expand All @@ -24,17 +25,20 @@ def netdata_state_location(self):

@private
def post_dataset_mount_action(self):
if os.path.exists(get_netdata_state_path()):
netdata_state_path = get_netdata_state_path()
# We want to make sure this path exists always regardless of an error so that
# at least netdata can start itself gracefully
try:
os.makedirs(netdata_state_path, exist_ok=False)
except FileExistsError:
return

cp = subprocess.run(
['cp', '-a', '/var/lib/netdata', get_netdata_state_path()], check=False, capture_output=True,
)
if cp.returncode != 0:
self.logger.error('Failed to copy netdata state over from /var/lib/netdata: %r', cp.stderr.decode())
# We want to make sure this path exists always regardless of an error so that
# at least netdata can start itself gracefully
os.makedirs(get_netdata_state_path(), exist_ok=True)
try:
copytree('/var/lib/netdata', netdata_state_path, config=CopyTreeConfig())
except Exception:
self.logger.error('Failed to copy netdata state over from /var/lib/netdata', exc_info=True)
os.chown(netdata_state_path, uid=999, gid=997)
os.chmod(netdata_state_path, mode=0o755)

@private
async def start_service(self):
Expand Down
3 changes: 2 additions & 1 deletion src/middlewared/middlewared/plugins/sysdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ def __mount(self, pool, uuid, path=SYSDATASET_PATH):
os.chmod(mountpoint, mode_perms)

mounted = True
self.__post_mount_actions(ds_config['name'], ds_config.get('post_mount_actions', []))
if path == SYSDATASET_PATH:
self.__post_mount_actions(ds_config['name'], ds_config.get('post_mount_actions', []))

if mounted and path == SYSDATASET_PATH:
fsid = os.statvfs(SYSDATASET_PATH).f_fsid
Expand Down
8 changes: 8 additions & 0 deletions tests/api2/test_system_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,11 @@ def test_system_dataset_mountpoints():
assert ds_stats["uid"] == system_dataset_spec["chown_config"]["uid"]
assert ds_stats["gid"] == system_dataset_spec["chown_config"]["gid"]
assert ds_stats["mode"] & 0o777 == system_dataset_spec["chown_config"]["mode"]


def test_netdata_post_mount_action():
# We rely on this to make sure system dataset post mount actions are working as intended
Qubad786 marked this conversation as resolved.
Show resolved Hide resolved
ds_stats = call("filesystem.stat", "/var/db/system/netdata/ix_state")
assert ds_stats["uid"] == 999, ds_stats
assert ds_stats["gid"] == 997, ds_stats
assert ds_stats["mode"] & 0o777 == 0o755, ds_stats
Loading