Esempio n. 1
0
 def setUp(self):
     super(FlatNetworkTestCase, self).setUp()
     self.network = network_manager.FlatManager(host=HOST)
     self.network.db = db
     self.context = context.RequestContext('testuser',
                                           'testproject',
                                           is_admin=False)
Esempio n. 2
0
def fake_get_instance_nw_info(stubs,
                              num_networks=1,
                              ips_per_vif=2,
                              floating_ips_per_fixed_ip=0):
    # stubs is the self.stubs from the test
    # ips_per_vif is the number of ips each vif will have
    # num_floating_ips is number of float ips for each fixed ip
    network = network_manager.FlatManager(host=HOST)
    network.db = db

    # reset the fixed and floating ip generators
    global floating_ip_id, fixed_ip_id
    floating_ip_id = floating_ip_ids()
    fixed_ip_id = fixed_ip_ids()

    def fixed_ips_fake(*args, **kwargs):
        return [
            next_fixed_ip(i, floating_ips_per_fixed_ip)
            for i in xrange(num_networks) for j in xrange(ips_per_vif)
        ]

    def virtual_interfaces_fake(*args, **kwargs):
        return [vif for vif in vifs(num_networks)]

    def instance_type_fake(*args, **kwargs):
        return flavor

    stubs.Set(db, 'fixed_ip_get_by_instance', fixed_ips_fake)
    stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interfaces_fake)
    stubs.Set(db, 'instance_type_get', instance_type_fake)

    return network.get_instance_nw_info(None, 0, 0, None)
Esempio n. 3
0
 def setUp(self):
     super(FlatNetworkTestCase, self).setUp()
     self.network = network_manager.FlatManager(host=HOST)
     temp = utils.import_object('nova.network.minidns.MiniDNS')
     self.network.instance_dns_manager = temp
     self.network.db = db
     self.context = context.RequestContext('testuser',
                                           'testproject',
                                           is_admin=False)
Esempio n. 4
0
def fake_get_instance_nw_info(stubs,
                              num_networks=1,
                              ips_per_vif=2,
                              floating_ips_per_fixed_ip=0):
    # stubs is the self.stubs from the test
    # ips_per_vif is the number of ips each vif will have
    # num_floating_ips is number of float ips for each fixed ip
    network = network_manager.FlatManager(host=HOST)
    network.db = db

    # reset the fixed and floating ip generators
    global floating_ip_id, fixed_ip_id
    floating_ip_id = floating_ip_ids()
    fixed_ip_id = fixed_ip_ids()

    networks = [fake_network(x) for x in xrange(num_networks)]

    def fixed_ips_fake(*args, **kwargs):
        return [
            next_fixed_ip(i, floating_ips_per_fixed_ip)
            for i in xrange(num_networks) for j in xrange(ips_per_vif)
        ]

    def floating_ips_fake(*args, **kwargs):
        return []

    def virtual_interfaces_fake(*args, **kwargs):
        return [vif for vif in vifs(num_networks)]

    def instance_type_fake(*args, **kwargs):
        return flavor

    def network_get_fake(context, network_id):
        nets = [n for n in networks if n['id'] == network_id]
        if not nets:
            raise exception.NetworkNotFound(network_id=network_id)
        return nets[0]

    def update_cache_fake(*args, **kwargs):
        pass

    stubs.Set(db, 'fixed_ip_get_by_instance', fixed_ips_fake)
    stubs.Set(db, 'floating_ip_get_by_fixed_address', floating_ips_fake)
    stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interfaces_fake)
    stubs.Set(db, 'instance_type_get', instance_type_fake)
    stubs.Set(db, 'network_get', network_get_fake)
    stubs.Set(db, 'instance_info_cache_update', update_cache_fake)

    context = nova.context.RequestContext('testuser',
                                          'testproject',
                                          is_admin=False)
    return network.get_instance_nw_info(context, 0, 0, 0, None)
Esempio n. 5
0
def fake_get_instance_nw_info(test,
                              num_networks=1,
                              ips_per_vif=2,
                              floating_ips_per_fixed_ip=0):
    # test is an instance of nova.test.TestCase
    # ips_per_vif is the number of ips each vif will have
    # num_floating_ips is number of float ips for each fixed ip
    network = network_manager.FlatManager(host=HOST)
    network.db = db

    # reset the fixed and floating ip generators
    global floating_ip_id, fixed_ip_id, fixed_ips
    floating_ip_id = floating_ip_ids()
    fixed_ip_id = fixed_ip_ids()
    fixed_ips = []

    def fixed_ips_fake(*args, **kwargs):
        global fixed_ips
        ips = [
            next_fixed_ip(i, floating_ips_per_fixed_ip)
            for i in range(1, num_networks + 1) for j in range(ips_per_vif)
        ]
        fixed_ips = ips
        return ips

    def update_cache_fake(*args, **kwargs):
        fake_info_cache = {
            'created_at': None,
            'updated_at': None,
            'deleted_at': None,
            'deleted': False,
            'instance_uuid': uuids.vifs_1,
            'network_info': '[]',
        }
        return fake_info_cache

    test.stub_out('nova.db.fixed_ip_get_by_instance', fixed_ips_fake)
    test.stub_out('nova.db.instance_info_cache_update', update_cache_fake)

    class FakeContext(nova.context.RequestContext):
        def is_admin(self):
            return True

    nw_model = network.get_instance_nw_info(
        FakeContext('fakeuser', 'fake_project'), 0, 3, None)
    return nw_model
