Use keystoneauth.betamax for shade mocks

Instead of mocking the clients, use keystoneauth1.betamax
fixture to intercept keystoneauth.construct_session, and provide
our own recorded fixtures.

Change-Id: I7b2973b0f89b66c19d6bf10571c3c93692107aa3
This commit is contained in:
Yolanda Robla 2016-03-29 12:30:07 +02:00 committed by Yolanda Robla
parent a53db2c680
commit 5f5c925631
5 changed files with 29 additions and 3 deletions

View File

@ -8,7 +8,7 @@ os-client-config>=1.17.0
requestsexceptions>=1.1.1 requestsexceptions>=1.1.1
six six
keystoneauth1>=1.0.0 keystoneauth1>=2.8.0
netifaces>=0.10.4 netifaces>=0.10.4
python-novaclient>=2.21.0,!=2.27.0,!=2.32.0 python-novaclient>=2.21.0,!=2.27.0,!=2.32.0
python-keystoneclient>=0.11.0 python-keystoneclient>=0.11.0

View File

@ -18,6 +18,7 @@
import time import time
import fixtures import fixtures
import os
import os_client_config as occ import os_client_config as occ
import tempfile import tempfile
@ -56,10 +57,21 @@ class TestCase(base.TestCase):
vendor.write(b'{}') vendor.write(b'{}')
vendor.close() vendor.close()
# set record mode depending on environment
record_mode = os.environ.get('BETAMAX_RECORD_FIXTURES', False)
if record_mode:
self.record_fixtures = 'new_episodes'
else:
self.record_fixtures = None
test_cloud = os.environ.get('SHADE_OS_CLOUD', '_test_cloud_')
self.config = occ.OpenStackConfig( self.config = occ.OpenStackConfig(
config_files=[config.name], config_files=[config.name],
vendor_files=[vendor.name]) vendor_files=[vendor.name])
self.cloud_config = self.config.get_one_cloud(cloud='_test_cloud_') self.cloud_config = self.config.get_one_cloud(cloud=test_cloud)
self.cloud = shade.OpenStackCloud( self.cloud = shade.OpenStackCloud(
cloud_config=self.cloud_config, cloud_config=self.cloud_config,
log_inner_exceptions=True) log_inner_exceptions=True)
self.op_cloud = shade.OperatorCloud(
cloud_config=self.cloud_config,
log_inner_exceptions=True)

View File

@ -24,7 +24,6 @@ class TestFlavors(base.TestCase):
def setUp(self): def setUp(self):
super(TestFlavors, self).setUp() super(TestFlavors, self).setUp()
self.op_cloud = shade.operator_cloud(validate=False)
@mock.patch.object(shade.OpenStackCloud, 'nova_client') @mock.patch.object(shade.OpenStackCloud, 'nova_client')
def test_create_flavor(self, mock_nova): def test_create_flavor(self, mock_nova):

View File

@ -1,5 +1,6 @@
hacking>=0.10.0,<0.11 hacking>=0.10.0,<0.11
betamax-serializers>=0.1.1
coverage>=3.6 coverage>=3.6
discover discover
fixtures>=0.3.14 fixtures>=0.3.14

14
tox.ini
View File

@ -15,6 +15,20 @@ deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt
commands = python setup.py testr --slowest --testr-args='{posargs}' commands = python setup.py testr --slowest --testr-args='{posargs}'
[testenv:record]
usedevelop = True
install_command = pip install -U {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=C
BETAMAX_RECORD_FIXTURES=1
passenv = SHADE_OS_CLOUD
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = python setup.py testr --slowest --testr-args='--concurrency=1 {posargs}'
[testenv:functional] [testenv:functional]
setenv = setenv =
OS_TEST_PATH = ./shade/tests/functional OS_TEST_PATH = ./shade/tests/functional