-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update the spec "du_dirs" to filterable (#3384)
* fix: Update the spec "du_dirs" to filterable Signed-off-by: Huanhuan Li <[email protected]> * Move the "du_dirs_list" datasource to the datasource directory Signed-off-by: Huanhuan Li <[email protected]> * Rename to "dir_list" * Also raise SkipComponent if there are no filters Signed-off-by: Huanhuan Li <[email protected]>
- Loading branch information
Showing
5 changed files
with
63 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Custom datasources to get a list of directories to check disk size. | ||
""" | ||
|
||
from insights.core.context import HostContext | ||
from insights.core.dr import SkipComponent | ||
from insights.core.plugins import datasource | ||
from insights.core.filters import get_filters | ||
from insights.specs import Specs | ||
|
||
|
||
@datasource(HostContext) | ||
def du_dir_list(broker): | ||
""" Return a list of directories from the spec filter """ | ||
filters = list(get_filters(Specs.du_dirs)) | ||
if filters: | ||
return filters | ||
raise SkipComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
|
||
from insights.specs import Specs | ||
from insights.core import filters | ||
from insights.specs.datasources.dir_list import du_dir_list | ||
from insights.core.dr import SkipComponent | ||
|
||
|
||
def setup_function(func): | ||
if Specs.du_dirs in filters._CACHE: | ||
del filters._CACHE[Specs.du_dirs] | ||
if Specs.du_dirs in filters.FILTERS: | ||
del filters.FILTERS[Specs.du_dirs] | ||
|
||
if func is test_du_dirs_list: | ||
filters.add_filter(Specs.du_dirs, ["/var/lib/pulp", "/etc/httpd"]) | ||
if func is test_du_dirs_list_no_filter: | ||
filters.add_filter(Specs.du_dirs, []) | ||
|
||
|
||
def test_du_dirs_list(): | ||
broker = {} | ||
result = du_dir_list(broker) | ||
assert len(result) == 2 | ||
assert '/var/lib/pulp' in result | ||
assert '/etc/httpd' in result | ||
|
||
|
||
def test_du_dirs_list_no_filter(): | ||
broker = {} | ||
with pytest.raises(SkipComponent): | ||
du_dir_list(broker) |