Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8ebc975

Browse files
Updates to pkg beacon, fire when installed or removed (#59463)
* Updating the pkg beacon to fire the events when there are upgrades to packages, but also when watched packages are installed or removed. Breaking out the logic for listing pkgs from context into a separate function to aid in testing. Updating tests to ensure context is not used when use_context option to list_pkgs is False.saltstack/salt-enhancement-proposals#39* Adding changelog file* Converting tests to pytest.* removing self from tests.pytests.unit.modules.test_yumpkg.test_pkg_hold_tdnf* swapping global variables for pytest fixtures.* Running pre-commit manually against salt/modules/pkgng.py salt/modules/freebsdpkg.py
1 parent115304a commit8ebc975

33 files changed

+4272
-2087
lines changed

‎changelog/59463.changed‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updating the pkg beacon to fire the events when there are upgrades to packages, but also when watched packages are installed or removed. Breaking out the logic for listing pkgs from context into a separate function to aid in testing. Updating tests to ensure context is not used when use_context option to list_pkgs is False.

‎salt/beacons/pkg.py‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def beacon(config):
5353
- apache2
5454
- refresh: True
5555
"""
56+
if"beacon.pkg"notin__context__:
57+
__context__["beacon.pkg"]= {}
58+
5659
ret= []
5760

5861
_refresh=False
@@ -64,9 +67,30 @@ def beacon(config):
6467
_refresh=True
6568

6669
forpkginpkgs:
67-
_installed=__salt__["pkg.version"](pkg)
68-
_latest=__salt__["pkg.latest_version"](pkg,refresh=_refresh)
69-
if_installedand_latest:
70-
_pkg= {"pkg":pkg,"version":_latest}
71-
ret.append(_pkg)
70+
ifpkgnotin__context__["beacon.pkg"]:
71+
__context__["beacon.pkg"][pkg]=None
72+
status=__context__["beacon.pkg"][pkg]
73+
74+
# Status is None, so skip the first pass
75+
_installed=__salt__["pkg.version"](pkg,use_context=False)
76+
if_installed:
77+
version=_installed
78+
__context__["beacon.pkg"][pkg]="installed"
79+
80+
_latest=__salt__["pkg.latest_version"](pkg,refresh=_refresh)
81+
if_latest:
82+
version=_latest
83+
__context__["beacon.pkg"][pkg]="upgrade"
84+
else:
85+
__context__["beacon.pkg"][pkg]="not-installed"
86+
version=None
87+
88+
ifstatus:
89+
if__context__["beacon.pkg"][pkg]!=status:
90+
_pkg= {
91+
"pkg":pkg,
92+
"version":version,
93+
"status":__context__["beacon.pkg"][pkg],
94+
}
95+
ret.append(_pkg)
7296
returnret

‎salt/modules/aixpkg.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ def _is_installed_rpm(name):
7676
return__salt__["cmd.retcode"](cmd)==0
7777

7878

79+
def_list_pkgs_from_context(versions_as_list):
80+
"""
81+
Use pkg list from __context__
82+
"""
83+
ifversions_as_list:
84+
return__context__["pkg.list_pkgs"]
85+
else:
86+
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
87+
__salt__["pkg_resource.stringify"](ret)
88+
returnret
89+
90+
7991
deflist_pkgs(versions_as_list=False,**kwargs):
8092
"""
8193
List the filesets/rpm packages currently installed as a dict:
@@ -98,13 +110,8 @@ def list_pkgs(versions_as_list=False, **kwargs):
98110
):
99111
returnret
100112

101-
if"pkg.list_pkgs"in__context__:
102-
ifversions_as_list:
103-
return__context__["pkg.list_pkgs"]
104-
else:
105-
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
106-
__salt__["pkg_resource.stringify"](ret)
107-
returnret
113+
if"pkg.list_pkgs"in__context__andkwargs.get("use_context",True):
114+
return_list_pkgs_from_context(versions_as_list)
108115

109116
# cmd returns information colon delimited in a single linei, format
110117
# Package Name:Fileset:Level:State:PTF Id:Fix State:Type:Description:

‎salt/modules/apkpkg.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ def refresh_db(**kwargs):
111111
returnret
112112

113113

