def test_compat_version_1_1(self): network = network_obj.Network._from_db_object(self.context, network_obj.Network(), fake_network) primitive = network.obj_to_primitive(target_version='1.1') self.assertNotIn('mtu', primitive) self.assertNotIn('enable_dhcp', primitive) self.assertNotIn('dhcp_server', primitive) self.assertNotIn('share_address', primitive)
def _test_is_multi_host_network_has_no_project_id(self, is_multi_host, net_get, fip_get): net_get.return_value = network_obj.Network(id=123, project_id=None, multi_host=is_multi_host) fip_get.return_value = [ fixed_ip_obj.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)
def test_save_with_host(self, get, set_host, update): result = dict(fake_network, injected=True) network = network_obj.Network._from_db_object(self.context, network_obj.Network(), fake_network) network.obj_reset_changes() network.host = 'foo' get.return_value = result network.save() set_host.assert_called_once_with(self.context, network.id, 'foo') self.assertFalse(update.called) self._compare(network, result)
def test_save(self, set_host, update): result = dict(fake_network, injected=True) network = network_obj.Network._from_db_object(self.context, network_obj.Network(), fake_network) network.obj_reset_changes() network.save() network.label = 'bar' update.return_value = result network.save() update.assert_called_once_with(self.context, network.id, {'label': 'bar'}) self.assertFalse(set_host.called) self._compare(network, result)
def _from_db_object(context, fixedip, db_fixedip, expected_attrs=None): if expected_attrs is None: expected_attrs = [] for field in fixedip.fields: if field not in FIXED_IP_OPTIONAL_ATTRS: fixedip[field] = db_fixedip[field] # NOTE(danms): Instance could be deleted, and thus None if 'instance' in expected_attrs: fixedip.instance = instance_obj.Instance._from_db_object( context, instance_obj.Instance(), db_fixedip['instance']) if db_fixedip['instance'] else None if 'network' in expected_attrs: fixedip.network = network_obj.Network._from_db_object( context, network_obj.Network(), db_fixedip['network']) fixedip._context = context fixedip.obj_reset_changes() return fixedip
def _from_db_object(context, fixedip, db_fixedip, expected_attrs=None): if expected_attrs is None: expected_attrs = [] for field in fixedip.fields: if field == 'virtual_interface': # NOTE(danms): This field is only set when doing a # FixedIPList.get_by_network() because it's a relatively # special-case thing, so skip it here continue if field not in FIXED_IP_OPTIONAL_ATTRS: fixedip[field] = db_fixedip[field] # NOTE(danms): Instance could be deleted, and thus None if 'instance' in expected_attrs: fixedip.instance = instance_obj.Instance._from_db_object( context, instance_obj.Instance(), db_fixedip['instance']) if db_fixedip['instance'] else None if 'network' in expected_attrs: fixedip.network = network_obj.Network._from_db_object( context, network_obj.Network(), db_fixedip['network']) fixedip._context = context fixedip.obj_reset_changes() return fixedip
def test_destroy(self, delete): network = network_obj.Network(context=self.context, id=123) network.destroy() delete.assert_called_once_with(self.context, 123) self.assertTrue(network.deleted) self.assertNotIn('deleted', network.obj_what_changed())
def test_create(self, create): create.return_value = fake_network network = network_obj.Network(context=self.context, label='foo') network.create() create.assert_called_once_with(self.context, {'label': 'foo'}) self._compare(network, fake_network)
def fake_network_obj(context, network_id=1, ipv6=None): return network_obj.Network._from_db_object(context, network_obj.Network(), fake_network(network_id, ipv6))