How to use get_nvr_info method in autotest

Best Python code snippet using autotest_python

utils_koji.py

Source:utils_koji.py Github

copy

Full Screen

...59 '''60 wo_suffix = self.get_filename_without_suffix()61 arch_sep = wo_suffix.rfind('.')62 return wo_suffix[arch_sep + 1:]63 def get_nvr_info(self):64 '''65 Returns a dictionary with the name, version and release components66 If koji is not installed, this returns None67 '''68 if not KOJI_INSTALLED:69 return None70 return koji.util.koji.parse_NVR(self.get_filename_without_arch())71class KojiClient(object):72 """73 Stablishes a connection with the build system, either koji or brew.74 This class provides convenience methods to retrieve information on packages75 and the packages themselves hosted on the build system. Packages should be76 specified in the KojiPgkSpec syntax.77 """78 CMD_LOOKUP_ORDER = ['/usr/bin/brew', '/usr/bin/koji']79 CONFIG_MAP = {'/usr/bin/brew': '/etc/brewkoji.conf',80 '/usr/bin/koji': '/etc/koji.conf'}81 def __init__(self, cmd=None):82 """83 Verifies whether the system has koji or brew installed, then loads84 the configuration file that will be used to download the files.85 :type cmd: string86 :param cmd: Optional command name, either 'brew' or 'koji'. If not87 set, get_default_command() is used and to look for88 one of them.89 :raise: ValueError90 """91 if not KOJI_INSTALLED:92 raise ValueError('No koji/brew installed on the machine')93 # Instance variables used by many methods94 self.command = None95 self.config = None96 self.config_options = {}97 self.session = None98 # Set koji command or get default99 if cmd is None:100 self.command = self.get_default_command()101 else:102 self.command = cmd103 # Check koji command104 if not self.is_command_valid():105 raise ValueError('Koji command "%s" is not valid' % self.command)106 # Assuming command is valid, set configuration file and read it107 self.config = self.CONFIG_MAP[self.command]108 self.read_config()109 # Setup koji session110 server_url = self.config_options['server']111 session_options = self.get_session_options()112 self.session = koji.ClientSession(server_url,113 session_options)114 def read_config(self, check_is_valid=True):115 '''116 Reads options from the Koji configuration file117 By default it checks if the koji configuration is valid118 :type check_valid: boolean119 :param check_valid: whether to include a check on the configuration120 :raise: ValueError121 :return: None122 '''123 if check_is_valid:124 if not self.is_config_valid():125 raise ValueError('Koji config "%s" is not valid' % self.config)126 config = ConfigParser.ConfigParser()127 config.read(self.config)128 basename = os.path.basename(self.command)129 for name, value in config.items(basename):130 self.config_options[name] = value131 def get_session_options(self):132 '''133 Filter only options necessary for setting up a cobbler client session134 :return: only the options used for session setup135 '''136 session_options = {}137 for name, value in self.config_options.items():138 if name in ('user', 'password', 'debug_xmlrpc', 'debug'):139 session_options[name] = value140 return session_options141 def is_command_valid(self):142 '''143 Checks if the currently set koji command is valid144 :return: True or False145 '''146 koji_command_ok = True147 if not os.path.isfile(self.command):148 logging.error('Koji command "%s" is not a regular file',149 self.command)150 koji_command_ok = False151 if not os.access(self.command, os.X_OK):152 logging.warn('Koji command "%s" is not executable: this is '153 'not fatal but indicates an unexpected situation',154 self.command)155 if self.command not in self.CONFIG_MAP.keys():156 logging.error('Koji command "%s" does not have a configuration '157 'file associated to it', self.command)158 koji_command_ok = False159 return koji_command_ok160 def is_config_valid(self):161 '''162 Checks if the currently set koji configuration is valid163 :return: True or False164 '''165 koji_config_ok = True166 if not os.path.isfile(self.config):167 logging.error('Koji config "%s" is not a regular file', self.config)168 koji_config_ok = False169 if not os.access(self.config, os.R_OK):170 logging.error('Koji config "%s" is not readable', self.config)171 koji_config_ok = False172 config = ConfigParser.ConfigParser()173 config.read(self.config)174 basename = os.path.basename(self.command)175 if not config.has_section(basename):176 logging.error('Koji configuration file "%s" does not have a '177 'section "%s", named after the base name of the '178 'currently set koji command "%s"', self.config,179 basename, self.command)180 koji_config_ok = False181 return koji_config_ok182 def get_default_command(self):183 '''184 Looks up for koji or brew "binaries" on the system185 Systems with plain koji usually don't have a brew cmd, while systems186 with koji, have *both* koji and brew utilities. So we look for brew187 first, and if found, we consider that the system is configured for188 brew. If not, we consider this is a system with plain koji.189 :return: either koji or brew command line executable path, or None190 '''191 koji_command = None192 for command in self.CMD_LOOKUP_ORDER:193 if os.path.isfile(command):194 koji_command = command195 break196 else:197 koji_command_basename = os.path.basename(command)198 try:199 koji_command = os_dep.command(koji_command_basename)200 break201 except ValueError:202 pass203 return koji_command204 def get_pkg_info(self, pkg):205 '''206 Returns information from Koji on the package207 :type pkg: KojiPkgSpec208 :param pkg: information about the package, as a KojiPkgSpec instance209 :return: information from Koji about the specified package210 '''211 info = {}212 if pkg.build is not None:213 info = self.session.getBuild(int(pkg.build))214 elif pkg.tag is not None and pkg.package is not None:215 builds = self.session.listTagged(pkg.tag,216 latest=True,217 inherit=True,218 package=pkg.package)219 if builds:220 info = builds[0]221 return info222 def is_pkg_valid(self, pkg):223 '''224 Checks if this package is altogether valid on Koji225 This verifies if the build or tag specified in the package226 specification actually exist on the Koji server227 :return: True or False228 '''229 valid = True230 if pkg.build:231 if not self.is_pkg_spec_build_valid(pkg):232 valid = False233 elif pkg.tag:234 if not self.is_pkg_spec_tag_valid(pkg):235 valid = False236 else:237 valid = False238 return valid239 def is_pkg_spec_build_valid(self, pkg):240 '''241 Checks if build is valid on Koji242 :param pkg: a Pkg instance243 '''244 if pkg.build is not None:245 info = self.session.getBuild(int(pkg.build))246 if info:247 return True248 return False249 def is_pkg_spec_tag_valid(self, pkg):250 '''251 Checks if tag is valid on Koji252 :type pkg: KojiPkgSpec253 :param pkg: a package specification254 '''255 if pkg.tag is not None:256 tag = self.session.getTag(pkg.tag)257 if tag:258 return True259 return False260 def get_pkg_rpm_info(self, pkg, arch=None):261 '''262 Returns a list of information on the RPM packages found on koji263 :type pkg: KojiPkgSpec264 :param pkg: a package specification265 :type arch: string266 :param arch: packages built for this architecture, but also including267 architecture independent (noarch) packages268 '''269 if arch is None:270 arch = utils.get_arch()271 rpms = []272 info = self.get_pkg_info(pkg)273 if info:274 rpms = self.session.listRPMs(buildID=info['id'],275 arches=[arch, 'noarch'])276 if pkg.subpackages:277 rpms = [d for d in rpms if d['name'] in pkg.subpackages]278 return rpms279 def get_pkg_rpm_names(self, pkg, arch=None):280 '''281 Gets the names for the RPM packages specified in pkg282 :type pkg: KojiPkgSpec283 :param pkg: a package specification284 :type arch: string285 :param arch: packages built for this architecture, but also including286 architecture independent (noarch) packages287 '''288 if arch is None:289 arch = utils.get_arch()290 rpms = self.get_pkg_rpm_info(pkg, arch)291 return [rpm['name'] for rpm in rpms]292 def get_pkg_rpm_file_names(self, pkg, arch=None):293 '''294 Gets the file names for the RPM packages specified in pkg295 :type pkg: KojiPkgSpec296 :param pkg: a package specification297 :type arch: string298 :param arch: packages built for this architecture, but also including299 architecture independent (noarch) packages300 '''301 if arch is None:302 arch = utils.get_arch()303 rpm_names = []304 rpms = self.get_pkg_rpm_info(pkg, arch)305 for rpm in rpms:306 arch_rpm_name = koji.pathinfo.rpm(rpm)307 rpm_name = os.path.basename(arch_rpm_name)308 rpm_names.append(rpm_name)309 return rpm_names310 def get_pkg_base_url(self):311 '''312 Gets the base url for packages in Koji313 '''314 if self.config_options.has_key('pkgurl'):315 return self.config_options['pkgurl']316 else:317 return "%s/%s" % (self.config_options['topurl'],318 'packages')319 def get_scratch_base_url(self):320 '''321 Gets the base url for scratch builds in Koji322 '''323 one_level_up = os.path.dirname(self.get_pkg_base_url())324 return "%s/%s" % (one_level_up, 'scratch')325 def get_pkg_urls(self, pkg, arch=None):326 '''327 Gets the urls for the packages specified in pkg328 :type pkg: KojiPkgSpec329 :param pkg: a package specification330 :type arch: string331 :param arch: packages built for this architecture, but also including332 architecture independent (noarch) packages333 '''334 info = self.get_pkg_info(pkg)335 rpms = self.get_pkg_rpm_info(pkg, arch)336 rpm_urls = []337 base_url = self.get_pkg_base_url()338 for rpm in rpms:339 rpm_name = koji.pathinfo.rpm(rpm)340 url = ("%s/%s/%s/%s/%s" % (base_url,341 info['package_name'],342 info['version'], info['release'],343 rpm_name))344 rpm_urls.append(url)345 return rpm_urls346 def get_pkgs(self, pkg, dst_dir, arch=None):347 '''348 Download the packages349 :type pkg: KojiPkgSpec350 :param pkg: a package specification351 :type dst_dir: string352 :param dst_dir: the destination directory, where the downloaded353 packages will be saved on354 :type arch: string355 :param arch: packages built for this architecture, but also including356 architecture independent (noarch) packages357 '''358 rpm_urls = self.get_pkg_urls(pkg, arch)359 for url in rpm_urls:360 utils.get_file(url,361 os.path.join(dst_dir, os.path.basename(url)))362 def get_scratch_pkg_urls(self, pkg, arch=None):363 '''364 Gets the urls for the scratch packages specified in pkg365 :type pkg: KojiScratchPkgSpec366 :param pkg: a scratch package specification367 :type arch: string368 :param arch: packages built for this architecture, but also including369 architecture independent (noarch) packages370 '''371 rpm_urls = []372 if arch is None:373 arch = utils.get_arch()374 arches = [arch, 'noarch']375 index_url = "%s/%s/task_%s" % (self.get_scratch_base_url(),376 pkg.user,377 pkg.task)378 index_parser = KojiDirIndexParser()379 index_parser.feed(urllib.urlopen(index_url).read())380 if pkg.subpackages:381 for p in pkg.subpackages:382 for pfn in index_parser.package_file_names:383 r = RPMFileNameInfo(pfn)384 info = r.get_nvr_info()385 if (p == info['name'] and386 r.get_arch() in arches):387 rpm_urls.append("%s/%s" % (index_url, pfn))388 else:389 for pfn in index_parser.package_file_names:390 if (RPMFileNameInfo(pfn).get_arch() in arches):391 rpm_urls.append("%s/%s" % (index_url, pfn))392 return rpm_urls393 def get_scratch_pkgs(self, pkg, dst_dir, arch=None):394 '''395 Download the packages from a scratch build396 :type pkg: KojiScratchPkgSpec397 :param pkg: a scratch package specification398 :type dst_dir: string...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful