Fixes to dhcp lease code to use a flagfile

This commit is contained in:
Vishvananda Ishaya
2010-07-19 20:07:39 +00:00
committed by Tarmac
8 changed files with 36 additions and 26 deletions

View File

@@ -18,23 +18,27 @@
# under the License. # under the License.
""" """
dhcpleasor.py nova-dhcpbridge
Handle lease database updates from DHCP servers. Handle lease database updates from DHCP servers.
""" """
import sys
import os
import logging import logging
import os
import sys
#TODO(joshua): there is concern that the user dnsmasq runs under will not
# have nova in the path. This should be verified and if it is
# not true the ugly line below can be removed
sys.path.append(os.path.abspath(os.path.join(__file__, "../../"))) sys.path.append(os.path.abspath(os.path.join(__file__, "../../")))
logging.debug(sys.path)
import getopt
from os import environ
from nova import rpc
from nova import flags from nova import flags
from nova import rpc
from nova import utils
from nova.compute import linux_net from nova.compute import linux_net
from nova.compute import network from nova.compute import network
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
@@ -63,11 +67,12 @@ def init_leases(interface):
return res return res
def main(argv=None): def main():
if argv is None: flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile)
argv = sys.argv utils.default_flagfile(flagfile)
interface = environ.get('DNSMASQ_INTERFACE', 'br0') argv = FLAGS(sys.argv)
if int(environ.get('TESTING', '0')): interface = os.environ.get('DNSMASQ_INTERFACE', 'br0')
if int(os.environ.get('TESTING', '0')):
FLAGS.fake_rabbit = True FLAGS.fake_rabbit = True
FLAGS.redis_db = 8 FLAGS.redis_db = 8
FLAGS.network_size = 32 FLAGS.network_size = 32

View File

@@ -1,5 +1,6 @@
--daemonize=1 --daemonize=1
--ca_path=/var/lib/nova/CA --ca_path=/var/lib/nova/CA
--keys_path=/var/lib/nova/keys --keys_path=/var/lib/nova/keys
--networks_path=/var/lib/nova/networks
--dhcpbridge_flagfile=/etc/nova/nova-dhcpbridge.conf
--fake_users=1 --fake_users=1
--datastore_path=/var/lib/nova/keeper

View File

@@ -1,2 +1,3 @@
bin/nova-api usr/bin bin/nova-api usr/bin
debian/nova-api.conf etc/nova debian/nova-api.conf etc/nova
debian/nova-dhcpbridge.conf etc/nova

View File

@@ -1,8 +1,6 @@
--ca_path=/var/lib/nova/CA --ca_path=/var/lib/nova/CA
--keys_path=/var/lib/nova/keys --keys_path=/var/lib/nova/keys
--datastore_path=/var/lib/nova/keeper
--instances_path=/var/lib/nova/instances --instances_path=/var/lib/nova/instances
--networks_path=/var/lib/nova/networks
--simple_network_template=/usr/share/nova/interfaces.template --simple_network_template=/usr/share/nova/interfaces.template
--libvirt_xml_template=/usr/share/nova/libvirt.xml.template --libvirt_xml_template=/usr/share/nova/libvirt.xml.template
--vpn_client_template=/usr/share/nova/client.ovpn.template --vpn_client_template=/usr/share/nova/client.ovpn.template

2
debian/nova-dhcp.conf vendored Normal file
View File

@@ -0,0 +1,2 @@
--networks_path=/var/lib/nova/networks
--fake_users=1

View File

@@ -1,7 +1,6 @@
--daemonize=1 --daemonize=1
--ca_path=/var/lib/nova/CA --ca_path=/var/lib/nova/CA
--keys_path=/var/lib/nova/keys --keys_path=/var/lib/nova/keys
--datastore_path=/var/lib/nova/keeper
--fake_users=1 --fake_users=1
--images_path=/var/lib/nova/images --images_path=/var/lib/nova/images
--buckets_path=/var/lib/nova/buckets --buckets_path=/var/lib/nova/buckets

View File

@@ -1,7 +1,6 @@
--daemonize=1 --daemonize=1
--ca_path=/var/lib/nova/CA --ca_path=/var/lib/nova/CA
--keys_path=/var/lib/nova/keys --keys_path=/var/lib/nova/keys
--datastore_path=/var/lib/nova/keeper
--fake_users=1 --fake_users=1
--images_path=/var/lib/nova/images --images_path=/var/lib/nova/images
--buckets_path=/var/lib/nova/buckets --buckets_path=/var/lib/nova/buckets

View File

@@ -19,16 +19,15 @@
import IPy import IPy
import os import os
import logging import logging
import unittest
from nova import flags from nova import flags
from nova import test 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 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): class NetworkTestCase(test.TrialTestCase):
def setUp(self): def setUp(self):
@@ -180,14 +179,20 @@ def binpath(script):
class FakeDNSMasq(object): class FakeDNSMasq(object):
def issue_ip(self, mac, ip, hostname, interface): def issue_ip(self, mac, ip, hostname, interface):
cmd = "%s add %s %s %s" % (binpath('dhcpleasor.py'), mac, ip, hostname) cmd = "%s add %s %s %s" % (binpath('nova-dhcpbridge'),
env = {'DNSMASQ_INTERFACE': interface, 'TESTING' : '1'} mac, ip, hostname)
env = {'DNSMASQ_INTERFACE': interface,
'TESTING' : '1',
'FLAGFILE' : FLAGS.dhcpbridge_flagfile}
(out, err) = utils.execute(cmd, addl_env=env) (out, err) = utils.execute(cmd, addl_env=env)
logging.debug("ISSUE_IP: %s, %s " % (out, err)) logging.debug("ISSUE_IP: %s, %s " % (out, err))
def release_ip(self, mac, ip, hostname, interface): def release_ip(self, mac, ip, hostname, interface):
cmd = "%s del %s %s %s" % (binpath('dhcpleasor.py'), mac, ip, hostname) cmd = "%s del %s %s %s" % (binpath('nova-dhcpbridge'),
env = {'DNSMASQ_INTERFACE': interface, 'TESTING' : '1'} mac, ip, hostname)
env = {'DNSMASQ_INTERFACE': interface,
'TESTING' : '1',
'FLAGFILE' : FLAGS.dhcpbridge_flagfile}
(out, err) = utils.execute(cmd, addl_env=env) (out, err) = utils.execute(cmd, addl_env=env)
logging.debug("RELEASE_IP: %s, %s " % (out, err)) logging.debug("RELEASE_IP: %s, %s " % (out, err))