<commit_before># Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from testtools import content as ttc
import time
from unittest import mock
import uuid

from cinderclient.v3 import client as cinderclient
import glance_store
from glance_store._drivers import cinder
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils

from glance.common import wsgi
from glance.tests import functional

LOG = logging.getLogger(__name__)

CONF = cfg.CONF


class FakeObject(object):
    def __init__(self, **kwargs):
        for name, value in kwargs.items():
            setattr(self, name, value)


class TestLegacyUpdateCinderStore(functional.SynchronousAPIBase):

    def setUp(self):
        super(TestLegacyUpdateCinderStore, self).setUp()
        self.vol_id = uuid.uuid4()
        self.volume = FakeObject(
            id=self.vol_id,
            status='available',
            size=1,
            reserve=mock.MagicMock(),
            # FIXME(danms): Remove this after glance store
            # moves past 2.3.0
            begin_detaching=mock.MagicMock(),
            initialize_connection=mock.MagicMock(),
            terminate_connection=mock.MagicMock(),
            encrypted=False,
            unreserve=mock.MagicMock(),
            delete=mock.MagicMock(),
            # FIXME(danms): Remove this after glance store
            # moves past 2.3.0
            attach=mock.MagicMock(),
            update_all_metadata=mock.MagicMock(),
            update_readonly_flag=mock.MagicMock())
        self.volume.manager = FakeObject(get=lambda id: self.volume)
        self.cinder_store_mock = FakeObject(
            attachments=mock.MagicMock(),
            client=mock.MagicMock(), volumes=FakeObject(<commit_msg>Fix: glance cinder functional test<commit_after># Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from testtools import content as ttc
import time
from unittest import mock
import uuid

from cinderclient.v3 import client as cinderclient
import glance_store
from glance_store._drivers import cinder
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils

from glance.common import wsgi
from glance.tests import functional

LOG = logging.getLogger(__name__)

CONF = cfg.CONF


class FakeObject(object):
    def __init__(self, **kwargs):
        for name, value in kwargs.items():
            setattr(self, name, value)


class TestLegacyUpdateCinderStore(functional.SynchronousAPIBase):

    def setUp(self):
        super(TestLegacyUpdateCinderStore, self).setUp()
        self.vol_id = uuid.uuid4()
        self.volume = FakeObject(
            id=self.vol_id,
            status='available',
            size=1,
            multiattach=False,
            reserve=mock.MagicMock(),
            # FIXME(danms): Remove this after glance store
            # moves past 2.3.0
            begin_detaching=mock.MagicMock(),
            initialize_connection=mock.MagicMock(),
            terminate_connection=mock.MagicMock(),
            encrypted=False,
            unreserve=mock.MagicMock(),
            delete=mock.MagicMock(),
            # FIXME(danms): Remove this after glance store
            # moves past 2.3.0
            attach=mock.MagicMock(),
            update_all_metadata=mock.MagicMock(),
            update_readonly_flag=mock.MagicMock())
        self.volume.manager = FakeObject(get=lambda id: self.volume)
        self.cinder_store_mock = FakeObject(
            attachments=mock.MagicMock(),
            client=mock.MagicMock(), volumes=FakeObject(
{'fraction_non_alphanumeric': 0.07911392405063292, 'fraction_numerical': 0.007172995780590718, 'mean_word_length': 2.841977309562399, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4891341', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1270, 'n_words': 408}