Example #1
0
def command_handler():
    parser = argparse.ArgumentParser()

    subparsers = parser.add_subparsers(title="InfraSIM Commands:")
    add_command_parsers(subparsers)

    # for init command
    init_parser = subparsers.add_parser("init", help="init infrasim environment")
    init_parser.set_defaults(init="init")
    init_parser.add_argument("-s", "--skip-installation", action="store_true",
                             help="Ignore qemu/openipmi package installation")
    init_parser.add_argument("-i", "--infrasim-home", action="store",
                             help="Target infrasim home foler, default $HOME/.infrasim")
    exclusive_group = init_parser.add_mutually_exclusive_group()
    exclusive_group.add_argument("-c", "--config-file", action="store", help="Node configuration file")
    exclusive_group.add_argument("-t", "--type", action="store", default="quanta_d51", help="Node type")

    # version command
    version_parser = subparsers.add_parser("version", help="check version of infrasim and dependencies")
    version_parser.set_defaults(version="version")

    args = parser.parse_args(sys.argv[1:])
    if hasattr(args, "init"):
        # Do init
        infrasim_init(args.type, args.skip_installation, args.infrasim_home, args.config_file)
    elif hasattr(args, "version"):
        # Print version
        print version()
    else:
        fn = args.action_fn

        fn_args = get_func_args(fn, args)

        # Handle the command
        fn(*fn_args)
Example #2
0
def command_handler():
    parser = argparse.ArgumentParser()

    subparsers = parser.add_subparsers(title="InfraSIM Commands:")
    add_command_parsers(subparsers)

    # for init command
    init_parser = subparsers.add_parser("init", help="init infrasim environment")
    init_parser.set_defaults(init="init")
    init_parser.add_argument("-s", "--skip-installation", action="store_true",
                             help="Ignore qemu/openipmi package installation")
    init_parser.add_argument("-f", "--force", action="store_true",
                            help="Destroy existing Nodes")
    init_parser.add_argument("-i", "--infrasim-home", action="store",
                             help="Target infrasim home folder,"
                                  " default $HOME/.infrasim")
    exclusive_group = init_parser.add_mutually_exclusive_group()
    exclusive_group.add_argument("-c", "--config-file", action="store", help="Node configuration file")
    exclusive_group.add_argument("-t", "--type", action="store", default="dell_r730", help="Node type")

    # version command
    version_parser = subparsers.add_parser("version", help="check version of infrasim and dependencies")
    version_parser.set_defaults(version="version")

    args = parser.parse_args(sys.argv[1:])
    cmd = ''
    for word in sys.argv[1:]:
        cmd += word+" "
    logger_cmd.info("cmd rev: infrasim {}".format(cmd))
    if hasattr(args, "init"):
        # Do init
        try:
            infrasim_init(args.type, args.skip_installation,
                          args.force, args.infrasim_home,
                          args.config_file)
            print "Infrasim init OK"
        except Exception as e:
            msg = "Infrasim init failed\nException Type: {}\n" \
                  "Error Message:\n{}".format(e.__class__.__name__,
                                              eval(str(e)))
            logger_cmd.error("cmd res: {} \n".format(msg))
            sys.exit(msg)


    elif hasattr(args, "version"):
        # Print version
        print version()
        logger_cmd.info("cmd res: print version Ok")
    else:
        fn = args.action_fn

        fn_args = get_func_args(fn, args)

        # Handle the command
        fn(*fn_args)
