def test_is_mounted(self): mount_path = "/var/lib/nova/mnt" source = "192.168.0.1:/nova" proc_with_mnt = """/dev/sda3 / xfs rw,seclabel,attr2,inode64 0 0 tmpfs /tmp tmpfs rw,seclabel 0 0 hugetlbfs /dev/hugepages hugetlbfs rw,seclabel,relatime 0 0 mqueue /dev/mqueue mqueue rw,seclabel,relatime 0 0 debugfs /sys/kernel/debug debugfs rw,seclabel,relatime 0 0 nfsd /proc/fs/nfsd nfsd rw,relatime 0 0 /dev/sda1 /boot ext4 rw,seclabel,relatime,data=ordered 0 0 sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0 192.168.0.1:/nova /var/lib/nova/mnt nfs4 rw,relatime,vers=4.1 """ proc_wrong_mnt = """/dev/sda3 / xfs rw,seclabel,attr2,inode64 0 0 tmpfs /tmp tmpfs rw,seclabel 0 0 hugetlbfs /dev/hugepages hugetlbfs rw,seclabel,relatime 0 0 mqueue /dev/mqueue mqueue rw,seclabel,relatime 0 0 debugfs /sys/kernel/debug debugfs rw,seclabel,relatime 0 0 nfsd /proc/fs/nfsd nfsd rw,relatime 0 0 /dev/sda1 /boot ext4 rw,seclabel,relatime,data=ordered 0 0 sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0 192.168.0.2:/nova /var/lib/nova/mnt nfs4 rw,relatime,vers=4.1 """ proc_without_mnt = """/dev/sda3 / xfs rw,seclabel,,attr2,inode64 0 0 tmpfs /tmp tmpfs rw,seclabel 0 0 hugetlbfs /dev/hugepages hugetlbfs rw,seclabel,relatime 0 0 mqueue /dev/mqueue mqueue rw,seclabel,relatime 0 0 debugfs /sys/kernel/debug debugfs rw,seclabel,relatime 0 0 nfsd /proc/fs/nfsd nfsd rw,relatime 0 0 /dev/sda1 /boot ext4 rw,seclabel,relatime,data=ordered 0 0 sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0 """ with mock.patch.object(os.path, 'ismount') as mock_ismount: # is_mounted(mount_path) with no source is equivalent to # os.path.ismount(mount_path) mock_ismount.return_value = False self.assertFalse(libvirt_utils.is_mounted(mount_path)) mock_ismount.return_value = True self.assertTrue(libvirt_utils.is_mounted(mount_path)) # Source is given, and matches source in /proc/mounts proc_mnt = mock.mock_open(read_data=proc_with_mnt) with mock.patch.object(six.moves.builtins, "open", proc_mnt): self.assertTrue(libvirt_utils.is_mounted(mount_path, source)) # Source is given, and doesn't match source in /proc/mounts proc_mnt = mock.mock_open(read_data=proc_wrong_mnt) with mock.patch.object(six.moves.builtins, "open", proc_mnt): self.assertFalse(libvirt_utils.is_mounted(mount_path, source)) # Source is given, and mountpoint isn't present in /proc/mounts # Note that this shouldn't occur, as os.path.ismount should have # previously returned False in this case. proc_umnt = mock.mock_open(read_data=proc_without_mnt) with mock.patch.object(six.moves.builtins, "open", proc_umnt): self.assertFalse(libvirt_utils.is_mounted(mount_path, source))
def connect_volume(self, connection_info, instance): """Connect the volume.""" if is_systemd(): LOG.debug("systemd detected.") else: LOG.debug("No systemd detected.") data = connection_info['data'] quobyte_volume = self._normalize_export(data['export']) mount_path = self._get_mount_path(connection_info) mounted = libvirt_utils.is_mounted( mount_path, SOURCE_PROTOCOL + '@' + quobyte_volume) if mounted: try: os.stat(mount_path) except OSError as exc: if exc.errno == errno.ENOTCONN: mounted = False LOG.info( 'Fixing previous mount %s which was not' ' unmounted correctly.', mount_path) umount_volume(mount_path) if not mounted: mount_volume(quobyte_volume, mount_path, CONF.libvirt.quobyte_client_cfg) validate_volume(mount_path)
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
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)) if not libvirt_utils.is_mounted(mount_path, nfs_export): self._mount_nfs(mount_path, nfs_export, options, ensure=True) return mount_path
def _ensure_mounted(self, connection_info): """@type connection_info: dict """ nfs_export = connection_info["data"]["export"] mount_path = self._get_mount_path(connection_info) if not libvirt_utils.is_mounted(mount_path, nfs_export): options = connection_info["data"].get("options") self._mount_nfs(mount_path, nfs_export, options, ensure=True) return mount_path
def _ensure_mounted(self, connection_info): """@type connection_info: dict """ nfs_export = connection_info['data']['export'] mount_path = self._get_mount_path(connection_info) if not libvirt_utils.is_mounted(mount_path, nfs_export): options = connection_info['data'].get('options') self._mount_nfs(mount_path, nfs_export, options, ensure=True) return mount_path
def _ensure_mounted(self, connection_info): """@type connection_info: dict """ glusterfs_export = connection_info['data']['export'] mount_path = self._get_mount_path(connection_info) if not libvirt_utils.is_mounted(mount_path, glusterfs_export): options = connection_info['data'].get('options') self._mount_glusterfs(mount_path, glusterfs_export, options, ensure=True) return mount_path
def disconnect_volume(self, connection_info, disk_dev): """Disconnect the volume.""" quobyte_volume = self._normalize_url(connection_info['data']['export']) mount_path = self._get_mount_point_for_share(quobyte_volume) if libvirt_utils.is_mounted(mount_path, 'quobyte@' + quobyte_volume): umount_volume(mount_path) else: LOG.info(_LI("Trying to disconnected unmounted volume at %s"), mount_path)
def connect_volume(self, connection_info, disk_info): """Connect the volume.""" smbfs_share = connection_info['data']['export'] mount_path = self._get_mount_path(smbfs_share) if not libvirt_utils.is_mounted(mount_path, smbfs_share): mount_options = self._parse_mount_options(connection_info) remotefs.mount_share(mount_path, smbfs_share, export_type='cifs', options=mount_options) device_path = self._get_device_path(connection_info) connection_info['data']['device_path'] = device_path
def disconnect_volume(self, connection_info, instance): """Disconnect the volume.""" quobyte_volume = self._normalize_export( connection_info['data']['export']) mount_path = self._get_mount_path(connection_info) if libvirt_utils.is_mounted(mount_path, 'quobyte@' + quobyte_volume): umount_volume(mount_path) else: LOG.info("Trying to disconnected unmounted volume at %s", mount_path)
def connect_volume(self, connection_info, disk_info): """Connect the volume.""" data = connection_info['data'] quobyte_volume = self._normalize_url(data['export']) mount_path = self._get_mount_point_for_share(quobyte_volume) mounted = libvirt_utils.is_mounted( mount_path, SOURCE_PROTOCOL + '@' + quobyte_volume) if mounted: try: os.stat(mount_path) except OSError as exc: if exc.errno == errno.ENOTCONN: mounted = False LOG.info( _LI('Fixing previous mount %s which was not' ' unmounted correctly.'), mount_path) umount_volume(mount_path) if not mounted: mount_volume(quobyte_volume, mount_path, CONF.libvirt.quobyte_client_cfg) validate_volume(mount_path)
def connect_volume(self, connection_info, disk_info): """Connect the volume.""" data = connection_info['data'] quobyte_volume = self._normalize_export(data['export']) mount_path = self._get_mount_path(connection_info) mounted = libvirt_utils.is_mounted(mount_path, SOURCE_PROTOCOL + '@' + quobyte_volume) if mounted: try: os.stat(mount_path) except OSError as exc: if exc.errno == errno.ENOTCONN: mounted = False LOG.info(_LI('Fixing previous mount %s which was not' ' unmounted correctly.'), mount_path) umount_volume(mount_path) if not mounted: mount_volume(quobyte_volume, mount_path, CONF.libvirt.quobyte_client_cfg) validate_volume(mount_path)