summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Kurilin <akurilin@mirantis.com>2015-12-22 16:41:03 +0200
committerAndrey Kurilin <akurilin@mirantis.com>2016-02-19 13:21:50 +0200
commit083ce7eeeada3e4d73c55e4e2d7239febb3993f6 (patch)
treee2d9a307680f3cc3718c1b3e6a6521d470262695
parent9774405f8e6edb5aad83866c7c94226ab15ab4cc (diff)
downloadpython-novaclient-083ce7eeeada3e4d73c55e4e2d7239febb3993f6.tar.gz
[functional] Move code for boot vm to base testcase
It would be nice to reduce code duplication. Change-Id: Ie430b64c7e08f6cba8771c85cc1894fa71357ccb
-rw-r--r--novaclient/tests/functional/base.py15
-rw-r--r--novaclient/tests/functional/v2/legacy/test_consoles.py10
-rw-r--r--novaclient/tests/functional/v2/legacy/test_extended_attributes.py10
-rw-r--r--novaclient/tests/functional/v2/legacy/test_fixedips.py12
-rw-r--r--novaclient/tests/functional/v2/legacy/test_servers.py13
-rw-r--r--novaclient/tests/functional/v2/legacy/test_virtual_interface.py12
-rw-r--r--novaclient/tests/functional/v2/test_servers.py15
7 files changed, 21 insertions, 66 deletions
diff --git a/novaclient/tests/functional/base.py b/novaclient/tests/functional/base.py
index e148d0b8..42cef9e1 100644
--- a/novaclient/tests/functional/base.py
+++ b/novaclient/tests/functional/base.py
@@ -23,6 +23,7 @@ import testtools
import novaclient
import novaclient.api_versions
import novaclient.client
+import novaclient.v2.shell
# The following are simple filter functions that filter our available
@@ -307,6 +308,20 @@ class ClientTestBase(testtools.TestCase):
raise ValueError("Unable to find value for column '%s'.")
+ def _create_server(self, name=None, with_network=True, **kwargs):
+ name = name or self.name_generate(prefix='server')
+ if with_network:
+ nics = [{"net-id": self.network.id}]
+ else:
+ nics = None
+ server = self.client.servers.create(name, self.image, self.flavor,
+ nics=nics, **kwargs)
+ self.addCleanup(server.delete)
+ novaclient.v2.shell._poll_for_status(
+ self.client.servers.get, server.id,
+ 'building', ['active'])
+ return server
+
class TenantTestBase(ClientTestBase):
"""Base test class for additional tenant and user creation which
diff --git a/novaclient/tests/functional/v2/legacy/test_consoles.py b/novaclient/tests/functional/v2/legacy/test_consoles.py
index 5ca022a7..318541f9 100644
--- a/novaclient/tests/functional/v2/legacy/test_consoles.py
+++ b/novaclient/tests/functional/v2/legacy/test_consoles.py
@@ -14,7 +14,6 @@
from tempest_lib import exceptions
from novaclient.tests.functional import base
-from novaclient.v2 import shell
class TestConsolesNovaClient(base.ClientTestBase):
@@ -22,15 +21,6 @@ class TestConsolesNovaClient(base.ClientTestBase):
COMPUTE_API_VERSION = "2.1"
- def _create_server(self):
- name = self.name_generate(prefix='server')
- server = self.client.servers.create(name, self.image, self.flavor)
- shell._poll_for_status(
- self.client.servers.get, server.id,
- 'building', ['active'])
- self.addCleanup(server.delete)
- return server
-
def _test_console_get(self, command):
server = self._create_server()
completed_command = command % server.id
diff --git a/novaclient/tests/functional/v2/legacy/test_extended_attributes.py b/novaclient/tests/functional/v2/legacy/test_extended_attributes.py
index 55da9882..ef579e91 100644
--- a/novaclient/tests/functional/v2/legacy/test_extended_attributes.py
+++ b/novaclient/tests/functional/v2/legacy/test_extended_attributes.py
@@ -13,7 +13,6 @@
import json
from novaclient.tests.functional import base
-from novaclient.v2 import shell
class TestExtAttrNovaClient(base.ClientTestBase):
@@ -22,16 +21,11 @@ class TestExtAttrNovaClient(base.ClientTestBase):
COMPUTE_API_VERSION = "2.1"
def _create_server_and_attach_volume(self):
- name = self.name_generate(prefix='server')
- server = self.client.servers.create(name, self.image, self.flavor)
- self.addCleanup(server.delete)
- shell._poll_for_status(
- self.client.servers.get, server.id,
- 'building', ['active'])
+ server = self._create_server()
volume = self.client.volumes.create(1)
self.addCleanup(self.nova, 'volume-delete', params=volume.id)
self.wait_for_volume_status(volume, 'available')
- self.nova('volume-attach', params="%s %s" % (name, volume.id))
+ self.nova('volume-attach', params="%s %s" % (server.name, volume.id))
self.addCleanup(self._release_volume, server, volume)
self.wait_for_volume_status(volume, 'in-use')
return server, volume
diff --git a/novaclient/tests/functional/v2/legacy/test_fixedips.py b/novaclient/tests/functional/v2/legacy/test_fixedips.py
index 0206a140..283faa5a 100644
--- a/novaclient/tests/functional/v2/legacy/test_fixedips.py
+++ b/novaclient/tests/functional/v2/legacy/test_fixedips.py
@@ -14,7 +14,6 @@
from oslo_utils import strutils
from novaclient.tests.functional import base
-from novaclient.v2 import shell
class TestFixedIPsNovaClient(base.ClientTestBase):
@@ -22,17 +21,8 @@ class TestFixedIPsNovaClient(base.ClientTestBase):
COMPUTE_API_VERSION = '2.1'
- def _create_server(self):
- name = self.name_generate(prefix='server')
- server = self.client.servers.create(name, self.image, self.flavor)
- shell._poll_for_status(
- self.client.servers.get, server.id,
- 'building', ['active'])
- self.addCleanup(server.delete)
- return server
-
def _test_fixedip_get(self, expect_reserved=False):
- server = self._create_server()
+ server = self._create_server(with_network=False)
networks = server.networks
self.assertIn('private', networks)
fixed_ip = networks['private'][0]
diff --git a/novaclient/tests/functional/v2/legacy/test_servers.py b/novaclient/tests/functional/v2/legacy/test_servers.py
index e13cd1ef..12998841 100644
--- a/novaclient/tests/functional/v2/legacy/test_servers.py
+++ b/novaclient/tests/functional/v2/legacy/test_servers.py
@@ -13,7 +13,6 @@
import uuid
from novaclient.tests.functional import base
-from novaclient.v2 import shell
class TestServersBootNovaClient(base.ClientTestBase):
@@ -75,17 +74,7 @@ class TestServersListNovaClient(base.ClientTestBase):
COMPUTE_API_VERSION = "2.1"
def _create_servers(self, name, number):
- servers = []
- for i in range(number):
- servers.append(self.client.servers.create(
- name, self.image, self.flavor,
- nics=[{"net-id": self.network.id}]))
- shell._poll_for_status(
- self.client.servers.get, servers[-1].id,
- 'building', ['active'])
-
- self.addCleanup(servers[-1].delete)
- return servers
+ return [self._create_server(name) for i in range(number)]
def test_list_with_limit(self):
name = str(uuid.uuid4())
diff --git a/novaclient/tests/functional/v2/legacy/test_virtual_interface.py b/novaclient/tests/functional/v2/legacy/test_virtual_interface.py
index fe76dfbe..f37b19be 100644
--- a/novaclient/tests/functional/v2/legacy/test_virtual_interface.py
+++ b/novaclient/tests/functional/v2/legacy/test_virtual_interface.py
@@ -12,7 +12,6 @@
# under the License.
from novaclient.tests.functional import base
-from novaclient.v2 import shell
class TestVirtualInterfacesNovaClient(base.ClientTestBase):
@@ -20,17 +19,6 @@ class TestVirtualInterfacesNovaClient(base.ClientTestBase):
COMPUTE_API_VERSION = "2.1"
- def _create_server(self):
- name = self.name_generate(prefix='server')
- network = self.client.networks.list()[0]
- server = self.client.servers.create(
- name, self.image, self.flavor, nics=[{"net-id": network.id}])
- shell._poll_for_status(
- self.client.servers.get, server.id,
- 'building', ['active'])
- self.addCleanup(server.delete)
- return server
-
def test_virtual_interface_list(self):
server = self._create_server()
output = self.nova('virtual-interface-list %s' % server.id)
diff --git a/novaclient/tests/functional/v2/test_servers.py b/novaclient/tests/functional/v2/test_servers.py
index de5e57d9..cf6f45a1 100644
--- a/novaclient/tests/functional/v2/test_servers.py
+++ b/novaclient/tests/functional/v2/test_servers.py
@@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import uuid
-
from novaclient.tests.functional import base
from novaclient.tests.functional.v2.legacy import test_servers
@@ -39,11 +37,7 @@ class TestServerLockV29(base.ClientTestBase):
def test_attribute_presented(self):
# prepare
- name = str(uuid.uuid4())
- network = self.client.networks.list()[0]
- server = self.client.servers.create(
- name, self.image, self.flavor, nics=[{"net-id": network.id}])
- self.addCleanup(server.delete)
+ server = self._create_server()
# testing
self._show_server_and_check_lock_attr(server, False)
@@ -60,13 +54,8 @@ class TestServersDescription(base.ClientTestBase):
COMPUTE_API_VERSION = "2.19"
def _boot_server_with_description(self):
- name = str(uuid.uuid4())
- network = self.client.networks.list()[0]
descr = "Some words about this test VM."
- server = self.client.servers.create(
- name, self.image, self.flavor, nics=[{"net-id": network.id}],
- description=descr)
- self.addCleanup(server.delete)
+ server = self._create_server(description=descr)
self.assertEqual(descr, server.description)