Format the state into a log message
(ret: Any)
| 272 | |
| 273 | |
| 274 | def format_log(ret: Any) -> None: |
| 275 | """ |
| 276 | Format the state into a log message |
| 277 | """ |
| 278 | msg = "" |
| 279 | if isinstance(ret, dict): |
| 280 | # Looks like the ret may be a valid state return |
| 281 | if "changes" in ret: |
| 282 | # Yep, looks like a valid state return |
| 283 | chg = ret["changes"] |
| 284 | if not chg: |
| 285 | if ret["comment"]: |
| 286 | msg = ret["comment"] |
| 287 | else: |
| 288 | msg = "No changes made for {0[name]}".format(ret) |
| 289 | elif isinstance(chg, dict): |
| 290 | if "diff" in chg: |
| 291 | if isinstance(chg["diff"], str): |
| 292 | msg = "File changed:\n{}".format(chg["diff"]) |
| 293 | if all([isinstance(x, dict) for x in chg.values()]): |
| 294 | if all([("old" in x and "new" in x) for x in chg.values()]): |
| 295 | msg = "Made the following changes:\n" |
| 296 | for pkg in chg: |
| 297 | old = chg[pkg]["old"] |
| 298 | if not old and old not in (False, None): |
| 299 | old = "absent" |
| 300 | new = chg[pkg]["new"] |
| 301 | if not new and new not in (False, None): |
| 302 | new = "absent" |
| 303 | # This must be able to handle unicode as some package names contain |
| 304 | # non-ascii characters like "Français" or "Español". See Issue #33605. |
| 305 | msg += "'{}' changed from '{}' to '{}'\n".format( |
| 306 | pkg, old, new |
| 307 | ) |
| 308 | if not msg: |
| 309 | msg = str(ret["changes"]) |
| 310 | if ret["result"] is True or ret["result"] is None: |
| 311 | log.info(msg) |
| 312 | else: |
| 313 | log.error(msg) |
| 314 | else: |
| 315 | # catch unhandled data |
| 316 | log.info(str(ret)) |
| 317 | |
| 318 | |
| 319 | def master_compile(master_opts, minion_opts, grains, id_, saltenv): |