Esempio n. 6
0
def fake_get_instance_nw_info(stubs,
                              num_networks=1,
                              ips_per_vif=2,
                              floating_ips_per_fixed_ip=0):
    # stubs is the self.stubs from the test
    # ips_per_vif is the number of ips each vif will have
    # num_floating_ips is number of float ips for each fixed ip
    network = network_manager.FlatManager(host=HOST)
    network.db = db

    # reset the fixed and floating ip generators
    global floating_ip_id, fixed_ip_id, fixed_ips
    floating_ip_id = floating_ip_ids()
    fixed_ip_id = fixed_ip_ids()
    fixed_ips = []

    def fixed_ips_fake(*args, **kwargs):
        global fixed_ips
        ips = [
            next_fixed_ip(i, floating_ips_per_fixed_ip)
            for i in xrange(1, num_networks + 1) for j in xrange(ips_per_vif)
        ]
        fixed_ips = ips
        return ips

    def update_cache_fake(*args, **kwargs):
        pass

    stubs.Set(db, 'fixed_ip_get_by_instance', fixed_ips_fake)
    stubs.Set(db, 'instance_info_cache_update', update_cache_fake)

    class FakeContext(nova.context.RequestContext):
        def is_admin(self):
            return True

    nw_model = network.get_instance_nw_info(
        FakeContext('fakeuser', 'fake_project'), 0, 3, None)
    return nw_model
Esempio n. 7
0
def fake_get_instance_nw_info(stubs,
                              num_networks=1,
                              ips_per_vif=2,
                              floating_ips_per_fixed_ip=0):
    # stubs is the self.stubs from the test
    # ips_per_vif is the number of ips each vif will have
    # num_floating_ips is number of float ips for each fixed ip
    network = network_manager.FlatManager(host=HOST)
    network.db = db

    # reset the fixed and floating ip generators
    global floating_ip_id, fixed_ip_id, fixed_ips
    floating_ip_id = floating_ip_ids()
    fixed_ip_id = fixed_ip_ids()
    fixed_ips = []

    networks = [fake_network(x) for x in xrange(1, num_networks + 1)]

    def fixed_ips_fake(*args, **kwargs):
        global fixed_ips
        ips = [
            next_fixed_ip(i, floating_ips_per_fixed_ip)
            for i in xrange(1, num_networks + 1) for j in xrange(ips_per_vif)
        ]
        fixed_ips = ips
        return ips

    def floating_ips_fake(context, address):
        for ip in fixed_ips:
            if address == ip['address']:
                return ip['floating_ips']
        return []

    def fixed_ips_v6_fake():
        return ['2001:db8:0:%x::1' % i for i in xrange(1, num_networks + 1)]

    def virtual_interfaces_fake(*args, **kwargs):
        return [vif for vif in vifs(num_networks)]

    def vif_by_uuid_fake(context, uuid):
        return {
            'id': 1,
            'address': 'DE:AD:BE:EF:00:01',
            'uuid': uuid,
            'network_id': 1,
            'network': None,
            'instance_uuid': 'fake-uuid'
        }

    def network_get_fake(context, network_id, project_only='allow_none'):
        nets = [n for n in networks if n['id'] == network_id]
        if not nets:
            raise exception.NetworkNotFound(network_id=network_id)
        return nets[0]

    def update_cache_fake(*args, **kwargs):
        pass

    def get_subnets_by_net_id(self, context, project_id, network_uuid,
                              vif_uuid):
        i = int(network_uuid[-2:])
        subnet_v4 = dict(cidr='192.168.%d.0/24' % i,
                         dns1='192.168.%d.3' % i,
                         dns2='192.168.%d.4' % i,
                         gateway='192.168.%d.1' % i)

        subnet_v6 = dict(cidr='2001:db8:0:%x::/64' % i,
                         gateway='2001:db8:0:%x::1' % i)
        return [subnet_v4, subnet_v6]

    def get_network_by_uuid(context, uuid):
        return dict(id=1, cidr_v6='fe80::/64', bridge='br0', label='public')

    def get_v4_fake(*args, **kwargs):
        ips = fixed_ips_fake(*args, **kwargs)
        return [ip['address'] for ip in ips]

    def get_v6_fake(*args, **kwargs):
        return fixed_ips_v6_fake()

    stubs.Set(db, 'fixed_ip_get_by_instance', fixed_ips_fake)
    stubs.Set(db, 'floating_ip_get_by_fixed_address', floating_ips_fake)
    stubs.Set(db, 'virtual_interface_get_by_uuid', vif_by_uuid_fake)
    stubs.Set(db, 'network_get_by_uuid', get_network_by_uuid)
    stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interfaces_fake)
    stubs.Set(db, 'network_get', network_get_fake)
    stubs.Set(db, 'instance_info_cache_update', update_cache_fake)

    stubs.Set(nova_ipam_lib.NeutronNovaIPAMLib, 'get_subnets_by_net_id',
              get_subnets_by_net_id)
    stubs.Set(nova_ipam_lib.NeutronNovaIPAMLib, 'get_v4_ips_by_interface',
              get_v4_fake)
    stubs.Set(nova_ipam_lib.NeutronNovaIPAMLib, 'get_v6_ips_by_interface',
              get_v6_fake)

    class FakeContext(nova.context.RequestContext):
        def is_admin(self):
            return True

    nw_model = network.get_instance_nw_info(
        FakeContext('fakeuser', 'fake_project'), 0, 3, None)
    return nw_model
Esempio n. 8
0
 def setUp(self):
     super(FlatNetworkTestCase, self).setUp()
     self.network = network_manager.FlatManager(host=HOST)
     self.network.db = db