def test_lock_running_fail(self):

        def handler(signum, frame):
            raise Exception("Timeout occured while running unit test "
                            "test_lock_running_fail")

        # set an alarm, because test may hang
        signal.signal(signal.SIGALRM, handler)
        signal.setitimer(signal.ITIMER_REAL, 3)

        lock_file = tempfile.mktemp()

        read_fd1, write_fd1 = os.pipe()
        read_fd2, write_fd2 = os.pipe()
        pid = os.fork()
        if pid == 0:
            # Run lock_running in child first
            os.close(read_fd1)
            os.close(write_fd2)
            write_f1 = os.fdopen(write_fd1, 'w')
            read_f2 = os.fdopen(read_fd2, 'r')

            utils.lock_running(lock_file)

            write_f1.write('x')
            write_f1.close()
            read_f2.read()

            # exit from child by issuing execve, so that unit
            # testing framework will not finish in two instances
            os.execlp('true', 'true')
        else:
            # then in parent
            os.close(write_fd1)
            os.close(read_fd2)
            read_f1 = os.fdopen(read_fd1, 'r')
            write_f2 = os.fdopen(write_fd2, 'w')
            read_f1.read()

            # child is holding lock at this point
            self.assertFalse(utils.lock_running(lock_file))

            write_f2.write('x')
            write_f2.close()

            signal.alarm(0)
    def test_lock_running_fail(self):
        def handler(signum, frame):
            raise Exception("Timeout occured while running unit test "
                            "test_lock_running_fail")

        # set an alarm, because test may hang
        signal.signal(signal.SIGALRM, handler)
        signal.setitimer(signal.ITIMER_REAL, 3)

        lock_file = tempfile.mktemp()

        read_fd1, write_fd1 = os.pipe()
        read_fd2, write_fd2 = os.pipe()
        pid = os.fork()
        if pid == 0:
            # Run lock_running in child first
            os.close(read_fd1)
            os.close(write_fd2)
            write_f1 = os.fdopen(write_fd1, 'w')
            read_f2 = os.fdopen(read_fd2, 'r')

            utils.lock_running(lock_file)

            write_f1.write('x')
            write_f1.close()
            read_f2.read()

            # exit from child by issuing execve, so that unit
            # testing framework will not finish in two instances
            os.execlp('true', 'true')
        else:
            # then in parent
            os.close(write_fd1)
            os.close(read_fd2)
            read_f1 = os.fdopen(read_fd1, 'r')
            write_f2 = os.fdopen(write_fd2, 'w')
            read_f1.read()

            # child is holding lock at this point
            self.assertFalse(utils.lock_running(lock_file))

            write_f2.write('x')
            write_f2.close()

            signal.alarm(0)
Exemple #3
0
def main(*args, **kwargs):
    if urwid.VERSION < (1, 1, 0):
        print("This program requires urwid 1.1.0 or greater.")

    network_interfaces = network.get_physical_ifaces()
    if not network_interfaces:
        print("Unable to detect any network interfaces. Could not start")
        sys.exit(1)

    default_iface = network_interfaces[0]

    for nic in network_interfaces:
        if network.is_interface_has_ip(nic):
            default_iface = nic
            break

    parser = optparse.OptionParser()
    parser.add_option("-s", "--save-only", dest="save_only",
                      action="store_true",
                      help="Save default values and exit.")

    parser.add_option("-i", "--iface", dest="iface", metavar="IFACE",
                      default=default_iface, help="Set IFACE as primary.")

    parser.add_option("-l", "--lock-file",
                      default=consts.DEFAULT_LOCK_FILE,
                      help="Path to the process lock file. If unspecified, "
                           "the default {} is used."
                           .format(consts.DEFAULT_LOCK_FILE))

    options, args = parser.parse_args()

    if not utils.lock_running(options.lock_file):
        sys.exit(1)

    if not network.is_interface_has_ip(options.iface):
        print("Selected interface '{0}' has no assigned IP. "
              "Could not start.".format(options.iface))
        sys.exit(1)

    if options.save_only:
        setup(save_only=True,
              managed_iface=options.iface)
    else:
        if not os.isatty(sys.stdin.fileno()):
            print("Stdin is not a tty, can't run fuelmenu "
                  "in interactive mode.")
            sys.exit(1)
        setup()
Exemple #4
0
def main(*args, **kwargs):
    if urwid.VERSION < (1, 1, 0):
        print("This program requires urwid 1.1.0 or greater.")

    network_interfaces = network.get_physical_ifaces()
    if not network_interfaces:
        print("Unable to detect any network interfaces. Could not start")
        sys.exit(1)

    default_iface = network_interfaces[0]

    for nic in network_interfaces:
        if network.is_interface_has_ip(nic):
            default_iface = nic
            break

    parser = OptionParser()
    parser.add_option("-s", "--save-only", dest="save_only",
                      action="store_true",
                      help="Save default values and exit.")

    parser.add_option("-i", "--iface", dest="iface", metavar="IFACE",
                      default=default_iface, help="Set IFACE as primary.")

    parser.add_option("-l", "--lock-file",
                      default=consts.DEFAULT_LOCK_FILE,
                      help="Path to the process lock file. If unspecified, "
                           "the default {} is used."
                           .format(consts.DEFAULT_LOCK_FILE))

    options, args = parser.parse_args()

    if not utils.lock_running(options.lock_file):
        sys.exit(1)

    if not network.is_interface_has_ip(options.iface):
        print("Selected interface '{0}' has no assigned IP. "
              "Could not start.".format(options.iface))
        sys.exit(1)

    if options.save_only:
        setup(save_only=True,
              managed_iface=options.iface)
    else:
        setup()
 def test_lock_running(self):
     lock_file = tempfile.mktemp()
     self.assertTrue(utils.lock_running(lock_file))
 def test_lock_running(self):
     lock_file = tempfile.mktemp()
     self.assertTrue(utils.lock_running(lock_file))