Esempio n. 1
0
 def test_invalid_broadcast(self):
     for bc in INVALID_BROADCASTS:
         try:
             wol.send_magic_packet('11:11:11:11:11:11', bc)
         except ValueError:
             e = utils.fetch_last_exception()
             self.assertIn('Invalid broadcast', e.args[0])
         else:
             emsg = "The broadcast '%s' should not pass the test! " % bc
             raise AssertionError(emsg)
Esempio n. 2
0
 def _safe_execute(self, *args):
     """Execute the command and in case that a subprocess error show
     the outout of the executed command.
     """
     try:
         return self._execute(*args)
     except CalledProcessError:
         exp = fetch_last_exception()
         sys.stderr.write('\nDEBUG NOTE: %s\n' % exp.output)
         exp.message = exp.output
         raise exp
Esempio n. 3
0
def _bind_socket(sok, bind_ip):
    # binding to 0 means, use any random port that
    # the OS has available
    random_port = 0
    try:
        sok.bind((bind_ip, random_port))
    except socket.error:
        exep = utils.fetch_last_exception()
        raise AwakeNetworkError(
            "Unable to bind to '%s'.\n"
            "\t Make sure the IP is correct and is assigned to one of your NICs.\n\n"
            "\t If you use a network address (first addres in the network), \n"
            "\t it will go into the default routing.\n\n"
            "Original error: %s" % (bind_ip, exep),
            original_error=exep
        )
Esempio n. 4
0
 def _expect_error_and_assert_output(self, expoutput, *cmdargs):
     """Execute the subprocess command expecting an error and then
     validate that the `expoutput` is in the output of the command.
     """
     try:
         self._execute(*cmdargs)
     except CalledProcessError:
         exep = fetch_last_exception()
         output = exep.output.decode()
         if isinstance(expoutput, list) or  isinstance(expoutput, tuple):
             for emsg in expoutput:
                 self.assertIn(emsg, output)
         else:
             self.assertIn(expoutput, output)
     else:
         raise Exception('The process does not rise the '\
                         'expected exception CalledProcessError.')