コード例 #1
0
ファイル: test_utils.py プロジェクト: digambar15/nova
 def test_get_hash_str(self):
     base_str = b"foo"
     base_unicode = u"foo"
     value = hashlib.md5(base_str).hexdigest()
     self.assertEqual(
         value, utils.get_hash_str(base_str))
     self.assertEqual(
         value, utils.get_hash_str(base_unicode))
コード例 #2
0
ファイル: test_quobyte.py プロジェクト: mahak/nova
    def test_libvirt_quobyte_driver_qcow2(self, mock_mount_volume,
                                          mock_validate_volume, mock_umount):
        mnt_base = '/mnt'
        self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')
        libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_host)
        export_string = 'quobyte://192.168.1.1/volume-00001'
        name = 'volume-00001'
        image_format = 'qcow2'
        quobyte_volume = '192.168.1.1/volume-00001'

        connection_info = {'data': {'export': export_string,
                                    'name': name,
                                    'format': image_format}}

        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))
        mock_validate_volume.side_effect = [nova_exception.StaleVolumeMount(
            "This shall fail."), True, True]

        libvirt_driver.connect_volume(connection_info, mock.sentinel.instance)
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()
        self.assertEqual('file', tree.get('type'))
        self.assertEqual('qcow2', tree.find('./driver').get('type'))

        (mock_mount_volume.
         assert_called_once_with('192.168.1.1/volume-00001',
                                 export_mnt_base,
                                 mock.ANY))
        mock_validate_volume.assert_called_with(export_mnt_base)

        libvirt_driver.disconnect_volume(connection_info,
                                         mock.sentinel.instance)
        mock_umount.assert_has_calls([mock.call(export_mnt_base),
                                      mock.call(export_mnt_base)])
コード例 #3
0
ファイル: volume.py プロジェクト: EliseCheng/nova
    def get_config(self, connection_info, disk_info):
        """Returns xml for libvirt."""
        conf = super(LibvirtGlusterfsVolumeDriver,
                     self).get_config(connection_info, disk_info)

        data = connection_info['data']

        if 'gluster' in CONF.libvirt.qemu_allowed_storage_drivers:
            vol_name = data['export'].split('/')[1]
            source_host = data['export'].split('/')[0][:-1]

            conf.source_ports = ['24007']
            conf.source_type = 'network'
            conf.source_protocol = 'gluster'
            conf.source_hosts = [source_host]
            conf.source_name = '%s/%s' % (vol_name, data['name'])
        else:
            path = os.path.join(CONF.libvirt.glusterfs_mount_point_base,
                utils.get_hash_str(data['export']))
            path = os.path.join(path, data['name'])
            conf.source_type = 'file'
            conf.source_path = path

        conf.driver_format = connection_info['data'].get('format', 'raw')

        return conf
コード例 #4
0
ファイル: test_libvirt_volume.py プロジェクト: ewindisch/nova
    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)
        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)
        ]
        self.assertEqual(self.executes, expected_commands)
コード例 #5
0
ファイル: test_glusterfs.py プロジェクト: 4everming/nova
    def test_libvirt_glusterfs_driver_with_opts(self, mock_is_mounted):
        mnt_base = '/mnt'
        self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = glusterfs.LibvirtGlusterfsVolumeDriver(self.fake_conn)
        export_string = '192.168.1.1:/volume-00001'
        options = '-o backupvolfile-server=192.168.1.2'
        export_mnt_base = os.path.join(mnt_base,
                utils.get_hash_str(export_string))

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

        expected_commands = [
            ('mkdir', '-p', export_mnt_base),
            ('mount', '-t', 'glusterfs',
             '-o', 'backupvolfile-server=192.168.1.2',
             export_string, export_mnt_base),
            ('umount', export_mnt_base),
        ]
        self.assertEqual(expected_commands, self.executes)
        self.assertTrue(mock_is_mounted.called)
コード例 #6
0
ファイル: test_glusterfs.py プロジェクト: 4everming/nova
    def test_libvirt_glusterfs_driver_get_config(self):
        mnt_base = '/mnt'
        self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt')

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

        # Test default format - raw
        connection_info = {'data': {'export': export_string,
                                    'name': self.name,
                                    'device_path': file_path}}
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()
        self._assertFileTypeEquals(tree, file_path)
        self.assertEqual('raw', tree.find('./driver').get('type'))

        # Test specified format - qcow2
        connection_info = {'data': {'export': export_string,
                                    'name': self.name,
                                    'device_path': file_path,
                                    'format': 'qcow2'}}
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()
        self._assertFileTypeEquals(tree, file_path)
        self.assertEqual('qcow2', tree.find('./driver').get('type'))
コード例 #7
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, 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'
        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 = [
            ('mkdir', '-p', export_mnt_base),
            ('mount', '-t', 'nfs', export_string, export_mnt_base),
            ('umount', export_mnt_base)]
        self.assertEqual(expected_commands, self.executes)
コード例 #8
0
ファイル: quobyte.py プロジェクト: nuistchh/nova
    def _get_mount_point_for_share(self, quobyte_volume):
        """Return mount point for Quobyte volume.

        :param quobyte_volume: Example: storage-host/openstack-volumes
        """
        return os.path.join(CONF.libvirt.quobyte_mount_point_base,
                            utils.get_hash_str(quobyte_volume))
コード例 #9
0
    def test_libvirt_glusterfs_driver_with_opts(self):
        mnt_base = '/mnt'
        self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = volume.LibvirtGlusterfsVolumeDriver(self.fake_conn)
        self.stubs.Set(libvirt_utils, 'is_mounted', lambda x, d: False)
        export_string = '192.168.1.1:/volume-00001'
        options = '-o backupvolfile-server=192.168.1.2'
        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', 'glusterfs',
             '-o', 'backupvolfile-server=192.168.1.2',
             export_string, export_mnt_base),
            ('umount', export_mnt_base),
        ]
        self.assertEqual(self.executes, expected_commands)