Example #3
0
def command_handler():
    parser = argparse.ArgumentParser()

    subparsers = parser.add_subparsers(title="InfraSIM Commands:")
    add_command_parsers(subparsers)

    # for init command
    init_parser = subparsers.add_parser("init", help="init infrasim environment")
    init_parser.set_defaults(init="init")
    init_parser.add_argument("-s", "--skip-installation", action="store_true",
                             help="Ignore qemu/openipmi package installation")
    init_parser.add_argument("-f", "--force", action="store_true",
                             help="Destroy existing Nodes")
    init_parser.add_argument("-i", "--infrasim-home", action="store",
                             help="Target infrasim home folder,"
                                  " default $HOME/.infrasim")
    exclusive_group = init_parser.add_mutually_exclusive_group()
    exclusive_group.add_argument("-c", "--config-file", action="store", help="Node configuration file")
    exclusive_group.add_argument("-t", "--type", action="store", default="dell_r730", help="Node type")

    # version command
    version_parser = subparsers.add_parser("version", help="check version of infrasim and dependencies")
    version_parser.set_defaults(version="version")

    args = parser.parse_args(sys.argv[1:])
    cmd = ''
    for word in sys.argv[1:]:
        cmd += word + " "
    logger_cmd.info("cmd rev: infrasim {}".format(cmd))
    if hasattr(args, "init"):
        # Do init
        try:
            infrasim_init(args.type, args.skip_installation,
                          args.force, args.infrasim_home,
                          args.config_file)
            print "Infrasim init OK"
        except Exception as e:
            msg = "Infrasim init failed\nException Type: {}\n" \
                  "Error Message:\n{}".format(e.__class__.__name__,
                                              eval(str(e)))
            logger_cmd.error("cmd res: {} \n".format(msg))
            sys.exit(msg)

    elif hasattr(args, "version"):
        # Print version
        print version()
        logger_cmd.info("cmd res: print version Ok")
    else:
        fn = args.action_fn

        fn_args = get_func_args(fn, args)

        # Handle the command
        fn(*fn_args)
    def test_infrasim_ver(self):
        try:
            str_output = version.version()
            if 'failed' in str_output:
                assert False
            version_list = str_output.split('\n')
            for i in range(len(version_list)-1):
                version_list[i] = version_list[i].split(':')[1].strip()
            self.assertIsNotNone(
                re.search('Linux (\d+\.){2}\d+', version_list[0]),
                "kernel version is '{}', not expected".format(version_list[0])
            )
            self.assertIsNotNone(
                re.search('\d+.\d+', version_list[1]),
                "base OS version is '{}', not expected".format(version_list[1])
            )
            self.assertIsNotNone(
                re.search(
                    'QEMU emulator version (\d+.){2}\d+\(infrasim-qemu \w+-\w+ (\d+.)*\d+ build-(\d+.)*(\d+)\)',
                    version_list[2]
                ),
                "qemu version is '{}', not expected".format(version_list[2])
            )
            self.assertIsNotNone(
                re.search(
                    'IPMI Simulator version infrasim-openipmi_(\d+.){2}\d+',
                    version_list[3]
                ),
                "openipmi version is '{}', not expected".format(
                    version_list[3]))
            self.assertIsNotNone(
                re.search('socat version (\d+.){3}\d+', version_list[4]),
                "socat version is '{}', not expected".format(version_list[4])
            )
            self.assertIsNotNone(
                re.search(
                    'infrasim-compute version (\d+.){2}\d',
                    version_list[5]
                ),
                "infrasim-compute version is '{}', not expected".format(
                    version_list[5])
            )

        except AssertionError, e:
            print e
            assert False
Example #5
0
    def test_infrasim_ver(self):
        try:
            str_output = version.version()
            if 'failed' in str_output:
                assert False
            version_list = str_output.split('\n')
            for i in range(len(version_list) - 1):
                version_list[i] = version_list[i].split(':')[1].strip()
            self.assertIsNotNone(
                re.search('Linux (\d+\.){2}\d+', version_list[0]),
                "kernel version is '{}', not expected".format(version_list[0]))
            self.assertIsNotNone(
                re.search('\d+.\d+', version_list[1]),
                "base OS version is '{}', not expected".format(
                    version_list[1]))
            self.assertIsNotNone(
                re.search(
                    'QEMU emulator version (\d+.){2}\d+\(infrasim-qemu \w+-\w+ (\d+.)*\d+ build-(\d+.)*(\d+)\)',
                    version_list[2]),
                "qemu version is '{}', not expected".format(version_list[2]))
            self.assertIsNotNone(
                re.search(
                    'IPMI Simulator version infrasim-openipmi_(\d+.){2}\d+',
                    version_list[3]),
                "openipmi version is '{}', not expected".format(
                    version_list[3]))
            self.assertIsNotNone(
                re.search('socat version (\d+.){3}\d+', version_list[4]),
                "socat version is '{}', not expected".format(version_list[4]))
            self.assertIsNotNone(
                re.search('infrasim-compute version (\d+.){2}\d',
                          version_list[5]),
                "infrasim-compute version is '{}', not expected".format(
                    version_list[5]))

        except AssertionError, e:
            print e
            assert False