Esempio n. 1
0
 def test_public_network_association(self):
     """Makes sure that we can allocaate a public ip"""
     # TODO(vish): better way of adding floating ips
     self.context._project = self.projects[0]
     self.context.project_id = self.projects[0].id
     pubnet = IPy.IP(flags.FLAGS.floating_range)
     address = str(pubnet[0])
     try:
         db.floating_ip_get_by_address(context.get_admin_context(), address)
     except exception.NotFound:
         db.floating_ip_create(context.get_admin_context(),
                               {'address': address,
                                'host': FLAGS.host})
     float_addr = self.network.allocate_floating_ip(self.context,
                                                    self.projects[0].id)
     fix_addr = self._create_address(0)
     lease_ip(fix_addr)
     self.assertEqual(float_addr, str(pubnet[0]))
     self.network.associate_floating_ip(self.context, float_addr, fix_addr)
     address = db.instance_get_floating_address(context.get_admin_context(),
                                                self.instance_id)
     self.assertEqual(address, float_addr)
     self.network.disassociate_floating_ip(self.context, float_addr)
     address = db.instance_get_floating_address(context.get_admin_context(),
                                                self.instance_id)
     self.assertEqual(address, None)
     self.network.deallocate_floating_ip(self.context, float_addr)
     self.network.deallocate_fixed_ip(self.context, fix_addr)
     release_ip(fix_addr)
     db.floating_ip_destroy(context.get_admin_context(), float_addr)
Esempio n. 2
0
 def test_public_network_association(self):
     """Makes sure that we can allocaate a public ip"""
     # TODO(vish): better way of adding floating ips
     self.context._project = self.projects[0]
     self.context.project_id = self.projects[0].id
     pubnet = IPy.IP(flags.FLAGS.floating_range)
     address = str(pubnet[0])
     try:
         db.floating_ip_get_by_address(context.get_admin_context(), address)
     except exception.NotFound:
         db.floating_ip_create(context.get_admin_context(), {
             'address': address,
             'host': FLAGS.host
         })
     float_addr = self.network.allocate_floating_ip(self.context,
                                                    self.projects[0].id)
     fix_addr = self._create_address(0)
     lease_ip(fix_addr)
     self.assertEqual(float_addr, str(pubnet[0]))
     self.network.associate_floating_ip(self.context, float_addr, fix_addr)
     address = db.instance_get_floating_address(context.get_admin_context(),
                                                self.instance_id)
     self.assertEqual(address, float_addr)
     self.network.disassociate_floating_ip(self.context, float_addr)
     address = db.instance_get_floating_address(context.get_admin_context(),
                                                self.instance_id)
     self.assertEqual(address, None)
     self.network.deallocate_floating_ip(self.context, float_addr)
     self.network.deallocate_fixed_ip(self.context, fix_addr)
     release_ip(fix_addr)
     db.floating_ip_destroy(context.get_admin_context(), float_addr)
Esempio n. 3
0
 def _create_floating_ip(self):
     """Create a floating ip object."""
     host = "fake_host"
     db.floating_ip_create(self.context,
                           {'address': test_ipv4_address,
                           'host': host})
     db.floating_ip_create(self.context,
                           {'address': test_ipv6_address,
                           'host': host})
Esempio n. 4
0
 def test_too_many_addresses(self):
     address = '192.168.0.100'
     db.floating_ip_create(context.get_admin_context(), {
         'address': address,
         'project_id': self.project_id
     })
     self.assertRaises(quota.QuotaError, self.network.allocate_floating_ip,
                       self.context, self.project_id)
     db.floating_ip_destroy(context.get_admin_context(), address)
Esempio n. 5
0
 def _create_floating_ip(self):
     """Create a floating ip object."""
     host = "fake_host"
     db.floating_ip_create(self.context,
                           {'address': test_ipv4_address,
                           'host': host})
     db.floating_ip_create(self.context,
                           {'address': test_ipv6_address,
                           'host': host})
