Example #1
0
 def test_verify_protocol_failed(self):
     try:
         with volume_actions.VerifyProtocol(*self.command_args) as cmd:
             cmd.verify('protocol')
     except exception.ProtocolNotSupported:
         self.v_client.volumes.unreserve.assert_called_once_with(
             self.volume_id)
Example #2
0
    def attach(self,
               volume_id,
               hostname,
               mountpoint=None,
               mode='rw',
               multipath=False,
               enforce_multipath=False):

        # Check protocol type of storage backend.
        with actions.VerifyProtocol(self.volumes_client, volume_id) as cmd:
            # Retrieve vol-host attribute of volume.
            volume_info = self.volumes_client.volumes.get(volume_id)
            volume_capabilities = self.volumes_client.capabilities.get(
                volume_info.__dict__['os-vol-host-attr:host'])
            # Retrieve storage_protocol from storage backend capabilities.
            protocol = volume_capabilities.storage_protocol.upper()
            cmd.verify(protocol)

        # Reserve volume before attachment
        with actions.Reserve(self.volumes_client, volume_id) as cmd:
            cmd.reserve()

        with actions.InitializeConnection(self.volumes_client,
                                          volume_id) as cmd:
            connection = cmd.initialize(self, multipath, enforce_multipath)

        with actions.ConnectVolume(self.volumes_client, volume_id) as cmd:
            brick_connector = self._brick_get_connector(protocol,
                                                        do_local_attach=True)
            device_info = cmd.connect(brick_connector, connection['data'],
                                      mountpoint, mode, hostname)
            return device_info
    def _legacy_attach(self,
                       volume_id,
                       hostname,
                       mountpoint=None,
                       mode='rw',
                       multipath=False,
                       enforce_multipath=False,
                       nic=None):
        """The original/legacy attach workflow."""
        # Reserve volume before attachment
        with actions.Reserve(self.volumes_client, volume_id) as cmd:
            cmd.reserve()

        with actions.InitializeConnection(self.volumes_client,
                                          volume_id) as cmd:
            connection = cmd.initialize(self, multipath, enforce_multipath,
                                        nic)

        with actions.VerifyProtocol(self.volumes_client, volume_id) as cmd:
            cmd.verify(connection['driver_volume_type'])

        with actions.ConnectVolume(self.volumes_client, volume_id) as cmd:
            brick_connector = self._brick_get_connector(
                connection['driver_volume_type'], do_local_attach=True)
            device_info = cmd.connect(brick_connector, connection['data'],
                                      mountpoint, mode, hostname)
            return device_info
    def _attach(self,
                volume_id,
                hostname,
                mountpoint=None,
                mode='rw',
                multipath=False,
                enforce_multipath=False,
                nic=None):
        """Attempt to use the v3 API for attach workflow.

        If the cinder API microversion is good enough, we will use the new
        attach workflow, otherwise we resort back to the old workflow.
        """
        # We can use the new attach/detach workflow
        connector_properties = self.get_connector(
            multipath=multipath, enforce_multipath=enforce_multipath, nic=nic)

        instance_id = uuidutils.generate_uuid()

        info = self.volumes_client.attachments.create(volume_id,
                                                      connector_properties,
                                                      instance_id)

        connection = info['connection_info']
        with actions.VerifyProtocol(self.volumes_client, volume_id) as cmd:
            cmd.verify(connection['driver_volume_type'])

        brick_connector = self._brick_get_connector(
            connection['driver_volume_type'],
            do_local_attach=True,
            use_multipath=multipath,
        )
        device_info = brick_connector.connect_volume(connection)
        # MV 3.44 requires this step to move the volume to 'in-use'.
        self.volumes_client.attachments.complete(
            info['connection_info']['attachment_id'])
        return device_info
Example #5
0
 def test_verify_protocol(self, protocol):
     with volume_actions.VerifyProtocol(*self.command_args) as cmd:
         # NOTE(e0ne): veryfy that no exception is rased
         cmd.verify(protocol)