Add model support for DHCP lease expiration
bug 1022804 This fix is phase 1 of a fix that to address re-allocation of a fixed_ip before the DHCP lease expires. The next phases will add RPC and recycling support. Change-Id: I3c907ade5cde562ff5a222bd97e56ffef367c722
This commit is contained in:
parent
a055ef3dc1
commit
98c3486c47
@ -39,6 +39,9 @@ api_paste_config = api-paste.ini
|
|||||||
# Maximum amount of retries to generate a unique MAC address
|
# Maximum amount of retries to generate a unique MAC address
|
||||||
# mac_generation_retries = 16
|
# mac_generation_retries = 16
|
||||||
|
|
||||||
|
# DHCP Lease duration (in seconds)
|
||||||
|
# dhcp_lease_duration = 120
|
||||||
|
|
||||||
# Enable or disable bulk create/update/delete operations
|
# Enable or disable bulk create/update/delete operations
|
||||||
# allow_bulk = True
|
# allow_bulk = True
|
||||||
# RPC configuration options. Defined in rpc __init__
|
# RPC configuration options. Defined in rpc __init__
|
||||||
|
@ -48,6 +48,7 @@ core_opts = [
|
|||||||
cfg.IntOpt('max_dns_nameservers', default=5),
|
cfg.IntOpt('max_dns_nameservers', default=5),
|
||||||
cfg.IntOpt('max_subnet_host_routes', default=20),
|
cfg.IntOpt('max_subnet_host_routes', default=20),
|
||||||
cfg.StrOpt('state_path', default='.'),
|
cfg.StrOpt('state_path', default='.'),
|
||||||
|
cfg.IntOpt('dhcp_lease_duration', default=120),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Register the configuration options
|
# Register the configuration options
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ from quantum.common import utils
|
|||||||
from quantum.db import api as db
|
from quantum.db import api as db
|
||||||
from quantum.db import models_v2
|
from quantum.db import models_v2
|
||||||
from quantum.openstack.common import cfg
|
from quantum.openstack.common import cfg
|
||||||
|
from quantum.openstack.common import timeutils
|
||||||
from quantum import quantum_plugin_base_v2
|
from quantum import quantum_plugin_base_v2
|
||||||
|
|
||||||
|
|
||||||
@ -266,6 +268,11 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
QuantumDbPluginV2._delete_ip_allocation(context, network_id, subnet_id,
|
QuantumDbPluginV2._delete_ip_allocation(context, network_id, subnet_id,
|
||||||
port_id, ip_address)
|
port_id, ip_address)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _default_allocation_expiration():
|
||||||
|
return (timeutils.utcnow() +
|
||||||
|
datetime.timedelta(seconds=cfg.CONF.dhcp_lease_duration))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _delete_ip_allocation(context, network_id, subnet_id, port_id,
|
def _delete_ip_allocation(context, network_id, subnet_id, port_id,
|
||||||
ip_address):
|
ip_address):
|
||||||
@ -1016,7 +1023,8 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
for ip in ips:
|
for ip in ips:
|
||||||
allocated = models_v2.IPAllocation(
|
allocated = models_v2.IPAllocation(
|
||||||
network_id=port['network_id'], port_id=port.id,
|
network_id=port['network_id'], port_id=port.id,
|
||||||
ip_address=ip['ip_address'], subnet_id=ip['subnet_id'])
|
ip_address=ip['ip_address'], subnet_id=ip['subnet_id'],
|
||||||
|
expiration=self._default_allocation_expiration())
|
||||||
context.session.add(allocated)
|
context.session.add(allocated)
|
||||||
|
|
||||||
port.update(p)
|
port.update(p)
|
||||||
|
@ -84,6 +84,7 @@ class IPAllocation(model_base.BASEV2):
|
|||||||
network_id = sa.Column(sa.String(36), sa.ForeignKey("networks.id",
|
network_id = sa.Column(sa.String(36), sa.ForeignKey("networks.id",
|
||||||
ondelete="CASCADE"),
|
ondelete="CASCADE"),
|
||||||
nullable=False, primary_key=True)
|
nullable=False, primary_key=True)
|
||||||
|
expiration = sa.Column(sa.DateTime, nullable=True)
|
||||||
|
|
||||||
|
|
||||||
class Port(model_base.BASEV2, HasId, HasTenant):
|
class Port(model_base.BASEV2, HasId, HasTenant):
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import copy
|
import copy
|
||||||
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import mock
|
import mock
|
||||||
import os
|
import os
|
||||||
@ -34,6 +35,7 @@ from quantum.db import api as db
|
|||||||
from quantum.db import db_base_plugin_v2
|
from quantum.db import db_base_plugin_v2
|
||||||
from quantum.manager import QuantumManager
|
from quantum.manager import QuantumManager
|
||||||
from quantum.openstack.common import cfg
|
from quantum.openstack.common import cfg
|
||||||
|
from quantum.openstack.common import timeutils
|
||||||
from quantum.tests.unit import test_extensions
|
from quantum.tests.unit import test_extensions
|
||||||
from quantum.tests.unit.testlib_api import create_request
|
from quantum.tests.unit.testlib_api import create_request
|
||||||
from quantum.wsgi import Serializer, JSONDeserializer
|
from quantum.wsgi import Serializer, JSONDeserializer
|
||||||
@ -2025,3 +2027,14 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
|
|||||||
req = self.new_delete_request('subnets', subnet['subnet']['id'])
|
req = self.new_delete_request('subnets', subnet['subnet']['id'])
|
||||||
res = req.get_response(self.api)
|
res = req.get_response(self.api)
|
||||||
self.assertEquals(res.status_int, 204)
|
self.assertEquals(res.status_int, 204)
|
||||||
|
|
||||||
|
def test_default_allocation_expiration(self):
|
||||||
|
reference = datetime.datetime(2012, 8, 13, 23, 11, 0)
|
||||||
|
timeutils.utcnow.override_time = reference
|
||||||
|
|
||||||
|
cfg.CONF.set_override('dhcp_lease_duration', 120)
|
||||||
|
expires = QuantumManager.get_plugin()._default_allocation_expiration()
|
||||||
|
timeutils.utcnow
|
||||||
|
cfg.CONF.reset()
|
||||||
|
timeutils.utcnow.override_time = None
|
||||||
|
self.assertEqual(expires, reference + datetime.timedelta(seconds=120))
|
||||||
|
Loading…
Reference in New Issue
Block a user