@@ -69,20 +69,28 @@ def __init__(self, fs: FSOperations, path: str) -> None:
6969 self .fs = fs
7070 self .path = path
7171
72- def _handle_cephfs_error (self , e : Exception , action : str ) -> Optional [str ]:
72+ def _handle_cephfs_error (
73+ self , e : Exception , action : str
74+ ) -> Optional [str ]:
7375 if isinstance (e , ValueError ):
74- raise EarmarkException (errno .EINVAL , f"Invalid earmark specified: { e } " ) from e
76+ raise EarmarkException (
77+ errno .EINVAL , f"Invalid earmark specified: { e } "
78+ ) from e
7579 elif isinstance (e , OSError ):
7680 if e .errno == errno .ENODATA :
7781 # Return empty string when earmark is not set
78- log .info (f"No earmark set for the path while { action } . Returning empty result." )
82+ log .info (
83+ f"No earmark set for the path while { action } . Returning empty result."
84+ )
7985 return ''
8086 else :
8187 log .error (f"Error { action } earmark: { e } " )
8288 raise EarmarkException (- e .errno , e .strerror ) from e
8389 else :
8490 log .error (f"Unexpected error { action } earmark: { e } " )
85- raise EarmarkException (errno .EFAULT , f"Unexpected error { action } earmark: { e } " ) from e
91+ raise EarmarkException (
92+ errno .EFAULT , f"Unexpected error { action } earmark: { e } "
93+ ) from e
8694
8795 @staticmethod
8896 def parse_earmark (value : str ) -> Optional [EarmarkContents ]:
@@ -109,7 +117,9 @@ def parse_earmark(value: str) -> Optional[EarmarkContents]:
109117 raise EarmarkParseError ("Earmark contains empty sections." )
110118
111119 # Return parsed earmark with top scope and subsections
112- return EarmarkContents (top = EarmarkTopScope (parts [0 ]), subsections = parts [1 :])
120+ return EarmarkContents (
121+ top = EarmarkTopScope (parts [0 ]), subsections = parts [1 :]
122+ )
113123
114124 def _validate_earmark (self , earmark : str ) -> bool :
115125 """
@@ -130,19 +140,23 @@ def _validate_earmark(self, earmark: str) -> bool:
130140 # Specific validation for 'smb' scope
131141 if parsed .top == EarmarkTopScope .SMB :
132142 # Valid formats: 'smb' or 'smb.cluster.{cluster_id}'
133- if not (len (parsed .subsections ) == 0 or
134- (len (parsed .subsections ) == 2 and
135- parsed .subsections [0 ] == 'cluster' and parsed .subsections [1 ])):
143+ if not (
144+ len (parsed .subsections ) == 0
145+ or (
146+ len (parsed .subsections ) == 2
147+ and parsed .subsections [0 ] == 'cluster'
148+ and parsed .subsections [1 ]
149+ )
150+ ):
136151 return False
137152
138153 return True
139154
140155 def get_earmark (self ) -> Optional [str ]:
141156 try :
142- earmark_value = (
143- self .fs .getxattr (self .path , XATTR_SUBVOLUME_EARMARK_NAME )
144- .decode ('utf-8' )
145- )
157+ earmark_value = self .fs .getxattr (
158+ self .path , XATTR_SUBVOLUME_EARMARK_NAME
159+ ).decode ('utf-8' )
146160 return earmark_value
147161 except Exception as e :
148162 return self ._handle_cephfs_error (e , "getting" )
@@ -155,11 +169,16 @@ def set_earmark(self, earmark: str) -> None:
155169 f"Invalid earmark specified: '{ earmark } '. "
156170 "A valid earmark should either be empty or start with 'nfs' or 'smb', "
157171 "followed by dot-separated non-empty components or simply set "
158- "'smb.cluster.{cluster_id}' for the smb intra-cluster scope."
159- )
172+ "'smb.cluster.{cluster_id}' for the smb intra-cluster scope." ,
173+ )
160174
161175 try :
162- self .fs .setxattr (self .path , XATTR_SUBVOLUME_EARMARK_NAME , earmark .encode ('utf-8' ), 0 )
176+ self .fs .setxattr (
177+ self .path ,
178+ XATTR_SUBVOLUME_EARMARK_NAME ,
179+ earmark .encode ('utf-8' ),
180+ 0 ,
181+ )
163182 log .info (f"Earmark '{ earmark } ' set on { self .path } ." )
164183 except Exception as e :
165184 self ._handle_cephfs_error (e , "setting" )
0 commit comments