예제 #1
0
    def disassociate(cls, context, address):
        db_fixed = db.floating_ip_disassociate(context, str(address))

        return cls(context=context, address=address,
                   fixed_ip_id=db_fixed['id'],
                   fixed_ip=objects.FixedIP._from_db_object(
                       context, objects.FixedIP(context), db_fixed,
                       expected_attrs=['network']))
예제 #2
0
 def test_get_instance_by_floating_address(self, mock_get_by_floating):
     mock_get_by_floating.return_value = objects.FixedIP(
         instance_uuid = uuids.instance)
     self.assertEqual(uuids.instance,
                      self.network_api.get_instance_id_by_floating_address(
                          self.context, mock.sentinel.floating))
     mock_get_by_floating.assert_called_once_with(self.context,
                                                  mock.sentinel.floating)
예제 #3
0
    def test_translate_floating_ip_bad_instance_and_address(self):
        fip = objects.FixedIP()
        floater = self._build_floating_ip('10.0.0.2', fip)

        result = self.floating_ips._translate_floating_ip_view(floater)

        expected = self._build_expected(floater, None, None)
        self._test_result(expected, result)
예제 #4
0
    def test_translate_floating_ip_bad_instance_id(self):
        fip = objects.FixedIP(address='192.168.1.2')
        floater = self._build_floating_ip('10.0.0.2', fip)

        result = self.floating_ips._translate_floating_ip_view(floater)

        expected = self._build_expected(floater, fip.address, None)
        self._test_result(expected, result)
예제 #5
0
    def test_translate_floating_ip_view_obj(self):
        fip = objects.FixedIP(address='192.168.1.2', instance_uuid=FAKE_UUID)
        floater = self._build_floating_ip('10.0.0.2', fip)

        result = self.floating_ips._translate_floating_ip_view(floater)

        expected = self._build_expected(floater, fip.address,
                                        fip.instance_uuid)
        self._test_result(expected, result)
예제 #6
0
 def test_backport_fixedip_1_1(self):
     floating = objects.FloatingIP()
     fixed = objects.FixedIP()
     floating.fixed_ip = fixed
     with mock.patch.object(fixed, 'obj_make_compatible') as compat:
         primitive = {'fixed_ip': {'nova_object.data': {}}}
         floating.obj_make_compatible(primitive, '1.1')
         compat.assert_called_once_with(primitive['fixed_ip'], '1.1')
         self.assertEqual('1.1',
                          primitive['fixed_ip']['nova_object.version'])
예제 #7
0
 def test_backport_fixedip_1_1(self):
     floating = objects.FloatingIP()
     fixed = objects.FixedIP()
     floating.fixed_ip = fixed
     versions = ovo_base.obj_tree_get_versions('FloatingIP')
     versions['FixedIP'] = '1.1'
     primitive = floating.obj_to_primitive(target_version='1.1',
                                           version_manifest=versions)
     self.assertEqual('1.1',
         primitive['nova_object.data']['fixed_ip']['nova_object.version'])
예제 #8
0
 def _test_is_multi_host_network_has_project_id(self, is_multi_host,
                                                net_get, fip_get):
     net_get.return_value = objects.Network(
         id=123, project_id=self.context.project_id,
         multi_host=is_multi_host)
     fip_get.return_value = [
         objects.FixedIP(network_id=123, instance_uuid=FAKE_UUID)]
     instance = {'uuid': FAKE_UUID}
     result = self.network_api._is_multi_host(self.context, instance)
     self.assertEqual(is_multi_host, result)
예제 #9
0
파일: test_api.py 프로젝트: dbzhou2008/nova
 def _test_is_multi_host_network_has_project_id(self, is_multi_host,
                                                fip_get):
     network = objects.Network(
         id=123, project_id=self.context.project_id,
         multi_host=is_multi_host)
     fip_get.return_value = [
         objects.FixedIP(instance_uuid=FAKE_UUID, network=network,
                         floating_ips=objects.FloatingIPList())]
     instance = objects.Instance(uuid=FAKE_UUID)
     result, floats = self.network_api._get_multi_addresses(self.context,
                                                            instance)
     self.assertEqual(is_multi_host, result)
