Ejemplo n.º 1
0
    def test_unified_iso_deserialize(self):
        im = Images()
        i = Image(im)

        data = {
            'arch': 'x86_64',
            'disc_count': 1,
            'disc_number': 1,
            'format': 'iso',
            'type': 'dvd',
            'mtime': 1410855216,
            'path': "Fedora/x86_64/iso/Fedora-20-x86_64-DVD.iso",
            'size': 4603248640,
            'subvariant': 'Workstation',
            'volume_id': None,
            'implant_md5': None,
            'bootable': True,
            'checksums': {'sha256': 'XXXXXX'},
        }

        i.deserialize(data)
        self.assertFalse(i.unified)

        data['unified'] = True
        i.deserialize(data)
        self.assertTrue(i.unified)
Ejemplo n.º 2
0
    def test_unified_iso_deserialize(self):
        im = Images()
        i = Image(im)

        data = {
            'arch': 'x86_64',
            'disc_count': 1,
            'disc_number': 1,
            'format': 'iso',
            'type': 'dvd',
            'mtime': 1410855216,
            'path': "Fedora/x86_64/iso/Fedora-20-x86_64-DVD.iso",
            'size': 4603248640,
            'subvariant': 'Workstation',
            'volume_id': None,
            'implant_md5': None,
            'bootable': True,
            'checksums': {
                'sha256': 'XXXXXX'
            },
        }

        i.deserialize(data)
        self.assertFalse(i.unified)

        data['unified'] = True
        i.deserialize(data)
        self.assertTrue(i.unified)
Ejemplo n.º 3
0
    def test_unique_id_enforcement(self):
        """Test that adding two images with different checksums but
        matching UNIQUE_IMAGE_ATTRIBUTES is disallowed (on 1.1+).
        """
        im = Images()
        im.header.version = '1.1'

        i1 = Image(im)
        i2 = Image(im)
        data = {
            'arch': 'x86_64',
            'disc_count': 1,
            'disc_number': 1,
            'format': 'iso',
            'type': 'dvd',
            'mtime': 1410855216,
            'path': "Fedora/x86_64/iso/Fedora-20-x86_64-DVD.iso",
            'size': 4603248640,
            'subvariant': 'Workstation',
            'volume_id': None,
            'implant_md5': None,
            'bootable': True,
        }
        # NOTE: there's a rather subtle behaviour here where when you
        # deserialize, mutable things in the deserialized object are
        # not *copies* of the objects in the dict you deserialized
        # but *are* those objects. So if you modify them in the dict
        # after deserialization, *the deserialized object changes*.
        # I'm not sure whether this is intentional, but it means we
        # must be careful here, we cannot just deserialize i1, change
        # the checksums in data, then deserialize i2; if we do that,
        # i1's checksums are changed, the checksums for i1 and i2
        # match, and the expected error isn't triggered.
        data1 = dict(data)
        data1['checksums'] = {'sha256': 'XXXXXX'}
        i1.deserialize(data1)
        im.add("Workstation", "x86_64", i1)

        data2 = dict(data)
        data2['checksums'] = {'sha256': 'YYYYYY'}
        i2.deserialize(data2)
        self.assertRaises(ValueError, im.add, "Server", "x86_64", i2)
Ejemplo n.º 4
0
    def test_unique_id_enforcement(self):
        """Test that adding two images with different checksums but
        matching UNIQUE_IMAGE_ATTRIBUTES is disallowed (on 1.1+).
        """
        im = Images()
        im.header.version = '1.1'

        i1 = Image(im)
        i2 = Image(im)
        data = {
            'arch': 'x86_64',
            'disc_count': 1,
            'disc_number': 1,
            'format': 'iso',
            'type': 'dvd',
            'mtime': 1410855216,
            'path': "Fedora/x86_64/iso/Fedora-20-x86_64-DVD.iso",
            'size': 4603248640,
            'subvariant': 'Workstation',
            'volume_id': None,
            'implant_md5': None,
            'bootable': True,
        }
        # NOTE: there's a rather subtle behaviour here where when you
        # deserialize, mutable things in the deserialized object are
        # not *copies* of the objects in the dict you deserialized
        # but *are* those objects. So if you modify them in the dict
        # after deserialization, *the deserialized object changes*.
        # I'm not sure whether this is intentional, but it means we
        # must be careful here, we cannot just deserialize i1, change
        # the checksums in data, then deserialize i2; if we do that,
        # i1's checksums are changed, the checksums for i1 and i2
        # match, and the expected error isn't triggered.
        data1 = dict(data)
        data1['checksums'] = {'sha256': 'XXXXXX'}
        i1.deserialize(data1)
        im.add("Workstation", "x86_64", i1)

        data2 = dict(data)
        data2['checksums'] = {'sha256': 'YYYYYY'}
        i2.deserialize(data2)
        self.assertRaises(ValueError, im.add, "Server", "x86_64", i2)