コード例 #10
0
ファイル: test_quobyte.py プロジェクト: fabian4/nova
    def test_libvirt_quobyte_driver_mount(self,
                                          mock_is_mounted,
                                          mock_mount_volume,
                                          mock_validate_volume
                                          ):
        mnt_base = '/mnt'
        self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_conn)
        export_string = 'quobyte://192.168.1.1/volume-00001'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))
        file_path = os.path.join(export_mnt_base, self.name)

        connection_info = {'data': {'export': export_string,
                                    'name': self.name}}
        libvirt_driver.connect_volume(connection_info, self.disk_info)

        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()

        self._assertFileTypeEquals(tree, file_path)

        mock_mount_volume.assert_called_once_with(quobyte_volume,
                                                  export_mnt_base,
                                                  mock.ANY)
        mock_validate_volume.assert_called_with(export_mnt_base)
コード例 #11
0
ファイル: test_quobyte.py プロジェクト: fabian4/nova
    def test_libvirt_quobyte_driver_already_mounted(self,
                                                    mock_umount_volume,
                                                    mock_validate_volume
                                                    ):
        mnt_base = '/mnt'
        self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_conn)
        export_string = 'quobyte://192.168.1.1/volume-00001'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))
        file_path = os.path.join(export_mnt_base, self.name)

        connection_info = {'data': {'export': export_string,
                                    'name': self.name}}

        libvirt_driver.connect_volume(connection_info, self.disk_info)

        conf = libvirt_driver.get_config(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', "quobyte@" + quobyte_volume),
            ('findmnt', '--target', export_mnt_base,
             '--source', "quobyte@" + quobyte_volume),
            ]
        self.assertEqual(expected_commands, self.executes)

        mock_umount_volume.assert_called_once_with(export_mnt_base)
        mock_validate_volume.assert_called_once_with(export_mnt_base)
コード例 #12
0
ファイル: test_quobyte.py プロジェクト: fabian4/nova
    def test_libvirt_quobyte_driver_qcow2(self, mock_is_mounted,
                                          mock_mount_volume,
                                          mock_validate_volume
                                          ):
        mnt_base = '/mnt'
        self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')
        libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_conn)
        export_string = 'quobyte://192.168.1.1/volume-00001'
        name = 'volume-00001'
        image_format = 'qcow2'
        quobyte_volume = '192.168.1.1/volume-00001'

        connection_info = {'data': {'export': export_string,
                                    'name': name,
                                    'format': image_format}}

        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))

        libvirt_driver.connect_volume(connection_info, self.disk_info)
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()
        self.assertEqual(tree.get('type'), 'file')
        self.assertEqual(tree.find('./driver').get('type'), 'qcow2')

        (mock_mount_volume.
         assert_called_once_with('192.168.1.1/volume-00001',
                                 export_mnt_base,
                                 mock.ANY))
        mock_validate_volume.assert_called_with(export_mnt_base)

        libvirt_driver.disconnect_volume(connection_info, "vde")
コード例 #13
0
ファイル: test_quobyte.py プロジェクト: mahak/nova
    def test_libvirt_quobyte_driver_mount(self,
                                          mock_is_mounted,
                                          mock_mount_volume,
                                          mock_validate_volume,
                                          mock_umount_volume
                                          ):
        mnt_base = '/mnt'
        self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_host)
        export_string = 'quobyte://192.168.1.1/volume-00001'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))
        file_path = os.path.join(export_mnt_base, self.name)

        connection_info = {'data': {'export': export_string,
                                    'name': self.name}}
        mock_validate_volume.side_effect = [nova_exception.StaleVolumeMount(
            "This shall fail."), True, True]

        libvirt_driver.connect_volume(connection_info, mock.sentinel.instance)

        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()

        self._assertFileTypeEquals(tree, file_path)

        mock_mount_volume.assert_called_once_with(quobyte_volume,
                                                  export_mnt_base,
                                                  mock.ANY)
        mock_validate_volume.assert_called_with(export_mnt_base)
        mock_umount_volume.assert_called_once_with(
            libvirt_driver._get_mount_path(connection_info))
コード例 #14
0
ファイル: volume.py プロジェクト: Redosen/nova
 def _ensure_mounted(self, nfs_export, options=None):
     """@type nfs_export: string
        @type options: string
     """
     mount_path = os.path.join(CONF.libvirt.nfs_mount_point_base,
                               utils.get_hash_str(nfs_export))
     self._mount_nfs(mount_path, nfs_export, options, ensure=True)
     return mount_path
コード例 #15
0
ファイル: test_quobyte.py プロジェクト: wenlongwljs/nova
    def test_quobyte_umount_volume_fails(self, mock_execute, mock_exception):
        mnt_base = "/mnt"
        quobyte_volume = "192.168.1.1/volume-00001"
        export_mnt_base = os.path.join(mnt_base, utils.get_hash_str(quobyte_volume))

        quobyte.umount_volume(export_mnt_base)

        (mock_exception.assert_called_once_with("Couldn't unmount " "the Quobyte Volume at %s", export_mnt_base))
コード例 #16
0
ファイル: test_quobyte.py プロジェクト: wenlongwljs/nova
    def test_quobyte_umount_volume(self, mock_execute):
        mnt_base = "/mnt"
        quobyte_volume = "192.168.1.1/volume-00001"
        export_mnt_base = os.path.join(mnt_base, utils.get_hash_str(quobyte_volume))

        quobyte.umount_volume(export_mnt_base)

        mock_execute.assert_called_once_with("umount.quobyte", export_mnt_base)
コード例 #17
0
ファイル: test_quobyte.py プロジェクト: wenlongwljs/nova
    def test_quobyte_is_valid_volume(self, mock_execute, mock_access):
        mnt_base = "/mnt"
        quobyte_volume = "192.168.1.1/volume-00001"
        export_mnt_base = os.path.join(mnt_base, utils.get_hash_str(quobyte_volume))

        quobyte.validate_volume(export_mnt_base)

        mock_execute.assert_called_once_with("getfattr", "-n", "quobyte.info", export_mnt_base)
コード例 #18
0
ファイル: s3server.py プロジェクト: osrg/nova
 def _object_path(self, bucket, object_name):
     if self.application.bucket_depth < 1:
         return os.path.abspath(os.path.join(self.application.directory, bucket, object_name))
     hash = utils.get_hash_str(object_name)
     path = os.path.abspath(os.path.join(self.application.directory, bucket))
     for i in range(self.application.bucket_depth):
         path = os.path.join(path, hash[: 2 * (i + 1)])
     return os.path.join(path, object_name)
