Add base for functional tests
This adds the basic functional testing structure and initial support for the filesystem driver. Change-Id: Ia7f03b9ed91cc38a12d33479f75af167b45caeb0
This commit is contained in:
parent
2660ea9653
commit
a9d6cceaa4
|
@ -2,7 +2,7 @@
|
||||||
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
|
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
|
||||||
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
|
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
|
||||||
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \
|
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \
|
||||||
${PYTHON:-python} -m subunit.run discover -t ./ ./glance_store/tests/unit $LISTOPT $IDOPTION
|
${PYTHON:-python} -m subunit.run discover -t ./ ./glance_store/tests $LISTOPT $IDOPTION
|
||||||
|
|
||||||
test_id_option=--load-list $IDFILE
|
test_id_option=--load-list $IDFILE
|
||||||
test_list_option=--list
|
test_list_option=--list
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
# Copyright 2015 OpenStack Foundation
|
||||||
|
# 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 io import BytesIO
|
||||||
|
|
||||||
|
import glance_store
|
||||||
|
from oslo_config import cfg
|
||||||
|
import testtools
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
STORES = ['file', ]
|
||||||
|
|
||||||
|
UUID1 = '961973d8-3360-4364-919e-2c197825dbb4'
|
||||||
|
UUID2 = 'e03cf3b1-3070-4497-a37d-9703edfb615b'
|
||||||
|
UUID3 = '0d7f89b2-e236-45e9-b081-561cd3102e92'
|
||||||
|
UUID4 = '165e9681-ea56-46b0-a84c-f148c752ef8b'
|
||||||
|
IMAGE_BITS = b'I am a bootable image, I promise'
|
||||||
|
|
||||||
|
|
||||||
|
class Base(testtools.TestCase):
|
||||||
|
|
||||||
|
def __init__(self, driver_name, *args, **kwargs):
|
||||||
|
super(Base, self).__init__(*args, **kwargs)
|
||||||
|
self.driver_name = driver_name
|
||||||
|
|
||||||
|
glance_store.register_opts(CONF)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(Base, self).setUp()
|
||||||
|
|
||||||
|
if self.driver_name not in STORES:
|
||||||
|
self.skipTest('Not running %s store tests' % self.driver_name)
|
||||||
|
|
||||||
|
CONF.set_override('stores', [self.driver_name], group='glance_store')
|
||||||
|
glance_store.create_stores()
|
||||||
|
self.store = glance_store.backend._load_store(CONF, self.driver_name)
|
||||||
|
self.store.configure()
|
||||||
|
|
||||||
|
|
||||||
|
class BaseFunctionalTests(Base):
|
||||||
|
|
||||||
|
def test_add(self):
|
||||||
|
image_file = BytesIO(IMAGE_BITS)
|
||||||
|
loc, written, _, _ = self.store.add(UUID1, image_file, len(IMAGE_BITS))
|
||||||
|
self.assertEqual(len(IMAGE_BITS), written)
|
||||||
|
|
||||||
|
def test_delete(self):
|
||||||
|
image_file = BytesIO(IMAGE_BITS)
|
||||||
|
loc, written, _, _ = self.store.add(UUID2, image_file, len(IMAGE_BITS))
|
||||||
|
location = glance_store.location.get_location_from_uri(loc)
|
||||||
|
|
||||||
|
self.store.delete(location)
|
||||||
|
|
||||||
|
def test_get_size(self):
|
||||||
|
image_file = BytesIO(IMAGE_BITS)
|
||||||
|
loc, written, _, _ = self.store.add(UUID3, image_file, len(IMAGE_BITS))
|
||||||
|
location = glance_store.location.get_location_from_uri(loc)
|
||||||
|
|
||||||
|
size = self.store.get_size(location)
|
||||||
|
self.assertEqual(len(IMAGE_BITS), size)
|
||||||
|
|
||||||
|
def test_get(self):
|
||||||
|
image_file = BytesIO(IMAGE_BITS)
|
||||||
|
loc, written, _, _ = self.store.add(UUID3, image_file, len(IMAGE_BITS))
|
||||||
|
location = glance_store.location.get_location_from_uri(loc)
|
||||||
|
|
||||||
|
image, size = self.store.get(location)
|
||||||
|
|
||||||
|
self.assertEqual(len(IMAGE_BITS), size)
|
||||||
|
|
||||||
|
data = b''
|
||||||
|
for chunk in image:
|
||||||
|
data += chunk
|
||||||
|
|
||||||
|
self.assertEqual(IMAGE_BITS, data)
|
|
@ -0,0 +1,44 @@
|
||||||
|
# Copyright 2015 OpenStack Foundation
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
|
|
||||||
|
from glance_store.tests.functional import base
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
logging.basicConfig()
|
||||||
|
|
||||||
|
|
||||||
|
class TestFilesystem(base.BaseFunctionalTests):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(TestFilesystem, self).__init__('file', *args, **kwargs)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.tmp_image_dir = tempfile.mkdtemp(prefix='glance_store_')
|
||||||
|
CONF.set_override('filesystem_store_datadir',
|
||||||
|
self.tmp_image_dir,
|
||||||
|
group='glance_store')
|
||||||
|
super(TestFilesystem, self).setUp()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
shutil.rmtree(self.tmp_image_dir)
|
||||||
|
super(TestFilesystem, self).tearDown()
|
5
tox.ini
5
tox.ini
|
@ -26,6 +26,11 @@ commands = python setup.py testr --coverage --testr-args='^(?!.*test.*coverage).
|
||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
commands = {posargs}
|
commands = {posargs}
|
||||||
|
|
||||||
|
[testenv:functional]
|
||||||
|
setenv = OS_TEST_PATH=./glance_store/tests/functional
|
||||||
|
passenv = OS_*
|
||||||
|
commands = python setup.py testr --slowest --testr-args='glance_store.tests.functional'
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# TODO(dmllr): Analyze or fix the warnings blacklisted below
|
# TODO(dmllr): Analyze or fix the warnings blacklisted below
|
||||||
# H301 one import per line
|
# H301 one import per line
|
||||||
|
|
Loading…
Reference in New Issue