Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 3
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)
Ejemplo 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)
Ejemplo n.º 5
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)
Ejemplo 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)
Ejemplo n.º 7
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)
Ejemplo 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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
 def _delete_floating_ip(self):
     db.floating_ip_destroy(self.context, self.floating_ip)
Ejemplo n.º 16
0
 def destroy(cls, context, address):
     db.floating_ip_destroy(context, str(address))
Ejemplo n.º 17
0
 def _delete_floating_ip(self):
     db.floating_ip_destroy(self.context, test_ipv4_address)
     db.floating_ip_destroy(self.context, test_ipv6_address)
Ejemplo n.º 18
0
 def delete(self, ip_range):
     """Deletes floating ips by range"""
     for address in self.address_to_hosts(ip_range):
         db.floating_ip_destroy(context.get_admin_context(),
                                str(address))
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
 def _delete_floating_ip(self):
     db.floating_ip_destroy(self.context, testaddress)
Ejemplo n.º 21
0
 def _delete_floating_ip(self):
     db.floating_ip_destroy(self.context, self.floating_ip)
Ejemplo n.º 22
0
 def destroy(cls, context, address):
     db.floating_ip_destroy(context, str(address))