コード例 #1
0
    def test_push_with_upload_failure_falls_back(self):
        # Upload
        with mock.patch('snapcraft.storeapi._status_tracker.' 'StatusTracker'):
            result = self.run_command(['push', self.snap_file])
        self.assertThat(result.exit_code, Equals(0))

        # Raise exception in delta upload
        patcher = mock.patch('snapcraft._store._push_delta')
        mock_push_delta = patcher.start()
        self.addCleanup(patcher.stop)
        mock_push_delta.side_effect = StoreDeltaApplicationError(
            'There has been a problem while processing a snap delta.')

        mock_tracker = mock.Mock(storeapi._status_tracker.StatusTracker)
        mock_tracker.track.return_value = {
            'code': 'ready_to_release',
            'processed': True,
            'can_release': True,
            'url': '/fake/url',
            'revision': 9,
        }
        patcher = mock.patch.object(storeapi.StoreClient, 'upload')
        mock_upload = patcher.start()
        self.addCleanup(patcher.stop)
        mock_upload.return_value = mock_tracker

        # Upload and ensure fallback is called
        with mock.patch('snapcraft.storeapi.' '_status_tracker.StatusTracker'):
            result = self.run_command(['push', self.snap_file])
        self.assertThat(result.exit_code, Equals(0))
        mock_upload.assert_called_once_with('basic', self.snap_file)
コード例 #2
0
ファイル: test_push.py プロジェクト: tools-env/snapcraft
    def test_push_with_delta_generation_failure_falls_back(self):
        # Upload
        with mock.patch("snapcraft.storeapi._status_tracker.StatusTracker"):
            result = self.run_command(["push", self.snap_file])
        self.assertThat(result.exit_code, Equals(0))

        # Raise exception in delta upload
        patcher = mock.patch("snapcraft._store._push_delta")
        mock_push_delta = patcher.start()
        self.addCleanup(patcher.stop)
        mock_push_delta.side_effect = StoreDeltaApplicationError(
            "There has been a problem while processing a snap delta.")

        mock_tracker = mock.Mock(storeapi._status_tracker.StatusTracker)
        mock_tracker.track.return_value = {
            "code": "ready_to_release",
            "processed": True,
            "can_release": True,
            "url": "/fake/url",
            "revision": 9,
        }
        patcher = mock.patch.object(storeapi.StoreClient, "upload")
        mock_upload = patcher.start()
        self.addCleanup(patcher.stop)
        mock_upload.return_value = mock_tracker

        # Upload and ensure fallback is called
        with mock.patch("snapcraft.storeapi._status_tracker.StatusTracker"):
            result = self.run_command(["push", self.snap_file])
        self.assertThat(result.exit_code, Equals(0))
        mock_upload.assert_called_once_with("basic",
                                            self.snap_file,
                                            built_at=None)
コード例 #3
0
ファイル: _store.py プロジェクト: surajwarrier05/snapcraft
def _push_delta(snap_name, snap_filename, source_snap):
    store = storeapi.StoreClient()
    delta_format = 'xdelta3'
    logger.info('Found cached source snap {}.'.format(source_snap))
    target_snap = os.path.join(os.getcwd(), snap_filename)

    try:
        xdelta_generator = deltas.XDelta3Generator(source_path=source_snap,
                                                   target_path=target_snap)
        delta_filename = xdelta_generator.make_delta()
    except (DeltaGenerationError, DeltaGenerationTooBigError,
            DeltaToolError) as e:
        raise StoreDeltaApplicationError(str(e))

    snap_hashes = {
        'source_hash': calculate_sha3_384(source_snap),
        'target_hash': calculate_sha3_384(target_snap),
        'delta_hash': calculate_sha3_384(delta_filename)
    }

    try:
        logger.info('Pushing delta {}.'.format(delta_filename))
        with _requires_login():
            delta_tracker = store.upload(
                snap_name,
                delta_filename,
                delta_format=delta_format,
                source_hash=snap_hashes['source_hash'],
                target_hash=snap_hashes['target_hash'],
                delta_hash=snap_hashes['delta_hash'])
        result = delta_tracker.track()
        delta_tracker.raise_for_code()
    except storeapi.errors.StoreReviewError as e:
        if e.code == 'processing_upload_delta_error':
            raise StoreDeltaApplicationError
        else:
            raise
    finally:
        if os.path.isfile(delta_filename):
            try:
                os.remove(delta_filename)
            except OSError:
                logger.warning(
                    'Unable to remove delta {}.'.format(delta_filename))
    return result
コード例 #4
0
    def test_push_with_delta_generation_failure_falls_back(self):
        # Upload and ensure fallback is called
        with mock.patch(
                "snapcraft._store._push_delta",
                side_effect=StoreDeltaApplicationError("error"),
        ):
            result = self.run_command(["push", self.snap_file])

        self.assertThat(result.exit_code, Equals(0))
        self.fake_store_upload.mock.assert_called_once_with(
            snap_name="basic",
            snap_filename=self.snap_file,
            built_at=None,
            channels=None,
            delta_format=None,
            delta_hash=None,
            source_hash=None,
            target_hash=None,
        )
コード例 #5
0
    def test_push_with_upload_failure_falls_back(self):
        self.useFixture(fixture_setup.FakeTerminal())
        self.useFixture(fixture_setup.DeltaUploads())

        # Create a source snap to delta from
        main(['init'])
        main(['snap'])
        snap_file = glob.glob('*.snap')[0]

        # Upload
        with mock.patch('snapcraft.storeapi.StatusTracker'):
            main(['push', snap_file])

        # create a target snap
        main(['snap'])

        # Raise exception in delta upload
        patcher = mock.patch('snapcraft._store._push_delta')
        mock_push_delta = patcher.start()
        self.addCleanup(patcher.stop)
        mock_push_delta.side_effect = StoreDeltaApplicationError(
            'There has been a problem while processing a snap delta.')

        mock_tracker = mock.Mock(storeapi.StatusTracker)
        mock_tracker.track.return_value = {
            'code': 'ready_to_release',
            'processed': True,
            'can_release': True,
            'url': '/fake/url',
            'revision': 9,
        }
        patcher = mock.patch.object(storeapi.StoreClient, 'upload')
        mock_upload = patcher.start()
        self.addCleanup(patcher.stop)
        mock_upload.return_value = mock_tracker

        # Upload and ensure fallback is called
        with mock.patch('snapcraft.storeapi.StatusTracker'):
            main(['push', snap_file])
            mock_upload.assert_called_once_with('my-snap-name', snap_file)