Пример #1
0
    def test_add_fixed_ip_instance_without_vpn_requested_networks(self):
        self.mox.StubOutWithMock(db, 'network_get')
        self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(db,
                              'virtual_interface_get_by_instance_and_network')
        self.mox.StubOutWithMock(db, 'fixed_ip_update')

        db.fixed_ip_update(mox.IgnoreArg(),
                           mox.IgnoreArg(),
                           mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
                mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})

        db.instance_get(mox.IgnoreArg(),
                        mox.IgnoreArg()).AndReturn({'security_groups':
                                                             [{'id': 0}]})
        db.fixed_ip_associate_pool(mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn('192.168.0.101')
        db.network_get(mox.IgnoreArg(),
                       mox.IgnoreArg()).AndReturn(networks[0])
        self.mox.ReplayAll()
        self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
                                              networks[0]['id'])
Пример #2
0
    def test_add_fixed_ip_instance_without_vpn_requested_networks(self):
        self.mox.StubOutWithMock(db, 'network_get')
        self.mox.StubOutWithMock(db, 'network_update')
        self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(
            db, 'virtual_interface_get_by_instance_and_network')
        self.mox.StubOutWithMock(db, 'fixed_ip_update')

        db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(
            mox.IgnoreArg(), mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn({'id': 0})

        db.instance_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(
            {'security_groups': [{
                'id': 0
            }]})
        db.instance_get(self.context, 1).AndReturn({'display_name': HOST})
        db.fixed_ip_associate_pool(mox.IgnoreArg(), mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn('192.168.0.101')
        db.network_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(networks[0])
        db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.mox.ReplayAll()
        self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
                                              networks[0]['id'])
Пример #3
0
    def test_instance_dns(self):
        fixedip = '192.168.0.101'
        self.mox.StubOutWithMock(db, 'network_get')
        self.mox.StubOutWithMock(db, 'network_update')
        self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(
            db, 'virtual_interface_get_by_instance_and_network')
        self.mox.StubOutWithMock(db, 'fixed_ip_update')

        db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(
            mox.IgnoreArg(), mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn({'id': 0})

        db.instance_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(
            {'security_groups': [{
                'id': 0
            }]})

        db.instance_get(self.context, 1).AndReturn({'display_name': HOST})
        db.fixed_ip_associate_pool(mox.IgnoreArg(), mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(fixedip)
        db.network_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(networks[0])
        db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.mox.ReplayAll()
        self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
                                              networks[0]['id'])
        addresses = self.network.instance_dns_manager.get_entries_by_name(HOST)
        self.assertEqual(len(addresses), 1)
        self.assertEqual(addresses[0], fixedip)
Пример #4
0
    def test_instance_dns(self):
        fixedip = '192.168.0.101'
        self.mox.StubOutWithMock(db, 'network_get')
        self.mox.StubOutWithMock(db, 'network_update')
        self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(db,
                              'virtual_interface_get_by_instance_and_network')
        self.mox.StubOutWithMock(db, 'fixed_ip_update')

        db.fixed_ip_update(mox.IgnoreArg(),
                           mox.IgnoreArg(),
                           mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
                mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})

        db.instance_get(mox.IgnoreArg(),
                        mox.IgnoreArg()).AndReturn({'security_groups':
                                                             [{'id': 0}]})

        db.instance_get(self.context,
                        1).AndReturn({'display_name': HOST})
        db.fixed_ip_associate_pool(mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn(fixedip)
        db.network_get(mox.IgnoreArg(),
                       mox.IgnoreArg()).AndReturn(networks[0])
        db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        self.mox.ReplayAll()
        self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
                                              networks[0]['id'])
        addresses = self.network.instance_dns_manager.get_entries_by_name(HOST)
        self.assertEqual(len(addresses), 1)
        self.assertEqual(addresses[0], fixedip)
Пример #5
0
    def test_vpn_allocate_fixed_ip(self):
        self.mox.StubOutWithMock(db, "fixed_ip_associate")
        self.mox.StubOutWithMock(db, "fixed_ip_update")
        self.mox.StubOutWithMock(db, "virtual_interface_get_by_instance_and_network")

        db.fixed_ip_associate(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), reserved=True).AndReturn("192.168.0.1")
        db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(
            {"id": 0}
        )
        self.mox.ReplayAll()

        network = dict(networks[0])
        network["vpn_private_address"] = "192.168.0.2"
        self.network.allocate_fixed_ip(None, 0, network, vpn=True)