コード例 #19
0
ファイル: volume.py プロジェクト: kbijon/OpenStack-CVRM
 def _ensure_mounted(self, glusterfs_export, options=None):
     """@type glusterfs_export: string
        @type options: string
     """
     mount_path = os.path.join(CONF.libvirt.glusterfs_mount_point_base, utils.get_hash_str(glusterfs_export))
     if not virtutils.is_mounted(mount_path, glusterfs_export):
         self._mount_glusterfs(mount_path, glusterfs_export, options, ensure=True)
     return mount_path
コード例 #20
0
ファイル: test_quobyte.py プロジェクト: fabian4/nova
    def test_quobyte_is_valid_volume_vol_not_valid_volume(self, mock_execute):
        mnt_base = '/mnt'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))

        self.assertRaises(exception.NovaException,
                          quobyte.validate_volume,
                          export_mnt_base)
コード例 #21
0
ファイル: test_quobyte.py プロジェクト: wenlongwljs/nova
    def test_quobyte_mount_volume(self, mock_execute, mock_ensure_tree):
        mnt_base = "/mnt"
        quobyte_volume = "192.168.1.1/volume-00001"
        export_mnt_base = os.path.join(mnt_base, utils.get_hash_str(quobyte_volume))

        quobyte.mount_volume(quobyte_volume, export_mnt_base)

        mock_ensure_tree.assert_called_once_with(export_mnt_base)
        expected_commands = [mock.call("mount.quobyte", quobyte_volume, export_mnt_base, check_exit_code=[0, 4])]
        mock_execute.assert_has_calls(expected_commands)
コード例 #22
0
ファイル: test_quobyte.py プロジェクト: fabian4/nova
    def test_quobyte_mount_volume_fails(self, mock_execute, mock_ensure_tree):
        mnt_base = '/mnt'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))

        self.assertRaises(processutils.ProcessExecutionError,
                          quobyte.mount_volume,
                          quobyte_volume,
                          export_mnt_base)
コード例 #23
0
ファイル: test_quobyte.py プロジェクト: mahak/nova
    def test_quobyte_umount_volume_sysd(self, mock_lv_umount):
        mnt_base = '/mnt'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))
        quobyte._is_systemd = True

        quobyte.umount_volume(export_mnt_base)

        mock_lv_umount.assert_called_once_with(export_mnt_base)
コード例 #24
0
ファイル: test_quobyte.py プロジェクト: mahak/nova
 def test_quobyte_mount_volume_fails(self, mock_mount, mock_ensure_tree):
     mnt_base = '/mnt'
     quobyte_volume = '192.168.1.1/volume-00001'
     export_mnt_base = os.path.join(mnt_base,
                                    utils.get_hash_str(quobyte_volume))
     quobyte._is_systemd = False
     self.assertRaises(processutils.ProcessExecutionError,
                       quobyte.mount_volume,
                       quobyte_volume,
                       export_mnt_base)
     mock_ensure_tree.assert_called_once_with(export_mnt_base)
コード例 #25
0
ファイル: api.py プロジェクト: yuyanshuo/nova
def get_file_extension_for_os_type(os_type, specified_fs=None):
    mkfs_command = _MKFS_COMMAND.get(os_type, _DEFAULT_MKFS_COMMAND)
    if mkfs_command:
        extension = mkfs_command
    else:
        if not specified_fs:
            specified_fs = CONF.default_ephemeral_format
            if not specified_fs:
                specified_fs = _DEFAULT_FS_BY_OSTYPE.get(os_type, _DEFAULT_FILE_SYSTEM)
        extension = specified_fs
    return utils.get_hash_str(extension)[:7]
コード例 #26
0
ファイル: volume.py プロジェクト: EliseCheng/nova
    def get_config(self, connection_info, disk_info):
        """Returns xml for libvirt."""
        conf = super(LibvirtNFSVolumeDriver,
                     self).get_config(connection_info, disk_info)

        path = os.path.join(CONF.libvirt.nfs_mount_point_base,
            utils.get_hash_str(connection_info['data']['export']))
        path = os.path.join(path, connection_info['data']['name'])
        conf.source_type = 'file'
        conf.source_path = path
        conf.driver_format = connection_info['data'].get('format', 'raw')
        return conf
コード例 #27
0
ファイル: test_vzstorage.py プロジェクト: cyx1231st/nova
    def test_libvirt_vzstorage_driver_get_config(self):
        libvirt_driver = vzstorage.LibvirtVZStorageVolumeDriver(self.fake_conn)
        export_string = "vzstorage"
        export_mnt_base = os.path.join(self.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, "device_path": file_path}}
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        self.assertEqual("file", conf.source_type)
        self.assertEqual(file_path, conf.source_path)
        self.assertEqual("raw", conf.driver_format)
        self.assertEqual("writethrough", conf.driver_cache)
コード例 #28
0
ファイル: test_quobyte.py プロジェクト: fabian4/nova
    def test_quobyte_is_valid_volume(self, mock_execute, mock_access):
        mnt_base = '/mnt'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))

        quobyte.validate_volume(export_mnt_base)

        mock_execute.assert_called_once_with('getfattr',
                                             '-n',
                                             'quobyte.info',
                                             export_mnt_base)
コード例 #29
0
ファイル: test_smbfs.py プロジェクト: 375670450/nova
    def test_libvirt_smbfs_driver_get_config(self):
        libvirt_driver = smbfs.LibvirtSMBFSVolumeDriver(self.fake_conn)
        export_string = '//192.168.1.1/volumes'
        export_mnt_base = os.path.join(self.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,
                                    'device_path': file_path}}
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()
        self._assertFileTypeEquals(tree, file_path)
コード例 #30
0
ファイル: volume.py プロジェクト: kbijon/OpenStack-CVRM
    def disconnect_volume(self, connection_info, disk_dev):
        """Disconnect the volume."""

        export = connection_info["data"]["export"]
        mount_path = os.path.join(CONF.libvirt.nfs_mount_point_base, utils.get_hash_str(export))

        try:
            utils.execute("umount", mount_path, run_as_root=True)
        except processutils.ProcessExecutionError as exc:
            if "target is busy" in exc.message:
                LOG.debug(_("The NFS share %s is still in use."), export)
            else:
                LOG.exception(_("Couldn't unmount the NFS share %s"), export)
