Ejemplo n.º 1
0
def run():
    parser = optparse.OptionParser()
    # options we can override in the config file.
    groupConfigFile = optparse.OptionGroup(parser, "Config File Defaults",
                                           "All the options which have defaults read from a config file.")
    parser.add_option_group(groupConfigFile)
    parser.add_option_group(groupConfigFile)

    parser.add_option("--config", dest="config", default="web/web.conf",
                      help="Config file to read settings from, defaults to web.conf which will be read from configs/ and /etc/pybit/ in turn.",
                      metavar=META + "CONF_FILE")

    parser.add_option("-v", dest="verbose", action="store_true", default=False,
                      help="Turn on verbose messages.", metavar=META+"VERBOSE")
    (options, args) = parser.parse_args()
    (settings, opened_file) = pybit.load_settings(options.config)
    settings = pybit.merge_options(settings, groupConfigFile, options)

    # singleton instance
    myDb = Database(settings['db'])
    # singleton instance - Needs access to both controller and web settings
    buildController = Controller(settings, myDb)

    app = cnx_pybit.get_app(settings, myDb, buildController)
    bottle.debug(options.verbose)
    bottle.run(app=app,
               server=settings['web']['app'],
               host=settings['web']['interface'],
               port=settings['web']['port'],
               reloader=settings['web']['reloader'],
               )
Ejemplo n.º 2
0
def _acquire_pybit_settings():
    """Find and produce the PyBit settings as PyBit would normally
    know and use them.

    """
    pybit_config_path = get_current_registry().settings["pybit-config-path"]
    settings = pybit.load_settings(pybit_config_path)[0]
    return settings
Ejemplo n.º 3
0
def check_auth(username, password):
    # Load from local settings file in configs, or if not, from system settings in etc.
    (auth_settings, path) = pybit.load_settings("web/web.conf")
    if not auth_settings:
        # Cant load settings
        return False

    # Check credentials
    if auth_settings["web"]["username"] == username and auth_settings["web"]["password"] == password:
        return True
    else:
        return False
Ejemplo n.º 4
0
 def test_01_plugin (self) :
     log = logging.getLogger( "testCase" )
     log.debug(" ")
     plugin = None
     vcs = None
     client = None
     plugins = []
     distros = {}
     handlers = {}
     plugin_dir = "/var/lib/pybit-client.d/"
     (settings, opened_path) = pybit.load_settings("client/client.conf")
     if not os.path.exists (plugin_dir):
         plugin_dir = os.path.join (os.getcwd(), "pybitclient/")
     self.assertTrue (os.path.isdir(plugin_dir))
     for name in os.listdir(plugin_dir):
         if name.endswith(".py"):
             plugins.append(name.strip('.py'))
     for name in plugins :
         if (name == "buildclient" or name == "__init__"):
             continue
         plugin_path = [ plugin_dir ];
         fp, pathname, description = imp.find_module(name, plugin_path)
         try:
             mod = imp.load_module(name, fp, pathname, description)
             self.assertTrue (mod)
             self.assertTrue (hasattr(mod, 'createPlugin'))
             plugin = mod.createPlugin(settings)
             self.assertTrue (plugin)
             self.assertTrue (hasattr(plugin, 'get_distribution') or hasattr(plugin, 'method'))
             if (hasattr(plugin, 'get_distribution') and plugin.get_distribution() is not None) :
                 client = plugin
             elif (hasattr(plugin, 'method') and plugin.method is not None) :
                 vcs = plugin
             else :
                 self.assertTrue(False)
                 continue
         finally:
             # Since we may exit via an exception, close fp explicitly.
             if fp:
                 fp.close()
         if client:
             name = client.get_distribution()
             if (name not in distros) :
                 distros[name] = client
         if vcs :
             if (vcs.method not in handlers) :
                 handlers[vcs.method] = vcs;
     self.assertTrue (len(handlers.keys()) > 0)
     self.assertTrue (len(distros.keys()) > 0)
Ejemplo n.º 5
0
	def test_01_client_config (self) :
		log = logging.getLogger( "testCase" )
		log.debug(" ")
		conffile = "%s/configs/client/client.conf" % (os.getcwd());
		self.assertTrue (os.path.isfile(conffile), "could not find %s" % conffile)
		log.debug("I: reading %s" % (os.path.relpath(conffile, os.getcwd())))
		(self.options, opened_path) = pybit.load_settings(conffile)
		if not "dry_run" in self.options :
			msg = "I: asserting dry_run for test cases"
			log.debug (msg)
			self.options["dry_run"] = True
		elif self.options["dry_run"] == False :
			msg = "I: overriding dry_run for test cases"
			log.debug (msg)
			self.options["dry_run"] = True
		else :
			msg = "I: dry_run already set."
			log.debug(msg)
