You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by mr...@apache.org on 2009/08/14 18:18:28 UTC
svn commit: r804316 - /incubator/tashi/trunk/src/tashi/agents/dhcpdns.py
Author: mryan3
Date: Fri Aug 14 18:18:28 2009
New Revision: 804316
URL: http://svn.apache.org/viewvc?rev=804316&view=rev
Log:
This deals with a strange behavior I found in nsupdate -- it sometimes hangs instead of exiting after perfoming a DNS update.
Modified:
incubator/tashi/trunk/src/tashi/agents/dhcpdns.py
Modified: incubator/tashi/trunk/src/tashi/agents/dhcpdns.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/agents/dhcpdns.py?rev=804316&r1=804315&r2=804316&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/agents/dhcpdns.py (original)
+++ incubator/tashi/trunk/src/tashi/agents/dhcpdns.py Fri Aug 14 18:18:28 2009
@@ -17,7 +17,10 @@
import logging
import os
+import signal
import socket
+import subprocess
+import time
from instancehook import InstanceHook
from tashi.services.ttypes import Instance, NetworkConfiguration
from tashi import boolean
@@ -148,39 +151,57 @@
cmd = "nsupdate -k %s" % (self.dnsKeyFile)
else:
cmd = "nsupdate"
- (stdin, stdout) = os.popen2(cmd)
- stdin.write("server %s\n" % (self.dnsServer))
- stdin.write("update add %s.%s %d A %s\n" % (name, self.dnsDomain, self.dnsExpire, ip))
- stdin.write("\n")
- if (self.reverseDns):
- ipSegments = map(int, ip.split("."))
- ipSegments.reverse()
- reverseIpStr = ("%d.%d.%d.%d.in-addr.arpa" % (ipSegments[0], ipSegments[1], ipSegments[2], ipSegments[3]))
- stdin.write("update add %s %d IN PTR %s.%s.\n" % (reverseIpStr, self.dnsExpire, name, self.dnsDomain))
+ child = subprocess.Popen(args=cmd.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ try:
+ (stdin, stdout) = (child.stdin, child.stdout)
+ stdin.write("server %s\n" % (self.dnsServer))
+ stdin.write("update add %s.%s %d A %s\n" % (name, self.dnsDomain, self.dnsExpire, ip))
stdin.write("\n")
- stdin.close()
- output = stdout.read()
- stdout.close()
-
+ if (self.reverseDns):
+ ipSegments = map(int, ip.split("."))
+ ipSegments.reverse()
+ reverseIpStr = ("%d.%d.%d.%d.in-addr.arpa" % (ipSegments[0], ipSegments[1], ipSegments[2], ipSegments[3]))
+ stdin.write("update add %s %d IN PTR %s.%s.\n" % (reverseIpStr, self.dnsExpire, name, self.dnsDomain))
+ stdin.write("\n")
+ stdin.close()
+ output = stdout.read()
+ stdout.close()
+ finally:
+ os.kill(child.pid, signal.SIGTERM)
+ (pid, status) = os.waitpid(child.pid, os.WNOHANG)
+ while (pid == 0):
+ time.sleep(0.5)
+ os.kill(child.pid, signal.SIGTERM)
+ (pid, status) = os.waitpid(child.pid, os.WNOHANG)
+
def removeDns(self, name):
if (self.dnsKeyFile != ""):
cmd = "nsupdate -k %s" % (self.dnsKeyFile)
else:
cmd = "nsupdate"
- (stdin, stdout) = os.popen2(cmd)
- stdin.write("server %s\n" % (self.dnsServer))
- if (self.reverseDns):
- ip = socket.gethostbyname(name)
- ipSegments = map(int, ip.split("."))
- ipSegments.reverse()
- reverseIpStr = ("%d.%d.%d.%d.in-addr.arpa" % (ipSegments[0], ipSegments[1], ipSegments[2], ipSegments[3]))
- stdin.write("update delete %s IN PTR\n" % (reverseIpStr))
+ child = subprocess.Popen(args=cmd.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ try:
+ (stdin, stdout) = (child.stdin, child.stdout)
+ stdin.write("server %s\n" % (self.dnsServer))
+ if (self.reverseDns):
+ ip = socket.gethostbyname(name)
+ ipSegments = map(int, ip.split("."))
+ ipSegments.reverse()
+ reverseIpStr = ("%d.%d.%d.%d.in-addr.arpa" % (ipSegments[0], ipSegments[1], ipSegments[2], ipSegments[3]))
+ stdin.write("update delete %s IN PTR\n" % (reverseIpStr))
+ stdin.write("\n")
+ stdin.write("update delete %s.%s A\n" % (name, self.dnsDomain))
stdin.write("\n")
- stdin.write("update delete %s.%s A\n" % (name, self.dnsDomain))
- stdin.write("\n")
- stdin.close()
- output = stdout.read()
- stdout.close()
+ stdin.close()
+ output = stdout.read()
+ stdout.close()
+ finally:
+ os.kill(child.pid, signal.SIGTERM)
+ (pid, status) = os.waitpid(child.pid, os.WNOHANG)
+ while (pid == 0):
+ time.sleep(0.5)
+ os.kill(child.pid, signal.SIGTERM)
+ (pid, status) = os.waitpid(child.pid, os.WNOHANG)
def doUpdate(self, instance):
newInstance = Instance()