コード例 #31
0
ファイル: volume.py プロジェクト: yatinkumbhare/nova
    def disconnect_volume(self, connection_info, disk_dev):
        """Disconnect the volume."""

        export = connection_info['data']['export']
        mount_path = os.path.join(CONF.libvirt.nfs_mount_point_base,
                                  utils.get_hash_str(export))

        try:
            utils.execute('umount', mount_path, run_as_root=True)
        except processutils.ProcessExecutionError as exc:
            if ('device is busy' in exc.message
                    or 'target is busy' in exc.message):
                LOG.debug("The NFS share %s is still in use.", export)
            else:
                LOG.exception(_LE("Couldn't unmount the NFS share %s"), export)
コード例 #32
0
    def test_libvirt_vzstorage_driver_get_config(self):
        libvirt_driver = vzstorage.LibvirtVZStorageVolumeDriver(self.fake_host)
        export_string = 'vzstorage'
        export_mnt_base = os.path.join(self.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,
                                    'device_path': file_path}}
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        self.assertEqual('file', conf.source_type)
        self.assertEqual(file_path, conf.source_path)
        self.assertEqual('raw', conf.driver_format)
        self.assertEqual('writeback', conf.driver_cache)
コード例 #33
0
    def test_quobyte_mount_volume(self, mock_execute, mock_ensure_tree):
        mnt_base = '/mnt'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))

        quobyte.mount_volume(quobyte_volume, export_mnt_base)

        mock_ensure_tree.assert_called_once_with(export_mnt_base)
        expected_commands = [mock.call('mount.quobyte',
                                       quobyte_volume,
                                       export_mnt_base,
                                       check_exit_code=[0, 4])
                             ]
        mock_execute.assert_has_calls(expected_commands)
コード例 #34
0
    def test_quobyte_mount_volume_systemd(self, mock_execute, mock_ensure_tree,
                                          mock_exists):
        mnt_base = '/mnt'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))

        quobyte.mount_volume(quobyte_volume, export_mnt_base)

        mock_ensure_tree.assert_called_once_with(export_mnt_base)
        expected_commands = [
            mock.call('systemd-run', '--scope', '--user', 'mount.quobyte',
                      '--disable-xattrs', quobyte_volume, export_mnt_base)
        ]
        mock_execute.assert_has_calls(expected_commands)
        mock_exists.assert_called_once_with(" /run/systemd/system")
コード例 #35
0
    def test_libvirt_smbfs_driver_already_mounted(self, mock_is_mounted):
        libvirt_driver = smbfs.LibvirtSMBFSVolumeDriver(self.fake_host)
        export_string = '//192.168.1.1/volumes'
        export_mnt_base = os.path.join(self.mnt_base,
                                       utils.get_hash_str(export_string))
        connection_info = {'data': {'export': export_string,
                                    'name': self.name}}

        libvirt_driver.connect_volume(connection_info, self.disk_info,
                                      mock.sentinel.instance)
        libvirt_driver.disconnect_volume(connection_info, "vde",
                                         mock.sentinel.instance)

        expected_commands = [
            ('umount', export_mnt_base)]
        self.assertEqual(expected_commands, self.executes)
コード例 #36
0
    def test_libvirt_nfs_driver_already_mounted(self):
        libvirt_driver = nfs.LibvirtNFSVolumeDriver(self.fake_conn)

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

        connection_info = {'data': {'export': export_string,
                                    'name': self.name}}
        libvirt_driver.connect_volume(connection_info, self.disk_info)
        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)
コード例 #37
0
    def test_libvirt_smbfs_driver_get_config(self):
        libvirt_driver = smbfs.LibvirtSMBFSVolumeDriver(self.fake_host)
        export_string = '//192.168.1.1/volumes'
        export_mnt_base = os.path.join(self.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,
                'device_path': file_path
            }
        }
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()
        self._assertFileTypeEquals(tree, file_path)
コード例 #38
0
    def test_quobyte_umount_volume_warns(self, mock_execute, mock_debug):
        mnt_base = '/mnt'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))

        def exec_side_effect(*cmd, **kwargs):
            exerror = processutils.ProcessExecutionError(
                "Device or resource busy")
            raise exerror

        mock_execute.side_effect = exec_side_effect

        quobyte.umount_volume(export_mnt_base)

        (mock_debug.assert_called_once_with(
            "The Quobyte volume at %s is still in use.", export_mnt_base))
コード例 #39
0
    def test_quobyte_mount_volume_with_config(self, mock_execute,
                                              mock_ensure_tree, mock_exists):
        mnt_base = '/mnt'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))
        config_file_dummy = "/etc/quobyte/dummy.conf"

        quobyte.mount_volume(quobyte_volume, export_mnt_base,
                             config_file_dummy)

        mock_ensure_tree.assert_called_once_with(export_mnt_base)
        expected_commands = [
            mock.call('mount.quobyte', '--disable-xattrs', quobyte_volume,
                      export_mnt_base, '-c', config_file_dummy)
        ]
        mock_execute.assert_has_calls(expected_commands)
        mock_exists.assert_called_once_with(" /run/systemd/system")
コード例 #40
0
    def test_libvirt_nfs_driver_get_config(self):
        libvirt_driver = nfs.LibvirtNFSVolumeDriver(self.fake_conn)
        export_string = '192.168.1.1:/nfs/share1'
        export_mnt_base = os.path.join(self.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,
                'device_path': file_path
            }
        }
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()
        self._assertFileTypeEquals(tree, file_path)
        self.assertEqual('raw', tree.find('./driver').get('type'))
コード例 #41
0
ファイル: s3server.py プロジェクト: mnaser/nova-1
 def put(self, bucket, object_name):
     object_name = urllib.unquote(object_name)
     bucket_dir = os.path.abspath(
         os.path.join(self.application.directory, bucket))
     if (not bucket_dir.startswith(self.application.directory)
             or not os.path.isdir(bucket_dir)):
         self.set_404()
         return
     path = self._object_path(bucket, object_name)
     if not path.startswith(bucket_dir) or os.path.isdir(path):
         self.set_status(403)
         return
     directory = os.path.dirname(path)
     fileutils.ensure_tree(directory)
     with open(path, "w") as object_file:
         object_file.write(self.request.body)
     self.set_header('ETag', '"%s"' % utils.get_hash_str(self.request.body))
     self.finish()