Ejemplo n.º 6
0
if __name__ == '__main__':
    parser = optparse.OptionParser()
    #options we can override in the config file.
    groupConfigFile = optparse.OptionGroup(parser,
        "Config File Defaults","All the options which have defaults read from a config file.")
    parser.add_option_group(groupConfigFile)
    parser.add_option_group(groupConfigFile)

    parser.add_option("--config", dest="config", default="web/web.conf",
        help="Config file to read settings from, defaults to web.conf which will be read from configs/ and /etc/pybit/ in turn.",
        metavar=META + "CONF_FILE")

    parser.add_option("-v", dest="verbose", action="store_true", default=False,
        help="Turn on verbose messages.", metavar=META+"VERBOSE")
    (options, args) = parser.parse_args()
    (settings, opened_file) = pybit.load_settings(options.config)
    settings = pybit.merge_options(settings, groupConfigFile, options)
    
    FORMAT = '%(asctime)s %(filename)s:%(lineno)d %(msg)s'
    logging.basicConfig( stream=sys.stderr, level=logging.WARN)
    logging.basicConfig( format=FORMAT )
    
    myDb = Database(settings['db']) # singleton instance
    buildController = Controller(settings, myDb) # singleton instance - Needs access to both controller and web settings
#   try:
    app = pybitweb.get_app(settings, myDb, buildController)
    bottle.debug(options.verbose)
    bottle.run(app=app,
        server=settings['web']['app'],
        host=settings['web']['interface'],
        port=settings['web']['port'],
Ejemplo n.º 7
0
def main():
	conffile = "%s/pybitclient/client.conf" % (os.getcwd());
	if os.path.isfile (conffile):
		settings = pybit.load_settings(conffile)
	else :
		settings = pybit.load_settings("/etc/pybit/client/client.conf")
	build_client = PyBITClient(settings["host_arch"], settings["distribution"], settings["pkg_format"], settings["suite"], None, settings)

	testconf = "%s/buildd-test.conf" % (os.getcwd());
	if not os.path.isfile (testconf):
		print "E: Unable to find %s - no test data for this buildd" % (testconf)
		print "I: Copy /usr/share/pybitclient/buildd-test.conf and modify it for your available packages."
		return 1
	else :
		test_options = pybit.load_settings(testconf)

	count = 0
	max_count = test_options["count"]
	tags = [ "vcs_id", "method_type", "suite", "package", "version",
		"architecture", "source", "uri", "pkg_format", "distribution", "role" ]
	vcs = SubversionClient (settings)
	client = DebianBuildClient (settings)

	while count < test_options["count"] and count < 10: # catch typos in the conf file
		count = count + 1
		print "I: starting test #%s" % count
		for tag in tags :
			tag_run = "%s%s" % (tag, count)
			if tag_run not in test_options :
				print "E: missing config item in %s \"%s\"" % (testconf, tag_run)
				return -2
			if tag == "vcs_id" :
				vcs_id = test_options[tag_run]
			elif tag == "method_type" :
				method_type = test_options[tag_run]
			elif tag == "suite" :
				suite = test_options[tag_run]
			elif tag == "package" :
				package = test_options[tag_run]
			elif tag == "version" :
				version = test_options[tag_run]
			elif tag == "architecture" :
				architecture = test_options[tag_run]
			elif tag == "source" :
				source = test_options[tag_run]
			elif tag == "uri" :
				uri = test_options[tag_run]
			elif tag == "pkg_format" :
				pkg_format = test_options[tag_run]
			elif tag == "distribution" :
				distribution = test_options[tag_run]
			elif tag == "role" :
				role = test_options[tag_run]
			else :
				print "E: unrecognised option: %s" % tag_run
				return -1
		test_arch = Arch(0, architecture)
		test_suite = Suite (0, suite)
		test_transport = Transport (0, method_type, uri, vcs_id)
		test_package = Package(0, version, package)
		test_packageinstance = PackageInstance(1, test_package, test_arch, test_suite, pkg_format, distribution, True)
		test_job =  Job(2, test_packageinstance,None)
		test_req = BuildRequest(test_job,test_transport,None)
		vcs.fetch_source (test_req, None)
		# To check the build-dependencies in advance, we need to ensure the
		# chroot has an update apt-cache, so can't use apt-update option of
		# sbuild. The alternative is to update the apt-cache twice per build,
		# once for the dep check and once before the build. The choice depends
		# on whether two network trips are more efficient than rewriting the
		# lvm snapshot before even trying to do any build.
		if settings["use_lvm"] :
			name = suite + "-source"
		else:
			name = suite
		client.update_environment (name, test_req, None)
		if (role == "slave"):
			client.build_slave (test_req, None)
		else :
			client.build_master (test_req, None)
		client.upload (test_req, None)
		vcs.clean_source(test_req, None)
	return 0
Ejemplo n.º 8
0
def main():
	FORMAT = '%(asctime)s %(filename)s:%(lineno)d %(msg)s'
	logging.basicConfig( stream=sys.stderr, level=logging.DEBUG)
	logging.basicConfig( format=FORMAT )
	conffile = "%s/configs/client/client.conf" % (os.getcwd());
	testconf = "%s/buildd-test.conf" % (os.getcwd());
	if os.path.isfile (conffile):
		(settings, opened_path) = pybit.load_settings(conffile)
	else :
		(settings, opened_path) = pybit.load_settings("/etc/pybit/client/client.conf")
	build_client = PyBITClient(settings["host_arch"], settings["distribution"], settings["pkg_format"], settings["suites"], None, settings)

	if not os.path.isfile (testconf):
		print "E: Unable to find %s - no test data for this buildd" % (testconf)
		print "I: Copy /usr/share/pybitclient/buildd-test.conf and modify it for your available packages."
		return 1
	else :
		(test_options, opened_path) = pybit.load_settings(testconf)

	count = 0
	max_count = test_options["count"]
	tags = [ "vcs_id", "method_type", "suite", "package", "version",
		"architecture", "source", "uri", "pkg_format", "distribution", "role", "commands" ]
	svn_vcs = SubversionClient (settings)
	git_vcs = GitClient(settings)
	apt_src = AptClient(settings)
	client = DebianBuildClient (settings)

	while count < test_options["count"] and count < 10: # catch typos in the conf file
		count = count + 1
		for tag in tags :
			tag_run = "%s%s" % (tag, count)
			if tag_run not in test_options :
				print "E: missing config item in %s \"%s\"" % (testconf, tag_run)
				return -2
			if test_options[tag_run] == '' :
				test_options[tag_run] = None
			if tag == "vcs_id" :
				vcs_id = test_options[tag_run]
			elif tag == "method_type" :
				method_type = test_options[tag_run]
			elif tag == "suite" :
				suite = test_options[tag_run]
			elif tag == "package" :
				package = test_options[tag_run]
			elif tag == "version" :
				version = test_options[tag_run]
			elif tag == "architecture" :
				architecture = test_options[tag_run]
			elif tag == "source" :
				source = test_options[tag_run]
			elif tag == "uri" :
				uri = test_options[tag_run]
			elif tag == "pkg_format" :
				pkg_format = test_options[tag_run]
			elif tag == "distribution" :
				distribution = test_options[tag_run]
			elif tag == "commands" :
				commands = test_options[tag_run]
			elif tag == "role" :
				role = test_options[tag_run]
			else :
				print "E: unrecognised option: %s" % tag_run
				return -1
		logging.debug("I: starting test #%s (%s)" % (count, role))
		if commands is not None :
			logging.debug("I: test #%s requires a custom build command: '%s'" % (count, commands))
		test_arch = Arch(0, architecture)
		test_suite = Suite (0, suite)
		test_transport = Transport (0, method_type, uri, vcs_id)
		test_package = Package(0, version, package)
		test_packageinstance = PackageInstance(1, test_package, test_arch, test_suite, pkg_format, distribution, True)
		test_job =  Job(2, test_packageinstance,None)
		test_req = BuildRequest(test_job,test_transport,None,commands)
		test_req.stamp_request()
		# clean up in case the last test failed.
		if (method_type == "svn") :
			svn_vcs.clean_source(test_req, None)
			svn_vcs.fetch_source (test_req, None)
		if (method_type == "git") :
			git_vcs.clean_source(test_req, None)
			git_vcs.fetch_source (test_req, None)
		if (method_type == "apt") :
			apt_src.clean_source(test_req, None)
			apt_src.fetch_source(test_req, None)
		if (role == "slave"):
			# runs the build with --apt-update
			client.build_slave (test_req, None)
		else :
			# runs update_environment first
			client.build_master (test_req, None)
		client.upload (test_req, None)
		if (method_type == "svn") :
			svn_vcs.clean_source(test_req, None)
		if (method_type == "git") :
			git_vcs.clean_source(test_req, None)
		if (method_type == "apt") :
			apt_src.clean_source(test_req, None)
	return 0