Beispiel #1
0
 def __init__(self, stubs=None):
     self.db = self.FakeDB()
     if stubs:
         stubs.Set(vif_obj, 'db', self.db)
     self.deallocate_called = None
     self.deallocate_fixed_ip_calls = []
     self.network_rpcapi = network_rpcapi.NetworkAPI()
Beispiel #2
0
 def __init__(self, **kwargs):
     self.network_rpcapi = network_rpcapi.NetworkAPI()
     helper = utils.ExceptionHelper
     # NOTE(vish): this local version of floating_manager has to convert
     #             ClientExceptions back since they aren't going over rpc.
     self.floating_manager = helper(floating_ips.LocalManager())
     super(API, self).__init__(**kwargs)
Beispiel #3
0
 def __init__(self):
     super(LocalManager, self).__init__()
     # NOTE(vish): setting the host to none ensures that the actual
     #             l3driver commands for l3 are done via rpc.
     self.host = None
     self.servicegroup_api = servicegroup.API()
     self.network_rpcapi = network_rpcapi.NetworkAPI()
     self.floating_dns_manager = importutils.import_object(
             CONF.floating_ip_dns_manager)
     self.instance_dns_manager = importutils.import_object(
             CONF.instance_dns_manager)
     self.notifier = rpc.get_notifier('network', CONF.host)
Beispiel #4
0
    def _test_network_api(self, method, rpc_method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')

        rpcapi = network_rpcapi.NetworkAPI()
        self.assertIsNotNone(rpcapi.client)
        self.assertEqual(rpcapi.client.target.topic, CONF.network_topic)

        expected_retval = 'foo' if rpc_method == 'call' else None
        expected_version = kwargs.pop('version', None)
        expected_fanout = kwargs.pop('fanout', None)
        expected_kwargs = kwargs.copy()

        for k, v in expected_kwargs.items():
            if isinstance(v, self.DefaultArg):
                expected_kwargs[k] = v.value
                kwargs.pop(k)

        prepare_kwargs = {}
        if expected_version:
            prepare_kwargs['version'] = expected_version
        if expected_fanout:
            prepare_kwargs['fanout'] = True

        if 'source_compute' in expected_kwargs:
            # Fix up for migrate_instance_* calls.
            expected_kwargs['source'] = expected_kwargs.pop('source_compute')
            expected_kwargs['dest'] = expected_kwargs.pop('dest_compute')

        targeted_methods = [
            'lease_fixed_ip',
            'release_fixed_ip',
            'rpc_setup_network_on_host',
            '_rpc_allocate_fixed_ip',
            'deallocate_fixed_ip',
            'update_dns',
            '_associate_floating_ip',
            '_disassociate_floating_ip',
            'lease_fixed_ip',
            'release_fixed_ip',
            'migrate_instance_start',
            'migrate_instance_finish',
            'allocate_for_instance',
            'deallocate_for_instance',
        ]
        targeted_by_instance = ['deallocate_for_instance']
        if method in targeted_methods and ('host' in expected_kwargs
                                           or 'instance' in expected_kwargs):
            if method in targeted_by_instance:
                host = expected_kwargs['instance']['host']
            else:
                host = expected_kwargs['host']
                if method not in [
                        'allocate_for_instance', 'deallocate_fixed_ip'
                ]:
                    expected_kwargs.pop('host')
            if CONF.multi_host:
                prepare_kwargs['server'] = host

        self.mox.StubOutWithMock(rpcapi, 'client')

        version_check = [
            'deallocate_for_instance',
            'deallocate_fixed_ip',
            'allocate_for_instance',
        ]
        if method in version_check:
            rpcapi.client.can_send_version(mox.IgnoreArg()).AndReturn(True)

        if prepare_kwargs:
            rpcapi.client.prepare(**prepare_kwargs).AndReturn(rpcapi.client)

        rpc_method = getattr(rpcapi.client, rpc_method)
        rpc_method(ctxt, method, **expected_kwargs).AndReturn('foo')

        self.mox.ReplayAll()

        retval = getattr(rpcapi, method)(ctxt, **kwargs)
        self.assertEqual(retval, expected_retval)
Beispiel #5
0
def del_lease(mac, ip_address):
    """Called when a lease expires."""
    api = network_rpcapi.NetworkAPI()
    api.release_fixed_ip(context.get_admin_context(), ip_address, CONF.host)
Beispiel #6
0
def add_lease(mac, ip_address):
    """Set the IP that was assigned by the DHCP server."""
    api = network_rpcapi.NetworkAPI()
    api.lease_fixed_ip(context.get_admin_context(), ip_address, CONF.host)