Add functional api_samples test for addFloatingIp action

This is needed for filling the gap in the api-ref docs.

Change-Id: Ib21e4ae25780c1780678074b4ccc5a86944ce992
Related-Bug: #1636185
This commit is contained in:
Matt Riedemann 2016-11-07 11:28:34 -05:00
parent 0132cc8c26
commit 1e4178b6a0
4 changed files with 68 additions and 3 deletions

View File

@ -0,0 +1,6 @@
{
"addFloatingIp" : {
"address": "10.10.10.10",
"fixed_address": "192.168.0.3"
}
}

View File

@ -0,0 +1,6 @@
{
"addFloatingIp" : {
"address": "%(address)s",
"fixed_address": "%(fixed_address)s"
}
}

View File

@ -14,6 +14,7 @@
# under the License.
import base64
import time
from nova.api.openstack import api_version_request as avr
from nova.tests.functional.api_sample_tests import api_sample_base
@ -281,6 +282,54 @@ class ServersActionsJsonTest(ServersSampleBase):
'server-action-create-image',
{'name': 'foo-image'})
def _wait_for_active_server(self, uuid):
"""Wait 10 seconds for the server to be ACTIVE, else fail.
:param uuid: The server id.
:returns: The ACTIVE server.
"""
server = self._do_get('servers/%s' % uuid,
return_json_body=True)['server']
count = 0
while server['status'] != 'ACTIVE' and count < 10:
time.sleep(1)
server = self._do_get('servers/%s' % uuid,
return_json_body=True)['server']
count += 1
if server['status'] != 'ACTIVE':
self.fail('Timed out waiting for server %s to be ACTIVE.' % uuid)
return server
def test_server_add_floating_ip(self):
uuid = self._post_server()
# Get the server details so we can find a fixed IP to use in the
# addFloatingIp request.
server = self._wait_for_active_server(uuid)
addresses = server['addresses']
# Find a fixed IP.
fixed_address = None
for network, ips in addresses.items():
for ip in ips:
if ip['OS-EXT-IPS:type'] == 'fixed':
fixed_address = ip['addr']
break
if fixed_address:
break
if fixed_address is None:
self.fail('Failed to find a fixed IP for server %s in addresses: '
'%s' % (uuid, addresses))
subs = {
"address": "10.10.10.10",
"fixed_address": fixed_address
}
# This is gross, but we need to stub out the associate_floating_ip
# call in the FloatingIPActionController since we don't have a real
# networking service backing this up, just the fake nova-network stubs.
self.stub_out('nova.network.api.API.associate_floating_ip',
lambda *a, **k: None)
self._test_server_action(uuid, 'addFloatingIp',
'server-action-addfloatingip', subs)
class ServersActionsJson219Test(ServersSampleBase):
microversion = '2.19'

View File

@ -479,9 +479,13 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
return self._get_response(url, 'OPTIONS', strip_version=strip_version,
headers=headers)
def _do_get(self, url, strip_version=False, headers=None):
return self._get_response(url, 'GET', strip_version=strip_version,
headers=headers)
def _do_get(self, url, strip_version=False, headers=None,
return_json_body=False):
response = self._get_response(url, 'GET', strip_version=strip_version,
headers=headers)
if return_json_body and hasattr(response, 'content'):
return jsonutils.loads(response.content)
return response
def _do_post(self, url, name, subs, method='POST', headers=None):
self.subs = subs