コード例 #42
0
    def test_libvirt_smbfs_driver_already_mounted(self, mock_umount,
                                                  mock_is_mounted):
        libvirt_driver = smbfs.LibvirtSMBFSVolumeDriver(self.fake_host)
        export_string = '//192.168.1.1/volumes'
        export_mnt_base = os.path.join(self.mnt_base,
                                       utils.get_hash_str(export_string))
        connection_info = {
            'data': {
                'export': export_string,
                'name': self.name
            }
        }

        libvirt_driver.connect_volume(connection_info, mock.sentinel.instance)
        libvirt_driver.disconnect_volume(connection_info,
                                         mock.sentinel.instance)

        mock_umount.assert_has_calls([mock.call(export_mnt_base)])
コード例 #43
0
    def disconnect_volume(self, connection_info, disk_dev):
        """Disconnect the volume."""

        if 'gluster' in CONF.libvirt.qemu_allowed_storage_drivers:
            return

        export = connection_info['data']['export']
        mount_path = os.path.join(CONF.libvirt.glusterfs_mount_point_base,
                                  utils.get_hash_str(export))

        try:
            utils.execute('umount', mount_path, run_as_root=True)
        except processutils.ProcessExecutionError as exc:
            if 'target is busy' in exc.message:
                LOG.debug("The GlusterFS share %s is still in use.", export)
            else:
                LOG.exception(_LE("Couldn't unmount the GlusterFS share %s"),
                              export)
コード例 #44
0
    def test_libvirt_glusterfs_driver_already_mounted(self):
        mnt_base = '/mnt'
        self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = glusterfs.LibvirtGlusterfsVolumeDriver(self.fake_conn)
        export_string = '192.168.1.1:/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                utils.get_hash_str(export_string))

        connection_info = {'data': {'export': export_string,
                                    'name': self.name}}
        libvirt_driver.connect_volume(connection_info, self.disk_info)
        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)
コード例 #45
0
ファイル: test_smbfs.py プロジェクト: bopopescu/nova-16
    def test_libvirt_smbfs_driver(self, mock_is_mounted):
        mock_is_mounted.return_value = False

        libvirt_driver = smbfs.LibvirtSMBFSVolumeDriver(self.fake_host)
        export_string = '//192.168.1.1/volumes'
        export_mnt_base = os.path.join(self.mnt_base,
                                       utils.get_hash_str(export_string))
        connection_info = {'data': {'export': export_string,
                                    'name': self.name,
                                    'options': None}}
        libvirt_driver.connect_volume(connection_info, self.disk_info)
        libvirt_driver.disconnect_volume(connection_info, "vde")

        expected_commands = [
            ('mkdir', '-p', export_mnt_base),
            ('mount', '-t', 'cifs', '-o', 'username=guest',
             export_string, export_mnt_base),
            ('umount', export_mnt_base)]
        self.assertEqual(expected_commands, self.executes)
コード例 #46
0
ファイル: test_glusterfs.py プロジェクト: tjjh89017/nova
    def test_libvirt_glusterfs_driver_already_mounted(self, mock_is_mounted):
        mnt_base = '/mnt'
        self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = glusterfs.LibvirtGlusterfsVolumeDriver(self.fake_host)
        export_string = '192.168.1.1:/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                utils.get_hash_str(export_string))

        connection_info = {'data': {'export': export_string,
                                    'name': self.name}}
        libvirt_driver.connect_volume(connection_info, self.disk_info,
                                      mock.sentinel.instance)
        libvirt_driver.disconnect_volume(connection_info, "vde",
                                         mock.sentinel.instance)

        expected_commands = [
            ('umount', export_mnt_base)]
        self.assertEqual(expected_commands, self.executes)
コード例 #47
0
    def _get_mount_path(self, connection_info):
        """Returns the mount path prefix using the mount point base and share.

        :param connection_info: dict of the form

        ::

          connection_info = {
              'data': {
                  'export': the file system share,
                  ...
              }
              ...
          }

        :returns: The mount path prefix.
        """
        share = self._normalize_export(connection_info['data']['export'])
        return os.path.join(self._get_mount_point_base(),
                            utils.get_hash_str(share))
コード例 #48
0
    def test_libvirt_nfs_driver_with_opts(self):
        libvirt_driver = nfs.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(self.mnt_base,
                utils.get_hash_str(export_string))

        connection_info = {'data': {'export': export_string,
                                    'name': self.name,
                                    'options': options}}
        libvirt_driver.connect_volume(connection_info, self.disk_info)
        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)
コード例 #49
0
    def test_libvirt_nfs_driver(self):
        libvirt_driver = nfs.LibvirtNFSVolumeDriver(self.fake_conn)
        self.stubs.Set(libvirt_utils, 'is_mounted', lambda x, d: False)

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

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

        device_path = os.path.join(export_mnt_base,
                                   connection_info['data']['name'])
        self.assertEqual(device_path, connection_info['data']['device_path'])
        expected_commands = [
            ('mkdir', '-p', export_mnt_base),
            ('mount', '-t', 'nfs', export_string, export_mnt_base),
            ('umount', export_mnt_base)]
        self.assertEqual(expected_commands, self.executes)
コード例 #50
0
    def test_libvirt_quobyte_driver_qcow2(self, mock_mount_volume,
                                          mock_validate_volume, mock_umount):
        mnt_base = '/mnt'
        self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')
        libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_host)
        export_string = 'quobyte://192.168.1.1/volume-00001'
        name = 'volume-00001'
        image_format = 'qcow2'
        quobyte_volume = '192.168.1.1/volume-00001'

        connection_info = {
            'data': {
                'export': export_string,
                'name': name,
                'format': image_format
            }
        }

        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))
        mock_validate_volume.side_effect = [
            nova_exception.StaleVolumeMount("This shall fail."), True, True
        ]

        libvirt_driver.connect_volume(connection_info, mock.sentinel.instance)
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()
        self.assertEqual('file', tree.get('type'))
        self.assertEqual('qcow2', tree.find('./driver').get('type'))

        (mock_mount_volume.assert_called_once_with('192.168.1.1/volume-00001',
                                                   export_mnt_base, mock.ANY))
        mock_validate_volume.assert_called_with(export_mnt_base)

        libvirt_driver.disconnect_volume(connection_info,
                                         mock.sentinel.instance)
        mock_umount.assert_has_calls(
            [mock.call(export_mnt_base),
             mock.call(export_mnt_base)])
