From 8984c7294a6026be89ddedc3ced7f612a0b226ab Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Jun 08 2019 02:15:14 +0000 Subject: Convert from fedmsg to fedora-messaging This converts all the consumers (for job scheduling and result reporting) from fedmsg to fedora-messaging. There are some differences in configuration: things that were previously set in `schedule.conf` are now set in the consumer config file. You will need to follow the instructions in the README to set up the fedora-messaging consumers. Signed-off-by: Adam Williamson --- diff --git a/README.md b/README.md index befd262..2bb81a7 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ See the command's help (and the help for the subcommands, `schedule` and `report Installation ------------ -You can install the library and CLI systemwide if you choose to. After installing all the dependencies, just run `sudo python setup.py install`. You must install systemwide if you wish to use the fedmsg consumers to trigger jobs automatically. +You can install the library and CLI systemwide if you choose to. After installing all the dependencies, just run `sudo python setup.py install`. You must install systemwide if you wish to use the fedora-messaging consumers to trigger jobs automatically. Configuration ------------- @@ -80,39 +80,38 @@ If you wish to forward results to [Wikitcms](https://fedoraproject.org/wiki/Wiki echo "fas_username fas_password" > /etc/fedora/credentials chmod 0600 /etc/fedora/credentials -This tool has its own configuration file which can be installed to `/etc/fedora-openqa/schedule.conf` or `~/.config/fedora-openqa/schedule.conf`. In this config file you can specify the locations of the wiki and ResultsDB instance that will be used when reporting results with `fedora-openqa report`; by default, results will be reported to the [staging wiki](https://stg.fedoraproject.org/wiki/) and to a ResultsDB instance running on localhost port 5001 (which is what you get if you follow the instructions to do a local deployment of ResultsDB for testing). You can also specify the openQA, wiki and ResultsDB URLs / hostnames which will be used by the various fedmsg consumers. A sample config file is provided as `schedule.conf.sample`, which you can copy into place and modify. +This tool has its own configuration file which can be installed to `/etc/fedora-openqa/schedule.conf` or `~/.config/fedora-openqa/schedule.conf`. In this config file you can specify the locations of the wiki and ResultsDB instance that will be used when reporting results with `fedora-openqa report`; by default, results will be reported to the [staging wiki](https://stg.fedoraproject.org/wiki/) and to a ResultsDB instance running on localhost port 5001 (which is what you get if you follow the instructions to do a local deployment of ResultsDB for testing). A sample config file is provided as `schedule.conf.sample`, which you can copy into place and modify. You can configure the set of images from each compose which will be downloaded and tested. For more details on this, see the comments in `images.json.sample`. -To run openQA jobs whenever a compose completes, you must install and enable fedmsg-hub. On Fedora: +To run openQA jobs whenever a compose completes, and to report results to a ResultsDB instance and/or a wiki, you can use the fedora-messaging systemd service pattern. - sudo dnf install fedmsg-hub - sudo systemctl enable fedmsg-hub.service +**PLEASE NOTE** that there should never be more than one Fedora production Wiki or ResultsDB reporter enabled in the world, and both of these are run in the Fedora infrastructure, so please don't enable these on your own deployments. Reporting to your own wiki or ResultsDB instance for testing is of course fine. -Now enable the consumer. Create a file `/etc/fedmsg.d/fedora_openqa.py` with the contents: +First, you need to install one or more consumer configuration files to `/etc/fedora-messaging`. There are sample files provided in this directory for Fedora production and staging configurations for the job scheduler, ResultsDB reporter and Wiki reporter: - config = { - 'fedora_openqa.scheduler.prod.enabled': True, - } + fedora_openqa_resultsdb_reporter.stg.toml + fedora_openqa_resultsdb_reporter.toml + fedora_openqa_scheduler.stg.toml + fedora_openqa_scheduler.toml + fedora_openqa_wiki_reporter.stg.toml + fedora_openqa_wiki_reporter.toml -Now start fedmsg-hub (or restart it if it's already running): +You can copy these into place and modify them as you like. You will at least need to replace the dummy UUID in each file (00000000-0000-0000-0000-000000000000) with a unique one generated by `uuidgen`, as explained in the comments. You may also change the authentication configuration and the settings in `consumer_config`. `openqa_hostname` is the openQA hostname to schedule jobs on (for the scheduler) or to retrieve the full job result details from (for the reporters). `openqa_baseurl` is the base URL to use for constructing links back to the results (for the reporters). For the Wiki reporter, `wiki_hostname` is the hostname of the wiki to send results to. For the ResultsDB reporter, `resultsdb_url` is the URL to send the results to (it should be the top-level API URL). For both reporter plugins, `do_report` configures whether to actually send the reports (if it is set false, the consumer will just log what it would have reported instead of actually reporting it). - sudo systemctl start fedmsg-hub.service +You will also need to install the `fedora-messaging` package: -In the Docker configuration you should probably set up the fedmsg consumer on the host system, ensuring you have set up the API credentials (as explained above). The fedmsg consumer will run as user 'fedmsg', so you need to give this user access to the openQA credentials: + sudo dnf install fedora-messaging - sudo chown root.fedmsg /etc/openqa/client.conf - sudo chmod 0640 /etc/openqa/client.conf +Once the configuration file(s) is/are in place, you can enable and start each consumer as a systemd service, for e.g.: -To report results automatically when tests complete, you can use the various `reporter` consumers. There are six of these, three for reporting to Wikitcms and three for reporting to ResultsDB. For each system, one consumer listens out for production fedmsgs, one for staging fedmsgs, and one for 'dev' fedmsgs (which are what you get when replaying fedmsgs using `fedmsg-dg-replay`, commonly used for testing). Their configuration keys (to be added to the `/etc/fedmsg.d/fedora_openqa.py` file) are: + sudo systemctl enable fm-consumer@fedora_openqa_scheduler + sudo systemctl enable fedora_openqa_wiki_reporter.stg + sudo systemctl start fm-consumer@fedora_openqa_scheduler + sudo systemctl start fedora_openqa_wiki_reporter.stg - fedora_openqa.reporter.resultsdb.prod.enabled - fedora_openqa.reporter.resultsdb.stg.enabled - fedora_openqa.reporter.resultsdb.test.enabled - fedora_openqa.reporter.wiki.prod.enabled - fedora_openqa.reporter.wiki.stg.enabled - fedora_openqa.reporter.wiki.test.enabled +Once again, please please do **NOT** enable result reporter consumers unless you're really sure you should be doing it, and they are definitely not pointed at Fedora's production wiki or ResultsDB. -Usually, if you enable any of these consumers, they will respond to jobs run in the official Fedora openQA deployments, not your own deployment. If you want to test the reporting workflow with jobs run on any other openQA instance, you will need to configure that instance such that fedmsg emitted by openQA are published onto a fedmsg bus that the reporter consumers can subscribe to, and then configure the system where the reporter consumers run to lsiten to that bus. This is all somewhat outside the scope of this document. Usually, these consumers will only be used by the official Fedora openQA deployments. +Also be aware that the result reporter consumer configurations are set to respond to jobs run in the official Fedora openQA deployments, not your own deployment. If you want to test the reporting workflow with jobs run on any other openQA instance, you will need to configure that instance such that fedmsgs emitted by openQA are forwarded to a fedora-messaging broker that the reporter consumers can subscribe to, and then configure the reporter consumers to subscribe to that broker instead. This is all somewhat outside the scope of this document. Usually, these consumers will only be used by the official Fedora openQA deployments. # vim: set ts=8 et sw=4: diff --git a/fedora_openqa/config.py b/fedora_openqa/config.py index 9dfde67..c365adf 100644 --- a/fedora_openqa/config.py +++ b/fedora_openqa/config.py @@ -45,33 +45,6 @@ CONFIG.set('cli', 'log-level', 'info') CONFIG.set('report', 'resultsdb_url', 'http://localhost:5001/api/v2.0/') CONFIG.set('report', 'wiki_hostname', 'stg.fedoraproject.org') -# Default URLs and submission settings for the fedmsg consumers. It'd -# be nice if fedmsg itself provided a config mechanism for consumers, -# but AFAICS it doesn't -CONFIG.set('consumers', 'prod_oqa_hostname', 'openqa.fedoraproject.org') -CONFIG.set('consumers', 'prod_oqa_baseurl', '') -CONFIG.set('consumers', 'stg_oqa_hostname', 'openqa.stg.fedoraproject.org') -CONFIG.set('consumers', 'stg_oqa_baseurl', '') -# this all depends on which instance's messages you replay... -CONFIG.set('consumers', 'test_oqa_hostname', 'openqa.fedoraproject.org') -CONFIG.set('consumers', 'test_oqa_baseurl', '') -# We default to localhost for all of these for safety (and so you can -# test reporting from 'real' fedmsgs to a test rdb instance), and the -# infra deployments change in their local configs -CONFIG.set('consumers', 'prod_rdb_url', 'http://localhost:5001/api/v2.0/') -CONFIG.set('consumers', 'prod_rdb_report', 'false') -CONFIG.set('consumers', 'stg_rdb_url', 'http://localhost:5001/api/v2.0/') -CONFIG.set('consumers', 'stg_rdb_report', 'false') -CONFIG.set('consumers', 'test_rdb_url', 'http://localhost:5001/api/v2.0/') -CONFIG.set('consumers', 'test_rdb_report', 'true') -CONFIG.set('consumers', 'prod_wiki_hostname', 'fedoraproject.org') -CONFIG.set('consumers', 'prod_wiki_report', 'false') -CONFIG.set('consumers', 'stg_wiki_hostname', 'stg.fedoraproject.org') -CONFIG.set('consumers', 'stg_wiki_report', 'false') -CONFIG.set('consumers', 'test_wiki_hostname', 'stg.fedoraproject.org') -# As the default location is public staging, keep this as false -CONFIG.set('consumers', 'test_wiki_report', 'false') - CONFIG.read('/etc/fedora-openqa/schedule.conf') CONFIG.read('{0}/.config/fedora-openqa/schedule.conf'.format(os.path.expanduser('~'))) diff --git a/fedora_openqa/consumer.py b/fedora_openqa/consumer.py index 3d2b95b..544bf45 100755 --- a/fedora_openqa/consumer.py +++ b/fedora_openqa/consumer.py @@ -18,124 +18,75 @@ # Author(s): John Dulaney # Adam Williamson -"""fedmsg consumer to schedule openQA jobs.""" +"""fedora-messaging consumers to schedule and report results for +openQA jobs.""" + +# standard libraries +import logging # external imports -import fedmsg.consumers +import fedora_messaging.config # internal imports -from .config import CONFIG, UPDATEWL +from .config import UPDATEWL from . import schedule from . import report -# COMMON BASE CLASSES WITH OPENQA CONFIG VALUES - - -class OpenQAProductionConsumer(fedmsg.consumers.FedmsgConsumer): - """Production mixin for both wiki and ResultsDB reporters so they - can handily share some config settings. - """ - topic = "org.fedoraproject.prod.openqa.job.done" - - # Values read from CONFIG are implemented as properties (not class - # or instance variables) to ease testing - @property - def openqa_hostname(self): - """openQA hostname.""" - return CONFIG.get('consumers', 'prod_oqa_hostname') - - @property - def openqa_baseurl(self): - """openQA base URL.""" - return CONFIG.get('consumers', 'prod_oqa_baseurl') +# SCHEDULER -class OpenQAStagingConsumer(fedmsg.consumers.FedmsgConsumer): - """Staging mixin for both wiki and ResultsDB reporters so they can - handily share some config settings. +class OpenQAScheduler(object): + """A fedora-messaging consumer that schedules openQA jobs when a + new compose or update appears. """ - topic = "org.fedoraproject.stg.openqa.job.done" - - @property - def openqa_hostname(self): - """openQA hostname.""" - return CONFIG.get('consumers', 'stg_oqa_hostname') - - @property - def openqa_baseurl(self): - """openQA base URL.""" - return CONFIG.get('consumers', 'stg_oqa_baseurl') - - -class OpenQATestConsumer(fedmsg.consumers.FedmsgConsumer): - """Test mixin for both wiki and ResultsDB reporters so they can - handily share some config settings. - """ - topic = "org.fedoraproject.dev.openqa.job.done" - validate_signatures = False - - @property - def openqa_hostname(self): - """openQA hostname.""" - return CONFIG.get('consumers', 'test_oqa_hostname') - - @property - def openqa_baseurl(self): - """openQA base URL.""" - return CONFIG.get('consumers', 'test_oqa_baseurl') - - -# SCHEDULER CLASSES + def __init__(self): + self.openqa_hostname = fedora_messaging.config.conf["consumer_config"]["openqa_hostname"] + self.logger = logging.getLogger(self.__class__.__name__) -class OpenQAScheduler(fedmsg.consumers.FedmsgConsumer): - """A fedmsg consumer that schedules openQA jobs when a new compose - or update appears. - """ - - def _log(self, level, message): - """Convenience function for sticking the class name on the - front of the log message as an identifier. - """ - logfnc = getattr(self.log, level) - logfnc("%s: %s", self.__class__.__name__, message) + def __call__(self, message): + """Consume incoming message.""" + if 'pungi' in message.topic: + return self._consume_compose(message) + elif 'bodhi' in message.topic: + return self._consume_update(message) def _consume_compose(self, message): """Consume a 'compose' type message.""" - status = message['body']['msg'].get('status') - location = message['body']['msg'].get('location') - compstr = message['body']['msg'].get('compose_id', location) + status = message.body['msg'].get('status') + location = message.body['msg'].get('location') + compstr = message.body['msg'].get('compose_id', location) # don't schedule tests on modular composes, for now, as we know # many fail if 'Fedora-Modular' in compstr: - self._log('info', "Not scheduling jobs for modular compose {0}".format(compstr)) + self.logger.info("Not scheduling jobs for modular compose %s", compstr) return if 'FINISHED' in status and location: # We have a complete pungi4 compose - self._log('info', "Scheduling openQA jobs for compose {0}".format(compstr)) + self.logger.info("Scheduling openQA jobs for compose %s", compstr) try: # pylint: disable=no-member (compose, jobs) = schedule.jobs_from_compose(location, openqa_hostname=self.openqa_hostname) except schedule.TriggerException as err: - self._log('warning', "No openQA jobs run! {0}".format(err)) + self.logger.warning("No openQA jobs run! %s", err) return if jobs: - self._log('info', "openQA jobs run on compose {0}: " - "{1}".format(compose, ' '.join(str(job) for job in jobs))) + self.logger.info("openQA jobs run on compose %s: " + "%s", compose, ' '.join(str(job) for job in jobs)) else: - self._log('warning', "No openQA jobs run!") + self.logger.warning("No openQA jobs run!") return - self._log('debug', "Finished") + self.logger.debug("Finished") return return def _consume_update(self, message): """Consume an 'update' type message.""" - update = message['body']['msg'].get('update', {}) + update = message.body.get('update', {}) advisory = update.get('alias') critpath = update.get('critpath', False) version = update.get('release', {}).get('version') @@ -147,12 +98,12 @@ class OpenQAScheduler(fedmsg.consumers.FedmsgConsumer): # if update is critpath, always run all update tests if critpath and advisory and version and idpref == 'FEDORA': - self._log('info', "Scheduling openQA jobs for critical path update {0}".format(advisory)) + self.logger.info("Scheduling openQA jobs for critical path update %s", advisory) flavors = None # otherwise check the whitelist elif advisory and version and idpref == 'FEDORA': - self._log('debug', "Checking whitelist for update {0}".format(advisory)) + self.logger.debug("Checking whitelist for update %s", advisory) for build in update.get('builds', []): # get just the package name by splitting the NVR. This # assumes all NVRs actually contain a V and an R. @@ -162,7 +113,7 @@ class OpenQAScheduler(fedmsg.consumers.FedmsgConsumer): if pkgname in UPDATEWL: if not UPDATEWL[pkgname]: # this means *all* flavors, and we can short - self._log('info', "Running ALL openQA tests for whitelisted update {0}".format(advisory)) + self.logger.info("Running ALL openQA tests for whitelisted update %s", advisory) flavors = None break else: @@ -171,11 +122,11 @@ class OpenQAScheduler(fedmsg.consumers.FedmsgConsumer): if flavors: # this means we have a list of flavors, not None indicating # *all* flavors, let's log that - tmpl = "Running update tests for flavors {0} for whitelisted update {1}" - self._log('info', tmpl.format(', '.join(flavors), advisory)) + tmpl = "Running update tests for flavors %s for whitelisted update %s" + self.logger.info(tmpl, ', '.join(flavors), advisory) elif flavors == []: # This means we ain't running nothin' - self._log('debug', "Update is not critical path and no packages in whitelist, no jobs scheduled") + self.logger.debug("Update is not critical path and no packages in whitelist, no jobs scheduled") return # Finally, now we've decided on flavors, run the jobs. flavors @@ -185,71 +136,35 @@ class OpenQAScheduler(fedmsg.consumers.FedmsgConsumer): jobs = schedule.jobs_from_update( advisory, version, flavors=flavors, openqa_hostname=self.openqa_hostname, force=True) if jobs: - self._log('info', "openQA jobs run on update {0}: " - "{1}".format(advisory, ' '.join(str(job) for job in jobs))) + self.logger.info("openQA jobs run on update %s: " + "%s", advisory, ' '.join(str(job) for job in jobs)) else: - self._log('warning', "No openQA jobs run!") + self.logger.warning("No openQA jobs run!") return - self._log('debug', "Finished") + self.logger.debug("Finished") return - def consume(self, message): - """Consume incoming message.""" - if 'pungi' in message['body']['topic']: - return self._consume_compose(message) - elif 'bodhi' in message['body']['topic']: - return self._consume_update(message) - -class OpenQAProductionScheduler(OpenQAScheduler, OpenQAProductionConsumer): - """A scheduling consumer that listens for production fedmsgs and - creates events in the production openQA instance by default. - """ - topic = ["org.fedoraproject.prod.pungi.compose.status.change", - "org.fedoraproject.prod.bodhi.update.request.testing", - "org.fedoraproject.prod.bodhi.update.edit"] - config_key = "fedora_openqa.scheduler.prod.enabled" +# WIKI REPORTER -class OpenQAStagingScheduler(OpenQAScheduler, OpenQAStagingConsumer): - """A scheduling consumer that listens for staging fedmsgs and - creates events in the staging openQA instance by default. +class OpenQAWikiReporter(object): + """A fedora-messaging consumer that reports openQA results to + Wikitcms when a job completes. """ - topic = ["org.fedoraproject.stg.pungi.compose.status.change", - "org.fedoraproject.stg.bodhi.update.request.testing", - "org.fedoraproject.stg.bodhi.update.edit"] - config_key = "fedora_openqa.scheduler.stg.enabled" - - -class OpenQATestScheduler(OpenQAScheduler): - """A scheduling consumer that listens for dev fedmsgs and creates - events in a local openQA instance by default. - """ - topic = ["org.fedoraproject.dev.pungi.compose.status.change", - "org.fedoraproject.dev.bodhi.update.request.testing", - "org.fedoraproject.dev.bodhi.update.edit"] - config_key = "fedora_openqa.scheduler.test.enabled" - # We just hardcode this here and don't inherit from TestConsumer, - # as the config values are intended for the Reporter consumers - # that *consume* openQA jobs, we likely always want localhost for - # test *creating* openQA jobs - openqa_hostname = 'localhost' - -# WIKI REPORTER CLASSES + def __init__(self): + self.logger = logging.getLogger(self.__class__.__name__) + self.do_report = fedora_messaging.config.conf["consumer_config"]["do_report"] + self.openqa_hostname = fedora_messaging.config.conf["consumer_config"]["openqa_hostname"] + self.openqa_baseurl = fedora_messaging.config.conf["consumer_config"]["openqa_baseurl"] + self.wiki_hostname = fedora_messaging.config.conf["consumer_config"]["wiki_hostname"] - -class OpenQAWikiReporter(fedmsg.consumers.FedmsgConsumer): - """A fedmsg consumer that reports openQA results to Wikitcms when - a job completes. This is a parent class for prod, stg and test - variants, it is not intended to be used itself. - """ - - def consume(self, message): + def __call__(self, message): """Consume incoming message.""" - job = message['body']['msg']['id'] - self.log.info("%s: reporting results for %s", self.__class__.__name__, job) + job = message.body['msg']['id'] + self.logger.info("reporting results for %s", job) # pylint: disable=no-member results = report.wiki_report( wiki_hostname=self.wiki_hostname, jobs=[job], do_report=self.do_report, @@ -259,140 +174,28 @@ class OpenQAWikiReporter(fedmsg.consumers.FedmsgConsumer): self.log.info("%s: would report %s", self.__class__.__name__, res) -class OpenQAProductionWikiReporter(OpenQAWikiReporter, OpenQAProductionConsumer): - """A result reporting consumer that listens for production fedmsgs - and reports to the production wiki. Only one of these should ever - be running at one time; it'd be particularly bad if we had two - running with different FAS accounts, all results would be duped. - Please don't enable this consumer unless you're sure you know what - you're doing. - """ - config_key = "fedora_openqa.reporter.wiki.prod.enabled" - - @property - def wiki_hostname(self): - """Wiki hostname.""" - return CONFIG.get('consumers', 'prod_wiki_hostname') - - @property - def do_report(self): - """Whether to report.""" - return CONFIG.getboolean('consumers', 'prod_wiki_report') - - -class OpenQAStagingWikiReporter(OpenQAWikiReporter, OpenQAStagingConsumer): - """A result reporting consumer that listens for staging fedmsgs - and reports to the staging wiki. Only one of these should ever - be running at one time; it'd be particularly bad if we had two - running with different FAS accounts, all results would be duped. - Please don't enable this consumer unless you're sure you know what - you're doing. - """ - config_key = "fedora_openqa.reporter.wiki.stg.enabled" - - @property - def wiki_hostname(self): - """Wiki hostname.""" - return CONFIG.get('consumers', 'stg_wiki_hostname') - - @property - def do_report(self): - """Whether to report.""" - return CONFIG.getboolean('consumers', 'stg_wiki_report') +# RESULTSDB REPORTER -class OpenQATestWikiReporter(OpenQAWikiReporter, OpenQATestConsumer): - """A result reporting consumer that listens for dev fedmsgs (so it - will catch ones produced by fedmsg-dg-replay) and does not really - report results, it should log the produced ResTuples instead. This - is the one you should use to test stuff, go nuts with it. +class OpenQAResultsDBReporter(object): + """A fedora-messaging consumer that reports openQA results to + ResultsDB when a job completes. """ - config_key = "fedora_openqa.reporter.wiki.test.enabled" - @property - def wiki_hostname(self): - """Wiki hostname.""" - return CONFIG.get('consumers', 'test_wiki_hostname') + def __init__(self): + self.logger = logging.getLogger(self.__class__.__name__) + self.do_report = fedora_messaging.config.conf["consumer_config"]["do_report"] + self.openqa_hostname = fedora_messaging.config.conf["consumer_config"]["openqa_hostname"] + self.openqa_baseurl = fedora_messaging.config.conf["consumer_config"]["openqa_baseurl"] + self.resultsdb_url = fedora_messaging.config.conf["consumer_config"]["resultsdb_url"] - @property - def do_report(self): - """Whether to report.""" - return CONFIG.getboolean('consumers', 'test_wiki_report') - - -# RESULTSDB REPORTER CLASSES - - -class OpenQAResultsDBReporter(fedmsg.consumers.FedmsgConsumer): - """A fedmsg consumer that reports openQA results to ResultsDB when - a job completes. This is a parent class for prod and test - variants, it is not complete in itself. - """ - - def consume(self, message): + def __call__(self, message): """Consume incoming message.""" - job = message['body']['msg']['id'] - self.log.info("%s: reporting results for %s", self.__class__.__name__, job) + job = message.body['msg']['id'] + self.logger.info("reporting results for %s", job) # pylint: disable=no-member report.resultsdb_report( resultsdb_url=self.resultsdb_url, jobs=[job], do_report=self.do_report, openqa_hostname=self.openqa_hostname, openqa_baseurl=self.openqa_baseurl) - -class OpenQAProductionResultsDBReporter(OpenQAResultsDBReporter, OpenQAProductionConsumer): - """A result reporting consumer that listens for production fedmsgs. - By default it reports to localhost; please don't configure it to - report to the official ResultsDB instances unless you're sure you - know what you're doing. - """ - config_key = "fedora_openqa.reporter.resultsdb.prod.enabled" - - @property - def resultsdb_url(self): - """ResultsDB URL.""" - return CONFIG.get('consumers', 'prod_rdb_url') - - @property - def do_report(self): - """Whether to report.""" - return CONFIG.getboolean('consumers', 'prod_rdb_report') - - -class OpenQAStagingResultsDBReporter(OpenQAResultsDBReporter, OpenQAStagingConsumer): - """A result reporting consumer that listens for staging fedmsgs. -By default it reports to localhost; please don't configure it to - report to the official ResultsDB instances unless you're sure you - know what you're doing. - """ - config_key = "fedora_openqa.reporter.resultsdb.stg.enabled" - - @property - def resultsdb_url(self): - """ResultsDB URL.""" - return CONFIG.get('consumers', 'stg_rdb_url') - - @property - def do_report(self): - """Whether to report.""" - return CONFIG.getboolean('consumers', 'stg_rdb_report') - - -class OpenQATestResultsDBReporter(OpenQAResultsDBReporter, OpenQATestConsumer): - """A result reporting consumer that listens for dev fedmsgs (so it - will catch ones produced by fedmsg-dg-replay) and reports to a - ResultsDB instance running on localhost:5001 (as you get by running - the development mode). - """ - config_key = "fedora_openqa.reporter.resultsdb.test.enabled" - - @property - def resultsdb_url(self): - """ResultsDB URL.""" - return CONFIG.get('consumers', 'test_rdb_url') - - @property - def do_report(self): - """Whether to report.""" - return CONFIG.getboolean('consumers', 'test_rdb_report') - # vim: set textwidth=120 ts=8 et sw=4: diff --git a/fedora_openqa/schedule.py b/fedora_openqa/schedule.py index 34b6302..3774a9b 100644 --- a/fedora_openqa/schedule.py +++ b/fedora_openqa/schedule.py @@ -231,8 +231,8 @@ def jobs_from_compose(location, wanted=None, force=False, extraparams=None, open of the compose ID and the list of job IDs. location is the top level of the compose. Note this value is - provided by fedmsg 'pungi.compose.status.change' messages as - 'location'. + provided by fedora-messaging 'pungi.compose.status.change' + messages as 'location'. wanted is a dict defining which images from the compose we should schedule tests for. It is passed direct to _get_images(). The diff --git a/fedora_openqa_resultsdb_reporter.stg.toml b/fedora_openqa_resultsdb_reporter.stg.toml new file mode 100644 index 0000000..f1767ee --- /dev/null +++ b/fedora_openqa_resultsdb_reporter.stg.toml @@ -0,0 +1,87 @@ +# fedora-messaging consumer configuration file for the staging openQA +# ResultsDB reporter. Note you must change the UUID here to something +# unique before using this. +# +# This file is in the TOML format. +amqp_url = "amqps://fedora.stg:@rabbitmq.stg.fedoraproject.org/%2Fpublic_pubsub" +callback = "fedora_openqa.consumer:OpenQAResultsDBReporter" + +[tls] +ca_cert = "/etc/fedora-messaging/stg-cacert.pem" +keyfile = "/etc/fedora-messaging/fedora.stg-key.pem" +certfile = "/etc/fedora-messaging/fedora.stg-cert.pem" + + +[client_properties] +app = "Fedora openQA" + +[exchanges."amq.topic"] +type = "topic" +durable = true +auto_delete = false +arguments = {} + +# Queue names *must* be in the normal UUID format: run "uuidgen" and use the +# output as your queue name. If your queue is not exclusive, anyone can connect +# and consume from it, causing you to miss messages, so do not share your queue +# name. Any queues that are not auto-deleted on disconnect are garbage-collected +# after approximately one hour. +# +# If you require a stronger guarantee about delivery, please talk to Fedora's +# Infrastructure team. +[queues.00000000-0000-0000-0000-000000000000] +durable = false +auto_delete = true +exclusive = true +arguments = {} + +[[bindings]] +queue = "00000000-0000-0000-0000-000000000000" +exchange = "amq.topic" +routing_keys = ["org.fedoraproject.stg.openqa.job.done"] + +[consumer_config] +openqa_hostname = "openqa.stg.fedoraproject.org" +openqa_baseurl = "https://openqa.stg.fedoraproject.org" +resultsdb_url = "http://resultsdb-stg01.qa.fedoraproject.org/resultsdb_api/api/v2.0/" +do_report = false + +[qos] +prefetch_size = 0 +prefetch_count = 25 + +[log_config] +version = 1 +disable_existing_loggers = true + +[log_config.formatters.simple] +format = "[%(levelname)s %(name)s] %(message)s" + +[log_config.handlers.console] +class = "logging.StreamHandler" +formatter = "simple" +stream = "ext://sys.stdout" + +[log_config.loggers.ResultsDBReporter] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.fedora_messaging] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.twisted] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.pika] +level = "WARNING" +propagate = false +handlers = ["console"] + +[log_config.root] +level = "ERROR" +handlers = ["console"] diff --git a/fedora_openqa_resultsdb_reporter.toml b/fedora_openqa_resultsdb_reporter.toml new file mode 100644 index 0000000..575f643 --- /dev/null +++ b/fedora_openqa_resultsdb_reporter.toml @@ -0,0 +1,86 @@ +# fedora-messaging consumer configuration file for the production +# openQA ResultsDB reporter. Note you must change the UUID here to +# something unique before using this. +# +# This file is in the TOML format. +amqp_url = "amqps://fedora:@rabbitmq.fedoraproject.org/%2Fpublic_pubsub" +callback = "fedora_openqa.consumer:OpenQAResultsDBReporter" + +[tls] +ca_cert = "/etc/fedora-messaging/cacert.pem" +keyfile = "/etc/fedora-messaging/fedora-key.pem" +certfile = "/etc/fedora-messaging/fedora-cert.pem" + +[client_properties] +app = "Fedora openQA" + +[exchanges."amq.topic"] +type = "topic" +durable = true +auto_delete = false +arguments = {} + +# Queue names *must* be in the normal UUID format: run "uuidgen" and use the +# output as your queue name. If your queue is not exclusive, anyone can connect +# and consume from it, causing you to miss messages, so do not share your queue +# name. Any queues that are not auto-deleted on disconnect are garbage-collected +# after approximately one hour. +# +# If you require a stronger guarantee about delivery, please talk to Fedora's +# Infrastructure team. +[queues.00000000-0000-0000-0000-000000000000] +durable = false +auto_delete = true +exclusive = true +arguments = {} + +[[bindings]] +queue = "00000000-0000-0000-0000-000000000000" +exchange = "amq.topic" +routing_keys = ["org.fedoraproject.prod.openqa.job.done"] + +[consumer_config] +openqa_hostname = "openqa.fedoraproject.org" +openqa_baseurl = "https://openqa.fedoraproject.org" +resultsdb_url = "http://resultsdb01.qa.fedoraproject.org/resultsdb_api/api/v2.0/" +do_report = false + +[qos] +prefetch_size = 0 +prefetch_count = 25 + +[log_config] +version = 1 +disable_existing_loggers = true + +[log_config.formatters.simple] +format = "[%(levelname)s %(name)s] %(message)s" + +[log_config.handlers.console] +class = "logging.StreamHandler" +formatter = "simple" +stream = "ext://sys.stdout" + +[log_config.loggers.ResultsDBReporter] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.fedora_messaging] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.twisted] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.pika] +level = "WARNING" +propagate = false +handlers = ["console"] + +[log_config.root] +level = "ERROR" +handlers = ["console"] diff --git a/fedora_openqa_scheduler.stg.toml b/fedora_openqa_scheduler.stg.toml new file mode 100644 index 0000000..4a436f1 --- /dev/null +++ b/fedora_openqa_scheduler.stg.toml @@ -0,0 +1,91 @@ +# fedora-messaging consumer configuration file for the staging openQA +# scheduler. Note you must change the UUID here to something unique +# before using this. +# +# This file is in the TOML format. + +# we listen to the prod broker here (not staging) as we need to use +# prod messages to schedule jobs in openQA staging, composes and +# updates just don't show up on the staging broker. +amqp_url = "amqps://fedora:@rabbitmq.fedoraproject.org/%2Fpublic_pubsub" +callback = "fedora_openqa.consumer:OpenQAScheduler" + +[tls] +ca_cert = "/etc/fedora-messaging/cacert.pem" +keyfile = "/etc/fedora-messaging/fedora-key.pem" +certfile = "/etc/fedora-messaging/fedora-cert.pem" + +[client_properties] +app = "Fedora openQA" + +[exchanges."amq.topic"] +type = "topic" +durable = true +auto_delete = false +arguments = {} + +# Queue names *must* be in the normal UUID format: run "uuidgen" and use the +# output as your queue name. If your queue is not exclusive, anyone can connect +# and consume from it, causing you to miss messages, so do not share your queue +# name. Any queues that are not auto-deleted on disconnect are garbage-collected +# after approximately one hour. +# +# If you require a stronger guarantee about delivery, please talk to Fedora's +# Infrastructure team. +[queues.00000000-0000-0000-0000-000000000000] +durable = false +auto_delete = true +exclusive = true +arguments = {} + +[[bindings]] +queue = "00000000-0000-0000-0000-000000000000" +exchange = "amq.topic" +# we subscribe to prod not staging keys here as per above. +routing_keys = ["org.fedoraproject.prod.pungi.compose.status.change", + "org.fedoraproject.prod.bodhi.update.request.testing", + "org.fedoraproject.prod.bodhi.update.edit"] + +[consumer_config] +openqa_hostname = "openqa.stg.fedoraproject.org" +openqa_baseurl = "https://openqa.stg.fedoraproject.org" + +[qos] +prefetch_size = 0 +prefetch_count = 25 + +[log_config] +version = 1 +disable_existing_loggers = true + +[log_config.formatters.simple] +format = "[%(levelname)s %(name)s] %(message)s" + +[log_config.handlers.console] +class = "logging.StreamHandler" +formatter = "simple" +stream = "ext://sys.stdout" + +[log_config.loggers.OpenQAScheduler] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.fedora_messaging] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.twisted] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.pika] +level = "WARNING" +propagate = false +handlers = ["console"] + +[log_config.root] +level = "ERROR" +handlers = ["console"] diff --git a/fedora_openqa_scheduler.toml b/fedora_openqa_scheduler.toml new file mode 100644 index 0000000..6c9e935 --- /dev/null +++ b/fedora_openqa_scheduler.toml @@ -0,0 +1,85 @@ +# fedora-messaging consumer configuration file for the production +# openQA scheduler. Note you must change the UUID here to something +# unique before using this. +# +# This file is in the TOML format. +amqp_url = "amqps://fedora:@rabbitmq.fedoraproject.org/%2Fpublic_pubsub" +callback = "fedora_openqa.consumer:OpenQAScheduler" + +[tls] +ca_cert = "/etc/fedora-messaging/cacert.pem" +keyfile = "/etc/fedora-messaging/fedora-key.pem" +certfile = "/etc/fedora-messaging/fedora-cert.pem" + +[client_properties] +app = "Fedora openQA" + +[exchanges."amq.topic"] +type = "topic" +durable = true +auto_delete = false +arguments = {} + +# Queue names *must* be in the normal UUID format: run "uuidgen" and use the +# output as your queue name. If your queue is not exclusive, anyone can connect +# and consume from it, causing you to miss messages, so do not share your queue +# name. Any queues that are not auto-deleted on disconnect are garbage-collected +# after approximately one hour. +# +# If you require a stronger guarantee about delivery, please talk to Fedora's +# Infrastructure team. +[queues.00000000-0000-0000-0000-000000000000] +durable = false +auto_delete = true +exclusive = true +arguments = {} + +[[bindings]] +queue = "00000000-0000-0000-0000-000000000000" +exchange = "amq.topic" +routing_keys = ["org.fedoraproject.prod.pungi.compose.status.change", + "org.fedoraproject.prod.bodhi.update.request.testing", + "org.fedoraproject.prod.bodhi.update.edit"] + +[consumer_config] +openqa_hostname = "openqa.fedoraproject.org" + +[qos] +prefetch_size = 0 +prefetch_count = 25 + +[log_config] +version = 1 +disable_existing_loggers = true + +[log_config.formatters.simple] +format = "[%(levelname)s %(name)s] %(message)s" + +[log_config.handlers.console] +class = "logging.StreamHandler" +formatter = "simple" +stream = "ext://sys.stdout" + +[log_config.loggers.OpenQAScheduler] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.fedora_messaging] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.twisted] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.pika] +level = "WARNING" +propagate = false +handlers = ["console"] + +[log_config.root] +level = "ERROR" +handlers = ["console"] diff --git a/fedora_openqa_wiki_reporter.stg.toml b/fedora_openqa_wiki_reporter.stg.toml new file mode 100644 index 0000000..7e871c0 --- /dev/null +++ b/fedora_openqa_wiki_reporter.stg.toml @@ -0,0 +1,87 @@ +# fedora-messaging consumer configuration file for the staging openQA +# wiki reporter. Note you must change the UUID here to something +# unique before using this. +# +# This file is in the TOML format. +amqp_url = "amqps://fedora.stg:@rabbitmq.stg.fedoraproject.org/%2Fpublic_pubsub" +callback = "fedora_openqa.consumer:OpenQAWikiReporter" + +[tls] +ca_cert = "/etc/fedora-messaging/stg-cacert.pem" +keyfile = "/etc/fedora-messaging/fedora.stg-key.pem" +certfile = "/etc/fedora-messaging/fedora.stg-cert.pem" + + +[client_properties] +app = "Fedora openQA" + +[exchanges."amq.topic"] +type = "topic" +durable = true +auto_delete = false +arguments = {} + +# Queue names *must* be in the normal UUID format: run "uuidgen" and use the +# output as your queue name. If your queue is not exclusive, anyone can connect +# and consume from it, causing you to miss messages, so do not share your queue +# name. Any queues that are not auto-deleted on disconnect are garbage-collected +# after approximately one hour. +# +# If you require a stronger guarantee about delivery, please talk to Fedora's +# Infrastructure team. +[queues.00000000-0000-0000-0000-000000000000] +durable = false +auto_delete = true +exclusive = true +arguments = {} + +[[bindings]] +queue = "00000000-0000-0000-0000-000000000000" +exchange = "amq.topic" +routing_keys = ["org.fedoraproject.stg.openqa.job.done"] + +[consumer_config] +openqa_hostname = "openqa.stg.fedoraproject.org" +openqa_baseurl = "https://openqa.stg.fedoraproject.org" +wiki_hostname = "stg.fedoraproject.org" +do_report = false + +[qos] +prefetch_size = 0 +prefetch_count = 25 + +[log_config] +version = 1 +disable_existing_loggers = true + +[log_config.formatters.simple] +format = "[%(levelname)s %(name)s] %(message)s" + +[log_config.handlers.console] +class = "logging.StreamHandler" +formatter = "simple" +stream = "ext://sys.stdout" + +[log_config.loggers.OpenQAWikiReporter] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.fedora_messaging] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.twisted] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.pika] +level = "WARNING" +propagate = false +handlers = ["console"] + +[log_config.root] +level = "ERROR" +handlers = ["console"] diff --git a/fedora_openqa_wiki_reporter.toml b/fedora_openqa_wiki_reporter.toml new file mode 100644 index 0000000..89d4133 --- /dev/null +++ b/fedora_openqa_wiki_reporter.toml @@ -0,0 +1,86 @@ +# fedora-messaging consumer configuration file for the production +# openQA wiki reporter. Note you must change the UUID here to +# something unique before using this. +# +# This file is in the TOML format. +amqp_url = "amqps://fedora:@rabbitmq.fedoraproject.org/%2Fpublic_pubsub" +callback = "fedora_openqa.consumer:OpenQAWikiReporter" + +[tls] +ca_cert = "/etc/fedora-messaging/cacert.pem" +keyfile = "/etc/fedora-messaging/fedora-key.pem" +certfile = "/etc/fedora-messaging/fedora-cert.pem" + +[client_properties] +app = "Fedora openQA" + +[exchanges."amq.topic"] +type = "topic" +durable = true +auto_delete = false +arguments = {} + +# Queue names *must* be in the normal UUID format: run "uuidgen" and use the +# output as your queue name. If your queue is not exclusive, anyone can connect +# and consume from it, causing you to miss messages, so do not share your queue +# name. Any queues that are not auto-deleted on disconnect are garbage-collected +# after approximately one hour. +# +# If you require a stronger guarantee about delivery, please talk to Fedora's +# Infrastructure team. +[queues.00000000-0000-0000-0000-000000000000] +durable = false +auto_delete = true +exclusive = true +arguments = {} + +[[bindings]] +queue = "00000000-0000-0000-0000-000000000000" +exchange = "amq.topic" +routing_keys = ["org.fedoraproject.prod.openqa.job.done"] + +[consumer_config] +openqa_hostname = "openqa.fedoraproject.org" +openqa_baseurl = "https://openqa.fedoraproject.org" +wiki_hostname = "fedoraproject.org" +do_report = false + +[qos] +prefetch_size = 0 +prefetch_count = 25 + +[log_config] +version = 1 +disable_existing_loggers = true + +[log_config.formatters.simple] +format = "[%(levelname)s %(name)s] %(message)s" + +[log_config.handlers.console] +class = "logging.StreamHandler" +formatter = "simple" +stream = "ext://sys.stdout" + +[log_config.loggers.OpenQAWikiReporter] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.fedora_messaging] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.twisted] +level = "INFO" +propagate = false +handlers = ["console"] + +[log_config.loggers.pika] +level = "WARNING" +propagate = false +handlers = ["console"] + +[log_config.root] +level = "ERROR" +handlers = ["console"] diff --git a/schedule.conf.sample b/schedule.conf.sample index 3781fc2..33f8970 100644 --- a/schedule.conf.sample +++ b/schedule.conf.sample @@ -17,64 +17,3 @@ resultsdb_url: http://localhost/resultsdb_api/api/v2.0/ # Hostname of Fedora wiki to report to wiki_hostname: stg.fedoraproject.org - -[consumers] -# Settings in this section affect the behaviour of the Fedmsg consumers -# in consumer.py - -# openQA host to query for results (for production reporters) or -# create jobs on (for production scheduler) -prod_oqa_hostname: openqa.fedoraproject.org - -# openQA baseurl (for formatting links) for production reporters -prod_oqa_baseurl: - -# openQA host to query for results (for staging reporters) or -# create jobs on (for staging scheduler) -stg_oqa_hostname: openqa.stg.fedoraproject.org - -# openQA baseurl (for formatting links) for staging reporters -stg_oqa_baseurl: - -# openQA host to query for results for test reporters -# NOTE: test scheduler does not respect this, always uses localhost -test_oqa_hostname: openqa.fedoraproject.org - -# openQA baseurl (for formatting links) for test reporters -test_oqa_baseurl: - -# URL for ResultsDB instance the production reporter should report to -prod_rdb_url: http://resultsdb01.qa.fedoraproject.org/resultsdb_api/api/v2.0/ - -# Whether the production ResultsDB reporter should actually submit results -prod_rdb_report: false - -# URL for ResultsDB instance the staging reporter should report to -stg_rdb_url: http://resultsdb-stg01.qa.fedoraproject.org/resultsdb_api/api/v2.0/ - -# Whether the staging ResultsDB reporter should actually submit results -stg_rdb_report: false - -# URL for ResultsDB instance the test reporter should report to -test_rdb_url: http://localhost:5001/api/v2.0/ - -# Whether the testing ResultsDB reporter should actually submit results -test_rdb_report: true - -# Host name for Mediawiki instance the production reporter should report to -prod_wiki_hostname: fedoraproject.org - -# Whether the production wiki reporter should actually submit results -prod_wiki_report: false - -# Host name for Mediawiki instance the staging reporter should report to -stg_wiki_hostname: stg.fedoraproject.org - -# Whether the staging wiki reporter should actually submit results -stg_wiki_report: false - -# Host name for Mediawiki instance the test reporter should report to -test_wiki_hostname: stg.fedoraproject.org - -# Whether the test wiki reporter should actually submit results -test_wiki_report: false diff --git a/setup.py b/setup.py index 76f1cc8..740218c 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ if "--nodeps" in sys.argv: installreqs = [] sys.argv.remove("--nodeps") else: - installreqs = ['fedfind>=2.5.0', 'fedmsg', 'openqa-client>=1.1', 'setuptools', + installreqs = ['fedfind>=2.5.0', 'fedora-messaging', 'openqa-client>=1.1', 'setuptools', 'six', 'resultsdb_api', 'resultsdb_conventions>=2.0.2', 'wikitcms'] setup( @@ -50,17 +50,6 @@ setup( 'console_scripts': [ 'fedora-openqa = fedora_openqa.cli:main', ], - 'moksha.consumer': [ - 'fedora_openqa.scheduler.prod = fedora_openqa.consumer:OpenQAProductionScheduler', - 'fedora_openqa.scheduler.stg = fedora_openqa.consumer:OpenQAStagingScheduler', - 'fedora_openqa.scheduler.test = fedora_openqa.consumer:OpenQATestScheduler', - 'fedora_openqa.wiki.reporter.prod = fedora_openqa.consumer:OpenQAProductionWikiReporter', - 'fedora_openqa.wiki.reporter.stg = fedora_openqa.consumer:OpenQAStagingWikiReporter', - 'fedora_openqa.wiki.reporter.test = fedora_openqa.consumer:OpenQATestWikiReporter', - 'fedora_openqa.resultsdb.reporter.prod = fedora_openqa.consumer:OpenQAProductionResultsDBReporter', - 'fedora_openqa.resultsdb.reporter.stg = fedora_openqa.consumer:OpenQAStagingResultsDBReporter', - 'fedora_openqa.resultsdb.reporter.test = fedora_openqa.consumer:OpenQATestResultsDBReporter', - ], }, author = "Fedora QA devel team", author_email = "qa-devel@lists.fedoraproject.org", diff --git a/tests/test_consumers.py b/tests/test_consumers.py index 5f41848..8b0db3d 100644 --- a/tests/test_consumers.py +++ b/tests/test_consumers.py @@ -29,6 +29,7 @@ from __future__ import print_function import copy # external imports +from fedora_messaging.api import Message import mock import pytest @@ -45,10 +46,9 @@ MODIFIEDWL['gnome-terminal'] = ('workstation',) MODIFIEDWL['kernel'] = None # Passed test message -PASSMSG = { - 'body': { - "i": 1, - "msg": { +PASSMSG = Message( + topic="org.fedoraproject.stg.openqa.job.done", + body={ "ARCH": "x86_64", "BUILD": "Fedora-Rawhide-20170207.n.0", "FLAVOR": "universal", @@ -59,201 +59,178 @@ PASSMSG = { "newbuild": None, "remaining": 23, "result": "passed" - }, - "msg_id": "2017-0c3079cf-b21c-4aca-89b1-982d37ce4065", - "source_name": "datanommer", - "source_version": "0.6.5", - "timestamp": 1486473322.0, - "topic": "org.fedoraproject.stg.openqa.job.done" } -} +) # Started compose message -STARTEDCOMPOSE = { - 'body': { - "i": 1, - "msg": { - "compose_id": "Fedora-Atomic-25-20170206.0", - "location": "http://kojipkgs.fedoraproject.org/compose/twoweek/Fedora-Atomic-25-20170206.0/compose", - "status": "STARTED" - }, - "msg_id": "2017-e6670216-2f1a-45d8-b338-3e6da221c467", - "source_name": "datanommer", - "source_version": "0.6.5", - "timestamp": 1486358122.0, - "topic": "org.fedoraproject.prod.pungi.compose.status.change" +STARTEDCOMPOSE = Message( + topic="org.fedoraproject.prod.pungi.compose.status.change", + body={ + "compose_id": "Fedora-Atomic-25-20170206.0", + "location": "http://kojipkgs.fedoraproject.org/compose/twoweek/Fedora-Atomic-25-20170206.0/compose", + "status": "STARTED" } -} +) # Doomed compose message -DOOMEDCOMPOSE = { - 'body': { - "i": 1, - "msg": { - "compose_id": "Fedora-Docker-25-20170206.0", - "location": "http://kojipkgs.fedoraproject.org/compose/Fedora-Docker-25-20170206.0/compose", - "status": "DOOMED" - }, - "msg_id": "2017-984d8234-a6be-4df4-937d-cb778d4e689f", - "source_name": "datanommer", - "source_version": "0.6.5", - "timestamp": 1486360017.0, - "topic": "org.fedoraproject.prod.pungi.compose.status.change" +DOOMEDCOMPOSE = Message( + topic="org.fedoraproject.prod.pungi.compose.status.change", + body={ + "compose_id": "Fedora-Docker-25-20170206.0", + "location": "http://kojipkgs.fedoraproject.org/compose/Fedora-Docker-25-20170206.0/compose", + "status": "DOOMED" } -} +) # Finished compose message -FINISHEDCOMPOSE = { - 'body': { - "i": 1, - "msg": { - "compose_id": "Fedora-Atomic-25-20170206.0", - "location": "http://kojipkgs.fedoraproject.org/compose/twoweek/Fedora-Atomic-25-20170206.0/compose", - "status": "FINISHED" - }, - "msg_id": "2017-6fedef19-1f2c-44ff-bef5-f59b69eaa0c0", - "source_name": "datanommer", - "source_version": "0.6.5", - "timestamp": 1486363419.0, - "topic": "org.fedoraproject.prod.pungi.compose.status.change" +FINISHEDCOMPOSE = Message( + topic="org.fedoraproject.prod.pungi.compose.status.change", + body={ + "compose_id": "Fedora-Atomic-25-20170206.0", + "location": "http://kojipkgs.fedoraproject.org/compose/twoweek/Fedora-Atomic-25-20170206.0/compose", + "status": "FINISHED" } -} +) # Finished incomplete compose message -FINCOMPLETE = { - 'body': { - "i": 1, - "msg": { - "compose_id": "Fedora-Rawhide-20170206.n.0", - "location": "http://kojipkgs.fedoraproject.org/compose/rawhide/Fedora-Rawhide-20170206.n.0/compose", - "status": "FINISHED_INCOMPLETE" - }, - "msg_id": "2017-a396bf9d-48be-477e-a07c-bf69daf044ca", - "source_name": "datanommer", - "source_version": "0.6.5", - "timestamp": 1486378978.0, - "topic": "org.fedoraproject.prod.pungi.compose.status.change" +FINCOMPLETE = Message( + topic="org.fedoraproject.prod.pungi.compose.status.change", + body={ + "compose_id": "Fedora-Rawhide-20170206.n.0", + "location": "http://kojipkgs.fedoraproject.org/compose/rawhide/Fedora-Rawhide-20170206.n.0/compose", + "status": "FINISHED_INCOMPLETE" } -} +) # Critpath update creation message. These are huge, so this is heavily # edited. -CRITPATHCREATE = { - "body": { - "i": 1, - "msg": { - "agent": "msekleta", - "update": { - "alias": "FEDORA-2017-ea07abb5d5", - "builds": [ - { - "epoch": 0, - "nvr": "systemd-231-14.fc24", - "signed": False - } - ], - "critpath": True, - "release": { - "branch": "f24", - "dist_tag": "f24", - "id_prefix": "FEDORA", - "long_name": "Fedora 24", - "name": "F24", - "version": "24" - }, +CRITPATHCREATE = Message( + topic="org.fedoraproject.prod.bodhi.update.request.testing", + body={ + "agent": "msekleta", + "update": { + "alias": "FEDORA-2017-ea07abb5d5", + "builds": [ + { + "epoch": 0, + "nvr": "systemd-231-14.fc24", + "signed": False + } + ], + "critpath": True, + "release": { + "branch": "f24", + "dist_tag": "f24", + "id_prefix": "FEDORA", + "long_name": "Fedora 24", + "name": "F24", + "version": "24" }, }, - "msg_id": "2017-a6e10ab5-f861-4671-8945-ac1cf004a474", - "source_name": "datanommer", - "source_version": "0.6.5", - "timestamp": 1487862992.0, - "topic": "org.fedoraproject.prod.bodhi.update.request.testing" } -} +) # Non-critpath, non-whitelisted update creation message NONCRITCREATE = copy.deepcopy(CRITPATHCREATE) -NONCRITCREATE['body']['msg']['update']['critpath'] = False +NONCRITCREATE.body['update']['critpath'] = False # Non-critpath, one-flavor-whitelisted update creation message WLCREATE = copy.deepcopy(CRITPATHCREATE) -WLCREATE['body']['msg']['update']['critpath'] = False -WLCREATE['body']['msg']['update']['builds'] = [{"epoch": 0, "nvr": "freeipa-4.4.4-1.fc24", "signed": False}] +WLCREATE.body['update']['critpath'] = False +WLCREATE.body['update']['builds'] = [{"epoch": 0, "nvr": "freeipa-4.4.4-1.fc24", "signed": False}] # Critpath EPEL update creation message EPELCREATE = copy.deepcopy(CRITPATHCREATE) -EPELCREATE['body']['msg']['update']['release']['id_prefix'] = 'FEDORA-EPEL' +EPELCREATE.body['update']['release']['id_prefix'] = 'FEDORA-EPEL' # Critpath update edit message -CRITPATHEDIT = { - "body": { - "i": 1, - "msg": { - "agent": "hobbes1069", - "update": { - "alias": "FEDORA-2017-e6d7184200", - "critpath": True, - "release": { - "branch": "f24", - "dist_tag": "f24", - "id_prefix": "FEDORA", - "long_name": "Fedora 24", - "name": "F24", - "version": "24" - }, +CRITPATHEDIT = Message( + topic="org.fedoraproject.prod.bodhi.update.edit", + body={ + "agent": "hobbes1069", + "update": { + "alias": "FEDORA-2017-e6d7184200", + "critpath": True, + "release": { + "branch": "f24", + "dist_tag": "f24", + "id_prefix": "FEDORA", + "long_name": "Fedora 24", + "name": "F24", + "version": "24" }, }, - "msg_id": "2017-7213730f-40c8-4e27-9135-630f5de2113d", - "source_name": "datanommer", - "source_version": "0.6.5", - "timestamp": 1487735650.0, - "topic": "org.fedoraproject.prod.bodhi.update.edit" } -} +) # Non-critpath, non-whitelisted update edit message NONCRITEDIT = copy.deepcopy(CRITPATHEDIT) -NONCRITEDIT['body']['msg']['update']['critpath'] = False +NONCRITEDIT.body['update']['critpath'] = False # Non-critpath, two-flavors-whitelisted update edit message WLEDIT = copy.deepcopy(CRITPATHEDIT) -WLEDIT['body']['msg']['update']['critpath'] = False -WLEDIT['body']['msg']['update']['builds'] = [ +WLEDIT.body['update']['critpath'] = False +WLEDIT.body['update']['builds'] = [ {"epoch": 0, "nvr": "freeipa-4.4.4-1.fc26", "signed": False}, {"epoch": 0, "nvr": "gnome-terminal-3.24.1-1.fc24", "signed": False}, ] # Non-critpath, all-flavors-whitelisted update edit message WLALLEDIT = copy.deepcopy(CRITPATHEDIT) -WLALLEDIT['body']['msg']['update']['critpath'] = False -WLALLEDIT['body']['msg']['update']['builds'] = [{"epoch": 0, "nvr": "kernel-4.10.12-100.fc24", "signed": False}] +WLALLEDIT.body['update']['critpath'] = False +WLALLEDIT.body['update']['builds'] = [{"epoch": 0, "nvr": "kernel-4.10.12-100.fc24", "signed": False}] # Critpath EPEL update edit message EPELEDIT = copy.deepcopy(CRITPATHEDIT) -EPELEDIT['body']['msg']['update']['release']['id_prefix'] = 'FEDORA-EPEL' - - -# proper consumer init requires a fedmsg hub instance, we don't have -# one and don't want to faff around faking one. -with mock.patch('fedmsg.consumers.FedmsgConsumer.__init__', return_value=None): - PRODSCHED = fedora_openqa.consumer.OpenQAProductionScheduler(None) - STGSCHED = fedora_openqa.consumer.OpenQAStagingScheduler(None) - TESTSCHED = fedora_openqa.consumer.OpenQATestScheduler(None) - PRODWIKI = fedora_openqa.consumer.OpenQAProductionWikiReporter(None) - STGWIKI = fedora_openqa.consumer.OpenQAStagingWikiReporter(None) - TESTWIKI = fedora_openqa.consumer.OpenQATestWikiReporter(None) - PRODRDB = fedora_openqa.consumer.OpenQAProductionResultsDBReporter(None) - STGRDB = fedora_openqa.consumer.OpenQAStagingResultsDBReporter(None) - TESTRDB = fedora_openqa.consumer.OpenQATestResultsDBReporter(None) +EPELEDIT.body['update']['release']['id_prefix'] = 'FEDORA-EPEL' + +# initialize a few test consumers with different configs +PRODCONF = { + 'consumer_config': { + 'do_report':True, + 'openqa_hostname':'openqa.fedoraproject.org', + 'openqa_baseurl':'https://openqa.fedoraproject.org', + 'wiki_hostname':'fedoraproject.org', + 'resultsdb_url':'http://resultsdb01.qa.fedoraproject.org/resultsdb_api/api/v2.0/', + } +} +STGCONF = { + 'consumer_config': { + 'do_report':False, + 'openqa_hostname':'openqa.stg.fedoraproject.org', + 'openqa_baseurl':'https://openqa.stg.fedoraproject.org', + 'wiki_hostname':'stg.fedoraproject.org', + 'resultsdb_url':'http://resultsdb-stg01.qa.fedoraproject.org/resultsdb_api/api/v2.0/', + } +} +TESTCONF = { + 'consumer_config': { + 'do_report':False, + 'openqa_hostname':'localhost', + 'openqa_baseurl':'https://localhost', + 'wiki_hostname':'stg.fedoraproject.org', + 'resultsdb_url':'http://localhost:5001/api/v2.0/', + } +} + +with mock.patch.dict('fedora_messaging.config.conf', PRODCONF): + PRODSCHED = fedora_openqa.consumer.OpenQAScheduler() + PRODWIKI = fedora_openqa.consumer.OpenQAWikiReporter() + PRODRDB = fedora_openqa.consumer.OpenQAResultsDBReporter() +with mock.patch.dict('fedora_messaging.config.conf', STGCONF): + STGSCHED = fedora_openqa.consumer.OpenQAScheduler() + STGWIKI = fedora_openqa.consumer.OpenQAWikiReporter() + STGRDB = fedora_openqa.consumer.OpenQAResultsDBReporter() +with mock.patch.dict('fedora_messaging.config.conf', TESTCONF): + TESTSCHED = fedora_openqa.consumer.OpenQAScheduler() + TESTWIKI = fedora_openqa.consumer.OpenQAWikiReporter() + TESTRDB = fedora_openqa.consumer.OpenQAResultsDBReporter() PRODS = (PRODWIKI, PRODRDB, PRODSCHED) STGS = (STGWIKI, STGRDB, STGSCHED) # we don't include TESTSCHED as its values are hardcoded TESTS = (TESTWIKI, TESTRDB) -for _con in PRODS + STGS + TESTS + (TESTSCHED,): - # skipping __init__ means this doesn't get set up, so mock it - _con.log = mock.Mock() @pytest.mark.usefixtures("ffmock") class TestConsumers: @@ -308,7 +285,7 @@ class TestConsumers: and that the hostname is as expected. If jobs aren't expected, we check the schedule function was not hit. """ - consumer.consume(message) + consumer(message) if flavors is False: assert fake_schedule.call_count + fake_update.call_count == 0 else: @@ -325,9 +302,9 @@ class TestConsumers: @pytest.mark.parametrize( "consumer,expected", [ - (PRODWIKI, {'report': False, 'oqah': 'openqa.fedoraproject.org', 'wikih': 'fedoraproject.org'}), + (PRODWIKI, {'report': True, 'oqah': 'openqa.fedoraproject.org', 'wikih': 'fedoraproject.org'}), (STGWIKI, {'report': False, 'oqah': 'openqa.stg.fedoraproject.org', 'wikih': 'stg.fedoraproject.org'}), - (TESTWIKI, {'report': False, 'oqah': 'openqa.fedoraproject.org', 'wikih': 'stg.fedoraproject.org'}), + (TESTWIKI, {'report': False, 'oqah': 'localhost', 'wikih': 'stg.fedoraproject.org'}), ] ) def test_wiki_default(self, fake_report, consumer, expected): @@ -337,7 +314,7 @@ class TestConsumers: to the wiki_report call for each consumer. We compare against the call_args of the mock. """ - consumer.consume(PASSMSG) + consumer(PASSMSG) assert fake_report.call_count == 1 assert fake_report.call_args[1]['jobs'] == [71262] assert fake_report.call_args[1]['do_report'] == expected['report'] @@ -353,9 +330,9 @@ class TestConsumers: ( PRODRDB, { - 'report': False, + 'report': True, 'oqah': 'openqa.fedoraproject.org', - 'rdburl': 'http://localhost:5001/api/v2.0/' + 'rdburl': 'http://resultsdb01.qa.fedoraproject.org/resultsdb_api/api/v2.0/' } ), ( @@ -363,14 +340,14 @@ class TestConsumers: { 'report': False, 'oqah': 'openqa.stg.fedoraproject.org', - 'rdburl': 'http://localhost:5001/api/v2.0/' + 'rdburl': 'http://resultsdb-stg01.qa.fedoraproject.org/resultsdb_api/api/v2.0/' } ), ( TESTRDB, { - 'report': True, - 'oqah': 'openqa.fedoraproject.org', + 'report': False, + 'oqah': 'localhost', 'rdburl': 'http://localhost:5001/api/v2.0/' } ), @@ -382,7 +359,7 @@ class TestConsumers: same as test_wiki_default; the parametrization tuples specify the expected resultsdb_report args for each consumer. """ - consumer.consume(PASSMSG) + consumer(PASSMSG) assert fake_report.call_count == 1 assert fake_report.call_args[1]['jobs'] == [71262] assert fake_report.call_args[1]['do_report'] == expected['report'] @@ -390,57 +367,4 @@ class TestConsumers: assert fake_report.call_args[1]['resultsdb_url'] == expected['rdburl'] fake_report.reset_mock() - - @mock.patch('fedora_openqa.schedule.jobs_from_compose', return_value=('somecompose', []), autospec=True) - @mock.patch('fedora_openqa.report.resultsdb_report', autospec=True) - @mock.patch('fedora_openqa.report.wiki_report', autospec=True) - @pytest.mark.parametrize( - "consumers,setting,value,arg,expected", - [ - (PRODS, 'prod_oqa_hostname', 'testing', 'openqa_hostname', 'testing'), - (STGS, 'stg_oqa_hostname', 'testing', 'openqa_hostname', 'testing'), - (TESTS, 'test_oqa_hostname', 'testing', 'openqa_hostname', 'testing'), - # openqa_baseurl isn't used or passed by the schedulers - ([PRODWIKI, PRODRDB], 'prod_oqa_baseurl', 'https://test.ing', 'openqa_baseurl', 'https://test.ing'), - ([STGWIKI, STGRDB], 'stg_oqa_baseurl', 'https://test.ing', 'openqa_baseurl', 'https://test.ing'), - (TESTS, 'test_oqa_baseurl', 'https://test.ing', 'openqa_baseurl', 'https://test.ing'), - ([PRODWIKI], 'prod_wiki_hostname', 'testing', 'wiki_hostname', 'testing'), - ([STGWIKI], 'stg_wiki_hostname', 'testing', 'wiki_hostname', 'testing'), - ([TESTWIKI], 'test_wiki_hostname', 'testing', 'wiki_hostname', 'testing'), - ([PRODWIKI], 'prod_wiki_report', 'true', 'do_report', True), - ([STGWIKI], 'stg_wiki_report', 'true', 'do_report', True), - ([TESTWIKI], 'test_wiki_report', 'true', 'do_report', True), - ([PRODRDB], 'prod_rdb_url', 'https://test.ing', 'resultsdb_url', 'https://test.ing'), - ([STGRDB], 'stg_rdb_url', 'https://test.ing', 'resultsdb_url', 'https://test.ing'), - ([TESTRDB], 'test_rdb_url', 'https://test.ing', 'resultsdb_url', 'https://test.ing'), - ([PRODRDB], 'prod_rdb_report', 'true', 'do_report', True), - ([STGRDB], 'stg_rdb_report', 'true', 'do_report', True), - ([TESTRDB], 'test_rdb_report', 'true', 'do_report', True), - ] - ) - def test_configs(self, fake_wiki, fake_rdb, fake_sched, consumers, setting, value, arg, expected): - """Test configuration settings are properly respected by all - consumers. The parametrization tuples specify an iterable of - consumers, a config setting name in the 'consumers' section, - the value to which it should be set, the name of the arg whose - value should be affected by the setting, and the value the arg - should get. We mock all three of the functions that the three - different consumers call, and each time, we just find the one - whose call_count is 1 to know which one got hit, then we check - the arg. - """ - backup = fedora_openqa.consumer.CONFIG.get('consumers', setting) - fedora_openqa.consumer.CONFIG.set('consumers', setting, value) - for consumer in consumers: - for fake in (fake_wiki, fake_rdb, fake_sched): - fake.reset_mock() - if isinstance(consumer, fedora_openqa.consumer.OpenQAScheduler): - consumer.consume(FINISHEDCOMPOSE) - else: - consumer.consume(PASSMSG) - # figure out which mock to check the calls for - fake = next(fake for fake in (fake_wiki, fake_rdb, fake_sched) if fake.call_count == 1) - assert fake.call_args[1][arg] == expected - fedora_openqa.consumer.CONFIG.set('consumers', setting, backup) - # vim: set textwidth=120 ts=8 et sw=4: