class LaunchpadTest(VCRTestCase): def _get_vcr_kwargs(self): """ This removes the authorization header from VCR so we don't record auth parameters """ return {"filter_headers": ["Authorization"]} def setUp(self): self.lp_for_snaps = Launchpad( username="******", token=getenv("SNAP_BUILDS_TOKEN", "secret"), secret=getenv("SNAP_BUILDS_SECRET", "secret"), session=requests.Session(), ) return super().setUp() def test_01_build_image(self): lp_for_images = Launchpad( username="******", token=getenv("IMAGE_BUILDS_TOKEN", "secret"), secret=getenv("IMAGE_BUILDS_SECRET", "secret"), session=requests.Session(), ) response = lp_for_images.build_image(board="cm3", system="core16", snaps=["code", "toto"]) self.assertEqual(response.status_code, 201) def test_02_get_snap_by_store_name(self): snap = self.lp_for_snaps.get_snap_by_store_name("toto") self.assertEqual("toto", snap["store_name"]) snap = self.lp_for_snaps.get_snap_by_store_name( "snap-that-does-not-exist") self.assertEqual(None, snap) def test_03_create_snap(self): snap_name = "new-test-snap" git_repo = "https://github.com/build-staging-snapcraft-io/test1" self.lp_for_snaps.create_snap(snap_name, git_repo, "macaroon") # Check that the snap exist new_snap = self.lp_for_snaps.get_snap_by_store_name("new-test-snap") self.assertEqual(git_repo, new_snap["git_repository_url"]) def test_04_build_snap(self): result = self.lp_for_snaps.build_snap("toto") self.assertEqual(True, result)
class LaunchpadTest(VCRTestCase): def _get_vcr_kwargs(self): """ This removes the authorization header from VCR so we don't record auth parameters """ return {"filter_headers": ["Authorization"]} def setUp(self): self.lp_for_snaps = Launchpad( username="******", token=getenv("SNAP_BUILDS_TOKEN", "secret"), secret=getenv("SNAP_BUILDS_SECRET", "secret"), session=requests.Session(), ) self.lp_for_images = Launchpad( username="******", token=getenv("IMAGE_BUILDS_TOKEN", "secret"), secret=getenv("IMAGE_BUILDS_SECRET", "secret"), session=requests.Session(), ) return super().setUp() def test_01_build_image(self): response = self.lp_for_images.build_image( board="cm3", system="core16", snaps=["code", "toto"], author_info={ "name": "somename", "email": "someemail" }, gpg_passphrase="fakepassword", ) self.assertEqual(response.status_code, 201) def test_02_create_webhooks(self): print(getenv("IMAGE_BUILDS_TOKEN", "secret")) print(getenv("IMAGE_BUILDS_SECRET", "secret")) with self.assertRaises(WebhookExistsError): self.lp_for_images.create_system_build_webhook( "core18", "https://design.staging.ubuntu.com/?image.build", "fake-secret", ) response = self.lp_for_images.create_system_build_webhook( "classic18.04", "https://design.staging.ubuntu.com/?image.build", "fake-secret", ) self.assertEqual(response.status_code, 201) def test_03_get_snap_by_store_name(self): snap = self.lp_for_snaps.get_snap_by_store_name("toto") self.assertEqual("toto", snap["store_name"]) snap = self.lp_for_snaps.get_snap_by_store_name( "snap-that-does-not-exist") self.assertEqual(None, snap) def test_04_create_snap(self): snap_name = "new-test-snap" git_repo = "https://github.com/build-staging-snapcraft-io/test1" self.lp_for_snaps.create_snap(snap_name, git_repo, "macaroon") # Check that the snap exist new_snap = self.lp_for_snaps.get_snap_by_store_name("new-test-snap") self.assertEqual(git_repo, new_snap["git_repository_url"]) def test_05_build_snap(self): result = self.lp_for_snaps.build_snap("toto") self.assertEqual(True, result) def test_05_delete_snap(self): result = self.lp_for_snaps.delete_snap("new-test-snap") self.assertEqual(True, result)
error_snaps = 0 for snap in snaps: current_snap += 1 logaugment.add(logger, current_snap=current_snap) try: if needs_building(snap, logger): logger.debug(f"Snap {snap['store_name']} needs building") if launchpad.is_snap_building(snap["store_name"]): logger.debug( f"Snap {snap['store_name']} is already being build") else: logger.warning(f"BUILD {snap['store_name']}") launchpad.build_snap(snap["store_name"]) built_snaps += 1 else: skipped_snaps += 1 except GitHubRateLimit as e: logger.error("GitHub API rate limit exceeded") # Raise the exception to abort the script and catch it on Sentry raise e except Exception as e: # Extra info for Sentry e.snap_launchpad_name = snap["name"] e.snap_name = snap["store_name"] e.snap_github_repo = snap["git_repository_url"] # Send this exception to Sentry but script will continue capture_exception(e)