Exemplo n.º 1
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
Exemplo n.º 3
0
    def test_reserve_failed(self):
        self.v_client.volumes.reserve.side_effect = (
            cinder_exceptions.BadRequest(400))
        try:
            with volume_actions.Reserve(*self.command_args) as cmd:
                cmd.reserve()
        except cinder_exceptions.BadRequest:
            self.v_client.volumes.unreserve.assert_called_once_with(
                self.volume_id)

        self.v_client.volumes.reserve.assert_called_once_with(self.volume_id)
Exemplo n.º 4
0
    def test_reserve(self):
        with volume_actions.Reserve(*self.command_args) as cmd:
            cmd.reserve()

        self.v_client.volumes.reserve.assert_called_once_with(self.volume_id)