114+
def_list_pkgs_from_context(versions_as_list):
115+
"""
116+
Use pkg list from __context__
117+
"""
118+
ifversions_as_list:
119+
return__context__["pkg.list_pkgs"]
120+
else:
121+
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
122+
__salt__["pkg_resource.stringify"](ret)
123+
returnret
124+
125+
114126
deflist_pkgs(versions_as_list=False,**kwargs):
115127
"""
116128
List the packages currently installed in a dict::
@@ -131,13 +143,8 @@ def list_pkgs(versions_as_list=False, **kwargs):
131143
):
132144
return {}
133145

134-
if"pkg.list_pkgs"in__context__:
135-
ifversions_as_list:
136-
return__context__["pkg.list_pkgs"]
137-
else:
138-
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
139-
__salt__["pkg_resource.stringify"](ret)
140-
returnret
146+
if"pkg.list_pkgs"in__context__andkwargs.get("use_context",True):
147+
return_list_pkgs_from_context(versions_as_list)
141148

142149
cmd= ["apk","info","-v"]
143150
ret= {}

‎salt/modules/aptpkg.py‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,21 @@ def unhold(name=None, pkgs=None, sources=None, **kwargs): # pylint: disable=W06
12751275
returnret
12761276

12771277

1278+
def_list_pkgs_from_context(versions_as_list,removed,purge_desired):
1279+
"""
1280+
Use pkg list from __context__
1281+
"""
1282+
ifremoved:
1283+
ret=copy.deepcopy(__context__["pkg.list_pkgs"]["removed"])
1284+
else:
1285+
ret=copy.deepcopy(__context__["pkg.list_pkgs"]["purge_desired"])
1286+
ifnotpurge_desired:
1287+
ret.update(__context__["pkg.list_pkgs"]["installed"])
1288+
ifnotversions_as_list:
1289+
__salt__["pkg_resource.stringify"](ret)
1290+
returnret
1291+
1292+
12781293
deflist_pkgs(
12791294
versions_as_list=False,removed=False,purge_desired=False,**kwargs
12801295
):# pylint: disable=W0613
@@ -1310,16 +1325,8 @@ def list_pkgs(
13101325
removed=salt.utils.data.is_true(removed)
13111326
purge_desired=salt.utils.data.is_true(purge_desired)
13121327

1313-
if"pkg.list_pkgs"in__context__:
1314-
ifremoved:
1315-
ret=copy.deepcopy(__context__["pkg.list_pkgs"]["removed"])
1316-
else:
1317-
ret=copy.deepcopy(__context__["pkg.list_pkgs"]["purge_desired"])
1318-
ifnotpurge_desired:
1319-
ret.update(__context__["pkg.list_pkgs"]["installed"])
1320-
ifnotversions_as_list:
1321-
__salt__["pkg_resource.stringify"](ret)
1322-
returnret
1328+
if"pkg.list_pkgs"in__context__andkwargs.get("use_context",True):
1329+
return_list_pkgs_from_context(versions_as_list,removed,purge_desired)
13231330

13241331
ret= {"installed": {},"removed": {},"purge_desired": {}}
13251332
cmd= [

‎salt/modules/beacons.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def add(name, beacon_data, **kwargs):
146146

147147
ifnameinlist_(return_yaml=False,**kwargs):
148148
ret["comment"]="Beacon {} is already configured.".format(name)
149+
ret["result"]=True
149150
returnret
150151

151152
# Check to see if a beacon_module is specified, if so, verify it is

‎salt/modules/ebuildpkg.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,18 @@ def porttree_matches(name):
411411
returnmatches
412412

413413

414+
def_list_pkgs_from_context(versions_as_list):
415+
"""
416+
Use pkg list from __context__
417+
"""
418+
ifversions_as_list:
419+
return__context__["pkg.list_pkgs"]
420+
else:
421+
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
422+
__salt__["pkg_resource.stringify"](ret)
423+
returnret
424+
425+
414426
deflist_pkgs(versions_as_list=False,**kwargs):
415427
"""
416428
List the packages currently installed in a dict::
@@ -430,13 +442,8 @@ def list_pkgs(versions_as_list=False, **kwargs):
430442
):
431443
return {}
432444

