用于Red Hat Errata工具的Python API

errata-tool的Python项目详细描述


https://travis-ci.org/red-hat-storage/errata-tool.svg?branch=masterhttps://badge.fury.io/py/errata-tool.svg

红帽勘误表工具的现代python api。

python errata工具是一个python库,它封装了errata工具的rest api。 它使用requests_kerberos 验证json响应并将其解析为Erratum对象。你可以 使用它创建新的建议,或阅读和更新现有的建议。这个 ErratumConnector类还提供对所有 勘误表工具的rest api。

示例:

fromerrata_toolimportErratume=Erratum(errata_id=1234)print(e.errata_state)# prints "NEW_FILES"print(e.url())# prints "https://errata.devel.redhat.com/advisory/1234"

创建新的错误修复建议:

e=Erratum(product='RHCEPH',release='rhceph-2.1',#errata_type='RHBA'         # Default; may be omittedsynopsis='Red Hat Ceph Storage 2.1 bug fix update',topic='An update for Red Hat Ceph 2.1 is now available.',description='This update contains the following fixes ...',solution='Before applying this update...',qe_email='someone@redhat.com',qe_group='RHC (Ceph) QE',owner_email='kdreyer@redhat.com',manager_email='ohno@redhat.com',)e.commit()print(e.url())

创建新的增强(功能)提示:

e=Erratum(product='RHCEPH',release='rhceph-2.1',errata_type='RHEA',# Set to RHEA for RHEAsynopsis='Red Hat Ceph Storage 2.1 enhancement update',topic='An update for Red Hat Ceph 2.1 is now available.',description='This update contains the following features ...',solution='Before applying this update...',qe_email='someone@redhat.com',qe_group='RHC (Ceph) QE',owner_email='kdreyer@redhat.com',manager_email='ohno@redhat.com',)e.commit()print(e.url())

创建新的安全顾问。注意RHSA(安全) 建议是四种影响之一(低、中、低 重要的和关键的)。有关详细信息,请参阅此链接: https://access.redhat.com/security/updates/classification

e=Erratum(product='RHCEPH',release='rhceph-2.1',errata_type='RHSA',# Set to RHSA for RHSAsecurity_impact='Moderate',# Required for RHSAsynopsis='Red Hat Ceph Storage 2.1 security update',topic='An update for Red Hat Ceph 2.1 is now available.',description='This update contains the following fixes ...',solution='Before applying this update...',qe_email='someone@redhat.com',qe_group='RHC (Ceph) QE',owner_email='kdreyer@redhat.com',manager_email='ohno@redhat.com',)e.commit()print(e.url())

勘误表工具命令行界面

errata-toolcli是类的瘦包装。你可以用它 从勘误表工具查询信息或创建新版本(发布):

errata-tool -h

usage: errata-tool [-h] [--stage] [--dry-run] {advisory,product,release} ...

positional arguments:
  {advisory,product,release}
    advisory            Get or create an advisory
    product             Get a product
    release             Get or create a release (RCM)

optional arguments:
  --stage               use staging ET instance
  --dry-run             show what would happen, but don't do it

更多python示例

获取勘误表的名称:

e=Erratum(errata_id=22986)print(e.errata_name)# prints "RH*A-YYYY:NNNNN", for example "RHBA-2018:12345"

添加错误:

e=Erratum(errata_id=22986)e.addBugs([12345,123678])e.commit()

删除错误:

e=Erratum(errata_id=22986)e.removeBugs([12345,123678])# You can simply call "commit()" without checking the return code, or check# it and use refresh() to refresh our local instance data for the errata# advisory.need_refresh=e.commit()ifneed_refresh:print('refreshing')e.refresh()

检查通知是否被禁止:

e=Erratum(errata_id=22986)ife.embargoed:# it's embargoedelse:# it's not embargoed

检查通知是否仅限文本:

e=Erratum(errata_id=24075)ife.text_only:# it's text-only# If it's an RHSA, you may want to get/set e.text_only_cpe here.else:# it's not text-only

添加生成:

e=Erratum(errata_id=24075)# For non-PDC advisories, the "release" kwarg is the Errata Tools's# "product version", in composedb, for example "RHEL-7-CEPH-2".# For PDC advisories, the "release" kwarg is the PDC identifier,# for example "rhceph-2.4@rhel-7".e.addBuilds(['ceph-10.2.3-17.el7cp'],release='RHEL-7-CEPH-2')

添加容器生成:

e=Erratum(errata_id=34279)# For non-RPM Brew builds, you must specify the file_types kwarg.# For container builds, this is "tar".e.addBuilds('rhceph-rhel7-container-3-9',release='RHEL-7-CEPH-3',file_types={'rhceph-rhel7-container-3-9':['tar']})

更改状态:

e=Erratum(errata_id=24075)e.setState('QE')e.commit()

更改文档审阅者:

e=Erratum(errata_id=24075)e.changeDocsReviewer('kdreyer@redhat.com')

将某人添加到抄送列表:

e=Erratum(errata_id=24075)e.addCC('kdreyer@redhat.com')

更改通知类型:

e=Erratum(errata_id=33840)e.update(errata_type='RHBA')e.commit()

重新加载缺少产品列表的所有特定生成:

e=Erratum(errata_id=24075)ife.missing_product_listings:# a (possibly-empty) list of build NVRsresult=e.reloadBuilds(no_rpm_listing_only=True)# result is a dict for this job tracker

确定通知是否具有RPM或容器:

e=Erratum(errata_id=24075)content_types=e.content_types# result is a list, like ["rpm"], or ["docker"]

获取活动的rpmdiff结果以获取建议:

e=Erratum(errata_id=24075)bad=[]forresultine.externalTests(test_type='rpmdiff'):ifresult['attributes']['status']notin('PASSED','WAIVED'):# See result['attributes']['external_id'] for the integer to pass# into RPMDiff's run API.bad.append(result)

为容器通知设置cdn repos(仅适用于通知 包含Docker图像):

e=Erratum(errata_id=24075)assert'docker'ine.content_typese.metadataCdnRepos(enable='rhel-7-server-rhceph-3-mon-rpms__x86_64')

同样的事情,但对于纯文本的建议:

e=Erratum(errata_id=24075)asserte.text_onlye.textOnlyRepos(enable='rhel-7-server-rhceph-3-mon-rpms__x86_64')

使用产品

^ {tt4} $类可以查找现有的产品。

查找产品:

fromerrata_tool.productimportProductp=Product('RHCEPH')print(p.id)# 104print(p.name)# "RHCEPH"print(p.description)# "Red Hat Ceph Storage"

使用版本

> > > > > }类可以查找现有的发布或 创建新的发布条目。

查找发行版:

fromerrata_tool.releaseimportReleaser=Release(name='rhceph-2.4')print(r.id)# 792print(r.name)# "rhceph-2.4"print(r.description)# "Red Hat Ceph Storage 2.4"print(r.type)# "QuarterlyUpdate"print(r.is_active)# Trueprint(r.enabled)# Trueprint(r.blocker_flags)# ['ceph-2.y', 'pm_ack', 'devel_ack', 'qa_ack']print(r.edit_url)# https://errata.devel.redhat.com/release/edit/792

查找发行版的所有“新文件”建议:

fromerrata_tool.releaseimportReleaserel=Release(name='rhceph-3.0')advisories=rel.advisories()new_files=[aforainadvisoriesifa['status']=='NEW_FILES']print(new_files)# prints the list of advisories' data

创建新版本(这需要勘误表工具中的“releng”角色):

fromerrata_tool.releaseimportReleaser=Release.create(name='rhceph-3.0',product='RHCEPH',product_versions=['RHEL-7-CEPH-3'],type='QuarterlyUpdate',program_manager='anharris',blocker_flags='ceph-3.0',default_brew_tag='ceph-3.0-rhel-7-candidate',)print('created new rhceph-3.0 release')print('visit %s to edit further'%r.edit_url)

使用登台服务器

要在不影响生产的情况下使用临时勘误表工具环境,请设置 临时url的ErrataConnector._url成员变量。

fromerrata_toolimportErrataConnector,ErratumErrataConnector._url='https://errata.stage.engineering.redhat.com/'# Now try something like creating an advisory, and it will not show up in# prod, or bother people with emails, etc.e=Erratum(product='RHCEPH',release='rhceph-2.1',synopsis='Red Hat Ceph Storage 2.1 bug fix update',...)e.commit()

调试许多勘误表工具API调用

也许你的应用程序进行了很多api调用(很多咨询、构建等)。 当处理来自高级工具的大量勘误表时,它是有帮助的 了解在何处花费时间查看是否可以避免多个调用。

设置ErrataConnector.debug = True,然后连接器对象将 记录每次通话的信息。每个get/put/post都被记录下来, 以及总计/平均值/最小值/最大值。

url api是根据它们的名称进行重复数据消除的,因此对不同的 同一api上的勘误表记录为单个api。

要提取并打印信息,可以使用prettytable:

e=Erratum(errata_id=24075)pt=PrettyTable()forcinErrataConnector.timings:foruinErrataConnector.timings[c]:pt.add_row([c,u,ErrataConnector.timings[c][u]['count'],ErrataConnector.timings[c][u]['total'],ErrataConnector.timings[c][u]['mean'],ErrataConnector.timings[c][u]['min'],ErrataConnector.timings[c][u]['max']])print(pt.get_string())

SSL错误

默认情况下,此库验证ET服务器的https证书。这是 更多的是python请求,但是如果收到ssl验证错误, 可能是因为你没有为你的Python设置的红帽子 环境。特别是如果你用Virtualenv运行这个,你会想要 设置以下配置变量:

REQUESTS_CA_BUNDLE=/etc/pki/ca-trust/source/anchors/RH-IT-Root-CA.crt

其中“rh-it-root-ca.crt”是签署ET服务器的 https证书。

当使用RHEL7的Python请求RPM时,请求只是检查 /etc/pki/tls/certs/ca-bundle.crt,因此您需要将it ca证书添加到 那个大文件包。

如果你已经加了红帽子对于您的系统范围捆绑包,您可以 让您的python代码始终使用此文件:

if'REQUESTS_CA_BUNDLE'notinos.environ:os.environ['REQUESTS_CA_BUNDLE']='/etc/pki/tls/certs/ca-bundle.crt'

这将使请求在virtualenv内部或外部的行为相同。在 换句话说,使用此代码,您的程序将始终验证 约.

构建RPM

安装fedpkg,然后使用makefile:

$ make srpm

然后您可以将srpm上传到copr。或者,在本地 计算机,使用模拟:

$ make rpm

更改日志

查看CHANGELOG

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java以编程方式从TableLayout中删除所有行   Java Web Sart Ubuntu12.1。加载资源(图像)   人们如何让Java SPNEGO客户端在Windows中工作?   java Eclipselink:ObjectArrayMapping和ClassDescriptor   控制台中带有引号/空格的java Javafx命名参数   java创建服务失败:找不到对象?   java Hazelcast:如何在测试期间禁用自动发现?   使用TuckyUrlRewriteFilter rermoteaddr的java块IP   javascript如何在angular 4中进行同步http调用   输入字符串的java排列   java Jenkins不是以Xrs Xmx2048m XX:MaxPermSize=512m(windows)开始的   AWS EMR上的java avro错误   java从两个ArrayList中提取特定连接的对象,组合这些相关对象并从子类中打印   java从主题中删除什么时间点消息?   谷歌像素设备上的java InvalidKeyException   java如何在执行测试后重建项目   java Android 2.2 readUTF()socket问题   按下安卓设备上的“后退”按钮后java Toast没有完成?