コード例 #51
0
    def test_libvirt_glusterfs_driver(self):
        mnt_base = '/mnt'
        self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = volume.LibvirtGlusterfsVolumeDriver(self.fake_conn)
        export_string = '192.168.1.1:/volume-00001'
        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 = [
            ('mkdir', '-p', export_mnt_base),
            ('mount', '-t', 'glusterfs', export_string, export_mnt_base),
            ('umount', export_mnt_base)]
        self.assertEqual(expected_commands, self.executes)
コード例 #52
0
ファイル: test_volume.py プロジェクト: nuistchh/nova
    def test_libvirt_glusterfs_driver_get_config(self):
        mnt_base = '/mnt'
        self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt')

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

        # Test default format - raw
        connection_info = {
            'data': {
                'export': export_string,
                'name': self.name,
                'device_path': file_path
            }
        }
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()
        self._assertFileTypeEquals(tree, file_path)
        self.assertEqual('raw', tree.find('./driver').get('type'))

        # Test specified format - qcow2
        connection_info = {
            'data': {
                'export': export_string,
                'name': self.name,
                'device_path': file_path,
                'format': 'qcow2'
            }
        }
        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()
        self._assertFileTypeEquals(tree, file_path)
        self.assertEqual('qcow2', tree.find('./driver').get('type'))
コード例 #53
0
    def test_libvirt_quobyte_driver_mount(self, mock_is_mounted,
                                          mock_mount_volume,
                                          mock_validate_volume,
                                          mock_umount_volume):
        mnt_base = '/mnt'
        self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_host)
        export_string = 'quobyte://192.168.1.1/volume-00001'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))
        file_path = os.path.join(export_mnt_base, self.name)

        connection_info = {
            'data': {
                'export': export_string,
                'name': self.name
            }
        }
        mock_validate_volume.side_effect = [
            nova_exception.StaleVolumeMount("This shall fail."), True, True
        ]

        libvirt_driver.connect_volume(connection_info, mock.sentinel.instance)

        conf = libvirt_driver.get_config(connection_info, self.disk_info)
        tree = conf.format_dom()

        self._assertFileTypeEquals(tree, file_path)

        mock_mount_volume.assert_called_once_with(quobyte_volume,
                                                  export_mnt_base, mock.ANY)
        mock_validate_volume.assert_called_with(export_mnt_base)
        mock_umount_volume.assert_called_once_with(
            libvirt_driver._get_mount_path(connection_info))
コード例 #54
0
    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)
コード例 #55
0
    def test_libvirt_quobyte_driver_already_mounted(self, mock_umount_volume,
                                                    mock_validate_volume):
        mnt_base = '/mnt'
        self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')

        libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_conn)
        export_string = 'quobyte://192.168.1.1/volume-00001'
        quobyte_volume = '192.168.1.1/volume-00001'
        export_mnt_base = os.path.join(mnt_base,
                                       utils.get_hash_str(quobyte_volume))
        file_path = os.path.join(export_mnt_base, self.name)

        connection_info = {
            'data': {
                'export': export_string,
                'name': self.name
            }
        }

        libvirt_driver.connect_volume(connection_info, self.disk_info)

        conf = libvirt_driver.get_config(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',
             "quobyte@" + quobyte_volume),
            ('findmnt', '--target', export_mnt_base, '--source',
             "quobyte@" + quobyte_volume),
        ]
        self.assertEqual(expected_commands, self.executes)

        mock_umount_volume.assert_called_once_with(export_mnt_base)
        mock_validate_volume.assert_called_once_with(export_mnt_base)