433-
if"pkg.list_pkgs"in__context__:
434-
ifversions_as_list:
435-
return__context__["pkg.list_pkgs"]
436-
else:
437-
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
438-
__salt__["pkg_resource.stringify"](ret)
439-
returnret
445+
if"pkg.list_pkgs"in__context__andkwargs.get("use_context",True):
446+
return_list_pkgs_from_context(versions_as_list)
440447

441448
ret= {}
442449
pkgs=_vartree().dbapi.cpv_all()

‎salt/modules/freebsdpkg.py‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,19 @@ def refresh_db(**kwargs):
260260
returnTrue
261261

262262

263+
def_list_pkgs_from_context(versions_as_list,with_origin):
264+
"""
265+
Use pkg list from __context__
266+
"""
267+
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
268+
ifnotversions_as_list:
269+
__salt__["pkg_resource.stringify"](ret)
270+
ifsalt.utils.data.is_true(with_origin):
271+
origins=__context__.get("pkg.origin", {})
272+
return {x: {"origin":origins.get(x,""),"version":y}forx,yinret.items()}
273+
returnret
274+
275+
263276
deflist_pkgs(versions_as_list=False,with_origin=False,**kwargs):
264277
"""
265278
List the packages currently installed as a dict::
@@ -285,16 +298,8 @@ def list_pkgs(versions_as_list=False, with_origin=False, **kwargs):
285298
):
286299
return {}
287300

288-
if"pkg.list_pkgs"in__context__:
289-
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
290-
ifnotversions_as_list:
291-
__salt__["pkg_resource.stringify"](ret)
292-
ifsalt.utils.data.is_true(with_origin):
293-
origins=__context__.get("pkg.origin", {})
294-
return {
295-
x: {"origin":origins.get(x,""),"version":y}forx,yinret.items()
296-
}
297-
returnret
301+
if"pkg.list_pkgs"in__context__andkwargs.get("use_context",True):
302+
return_list_pkgs_from_context(versions_as_list,with_origin)
298303

299304
ret= {}
300305
origins= {}

‎salt/modules/mac_brew_pkg.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ def _call_brew(*cmd, failhard=True):
121121
returnresult
122122

123123

124+
def_list_pkgs_from_context(versions_as_list):
125+
"""
126+
Use pkg list from __context__
127+
"""
128+
ifversions_as_list:
129+
return__context__["pkg.list_pkgs"]
130+
else:
131+
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
132+
__salt__["pkg_resource.stringify"](ret)
133+
returnret
134+
135+
124136
deflist_pkgs(versions_as_list=False,**kwargs):
125137
"""
126138
List the packages currently installed in a dict::
@@ -140,13 +152,8 @@ def list_pkgs(versions_as_list=False, **kwargs):
140152
):
141153
return {}
142154

143-
if"pkg.list_pkgs"in__context__:
144-
ifversions_as_list:
145-
return__context__["pkg.list_pkgs"]
146-
else:
147-
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
148-
__salt__["pkg_resource.stringify"](ret)
149-
returnret
155+
if"pkg.list_pkgs"in__context__andkwargs.get("use_context",True):
156+
return_list_pkgs_from_context(versions_as_list)
150157

151158
ret= {}
152159
package_info=salt.utils.json.loads(

‎salt/modules/mac_portspkg.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ def _list(query=""):
7777
returnret
7878

7979

80+
def_list_pkgs_from_context(versions_as_list):
81+
"""
82+
Use pkg list from __context__
83+
"""
84+
ifversions_as_list:
85+
return__context__["pkg.list_pkgs"]
86+
else:
87+
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
88+
__salt__["pkg_resource.stringify"](ret)
89+
returnret
90+
91+
8092
deflist_pkgs(versions_as_list=False,**kwargs):
8193
"""
8294
List the packages currently installed in a dict::
@@ -96,13 +108,8 @@ def list_pkgs(versions_as_list=False, **kwargs):
96108
):
97109
return {}
98110

99-
if"pkg.list_pkgs"in__context__:
100-
ifversions_as_list:
101-
return__context__["pkg.list_pkgs"]
102-
else:
103-
ret=copy.deepcopy(__context__["pkg.list_pkgs"])
104-
__salt__["pkg_resource.stringify"](ret)
105-
returnret
111+
if"pkg.list_pkgs"in__context__andkwargs.get("use_context",True):
112+
return_list_pkgs_from_context(versions_as_list)
106113

107114
ret= {}
108115
cmd= ["port","installed"]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp