Skip to content

Commit d391d30

Browse files
committed
NSOL-5941:mounting root volume automatically
1 parent 24ddb06 commit d391d30

1 file changed

Lines changed: 52 additions & 18 deletions

File tree

netapp_dataops_traditional/netapp_dataops/config/dataset_manager.py

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -308,36 +308,31 @@ def _create_root_volume_on_ontap(self, volume_name: str) -> bool:
308308
return False
309309

310310
def _is_mounted(self, mountpoint: str) -> bool:
311-
"""Check if a mountpoint is currently in use."""
311+
"""Check if a mountpoint is currently in use (cross-platform)."""
312312
try:
313-
# Check if mountpoint utility is available
314-
self._check_required_utilities('mountpoint')
315-
316-
result = subprocess.run(['mountpoint', '-q', mountpoint],
317-
capture_output=True, text=True)
318-
return result.returncode == 0
319-
except RuntimeError as e:
320-
# Re-raise utility check errors
321-
raise
313+
# Use mount command which is available on both Linux and macOS
314+
result = subprocess.run(['mount'], capture_output=True, text=True)
315+
if result.returncode == 0:
316+
# Check if mountpoint appears in mount output
317+
for line in result.stdout.split('\n'):
318+
# Match " on <mountpoint> " pattern to avoid false positives
319+
if f" on {mountpoint} " in line or line.endswith(f" on {mountpoint}"):
320+
return True
321+
return False
322322
except Exception:
323323
return False
324324

325325
def _get_mount_target(self, mountpoint: str) -> str:
326-
"""Get what is currently mounted at the given mountpoint."""
326+
"""Get what is currently mounted at the given mountpoint (cross-platform)."""
327327
try:
328-
# Check if mount utility is available
329-
self._check_required_utilities('mount')
330-
331328
result = subprocess.run(['mount'], capture_output=True, text=True)
332329
if result.returncode == 0:
333330
for line in result.stdout.split('\n'):
334-
if f" {mountpoint} " in line:
331+
# Match " on <mountpoint> " pattern
332+
if f" on {mountpoint} " in line or line.endswith(f" on {mountpoint}"):
335333
# Extract the source (first part before " on ")
336334
return line.split(' on ')[0]
337335
return "unknown"
338-
except RuntimeError as e:
339-
# Re-raise utility check errors
340-
raise
341336
except Exception:
342337
return "unknown"
343338

@@ -365,6 +360,8 @@ def _handle_root_volume_mounting(self, volume_name: str, mountpoint: str) -> Non
365360
# Add to fstab FIRST, then mount using fstab entry
366361
if self._add_to_fstab(volume_name, mountpoint, expected_nfs_target):
367362
logger.info(f" Volume '{volume_name}' added to fstab")
363+
# Now mount the volume using the fstab entry
364+
self._mount_from_fstab(mountpoint)
368365

369366
def _add_to_fstab(self, volume_name: str, mountpoint: str, nfs_target: str) -> bool:
370367
"""Add volume to fstab first, then mount using fstab entry (following requirements)."""
@@ -392,6 +389,43 @@ def _add_to_fstab(self, volume_name: str, mountpoint: str, nfs_target: str) -> b
392389
logger.info(f" Error in fstab setup and mount: {e}")
393390
return False
394391

392+
def _mount_from_fstab(self, mountpoint: str) -> bool:
393+
"""
394+
Mount a volume using its fstab entry.
395+
396+
Args:
397+
mountpoint: The mountpoint path to mount
398+
399+
Returns:
400+
bool: True if mount successful, False otherwise
401+
"""
402+
try:
403+
logger.info(f" Mounting volume at '{mountpoint}'...")
404+
405+
# Check if we need sudo
406+
needs_sudo = not os.access('/etc', os.W_OK)
407+
408+
if needs_sudo:
409+
result = subprocess.run(['sudo', 'mount', mountpoint],
410+
capture_output=True, text=True)
411+
else:
412+
result = subprocess.run(['mount', mountpoint],
413+
capture_output=True, text=True)
414+
415+
if result.returncode == 0:
416+
logger.info(f" Successfully mounted volume at '{mountpoint}'")
417+
return True
418+
else:
419+
error_msg = result.stderr.strip()
420+
logger.info(f" Warning: Failed to mount volume: {error_msg}")
421+
logger.info(f" You can manually mount it later with: sudo mount {mountpoint}")
422+
return False
423+
424+
except Exception as e:
425+
logger.info(f" Warning: Error mounting volume: {e}")
426+
logger.info(f" You can manually mount it later with: sudo mount {mountpoint}")
427+
return False
428+
395429
def _get_expected_nfs_target(self, volume_name: str) -> str:
396430
"""Get the expected NFS target for a volume."""
397431
try:

0 commit comments

Comments
 (0)