Merge fixed_ips functional tests of v2 and v2.1

Currently v2 and v2.1 have separate functional tests and their
corresponding sample files. As v2 and v2.1 are supposed to be identical,
there is overhead to maintain two set of functional tests and sample files.
We can have one set of tests which can run for both v2 and v2.1.

This commit merges fixed_ips functional tests.

Change-Id: Ia7d709adb90bf91adb92a3550584a30347d2f32d
This commit is contained in:
parklong 2015-04-07 11:54:11 +08:00
parent bf70df295b
commit edcc7ab360
6 changed files with 17 additions and 105 deletions

View File

@ -1,3 +0,0 @@
{
"reserve": null
}

View File

@ -1,8 +0,0 @@
{
"fixed_ip": {
"address": "192.168.1.1",
"cidr": "192.168.1.0/24",
"host": "host",
"hostname": "openstack"
}
}

View File

@ -1,3 +0,0 @@
{
"reserve": null
}

View File

@ -1,8 +0,0 @@
{
"fixed_ip": {
"cidr": "%(cidr)s",
"hostname": "%(hostname)s",
"host": "%(host)s",
"address": "%(address)s"
}
}

View File

@ -61,8 +61,6 @@ from nova.tests.unit import fake_network
from nova.tests.unit import fake_network_cache_model
from nova.tests.unit import fake_utils
from nova.tests.unit.image import fake
from nova.tests.unit.objects import test_network
from nova.tests.unit import utils as test_utils
from nova import utils
from nova.volume import cinder
@ -974,87 +972,6 @@ class CloudPipeUpdateJsonTest(ApiSampleTestBaseV2):
self.assertEqual(response.content, "")
class FixedIpJsonTest(ApiSampleTestBaseV2):
extension_name = "nova.api.openstack.compute.contrib.fixed_ips.Fixed_ips"
def _get_flags(self):
f = super(FixedIpJsonTest, self)._get_flags()
f['osapi_compute_extension'] = CONF.osapi_compute_extension[:]
return f
def setUp(self):
super(FixedIpJsonTest, self).setUp()
instance = dict(test_utils.get_test_instance(),
hostname='openstack', host='host')
fake_fixed_ips = [{'id': 1,
'address': '192.168.1.1',
'network_id': 1,
'virtual_interface_id': 1,
'instance_uuid': '1',
'allocated': False,
'leased': False,
'reserved': False,
'created_at': None,
'deleted_at': None,
'updated_at': None,
'deleted': None,
'instance': instance,
'network': test_network.fake_network,
'host': None},
{'id': 2,
'address': '192.168.1.2',
'network_id': 1,
'virtual_interface_id': 2,
'instance_uuid': '2',
'allocated': False,
'leased': False,
'reserved': False,
'created_at': None,
'deleted_at': None,
'updated_at': None,
'deleted': None,
'instance': instance,
'network': test_network.fake_network,
'host': None},
]
def fake_fixed_ip_get_by_address(context, address,
columns_to_join=None):
for fixed_ip in fake_fixed_ips:
if fixed_ip['address'] == address:
return fixed_ip
raise exception.FixedIpNotFoundForAddress(address=address)
def fake_fixed_ip_update(context, address, values):
fixed_ip = fake_fixed_ip_get_by_address(context, address)
if fixed_ip is None:
raise exception.FixedIpNotFoundForAddress(address=address)
else:
for key in values:
fixed_ip[key] = values[key]
self.stubs.Set(db, "fixed_ip_get_by_address",
fake_fixed_ip_get_by_address)
self.stubs.Set(db, "fixed_ip_update", fake_fixed_ip_update)
def test_fixed_ip_reserve(self):
# Reserve a Fixed IP.
response = self._do_post('os-fixed-ips/192.168.1.1/action',
'fixedip-post-req', {})
self.assertEqual(response.status_code, 202)
self.assertEqual(response.content, "")
def test_get_fixed_ip(self):
# Return data about the given fixed ip.
response = self._do_get('os-fixed-ips/192.168.1.1')
project = {'cidr': '192.168.1.0/24',
'hostname': 'openstack',
'host': 'host',
'address': '192.168.1.1'}
self._verify_response('fixedips-get-resp', project, response, 200)
class UsedLimitsSamplesJsonTest(ApiSampleTestBaseV2):
extension_name = ("nova.api.openstack.compute.contrib.used_limits."
"Used_limits")

View File

@ -12,15 +12,32 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from nova import db
from nova import exception
from nova.tests.functional.v3 import test_servers
from nova.tests.unit.objects import test_network
from nova.tests.unit import utils as test_utils
CONF = cfg.CONF
CONF.import_opt('osapi_compute_extension',
'nova.api.openstack.compute.extensions')
class FixedIpTest(test_servers.ServersSampleBase):
extension_name = "os-fixed-ips"
# TODO(park): Overriding '_api_version' till all functional tests
# are merged between v2 and v2.1. After that base class variable
# itself can be changed to 'v2'
_api_version = 'v2'
def _get_flags(self):
f = super(FixedIpTest, self)._get_flags()
f['osapi_compute_extension'] = CONF.osapi_compute_extension[:]
f['osapi_compute_extension'].append(
'nova.api.openstack.compute.contrib.fixed_ips.Fixed_ips')
return f
def setUp(self):
super(FixedIpTest, self).setUp()