|
@@ -29,14 +29,21 @@ class TestDhcpv4Daemon(unittest.TestCase):
|
|
def setUp(self):
|
|
def setUp(self):
|
|
# don't redirect stdout/stderr here as we want to print out things
|
|
# don't redirect stdout/stderr here as we want to print out things
|
|
# during the test
|
|
# during the test
|
|
- pass
|
|
|
|
|
|
+ #
|
|
|
|
+ # However, we do want to set the logging lock directory to somewhere
|
|
|
|
+ # to which we can write - use the current working directory. We then
|
|
|
|
+ # set the appropriate environment variable.
|
|
|
|
+ lockdir_envvar = "B10_LOCKFILE_DIR_FROM_BUILD"
|
|
|
|
+ lockdir = os.getenv(lockdir_envvar)
|
|
|
|
+ if lockdir is None:
|
|
|
|
+ os.putenv(lockdir_envvar, os.getcwd())
|
|
|
|
|
|
def tearDown(self):
|
|
def tearDown(self):
|
|
pass
|
|
pass
|
|
|
|
|
|
def runCommand(self, params, wait=1):
|
|
def runCommand(self, params, wait=1):
|
|
"""
|
|
"""
|
|
- This method runs dhcp4 and returns a touple: (returncode, stdout, stderr)
|
|
|
|
|
|
+ This method runs dhcp4 and returns a tuple: (returncode, stdout, stderr)
|
|
"""
|
|
"""
|
|
## @todo: Convert this into generic method and reuse it in dhcp6
|
|
## @todo: Convert this into generic method and reuse it in dhcp6
|
|
|
|
|
|
@@ -79,9 +86,9 @@ class TestDhcpv4Daemon(unittest.TestCase):
|
|
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
|
|
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
|
|
|
|
|
|
# There's potential problem if b10-dhcp4 prints out more
|
|
# There's potential problem if b10-dhcp4 prints out more
|
|
- # than 4k of text
|
|
|
|
|
|
+ # than 16kB of text
|
|
try:
|
|
try:
|
|
- output = os.read(self.stdout_pipes[0], 4096)
|
|
|
|
|
|
+ output = os.read(self.stdout_pipes[0], 16384)
|
|
except OSError:
|
|
except OSError:
|
|
print("No data available from stdout")
|
|
print("No data available from stdout")
|
|
output = ""
|
|
output = ""
|
|
@@ -91,7 +98,7 @@ class TestDhcpv4Daemon(unittest.TestCase):
|
|
output = ""
|
|
output = ""
|
|
|
|
|
|
try:
|
|
try:
|
|
- error = os.read(self.stderr_pipes[0], 4096)
|
|
|
|
|
|
+ error = os.read(self.stderr_pipes[0], 16384)
|
|
except OSError:
|
|
except OSError:
|
|
print("No data available on stderr")
|
|
print("No data available on stderr")
|
|
error = ""
|
|
error = ""
|
|
@@ -128,13 +135,13 @@ class TestDhcpv4Daemon(unittest.TestCase):
|
|
print(" not that is can bind sockets correctly. Please ignore binding errors.")
|
|
print(" not that is can bind sockets correctly. Please ignore binding errors.")
|
|
|
|
|
|
(returncode, output, error) = self.runCommand(["../b10-dhcp4", "-v"])
|
|
(returncode, output, error) = self.runCommand(["../b10-dhcp4", "-v"])
|
|
-
|
|
|
|
- self.assertEqual( str(output).count("[b10-dhcp4] Initiating DHCPv4 server operation."), 1)
|
|
|
|
|
|
+ output_text = str(output) + str(error)
|
|
|
|
+ self.assertEqual(output_text.count("DHCP4_STARTING"), 1)
|
|
|
|
|
|
def test_portnumber_0(self):
|
|
def test_portnumber_0(self):
|
|
print("Check that specifying port number 0 is not allowed.")
|
|
print("Check that specifying port number 0 is not allowed.")
|
|
|
|
|
|
- (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-p', '0'])
|
|
|
|
|
|
+ (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-v', '-p', '0'])
|
|
|
|
|
|
# When invalid port number is specified, return code must not be success
|
|
# When invalid port number is specified, return code must not be success
|
|
self.assertTrue(returncode != 0)
|
|
self.assertTrue(returncode != 0)
|
|
@@ -145,7 +152,7 @@ class TestDhcpv4Daemon(unittest.TestCase):
|
|
def test_portnumber_missing(self):
|
|
def test_portnumber_missing(self):
|
|
print("Check that -p option requires a parameter.")
|
|
print("Check that -p option requires a parameter.")
|
|
|
|
|
|
- (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-p'])
|
|
|
|
|
|
+ (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-v', '-p'])
|
|
|
|
|
|
# When invalid port number is specified, return code must not be success
|
|
# When invalid port number is specified, return code must not be success
|
|
self.assertTrue(returncode != 0)
|
|
self.assertTrue(returncode != 0)
|
|
@@ -156,7 +163,7 @@ class TestDhcpv4Daemon(unittest.TestCase):
|
|
def test_portnumber_invalid1(self):
|
|
def test_portnumber_invalid1(self):
|
|
print("Check that -p option is check against bogus port number (999999).")
|
|
print("Check that -p option is check against bogus port number (999999).")
|
|
|
|
|
|
- (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-p','999999'])
|
|
|
|
|
|
+ (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-v', '-p','999999'])
|
|
|
|
|
|
# When invalid port number is specified, return code must not be success
|
|
# When invalid port number is specified, return code must not be success
|
|
self.assertTrue(returncode != 0)
|
|
self.assertTrue(returncode != 0)
|
|
@@ -167,7 +174,7 @@ class TestDhcpv4Daemon(unittest.TestCase):
|
|
def test_portnumber_invalid2(self):
|
|
def test_portnumber_invalid2(self):
|
|
print("Check that -p option is check against bogus port number (123garbage).")
|
|
print("Check that -p option is check against bogus port number (123garbage).")
|
|
|
|
|
|
- (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-p','123garbage'])
|
|
|
|
|
|
+ (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-v', '-p','123garbage'])
|
|
|
|
|
|
# When invalid port number is specified, return code must not be success
|
|
# When invalid port number is specified, return code must not be success
|
|
self.assertTrue(returncode != 0)
|
|
self.assertTrue(returncode != 0)
|
|
@@ -178,28 +185,19 @@ class TestDhcpv4Daemon(unittest.TestCase):
|
|
def test_portnumber_nonroot(self):
|
|
def test_portnumber_nonroot(self):
|
|
print("Check that specifying unprivileged port number will work.")
|
|
print("Check that specifying unprivileged port number will work.")
|
|
|
|
|
|
- (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-s', '-p', '10057'])
|
|
|
|
-
|
|
|
|
- # When invalid port number is specified, return code must not be success
|
|
|
|
- # TODO: Temporarily commented out as socket binding on systems that do not have
|
|
|
|
- # interface detection implemented currently fails.
|
|
|
|
- # self.assertTrue(returncode == 0)
|
|
|
|
-
|
|
|
|
- # Check that there is an error message about invalid port number printed on stderr
|
|
|
|
- self.assertEqual( str(output).count("opening sockets on port 10057"), 1)
|
|
|
|
|
|
+ # Check that there is a message about running with an unprivileged port
|
|
|
|
+ (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-v', '-s', '-p', '10057'])
|
|
|
|
+ output_text = str(output) + str(error)
|
|
|
|
+ self.assertEqual(output_text.count("DHCP4_OPEN_SOCKET opening sockets on port 10057"), 1)
|
|
|
|
|
|
def test_skip_msgq(self):
|
|
def test_skip_msgq(self):
|
|
print("Check that connection to BIND10 msgq can be disabled.")
|
|
print("Check that connection to BIND10 msgq can be disabled.")
|
|
|
|
|
|
- (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-s', '-p', '10057'])
|
|
|
|
-
|
|
|
|
- # When invalid port number is specified, return code must not be success
|
|
|
|
- # TODO: Temporarily commented out as socket binding on systems that do not have
|
|
|
|
- # interface detection implemented currently fails.
|
|
|
|
- # self.assertTrue(returncode == 0)
|
|
|
|
-
|
|
|
|
- # Check that there is an error message about invalid port number printed on stderr
|
|
|
|
- self.assertEqual( str(output).count("Skipping connection to the BIND10 msgq."), 1)
|
|
|
|
|
|
+ # Check that the system outputs a message on one of its streams about running
|
|
|
|
+ # standalone.
|
|
|
|
+ (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-v', '-s', '-p', '10057'])
|
|
|
|
+ output_text = str(output) + str(error)
|
|
|
|
+ self.assertEqual(output_text.count("DHCP4_STANDALONE"), 1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
unittest.main()
|
|
unittest.main()
|