コード例 #56
0
class APITestCase(test.NoDBTestCase):
    def test_can_resize_need_fs_type_specified(self):
        # NOTE(mikal): Bug 1094373 saw a regression where we failed to
        # treat a failure to mount as a failure to be able to resize the
        # filesystem
        def _fake_get_disk_size(path):
            return 10

        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.api.get_disk_size',
                                 _fake_get_disk_size))

        def fake_trycmd(*args, **kwargs):
            return '', 'broken'

        self.useFixture(fixtures.MonkeyPatch('nova.utils.trycmd', fake_trycmd))

        def fake_returns_true(*args, **kwargs):
            return True

        def fake_returns_nothing(*args, **kwargs):
            return ''

        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.mount.nbd.NbdMount.get_dev',
                                 fake_returns_true))
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.mount.nbd.NbdMount.map_dev',
                                 fake_returns_true))
        self.useFixture(
            fixtures.MonkeyPatch(
                'nova.virt.disk.vfs.localfs.VFSLocalFS.get_image_fs',
                fake_returns_nothing))

        # Force the use of localfs, which is what was used during the failure
        # reported in the bug
        def fake_import_fails(*args, **kwargs):
            raise Exception('Failed')

        self.useFixture(
            fixtures.MonkeyPatch('oslo_utils.import_module',
                                 fake_import_fails))

        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)
        image = imgmodel.LocalFileImage(imgfile.name, imgmodel.FORMAT_QCOW2)
        self.assertFalse(api.is_image_extendable(image))

    def test_is_image_extendable_raw(self):
        imgfile = tempfile.NamedTemporaryFile()

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('e2label', imgfile)
        self.mox.ReplayAll()

        image = imgmodel.LocalFileImage(imgfile, imgmodel.FORMAT_RAW)
        self.addCleanup(imgfile.close)
        self.assertTrue(api.is_image_extendable(image))

    def test_resize2fs_success(self):
        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('e2fsck',
                      '-fp',
                      imgfile,
                      check_exit_code=[0, 1, 2],
                      run_as_root=False)
        utils.execute('resize2fs',
                      imgfile,
                      check_exit_code=False,
                      run_as_root=False)

        self.mox.ReplayAll()
        api.resize2fs(imgfile)

    def test_resize2fs_e2fsck_fails(self):
        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('e2fsck',
                      '-fp',
                      imgfile,
                      check_exit_code=[0, 1, 2],
                      run_as_root=False).AndRaise(
                          processutils.ProcessExecutionError("fs error"))
        self.mox.ReplayAll()
        api.resize2fs(imgfile)

    def test_extend_qcow_success(self):
        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)
        imgsize = 10
        device = "/dev/sdh"
        image = imgmodel.LocalFileImage(imgfile, imgmodel.FORMAT_QCOW2)

        self.flags(resize_fs_using_block_device=True)
        mounter = FakeMount.instance_for_format(image, None, None)
        mounter.device = device

        self.mox.StubOutWithMock(api, 'can_resize_image')
        self.mox.StubOutWithMock(utils, 'execute')
        self.mox.StubOutWithMock(api, 'is_image_extendable')
        self.mox.StubOutWithMock(mounter, 'get_dev')
        self.mox.StubOutWithMock(mounter, 'unget_dev')
        self.mox.StubOutWithMock(api, 'resize2fs')
        self.mox.StubOutWithMock(mount.Mount,
                                 'instance_for_format',
                                 use_mock_anything=True)

        api.can_resize_image(imgfile, imgsize).AndReturn(True)
        utils.execute('qemu-img', 'resize', imgfile, imgsize)
        api.is_image_extendable(image).AndReturn(True)
        mount.Mount.instance_for_format(image, None, None).AndReturn(mounter)
        mounter.get_dev().AndReturn(True)
        api.resize2fs(mounter.device, run_as_root=True, check_exit_code=[0])
        mounter.unget_dev()

        self.mox.ReplayAll()
        api.extend(image, imgsize)

    @mock.patch.object(api, 'can_resize_image', return_value=True)
    @mock.patch.object(api, 'is_image_extendable')
    @mock.patch.object(utils, 'execute')
    def test_extend_qcow_no_resize(self, mock_execute, mock_extendable,
                                   mock_can_resize_image):
        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)
        imgsize = 10
        image = imgmodel.LocalFileImage(imgfile, imgmodel.FORMAT_QCOW2)

        self.flags(resize_fs_using_block_device=False)

        api.extend(image, imgsize)

        mock_can_resize_image.assert_called_once_with(imgfile, imgsize)
        mock_execute.assert_called_once_with('qemu-img', 'resize', imgfile,
                                             imgsize)
        self.assertFalse(mock_extendable.called)

    def test_extend_raw_success(self):
        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)
        imgsize = 10
        image = imgmodel.LocalFileImage(imgfile, imgmodel.FORMAT_RAW)

        self.mox.StubOutWithMock(api, 'can_resize_image')
        self.mox.StubOutWithMock(utils, 'execute')
        self.mox.StubOutWithMock(api, 'resize2fs')

        api.can_resize_image(imgfile, imgsize).AndReturn(True)
        utils.execute('qemu-img', 'resize', imgfile, imgsize)
        utils.execute('e2label', image.path)
        api.resize2fs(imgfile, run_as_root=False, check_exit_code=[0])

        self.mox.ReplayAll()
        api.extend(image, imgsize)

    HASH_VFAT = utils.get_hash_str(api.FS_FORMAT_VFAT)[:7]
    HASH_EXT4 = utils.get_hash_str(api.FS_FORMAT_EXT4)[:7]
    HASH_NTFS = utils.get_hash_str(api.FS_FORMAT_NTFS)[:7]

    def test_get_file_extension_for_os_type(self):
        self.assertEqual(self.HASH_VFAT,
                         api.get_file_extension_for_os_type(None, None))
        self.assertEqual(self.HASH_EXT4,
                         api.get_file_extension_for_os_type('linux', None))
        self.assertEqual(self.HASH_NTFS,
                         api.get_file_extension_for_os_type('windows', None))

    def test_get_file_extension_for_os_type_with_overrides(self):
        with mock.patch('nova.virt.disk.api._DEFAULT_MKFS_COMMAND',
                        'custom mkfs command'):
            self.assertEqual("a74d253",
                             api.get_file_extension_for_os_type('linux', None))
            self.assertEqual(
                "a74d253", api.get_file_extension_for_os_type('windows', None))
            self.assertEqual("a74d253",
                             api.get_file_extension_for_os_type('osx', None))

        with mock.patch.dict(api._MKFS_COMMAND, {'osx': 'custom mkfs command'},
                             clear=True):
            self.assertEqual(self.HASH_VFAT,
                             api.get_file_extension_for_os_type(None, None))
            self.assertEqual(self.HASH_EXT4,
                             api.get_file_extension_for_os_type('linux', None))
            self.assertEqual(
                self.HASH_NTFS,
                api.get_file_extension_for_os_type('windows', None))
            self.assertEqual("a74d253",
                             api.get_file_extension_for_os_type('osx', None))
コード例 #57
0
ファイル: test_utils.py プロジェクト: gweuieon/nova
 def test_get_hash_str(self):
     base_str = "foo"
     value = hashlib.md5(base_str).hexdigest()
     self.assertEqual(value, utils.get_hash_str(base_str))