Esempio n. 6
0
 def test_too_many_addresses(self):
     address = "192.168.0.100"
     db.floating_ip_create(context.get_admin_context(), {"address": address, "host": FLAGS.host})
     float_addr = self.network.allocate_floating_ip(self.context, self.project.id)
     # NOTE(vish): This assert never fails. When cloud attempts to
     #             make an rpc.call, the test just finishes with OK. It
     #             appears to be something in the magic inline callbacks
     #             that is breaking.
     self.assertRaises(quota.QuotaError, network.API().allocate_floating_ip, self.context)
     db.floating_ip_destroy(context.get_admin_context(), address)
Esempio n. 7
0
 def test_too_many_addresses(self):
     address = '192.168.0.100'
     db.floating_ip_create(context.get_admin_context(),
                           {'address': address,
                            'project_id': self.project_id})
     self.assertRaises(quota.QuotaError,
                       self.network.allocate_floating_ip,
                       self.context,
                       self.project_id)
     db.floating_ip_destroy(context.get_admin_context(), address)
Esempio n. 8
0
 def test_describe_addresses(self):
     """Makes sure describe addresses runs without raising an exception"""
     address = "10.10.10.10"
     db.floating_ip_create(self.context,
                           {'address': address,
                            'host': self.network.host})
     self.cloud.allocate_address(self.context)
     self.cloud.describe_addresses(self.context)
     self.cloud.release_address(self.context,
                               public_ip=address)
     greenthread.sleep(0.3)
     db.floating_ip_destroy(self.context, address)
Esempio n. 9
0
 def test_describe_addresses(self):
     """Makes sure describe addresses runs without raising an exception"""
     address = "10.10.10.10"
     db.floating_ip_create(self.context, {
         'address': address,
         'host': self.network.host
     })
     self.cloud.allocate_address(self.context)
     self.cloud.describe_addresses(self.context)
     self.cloud.release_address(self.context, public_ip=address)
     greenthread.sleep(0.3)
     db.floating_ip_destroy(self.context, address)
Esempio n. 10
0
 def create(self, ip_range, pool=None, interface=None):
     """Creates floating ips for zone by range"""
     admin_context = context.get_admin_context()
     if not pool:
         pool = FLAGS.default_floating_pool
     if not interface:
         interface = FLAGS.public_interface
     for address in self.address_to_hosts(ip_range):
         db.floating_ip_create(admin_context,
                               {'address': str(address),
                                'pool': pool,
                                'interface': interface})
Esempio n. 11
0
 def test_too_many_addresses(self):
     address = '192.168.0.100'
     db.floating_ip_create(context.get_admin_context(), {
         'address': address,
         'host': FLAGS.host
     })
     float_addr = self.network.allocate_floating_ip(self.context,
                                                    self.project.id)
     # NOTE(vish): This assert never fails. When cloud attempts to
     #             make an rpc.call, the test just finishes with OK. It
     #             appears to be something in the magic inline callbacks
     #             that is breaking.
     self.assertRaises(quota.QuotaError,
                       network.API().allocate_floating_ip, self.context)
     db.floating_ip_destroy(context.get_admin_context(), address)
Esempio n. 12
0
    def test_ip_association_and_allocation_of_other_project(self):
        """Makes sure that we cannot deallocaate or disassociate
        a public ip of other project"""

        context1 = context.RequestContext("user", "project1")
        context2 = context.RequestContext("user", "project2")

        address = "1.2.3.4"
        float_addr = db.floating_ip_create(context1.elevated(), {"address": address, "project_id": context1.project_id})

        instance = db.instance_create(context1, {"project_id": "project1"})

        fix_addr = db.fixed_ip_associate_pool(context1.elevated(), 1, instance["id"])

        # Associate the IP with non-admin user context
        self.assertRaises(exception.NotAuthorized, self.network.associate_floating_ip, context2, float_addr, fix_addr)

        # Deallocate address from other project
        self.assertRaises(exception.NotAuthorized, self.network.deallocate_floating_ip, context2, float_addr)

        # Now Associates the address to the actual project
        self.network.associate_floating_ip(context1, float_addr, fix_addr)

        # Now try dis-associating from other project
        self.assertRaises(exception.NotAuthorized, self.network.disassociate_floating_ip, context2, float_addr)

        # Clean up the ip addresses
        self.network.deallocate_floating_ip(context1, float_addr)
        self.network.deallocate_fixed_ip(context1, fix_addr)
        db.floating_ip_destroy(context1.elevated(), float_addr)
        db.fixed_ip_disassociate(context1.elevated(), fix_addr)
