def test_libvirt_nfs_driver_with_opts(self):
        mnt_base = '/mnt'
        self.flags(nfs_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = volume.LibvirtNFSVolumeDriver(self.fake_conn)
        self.stubs.Set(libvirt_utils, 'is_mounted', lambda x, d: False)
        export_string = '192.168.1.1:/nfs/share1'
        options = '-o intr,nfsvers=3'
        export_mnt_base = os.path.join(mnt_base,
                utils.get_hash_str(export_string))
        file_path = os.path.join(export_mnt_base, self.name)

        connection_info = {'data': {'export': export_string,
                                    'name': self.name,
                                    'options': options}}
        conf = libvirt_driver.connect_volume(connection_info, self.disk_info)
        tree = conf.format_dom()
        self._assertFileTypeEquals(tree, file_path)
        libvirt_driver.disconnect_volume(connection_info, "vde")

        expected_commands = [
            ('mkdir', '-p', export_mnt_base),
            ('mount', '-t', 'nfs', '-o', 'intr,nfsvers=3',
             export_string, export_mnt_base),
            ('umount', export_mnt_base),
        ]
        self.assertEqual(expected_commands, self.executes)
Пример #2
0
    def test_libvirt_nfs_driver(self):
        # NOTE(vish) exists is to make driver assume connecting worked
        mnt_base = '/mnt'
        self.flags(nfs_mount_point_base=mnt_base)

        libvirt_driver = volume.LibvirtNFSVolumeDriver(self.fake_conn)
        export_string = '192.168.1.1:/nfs/share1'
        name = 'volume-00001'
        export_mnt_base = os.path.join(
            mnt_base, libvirt_driver.get_hash_str(export_string))
        file_path = os.path.join(export_mnt_base, name)

        connection_info = {'data': {'export': export_string, 'name': name}}
        disk_info = {
            "bus": "virtio",
            "dev": "vde",
            "type": "disk",
        }
        conf = libvirt_driver.connect_volume(connection_info, disk_info)
        tree = conf.format_dom()
        self.assertEqual(tree.get('type'), 'file')
        self.assertEqual(tree.find('./source').get('file'), file_path)
        libvirt_driver.disconnect_volume(connection_info, "vde")

        expected_commands = [('stat', export_mnt_base),
                             ('mount', '-t', 'nfs', export_string,
                              export_mnt_base)]
        self.assertEqual(self.executes, expected_commands)
    def test_libvirt_nfs_driver_already_mounted(self):
        # NOTE(vish) exists is to make driver assume connecting worked
        mnt_base = '/mnt'
        self.flags(nfs_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = volume.LibvirtNFSVolumeDriver(self.fake_conn)

        export_string = '192.168.1.1:/nfs/share1'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(export_string))
        file_path = os.path.join(export_mnt_base, self.name)

        connection_info = {
            'data': {
                'export': export_string,
                'name': self.name
            }
        }
        conf = libvirt_driver.connect_volume(connection_info, self.disk_info)
        tree = conf.format_dom()
        self._assertFileTypeEquals(tree, file_path)
        libvirt_driver.disconnect_volume(connection_info, "vde")

        expected_commands = [('findmnt', '--target', export_mnt_base,
                              '--source', export_string),
                             ('umount', export_mnt_base)]
        self.assertEqual(self.executes, expected_commands)
Пример #4
0
 def test_libvirt_nfs_driver_umount_error(self, mock_LOG_exception,
                                          mock_LOG_debug, mock_utils_exe):
     export_string = '192.168.1.1:/nfs/share1'
     connection_info = {
         'data': {
             'export': export_string,
             'name': self.name
         }
     }
     libvirt_driver = volume.LibvirtNFSVolumeDriver(self.fake_conn)
     mock_utils_exe.side_effect = processutils.ProcessExecutionError(
         None, None, None, 'umount', 'umount: device is busy.')
     libvirt_driver.disconnect_volume(connection_info, "vde")
     self.assertTrue(mock_LOG_debug.called)
     mock_utils_exe.side_effect = processutils.ProcessExecutionError(
         None, None, None, 'umount', 'umount: target is busy.')
     libvirt_driver.disconnect_volume(connection_info, "vde")
     self.assertTrue(mock_LOG_debug.called)
     mock_utils_exe.side_effect = processutils.ProcessExecutionError(
         None, None, None, 'umount', 'umount: Other error.')
     libvirt_driver.disconnect_volume(connection_info, "vde")
     self.assertTrue(mock_LOG_exception.called)