MCPcopy
hub / github.com/saltstack/salt / check_refresh

Method check_refresh

salt/state.py:1484–1539  ·  view source on GitHub ↗

Check to see if the modules for this state instance need to be updated, only update if the state is a file or a package and if it changed something. If the file function is managed check to see if the file is a possible module type, e.g. a python, pyx, or .so. Always

(self, data: dict, ret: dict)

Source from the content-addressed store, hash-verified

1482 self.functions["saltutil.refresh_modules"]()
1483
1484 def check_refresh(self, data: dict, ret: dict) -> None:
1485 """
1486 Check to see if the modules for this state instance need to be updated,
1487 only update if the state is a file or a package and if it changed
1488 something. If the file function is managed check to see if the file is a
1489 possible module type, e.g. a python, pyx, or .so. Always refresh if the
1490 function is recurse, since that can lay down anything.
1491 """
1492 _reload_modules = False
1493 if data.get("reload_grains", False):
1494 log.debug("Refreshing grains...")
1495 new_grains = salt.loader.grains(self.opts)
1496 # Use mutate_key if available (OptsDict), otherwise mutate in place (plain dict)
1497 if hasattr(self.opts, "mutate_key"):
1498 self.opts.mutate_key("grains", new_grains)
1499 elif "grains" in self.opts and isinstance(self.opts["grains"], dict):
1500 self.opts["grains"].clear()
1501 self.opts["grains"].update(new_grains)
1502 else:
1503 self.opts["grains"] = new_grains
1504 _reload_modules = True
1505
1506 if data.get("reload_pillar", False):
1507 log.debug("Refreshing pillar...")
1508 new_pillar = self._gather_pillar()
1509 # Use mutate_key if available (OptsDict), otherwise mutate in place (plain dict)
1510 if hasattr(self.opts, "mutate_key"):
1511 self.opts.mutate_key("pillar", new_pillar)
1512 elif "pillar" in self.opts and isinstance(self.opts["pillar"], dict):
1513 self.opts["pillar"].clear()
1514 self.opts["pillar"].update(new_pillar)
1515 else:
1516 self.opts["pillar"] = new_pillar
1517 _reload_modules = True
1518
1519 if not ret["changes"]:
1520 if data.get("force_reload_modules", False):
1521 self.module_refresh()
1522 return
1523
1524 if data.get("reload_modules", False) or _reload_modules:
1525 # User explicitly requests a reload
1526 self.module_refresh()
1527 return
1528
1529 if data["state"] == "file":
1530 if data["fun"] == "managed":
1531 if data["name"].endswith((".py", ".pyx", ".pyo", ".pyc", ".so")):
1532 self.module_refresh()
1533 elif data["fun"] == "recurse":
1534 self.module_refresh()
1535 elif data["fun"] == "symlink":
1536 if "bin" in data["name"]:
1537 self.module_refresh()
1538 elif data["state"] in ("pkg", "ports", "pip"):
1539 self.module_refresh()
1540
1541 def verify_data(self, data: dict[str, Any]) -> list[str]:

Callers 3

callMethod · 0.95

Calls 8

_gather_pillarMethod · 0.95
module_refreshMethod · 0.95
debugMethod · 0.80
grainsMethod · 0.80
mutate_keyMethod · 0.80
getMethod · 0.45
clearMethod · 0.45
updateMethod · 0.45

Tested by 2