def test_list_as_tuples(self, is_neutron): requests = objects.NetworkRequestList(objects=[ objects.NetworkRequest(network_id='123'), objects.NetworkRequest(network_id='456') ]) self.assertEqual([('123', None, None, None), ('456', None, None, None)], requests.as_tuples())
def test_is_single_unspecified(self): requests = objects.NetworkRequestList( objects=[objects.NetworkRequest(network_id='123')]) self.assertFalse(requests.is_single_unspecified) requests = objects.NetworkRequestList( objects=[objects.NetworkRequest(), objects.NetworkRequest()]) self.assertFalse(requests.is_single_unspecified) requests = objects.NetworkRequestList( objects=[objects.NetworkRequest()]) self.assertTrue(requests.is_single_unspecified)
def _get_requested_networks(self, requested_networks): """Create a list of requested networks from the networks attribute.""" networks = [] network_uuids = [] for network in requested_networks: request = objects.NetworkRequest() try: try: request.port_id = network.get('port', None) except ValueError: msg = _("Bad port format: port uuid is " "not in proper format " "(%s)") % network.get('port') raise exc.HTTPBadRequest(explanation=msg) if request.port_id: request.network_id = None if not utils.is_neutron(): # port parameter is only for neutron v2.0 msg = _("Unknown argument : port") raise exc.HTTPBadRequest(explanation=msg) else: request.network_id = network['uuid'] if (not request.port_id and not uuidutils.is_uuid_like(request.network_id)): br_uuid = request.network_id.split('-', 1)[-1] if not uuidutils.is_uuid_like(br_uuid): msg = _("Bad networks format: network uuid is " "not in proper format " "(%s)") % request.network_id raise exc.HTTPBadRequest(explanation=msg) # fixed IP address is optional # if the fixed IP address is not provided then # it will use one of the available IP address from the network try: request.address = network.get('fixed_ip', None) except ValueError: msg = _("Invalid fixed IP address (%s)") % request.address raise exc.HTTPBadRequest(explanation=msg) # duplicate networks are allowed only for neutron v2.0 if (not utils.is_neutron() and request.network_id and request.network_id in network_uuids): expl = (_("Duplicate networks" " (%s) are not allowed") % request.network_id) raise exc.HTTPBadRequest(explanation=expl) network_uuids.append(request.network_id) networks.append(request) except KeyError as key: expl = _('Bad network format: missing %s') % key raise exc.HTTPBadRequest(explanation=expl) except TypeError: expl = _('Bad networks format') raise exc.HTTPBadRequest(explanation=expl) return objects.NetworkRequestList(objects=networks)
def test_to_tuple_neutron(self): request = objects.NetworkRequest( network_id='123', address='1.2.3.4', port_id=FAKE_UUID, ) with mock.patch('patron.utils.is_neutron', return_value=True): self.assertEqual(('123', '1.2.3.4', FAKE_UUID, None), request.to_tuple())
def test_load(self): request = objects.NetworkRequest() self.assertIsNone(request.port_id)
def test_basic(self): request = objects.NetworkRequest() request.network_id = '456' request.address = '1.2.3.4' request.port_id = FAKE_UUID