@@ -753,6 +753,12 @@ def storage_locked(self, session=None):
753
753
elif self ._target_status () != "OFF" :
754
754
reason = "target is on"
755
755
result = True
756
+ elif (self ._storage_status == CONSTS .STORAGE .ON_NETWORK and
757
+ self ._storage_owner is not None and
758
+ self ._storage_owner != session ):
759
+ reason = ("storage shared on the network for " +
760
+ f"{ self ._storage_owner } " )
761
+ result = True
756
762
# Lastly, the shared storage device shall not be opened
757
763
elif self ._storage_opened is True :
758
764
reason = "shared storage is in use (opened)"
@@ -820,29 +826,37 @@ def storage_network(self, **kwargs):
820
826
result = False
821
827
session = kwargs .get ("session" , None )
822
828
self .session_ping (session )
823
- if self .storage_locked (session ) is False :
824
- if self .storage .to_host () is True :
825
- conf = os .path .join (NBD_CONF_DIR , NBD_CONF_FILE )
826
- file = None
827
-
828
- if hasattr (self .storage , 'path' ):
829
- file = self .storage .path ()
830
829
831
- if file is not None and os .path .exists (NBD_CONF_DIR ):
832
- with open (conf , 'w' ) as f :
833
- f .write ('[mtda-storage]\n ' )
834
- f .write ('authfile = /etc/nbd-server/allow\n ' )
835
- f .write (f'exportname = { file } \n ' )
836
- f .close ()
830
+ if self .storage is None :
831
+ raise RuntimeError ('no shared storage device' )
832
+ elif hasattr (self .storage , 'path' ) is False :
833
+ raise RuntimeError ('path to shared storage not available' )
834
+ elif os .path .exists (NBD_CONF_DIR ) is False :
835
+ raise RuntimeError ('NBD configuration directory not found' )
836
+ elif self .storage_locked (session ) is True :
837
+ raise RuntimeError ('shared storage in use' )
838
+ elif self .storage .to_host () is True :
839
+ file = self .storage .path ()
840
+ if file :
841
+ conf = os .path .join (NBD_CONF_DIR , NBD_CONF_FILE )
842
+ with open (conf , 'w' ) as f :
843
+ f .write ('[mtda-storage]\n ' )
844
+ f .write ('authfile = /etc/nbd-server/allow\n ' )
845
+ f .write (f'exportname = { file } \n ' )
846
+ f .close ()
837
847
838
- cmd = ['systemctl' , 'restart' , 'nbd-server' ]
839
- subprocess .check_call (cmd )
848
+ cmd = ['systemctl' , 'restart' , 'nbd-server' ]
849
+ subprocess .check_call (cmd )
840
850
841
- cmd = ['systemctl' , 'is-active' , 'nbd-server' ]
842
- subprocess .check_call (cmd )
851
+ cmd = ['systemctl' , 'is-active' , 'nbd-server' ]
852
+ subprocess .check_call (cmd )
843
853
844
- self ._storage_event (CONSTS .STORAGE .ON_NETWORK )
845
- result = True
854
+ self ._storage_owner = session
855
+ self .storage_locked ()
856
+ self ._storage_event (CONSTS .STORAGE .ON_NETWORK )
857
+ result = True
858
+ else :
859
+ raise RuntimeError ('no path to shared storage' )
846
860
847
861
self .mtda .debug (3 , f"main.storage_network(): { result } " )
848
862
return result
@@ -1014,7 +1028,8 @@ def systemd_configure_www(self):
1014
1028
dropin = os .path .join (etcdir , 'www.conf' )
1015
1029
with open (dropin , 'w' ) as f :
1016
1030
f .write ('[Service]\n ' )
1017
- f .write (f'Environment=HOST={ self ._www_host } PORT={ self ._www_port } \n ' )
1031
+ f .write (f'Environment=HOST={ self ._www_host } '
1032
+ f'PORT={ self ._www_port } \n ' )
1018
1033
else :
1019
1034
import shutil
1020
1035
shutil .rmtree (etcdir , ignore_errors = True )
0 commit comments