コード例 #1
0
ファイル: test_network.py プロジェクト: anotherjesse/nova
 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)
コード例 #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)
コード例 #3
0
ファイル: test_network.py プロジェクト: nicoleLiu/nova
    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)
コード例 #4
0
ファイル: test_quota.py プロジェクト: lerner/osc-robot-nova
 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)
コード例 #5
0
ファイル: test_quota.py プロジェクト: AsherBond/dodai-compute
 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)
コード例 #6
0
ファイル: test_quota.py プロジェクト: superstack/nova
 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)
コード例 #7
0
ファイル: test_cloud.py プロジェクト: yosh/nova
 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)
コード例 #8
0
ファイル: test_cloud.py プロジェクト: septimius/nova
 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)
コード例 #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)
コード例 #10
0
ファイル: test_quota.py プロジェクト: septimius/nova
 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)
コード例 #11
0
ファイル: test_network.py プロジェクト: lerner/osc-robot-nova
    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)
コード例 #12
0
ファイル: test_compute.py プロジェクト: cp16net/reddwarf
    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)
コード例 #13
0
ファイル: test_cloud.py プロジェクト: septimius/nova
 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)
コード例 #14
0
ファイル: test_cloud.py プロジェクト: yosh/nova
 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)
コード例 #15
0
ファイル: test_floating_ips.py プロジェクト: A7Zulu/nova
 def _delete_floating_ip(self):
     db.floating_ip_destroy(self.context, self.floating_ip)
コード例 #16
0
 def destroy(cls, context, address):
     db.floating_ip_destroy(context, str(address))
コード例 #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)
コード例 #18
0
ファイル: wic_floating.py プロジェクト: pubfox/webservices
 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))
コード例 #19
0
ファイル: test_quota.py プロジェクト: renuka-apte/nova
 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)
コード例 #20
0
ファイル: test_floating_ip_dns.py プロジェクト: rbenali/nova
 def _delete_floating_ip(self):
     db.floating_ip_destroy(self.context, testaddress)
コード例 #21
0
 def _delete_floating_ip(self):
     db.floating_ip_destroy(self.context, self.floating_ip)
コード例 #22
0
ファイル: floating_ip.py プロジェクト: EliseCheng/nova
 def destroy(cls, context, address):
     db.floating_ip_destroy(context, str(address))