diff --git a/neutron/plugins/cisco/n1kv/n1kv_client.py b/neutron/plugins/cisco/n1kv/n1kv_client.py index 29b4e0712..f41761c25 100644 --- a/neutron/plugins/cisco/n1kv/n1kv_client.py +++ b/neutron/plugins/cisco/n1kv/n1kv_client.py @@ -333,6 +333,8 @@ class Client(object): 'dhcp': subnet['enable_dhcp'], 'dnsServersList': subnet['dns_nameservers'], 'networkAddress': network_address, + 'netSegmentName': subnet['network_id'], + 'id': subnet['id'], 'tenantId': subnet['tenant_id']} return self._post(self.ip_pool_path % subnet['id'], body=body) diff --git a/neutron/tests/unit/cisco/n1kv/fake_client.py b/neutron/tests/unit/cisco/n1kv/fake_client.py index f1d621234..1a3c49455 100755 --- a/neutron/tests/unit/cisco/n1kv/fake_client.py +++ b/neutron/tests/unit/cisco/n1kv/fake_client.py @@ -28,7 +28,11 @@ _resource_metadata = {'port': ['id', 'macAddress', 'ipAddress', 'subnetId'], 'networkSegment', 'portProfile', 'portProfileId', 'tenantId', 'portId', 'macAddress', - 'ipAddress', 'subnetId']} + 'ipAddress', 'subnetId'], + 'subnet': ['addressRangeStart', 'addressRangeEnd', + 'ipAddressSubnet', 'description', 'gateway', + 'dhcp', 'dnsServersList', 'networkAddress', + 'netSegmentName', 'id', 'tenantId']} class TestClient(n1kv_client): @@ -85,6 +89,10 @@ def _validate_resource(action, body=None): port_set = set(_resource_metadata['port']) if body_set - port_set: raise c_exc.VSMError(reason='Invalid Request') + elif 'subnet' in action: + subnet_set = set(_resource_metadata['subnet']) + if body_set - subnet_set: + raise c_exc.VSMError(reason='Invalid Request') else: return diff --git a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py index b0db663ed..5520ad0e3 100644 --- a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py +++ b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py @@ -821,7 +821,18 @@ class TestN1kvNetworks(test_plugin.TestNetworksV2, class TestN1kvSubnets(test_plugin.TestSubnetsV2, N1kvPluginTestCase): - pass + def test_create_subnet_with_invalid_parameters(self): + """Test subnet creation with invalid parameters sent to the VSM.""" + with self.network() as network: + client_patch = patch(n1kv_client.__name__ + ".Client", + new=fake_client.TestClientInvalidRequest) + client_patch.start() + data = {'subnet': {'network_id': network['network']['id'], + 'cidr': "10.0.0.0/24"}} + subnet_req = self.new_create_request('subnets', data) + subnet_resp = subnet_req.get_response(self.api) + # Subnet creation should fail due to invalid network name + self.assertEqual(subnet_resp.status_int, 400) class TestN1kvL3Test(test_l3_plugin.L3NatExtensionTestCase):