Ejemplo n.º 1
0
    def test_from_legacy_mapping(self):
        def _get_image_bdms(bdms):
            return [bdm for bdm in bdms if bdm["source_type"] == "image"]

        def _get_bootable_bdms(bdms):
            return [bdm for bdm in bdms if bdm["boot_index"] >= 0]

        new_no_img = block_device.from_legacy_mapping(self.legacy_mapping)
        self.assertEqual(len(_get_image_bdms(new_no_img)), 0)

        for new, expected in zip(new_no_img, self.new_mapping):
            self.assertThat(new, matchers.IsSubDictOf(expected))

        new_with_img = block_device.from_legacy_mapping(self.legacy_mapping, "fake_image_ref")
        image_bdms = _get_image_bdms(new_with_img)
        boot_bdms = _get_bootable_bdms(new_with_img)
        self.assertEqual(len(image_bdms), 1)
        self.assertEqual(len(boot_bdms), 1)
        self.assertEqual(image_bdms[0]["boot_index"], 0)
        self.assertEqual(boot_bdms[0]["source_type"], "image")

        new_with_img_and_root = block_device.from_legacy_mapping(self.legacy_mapping, "fake_image_ref", "sda1")
        image_bdms = _get_image_bdms(new_with_img_and_root)
        boot_bdms = _get_bootable_bdms(new_with_img_and_root)
        self.assertEqual(len(image_bdms), 0)
        self.assertEqual(len(boot_bdms), 1)
        self.assertEqual(boot_bdms[0]["boot_index"], 0)
        self.assertEqual(boot_bdms[0]["source_type"], "volume")

        new_no_root = block_device.from_legacy_mapping(self.legacy_mapping, "fake_image_ref", "sda1", no_root=True)
        self.assertEqual(len(_get_image_bdms(new_no_root)), 0)
        self.assertEqual(len(_get_bootable_bdms(new_no_root)), 0)
Ejemplo n.º 2
0
    def test_from_legacy_mapping(self):
        def _get_image_bdms(bdms):
            return [bdm for bdm in bdms if bdm['source_type'] == 'image']

        def _get_bootable_bdms(bdms):
            return [bdm for bdm in bdms if bdm['boot_index'] >= 0]

        new_no_img = block_device.from_legacy_mapping(self.legacy_mapping)
        self.assertEqual(len(_get_image_bdms(new_no_img)), 0)

        for new, expected in zip(new_no_img, self.new_mapping):
            self.assertThat(new, matchers.IsSubDictOf(expected))

        new_with_img = block_device.from_legacy_mapping(
            self.legacy_mapping, 'fake_image_ref')
        image_bdms = _get_image_bdms(new_with_img)
        boot_bdms = _get_bootable_bdms(new_with_img)
        self.assertEqual(len(image_bdms), 1)
        self.assertEqual(len(boot_bdms), 1)
        self.assertEqual(image_bdms[0]['boot_index'], 0)
        self.assertEqual(boot_bdms[0]['source_type'], 'image')

        new_with_img_and_root = block_device.from_legacy_mapping(
            self.legacy_mapping, 'fake_image_ref', 'sda1')
        image_bdms = _get_image_bdms(new_with_img_and_root)
        boot_bdms = _get_bootable_bdms(new_with_img_and_root)
        self.assertEqual(len(image_bdms), 0)
        self.assertEqual(len(boot_bdms), 1)
        self.assertEqual(boot_bdms[0]['boot_index'], 0)
        self.assertEqual(boot_bdms[0]['source_type'], 'volume')

        new_no_root = block_device.from_legacy_mapping(
            self.legacy_mapping, 'fake_image_ref', 'sda1', no_root=True)
        self.assertEqual(len(_get_image_bdms(new_no_root)), 0)
        self.assertEqual(len(_get_bootable_bdms(new_no_root)), 0)
Ejemplo n.º 3
0
    def test_from_legacy_mapping(self):
        def _get_image_bdms(bdms):
            return [bdm for bdm in bdms if bdm['source_type'] == 'image']

        def _get_bootable_bdms(bdms):
            return [bdm for bdm in bdms if bdm['boot_index'] >= 0]

        new_no_img = block_device.from_legacy_mapping(self.legacy_mapping)
        self.assertEqual(0, len(_get_image_bdms(new_no_img)))

        for new, expected in zip(new_no_img, self.new_mapping):
            self.assertThat(new, matchers.IsSubDictOf(expected))

        new_with_img = block_device.from_legacy_mapping(
            self.legacy_mapping, 'fake_image_ref')
        image_bdms = _get_image_bdms(new_with_img)
        boot_bdms = _get_bootable_bdms(new_with_img)
        self.assertEqual(1, len(image_bdms))
        self.assertEqual(1, len(boot_bdms))
        self.assertEqual(0, image_bdms[0]['boot_index'])
        self.assertEqual('image', boot_bdms[0]['source_type'])

        new_with_img_and_root = block_device.from_legacy_mapping(
            self.legacy_mapping, 'fake_image_ref', 'sda1')
        image_bdms = _get_image_bdms(new_with_img_and_root)
        boot_bdms = _get_bootable_bdms(new_with_img_and_root)
        self.assertEqual(0, len(image_bdms))
        self.assertEqual(1, len(boot_bdms))
        self.assertEqual(0, boot_bdms[0]['boot_index'])
        self.assertEqual('volume', boot_bdms[0]['source_type'])

        new_no_root = block_device.from_legacy_mapping(self.legacy_mapping,
                                                       'fake_image_ref',
                                                       'sda1',
                                                       no_root=True)
        self.assertEqual(0, len(_get_image_bdms(new_no_root)))
        self.assertEqual(0, len(_get_bootable_bdms(new_no_root)))