示例#1
0
def test_config_defaults():
    #config_file = ('defaults.yml')
    logger = ActivityLogger('log/defaults.log')
    konf = Konfabulator('config/defaults.yml', logger)
    jenk_conf = konf.topLevel('Jenkins')
    ac_conf = konf.topLevel('AgileCentral')
    srv_config = konf.topLevel('Service')
    assert not ac_conf.get('Server', None)
    assert not jenk_conf.get('Server', None)

    # runner = BuildConnectorRunner([config_file])
    # runner.run()

    agicen = bsh.AgileCentralConnection(konf.topLevel('AgileCentral'), logger)
    agicen.other_name = 'Jenkins'
    agicen.project_name = jenk_conf['AgileCentral_DefaultBuildProject']
    agicen.connect()
    assert agicen.server == 'rally1.rallydev.com'
    assert not agicen.proxy

    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()
    assert jc.server == 'coyotepair.ca.com'
    assert jc.port   == 8080
    assert jc.protocol == 'http'
    def getConfiguration(self, config_file):
        try:
            config = Konfabulator(config_file, self.log)
        except NonFatalConfigurationError as msg:
            pass  # info for this will have already been logged or blurted
        except Exception as msg:
            raise ConfigurationError(msg)
        svc_conf = config.topLevel('Service')
        self.preview = False
        if svc_conf and svc_conf.get('Preview', None) == True:
            self.preview = True
        self.log_level = 'Info'
        if svc_conf:
            ll = svc_conf.get('LogLevel', 'Info').title()
            if ll in ['Fatal', 'Error', 'Warn', 'Info', 'Debug']:
                self.log_level = ll
                self.log.setLevel(self.log_level)
            else:
                pass  # bad LogLevel specified
            #if 'PostBatchExtension' in svc_conf:
            #    pba_class_name = svc_conf['PostBatchExtension']
            #    pba_class = ExtensionLoader().getExtension(pba_class_name)
            #    self.extension['PostBatch'] = pba_class()

        return config
示例#3
0
def connect_to_ac(config_file):
    logger = ActivityLogger('kublakhan.log')
    konf = Konfabulator('config/buildorama.yml', logger)
    jenk_conf = konf.topLevel('Jenkins')
    ac_conf = konf.topLevel('AgileCentral')
    ac_conf['Project'] = jenk_conf['AgileCentral_DefaultBuildProject']  # leak proj from jenkins section to ac section
    agicen = AgileCentralConnection(ac_conf, logger)
    agicen.other_name = 'Jenkins'
    agicen.connect()
    return agicen
示例#4
0
def connect_to_ac(config_file):
    logger = ActivityLogger('kublakhan.log')
    konf = Konfabulator('config/buildorama.yml', logger)
    jenk_conf = konf.topLevel('Jenkins')
    ac_conf = konf.topLevel('AgileCentral')
    ac_conf['Project'] = jenk_conf[
        'AgileCentral_DefaultBuildProject']  # leak proj from jenkins section to ac section
    agicen = AgileCentralConnection(ac_conf, logger)
    agicen.other_name = 'Jenkins'
    agicen.connect()
    return agicen
示例#5
0
def test_tab_yml():
    logger = ActivityLogger('log/bad_tab.log')
    expectedErrPattern = "Your config file contains tab characters which are not allowed in a YML file."
    with pytest.raises(Exception) as excinfo:
        konf = Konfabulator('config/bad_tab.yml', logger)
    actualErrVerbiage = excinfo.value.args[0]
    assert re.search(expectedErrPattern, actualErrVerbiage)
示例#6
0
def setup_config(filename,
                 jenkins_structure='DEFAULT_JENKINS_STRUCTURE',
                 services='DEFAULT_SERVICES'):
    filename = inflate_config_file(filename, jenkins_structure, services)
    logger = ActivityLogger('test.log')
    konf = Konfabulator(filename, logger)
    return logger, konf
示例#7
0
def test_without_project():
    config_file = ('missing-project.yml')
    ymlfile = open("config/{}".format(config_file), 'r')
    y = yaml.load(ymlfile)
    logger = ActivityLogger('log/missing-project.log')
    logger.setLevel('DEBUG')
    logAllExceptions(True, logger)
    konf = Konfabulator('config/missing-project.yml', logger)
    jenk_conf = konf.topLevel('Jenkins')
    ac_conf = konf.topLevel('AgileCentral')
    #expectedErrPattern = 'The Jenkins section of the config is missing AgileCentral_DefaultBuildProject property'
    expectedErrPattern = 'The Jenkins section of the config is missing a value for AgileCentral_DefaultBuildProject property'
    with pytest.raises(Exception) as excinfo:
        bc = bsh.BLDConnector(konf, logger)
    actualErrVerbiage = excinfo.value.args[0]
    assert re.search(expectedErrPattern, actualErrVerbiage) is not None
    assert excinfo.typename == 'ConfigurationError'
示例#8
0
def test_without_project():
    config_file = ('missing-project.yml')
    ymlfile = open("config/{}".format(config_file), 'r')
    y = yaml.load(ymlfile)
    logger = ActivityLogger('log/missing-project.log')
    logger.setLevel('DEBUG')
    logAllExceptions(True, logger)
    konf = Konfabulator('config/missing-project.yml', logger)
    jenk_conf = konf.topLevel('Jenkins')
    ac_conf = konf.topLevel('AgileCentral')
    #expectedErrPattern = 'The Jenkins section of the config is missing AgileCentral_DefaultBuildProject property'
    expectedErrPattern = 'The Jenkins section of the config is missing a value for AgileCentral_DefaultBuildProject property'
    with pytest.raises(Exception) as excinfo:
        bc = bsh.BLDConnector(konf, logger)
    actualErrVerbiage = excinfo.value.args[0]
    assert re.search(expectedErrPattern, actualErrVerbiage) is not None
    assert excinfo.typename == 'ConfigurationError'
示例#9
0
def test_bad_yml():
    logger = ActivityLogger('log/bad_yml.log')
    expectedErrPattern = "The file does not contain consistent indentation for the sections and section contents"
    unexpectedErrPattern = "Oh noes!"
    with pytest.raises(Exception) as excinfo:
        konf = Konfabulator('config/bad_yml.yml', logger)
    actualErrVerbiage = excinfo.value.args[0]
    assert re.search(expectedErrPattern, actualErrVerbiage)
    assert not re.search(unexpectedErrPattern, actualErrVerbiage)
示例#10
0
def test_config_defaults():
    #config_file = ('defaults.yml')
    logger = ActivityLogger('log/defaults.log')
    konf = Konfabulator('config/defaults.yml', logger)
    jenk_conf = konf.topLevel('Jenkins')
    ac_conf = konf.topLevel('AgileCentral')
    srv_config = konf.topLevel('Service')
    assert not ac_conf.get('Server', None)
    assert not jenk_conf.get('Server', None)

    # runner = BuildConnectorRunner([config_file])
    # runner.run()

    agicen = bsh.AgileCentralConnection(konf.topLevel('AgileCentral'), logger)
    agicen.other_name = 'Jenkins'
    agicen.project_name = jenk_conf['AgileCentral_DefaultBuildProject']
    agicen.connect()
    assert agicen.server == 'rally1.rallydev.com'
    assert not agicen.proxy

    jc = bsh.JenkinsConnection(jenk_conf, logger)
    jc.connect()
    assert jc.server == 'coyotepair.ca.com'
    assert jc.port == 8080
    assert jc.protocol == 'http'