11__author__ = 'desultory'
2- __version__ = '2.2.0 '
2+ __version__ = '2.2.1 '
33
44from zenlib .util import check_dict
55
@@ -99,12 +99,22 @@ def _process_cryptsetup_multi(self, mapped_name: str, config: dict) -> None:
9999 self ['cryptsetup' ][mapped_name ] = config
100100
101101
102- def _validate_luks_source (self , source_info : dict , cryptsetup_info : dict ) -> None :
102+ @check_dict ('validate' , value = True , log_level = 30 , message = "Skipping LUKS source validation." )
103+ def _validate_luks_source (self , mapped_name : str ) -> None :
103104 """ Checks that a LUKS source device is valid """
104- if not source_info ['uuid' ].startswith ('CRYPT-LUKS' ):
105- raise ValueError ("Device is not a crypt device: %s" % source_info )
105+ for _dm_info in self ['_dm_info' ].values ():
106+ if _dm_info ['name' ] == mapped_name :
107+ dm_info = _dm_info
108+ break
109+ else :
110+ raise ValueError ("No device mapper information found for: %s" % mapped_name )
111+
112+ cryptsetup_info = self ['cryptsetup' ][mapped_name ]
113+
114+ if not dm_info ['uuid' ].startswith ('CRYPT-LUKS' ):
115+ raise ValueError ("Device is not a crypt device: %s" % dm_info )
106116
107- slave_source = source_info ['slaves' ][0 ]
117+ slave_source = dm_info ['slaves' ][0 ]
108118
109119 try :
110120 blkid_info = self ['_blkid_info' ][f'/dev/{ slave_source } ' ]
@@ -114,10 +124,11 @@ def _validate_luks_source(self, source_info: dict, cryptsetup_info: dict) -> Non
114124 for token_type in ['partuuid' , 'uuid' ]:
115125 if cryptsetup_token := cryptsetup_info .get (token_type ):
116126 if blkid_info .get (token_type ) != cryptsetup_token :
117- raise ValueError ("LUKS %s mismatch, found '%s', expected: %s" % (token_type , cryptsetup_token , blkid_info [token_type ]))
127+ raise ValueError ("[%s] LUKS %s mismatch, found '%s', expected: %s" %
128+ (mapped_name , token_type , cryptsetup_token , blkid_info [token_type ]))
118129 break
119130 else :
120- raise ValueError ("Unable to validate LUKS source: %s" % source_info )
131+ raise ValueError ("[%s] Unable to validate LUKS source: %s" % ( mapped_name , cryptsetup_info ) )
121132
122133
123134def get_crypt_sources (self ) -> list [str ]:
@@ -143,13 +154,7 @@ def get_crypt_sources(self) -> list[str]:
143154
144155 self .logger .debug ("[%s] Created block device identifier token: %s" % (name , token ))
145156 # Check that it's actually a LUKS device
146- if self ['validate' ]: # Check that it's actually a LUKS device
147- for dm_info in self ['_dm_info' ].values ():
148- if dm_info ['name' ] == name :
149- _validate_luks_source (self , dm_info , parameters )
150- break
151- else :
152- raise ValueError ("No device mapper information found for: %s" % name )
157+ _validate_luks_source (self , name )
153158 # Add a blkid command to get the source device in the initramfs, only match if the device has a partuuid
154159 out .append (f"export SOURCE_TOKEN_{ name } ='{ token [0 ]} ={ token [1 ]} '" )
155160 source_cmd = f'export CRYPTSETUP_SOURCE_{ name } =$(blkid --match-token "$SOURCE_TOKEN_{ name } " --match-tag PARTUUID --output device)'
0 commit comments