简体   繁体   English

奇怪的buildbot Python行为

[英]Strange buildbot python behavior

EDIT for some explanations: The buildbot is a continous integration system in python which can be controlled by a web interface. 编辑一些解释:buildbot是python中的连续集成系统,可以通过Web界面进行控制。 In this web interface you have a "Waterfall" page where you can choose a specific builder and trigger a build with a "Force build" button. 在此Web界面中,您具有“瀑布”页面,您可以在其中选择特定的构建器并通过“强制构建”按钮触发构建。

URL: http://trac.buildbot.net/ 网址: http//trac.buildbot.net/

The background: We have a cluster of builders which are continous (check every few minutes if a change happened and if yes, rebuild) or nightly (build every night). 背景:我们有一组连续的(每隔几分钟检查一次是否发生更改,如果是,则进行重新生成)或每晚(每晚生成)的生成器。 Our system so far has only one specific enterprise builder for every project. 到目前为止,我们的系统每个项目只有一个特定的企业构建器。 This was done by enforcing that every project must be found under a constant URL like 这是通过强制每个项目都必须在恒定URL下找到的,例如

https://myrepositioryurl/{$projectname}.

Then when a project needs an enterprise build you need to choose one project XYZ and the buildbot assumes that the project needs to be checked out under 然后,当一个项目需要企业构建时,您需要选择一个项目XYZ,并且构建机器人假定该项目需要在

https://myrepositioryurl/{$projectname}.

This is very rigid and I wanted to reconfigure the buildbot that projects can be under different URLs. 这非常严格,我想重新配置buildbot,使项目可以位于不同的URL下。 During the setup of the builders which is started by "buildbot start master" a config file of our projects is read and stored in a ConfigParser object. 在由“ buildbot start master”启动的构建器的设置过程中,将读取我们项目的配置文件并将其存储在ConfigParser对象中。 In the following source code it is the clzoptions var und my URL I want to use should be 在以下源代码中,它是clzoptions var,我想使用的URL应该是

https://mytesturl/XYZ.

for project XYZ. 用于项目XYZ。 I added now my different URLs under a "svnBaseURL" entry for a test project. 我现在在测试项目的“ svnBaseURL”条目下添加了不同的URL。 Now I have encountered something which I do not quite understand in my python class which creates the builders. 现在,我在创建构建器的python类中遇到了一些不太了解的内容。 First the source: 首先是来源:

import os
import logging

from xcodebuild import xcodebuild
from projects import Projects

from buildbot.config import BuilderConfig
from buildbot.process.factory import BuildFactory
from buildbot.steps.source import SVN
from buildbot.steps.shell import ShellCommand, WithProperties
from buildbot.process.properties import Property


class builders(object):
    clzoptions = Projects().options


    def __init__(self):
        aProject = Projects()
        self.options = aProject.options


    def enterprise_checkout_url(self, curProjectName):
        return curProjectName

    def create_enterprise_builder(self):
        factory = BuildFactory()
        factory.addStep(ShellCommand(name='svn checkout',
                                     haltOnFailure=True,
                                     description='svn checkout',
                                     descriptionDone='svn checkout done',
                                     command=['svn', 'checkout', '--username', 'admin', self.enterprise_checkout_url(WithProperties('%(project)s')), '.']))



        builderConfig = BuilderConfig(name="foobuilder",
                                      category="OnDemand",
                                      slavenames=[ "buildslave01" ],
                                      factory=factory)
        return builderConfig



    def get_all_builders(self):
        builders = []

        builders.append(self.create_enterprise_builder())

        return builders

I have melted it down to the core problem, there are many more builders inside. 我已经解决了核心问题,内部还有更多的构建者。 The key function is self.enterprise_checkout_url(WithProperties('%(project)s')). 关键功能是self.enterprise_checkout_url(WithProperties('%(project)s'))。

If I call that builder with the project name "XYZ" in the Waterfall, I get as result 如果我在瀑布中以项目名称“ XYZ”来调用该生成器,则会得到结果

svn checkout --username admin XYZ .

for the ShellCommand. 用于ShellCommand。 While this is nonsensical because it is not an URL, I see that the parameter curProjectName evaluates to "XYZ". 尽管这不是URL,这很荒谬,但我看到参数curProjectName的值为“ XYZ”。 Easy so far,right ? 到目前为止很容易,对吗? Lets change now that function... 现在让我们更改该功能...