Esempio n. 13
0
 def _create_floating_ip(self):
     """Create a floating ip object."""
     host = "fake_host"
     return db.floating_ip_create(self.context, {
         'address': self.address,
         'host': host
     })
Esempio n. 14
0
 def _create_floating_ip(self):
     """Create a floating ip object."""
     host = "fake_host"
     return db.floating_ip_create(self.context,
                                  {'address': self.floating_ip,
                                   'pool': 'nova',
                                   'host': host})
Esempio n. 15
0
def _setup_networking(instance_id, ip="1.2.3.4", flo_addr="1.2.1.2"):
    ctxt = context.get_admin_context()
    network_ref = db.project_get_networks(ctxt, "fake", associate=True)[0]
    vif = {"address": "56:12:12:12:12:12", "network_id": network_ref["id"], "instance_id": instance_id}
    vif_ref = db.virtual_interface_create(ctxt, vif)

    fixed_ip = {
        "address": ip,
        "network_id": network_ref["id"],
        "virtual_interface_id": vif_ref["id"],
        "allocated": True,
        "instance_id": instance_id,
    }
    db.fixed_ip_create(ctxt, fixed_ip)
    fix_ref = db.fixed_ip_get_by_address(ctxt, ip)
    db.floating_ip_create(ctxt, {"address": flo_addr, "fixed_ip_id": fix_ref["id"]})
Esempio n. 16
0
def _setup_networking(instance_id, ip='1.2.3.4', flo_addr='1.2.1.2'):
    ctxt = context.get_admin_context()
    network_ref = db.project_get_networks(ctxt,
                                           'fake',
                                           associate=True)[0]
    vif = {'address': '56:12:12:12:12:12',
           'network_id': network_ref['id'],
           'instance_id': instance_id}
    vif_ref = db.virtual_interface_create(ctxt, vif)

    fixed_ip = {'address': ip,
                'network_id': network_ref['id'],
                'virtual_interface_id': vif_ref['id'],
                'allocated': True,
                'instance_id': instance_id}
    db.fixed_ip_create(ctxt, fixed_ip)
    fix_ref = db.fixed_ip_get_by_address(ctxt, ip)
    db.floating_ip_create(ctxt, {'address': flo_addr,
                                 'fixed_ip_id': fix_ref['id']})
Esempio n. 17
0
def _setup_networking(instance_id, ip='1.2.3.4', flo_addr='1.2.1.2'):
    ctxt = context.get_admin_context()
    network_ref = db.project_get_networks(ctxt,
                                           'fake',
                                           associate=True)[0]
    vif = {'address': '56:12:12:12:12:12',
           'network_id': network_ref['id'],
           'instance_id': instance_id}
    vif_ref = db.virtual_interface_create(ctxt, vif)

    fixed_ip = {'address': ip,
                'network_id': network_ref['id'],
                'virtual_interface_id': vif_ref['id'],
                'allocated': True,
                'instance_id': instance_id}
    db.fixed_ip_create(ctxt, fixed_ip)
    fix_ref = db.fixed_ip_get_by_address(ctxt, ip)
    db.floating_ip_create(ctxt, {'address': flo_addr,
                                 'fixed_ip_id': fix_ref['id']})
Esempio n. 18
0
 def test_associate_disassociate_address(self):
     """Verifies associate runs cleanly without raising an exception"""
     address = "10.10.10.10"
     db.floating_ip_create(self.context, {
         'address': address,
         'host': self.network.host
     })
     self.cloud.allocate_address(self.context)
     inst = db.instance_create(self.context, {'host': self.compute.host})
     fixed = self.network.allocate_fixed_ip(self.context, inst['id'])
     ec2_id = ec2utils.id_to_ec2_id(inst['id'])
     self.cloud.associate_address(self.context,
                                  instance_id=ec2_id,
                                  public_ip=address)
     greenthread.sleep(0.3)
     self.cloud.disassociate_address(self.context, public_ip=address)
     self.cloud.release_address(self.context, public_ip=address)
     greenthread.sleep(0.3)
     self.network.deallocate_fixed_ip(self.context, fixed)
     db.instance_destroy(self.context, inst['id'])
     db.floating_ip_destroy(self.context, address)
