'Triggers an error that calls rollback on session.'

def test_ipam_rollback_not_broken_on_session_rollback(self):

    with self.network() as net:
        with self.subnet(network=net, cidr='10.0.1.0/24') as subnet1:
            with self.subnet(network=net, cidr='10.0.2.0/24') as subnet2:
                pass
    def rollback(func, *args, **kwargs):
        func(*args, **kwargs)
    orig = ipam_pluggable_backend.IpamPluggableBackend._store_ip_allocation
    def store(context, ip_address, *args, **kwargs):
        try:
            return orig(context, ip_address, *args, **kwargs)
        finally:
            context.session.flush()
    result = self._create_port(self.fmt, net_id=net['network']['id'], fixed_ips=[{'subnet_id': subnet1['subnet']['id']}, {'subnet_id': subnet2['subnet']['id']}])
    port = self.deserialize(self.fmt, result)
    fixed_ips = port['port']['fixed_ips']
    ips = [{'subnet_id': fixed_ips[0]['subnet_id'], 'ip_address': fixed_ips[0]['ip_address']}, {'subnet_id': fixed_ips[1]['subnet_id'], 'ip_address': fixed_ips[1]['ip_address']}]
    def alloc(*args, **kwargs):
        def increment_address(a):
            a['ip_address'] = str((netaddr.IPAddress(a['ip_address']) + 1))
        increment_address(ips[0])
        try:
            return copy.deepcopy(ips)
        finally:
            increment_address(ips[1])
    Backend = ipam_pluggable_backend.IpamPluggableBackend
    with mock.patch.object(Backend, '_store_ip_allocation', wraps=store):
        with mock.patch.object(Backend, '_safe_rollback', wraps=rollback):
            with mock.patch.object(Backend, '_allocate_ips_for_port', wraps=alloc):
                response = self._create_port(self.fmt, net_id=net['network']['id'], fixed_ips=[{'subnet_id': subnet1['subnet']['id']}, {'subnet_id': subnet2['subnet']['id']}])
    self.assertEqual(webob.exc.HTTPCreated.code, response.status_int)
