diff options
| author | Vishvananda Ishaya <vishvananda@gmail.com> | 2010-07-19 20:07:39 +0000 |
|---|---|---|
| committer | Tarmac <> | 2010-07-19 20:07:39 +0000 |
| commit | a232ba0fda12a98e9da4345a6911a86b68f91826 (patch) | |
| tree | 3e45898c6f4a58fd17759ad29d8117294d4914ad /nova | |
| parent | d52925f1f3293a4ad1692bd1aab846c713f7c3de (diff) | |
| parent | 19a8556917ffebf9f85e68df4a841e1ea97124d2 (diff) | |
Fixes to dhcp lease code to use a flagfile
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/compute/linux_net.py | 16 | ||||
| -rw-r--r-- | nova/compute/network.py | 6 | ||||
| -rw-r--r-- | nova/tests/network_unittest.py | 23 |
3 files changed, 28 insertions, 17 deletions
diff --git a/nova/compute/linux_net.py b/nova/compute/linux_net.py index 00c64d81a..48e07da66 100644 --- a/nova/compute/linux_net.py +++ b/nova/compute/linux_net.py @@ -28,12 +28,16 @@ from nova import utils from nova import flags FLAGS=flags.FLAGS -def execute(cmd): +flags.DEFINE_string('dhcpbridge_flagfile', + '/etc/nova-dhcpbridge.conf', + 'location of flagfile for dhcpbridge') + +def execute(cmd, addl_env=None): if FLAGS.fake_network: logging.debug("FAKE NET: %s" % cmd) return "fake", 0 else: - return utils.execute(cmd) + return utils.execute(cmd, addl_env=addl_env) def runthis(desc, cmd): if FLAGS.fake_network: @@ -61,7 +65,7 @@ def remove_rule(cmd): def bind_public_ip(ip, interface): runthis("Binding IP to interface: %s", "sudo ip addr add %s dev %s" % (ip, interface)) - + def unbind_public_ip(ip, interface): runthis("Binding IP to interface: %s", "sudo ip addr del %s dev %s" % (ip, interface)) @@ -99,7 +103,7 @@ def dnsmasq_cmd(net): ' --except-interface=lo', ' --dhcp-range=%s,static,600s' % (net.dhcp_range_start), ' --dhcp-hostsfile=%s' % dhcp_file(net['vlan'], 'conf'), - ' --dhcp-script=%s' % bin_file('dhcpleasor.py'), + ' --dhcp-script=%s' % bin_file('nova-dhcpbridge'), ' --leasefile-ro'] return ''.join(cmd) @@ -139,7 +143,9 @@ def start_dnsmasq(network): if os.path.exists(lease_file): os.unlink(lease_file) - Popen(dnsmasq_cmd(network).split(" ")) + # FLAGFILE in env + env = {'FLAGFILE' : FLAGS.dhcpbridge_flagfile} + execute(dnsmasq_cmd(network), addl_env=env) def stop_dnsmasq(network): """ stops the dnsmasq instance for a given network """ diff --git a/nova/compute/network.py b/nova/compute/network.py index 90d6b2dc6..bdb8a22f9 100644 --- a/nova/compute/network.py +++ b/nova/compute/network.py @@ -251,7 +251,7 @@ class BaseNetwork(datastore.BasicModel): raise compute_exception.NoMoreAddresses("Project %s with network %s" % (project_id, str(self.network))) - def lease_ip(self, ip_str): + def lease_ip(self, ip_str): logging.debug("Leasing allocated IP %s" % (ip_str)) def release_ip(self, ip_str): @@ -566,10 +566,10 @@ def allocate_ip(user_id, project_id, mac): def deallocate_ip(address): return get_network_by_address(address).deallocate_ip(address) - + def release_ip(address): return get_network_by_address(address).release_ip(address) - + def lease_ip(address): return get_network_by_address(address).lease_ip(address) diff --git a/nova/tests/network_unittest.py b/nova/tests/network_unittest.py index a822cc1d9..444063d0f 100644 --- a/nova/tests/network_unittest.py +++ b/nova/tests/network_unittest.py @@ -19,16 +19,15 @@ import IPy import os import logging -import unittest from nova import flags from nova import test -from nova import exception -from nova.compute.exception import NoMoreAddresses -from nova.compute import network -from nova.auth import users from nova import utils +from nova.auth import users +from nova.compute import network +from nova.compute.exception import NoMoreAddresses +FLAGS = flags.FLAGS class NetworkTestCase(test.TrialTestCase): def setUp(self): @@ -180,14 +179,20 @@ def binpath(script): class FakeDNSMasq(object): def issue_ip(self, mac, ip, hostname, interface): - cmd = "%s add %s %s %s" % (binpath('dhcpleasor.py'), mac, ip, hostname) - env = {'DNSMASQ_INTERFACE': interface, 'TESTING' : '1'} + cmd = "%s add %s %s %s" % (binpath('nova-dhcpbridge'), + mac, ip, hostname) + env = {'DNSMASQ_INTERFACE': interface, + 'TESTING' : '1', + 'FLAGFILE' : FLAGS.dhcpbridge_flagfile} (out, err) = utils.execute(cmd, addl_env=env) logging.debug("ISSUE_IP: %s, %s " % (out, err)) def release_ip(self, mac, ip, hostname, interface): - cmd = "%s del %s %s %s" % (binpath('dhcpleasor.py'), mac, ip, hostname) - env = {'DNSMASQ_INTERFACE': interface, 'TESTING' : '1'} + cmd = "%s del %s %s %s" % (binpath('nova-dhcpbridge'), + mac, ip, hostname) + env = {'DNSMASQ_INTERFACE': interface, + 'TESTING' : '1', + 'FLAGFILE' : FLAGS.dhcpbridge_flagfile} (out, err) = utils.execute(cmd, addl_env=env) logging.debug("RELEASE_IP: %s, %s " % (out, err)) |
