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):
|
def test_server_ips(self):
|
||||||
server_name = "test_server"
|
server_name = "test_server"
|
||||||
initial_server = self.client.servers.create(
|
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)
|
self.addCleanup(initial_server.delete)
|
||||||
|
|
||||||
for x in range(60):
|
for x in range(60):
|
||||||
@ -32,4 +33,4 @@ class TestServersAPI(base.ClientTestBase):
|
|||||||
self.fail("Server %s did not go ACTIVE after 60s" % server)
|
self.fail("Server %s did not go ACTIVE after 60s" % server)
|
||||||
|
|
||||||
ips = self.client.servers.ips(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()
|
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):
|
class NoImageException(Exception):
|
||||||
"""We couldn't find an acceptable image."""
|
"""We couldn't find an acceptable image."""
|
||||||
pass
|
pass
|
||||||
@ -55,6 +65,11 @@ class NoFlavorException(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class NoNetworkException(Exception):
|
||||||
|
"""We couldn't find an acceptable network."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NoCloudConfigException(Exception):
|
class NoCloudConfigException(Exception):
|
||||||
"""We couldn't find a cloud configuration."""
|
"""We couldn't find a cloud configuration."""
|
||||||
pass
|
pass
|
||||||
@ -163,6 +178,7 @@ class ClientTestBase(testtools.TestCase):
|
|||||||
# pick some reasonable flavor / image combo
|
# pick some reasonable flavor / image combo
|
||||||
self.flavor = pick_flavor(self.client.flavors.list())
|
self.flavor = pick_flavor(self.client.flavors.list())
|
||||||
self.image = pick_image(self.client.images.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
|
# create a CLI client in case we'd like to do CLI
|
||||||
# testing. tempest_lib does this really weird thing where it
|
# testing. tempest_lib does this really weird thing where it
|
||||||
|
@ -40,10 +40,9 @@ class TestInstanceCLI(base.ClientTestBase):
|
|||||||
name = self.name_generate('Instance')
|
name = self.name_generate('Instance')
|
||||||
|
|
||||||
# Boot via the cli, as we're primarily testing the cli in this test
|
# Boot via the cli, as we're primarily testing the cli in this test
|
||||||
network = self.client.networks.list()[0]
|
|
||||||
self.nova('boot',
|
self.nova('boot',
|
||||||
params="--flavor %s --image %s %s --nic net-id=%s --poll" %
|
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
|
# Be nice about cleaning up, however, use the API for this to avoid
|
||||||
# parsing text.
|
# parsing text.
|
||||||
|
@ -75,11 +75,11 @@ class TestServersListNovaClient(base.ClientTestBase):
|
|||||||
COMPUTE_API_VERSION = "2.1"
|
COMPUTE_API_VERSION = "2.1"
|
||||||
|
|
||||||
def _create_servers(self, name, number):
|
def _create_servers(self, name, number):
|
||||||
network = self.client.networks.list()[0]
|
|
||||||
servers = []
|
servers = []
|
||||||
for i in range(number):
|
for i in range(number):
|
||||||
servers.append(self.client.servers.create(
|
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(
|
shell._poll_for_status(
|
||||||
self.client.servers.get, servers[-1].id,
|
self.client.servers.get, servers[-1].id,
|
||||||
'building', ['active'])
|
'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]
|
[testenv:functional]
|
||||||
basepython = python2.7
|
basepython = python2.7
|
||||||
|
passenv = OS_NOVACLIENT_TEST_NETWORK
|
||||||
setenv =
|
setenv =
|
||||||
OS_TEST_PATH = ./novaclient/tests/functional
|
OS_TEST_PATH = ./novaclient/tests/functional
|
||||||
commands = python setup.py testr --testr-args='--concurrency=1 {posargs}'
|
commands = python setup.py testr --testr-args='--concurrency=1 {posargs}'
|
||||||
|
|
||||||
[testenv:functional-py34]
|
[testenv:functional-py34]
|
||||||
basepython = python3.4
|
basepython = python3.4
|
||||||
|
passenv = OS_NOVACLIENT_TEST_NETWORK
|
||||||
setenv =
|
setenv =
|
||||||
OS_TEST_PATH = ./novaclient/tests/functional
|
OS_TEST_PATH = ./novaclient/tests/functional
|
||||||
commands = python setup.py testr --testr-args='--concurrency=1 {posargs}'
|
commands = python setup.py testr --testr-args='--concurrency=1 {posargs}'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user