Skip to content

Commit

Permalink
move warnings emitting for deprecated util plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
rutsky committed Feb 8, 2016
1 parent 1d432b9 commit 9f8c901
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 8 deletions.
55 changes: 53 additions & 2 deletions master/buildbot/plugins/db.py
Expand Up @@ -94,6 +94,41 @@ def value(self):
return self._plugin_entry.value


class _DeprecatedPluginEntry(_PluginEntry):
"""Plugin entry that emits warnings when it's value is requested."""

def __init__(self, compat_name, new_name, plugin_entry):
assert isinstance(plugin_entry, _PluginEntry)
self._plugin_entry = plugin_entry
self._compat_name = compat_name
self._new_name = new_name

def load(self):
self._plugin_entry.load()

@property
def group(self):
return self._plugin_entry.group

@property
def name(self):
return self._plugin_entry.name

@property
def info(self):
return self._plugin_entry.info

@property
def value(self):
reportDeprecatedWorkerNameUsage(
"'{group}.{compat_name}' is deprecated, "
"use '{group}.{new_name}' instead".format(
group=self.group,
compat_name=self._compat_name,
new_name=self._new_name))
return self._plugin_entry.value


class _NSNode(object):
# pylint: disable=W0212

Expand Down Expand Up @@ -377,12 +412,28 @@ def add_namespace(self, namespace, interface=None, check_extras=True,
('LibVirtSlave', 'LibVirtWorker'),
('OpenStackLatentBuildSlave', 'OpenStackLatentWorker'),
]
for old_name, new_name in old_new_names:
for compat_name, new_name in old_new_names:
buildslave_ns._tree.add(
old_name, worker_ns._tree._children[new_name])
compat_name, worker_ns._tree._children[new_name])

tempo = self._namespaces[namespace]

elif namespace == 'util':
tempo = _Plugins(namespace, interface, check_extras)

# Handle deprecated plugins names in util namespace
old_new_names = [
('SlaveLock', 'WorkerLock'),
('enforceChosenSlave', 'enforceChosenWorker'),
('BuildslaveChoiceParameter', 'WorkerChoiceParameter'),
]
for compat_name, new_name in old_new_names:
entry = tempo._tree._get(new_name)
assert isinstance(entry, _PluginEntry)
proxy_entry = _DeprecatedPluginEntry(
compat_name, new_name, entry)
tempo._tree.add(compat_name, proxy_entry)

else:
tempo = _Plugins(namespace, interface, check_extras)

Expand Down
46 changes: 46 additions & 0 deletions master/buildbot/test/integration/test_worker_transition.py
Expand Up @@ -15,6 +15,7 @@

import mock
import os
import re

import buildbot.worker

Expand Down Expand Up @@ -242,3 +243,48 @@ def test_api_import(self):

# Access of old-named workers through new API is an error.
self.assertRaises(AttributeError, lambda: worker_ns.BuildSlave)

def test_plugins_util_SlaveLock_import(self):
from buildbot.plugins import util

with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
new = util.WorkerLock

with assertProducesWarning(
DeprecatedWorkerNameWarning,
message_pattern=re.escape(
"'buildbot.util.SlaveLock' is deprecated, "
"use 'buildbot.util.WorkerLock' instead")):
deprecated = util.SlaveLock

self.assertIdentical(new, deprecated)

def test_plugins_util_enforceChosenSlave_import(self):
from buildbot.plugins import util

with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
new = util.enforceChosenWorker

with assertProducesWarning(
DeprecatedWorkerNameWarning,
message_pattern=re.escape(
"'buildbot.util.enforceChosenSlave' is deprecated, "
"use 'buildbot.util.enforceChosenWorker' instead")):
deprecated = util.enforceChosenSlave

self.assertIdentical(new, deprecated)

def test_plugins_util_BuildslaveChoiceParameter_import(self):
from buildbot.plugins import util

with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
new = util.WorkerChoiceParameter

