@@ -847,7 +847,7 @@ def _remove_deb_repo(self):
847847class ShamanProject (GitbuilderProject ):
848848 def __init__ (self , project , job_config , ctx = None , remote = None ):
849849 super (ShamanProject , self ).__init__ (project , job_config , ctx , remote )
850- self .query_url = 'https://%s/api/' % config .shaman_host
850+ self .query_url = 'https://%s/api/' % config .artifacts_host
851851
852852 # Force to use the "noarch" instead to build the uri.
853853 self .force_noarch = self .job_config .get ("shaman" , {}).get ("force_noarch" , False )
@@ -1054,13 +1054,113 @@ def _remove_rpm_repo(self):
10541054 )
10551055
10561056
1057+ class PulpProject (GitbuilderProject ):
1058+ def __init__ (self , project , job_config , ctx = None , remote = None ):
1059+ super (PulpProject , self ).__init__ (project , job_config , ctx , remote )
1060+
1061+ # Set the url for the pulp server.
1062+ self .pulp_server_url = f'http://{ config .artifacts_host } '
1063+ self .pulp_username = config .pulp .get ("username" )
1064+ self .pulp_password = config .pulp .get ("password" )
1065+
1066+ if not self .pulp_username or not self .pulp_password :
1067+ raise ValueError ("Pulp username and password are required" )
1068+
1069+ # Force to use the "noarch" instead to build the uri.
1070+ self .force_noarch = self .job_config .get ('pulp' , {}).get ('force_noarch' , False )
1071+
1072+ @property
1073+ def _search_uri (self ):
1074+ """Build the search url"""
1075+ tail = 'rpm' if self .pkg_type == 'rpm' else 'apt'
1076+ path = f'pulp/api/v3/distributions/{ self .pkg_type } /{ tail } '
1077+ return urljoin (self .pulp_server_url , path )
1078+
1079+ @property
1080+ def _result (self ):
1081+ """Get the results from the pulp api"""
1082+ if getattr (self , '_result_obj' , None ) is None :
1083+ # Get the results from the pulp api.
1084+ self ._result_obj = self ._search ().get ('results' , [])
1085+
1086+ # Check if there is exactly one result.
1087+ if not len (self ._result_obj ):
1088+ log .error (f'No results found for { self ._search_uri } ' )
1089+ raise VersionNotFoundError (f'No results found for { self ._search_uri } ' )
1090+ elif len (self ._result_obj ) > 1 :
1091+ log .error (f'Multiple results found for { self ._search_uri } ' )
1092+ raise VersionNotFoundError (f'Multiple results found for { self ._search_uri } ' )
1093+
1094+ return self ._result_obj [0 ]
1095+
1096+ @property
1097+ def repo_url (self ):
1098+ """Get the repo url from the pulp api"""
1099+ return urljoin (self .pulp_server_url , self ._result .get ('base_url' , '' ))
1100+
1101+ def _get_base_url (self ):
1102+ """Get the base url from the pulp api"""
1103+ return urljoin (
1104+ self .pulp_server_url ,
1105+ "/" .join (self ._result .get ('base_url' , '' ).split ('/' )[:- 2 ])
1106+ )
1107+
1108+ def _search (self ):
1109+ """Search for the package in the pulp api"""
1110+ # Build the search parameters.
1111+ labels = f'project:{ self .project } ,'
1112+ labels += f'flavor:{ self .flavor } ,'
1113+ labels += f'distro:{ self .os_type } ,'
1114+ labels += f'distro_version:{ self .os_version } ,'
1115+
1116+ # Add the architecture to the search parameters.
1117+ arch = 'noarch' if self .force_noarch else self .arch
1118+ labels += f'arch:{ arch } ,'
1119+
1120+ # Add the reference to the search parameters.
1121+ ref_name , ref_val = list (self ._choose_reference ().items ())[0 ]
1122+ labels += f'{ ref_name } :{ ref_val } '
1123+
1124+ resp = requests .get (
1125+ self ._search_uri ,
1126+ params = {'pulp_label_select' : labels },
1127+ auth = (self .pulp_username , self .pulp_password )
1128+ )
1129+ if not resp .ok :
1130+ log .error (f'Failed to get packages with labels: { labels } ' )
1131+ raise VersionNotFoundError (f'Failed to get packages with labels: { labels } ' )
1132+
1133+ return resp .json ()
1134+
1135+ @classmethod
1136+ def _get_distro (cls , distro = None , version = None , codename = None ):
1137+ if distro in ('centos' , 'rhel' ):
1138+ distro = 'centos'
1139+ version = cls ._parse_version (version )
1140+ if distro in ('alma' , 'rocky' ):
1141+ version = cls ._parse_version (version )
1142+ if distro in ('ubuntu' , 'debian' ):
1143+ version = codename or version
1144+ return f'{ distro } /{ version } '
1145+
1146+ def _get_package_sha1 (self ):
1147+ """Get the package sha1 from the pulp api"""
1148+ return self ._result .get ('pulp_labels' , {}).get ('sha1' , None )
1149+
1150+ def _get_package_version (self ):
1151+ """Get the package version from the pulp api"""
1152+ return self ._result .get ('pulp_labels' , {}).get ('version' , None )
1153+
1154+
10571155def get_builder_project ():
10581156 """
1059- Depending on whether config.use_shaman is True or False , return
1060- GitbuilderProject or ShamanProject (the class, not an instance).
1157+ Depending on whether config.use_artifacts is 'shaman' or 'pulp' , return
1158+ GitbuilderProject, ShamanProject or PulpProject (the class, not an instance).
10611159 """
1062- if config .use_shaman is True :
1160+ if config .use_artifacts == 'shaman' :
10631161 builder_class = ShamanProject
1162+ elif config .use_artifacts == 'pulp' :
1163+ builder_class = PulpProject
10641164 else :
10651165 builder_class = GitbuilderProject
10661166 return builder_class
0 commit comments