def test_attach_interface_no_more_fixed_ips(self, attach_mock, get_mock):
     fake_instance = objects.Instance(uuid=FAKE_UUID1)
     get_mock.return_value = fake_instance
     attach_mock.side_effect = exception.NoMoreFixedIps(net=FAKE_NET_ID1)
     body = {}
     self.assertRaises(exc.HTTPBadRequest,
                       self.attachments.create,
                       self.req,
                       FAKE_UUID1,
                       body=body)
     ctxt = self.req.environ['nova.context']
     attach_mock.assert_called_once_with(ctxt, fake_instance, None, None,
                                         None)
     get_mock.assert_called_once_with(ctxt,
                                      FAKE_UUID1,
                                      want_objects=True,
                                      expected_attrs=None)
Пример #2
0
 def _create_port(self,
                  client,
                  tenant_id,
                  network_id,
                  port_req_body,
                  fixed_ip=None,
                  security_group_ids=None,
                  dhcp_opts=None):
     try:
         if fixed_ip:
             port_req_body['port']['fixed_ips'] = [{'ip_address': fixed_ip}]
         port_req_body['port']['network_id'] = network_id
         port_req_body['port']['admin_state_up'] = True
         port_req_body['port']['tenant_id'] = tenant_id
         if security_group_ids:
             port_req_body['port']['security_groups'] = security_group_ids
         if dhcp_opts is not None:
             port_req_body['port']['extra_dhcp_opts'] = dhcp_opts
         port_id = client.create_port(port_req_body)['port']['id']
         LOG.debug('Successfully created port: %s', port_id)
         return port_id
     except neutron_client_exc.OverQuotaClient:
         LOG.warning(
             _LW('Neutron error: Port quota exceeded in tenant: %s'),
             port_req_body['port']['tenant_id'])
         raise exception.PortLimitExceeded()
     except neutron_client_exc.IpAddressGenerationFailureClient:
         LOG.warning(_LW('Neutron error: No more fixed IPs in network: %s'),
                     network_id)
         raise exception.NoMoreFixedIps()
     except neutron_client_exc.MacAddressInUseClient:
         LOG.warning(
             _LW('Neutron error: MAC address %(mac)s is already '
                 'in use on network %(network)s.') % {
                     'mac': mac_address,
                     'network': network_id
                 })
         raise exception.PortInUse(port_id=mac_address)
     except neutron_client_exc.NeutronClientException:
         with excutils.save_and_reraise_exception():
             LOG.exception(_LE('Neutron error creating port on network %s'),
                           network_id)
Пример #3
0
def fake_fixed_ip_associate(context, address, instance_id):
    ips = filter(lambda i: i['address'] == address, fixed_ips)
    if not ips:
        raise exception.NoMoreFixedIps(net='fake_net')
    ips[0]['instance'] = True
    ips[0]['instance_id'] = instance_id
Пример #4
0
def fake_fixed_ip_associate(context, address, instance_id):
    ips = [i for i in fixed_ips if i['address'] == address]
    if not ips:
        raise exception.NoMoreFixedIps(net='fake_net')
    ips[0]['instance'] = True
    ips[0]['instance_id'] = instance_id