def module_build_from_modulemd(yaml): """ Create a ModuleBuild object and return. It is not written into database. Please commit by yourself if necessary. """ mmd = load_mmd(yaml) build = ModuleBuild() build.name = mmd.get_module_name() build.stream = mmd.get_stream_name() build.version = mmd.get_version() build.state = BUILD_STATES["ready"] build.modulemd = yaml build.koji_tag = None build.batch = 0 build.owner = "some_other_user" build.time_submitted = datetime(2016, 9, 3, 12, 28, 33) build.time_modified = datetime(2016, 9, 3, 12, 28, 40) build.time_completed = None build.rebuild_strategy = "changed-and-after" return build
def _populate_data(data_size=10, contexts=False, scratch=False): # Query arch from passed database session, otherwise there will be an error # like "Object '<ModuleBuild at 0x7f4ccc805c50>' is already attached to # session '275' (this is '276')" when add new module build object to passed # session. task_id_counter = itertools.count(1) arch = db_session.query( module_build_service.common.models.ModuleArch).get(1) num_contexts = 2 if contexts else 1 for index in range(data_size): for context in range(num_contexts): build_one = ModuleBuild( name="nginx", stream="1", version=2 + index, state=BUILD_STATES["ready"], scratch=scratch, modulemd=read_staged_data("nginx_mmd"), koji_tag="scrmod-nginx-1.2" if scratch else "module-nginx-1.2", scmurl="git://pkgs.domain.local/modules/nginx" "?#ba95886c7a443b36a9ce31abda1f9bef22f2f8c9", batch=2, # https://www.youtube.com/watch?v=iQGwrK_yDEg, owner="Moe Szyslak", time_submitted=datetime(2016, 9, 3, 11, 23, 20) + timedelta(minutes=(index * 10)), time_modified=datetime(2016, 9, 3, 11, 25, 32) + timedelta(minutes=(index * 10)), time_completed=datetime(2016, 9, 3, 11, 25, 32) + timedelta(minutes=(index * 10)), rebuild_strategy="changed-and-after", ) build_one.arches.append(arch) if contexts: build_one.stream = str(index) nsvc = "{}:{}:{}:{}".format(build_one.name, build_one.stream, build_one.version, context) unique_hash = hashlib.sha1(nsvc.encode('utf-8')).hexdigest() build_one.build_context = unique_hash build_one.runtime_context = unique_hash combined_hashes = "{0}:{1}".format(unique_hash, unique_hash) build_one.context = hashlib.sha1( combined_hashes.encode("utf-8")).hexdigest()[:8] db_session.add(build_one) db_session.commit() build_one_component_release = get_rpm_release( db_session, build_one) db_session.add_all([ ComponentBuild(package="nginx", scmurl="git://pkgs.domain.local/rpms/nginx?" "#ga95886c8a443b36a9ce31abda1f9bed22f2f8c3", format="rpms", task_id=six.next(task_id_counter), state=koji.BUILD_STATES["COMPLETE"], nvr="nginx-1.10.1-2.{0}".format( build_one_component_release), batch=1, module_id=2 + index * 3, tagged=True, tagged_in_final=True), ComponentBuild( package="module-build-macros", scmurl="/tmp/module_build_service-build-macrosWZUPeK/SRPMS/" "module-build-macros-0.1-1.module_nginx_1_2.src.rpm", format="rpms", task_id=six.next(task_id_counter), state=koji.BUILD_STATES["COMPLETE"], nvr="module-build-macros-01-1.{0}".format( build_one_component_release), batch=2, module_id=2 + index * 3, tagged=True, tagged_in_final=True) ]) db_session.commit() build_two = ModuleBuild( name="postgressql", stream="1", version=2 + index, state=BUILD_STATES["done"], scratch=scratch, modulemd=read_staged_data("testmodule"), koji_tag="scrmod-postgressql-1.2" if scratch else "module-postgressql-1.2", scmurl="git://pkgs.domain.local/modules/postgressql" "?#aa95886c7a443b36a9ce31abda1f9bef22f2f8c9", batch=2, owner="some_user", time_submitted=datetime(2016, 9, 3, 12, 25, 33) + timedelta(minutes=(index * 10)), time_modified=datetime(2016, 9, 3, 12, 27, 19) + timedelta(minutes=(index * 10)), time_completed=datetime(2016, 9, 3, 11, 27, 19) + timedelta(minutes=(index * 10)), rebuild_strategy="changed-and-after", ) build_two.arches.append(arch) db_session.add(build_two) db_session.commit() build_two_component_release = get_rpm_release(db_session, build_two) db_session.add_all([ ComponentBuild(package="postgresql", scmurl="git://pkgs.domain.local/rpms/postgresql" "?#dc95586c4a443b26a9ce38abda1f9bed22f2f8c3", format="rpms", task_id=2433433 + index, state=koji.BUILD_STATES["COMPLETE"], nvr="postgresql-9.5.3-4.{0}".format( build_two_component_release), batch=2, module_id=3 + index * 3, tagged=True, tagged_in_final=True), ComponentBuild( package="module-build-macros", scmurl="/tmp/module_build_service-build-macrosWZUPeK/SRPMS/" "module-build-macros-0.1-1.module_postgresql_1_2.src.rpm", format="rpms", task_id=47383993 + index, state=koji.BUILD_STATES["COMPLETE"], nvr="module-build-macros-01-1.{0}".format( build_two_component_release), batch=1, module_id=3 + index * 3) ]) db_session.commit() build_three = ModuleBuild( name="testmodule", stream="4.3.43", version=6 + index, state=BUILD_STATES["wait"], scratch=scratch, modulemd=read_staged_data("testmodule"), koji_tag=None, scmurl="git://pkgs.domain.local/modules/testmodule" "?#ca95886c7a443b36a9ce31abda1f9bef22f2f8c9", batch=0, owner="some_other_user", time_submitted=datetime(2016, 9, 3, 12, 28, 33) + timedelta(minutes=(index * 10)), time_modified=datetime(2016, 9, 3, 12, 28, 40) + timedelta(minutes=(index * 10)), time_completed=None, rebuild_strategy="changed-and-after", ) db_session.add(build_three) db_session.commit() build_three_component_release = get_rpm_release( db_session, build_three) db_session.add_all([ ComponentBuild(package="rubygem-rails", scmurl="git://pkgs.domain.local/rpms/rubygem-rails" "?#dd55886c4a443b26a9ce38abda1f9bed22f2f8c3", format="rpms", task_id=2433433 + index, state=koji.BUILD_STATES["FAILED"], nvr="postgresql-9.5.3-4.{0}".format( build_three_component_release), batch=2, module_id=4 + index * 3), ComponentBuild( package="module-build-macros", scmurl="/tmp/module_build_service-build-macrosWZUPeK/SRPMS/" "module-build-macros-0.1-1.module_testmodule_1_2.src.rpm", format="rpms", task_id=47383993 + index, state=koji.BUILD_STATES["COMPLETE"], nvr="module-build-macros-01-1.{0}".format( build_three_component_release), batch=1, module_id=4 + index * 3, tagged=True, build_time_only=True) ]) db_session.commit()