-
Notifications
You must be signed in to change notification settings - Fork 27
read fmf metadata for selected cases #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| 1 |
This file contains hidden or 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,24 @@ | ||
| test: "best_practices.py" | ||
|
|
||
| /cmd_or_entrypoint: | ||
| class: "CmdOrEntrypointCheck" | ||
| message: "Cmd or Entrypoint has to be specified" | ||
| description: "An ENTRYPOINT allows you to configure a container that will run as an executable. The main purpose of a CMD is to provide defaults for an executing container." | ||
| reference_url: "https://fedoraproject.org/wiki/Container:Guidelines#CMD.2FENTRYPOINT_2" | ||
| tags: ["cmd", "entrypoint"] | ||
|
|
||
| /help_file_or_readme: | ||
| class: "HelpFileOrReadmeCheck" | ||
| message: "The 'helpfile' has to be provided." | ||
| description: "Just like traditional packages, containers need some 'man page' information about how they are to be used, configured, and integrated into a larger stack." | ||
| reference_url: "https://fedoraproject.org/wiki/Container:Guidelines#Help_File" | ||
| files: ['/help.1', '/README.md'] | ||
| tags: ['filesystem', 'helpfile', 'man'] | ||
| all_must_be_present: False | ||
|
|
||
| /no_root: | ||
| class: "NoRootCheck" | ||
| message: "Service should not run as root by default." | ||
| description: "It can be insecure to run service as root." | ||
| reference_url: "?????" | ||
| tags: ["root", "user"] |
This file contains hidden or 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,19 @@ | ||
| description: "Generic description for dockerfile test if not specific description given" | ||
| test: "dockerfile.py" | ||
| tags: ["dockerfile"] | ||
|
|
||
| /from_tag_not_latest: | ||
| class: "FromTagNotLatestCheck" | ||
| message: "In FROM, tag has to be specified and not 'latest'." | ||
| description: "Using the 'latest' tag may cause unpredictable builds.It is recommended that a specific tag is used in the FROM." | ||
| reference_url: "https://fedoraproject.org/wiki/Container:Guidelines#FROM" | ||
| tags+: ["from", "baseimage", "latest"] | ||
|
|
||
| /maintainer_deprecated: | ||
| class: "MaintainerDeprecatedCheck" | ||
| message: "Dockerfile instruction `MAINTAINER` is deprecated." | ||
| description: "Replace with label 'maintainer'." | ||
| reference_url: "https://docs.docker.com/engine/reference/builder/#maintainer-deprecated" | ||
| tags+: ["maintainer", "deprecated"] | ||
| instruction: "MAINTAINER" | ||
| max_count: 0 |
This file contains hidden or 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 hidden or 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,11 @@ | ||
| test: labels.py | ||
|
|
||
| /maintainer_label: | ||
| class: "MaintainerLabelCheck" | ||
| message: "Label 'maintainer' has to be specified." | ||
| description: "The name and email of the maintainer (usually the submitter)." | ||
| reference_url: "https://fedoraproject.org/wiki/Container:Guidelines#LABELS" | ||
| tags: ["maintainer", "label"] | ||
| labels: ["maintainer"] | ||
| required: True | ||
| value_regex: Null |
This file contains hidden or 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 hidden or 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 hidden or 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,59 @@ | ||
| """ | ||
| Module with FMF abstract check class | ||
| """ | ||
|
|
||
| import copy | ||
| import logging | ||
|
|
||
| from .abstract_check import AbstractCheck | ||
| from ..fmf_extension import ExtendedTree | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def receive_fmf_metadata(name, path, object_list=False): | ||
| """ | ||
| search node identified by name fmfpath | ||
|
|
||
| :param path: path to filesystem | ||
| :param name: str - name as pattern to search (substring) | ||
| :param object_list: bool, if true, return whole list of found items | ||
| :return: Tree Object or list | ||
| """ | ||
| output = {} | ||
| fmf_tree = ExtendedTree(path) | ||
| logger.debug("get FMF metadata for test (path:%s name=%s)", path, name) | ||
| # ignore items with @ in names, to avoid using unreferenced items | ||
| items = [x for x in fmf_tree.climb() if name in x.name and "@" not in x.name] | ||
| if object_list: | ||
| return items | ||
| if len(items) == 1: | ||
| output = items[0] | ||
| elif len(items) > 1: | ||
| raise Exception("There is more FMF test metadata for item by name:{}({}) {}".format( | ||
| name, len(items), [x.name for x in items])) | ||
| elif not items: | ||
| raise Exception("Unable to get FMF metadata for: {}".format(name)) | ||
| return output | ||
|
|
||
|
|
||
| class FMFAbstractCheck(AbstractCheck): | ||
| """ | ||
| Abstract class for checks and loading metadata from FMF format | ||
| """ | ||
| metadata = None | ||
| name = None | ||
| fmf_metadata_path = None | ||
|
|
||
| def __init__(self): | ||
| """ | ||
| wraps parameters to COLIN __init__ method format | ||
| """ | ||
| if not self.metadata: | ||
| self.metadata = receive_fmf_metadata(name=self.name, path=self.fmf_metadata_path) | ||
| kwargs = copy.deepcopy(self.metadata.data) | ||
| if "class" in kwargs: | ||
| del kwargs["class"] | ||
| if "test" in kwargs: | ||
| del kwargs["test"] | ||
| super(FMFAbstractCheck, self).__init__(**kwargs) | ||
This file contains hidden or 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,76 @@ | ||
| """ | ||
| Module handling FMF stored metadata for classes | ||
| """ | ||
|
|
||
| import logging | ||
| import re | ||
|
|
||
| from fmf import Tree | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ExtendedTree(Tree): | ||
| """ | ||
| FMF Extension. Allows to use references via @ to another items -> usefull for rulesets | ||
| """ | ||
|
|
||
| def __remove_append_items(self, whole=False): | ||
| """ | ||
| internal method, delete all append items (ends with +) | ||
| :param whole: pass thru 'whole' param to climb | ||
| :return: None | ||
| """ | ||
| for node in self.climb(whole=whole): | ||
| for key in sorted(node.data.keys()): | ||
| if key.endswith('+'): | ||
| del node.data[key] | ||
|
|
||
| def references(self, datatree, whole=False): | ||
| """ | ||
| Reference name resolver (eg. /a/b/c/d@.x.y or /a/b/c/@y will search data in .x.y or y nodes) | ||
| there are used regular expressions (re.search) to match names | ||
| it uses simple references schema, do not use references to another references, | ||
| avoid usind / in reference because actual solution creates also these tree items. | ||
|
|
||
| datatree contains for example data like (original check data) | ||
| /dockerfile/maintainer_check: | ||
| class: SomeClass | ||
| tags: [dockerfile] | ||
|
|
||
| and reference could be like (ruleset) | ||
| /default/check1@maintainer_check: | ||
| tags+: [required] | ||
|
|
||
| will produce output (output ruleset tree): | ||
| /default/check1@maintainer_check: | ||
| class: SomeClass | ||
| tags: [dockerfile, required] | ||
|
|
||
|
|
||
| :param whole: 'whole' param of original climb method, in colin this is not used anyhow now | ||
| iterate over all items not only leaves if True | ||
| :param datatree: original tree with testcases to contain parent nodes | ||
| :return: None | ||
| """ | ||
| reference_nodes = self.prune(whole=whole, names=["@"]) | ||
| for node in reference_nodes: | ||
| node.data = node.original_data | ||
| ref_item_name = node.name.rsplit("@", 1)[1] | ||
| # match item what does not contain @ before name, otherwise it | ||
| # match same item | ||
| reference_node = datatree.search("[^@]%s" % ref_item_name) | ||
| logger.debug("MERGING: %s @ %s", node.name, reference_node.name) | ||
| if not reference_node: | ||
| raise ValueError("Unable to find reference for node: %s via name search: %s" % | ||
| (node.name, ref_item_name)) | ||
| node.merge(parent=reference_node) | ||
|
|
||
| self.__remove_append_items(whole=whole) | ||
|
|
||
| def search(self, name): | ||
| """ Search node with given name based on regexp, basic method (find) uses equality""" | ||
| for node in self.climb(): | ||
| if re.search(name, node.name): | ||
| return node | ||
| return None |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish this function was integrated here: https://github.com/user-cont/colin/blob/master/colin/core/loader.py
so that you don't have to pass the path in such a hacky way (from cli via changing attribute on a class)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fixed, metadata loaded in loader.py