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

fix(storage): take storage ownership when put on the network #453

Merged
merged 1 commit into from
Mar 10, 2025
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
2 changes: 1 addition & 1 deletion mtda/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def storage_network(self, remote):
if os.path.exists(cmd_nbd) is False:
raise RuntimeError(f'{cmd_nbd} not found')

rdev = self._impl.storage_network()
rdev = self._impl.storage_network(session=self._session)
if rdev is None:
raise RuntimeError('could not put storage on network')

Expand Down
55 changes: 35 additions & 20 deletions mtda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,12 @@ def storage_locked(self, session=None):
elif self._target_status() != "OFF":
reason = "target is on"
result = True
elif (self._storage_status == CONSTS.STORAGE.ON_NETWORK and
self._storage_owner is not None and
self._storage_owner != session):
reason = ("storage shared on the network for " +
f"{self._storage_owner}")
result = True
# Lastly, the shared storage device shall not be opened
elif self._storage_opened is True:
reason = "shared storage is in use (opened)"
Expand Down Expand Up @@ -820,29 +826,37 @@ def storage_network(self, **kwargs):
result = False
session = kwargs.get("session", None)
self.session_ping(session)
if self.storage_locked(session) is False:
if self.storage.to_host() is True:
conf = os.path.join(NBD_CONF_DIR, NBD_CONF_FILE)
file = None

if hasattr(self.storage, 'path'):
file = self.storage.path()

if file is not None and os.path.exists(NBD_CONF_DIR):
with open(conf, 'w') as f:
f.write('[mtda-storage]\n')
f.write('authfile = /etc/nbd-server/allow\n')
f.write(f'exportname = {file}\n')
f.close()
if self.storage is None:
raise RuntimeError('no shared storage device')
elif hasattr(self.storage, 'path') is False:
raise RuntimeError('path to shared storage not available')
elif os.path.exists(NBD_CONF_DIR) is False:
raise RuntimeError('NBD configuration directory not found')
elif self.storage_locked(session) is True:
raise RuntimeError('shared storage in use')
elif self.storage.to_host() is True:
file = self.storage.path()
if file:
conf = os.path.join(NBD_CONF_DIR, NBD_CONF_FILE)
with open(conf, 'w') as f:
f.write('[mtda-storage]\n')
f.write('authfile = /etc/nbd-server/allow\n')
f.write(f'exportname = {file}\n')
f.close()

cmd = ['systemctl', 'restart', 'nbd-server']
subprocess.check_call(cmd)
cmd = ['systemctl', 'restart', 'nbd-server']
subprocess.check_call(cmd)

cmd = ['systemctl', 'is-active', 'nbd-server']
subprocess.check_call(cmd)
cmd = ['systemctl', 'is-active', 'nbd-server']
subprocess.check_call(cmd)

self._storage_event(CONSTS.STORAGE.ON_NETWORK)
result = True
self._storage_owner = session
self.storage_locked()
self._storage_event(CONSTS.STORAGE.ON_NETWORK)
result = True
else:
raise RuntimeError('no path to shared storage')

self.mtda.debug(3, f"main.storage_network(): {result}")
return result
Expand Down Expand Up @@ -1014,7 +1028,8 @@ def systemd_configure_www(self):
dropin = os.path.join(etcdir, 'www.conf')
with open(dropin, 'w') as f:
f.write('[Service]\n')
f.write(f'Environment=HOST={self._www_host} PORT={self._www_port}\n')
f.write(f'Environment=HOST={self._www_host} '
f'PORT={self._www_port}\n')
else:
import shutil
shutil.rmtree(etcdir, ignore_errors=True)
Expand Down