def test_init(self):
        # Test that we initialise the state of MountManager correctly at
        # startup
        def fake_disk(disk):
            libvirt_disk = libvirt_config.LibvirtConfigGuestDisk()
            libvirt_disk.source_type = disk[0]
            libvirt_disk.source_path = os.path.join(*disk[1])
            return libvirt_disk

        def mock_guest(uuid, disks):
            guest = mock.create_autospec(libvirt_guest.Guest)
            guest.uuid = uuid
            guest.get_all_disks.return_value = map(fake_disk, disks)
            return guest

        local_dir = '/local'
        mountpoint_a = '/mnt/a'
        mountpoint_b = '/mnt/b'

        self.mounted.add(mountpoint_a)
        self.mounted.add(mountpoint_b)

        guests = map(
            mock_guest,
            [uuids.instance_a, uuids.instance_b],
            [
                # Local file root disk and a volume on each of mountpoints a and b
                [
                    ('file', (local_dir, uuids.instance_a, 'disk')),
                    ('file', (mountpoint_a, 'vola1')),
                    ('file', (mountpoint_b, 'volb1')),
                ],

                # Local LVM root disk and a volume on each of mountpoints a and b
                [
                    ('block', ('/dev', 'vg', uuids.instance_b + '_disk')),
                    ('file', (mountpoint_a, 'vola2')),
                    ('file', (mountpoint_b, 'volb2')),
                ]
            ])

        host = mock.create_autospec(libvirt_host.Host)
        host.list_guests.return_value = guests

        m = mount._HostMountState(host, 0)

        self.assertEqual([mountpoint_a, mountpoint_b],
                         sorted(m.mountpoints.keys()))

        self.assertSetEqual(
            set([('vola1', uuids.instance_a), ('vola2', uuids.instance_b)]),
            m.mountpoints[mountpoint_a].attachments)
        self.assertSetEqual(
            set([('volb1', uuids.instance_a), ('volb2', uuids.instance_b)]),
            m.mountpoints[mountpoint_b].attachments)
Beispiel #2
0
    def test_init(self):
        # Test that we initialise the state of MountManager correctly at
        # startup
        def fake_disk(disk):
            libvirt_disk = libvirt_config.LibvirtConfigGuestDisk()
            libvirt_disk.source_type = disk[0]
            libvirt_disk.source_path = os.path.join(*disk[1])
            return libvirt_disk

        def mock_guest(uuid, disks):
            guest = mock.create_autospec(libvirt_guest.Guest)
            guest.uuid = uuid
            guest.get_all_disks.return_value = map(fake_disk, disks)
            return guest

        local_dir = '/local'
        mountpoint_a = '/mnt/a'
        mountpoint_b = '/mnt/b'

        self.mounted.add(mountpoint_a)
        self.mounted.add(mountpoint_b)

        guests = map(mock_guest, [uuids.instance_a, uuids.instance_b], [
            # Local file root disk and a volume on each of mountpoints a and b
            [
                ('file', (local_dir, uuids.instance_a, 'disk')),
                ('file', (mountpoint_a, 'vola1')),
                ('file', (mountpoint_b, 'volb1')),
            ],

            # Local LVM root disk and a volume on each of mountpoints a and b
            [
                ('block', ('/dev', 'vg', uuids.instance_b + '_disk')),
                ('file', (mountpoint_a, 'vola2')),
                ('file', (mountpoint_b, 'volb2')),
            ]
        ])

        host = mock.create_autospec(libvirt_host.Host)
        host.list_guests.return_value = guests

        m = mount._HostMountState(host, 0)

        self.assertEqual([mountpoint_a, mountpoint_b],
                         sorted(m.mountpoints.keys()))

        self.assertSetEqual(set([('vola1', uuids.instance_a),
                                 ('vola2', uuids.instance_b)]),
                            m.mountpoints[mountpoint_a].attachments)
        self.assertSetEqual(set([('volb1', uuids.instance_a),
                                 ('volb2', uuids.instance_b)]),
                            m.mountpoints[mountpoint_b].attachments)
Beispiel #3
0
 def _get_clean_hostmountstate():
     # list_guests returns no guests: _HostMountState initial state is
     # clean.
     host = mock.create_autospec(libvirt_host.Host)
     host.list_guests.return_value = []
     return mount._HostMountState(host, 0)
Beispiel #4
0
 def _get_clean_hostmountstate():
     # list_guests returns no guests: _HostMountState initial state is
     # clean.
     host = mock.create_autospec(libvirt_host.Host)
     host.list_guests.return_value = []
     return mount._HostMountState(host, 0)