Merge lp:~jamestait/pkgme-service/snappy-packages-have-snap-extension into lp:pkgme-service

Proposed by James Tait
Status: Merged
Approved by: James Tait
Approved revision: 207
Merged at revision: 207
Proposed branch: lp:~jamestait/pkgme-service/snappy-packages-have-snap-extension
Merge into: lp:pkgme-service
Diff against target: 129 lines (+41/-6)
4 files modified
.bzrignore (+1/-0)
requirements/test.txt (+1/-0)
src/djpkgme/tasks.py (+7/-1)
src/djpkgme/tests/test_tasks.py (+32/-5)
To merge this branch: bzr merge lp:~jamestait/pkgme-service/snappy-packages-have-snap-extension
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+244767@code.launchpad.net

Commit message

Detect whether the scanned package is a Snappy package, and return the is_snappy flag to SCA.

Description of the change

This branch looks in the scanned package for the presence of the
meta/package.yaml file, indicating that this is a Snappy package, and sets the
is_snap in the metadata response accordingly.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2014-05-02 18:21:36 +0000
3+++ .bzrignore 2014-12-15 17:35:33 +0000
4@@ -12,3 +12,4 @@
5 src/django_pkgme.egg-info/
6 test.db
7 env/
8+tags
9
10=== modified file 'requirements/test.txt'
11--- requirements/test.txt 2014-05-05 18:38:10 +0000
12+++ requirements/test.txt 2014-12-15 17:35:33 +0000
13@@ -8,6 +8,7 @@
14 pyflakes
15 testresources==0.2.5
16 txpkgme==0.3
17+PyYAML
18
19 -e bzr+ssh://bazaar.launchpad.net/+branch/django-pgtools#egg=django-pgtools
20 -e bzr+ssh://bazaar.launchpad.net/+branch/libdep-service#egg=libdep-service
21
22=== modified file 'src/djpkgme/tasks.py'
23--- src/djpkgme/tasks.py 2014-11-26 20:25:45 +0000
24+++ src/djpkgme/tasks.py 2014-12-15 17:35:33 +0000
25@@ -374,7 +374,7 @@
26 return results
27
28 def process_unpacked(self, metadata, unpacked, unpack_result, logger):
29- return [self.get_package_info(unpacked, logger)]
30+ return [self.get_package_info(unpacked, logger), self.get_extra_info(unpacked, logger)]
31
32 def get_package_architectures(self, package):
33 prefix = 'Architecture:'
34@@ -439,6 +439,12 @@
35 logger)
36 return manifest
37
38+ def get_extra_info(self, package, logger):
39+ extra_info = {}
40+ extra_info['is_snap'] = os.path.exists(
41+ os.path.join(package, 'meta', 'package.yaml'))
42+ return extra_info
43+
44
45 class ClickPackageReviewJob(ClickPackageJob):
46 CLICK_CHECKS = ['lint', 'content-hub', 'desktop', 'functional',
47
48=== modified file 'src/djpkgme/tests/test_tasks.py'
49--- src/djpkgme/tests/test_tasks.py 2014-11-26 20:56:07 +0000
50+++ src/djpkgme/tests/test_tasks.py 2014-12-15 17:35:33 +0000
51@@ -9,6 +9,7 @@
52 import sys
53 import tarfile
54 import traceback
55+import yaml
56
57 from celery.exceptions import MaxRetriesExceededError
58 from devportalbinary.metadata import MetadataBackend
59@@ -757,6 +758,17 @@
60 with open(os.path.join(debian_dir, 'control'), 'w') as f:
61 f.write(control_content)
62
63+ def make_snappy_manifest(self, manifest_content, directory, raw=False):
64+ meta_dir = os.path.join(directory, 'meta')
65+ if not os.path.exists(meta_dir):
66+ os.mkdir(meta_dir)
67+ with open(os.path.join(meta_dir, 'package.yaml'), 'w') as f:
68+ if raw:
69+ content = manifest_content
70+ else:
71+ content = yaml.dump(manifest_content, default_flow_style=False)
72+ f.write(content)
73+
74 def test_get_package_architectures(self):
75 job = ClickPackageInfoJob()
76 tempdir = self.useFixture(TempDir()).path
77@@ -956,9 +968,7 @@
78
79 self.assertFalse(mock_process_unpacked.called)
80
81- @patch('djpkgme.tasks.subprocess.check_output')
82- @patch('djpkgme.tasks.TempDir')
83- def test_integration(self, mock_tempdir, mock_call):
84+ def _assert_integration_succeeds(self, mock_tempdir, mock_call, snappy):
85 tempdir = self.useFixture(TempDir())
86 downloaded_path = os.path.join(tempdir.path,
87 'apackage_1.0_amd64.click')
88@@ -973,6 +983,11 @@
89 name=package_fullname,
90 icon='path/to/icon.png'),
91 unpacked_path)
92+ if snappy:
93+ self.make_snappy_manifest(dict(
94+ name=package_fullname,
95+ icon='path/to/icon.png'),
96+ unpacked_path)
97 self.make_control_file('Architecture: all', unpacked_path)
98
99 mock_tempdir.return_value = self.make_tempdir_fixture_mock(
100@@ -984,8 +999,8 @@
101 mock_call.assert_called_with(
102 ['dpkg-deb', '-R', downloaded_path, unpacked_path],
103 stderr=subprocess.STDOUT)
104- self.assertEqual(2, len(results))
105- checks, metadata = results
106+ self.assertEqual(3, len(results))
107+ checks, metadata, extra_info = results
108 # there are no errors
109 self.assertEqual(0, len(checks['warn']))
110 self.assertEqual(0, len(checks['error']))
111@@ -1000,6 +1015,18 @@
112 'filename': 'icon.png',
113 'data': None,
114 }}, metadata)
115+ # and that the package isn't a snap
116+ self.assertEqual(snappy, extra_info['is_snap'])
117+
118+ @patch('djpkgme.tasks.subprocess.check_output')
119+ @patch('djpkgme.tasks.TempDir')
120+ def test_integration(self, mock_tempdir, mock_call):
121+ self._assert_integration_succeeds(mock_tempdir, mock_call, False)
122+
123+ @patch('djpkgme.tasks.subprocess.check_output')
124+ @patch('djpkgme.tasks.TempDir')
125+ def test_snappy_integration(self, mock_tempdir, mock_call):
126+ self._assert_integration_succeeds(mock_tempdir, mock_call, False)
127
128
129 class TestClickPackageReviewJob(ClickPackageJobTestCase):

Subscribers

People subscribed via source and target branches