Пример #6
0
    def test_allocate_fixed_ip(self):
        self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
        self.mox.StubOutWithMock(db, 'fixed_ip_update')
        self.mox.StubOutWithMock(
            db, 'virtual_interface_get_by_instance_and_network')

        db.fixed_ip_associate_pool(mox.IgnoreArg(), mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn('192.168.0.1')
        db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(
            mox.IgnoreArg(), mox.IgnoreArg(),
            mox.IgnoreArg()).AndReturn({'id': 0})
        self.mox.ReplayAll()

        network = dict(networks[0])
        network['vpn_private_address'] = '192.168.0.2'
        self.network.allocate_fixed_ip(None, 0, network)
Пример #7
0
    def test_add_fixed_ip_instance_without_vpn_requested_networks(self):
        self.mox.StubOutWithMock(db, "network_get")
        self.mox.StubOutWithMock(db, "fixed_ip_associate_pool")
        self.mox.StubOutWithMock(db, "instance_get")
        self.mox.StubOutWithMock(db, "virtual_interface_get_by_instance_and_network")
        self.mox.StubOutWithMock(db, "fixed_ip_update")

        db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(
            {"id": 0}
        )

        db.instance_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({"security_groups": [{"id": 0}]})
        db.fixed_ip_associate_pool(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn("192.168.0.101")
        db.network_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(networks[0])
        self.mox.ReplayAll()
        self.network.add_fixed_ip_to_instance(self.context, 1, HOST, networks[0]["id"])
Пример #8
0
    def test_allocate_fixed_ip(self):
        self.mox.StubOutWithMock(db, "fixed_ip_associate_pool")
        self.mox.StubOutWithMock(db, "fixed_ip_update")
        self.mox.StubOutWithMock(db, "virtual_interface_get_by_instance_and_network")
        self.mox.StubOutWithMock(db, "instance_get")

        db.instance_get(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({"security_groups": [{"id": 0}]})
        db.fixed_ip_associate_pool(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn("192.168.0.1")
        db.fixed_ip_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(
            {"id": 0}
        )
        self.mox.ReplayAll()

        network = dict(networks[0])
        network["vpn_private_address"] = "192.168.0.2"
        self.network.allocate_fixed_ip(self.context, 0, network)
Пример #9
0
    def test_allocate_fixed_ip(self):
        self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
        self.mox.StubOutWithMock(db, 'fixed_ip_update')
        self.mox.StubOutWithMock(db,
                              'virtual_interface_get_by_instance_and_network')

        db.fixed_ip_associate_pool(mox.IgnoreArg(),
                                   mox.IgnoreArg(),
                                   mox.IgnoreArg()).AndReturn('192.168.0.1')
        db.fixed_ip_update(mox.IgnoreArg(),
                           mox.IgnoreArg(),
                           mox.IgnoreArg())
        db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
                mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
        self.mox.ReplayAll()

        network = dict(networks[0])
        network['vpn_private_address'] = '192.168.0.2'
        self.network.allocate_fixed_ip(None, 0, network)
 def get_by_instance_and_network(cls, context, instance_uuid, network_id):
     db_vif = db.virtual_interface_get_by_instance_and_network(
         context, instance_uuid, network_id)
     if db_vif:
         return cls._from_db_object(context, cls(), db_vif)
 def get_by_instance_and_network(cls, context, instance_uuid, network_id):
     db_vif = db.virtual_interface_get_by_instance_and_network(context,
             instance_uuid, network_id)
     if db_vif:
         return cls._from_db_object(context, cls(), db_vif)