Allow to specify a network for functional tests
Currently the tests just attach instances to the first network returned by "net-list". That might however not be the right thing in some environments. This change allows to override the default network via the environment variable "OS_NOVACLIENT_NETWORK". If not specified the test will fallback to the old behaviour and just use the first network. Closes-Bug: #1510975 Change-Id: Ie682111127584a33d8e96377d812d3a6352c760d
This commit is contained in:
parent
99c588e28c
commit
8a2ed13620
novaclient/tests/functional
tox.ini@ -19,7 +19,8 @@ class TestServersAPI(base.ClientTestBase):
|
||||
def test_server_ips(self):
|
||||
server_name = "test_server"
|
||||
initial_server = self.client.servers.create(
|
||||
server_name, self.image, self.flavor)
|
||||
server_name, self.image, self.flavor,
|
||||
nics=[{"net-id": self.network.id}])
|
||||
self.addCleanup(initial_server.delete)
|
||||
|
||||
for x in range(60):
|
||||
@ -32,4 +33,4 @@ class TestServersAPI(base.ClientTestBase):
|
||||
self.fail("Server %s did not go ACTIVE after 60s" % server)
|
||||
|
||||
ips = self.client.servers.ips(server)
|
||||
self.assertIn('private', ips)
|
||||
self.assertIn(self.network.label, ips)
|
||||
|
@ -45,6 +45,16 @@ def pick_image(images):
|
||||
raise NoImageException()
|
||||
|
||||
|
||||
def pick_network(networks):
|
||||
network_name = os.environ.get('OS_NOVACLIENT_NETWORK')
|
||||
if network_name:
|
||||
for network in networks:
|
||||
if network.label == network_name:
|
||||
return network
|
||||
raise NoNetworkException()
|
||||
return networks[0]
|
||||
|
||||
|
||||
class NoImageException(Exception):
|
||||
"""We couldn't find an acceptable image."""
|
||||
pass
|
||||
@ -55,6 +65,11 @@ class NoFlavorException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class NoNetworkException(Exception):
|
||||
"""We couldn't find an acceptable network."""
|
||||
pass
|
||||
|
||||
|
||||
class NoCloudConfigException(Exception):
|
||||
"""We couldn't find a cloud configuration."""
|
||||
pass
|
||||
@ -163,6 +178,7 @@ class ClientTestBase(testtools.TestCase):
|
||||
# pick some reasonable flavor / image combo
|
||||
self.flavor = pick_flavor(self.client.flavors.list())
|
||||
self.image = pick_image(self.client.images.list())
|
||||
self.network = pick_network(self.client.networks.list())
|
||||
|
||||
# create a CLI client in case we'd like to do CLI
|
||||
# testing. tempest_lib does this really weird thing where it
|
||||
|
@ -40,10 +40,9 @@ class TestInstanceCLI(base.ClientTestBase):
|
||||
name = self.name_generate('Instance')
|
||||
|
||||
# Boot via the cli, as we're primarily testing the cli in this test
|
||||
network = self.client.networks.list()[0]
|
||||
self.nova('boot',
|
||||
params="--flavor %s --image %s %s --nic net-id=%s --poll" %
|
||||
(self.flavor.name, self.image.name, name, network.id))
|
||||
(self.flavor.name, self.image.name, name, self.network.id))
|
||||
|
||||
# Be nice about cleaning up, however, use the API for this to avoid
|
||||
# parsing text.
|
||||
|
@ -75,11 +75,11 @@ class TestServersListNovaClient(base.ClientTestBase):
|
||||
COMPUTE_API_VERSION = "2.1"
|
||||
|
||||
def _create_servers(self, name, number):
|
||||
network = self.client.networks.list()[0]
|
||||
servers = []
|
||||
for i in range(number):
|
||||
servers.append(self.client.servers.create(
|
||||
name, self.image, self.flavor, nics=[{"net-id": network.id}]))
|
||||
name, self.image, self.flavor,
|
||||
nics=[{"net-id": self.network.id}]))
|
||||
shell._poll_for_status(
|
||||
self.client.servers.get, servers[-1].id,
|
||||
'building', ['active'])
|
||||
|
2
tox.ini
2
tox.ini
@ -36,12 +36,14 @@ commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasen
|
||||
|
||||
[testenv:functional]
|
||||
basepython = python2.7
|
||||
passenv = OS_NOVACLIENT_TEST_NETWORK
|
||||
setenv =
|
||||
OS_TEST_PATH = ./novaclient/tests/functional
|
||||
commands = python setup.py testr --testr-args='--concurrency=1 {posargs}'
|
||||
|
||||
[testenv:functional-py34]
|
||||
basepython = python3.4
|
||||
passenv = OS_NOVACLIENT_TEST_NETWORK
|
||||
setenv =
|
||||
OS_TEST_PATH = ./novaclient/tests/functional
|
||||
commands = python setup.py testr --testr-args='--concurrency=1 {posargs}'
|
||||
|
Loading…
x
Reference in New Issue
Block a user