@@ -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,115 @@ 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+ return urljoin (
1076+ self .pulp_server_url ,
1077+ f'pulp/api/v3/distributions/{ self .pkg_type } /' ,
1078+ self .pkg_type if self .pkg_type == 'rpm' else 'apt'
1079+ )
1080+
1081+ @property
1082+ def _result (self ):
1083+ """Get the results from the pulp api"""
1084+ if getattr (self , '_result_obj' , None ) is None :
1085+ # Get the results from the pulp api.
1086+ self ._result_obj = self ._search ().get ('results' , [])
1087+
1088+ # Check if there is exactly one result.
1089+ if not len (self ._result_obj ):
1090+ log .error (f'No results found for { self ._search_uri } ' )
1091+ raise VersionNotFoundError (f'No results found for { self ._search_uri } ' )
1092+ elif len (self ._result_obj ) > 1 :
1093+ log .error (f'Multiple results found for { self ._search_uri } ' )
1094+ raise VersionNotFoundError (f'Multiple results found for { self ._search_uri } ' )
1095+
1096+ return self ._result_obj [0 ]
1097+
1098+ @property
1099+ def repo_url (self ):
1100+ """Get the repo url from the pulp api"""
1101+ return urljoin (self .pulp_server_url , self ._result .get ('base_url' , '' ))
1102+
1103+ def _get_base_url (self ):
1104+ """Get the base url from the pulp api"""
1105+ return urljoin (
1106+ self .pulp_server_url ,
1107+ "/" .join (self ._result .get ('base_url' , '' ).split ('/' )[:- 2 ])
1108+ )
1109+
1110+ def _search (self ):
1111+ """Search for the package in the pulp api"""
1112+ # Build the search parameters.
1113+ labels = f'project:{ self .project } ,'
1114+ labels += f'flavor:{ self .flavor } ,'
1115+ labels += f'distro:{ self .os_type } ,'
1116+ labels += f'distro_version:{ self .os_version } ,'
1117+
1118+ # Add the architecture to the search parameters.
1119+ arch = 'noarch' if self .force_noarch else self .arch
1120+ labels += f'arch:{ arch } ,'
1121+
1122+ # Add the reference to the search parameters.
1123+ ref_name , ref_val = list (self ._choose_reference ().items ())[0 ]
1124+ labels += f'{ ref_name } :{ ref_val } '
1125+
1126+ resp = requests .get (
1127+ self ._search_uri ,
1128+ params = {'pulp_label_select' : labels },
1129+ auth = (self .pulp_username , self .pulp_password )
1130+ )
1131+ if not resp .ok :
1132+ log .error (f'Failed to get packages with labels: { labels } ' )
1133+ raise VersionNotFoundError (f'Failed to get packages with labels: { labels } ' )
1134+
1135+ return resp .json ()
1136+
1137+ @classmethod
1138+ def _get_distro (cls , distro = None , version = None , codename = None ):
1139+ if distro in ('centos' , 'rhel' ):
1140+ distro = 'centos'
1141+ version = cls ._parse_version (version )
1142+ if distro in ('alma' , 'rocky' ):
1143+ version = cls ._parse_version (version )
1144+ if distro in ('ubuntu' , 'debian' ):
1145+ version = codename
1146+ return f'{ distro } /{ version } '
1147+
1148+ def _get_package_sha1 (self ):
1149+ """Get the package sha1 from the pulp api"""
1150+ return self ._result .get ('pulp_labels' , {}).get ('sha1' , None )
1151+
1152+ def _get_package_version (self ):
1153+ """Get the package version from the pulp api"""
1154+ return self ._result .get ('pulp_labels' , {}).get ('version' , None )
1155+
1156+
10571157def get_builder_project ():
10581158 """
1059- Depending on whether config.use_shaman is True or False , return
1060- GitbuilderProject or ShamanProject (the class, not an instance).
1159+ Depending on whether config.use_artifacts is 'shaman' or 'pulp' , return
1160+ GitbuilderProject, ShamanProject or PulpProject (the class, not an instance).
10611161 """
1062- if config .use_shaman is True :
1162+ if config .use_artifacts == 'shaman' :
10631163 builder_class = ShamanProject
1164+ elif config .use_artifacts == 'pulp' :
1165+ builder_class = PulpProject
10641166 else :
10651167 builder_class = GitbuilderProject
10661168 return builder_class
0 commit comments