def enterprise_checkout_url(self, curProjectName):
  return builders.clzoptions.get("XYZ", "svnBaseURL"))

and get 并得到

svn checkout --username admin https://mytesturl/XYZ .

This is nearly the thing I need, 这几乎是我所需要的,

https://mytesturl/XYZ

is the right path. 是正确的道路。 But the key is constant, I need it to be variable. 但是关键是不变的,我需要它是可变的。 But at least I know that the dictionary exists and has the correct entry for XYZ. 但是至少我知道该字典存在并且具有XYZ的正确条目。

Now the problem I simply do not understand. 现在我根本不明白这个问题。

Lets try now 让我们现在尝试

def enterprise_checkout_url(self, curProjectName):
      return builders.clzoptions.get(curProjectName, "svnBaseURL"))

and oops, he does not build 哎呀,他没有建立

ConfigParser.NoSectionError: No section: <buildbot.process.properties.WithProperties instance at 0x1073739e0>

Ok, during the compile phase curProjectName may not be set, how about: 好的,在编译阶段可能未设置curProjectName,如何处理:

def enterprise_checkout_url(self, curProjectName):
    projects = builders.clzoptions.sections()
    for project in projects:
      if project == curProjectName:
        return builders.clzoptions.get(project, "svnBaseURL" )

which compiles. 编译。 I am getting all my projects, test if the curProjectName is right and then return my svnBaseURL with the project key which should be equal to curProjectName. 我正在获取所有项目,测试curProjectName是否正确,然后返回带有项目密钥的svnBaseURL,该密钥应该等于curProjectName。 But I get: 但是我得到:

<type 'exceptions.TypeError'>: 'NoneType' object is not iterable

Your turn. 轮到你了。 I have tried to use str(), repr(), eval() on curProjectName, but to no avail. 我试图在curProjectName上使用str(),repr(),eval(),但无济于事。 I cannot access both the existing dictionary and curProjectName. 我无法同时访问现有字典和curProjectName。

Does this help you ? 这对您有帮助吗?

class builders(object):

    builders = []
    print 'id of buiders just created ==',id(builders)

    def __init__(self,x):
        self.the = x

    def enterprise_checkout_url(self, curProjectName):
        return curProjectName

    def create_enterprise_builder(self,yy):
        builderConfig = dict(descriptionDone='-SVN-',
                             command=yy)
        return builderConfig

    def get_all_builders(self):
        print 'id of builders inside get_all_builders ==',id(builders)
        print 'id of builders.builders inside get_all_builders ==',id(builders.builders)

        builders.builders.append(self.create_enterprise_builder((self.the)))

        return builders.builders

print 'id of class builders ==',id(builders)
print '\n################################\n'

b = builders('BOF')
print b.get_all_builders()

print '\n=================================\n'

b2 = builders('MOTO')
print b2.get_all_builders()

result 结果

id of buiders just created == 18709040
id of class builders == 13819408

################################

id of builders inside get_all_builders == 13819408
id of builders.builders inside get_all_builders == 18709040
[{'descriptionDone': '-SVN-', 'command': 'BOF'}]

=================================

id of builders inside get_all_builders == 13819408
id of builders.builders inside get_all_builders == 18709040
[{'descriptionDone': '-SVN-', 'command': 'BOF'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}]

EDIT 编辑

Ther's a problem with my code. 那是我的代码有问题。
If the instruction print b2.get_all_builders() is executed two times, the result is 如果两次执行指令print b2.get_all_builders() ,则结果为

id of buiders just created == 18709040
id of class builders == 13819408

################################

id of builders inside get_all_builders == 13819408
id of builders.builders inside get_all_builders == 18709040
[{'descriptionDone': '-SVN-', 'command': 'BOF'}]

=================================

id of builders inside get_all_builders == 13819408
id of builders.builders inside get_all_builders == 18709040
[{'descriptionDone': '-SVN-', 'command': 'BOF'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}]

id of builders inside get_all_builders == 13819408
id of builders.builders inside get_all_builders == 18709040
[{'descriptionDone': '-SVN-', 'command': 'BOF'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}]

One of the dictionaries appears two times. 其中一本词典出现两次。

Since I don't understand very well your problem and I'm not sure of what you want exactly, I don't know how to correct it 由于我不太了解您的问题,也不确定您要的是什么,所以我不知道如何解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM