

def setUp(self):
    super(FixedIpTest, self).setUp()
    self.api.microversion = self.microversion
    instance = dict(test_utils.get_test_instance(), hostname='compute.host.pvt', host='host')
    fake_fixed_ips = [{
        'id': 1,
        'address': '192.168.1.1',
        'network_id': 1,
        'virtual_interface_id': 1,
        'instance_uuid': '1',
        'allocated': False,
        'leased': False,
        'reserved': False,
        'created_at': None,
        'deleted_at': None,
        'updated_at': None,
        'deleted': None,
        'instance': instance,
        'network': test_network.fake_network,
        'host': None,
    }, {
        'id': 2,
        'address': '192.168.1.2',
        'network_id': 1,
        'virtual_interface_id': 2,
        'instance_uuid': '2',
        'allocated': False,
        'leased': False,
        'reserved': False,
        'created_at': None,
        'deleted_at': None,
        'updated_at': None,
        'deleted': None,
        'instance': instance,
        'network': test_network.fake_network,
        'host': None,
    }]

    def fake_fixed_ip_get_by_address(context, address, columns_to_join=None):
        for fixed_ip in fake_fixed_ips:
            if (fixed_ip['address'] == address):
                return fixed_ip
        raise exception.FixedIpNotFoundForAddress(address=address)

    def fake_fixed_ip_update(context, address, values):
        fixed_ip = fake_fixed_ip_get_by_address(context, address)
        if (fixed_ip is None):
            raise exception.FixedIpNotFoundForAddress(address=address)
        else:
            for key in values:
                fixed_ip[key] = values[key]
    self.stub_out('nova.db.fixed_ip_get_by_address', fake_fixed_ip_get_by_address)
    self.stub_out('nova.db.fixed_ip_update', fake_fixed_ip_update)

dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/tests/functional/api_sample_tests/test_fixed_ips.py FixedIpTest.setUp/original