Commit ff18f526 authored by Guido Trotter's avatar Guido Trotter
Browse files

Merge remote branch 'origin/devel-2.1'



* origin/devel-2.1:
  Explicitely return None from IgnoreSignals
  AsyncUDPSocket: fix IgnoreSignals usage and test
  Add KVM chroot feature
  Fix and Improve TryToRoman unittest

Conflicts:
	test/ganeti.daemon_unittest.py
	  - trivial
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parents a01b500b 2fd7f564
......@@ -112,10 +112,12 @@ class AsyncUDPSocket(GanetiBaseAsyncoreDispatcher):
# this method is overriding an asyncore.dispatcher method
def handle_read(self):
payload, address = utils.IgnoreSignals(self.recvfrom,
constants.MAX_UDP_DATA_SIZE)
ip, port = address
self.handle_datagram(payload, ip, port)
recv_result = utils.IgnoreSignals(self.recvfrom,
constants.MAX_UDP_DATA_SIZE)
if recv_result is not None:
payload, address = recv_result
ip, port = address
self.handle_datagram(payload, ip, port)
def handle_datagram(self, payload, ip, port):
"""Handle an already read udp datagram
......
......@@ -3104,12 +3104,16 @@ def IgnoreSignals(fn, *args, **kwargs):
try:
return fn(*args, **kwargs)
except EnvironmentError, err:
if err.errno != errno.EINTR:
if err.errno == errno.EINTR:
return None
else:
raise
except (select.error, socket.error), err:
# In python 2.6 and above select.error is an IOError, so it's handled
# above, in 2.5 and below it's not, and it's handled here.
if not (err.args and err.args[0] == errno.EINTR):
if err.args and err.args[0] == errno.EINTR:
return None
else:
raise
......
......@@ -690,7 +690,24 @@
<simpara>This option is only effective with kvm versions >= 87
and qemu-kvm versions >= 0.11.0.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>use_chroot</term>
<listitem>
<simpara>Valid for the KVM hypervisor.</simpara>
<simpara>This boolean option determines wether to run the KVM
instance in a chroot directory.
</simpara>
<para>If it is set to <quote>true</quote>, an empty directory
is created before starting the instance and its path is passed via
the -chroot flag to kvm.
The directory is removed when the instance is stopped.
</para>
<simpara>It is set to <quote>false</quote> by default.</simpara>
</listitem>
</varlistentry>
......
......@@ -61,11 +61,31 @@ class TestPartial(testutils.GanetiTestCase):
class TestTryToRoman(testutils.GanetiTestCase):
"""test the compat.TryToRoman function"""
def setUp(self):
testutils.GanetiTestCase.setUp(self)
# Save the compat.roman module so we can alter it with a fake...
self.compat_roman_module = compat.roman
def tearDown(self):
# ...and restore it at the end of the test
compat.roman = self.compat_roman_module
testutils.GanetiTestCase.tearDown(self)
def testAFewIntegers(self):
# This test only works is the roman module is installed
if compat.roman is not None:
self.assertEquals(compat.TryToRoman(0), 0)
self.assertEquals(compat.TryToRoman(1), "I")
self.assertEquals(compat.TryToRoman(4), "IV")
self.assertEquals(compat.TryToRoman(5), "V")
def testWithNoRoman(self):
# compat.roman is saved/restored in setUp/tearDown
compat.roman = None
self.assertEquals(compat.TryToRoman(0), 0)
self.assertEquals(compat.TryToRoman(1), "I")
self.assertEquals(compat.TryToRoman(4), "IV")
self.assertEquals(compat.TryToRoman(5), "V")
self.assertEquals(compat.TryToRoman(1), 1)
self.assertEquals(compat.TryToRoman(4), 4)
self.assertEquals(compat.TryToRoman(5), 5)
def testStrings(self):
self.assertEquals(compat.TryToRoman("astring"), "astring")
......
......@@ -29,6 +29,7 @@ import time
from ganeti import daemon
from ganeti import errors
from ganeti import utils
import testutils
......@@ -172,10 +173,14 @@ class TestAsyncUDPSocket(testutils.GanetiTestCase):
self.client = _MyAsyncUDPSocket()
self.server.bind(("127.0.0.1", 0))
self.port = self.server.getsockname()[1]
# Save utils.IgnoreSignals so we can do evil things to it...
self.saved_utils_ignoresignals = utils.IgnoreSignals
def tearDown(self):
self.server.close()
self.client.close()
# ...and restore it as well
utils.IgnoreSignals = self.saved_utils_ignoresignals
testutils.GanetiTestCase.tearDown(self)
def testNoDoubleBind(self):
......@@ -229,6 +234,17 @@ class TestAsyncUDPSocket(testutils.GanetiTestCase):
["p1", "p2", "error", "p3", "error", "terminate"])
self.assertEquals(self.server.error_count, 2)
def testSignaledWhileReceiving(self):
utils.IgnoreSignals = lambda fn, *args, **kwargs: None
self.client.enqueue_send("127.0.0.1", self.port, "p1")
self.client.enqueue_send("127.0.0.1", self.port, "p2")
self.server.handle_read()
self.assertEquals(self.server.received, [])
self.client.enqueue_send("127.0.0.1", self.port, "terminate")
utils.IgnoreSignals = self.saved_utils_ignoresignals
self.mainloop.Run()
self.assertEquals(self.server.received, ["p1", "p2", "terminate"])
if __name__ == "__main__":
testutils.GanetiTestProgram()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment