Skip to content

Commit e2eefc2

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "api: Add response body schemas for floating IP APIs"
2 parents df6f5c3 + a61a1c4 commit e2eefc2

3 files changed

Lines changed: 70 additions & 6 deletions

File tree

nova/api/openstack/compute/floating_ips.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ def _translate_floating_ip_view(floating_ip):
4242

4343
return {
4444
'floating_ip': {
45+
'fixed_ip': floating_ip['fixed_ip_address'],
4546
'id': floating_ip['id'],
47+
'instance_id': instance_id,
4648
'ip': floating_ip['floating_ip_address'],
47-
'pool': floating_ip['network_details']['name'] or (
49+
'pool': (
50+
floating_ip['network_details']['name'] or
4851
floating_ip['network_details']['id']),
49-
'fixed_ip': floating_ip['fixed_ip_address'],
50-
'instance_id': instance_id,
5152
}
5253
}
5354

5455

5556
def get_instance_by_floating_ip_addr(self, context, address):
5657
try:
57-
instance_id =\
58-
self.network_api.get_instance_id_by_floating_address(
59-
context, address)
58+
instance_id = self.network_api.get_instance_id_by_floating_address(
59+
context, address)
6060
except exception.FloatingIpNotFoundForAddress as ex:
6161
raise webob.exc.HTTPNotFound(explanation=ex.format_message())
6262
except exception.FloatingIpMultipleFoundForAddress as ex:
@@ -74,6 +74,7 @@ def disassociate_floating_ip(self, context, instance, address):
7474
raise webob.exc.HTTPForbidden()
7575

7676

77+
@validation.validated
7778
class FloatingIPController(wsgi.Controller):
7879
"""The Floating IPs API controller for the OpenStack API."""
7980

@@ -85,6 +86,7 @@ def __init__(self):
8586
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
8687
@wsgi.expected_errors((400, 404))
8788
@validation.query_schema(schema.show_query)
89+
@validation.response_body_schema(schema.show_response)
8890
def show(self, req, id):
8991
"""Return data about the given floating IP."""
9092
context = req.environ['nova.context']
@@ -104,6 +106,7 @@ def show(self, req, id):
104106
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
105107
@wsgi.expected_errors(())
106108
@validation.query_schema(schema.index_query)
109+
@validation.response_body_schema(schema.index_response)
107110
def index(self, req):
108111
"""Return a list of floating IPs allocated to a project."""
109112
context = req.environ['nova.context']
@@ -118,6 +121,7 @@ def index(self, req):
118121
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
119122
@wsgi.expected_errors((400, 403, 404))
120123
@validation.schema(schema.create)
124+
@validation.response_body_schema(schema.create_response)
121125
def create(self, req, body=None):
122126
context = req.environ['nova.context']
123127
context.can(fi_policies.BASE_POLICY_NAME % 'create',
@@ -151,6 +155,7 @@ def create(self, req, body=None):
151155
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
152156
@wsgi.response(202)
153157
@wsgi.expected_errors((400, 403, 404, 409))
158+
@validation.response_body_schema(schema.delete_response)
154159
def delete(self, req, id):
155160
context = req.environ['nova.context']
156161
context.can(fi_policies.BASE_POLICY_NAME % 'delete',

nova/api/openstack/compute/schemas/floating_ips.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15+
import copy
1516

1617
from nova.api.validation import parameter_types
1718

@@ -62,6 +63,50 @@
6263
show_query = {}
6364
index_query = {}
6465

66+
_floating_ip_response = {
67+
'type': 'object',
68+
'properties': {
69+
'fixed_ip': {
70+
'type': ['string', 'null'],
71+
'anyOf': [{'format': 'ipv4'}, {'format': 'ipv6'}],
72+
},
73+
'id': {'type': 'string', 'format': 'uuid'},
74+
'instance_id': {'type': ['string', 'null'], 'format': 'uuid'},
75+
'ip': {
76+
'type': 'string',
77+
'anyOf': [{'format': 'ipv4'}, {'format': 'ipv6'}],
78+
},
79+
'pool': {'type': 'string'},
80+
},
81+
'required': ['fixed_ip', 'id', 'instance_id', 'ip', 'pool'],
82+
'additionalProperties': False
83+
}
84+
85+
show_response = {
86+
'type': 'object',
87+
'properties': {
88+
'floating_ip': _floating_ip_response,
89+
},
90+
'required': ['floating_ip'],
91+
'additionalProperties': False,
92+
}
93+
94+
index_response = {
95+
'type': 'object',
96+
'properties': {
97+
'floating_ips': {
98+
'type': 'array',
99+
'items': _floating_ip_response,
100+
},
101+
},
102+
'required': ['floating_ips'],
103+
'additionalProperties': False,
104+
}
105+
106+
create_response = copy.deepcopy(show_response)
107+
108+
delete_response = {'type': 'null'}
109+
65110
add_floating_ip_response = {
66111
'type': 'null',
67112
}

nova/tests/unit/policies/test_floating_ips.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ def setUp(self):
9191

9292
@mock.patch('nova.network.neutron.API.get_floating_ip')
9393
def test_show_floating_ip_policy(self, mock_get):
94+
mock_get.return_value = {
95+
'fixed_ip_address': None,
96+
'floating_ip_address': '172.16.22.3',
97+
'id': uuids.floating_ip_id,
98+
'network_details': {'name': 'public'},
99+
'port_details': None,
100+
}
94101
rule_name = "os_compute_api:os-floating-ips:show"
95102
self.common_policy_auth(self.project_reader_authorized_contexts,
96103
rule_name, self.controller.show,
@@ -106,6 +113,13 @@ def test_index_floating_ip_policy(self, mock_get):
106113
@mock.patch('nova.network.neutron.API.get_floating_ip_by_address')
107114
@mock.patch('nova.network.neutron.API.allocate_floating_ip')
108115
def test_create_floating_ip_policy(self, mock_create, mock_get):
116+
mock_get.return_value = {
117+
'fixed_ip_address': None,
118+
'floating_ip_address': '172.16.22.3',
119+
'id': uuids.floating_ip_id,
120+
'network_details': {'name': 'public'},
121+
'port_details': None,
122+
}
109123
rule_name = "os_compute_api:os-floating-ips:create"
110124
self.common_policy_auth(self.member_authorized_contexts,
111125
rule_name, self.controller.create,

0 commit comments

Comments
 (0)