Commit c293a1e extra-files: Allow configuring used checksums

3 files Authored and Committed by lsedlar 7 months ago
extra-files: Allow configuring used checksums

Instead of adding a new config option, we can just reuse the existing
`media_checksums` value. If the value is good for image checksums, it
should work for extra files as well.

Relates: #591
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>

    
 1 @@ -764,7 +764,8 @@
 2   Extra Files Metadata
 3   --------------------
 4   If extra files are specified a metadata file, ``extra_files.json``, is placed
 5 - in the os/ directory and media. This metadata file is in the format:
 6 + in the ``os/`` directory and media. The checksums generated are determined by
 7 + ``media_checksums`` option. This metadata file is in the format:
 8   
 9   ::
10   
 1 @@ -47,7 +47,8 @@
 2                                             % (arch, variant.uid))
 3   
 4   
 5 - def copy_extra_files(compose, cfg, arch, variant, package_sets, checksum_type='sha256'):
 6 + def copy_extra_files(compose, cfg, arch, variant, package_sets, checksum_type=None):
 7 +     checksum_type = checksum_type or compose.conf['media_checksums']
 8       var_dict = {
 9           "arch": arch,
10           "variant_id": variant.id,
 1 @@ -200,6 +200,53 @@
 2           self.assertEqual(expected_metadata['header'], actual_metadata['header'])
 3           self.assertEqual(expected_metadata['data'], actual_metadata['data'])
 4   
 5 +     def test_write_extra_files_multiple_checksums(self):
 6 +         """Assert metadata is written to the proper location with valid data"""
 7 +         self.maxDiff = None
 8 +         mock_logger = mock.Mock()
 9 +         files = ['file1', 'file2', 'subdir/file3']
10 +         expected_metadata = {
11 +             u'header': {u'version': u'1.0'},
12 +             u'data': [
13 +                 {
14 +                     u'file': u'file1',
15 +                     u'checksums': {
16 +                         u'md5': u'5149d403009a139c7e085405ef762e1a',
17 +                         u'sha256': u'ecdc5536f73bdae8816f0ea40726ef5e9b810d914493075903bb90623d97b1d8'
18 +                     },
19 +                     u'size': 6,
20 +                 },
21 +                 {
22 +                     u'file': u'file2',
23 +                     u'checksums': {
24 +                         u'md5': u'3d709e89c8ce201e3c928eb917989aef',
25 +                         u'sha256': u'67ee5478eaadb034ba59944eb977797b49ca6aa8d3574587f36ebcbeeb65f70e'
26 +                     },
27 +                     u'size': 6,
28 +                 },
29 +                 {
30 +                     u'file': u'subdir/file3',
31 +                     u'checksums': {
32 +                         u'md5': u'1ed02b5cf7fd8626f854e9ef3fee8694',
33 +                         u'sha256': u'52f9f0e467e33da811330cad085fdb4eaa7abcb9ebfe6001e0f5910da678be51'
34 +                     },
35 +                     u'size': 13,
36 +                 },
37 +             ]
38 +         }
39 +         tree_dir = os.path.join(self.topdir, 'compose', 'Server', 'x86_64', 'os')
40 +         for f in files:
41 +             helpers.touch(os.path.join(tree_dir, f), f + '\n')
42 + 
43 +         metadata_file = metadata.write_extra_files(tree_dir, files,
44 +                                                    checksum_type=['md5', 'sha256'],
45 +                                                    logger=mock_logger)
46 +         with open(metadata_file) as metadata_fd:
47 +             actual_metadata = json.load(metadata_fd)
48 + 
49 +         self.assertEqual(expected_metadata['header'], actual_metadata['header'])
50 +         self.assertEqual(expected_metadata['data'], actual_metadata['data'])
51 + 
52       def test_write_extra_files_missing_file(self):
53           """Assert metadata is written to the proper location with valid data"""
54           mock_logger = mock.Mock()