Skip to content

Commit

Permalink
Merge pull request #234 from fedora-infra/feature/warn-if-no-plugin
Browse files Browse the repository at this point in the history
Feature/warn if no plugin
  • Loading branch information
ralphbean committed Mar 9, 2014
2 parents c4df21d + 9b3f65b commit 281439d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
5 changes: 4 additions & 1 deletion fedmsg/commands/tail.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def run(self):
self.config['mute'] = True self.config['mute'] = True


fedmsg.init(**self.config) fedmsg.init(**self.config)
fedmsg.meta.make_processors(**self.config)


# Build a message formatter # Build a message formatter
formatter = lambda d: d formatter = lambda d: d
Expand Down Expand Up @@ -149,6 +148,10 @@ def formatter(d):
if self.config['packages']: if self.config['packages']:
packages = set(map(str.strip, self.config['packages'].split(','))) packages = set(map(str.strip, self.config['packages'].split(',')))


# Only initialize this if we have to
if users or packages or self.config['terse']:
fedmsg.meta.make_processors(**self.config)

# Spin up a zmq.Poller and yield messages # Spin up a zmq.Poller and yield messages
for name, ep, topic, message in fedmsg.tail_messages(**self.config): for name, ep, topic, message in fedmsg.tail_messages(**self.config):
if exclusive_regexp.search(topic): if exclusive_regexp.search(topic):
Expand Down
9 changes: 8 additions & 1 deletion fedmsg/meta/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from fedmsg.meta.default import DefaultProcessor from fedmsg.meta.default import DefaultProcessor


import logging import logging
log = logging.getLogger("fedmsg")




class ProcessorsNotInitialized(Exception): class ProcessorsNotInitialized(Exception):
Expand Down Expand Up @@ -90,13 +91,19 @@ def make_processors(**config):
try: try:
processors.append(processor.load()(_, **config)) processors.append(processor.load()(_, **config))
except Exception as e: except Exception as e:
log = logging.getLogger("fedmsg")
log.warn("Failed to load %r processor." % processor.name) log.warn("Failed to load %r processor." % processor.name)
log.warn(str(e)) log.warn(str(e))


# This should always be last # This should always be last
processors.append(DefaultProcessor(_, **config)) processors.append(DefaultProcessor(_, **config))


# By default we have three builtin processors: Default, Logger, and
# Announce. If these are the only three, then we didn't find any
# externally provided ones. calls to msg2subtitle and msg2link likely will
# not work the way the user is expecting.
if len(processors) == 3:
log.warn("No fedmsg.meta plugins found. fedmsg.meta.msg2* crippled")



def msg2processor(msg, **config): def msg2processor(msg, **config):
""" For a given message return the text processor that can handle it. """ For a given message return the text processor that can handle it.
Expand Down
46 changes: 46 additions & 0 deletions fedmsg/tests/test_meta.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,6 +51,52 @@ def inner(self):
return wrapper return wrapper




def skip_if_fedmsg_meta_FI_is_present(f):
""" A test decorator that will skip if fedmsg_meta_fedora_infrastructure
is installed.
The presence of that module will screw up some tests.
"""
def _wrapper(self, *args, **kw):
try:
import fedmsg_meta_fedora_infrastructure
raise SkipTest("fedmsg_meta_FI is present")
except ImportError:
pass

return f(self, *args, **kw)

return make_decorator(f)(_wrapper)


class TestForWarning(unittest.TestCase):
def setUp(self):
dirname = os.path.abspath(os.path.dirname(__file__))
self.config = fedmsg.config.load_config(
filenames=[os.path.join(dirname, "fedmsg-test-config.py")],
invalidate_cache=True,
)
self.config['topic_prefix'] = 'org.fedoraproject'
self.config['topic_prefix_re'] = '^org\.fedoraproject\.(dev|stg|prod)'

@skip_if_fedmsg_meta_FI_is_present
def test_for_no_plugins(self):
""" Test that we print a warning if no plugin is installed """
messages = []

def mocked_warning(message):
messages.append(message)

expected = 'No fedmsg.meta plugins found. fedmsg.meta.msg2* crippled'
original = fedmsg.meta.log.warn
try:
fedmsg.meta.log.warn = mocked_warning
fedmsg.meta.make_processors(**self.config)
eq_(messages, [expected])
finally:
fedmsg.meta.log.warn = original


class Base(unittest.TestCase): class Base(unittest.TestCase):
msg = None msg = None
expected_title = None expected_title = None
Expand Down

0 comments on commit 281439d

Please sign in to comment.