Esempio n. 19
0
 def test_associate_disassociate_address(self):
     """Verifies associate runs cleanly without raising an exception"""
     address = "10.10.10.10"
     db.floating_ip_create(self.context,
                           {'address': address,
                            'host': self.network.host})
     self.cloud.allocate_address(self.context)
     inst = db.instance_create(self.context, {'host': self.compute.host})
     fixed = self.network.allocate_fixed_ip(self.context, inst['id'])
     ec2_id = cloud.id_to_ec2_id(inst['id'])
     self.cloud.associate_address(self.context,
                                  instance_id=ec2_id,
                                  public_ip=address)
     greenthread.sleep(0.3)
     self.cloud.disassociate_address(self.context,
                                     public_ip=address)
     self.cloud.release_address(self.context,
                               public_ip=address)
     greenthread.sleep(0.3)
     self.network.deallocate_fixed_ip(self.context, fixed)
     db.instance_destroy(self.context, inst['id'])
     db.floating_ip_destroy(self.context, address)
Esempio n. 20
0
    def test_post_live_migration_working_correctly(self):
        """Confirm post_live_migration() works as expected correctly."""
        dest = 'desthost'
        flo_addr = '1.2.1.2'

        # Preparing datas
        c = context.get_admin_context()
        instance_id = self._create_instance()
        i_ref = db.instance_get(c, instance_id)
        db.instance_update(c, i_ref['id'], {
            'state_description': 'migrating',
            'state': power_state.PAUSED
        })
        v_ref = db.volume_create(c, {'size': 1, 'instance_id': instance_id})
        fix_addr = db.fixed_ip_create(c, {
            'address': '1.1.1.1',
            'instance_id': instance_id
        })
        fix_ref = db.fixed_ip_get_by_address(c, fix_addr)
        flo_ref = db.floating_ip_create(c, {
            'address': flo_addr,
            'fixed_ip_id': fix_ref['id']
        })
        # reload is necessary before setting mocks
        i_ref = db.instance_get(c, instance_id)

        # Preparing mocks
        self.mox.StubOutWithMock(self.compute.volume_manager,
                                 'remove_compute_volume')
        for v in i_ref['volumes']:
            self.compute.volume_manager.remove_compute_volume(c, v['id'])
        self.mox.StubOutWithMock(self.compute.driver, 'unfilter_instance')
        self.compute.driver.unfilter_instance(i_ref, [])

        # executing
        self.mox.ReplayAll()
        ret = self.compute.post_live_migration(c, i_ref, dest)

        # make sure every data is rewritten to dest
        i_ref = db.instance_get(c, i_ref['id'])
        c1 = (i_ref['host'] == dest)
        flo_refs = db.floating_ip_get_all_by_host(c, dest)
        c2 = (len(flo_refs) != 0 and flo_refs[0]['address'] == flo_addr)

        # post operaton
        self.assertTrue(c1 and c2)
        db.instance_destroy(c, instance_id)
        db.volume_destroy(c, v_ref['id'])
        db.floating_ip_destroy(c, flo_addr)
Esempio n. 21
0
    def test_ip_association_and_allocation_of_other_project(self):
        """Makes sure that we cannot deallocaate or disassociate
        a public ip of other project"""

        context1 = context.RequestContext('user', 'project1')
        context2 = context.RequestContext('user', 'project2')

        address = '1.2.3.4'
        float_addr = db.floating_ip_create(context1.elevated(),
                {'address': address,
                 'project_id': context1.project_id})

        instance = db.instance_create(context1,
                {'project_id': 'project1'})

        fix_addr = db.fixed_ip_associate_pool(context1.elevated(),
                1, instance['id'])

        # Associate the IP with non-admin user context
        self.assertRaises(exception.NotAuthorized,
                          self.network.associate_floating_ip,
                          context2,
                          float_addr,
                          fix_addr)

        # Deallocate address from other project
        self.assertRaises(exception.NotAuthorized,
                          self.network.deallocate_floating_ip,
                          context2,
                          float_addr)

        # Now Associates the address to the actual project
        self.network.associate_floating_ip(context1, float_addr, fix_addr)

        # Now try dis-associating from other project
        self.assertRaises(exception.NotAuthorized,
                          self.network.disassociate_floating_ip,
                          context2,
                          float_addr)

        # Clean up the ip addresses
        self.network.deallocate_floating_ip(context1, float_addr)
        self.network.deallocate_fixed_ip(context1, fix_addr)
        db.floating_ip_destroy(context1.elevated(), float_addr)
        db.fixed_ip_disassociate(context1.elevated(), fix_addr)
