@@ -107,6 +107,7 @@ func runIntegrationTest(t *testing.T, testFolder string) {
107107 Cmds : map [string ]func (* testscript.TestScript , bool , []string ){
108108 "isocmp" : isoCmp ,
109109 "ignitionImgContains" : ignitionImgContains ,
110+ "configImgContains" : configImgContains ,
110111 "initrdImgContains" : initrdImgContains ,
111112 },
112113 })
@@ -123,12 +124,39 @@ func ignitionImgContains(ts *testscript.TestScript, neg bool, args []string) {
123124 isoPath , eFilePath := args [0 ], args [1 ]
124125 isoPathAbs := filepath .Join (workDir , isoPath )
125126
126- _ , err := extractFileFromIgnitionImg (isoPathAbs , eFilePath )
127+ _ , err := extractArchiveFile (isoPathAbs , "/images/ignition.img" , eFilePath )
127128 ts .Check (err )
128129}
129130
131+ // [!] configImgContains `isoPath` `file` check if the specified file `file`
132+ // is stored within the config image ISO.
133+ func configImgContains (ts * testscript.TestScript , neg bool , args []string ) {
134+ if len (args ) != 2 {
135+ ts .Fatalf ("usage: configImgContains isoPath file" )
136+ }
137+
138+ workDir := ts .Getenv ("WORK" )
139+ isoPath , eFilePath := args [0 ], args [1 ]
140+ isoPathAbs := filepath .Join (workDir , isoPath )
141+
142+ _ , err := extractArchiveFile (isoPathAbs , eFilePath , "" )
143+ ts .Check (err )
144+ }
145+
146+ // archiveFileNames `isoPath` get the names of the archive files to use
147+ // based on the name of the ISO image.
148+ func archiveFileNames (isoPath string ) (string , string , error ) {
149+ if strings .HasPrefix (isoPath , "agent." ) {
150+ return "/images/ignition.img" , "config.ign" , nil
151+ } else if strings .HasPrefix (isoPath , "agentconfig." ) {
152+ return "/config.gz" , "" , nil
153+ }
154+
155+ return "" , "" , errors .NotFound (fmt .Sprintf ("ISO %s has unrecognized prefix" , isoPath ))
156+ }
157+
130158// [!] isoCmp `isoPath` `isoFile` `expectedFile` check that the content of the file
131- // `isoFile` - extracted from the ISO embedded ignition configuration file referenced
159+ // `isoFile` - extracted from the ISO embedded configuration file referenced
132160// by `isoPath` - matches the content of the local file `expectedFile`.
133161func isoCmp (ts * testscript.TestScript , neg bool , args []string ) {
134162 if len (args ) != 3 {
@@ -139,7 +167,12 @@ func isoCmp(ts *testscript.TestScript, neg bool, args []string) {
139167 isoPath , aFilePath , eFilePath := args [0 ], args [1 ], args [2 ]
140168 isoPathAbs := filepath .Join (workDir , isoPath )
141169
142- aData , err := readFileFromISOIgnitionCfg (isoPathAbs , aFilePath )
170+ archiveFile , ignitionFile , err := archiveFileNames (isoPath )
171+ if err != nil {
172+ ts .Check (err )
173+ }
174+
175+ aData , err := readFileFromISO (isoPathAbs , archiveFile , ignitionFile , aFilePath )
143176 ts .Check (err )
144177
145178 eFilePathAbs := filepath .Join (workDir , eFilePath )
@@ -171,26 +204,16 @@ func isoCmp(ts *testscript.TestScript, neg bool, args []string) {
171204 ts .Fatalf ("%s and %s differ" , aFilePath , eFilePath )
172205}
173206
174- func readFileFromISOIgnitionCfg (isoPath string , nodePath string ) ([]byte , error ) {
175- config , err := extractIgnitionCfg (isoPath )
207+ func readFileFromISO (isoPath , archiveFile , ignitionFile , nodePath string ) ([]byte , error ) {
208+ config , err := extractCfgData (isoPath , archiveFile , ignitionFile , nodePath )
176209 if err != nil {
177210 return nil , err
178211 }
179212
180- for _ , f := range config .Storage .Files {
181- if f .Node .Path == nodePath {
182- actualData , err := dataurl .DecodeString (* f .FileEmbedded1 .Contents .Source )
183- if err != nil {
184- return nil , err
185- }
186- return actualData .Data , nil
187- }
188- }
189-
190- return nil , errors .NotFound (nodePath )
213+ return config , nil
191214}
192215
193- func extractFileFromIgnitionImg (isoPath string , fileName string ) ([]byte , error ) {
216+ func extractArchiveFile (isoPath , archive , fileName string ) ([]byte , error ) {
194217 disk , err := diskfs .OpenWithMode (isoPath , diskfs .ReadOnly )
195218 if err != nil {
196219 return nil , err
@@ -201,7 +224,7 @@ func extractFileFromIgnitionImg(isoPath string, fileName string) ([]byte, error)
201224 return nil , err
202225 }
203226
204- ignitionImg , err := fs .OpenFile ("/images/ignition.img" , os .O_RDONLY )
227+ ignitionImg , err := fs .OpenFile (archive , os .O_RDONLY )
205228 if err != nil {
206229 return nil , err
207230 }
@@ -223,7 +246,8 @@ func extractFileFromIgnitionImg(isoPath string, fileName string) ([]byte, error)
223246 return nil , err
224247 }
225248
226- if header .Name == fileName {
249+ // If the file is not in ignition return it directly
250+ if fileName == "" || header .Name == fileName {
227251 rawContent , err := io .ReadAll (cpioReader )
228252 if err != nil {
229253 return nil , err
@@ -232,11 +256,20 @@ func extractFileFromIgnitionImg(isoPath string, fileName string) ([]byte, error)
232256 }
233257 }
234258
235- return nil , errors .NotFound (fmt .Sprintf ("File %s not found within the /images/ignition.img archive" , fileName ))
259+ return nil , errors .NotFound (fmt .Sprintf ("File %s not found within the %s archive" , fileName , archive ))
236260}
237261
238- func extractIgnitionCfg (isoPath string ) (* igntypes.Config , error ) {
239- rawContent , err := extractFileFromIgnitionImg (isoPath , "config.ign" )
262+ func extractCfgData (isoPath , archiveFile , ignitionFile , nodePath string ) ([]byte , error ) {
263+ if ignitionFile == "" {
264+ // If the archive is not part of an ignition file return the archive data
265+ rawContent , err := extractArchiveFile (isoPath , archiveFile , nodePath )
266+ if err != nil {
267+ return nil , err
268+ }
269+ return rawContent , nil
270+ }
271+
272+ rawContent , err := extractArchiveFile (isoPath , archiveFile , ignitionFile )
240273 if err != nil {
241274 return nil , err
242275 }
@@ -247,7 +280,17 @@ func extractIgnitionCfg(isoPath string) (*igntypes.Config, error) {
247280 return nil , err
248281 }
249282
250- return & config , nil
283+ for _ , f := range config .Storage .Files {
284+ if f .Node .Path == nodePath {
285+ actualData , err := dataurl .DecodeString (* f .FileEmbedded1 .Contents .Source )
286+ if err != nil {
287+ return nil , err
288+ }
289+ return actualData .Data , nil
290+ }
291+ }
292+
293+ return nil , errors .NotFound (fmt .Sprintf ("File %s not found within the %s archive" , nodePath , archiveFile ))
251294}
252295
253296// [!] initrdImgContains `isoPath` `file` check if the specified file `file`
0 commit comments