Merge ~jugmac00/launchpad:oval-check-changes into launchpad:master

Proposed by Jürgen Gmach
Status: Merged
Merged at revision: b548d5ba8a0323532dc263b11b5c6d7bb3b02a00
Proposed branch: ~jugmac00/launchpad:oval-check-changes
Merge into: launchpad:master
Diff against target: 116 lines (+77/-0)
1 file modified
lib/lp/archivepublisher/scripts/publishdistro.py (+77/-0)
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+441101@code.launchpad.net

Commit message

Compare incoming OVAL data with already published one

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) wrote (last edit ):

current state:
- tests missing
- one failing test of the tests added for the first OVAL task

Revision history for this message
Jürgen Gmach (jugmac00) wrote (last edit ):

```
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/oval-data'
```

Looks like this is an integration issue, as
```
    def setUpOVALDataRsync(self):
        self.pushConfig(
            "archivepublisher",
            oval_data_rsync_endpoint="oval.internal::oval/",
            oval_data_root="/tmp/oval-data",
            oval_data_rsync_timeout=90,
        )
```
defines `/tmp/oval-data` but does not create it.

For testing we should better use a temporary directory handled by one of the test helpers we use.

Revision history for this message
Guruprasad (lgp171188) wrote :

Jürgen,

> - one failing test of the tests added for the first OVAL task
...
> Looks like this is an integration issue, as
> ...
> defines `/tmp/oval-data` but does not create it.
> For testing we should better use a temporary directory handled by one of the test helpers we use.

All the tests that were added along with this helper method in my changes for the first OVAL task **do not** invoke `rsync` (it doesn't make sense to do so when running tests) at all. So there was no need to create a directory because even if we created one, it wouldn't be used at all and any other arbitrary directory value would have worked as well for those tests. That is why those tests passed and the changes were deployed. :)

If the new code/tests that you have written expect the directory to be created, feel free to add the necessary setup code for it.

Revision history for this message
Colin Watson (cjwatson) wrote :

I adopted this and proposed https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/441468 with a number of fixes on top of it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/archivepublisher/scripts/publishdistro.py b/lib/lp/archivepublisher/scripts/publishdistro.py
2index 419b1ef..8147040 100644
3--- a/lib/lp/archivepublisher/scripts/publishdistro.py
4+++ b/lib/lp/archivepublisher/scripts/publishdistro.py
5@@ -8,7 +8,9 @@ __all__ = [
6 ]
7
8 import os
9+from filecmp import dircmp
10 from optparse import OptionValueError
11+from pathlib import Path
12 from subprocess import CalledProcessError, check_call
13
14 from storm.store import Store
15@@ -21,6 +23,7 @@ from lp.archivepublisher.publishing import (
16 getPublisher,
17 )
18 from lp.archivepublisher.scripts.base import PublisherScript
19+from lp.registry.interfaces.distribution import IDistributionSet
20 from lp.services.config import config
21 from lp.services.limitedlist import LimitedList
22 from lp.services.scripts.base import LaunchpadScriptFailure
23@@ -46,6 +49,35 @@ def is_ppa_public(ppa):
24 return not ppa.private
25
26
27+def has_oval_data_changed(incoming_dir, published_dir):
28+ """Compare the incoming data with the already published one."""
29+ return bool(dircmp(incoming_dir, published_dir).diff_files)
30+
31+
32+def path_to_published_oval_data(
33+ owner, archive, distribution, series, is_private_ppa
34+):
35+ """A path could look like this on dogfood:
36+
37+ /srv/launchpad.net/ppa/cjwatson/dogfood/ubuntu/dists/jammy/main
38+ """
39+ if is_private_ppa:
40+ start_dir = Path(config.personalpackagearchive.private_root)
41+ else:
42+ start_dir = Path(config.personalpackagearchive.root)
43+ path = (
44+ start_dir
45+ / owner
46+ / archive
47+ / distribution
48+ / "dists"
49+ / series
50+ / "main"
51+ / "oval"
52+ )
53+ return path
54+
55+
56 class PublishDistro(PublisherScript):
57 """Distro publisher."""
58
59@@ -548,12 +580,57 @@ class PublishDistro(PublisherScript):
60 " has been configured."
61 )
62
63+ def check_for_updated_oval_data(self):
64+ """Compare the published OVAL files with the incoming one."""
65+ # XXX 2023-04-14 jugmac00: pull this up together with the same check
66+ # in `rsync_oval_data`
67+ if not config.archivepublisher.oval_data_rsync_endpoint:
68+ return
69+ start_dir = Path(config.archivepublisher.oval_data_root)
70+ for owner_path in start_dir.iterdir():
71+ for distribution_path in owner_path.iterdir():
72+ distribution = getUtility(IDistributionSet).getByName(
73+ distribution_path.name
74+ )
75+ for archive_path in start_dir.iterdir():
76+ for suite_path in archive_path.iterdir():
77+ incoming_dir = suite_path / "main"
78+ series, pocket = self.findSuite(
79+ distribution=distribution, suite=suite_path.name
80+ )
81+ archive = getUtility(IArchiveSet).getByReference(
82+ "~"
83+ + owner_path.name
84+ + "/"
85+ + distribution_path.name
86+ + "/"
87+ + archive_path.name
88+ )
89+ published_dir = path_to_published_oval_data(
90+ owner=owner_path.name,
91+ archive=archive_path.name,
92+ distribution=distribution_path.name,
93+ series=series,
94+ is_private_ppa=archive.private,
95+ )
96+ if has_oval_data_changed(
97+ incoming_dir=incoming_dir,
98+ published_dir=published_dir,
99+ ):
100+ archive.markSuiteDirty(
101+ distroseries=distribution.getSeries(series),
102+ pocket=pocket,
103+ )
104+
105 def main(self, reset_store_between_archives=True):
106 """See `LaunchpadScript`."""
107 self.validateOptions()
108 self.logOptions()
109
110+ # XXX jugmac00 2023-04-14: pull up config check from the following two
111+ # methods
112 self.rsync_oval_data()
113+ self.check_for_updated_oval_data()
114
115 archive_ids = []
116 for distribution in self.findDistros():

Subscribers

People subscribed via source and target branches

to status/vote changes: