def test_get_p2o_params_from_url_error(self): """Test whether an exception is thrown when the tokens obtained when parsing the filter are not 2""" with self.assertRaises(ELKError): _ = ElasticOcean.get_p2o_params_from_url( "https://finosfoundation.atlassian.net/wiki/ " "--filter-raw=data.project:openstack/stx-clients=xxx") with self.assertRaises(ELKError): _ = ElasticOcean.get_p2o_params_from_url( "https://finosfoundation.atlassian.net/wiki/ " "--filter-raw")
def get_params_parser_create_dash(): """Parse command line arguments""" parser = argparse.ArgumentParser(usage="usage: e2k.py [options]", description="Create a Kibana dashboard from a template") ElasticOcean.add_params(parser) parser.add_argument("-d", "--dashboard", help="dashboard to be used as template") parser.add_argument("-i", "--index", help="enriched index to be used as data source") parser.add_argument("--kibana", dest="kibana_index", default=".kibana", help="Kibana index name (.kibana default)") parser.add_argument('-g', '--debug', dest='debug', action='store_true') return parser
def get_params_parser(): """Parse command line arguments""" parser = argparse.ArgumentParser() ElasticOcean.add_params(parser) parser.add_argument('-g', '--debug', dest='debug', action='store_true') parser.add_argument('-t', '--token', dest='token', help="GitHub token") parser.add_argument('-o', '--org', dest='org', help='GitHub Organization to be analyzed') parser.add_argument('-c', '--contact', dest='contact', help='Contact (mail) to notify events.') parser.add_argument('--twitter', dest='twitter', help='Twitter account to notify.') parser.add_argument( '-w', '--web-dir', default='/var/www/cauldron/dashboards', dest='web_dir', help='Redirect HTML project pages for accessing Kibana dashboards.') parser.add_argument('-k', '--kibana-url', default='https://dashboard.cauldron.io', dest='kibana_url', help='Kibana URL.') parser.add_argument('-u', '--graas-url', default='https://cauldron.io', dest='graas_url', help='GraaS service URL.') parser.add_argument( '-n', '--nrepos', dest='nrepos', type=int, default=NREPOS, help= 'Number of GitHub repositories from the Organization to be analyzed (default:10)' ) return parser
def test_get_p2o_params_from_url(self): """Test whether a URL without params is correctly parsed""" params = ElasticOcean.get_p2o_params_from_url( "https://finosfoundation.atlassian.net/wiki/") self.assertEqual(len(params), 1) self.assertEqual(params['url'], "https://finosfoundation.atlassian.net/wiki/")
def test_get_p2o_params_from_url_filter(self): """Test whether a URL with a filter is correctly parsed""" params = ElasticOcean.get_p2o_params_from_url( "https://bugzilla.mozilla.org " "--filter-raw=data.product:Add-on SDK,data.component:General") self.assertEqual(len(params), 2) self.assertEqual(params['url'], "https://bugzilla.mozilla.org") self.assertEqual(params['filter-raw'], "data.product:Add-on SDK,data.component:General")
def test_get_p2o_params_from_url_more_filters(self): """Test whether a warning is logged in """ with self.assertLogs(logger, level='WARNING') as cm: params = ElasticOcean.get_p2o_params_from_url( "https://finosfoundation.atlassian.net/wiki/ " "--filter-raw=data.project:openstack/stx-clients " "--filter-raw-prefix=data.project:https://github.com/") self.assertEqual(len(params), 2) self.assertEqual(params['url'], "https://finosfoundation.atlassian.net/wiki/") self.assertEqual(params['filter-raw'], "data.project:openstack/stx-clients") self.assertEqual( cm.output[0], 'WARNING:grimoire_elk.raw.elastic:Too many filters defined ' 'for https://finosfoundation.atlassian.net/wiki/ ' '--filter-raw=data.project:openstack/stx-clients ' '--filter-raw-prefix=data.project:https://github.com/, ' 'only the first one is considered')
if backend.get_name() == name: found = connector return found if __name__ == '__main__': """Gelk: perceval2ocean and ocean2kibana""" connectors = [[Bugzilla, BugzillaOcean, BugzillaEnrich], [GitHub, GitHubOcean, GitHubEnrich], [Gerrit, GerritOcean, GerritEnrich]] # Will come from Registry parser = argparse.ArgumentParser() ElasticOcean.add_params(parser) subparsers = parser.add_subparsers(dest='backend', help='perceval backend') for connector in connectors: name = connector[0].get_name() subparser = subparsers.add_parser(name, help='gelk %s -h' % name) # We need params for feed connector[0].add_params(subparser) args = parser.parse_args() app_init = datetime.now() backend_name = args.backend
def test_get_field_date(self): """Test whether the field date is correctly returned""" perceval_backend = Git('http://example.com', '/tmp/foo') eitems = ElasticOcean(perceval_backend) self.assertEqual(eitems.get_field_date(), 'metadata__updated_on')