예제 #10
0
 def _from_db_object(context, floatingip, db_floatingip,
                     expected_attrs=None):
     if expected_attrs is None:
         expected_attrs = []
     for field in floatingip.fields:
         if field not in FLOATING_IP_OPTIONAL_ATTRS:
             floatingip[field] = db_floatingip[field]
     if 'fixed_ip' in expected_attrs:
         floatingip.fixed_ip = objects.FixedIP._from_db_object(
             context, objects.FixedIP(context), db_floatingip['fixed_ip'])
     floatingip._context = context
     floatingip.obj_reset_changes()
     return floatingip
예제 #11
0
    def test_translate_floating_ips_view(self):
        mock_trans = mock.Mock()
        mock_trans.return_value = {'floating_ip': 'foo'}
        self.floating_ips._translate_floating_ip_view = mock_trans
        fip1 = objects.FixedIP(address='192.168.1.2', instance_uuid=FAKE_UUID)
        fip2 = objects.FixedIP(address='192.168.1.3', instance_uuid=FAKE_UUID)

        floaters = [self._build_floating_ip('10.0.0.2', fip1),
                    self._build_floating_ip('10.0.0.3', fip2)]

        result = self.floating_ips._translate_floating_ips_view(floaters)

        called_floaters = [call[0][0] for call in mock_trans.call_args_list]
        self.assertTrue(any(obj_base.obj_equal_prims(floaters[0], f)
                            for f in called_floaters),
                        "_translate_floating_ip_view was not called with all "
                        "floating ips")
        self.assertTrue(any(obj_base.obj_equal_prims(floaters[1], f)
                            for f in called_floaters),
                        "_translate_floating_ip_view was not called with all "
                        "floating ips")
        expected_result = {'floating_ips': ['foo', 'foo']}
        self.assertEqual(expected_result, result)
예제 #12
0
    def associate(cls, context, floating_address, fixed_address, host):
        db_fixed = db.floating_ip_fixed_ip_associate(context,
                                                     str(floating_address),
                                                     str(fixed_address),
                                                     host)
        if db_fixed is None:
            return None

        floating = FloatingIP(
            context=context, address=floating_address, host=host,
            fixed_ip_id=db_fixed['id'],
            fixed_ip=objects.FixedIP._from_db_object(
                context, objects.FixedIP(context), db_fixed,
                expected_attrs=['network']))
        return floating
예제 #13
0
    def test_list_ips_associated(self, mock_get):
        instance_uuid = "fake-uuid"
        fixed_address = "10.0.0.1"
        floating_address = "192.168.0.1"
        fixed_ip = objects.FixedIP(instance_uuid=instance_uuid,
                                   address=fixed_address)
        floating_ip = objects.FloatingIP(address=floating_address,
                                         fixed_ip=fixed_ip,
                                         pool=CONF.default_floating_pool,
                                         interface=CONF.public_interface,
                                         project_id=None)
        floating_list = objects.FloatingIPList(objects=[floating_ip])
        mock_get.return_value = floating_list
        res_dict = self.controller.index(self.admin_req)

        ip_info = [{'address': floating_address,
                    'pool': CONF.default_floating_pool,
                    'interface': CONF.public_interface,
                    'project_id': None,
                    'instance_uuid': instance_uuid,
                    'fixed_ip': fixed_address}]
        response = {'floating_ip_info': ip_info}

        self.assertEqual(res_dict, response)
예제 #14
0
 def test_save_no_fixedip(self, update):
     update.return_value = fake_floating_ip
     floatingip = floating_ip.FloatingIP(context=self.context, id=123)
     floatingip.fixed_ip = objects.FixedIP(context=self.context, id=456)
     self.assertNotIn('fixed_ip', update.calls[1])
 def obj_make_compatible(self, primitive, target_version):
     target_version = utils.convert_version_to_tuple(target_version)
     if target_version < (1, 2) and 'fixed_ip' in primitive:
         primitive['fixed_ip'] = (objects.FixedIP().object_make_compatible(
             primitive['fixed_ip']['nova_object.data'], '1.1'))