Esempio n. 22
0
    def test_post_live_migration_working_correctly(self):
        """Confirm post_live_migration() works as expected correctly."""
        dest = 'desthost'
        flo_addr = '1.2.1.2'

        # Preparing datas
        c = context.get_admin_context()
        instance_id = self._create_instance()
        i_ref = db.instance_get(c, instance_id)
        db.instance_update(c, i_ref['id'], {'state_description': 'migrating',
                                            'state': power_state.PAUSED})
        v_ref = db.volume_create(c, {'size': 1, 'instance_id': instance_id})
        fix_addr = db.fixed_ip_create(c, {'address': '1.1.1.1',
                                          'instance_id': instance_id})
        fix_ref = db.fixed_ip_get_by_address(c, fix_addr)
        flo_ref = db.floating_ip_create(c, {'address': flo_addr,
                                        'fixed_ip_id': fix_ref['id']})
        # reload is necessary before setting mocks
        i_ref = db.instance_get(c, instance_id)

        # Preparing mocks
        self.mox.StubOutWithMock(self.compute.volume_manager,
                                 'remove_compute_volume')
        for v in i_ref['volumes']:
            self.compute.volume_manager.remove_compute_volume(c, v['id'])
        self.mox.StubOutWithMock(self.compute.driver, 'unfilter_instance')
        self.compute.driver.unfilter_instance(i_ref, [])

        # executing
        self.mox.ReplayAll()
        ret = self.compute.post_live_migration(c, i_ref, dest)

        # make sure every data is rewritten to dest
        i_ref = db.instance_get(c, i_ref['id'])
        c1 = (i_ref['host'] == dest)
        flo_refs = db.floating_ip_get_all_by_host(c, dest)
        c2 = (len(flo_refs) != 0 and flo_refs[0]['address'] == flo_addr)

        # post operaton
        self.assertTrue(c1 and c2)
        db.instance_destroy(c, instance_id)
        db.volume_destroy(c, v_ref['id'])
        db.floating_ip_destroy(c, flo_addr)
Esempio n. 23
0
 def test_get_counters_not_empty(self):
     db.floating_ip_create(self.context, {
         'address': '1.1.1.1',
         'host': self.manager.host,
     })
     db.floating_ip_create(self.context, {
         'address': '1.1.1.2',
         'host': self.manager.host + "randomstring",
     })
     db.floating_ip_create(self.context, {
         'address': '1.1.1.3',
         'host': self.manager.host + "randomstring",
     })
     counters = list(self.pollster.get_counters(self.manager, self.context))
     self.assertEqual(len(counters), 1)
     self.assertEqual(counters[0].resource_metadata['address'], '1.1.1.1')
Esempio n. 24
0
 def test_get_counters_not_empty(self):
     db.floating_ip_create(self.context,
                           {'address': '1.1.1.1',
                            'host': self.manager.host,
                            })
     db.floating_ip_create(self.context,
                           {'address': '1.1.1.2',
                            'host': self.manager.host + "randomstring",
                            })
     db.floating_ip_create(self.context,
                           {'address': '1.1.1.3',
                            'host': self.manager.host + "randomstring",
                            })
     counters = list(self.pollster.get_counters(self.manager, self.context))
     self.assertEqual(len(counters), 1)
     self.assertEqual(counters[0].resource_metadata['address'], '1.1.1.1')
Esempio n. 25
0
 def test_too_many_addresses(self):
     address = "192.168.0.100"
     db.floating_ip_create(context.get_admin_context(), {"address": address, "project_id": self.project_id})
     self.assertRaises(exception.QuotaError, self.network.allocate_floating_ip, self.context, self.project_id)
     db.floating_ip_destroy(context.get_admin_context(), address)
Esempio n. 26
0
 def _create_floating_ip(self):
     """Create a floating ip object."""
     host = "fake_host"
     return db.floating_ip_create(self.context, {"address": self.floating_ip, "pool": "nova", "host": host})