def set(self, configs, restart=False):
        for role in configs:
            if role in self.roles:

                self.roles[role].set(configs[role])

            else:
                log.warning(
                    "Role: \"{0}\" doesn't exist for service: \"{1}\"".format(
                        role, self.name))
def exec_formula(cluster, args):
    log.info("using formula: {0}".format(args.formula))
    user_formula_args = None
    if args.formula_args:
        user_formula_args_path = file.file_path(cc.FORMULA_ARGS, args.path)
        log.info("Reading formula args config file: {0}".format(
            user_formula_args_path))
        user_formula_args = file.open_yaml_conf(user_formula_args_path)

    #execute formula global variables
    vars = {
        "log": log,
        "kb_to_bytes": convert.kb_to_bytes,
        "bytes_to_kb": convert.bytes_to_kb,
        "mb_to_bytes": convert.mb_to_bytes,
        "bytes_to_mb": convert.bytes_to_mb,
        "gb_to_bytes": convert.gb_to_bytes,
        "bytes_to_gb": convert.bytes_to_gb,
        "tr_to_bytes": convert.tr_to_bytes,
        "bytes_to_tr": convert.bytes_to_tr
    }
    local = {}
    config = {}
    try:
        execfile(args.formula, vars, local)
        constants = local["constants"](cluster, log)
        for member in constants:
            if hasattr(constants[member], '__call__'):
                if user_formula_args and member in user_formula_args:
                    if constants[member](user_formula_args[member]
                                         ) != user_formula_args[member]:
                        log.warning(
                            "Formula arg value '{0}' was ignored using default '{1}'. Formula arg value must adhere to these rules {2}  "
                            .format(
                                user_formula_args[member],
                                constants[member](user_formula_args[member]),
                                inspect.getsource(constants[member])))

                    constants[member] = constants[member](
                        user_formula_args[member])
                else:
                    constants[member] = constants[member](None)

        config = local["formula"](cluster, log, constants)

    except IOError:
        log.fatal("formula file: {0} doesn't exist".format(args.formula))

    return config
def save_cdh_configuration(vars, args):
    #TODO: think of a better name

    if len(vars["cdh"]) > 0:
        temp = {}
        path = file.file_path(cc.CDH_CONFIG, args.path)
        for key in vars["cdh"]:
            key_split = key.split(".")
            cc.utils.dict.nest(temp, key_split, vars["cdh"][key])
        file.write_json_conf(temp, path)
        log.info("Wrote CDH configuration file to: {0}".format(path))
        return path
    else:
        log.warning("No CDH configurations to save.")
        return None
Esempio n. 4
0
 def set(self, configs):
     '''
     re key our configs to use actual CDH config key
     :param configs: dictionary of configs that were parsed from json.
     :return:
     '''
     temp = {}
     for config in configs:
         if config in self.configs:
             temp[self.configs[config].cdh_config.name] = configs[config]
         else:
             log.warning(
                 "No configuration key found for: {0}".format(config))
     log.info("Updating config group: {0}".format(self.key))
     self.cdh_group.update_config(temp)
     self.__update()
     return temp
Esempio n. 5
0
    def test_warning(self):
        log.logger.log = MagicMock()

        log.warning("warning")

        log.logger.log.assert_called_with(logging.WARNING, "warning")