def get_volume_object(self, context, volume_id): volume = self.cinder_db.get_cinder_volume(volume_id) LOG.debug("Finding if LUN for volume '%s' already exists", volume_id) masking = self.emc.populate_masking(volume) masking_view = self.emc.find_masking_view(masking) if not masking_view: self.emc.delete_volume_from_default_sg(masking) self.created_masking_view = self.emc.create_masking_view(masking) else: self.created_masking_view = masking_view props = self.emc.find_iscsi_connection_properties(masking) try: LOG.debug("Connecting iSCSI volume") self.iscsi.discover(props.target) block_device = self.iscsi.connect_volume(props.target, props.iqn, props.lun) self.connected_volume = props LOG.debug("Block device connected at %s", block_device) except (local.LocalExecutionFailed, iscsi.CannotConnectISCSIVolume): msg = "Unable to connect iSCSI volume '{}'".format(volume_id) LOG.warning(msg) raise base.VolumeObjectNotFoundError(msg) # TODO implicit dependency host = socket.gethostbyname(socket.gethostname()) return copy_mechanisms.CopyObject(host=host, path=block_device)
def get_volume_object(self, context, volume_id): """:raises: VolumeObjectNotFoundError in case object is not found""" controller = context.cloud_config.cloud.ssh_host user = context.cloud_config.cloud.ssh_user password = context.cloud_config.cloud.ssh_sudo_password paths = context.cloud_config.storage.nfs_mount_point_bases volume_template = context.cloud_config.storage.volume_name_template volume_pattern = generate_volume_pattern(volume_template, volume_id) rr = remote_runner.RemoteRunner( controller, user, ignore_errors=True, sudo=True, password=password) for mount_point in paths: # errors are ignored to avoid "Filesystem loop detected" messages # which don't matter anyways find = "find {mount_point} -name '{volume_pattern}' 2>/dev/null" res = rr.run(find.format(mount_point=mount_point, volume_pattern=volume_pattern)) if res: # there should only be one file matching path = res.stdout.splitlines().pop() return copy_mechanisms.CopyObject(host=controller, path=path) msg = ("Volume object for volume '{volume_id}' not found. Either " "volume exists in DB, but is not present on storage, or " "'nfs_mount_point_bases' is set incorrectly in config") raise base.VolumeObjectNotFoundError(msg.format(volume_id=volume_id))
def test_has_path_attribute(self): self.assertTrue(hasattr(copy_mechanisms.CopyObject(), "path"))
def test_has_host_attribute(self): self.assertTrue(hasattr(copy_mechanisms.CopyObject(), "host"))