#8940 add fedora-messaging wrapper
Merged 2 years ago by kevin. Opened 2 years ago by karsten.
karsten/releng fedora-messaging  into  master

@@ -0,0 +1,108 @@ 

+ #!/usr/bin/python3

+ 

+ # fedora-messaging replacement for fedmsg-logger

+ # implemented are only features required by releng/scripts/fedmsg-functions.sh 

+ 

+ # Copyright (c) 2019 Red Hat, Inc.

+ #

+ # Authors:

+ #       Karsten Hopp <karsten@redhat.com>

+ 

+ 

+ import argparse

+ import json

+ from fedora_messaging import api, message

+ 

+ parser = argparse.ArgumentParser(description="Process commandline parameters.")

+ parser.add_argument(

+     "--topic-prefix",

+     dest="topicprefix",

+     default="",

+     help="Prefix for the topic of each message sent.",

+ )

+ parser.add_argument(

+     "--modname",

+     dest="modname",

+     default="",

+     help="More control over the topic. Think org.fp.MODNAME.TOPIC.",

+ )

+ parser.add_argument(

+     "--message", dest="message", default="", help="The message to send."

+ )

+ parser.add_argument(

+     "--topic", dest="topic", default="", help="Think org.fedoraproject.dev.logger.TOPIC"

+ )

+ parser.add_argument(

+     "--json-input",

+     dest="jsoninput",

+     action="store_true",

+     help="Take each line of input as JSON.",

+ )

+ 

+ # unused options for backwards compatibility with fedmsg-logger scripts:

+ parser.add_argument(

+     "--cert-prefix",

+     dest="certprefix",

+     default="",

+     help="Specify a different cert from /etc/fedora-messaging/ (unused)",

+ )

+ parser.add_argument(

+     "--io-threads",

+     dest="io-threads",

+     type=int,

+     default=1,

+     help="Number of io threads for 0mq to use (unused)",

+ )

+ parser.add_argument(

+     "--config-filename", dest="config-filename", default="", help="Config file to use."

+ )

+ parser.add_argument(

+     "--print-config",

+     dest="print-config",

+     action="store_true",

+     help="Simply print out the configuration and exit. No action taken. (unused)",

+ )

+ parser.add_argument(

+     "--timeout",

+     dest="timeout",

+     type=int,

+     default=0,

+     help="Timeout in seconds for any blocking zmq operations. (unused)",

+ )

+ parser.add_argument(

+     "--high-water-mark",

+     dest="high-water-mark",

+     type=int,

+     default=0,

+     help="Limit on the number of messages in the queue before blocking. (unused)",

+ )

+ parser.add_argument(

+     "--linger",

+     dest="linger",

+     type=int,

+     default=0,

+     help="Number of milliseconds to wait before timing out connections. (unused)",

+ )

+ 

+ args = parser.parse_args()

+ print(args)

+ print(args.topic)

+ 

+ if args.jsoninput:

+     import sys

+     msgstring=""

+     for line in sys.stdin:

+         msgstring += line

+     body = json.loads(msgstring)

+ elif args.message:

+     msgstring='{"log":"start","msg":"' +args.message+ '"}'

+     body = json.loads(msgstring)

+ 

+ wholetopic=args.topicprefix+args.modname+args.topic

+ msg = message.Message(

+     topic=wholetopic,

+     headers={u"niceness": u"very"},

+     body=body,

+ )

+ 

+ api.publish(msg)

@@ -0,0 +1,40 @@ 

+ # fedora-messaging.sh

+ #

+ # This is a bash shell script that is meant to be sourced by other scripts

+ # and aims to deliver functions common to sending messages to 

+ # fedora-messaging[0] in rel-eng shell scripts.

+ #

+ # [0] - https://github.com/fedora-infra/fedora-messaging

+ 

+ 

+ # NOTES:

+ #  FIXME: This might be obsolete:

+ #   - Scripts that source this should define at least the following:

+ #       FEDMSG_MODNAME

+ #       FEDMSG_CERTPREFIX

+ #

+ #       Example:

+ #

+ #           FEDMSG_MODNAME="compose"

+ #           FEDMSG_CERTPREFIX="bodhi"

+ #           source ./scripts/fedora-messaging.sh

+ #

+ #           fedmsg_json_start=$(printf '{"log": "start", "branch": "f24", "arch": "x86_64"}')

+ #           send_fedora_message "${fedmsg_json_start}" f24 start

+ 

+ # This uses the new fedora-messaging bus:

+ LOGGER=./fedora-messaging-logger

+ 

+ function send_fedora_message()

+ {

+     jsoninput="${1}"

+     dist="${2}"

+     topic="${3}"

+ 

+     echo ${jsoninput} | $LOGGER \

+         --cert-prefix ${FEDMSG_CERTPREFIX} \

+         --modname ${FEDMSG_MODNAME} \

+         --topic "${dist}.${topic}" \

+         --json-input

+ }

+ 

I'm not sure about the cert-prefix, do our services have their own certs for fedora-messaging ?
Right now this will be ignored , as well as other fedmsg-logger options that aren't used here.

Signed-off-by: Karsten Hopp karsten@redhat.com

1 new commit added

  • revert changes to fedmsg-functions.sh, move fedora-messaging code
2 years ago

Awesome. Looks pretty good to me (although I have not tested it).

Can you rebase?

rebased onto d968db7384356ecd252f6d8908a31acec8c83143

2 years ago

rebased onto 90daad5

2 years ago

@kevin can this get merged, then ?

Sure! lets try it...

Pull-Request has been merged by kevin

2 years ago