Merge ~emitorino/ubuntu-cve-tracker:add_project_yml_when_loading_subproject into ubuntu-cve-tracker:master

Proposed by Emilia Torino
Status: Merged
Merged at revision: eaf926f8d3b7d08850bebd5c8af90aaac2cfdea2
Proposed branch: ~emitorino/ubuntu-cve-tracker:add_project_yml_when_loading_subproject
Merge into: ubuntu-cve-tracker:master
Diff against target: 70 lines (+39/-5)
2 files modified
scripts/cve_lib.py (+18/-5)
scripts/test_cve_lib.py (+21/-0)
Reviewer Review Type Date Requested Status
Alex Murray Approve
Review via email: mp+440781@code.launchpad.net

Commit message

For the purpose of improving the management of subprojects, adding support to load the project.yml information into subprojects. Unless missed, it seems cve_lib is not yet doing this.

Also, checking configs before setting them into subprojects, otherwise if a given config is not available, the KeyError exception is catch for the first config not found, and the following ones are not loaded at all.

Description of the change

* cve_lib.py:
  - check config before trying to assign it to subprojects[rel]
  - load customer metadata from project.yml into subprojects[rel]
* test_cve_lib:
  - test for changes

To post a comment you must log in.
Revision history for this message
Alex Murray (alexmurray) wrote :

LGTM - thanks Emi (in particular thanks for the unit test - very nice!)

Revision history for this message
Alex Murray (alexmurray) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/cve_lib.py b/scripts/cve_lib.py
2index f118f93..79b4225 100755
3--- a/scripts/cve_lib.py
4+++ b/scripts/cve_lib.py
5@@ -856,6 +856,17 @@ def read_external_subproject_config(subproject):
6 with open(config_yaml) as cfg:
7 return yaml.safe_load(cfg)
8
9+
10+def read_external_subproject_details(subproject):
11+ """Read and return the project details for the given subproject."""
12+ sp_dir = get_external_subproject_dir(subproject)
13+ # project.yml is located in the top level folder for the subproject
14+ project_dir = sp_dir[:sp_dir.rfind("/")]
15+ project_yaml = os.path.join(project_dir, "project.yml")
16+ if os.path.isfile(project_yaml):
17+ with open(project_yaml) as cfg:
18+ return yaml.safe_load(cfg)
19+
20 def find_files_recursive(path, name):
21 """Return a list of all files under path with name."""
22 matches = []
23@@ -920,11 +931,13 @@ def load_external_subprojects():
24 # use config to populate other parts of the
25 # subproject settings
26 config = read_external_subproject_config(rel)
27- subprojects[rel].setdefault("ppa", config["ppa"])
28- subprojects[rel].setdefault("oval", config["oval"])
29- subprojects[rel].setdefault("name", config["name"])
30- subprojects[rel].setdefault("description", config["description"])
31- subprojects[rel].setdefault("parent", config["parent"])
32+ config_data = ['ppa', 'oval', 'name', 'description', 'parent']
33+ for data in config_data:
34+ if data in config:
35+ subprojects[rel].setdefault(data, config[data])
36+ project = read_external_subproject_details(rel)
37+ if project and "customer" in project:
38+ subprojects[rel].setdefault("customer", project["customer"])
39 except:
40 pass
41
42diff --git a/scripts/test_cve_lib.py b/scripts/test_cve_lib.py
43index c5130dc..f9bd1d2 100755
44--- a/scripts/test_cve_lib.py
45+++ b/scripts/test_cve_lib.py
46@@ -184,3 +184,24 @@ class TestParseCVEFiles:
47 js = cve_lib.parse_cvss(cvss[0]['vector'])
48 assert cvss[0]['baseScore'] == str(js['baseMetricV3']['cvssV3']['baseScore'])
49 assert cvss[0]['baseSeverity'] == js['baseMetricV3']['cvssV3']['baseSeverity']
50+
51+
52+class TestSubprojects:
53+
54+ def test_load_subprojects_loads_every_config_available(self):
55+ # mimic here how subprojects are loaded to then assert cve_lib.subprojects
56+ # contains every config available
57+ for supported_txt in cve_lib.find_files_recursive(cve_lib.subprojects_dir, "supported.txt"):
58+ # rel name is the path component between subprojects/ and
59+ # /supported.txt
60+ rel = supported_txt[len(cve_lib.subprojects_dir) + 1:-len("supported.txt") - 1]
61+ config = cve_lib.read_external_subproject_config(rel)
62+ config_data = ['ppa', 'oval', 'name', 'description', 'parent']
63+ for data in config_data:
64+ if data in config:
65+ assert cve_lib.subprojects[rel][data] == config[data]
66+ project = cve_lib.read_external_subproject_details(rel)
67+ if project and "customer" in project:
68+ assert cve_lib.subprojects[rel]["customer"] == project["customer"]
69+
70+

Subscribers

People subscribed via source and target branches