def test_process_success_waiting_for_package_different_package_id(self): build_output = _setup_build_output("create.json") with database.session_scope() as session: ecosystem = util.create_ecosystem(dict()) waiting_build_id = _create_waiting_build( session, ecosystem, missing_packages=[ util.create_package({ "ecosystem": ecosystem, "package.package_id": "d057732059ea44a47760900cb5e4855d2bea8714" }) ]) build_id = _create_build(session, ecosystem) result = manager.process_success(build_id, build_output) self.assertFalse("new_builds" in result.keys()) with database.session_scope() as session: waiting_build = session.query( database.Build).filter_by(id=waiting_build_id).first() self.assertEqual(database.BuildStatus.error, waiting_build.status)
def test_process_success_waiting_for_package_different_revision(self): build_output = _setup_build_output("create.json") with database.session_scope() as session: ecosystem = util.create_ecosystem(dict()) waiting_build_id = _create_waiting_build( session, ecosystem, missing_packages=[ util.create_package({ "ecosystem": ecosystem, "recipe_revision.revision": "f5c1ba6f1af634f500f7e0255619fecf4777965f" }) ]) build_id = _create_build(session, ecosystem) result = manager.process_success(build_id, build_output) self.assertTrue(result["new_builds"]) with database.session_scope() as session: waiting_build = session.query( database.Build).filter_by(id=waiting_build_id).first() self.assertEqual(database.BuildStatus.new, waiting_build.status)
def test_process_success_remove_missing_items(self): build_output = _setup_build_output("create.json") with database.session_scope() as session: build = util.create_build(dict()) build.missing_recipes = [util.create_recipe(dict())] build.missing_packages = [util.create_package(dict())] session.add(build) session.commit() build_id = build.id manager.process_success(build_id, build_output) with database.session_scope() as session: build = session.query( database.Build).filter_by(id=build_id).first() self.assertEqual(0, len(build.missing_recipes)) self.assertEqual(0, len(build.missing_packages))
def test_process_success_existing_package(self): build_output = _setup_build_output() with database.session_scope() as session: parameters = dict() package = util.create_package(parameters) session.add(package) build = util.create_build(parameters) session.add(build) session.commit() build_id = build.id manager.process_success(build_id, build_output) with database.session_scope() as session: build = session.query( database.Build).filter_by(id=build_id).first() packages = session.query(database.Package).all() self.assertEqual(1, len(packages)) self.assertEqual(1, build.package.id)
def test_process_success_waiting_for_recipe(self): build_output = _setup_build_output("create.json") with database.session_scope() as session: ecosystem = util.create_ecosystem(dict()) waiting_build_id = _create_waiting_build( session, ecosystem, missing_recipes=[util.create_recipe({"ecosystem": ecosystem})]) build_id = _create_build(session, ecosystem) result = manager.process_success(build_id, build_output) self.assertTrue(result["new_builds"]) with database.session_scope() as session: waiting_build = session.query( database.Build).filter_by(id=waiting_build_id).first() self.assertEqual(database.BuildStatus.new, waiting_build.status)
def test_process_success(self): build_output = _setup_build_output() with database.session_scope() as session: build = util.create_build(dict()) session.add(build) session.commit() build_id = build.id result = manager.process_success(build_id, build_output) self.assertFalse("new_builds" in result.keys()) with database.session_scope() as session: build = session.query( database.Build).filter_by(id=build_id).first() self.assertIsNotNone(build.package) self.assertEqual("227220812d7ea3aa060187bae41abbc9911dfdfd", build.package.package_id) self.assertEqual("app", build.package.recipe_revision.recipe.name) self.assertEqual("2b44d2dde63878dd279ebe5d38c60dfaa97153fb", build.package.recipe_revision.revision)
async def __process_builds(self): # database.populate_database() # return logger.info("Start processing builds") platform = database.Platform.linux if sonja_os == "Linux" else database.Platform.windows with database.session_scope() as session: build = session\ .query(database.Build)\ .join(database.Build.profile)\ .filter(database.Profile.platform == platform,\ database.Build.status == database.BuildStatus.new)\ .populate_existing()\ .with_for_update(skip_locked=True, of=database.Build)\ .first() if not build: logger.info("Stop processing builds with *no* builds processed") return False logger.info("Set status of build '%d' to 'active'", build.id) self.__build_id = build.id build.status = database.BuildStatus.active build.log.logs = '' container = build.profile.container parameters = { "conan_config_url": build.profile.ecosystem.conan_config_url, "conan_config_path": build.profile.ecosystem.conan_config_path, "conan_config_branch": build.profile.ecosystem.conan_config_branch, "conan_remote": build.profile.ecosystem.conan_remote, "conan_user": build.profile.ecosystem.conan_user, "conan_password": build.profile.ecosystem.conan_password, "conan_profile": build.profile.conan_profile, "conan_options": " ".join(["-o {0}={1}".format(option.key, option.value) for option in build.commit.repo.options]), "git_url": build.commit.repo.url, "git_sha": build.commit.sha, "git_credentials": [ { "url": c.url, "username": c.username, "password": c.password } for c in build.profile.ecosystem.credentials ], "sonja_user": build.profile.ecosystem.user, "channel": build.commit.channel.conan_channel, "path": "./{0}/{1}".format(build.commit.repo.path, "conanfile.py") if build.commit.repo.path != "" else "./conanfile.py", "ssh_key": build.profile.ecosystem.ssh_key, "known_hosts": build.profile.ecosystem.known_hosts, "docker_user": build.profile.docker_user, "docker_password": build.profile.docker_password, "mtu": os.environ.get("SONJA_MTU", "1500") } try: with Builder(sonja_os, container) as builder: builder_task = asyncio.create_task(_run_build(builder, parameters)) while True: # wait 10 seconds done, _ = await asyncio.wait({builder_task}, timeout=10) self.__update_logs(builder) # if finished exit if done: builder_task.result() break # check if the build was stopped and cancel it # if necessary if self.__cancel_stopping_build(builder): return True logger.info("Process build output") result = manager.process_success(self.__build_id, builder.build_output) if result.get("new_builds", False): self.__trigger_scheduler() logger.info("Set status of build '%d' to 'success'", self.__build_id) self.__set_build_status(database.BuildStatus.success) self.__build_id = None except Exception as e: logger.info(e) manager.process_failure(self.__build_id, builder.build_output) logger.info("Set status of build '%d' to 'error'", self.__build_id) self.__set_build_status(database.BuildStatus.error) self.__build_id = None return True