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
=== modified file '.bzrignore'
--- .bzrignore 2014-05-02 18:21:36 +0000
+++ .bzrignore 2014-12-15 17:35:33 +0000
@@ -12,3 +12,4 @@
12src/django_pkgme.egg-info/12src/django_pkgme.egg-info/
13test.db13test.db
14env/14env/
15tags
1516
=== modified file 'requirements/test.txt'
--- requirements/test.txt 2014-05-05 18:38:10 +0000
+++ requirements/test.txt 2014-12-15 17:35:33 +0000
@@ -8,6 +8,7 @@
8pyflakes8pyflakes
9testresources==0.2.59testresources==0.2.5
10txpkgme==0.310txpkgme==0.3
11PyYAML
1112
12-e bzr+ssh://bazaar.launchpad.net/+branch/django-pgtools#egg=django-pgtools13-e bzr+ssh://bazaar.launchpad.net/+branch/django-pgtools#egg=django-pgtools
13-e bzr+ssh://bazaar.launchpad.net/+branch/libdep-service#egg=libdep-service14-e bzr+ssh://bazaar.launchpad.net/+branch/libdep-service#egg=libdep-service
1415
=== modified file 'src/djpkgme/tasks.py'
--- src/djpkgme/tasks.py 2014-11-26 20:25:45 +0000
+++ src/djpkgme/tasks.py 2014-12-15 17:35:33 +0000
@@ -374,7 +374,7 @@
374 return results374 return results
375375
376 def process_unpacked(self, metadata, unpacked, unpack_result, logger):376 def process_unpacked(self, metadata, unpacked, unpack_result, logger):
377 return [self.get_package_info(unpacked, logger)]377 return [self.get_package_info(unpacked, logger), self.get_extra_info(unpacked, logger)]
378378
379 def get_package_architectures(self, package):379 def get_package_architectures(self, package):
380 prefix = 'Architecture:'380 prefix = 'Architecture:'
@@ -439,6 +439,12 @@
439 logger)439 logger)
440 return manifest440 return manifest
441441
442 def get_extra_info(self, package, logger):
443 extra_info = {}
444 extra_info['is_snap'] = os.path.exists(
445 os.path.join(package, 'meta', 'package.yaml'))
446 return extra_info
447
442448
443class ClickPackageReviewJob(ClickPackageJob):449class ClickPackageReviewJob(ClickPackageJob):
444 CLICK_CHECKS = ['lint', 'content-hub', 'desktop', 'functional',450 CLICK_CHECKS = ['lint', 'content-hub', 'desktop', 'functional',
445451
=== modified file 'src/djpkgme/tests/test_tasks.py'
--- src/djpkgme/tests/test_tasks.py 2014-11-26 20:56:07 +0000
+++ src/djpkgme/tests/test_tasks.py 2014-12-15 17:35:33 +0000
@@ -9,6 +9,7 @@
9import sys9import sys
10import tarfile10import tarfile
11import traceback11import traceback
12import yaml
1213
13from celery.exceptions import MaxRetriesExceededError14from celery.exceptions import MaxRetriesExceededError
14from devportalbinary.metadata import MetadataBackend15from devportalbinary.metadata import MetadataBackend
@@ -757,6 +758,17 @@
757 with open(os.path.join(debian_dir, 'control'), 'w') as f:758 with open(os.path.join(debian_dir, 'control'), 'w') as f:
758 f.write(control_content)759 f.write(control_content)
759760
761 def make_snappy_manifest(self, manifest_content, directory, raw=False):
762 meta_dir = os.path.join(directory, 'meta')
763 if not os.path.exists(meta_dir):
764 os.mkdir(meta_dir)
765 with open(os.path.join(meta_dir, 'package.yaml'), 'w') as f:
766 if raw:
767 content = manifest_content
768 else:
769 content = yaml.dump(manifest_content, default_flow_style=False)
770 f.write(content)
771
760 def test_get_package_architectures(self):772 def test_get_package_architectures(self):
761 job = ClickPackageInfoJob()773 job = ClickPackageInfoJob()
762 tempdir = self.useFixture(TempDir()).path774 tempdir = self.useFixture(TempDir()).path
@@ -956,9 +968,7 @@
956968
957 self.assertFalse(mock_process_unpacked.called)969 self.assertFalse(mock_process_unpacked.called)
958970
959 @patch('djpkgme.tasks.subprocess.check_output')971 def _assert_integration_succeeds(self, mock_tempdir, mock_call, snappy):
960 @patch('djpkgme.tasks.TempDir')
961 def test_integration(self, mock_tempdir, mock_call):
962 tempdir = self.useFixture(TempDir())972 tempdir = self.useFixture(TempDir())
963 downloaded_path = os.path.join(tempdir.path,973 downloaded_path = os.path.join(tempdir.path,
964 'apackage_1.0_amd64.click')974 'apackage_1.0_amd64.click')
@@ -973,6 +983,11 @@
973 name=package_fullname,983 name=package_fullname,
974 icon='path/to/icon.png'),984 icon='path/to/icon.png'),
975 unpacked_path)985 unpacked_path)
986 if snappy:
987 self.make_snappy_manifest(dict(
988 name=package_fullname,
989 icon='path/to/icon.png'),
990 unpacked_path)
976 self.make_control_file('Architecture: all', unpacked_path)991 self.make_control_file('Architecture: all', unpacked_path)
977992
978 mock_tempdir.return_value = self.make_tempdir_fixture_mock(993 mock_tempdir.return_value = self.make_tempdir_fixture_mock(
@@ -984,8 +999,8 @@
984 mock_call.assert_called_with(999 mock_call.assert_called_with(
985 ['dpkg-deb', '-R', downloaded_path, unpacked_path],1000 ['dpkg-deb', '-R', downloaded_path, unpacked_path],
986 stderr=subprocess.STDOUT)1001 stderr=subprocess.STDOUT)
987 self.assertEqual(2, len(results))1002 self.assertEqual(3, len(results))
988 checks, metadata = results1003 checks, metadata, extra_info = results
989 # there are no errors1004 # there are no errors
990 self.assertEqual(0, len(checks['warn']))1005 self.assertEqual(0, len(checks['warn']))
991 self.assertEqual(0, len(checks['error']))1006 self.assertEqual(0, len(checks['error']))
@@ -1000,6 +1015,18 @@
1000 'filename': 'icon.png',1015 'filename': 'icon.png',
1001 'data': None,1016 'data': None,
1002 }}, metadata)1017 }}, metadata)
1018 # and that the package isn't a snap
1019 self.assertEqual(snappy, extra_info['is_snap'])
1020
1021 @patch('djpkgme.tasks.subprocess.check_output')
1022 @patch('djpkgme.tasks.TempDir')
1023 def test_integration(self, mock_tempdir, mock_call):
1024 self._assert_integration_succeeds(mock_tempdir, mock_call, False)
1025
1026 @patch('djpkgme.tasks.subprocess.check_output')
1027 @patch('djpkgme.tasks.TempDir')
1028 def test_snappy_integration(self, mock_tempdir, mock_call):
1029 self._assert_integration_succeeds(mock_tempdir, mock_call, False)
10031030
10041031
1005class TestClickPackageReviewJob(ClickPackageJobTestCase):1032class TestClickPackageReviewJob(ClickPackageJobTestCase):

Subscribers

People subscribed via source and target branches