Example #1
0
    def __validate_config(self, options, cfg):
        '''
        This function validates all general configuration parameters.
        Furtheron it fetches a copy of the original daemon init script, puts it
        into the users home directory and inserts the correct paths.

        Args:
           options (dict): The dictionary containing all options.

           cfg (ConfigParser): The config parser instance.

        Returns:
           The filled options dictionary.
        '''
        try:
            userpath = os.path.expanduser("~")
            conf_file_path = userpath + "/.des-gossip-adv"
            options["testbed_dir"] = cfg.get("experiment",
                                             "testbed_dir").rstrip("/") + "/"
            init_script_path = options["testbed_dir"] + "des-gossip-adv.init"
            cmd = "scp t9-157t:/etc/init.d/des-gossip-adv %s" % init_script_path
            try:
                self.MISC.execute_command(cmd)
            except KeyboardInterrupt:
                self.LOGGER.warning(
                    "Keyboard Interrupt. Trying to copy file from \"grid10x10_a0\"!"
                )
                cmd = "scp grid10x10_a0:/etc/init.d/des-gossip-adv %s" % init_script_path
                self.MISC.execute_command(cmd)
            cmd = "sed -i \"s/\/etc\/default\/$NAME/%s/g\" %s" % (
                conf_file_path.replace("/", "\/"), init_script_path)
            self.MISC.execute_command(cmd)
            options["archive_suffix"] = cfg.get("experiment", "archive_suffix")
            if len(options["archive_suffix"]) == 0:
                options["archive_suffix"] = ""
            options["archive_location"] = cfg.get("experiment",
                                                  "archive_location")
            if len(options["archive_location"]) == 0:
                raise ConfigParser.NoOptionError("archive_location",
                                                 "experiment")
            tap_name = cfg.get("daemon", "tap_name")
            if len(tap_name) == 0:
                raise ConfigParser.NoOptionError("tap_name", "daemon")
            options["tap_name"] = tap_name
            tap_ip = cfg.get("daemon", "tap_ip")
            if len(tap_ip) == 0:
                raise ConfigParser.NoOptionError("tap_ip", "daemon")
            options["tap_ip"] = tap_ip
            tap_netmask = cfg.get("daemon", "tap_netmask")
            if len(tap_netmask) == 0:
                raise ConfigParser.NoOptionError("tap_netmask", "daemon")
            options["tap_netmask"] = tap_netmask
            cli_port = cfg.get("daemon", "cli_port")
            if len(cli_port) == 0:
                raise ConfigParser.NoOptionsError("cli_port", "daemon")
            options["cli_port"] = cli_port
            daemon_logdir = cfg.get("daemon", "daemon_logdir")
            if len(daemon_logdir) == 0:
                raise ConfigParser.NoOptionError("daemon_logdir", "daemon")
            options["daemon_logdir"] = daemon_logdir
        except ConfigParser.NoSectionError, err:
            self.LOGGER.critical(err)
            sys.exit(9)