with assertProducesWarning(
DeprecatedWorkerNameWarning,
message_pattern=re.escape(
"'buildbot.util.BuildslaveChoiceParameter' is deprecated, "
"use 'buildbot.util.WorkerChoiceParameter' instead")):
deprecated = util.BuildslaveChoiceParameter

self.assertIdentical(new, deprecated)
40 changes: 40 additions & 0 deletions master/buildbot/test/unit/test_plugins.py
Expand Up @@ -18,6 +18,7 @@
"""

import mock
import re

import buildbot.plugins.db

Expand Down Expand Up @@ -265,6 +266,11 @@ def __init__(self, name, value):
SimpleFakeEntry('thirdparty', ClassWithInterface),
SimpleFakeEntry('deep.thirdparty', ClassWithInterface),
],
'buildbot.util': [
SimpleFakeEntry('WorkerLock', ClassWithInterface),
SimpleFakeEntry('enforceChosenWorker', ClassWithInterface),
SimpleFakeEntry('WorkerChoiceParameter', ClassWithInterface),
],
}


Expand All @@ -284,6 +290,7 @@ def setUp(self):
provide_worker_fake_entries):
self.worker_ns = db.get_plugins('worker')
self.buildslave_ns = db.get_plugins('buildslave')
self.util_ns = db.get_plugins('util')

def test_new_api(self):
with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
Expand Down Expand Up @@ -357,3 +364,36 @@ def test_new_api_thirdparty_deep(self):
with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
self.assertTrue(
self.worker_ns.deep.newthirdparty is ClassWithInterface)

def test_util_SlaveLock_import(self):
with assertProducesWarning(
DeprecatedWorkerNameWarning,
message_pattern=re.escape(
"'buildbot.util.SlaveLock' is deprecated, "
"use 'buildbot.util.WorkerLock' instead")):
deprecated = self.util_ns.SlaveLock

with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
self.assertIdentical(deprecated, ClassWithInterface)

def test_util_enforceChosenSlave_import(self):
with assertProducesWarning(
DeprecatedWorkerNameWarning,
message_pattern=re.escape(
"'buildbot.util.enforceChosenSlave' is deprecated, "
"use 'buildbot.util.enforceChosenWorker' instead")):
deprecated = self.util_ns.enforceChosenSlave

with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
self.assertIdentical(deprecated, ClassWithInterface)

def test_util_BuildslaveChoiceParameter_import(self):
with assertProducesWarning(
DeprecatedWorkerNameWarning,
message_pattern=re.escape(
"'buildbot.util.BuildslaveChoiceParameter' is deprecated, "
"use 'buildbot.util.WorkerChoiceParameter' instead")):
deprecated = self.util_ns.BuildslaveChoiceParameter

with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
self.assertIdentical(deprecated, ClassWithInterface)
6 changes: 0 additions & 6 deletions master/setup.py
Expand Up @@ -312,15 +312,11 @@ def define_plugin_entries(groups):
('buildbot.locks', [
'MasterLock',
'WorkerLock',
# deprecated, use WorkerLock
'SlaveLock'
]),
('buildbot.manhole', [
'AuthorizedKeysManhole', 'PasswordManhole', 'TelnetManhole']),
('buildbot.process.builder', [
'enforceChosenWorker',
# deprecated, use enforceChosenWorker
'enforceChosenSlave',
]),
('buildbot.process.factory', [
'BuildFactory', 'GNUAutoconf', 'CPAN', 'Distutils', 'Trial',
Expand All @@ -339,8 +335,6 @@ def define_plugin_entries(groups):
'IntParameter', 'NestedParameter', 'ParameterGroup',
'StringParameter', 'TextParameter', 'UserNameParameter',
'WorkerChoiceParameter',
# deprecated, use WorkerChoiceParameter
'BuildslaveChoiceParameter',
]),
('buildbot.process.results', [
'Results', 'SUCCESS', 'WARNINGS', 'FAILURE', 'SKIPPED',
Expand Down

0 comments on commit 9f8c901

Please sign in to comment.