def test_raises_error_when_omshell_not_connected(self):
error = ExternalProcessError(
returncode=2, cmd=("omshell",), output="")
self.patch(ExternalProcessError, 'output_as_unicode', 'not connected.')
omshell = Mock()
omshell.create.side_effect = error
mac = factory.make_mac_address()
ip = factory.make_ip_address()
with FakeLogger("maas.dhcp") as logger:
error = self.assertRaises(
exceptions.CannotCreateHostMap, dhcp._create_host_map,
omshell, mac, ip)
# The CannotCreateHostMap exception includes a message describing the
# problematic mapping.
self.assertDocTestMatches(
"Could not create host map for %s -> %s: "
"The DHCP server could not be reached." % (mac, ip),
str(error))
# A message is also written to the maas.dhcp logger that describes the
# problematic mapping.
self.assertDocTestMatches(
"Could not create host map for %s -> %s: "
"The DHCP server could not be reached." % (mac, ip),
logger.output)
评论列表
文章目录