Merge "Add functional api_samples test for addFloatingIp action"
This commit is contained in:
commit
bc2a5d8709
6
doc/api_samples/servers/server-action-addfloatingip.json
Normal file
6
doc/api_samples/servers/server-action-addfloatingip.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"addFloatingIp" : {
|
||||||
|
"address": "10.10.10.10",
|
||||||
|
"fixed_address": "192.168.0.3"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"addFloatingIp" : {
|
||||||
|
"address": "%(address)s",
|
||||||
|
"fixed_address": "%(fixed_address)s"
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import time
|
||||||
|
|
||||||
from nova.api.openstack import api_version_request as avr
|
from nova.api.openstack import api_version_request as avr
|
||||||
from nova.tests.functional.api_sample_tests import api_sample_base
|
from nova.tests.functional.api_sample_tests import api_sample_base
|
||||||
@ -281,6 +282,54 @@ class ServersActionsJsonTest(ServersSampleBase):
|
|||||||
'server-action-create-image',
|
'server-action-create-image',
|
||||||
{'name': 'foo-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):
|
class ServersActionsJson219Test(ServersSampleBase):
|
||||||
microversion = '2.19'
|
microversion = '2.19'
|
||||||
|
@ -479,9 +479,13 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
|||||||
return self._get_response(url, 'OPTIONS', strip_version=strip_version,
|
return self._get_response(url, 'OPTIONS', strip_version=strip_version,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
|
|
||||||
def _do_get(self, url, strip_version=False, headers=None):
|
def _do_get(self, url, strip_version=False, headers=None,
|
||||||
return self._get_response(url, 'GET', strip_version=strip_version,
|
return_json_body=False):
|
||||||
|
response = self._get_response(url, 'GET', strip_version=strip_version,
|
||||||
headers=headers)
|
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):
|
def _do_post(self, url, name, subs, method='POST', headers=None):
|
||||||
self.subs = subs
|
self.subs = subs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user