コード例 #58
0
ファイル: test_api.py プロジェクト: bralike/zero
class APITestCase(test.NoDBTestCase):
    def test_can_resize_need_fs_type_specified(self):
        # Downstream-only skip
        # This test fails when libguestfs is available in the unit test
        # environment.
        # This can be trivially made to pass by passing imgfile.name instead of
        # imgfile to api.is_image_extendable. However, it needs a significant
        # rework to be meaningful. We're skipping it for the moment.
        self.skipTest("Fails when libguestfs is available")

        # NOTE(mikal): Bug 1094373 saw a regression where we failed to
        # treat a failure to mount as a failure to be able to resize the
        # filesystem
        def _fake_get_disk_size(path):
            return 10

        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.api.get_disk_size',
                                 _fake_get_disk_size))

        def fake_trycmd(*args, **kwargs):
            return '', 'broken'

        self.useFixture(fixtures.MonkeyPatch('nova.utils.trycmd', fake_trycmd))

        def fake_returns_true(*args, **kwargs):
            return True

        def fake_returns_nothing(*args, **kwargs):
            return ''

        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.mount.nbd.NbdMount.get_dev',
                                 fake_returns_true))
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.disk.mount.nbd.NbdMount.map_dev',
                                 fake_returns_true))
        self.useFixture(
            fixtures.MonkeyPatch(
                'nova.virt.disk.vfs.localfs.VFSLocalFS.get_image_fs',
                fake_returns_nothing))

        # Force the use of localfs, which is what was used during the failure
        # reported in the bug
        def fake_import_fails(*args, **kwargs):
            raise Exception('Failed')

        self.useFixture(
            fixtures.MonkeyPatch('oslo.utils.import_module',
                                 fake_import_fails))

        imgfile = tempfile.NamedTemporaryFile()
        self.addCleanup(imgfile.close)
        self.assertFalse(api.is_image_extendable(imgfile, use_cow=True))

    def test_resize2fs_success(self):
        imgfile = tempfile.NamedTemporaryFile()

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('e2fsck',
                      '-fp',
                      imgfile,
                      check_exit_code=[0, 1, 2],
                      run_as_root=False)
        utils.execute('resize2fs',
                      imgfile,
                      check_exit_code=False,
                      run_as_root=False)

        self.mox.ReplayAll()
        api.resize2fs(imgfile)

    def test_resize2fs_e2fsck_fails(self):
        imgfile = tempfile.NamedTemporaryFile()

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('e2fsck',
                      '-fp',
                      imgfile,
                      check_exit_code=[0, 1, 2],
                      run_as_root=False).AndRaise(
                          processutils.ProcessExecutionError("fs error"))
        self.mox.ReplayAll()
        api.resize2fs(imgfile)

    def test_extend_qcow_success(self):
        imgfile = tempfile.NamedTemporaryFile()
        imgsize = 10
        device = "/dev/sdh"
        use_cow = True

        self.flags(resize_fs_using_block_device=True)
        mounter = FakeMount.instance_for_format(imgfile, None, None, 'qcow2')
        mounter.device = device

        self.mox.StubOutWithMock(api, 'can_resize_image')
        self.mox.StubOutWithMock(utils, 'execute')
        self.mox.StubOutWithMock(api, 'is_image_extendable')
        self.mox.StubOutWithMock(mounter, 'get_dev')
        self.mox.StubOutWithMock(mounter, 'unget_dev')
        self.mox.StubOutWithMock(api, 'resize2fs')
        self.mox.StubOutWithMock(mount.Mount,
                                 'instance_for_format',
                                 use_mock_anything=True)

        api.can_resize_image(imgfile, imgsize).AndReturn(True)
        utils.execute('qemu-img', 'resize', imgfile, imgsize)
        api.is_image_extendable(imgfile, use_cow).AndReturn(True)
        mount.Mount.instance_for_format(imgfile, None, None,
                                        'qcow2').AndReturn(mounter)
        mounter.get_dev().AndReturn(True)
        api.resize2fs(mounter.device, run_as_root=True, check_exit_code=[0])
        mounter.unget_dev()

        self.mox.ReplayAll()
        api.extend(imgfile, imgsize, use_cow=use_cow)

    def test_extend_raw_success(self):
        imgfile = tempfile.NamedTemporaryFile()
        imgsize = 10
        use_cow = False

        self.mox.StubOutWithMock(api, 'can_resize_image')
        self.mox.StubOutWithMock(utils, 'execute')
        self.mox.StubOutWithMock(api, 'is_image_extendable')
        self.mox.StubOutWithMock(api, 'resize2fs')

        api.can_resize_image(imgfile, imgsize).AndReturn(True)
        utils.execute('qemu-img', 'resize', imgfile, imgsize)
        api.is_image_extendable(imgfile, use_cow).AndReturn(True)
        api.resize2fs(imgfile, run_as_root=False, check_exit_code=[0])

        self.mox.ReplayAll()
        api.extend(imgfile, imgsize, use_cow=use_cow)

    HASH_VFAT = utils.get_hash_str(api.FS_FORMAT_VFAT)[:7]
    HASH_EXT4 = utils.get_hash_str(api.FS_FORMAT_EXT4)[:7]
    HASH_NTFS = utils.get_hash_str(api.FS_FORMAT_NTFS)[:7]

    def test_get_file_extension_for_os_type(self):
        self.assertEqual(self.HASH_VFAT,
                         api.get_file_extension_for_os_type(None, None))
        self.assertEqual(self.HASH_EXT4,
                         api.get_file_extension_for_os_type('linux', None))
        self.assertEqual(self.HASH_NTFS,
                         api.get_file_extension_for_os_type('windows', None))

    def test_get_file_extension_for_os_type_with_overrides(self):
        with mock.patch('nova.virt.disk.api._DEFAULT_MKFS_COMMAND',
                        'custom mkfs command'):
            self.assertEqual("a74d253",
                             api.get_file_extension_for_os_type('linux', None))
            self.assertEqual(
                "a74d253", api.get_file_extension_for_os_type('windows', None))
            self.assertEqual("a74d253",
                             api.get_file_extension_for_os_type('osx', None))

        with mock.patch.dict(api._MKFS_COMMAND, {'osx': 'custom mkfs command'},
                             clear=True):
            self.assertEqual(self.HASH_VFAT,
                             api.get_file_extension_for_os_type(None, None))
            self.assertEqual(self.HASH_EXT4,
                             api.get_file_extension_for_os_type('linux', None))
            self.assertEqual(
                self.HASH_NTFS,
                api.get_file_extension_for_os_type('windows', None))
            self.assertEqual("a74d253",
                             api.get_file_extension_for_os_type('osx', None))
コード例 #59
0
 def _get_mount_path(self, smbfs_share):
     mount_path = os.path.join(CONF.libvirt.smbfs_mount_point_base,
                               utils.get_hash_str(smbfs_share))
     return mount_path
コード例 #60
0
 def _get_device_path(self, connection_info):
     path = os.path.join(CONF.libvirt.glusterfs_mount_point_base,
         utils.get_hash_str(connection_info['data']['export']))
     path = os.path.join(path, connection_info['data']['name'])
     return path