Merge "Do not use stevedore namespase as a prefix for class FQNs"
This commit is contained in:
commit
420f7e7a23
|
@ -53,7 +53,6 @@ class PluginLoader(object):
|
|||
LOG.warning(_LW("Entry-point 'name' {name} is invalid").format(
|
||||
name=name))
|
||||
return
|
||||
name = "%s.%s" % (self.namespace, name)
|
||||
name_map.setdefault(name, []).append(dist_name)
|
||||
if dist_name in self.packages:
|
||||
package = self.packages[dist_name]
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
# under the License.
|
||||
|
||||
import inspect
|
||||
import warnings
|
||||
import weakref
|
||||
|
||||
import debtcollector
|
||||
import semantic_version
|
||||
import six
|
||||
from yaql.language import specs
|
||||
|
@ -188,6 +190,24 @@ class MuranoPackage(dsl_types.MuranoPackage, dslmeta.MetaProvider):
|
|||
try:
|
||||
return referenced_package.find_class(name, False)
|
||||
except exceptions.NoClassFound:
|
||||
if name.startswith('io.murano.extensions'):
|
||||
try:
|
||||
short_name = name.replace(
|
||||
'io.murano.extensions.', '', 1)
|
||||
result = referenced_package.find_class(
|
||||
short_name, False)
|
||||
warnings.simplefilter("once")
|
||||
msg = ("Plugin %(name)s was not found, but a "
|
||||
"%(shorter_name)s was found instead and "
|
||||
"will be used. This could be caused by "
|
||||
"recent change in plugin naming scheme. If "
|
||||
"you are developing applications targeting "
|
||||
"this plugin consider changing its name" %
|
||||
{'name': name, 'shorter_name': short_name})
|
||||
debtcollector.deprecate(msg)
|
||||
return result
|
||||
except exceptions.NoClassFound:
|
||||
pass
|
||||
pkgs_for_search.append(referenced_package)
|
||||
continue
|
||||
raise exceptions.NoClassFound(
|
||||
|
|
|
@ -42,9 +42,9 @@ class PluginLoaderTest(base.MuranoTestCase):
|
|||
loaded_pkg = list(test_obj.packages.values())[0]
|
||||
self.assertIsInstance(loaded_pkg,
|
||||
extensions_loader.PackageDefinition)
|
||||
self.assertEqual('test.namespace.Test',
|
||||
self.assertEqual('Test',
|
||||
list(loaded_pkg.classes.keys())[0])
|
||||
result = {'test.namespace.Test': list(test_obj.packages.keys())}
|
||||
result = {'Test': list(test_obj.packages.keys())}
|
||||
self.assertEqual(result,
|
||||
name_map)
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
Name: TestFindClass
|
||||
|
||||
Methods:
|
||||
testFindClassWithPrefix:
|
||||
Body:
|
||||
- new('io.murano.extensions.io.murano.test.TestFixture')
|
||||
|
||||
testFindClassShortName:
|
||||
Body:
|
||||
- new('io.murano.test.TestFixture')
|
||||
|
||||
testClassWithPrefixNotFound:
|
||||
Body:
|
||||
- new('io.murano.extensions.io.murano.test.TestFixture1')
|
|
@ -0,0 +1,51 @@
|
|||
# coding: utf-8
|
||||
# Copyright (c) 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
import warnings
|
||||
|
||||
from murano.dsl import exceptions
|
||||
from murano.tests.unit.dsl.foundation import object_model as om
|
||||
from murano.tests.unit.dsl.foundation import test_case
|
||||
|
||||
|
||||
class TestFindClass(test_case.DslTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFindClass, self).setUp()
|
||||
self._runner = self.new_runner(om.Object('TestFindClass'))
|
||||
|
||||
def test_find_class_with_prefix(self):
|
||||
with warnings.catch_warnings(record=True) as capture:
|
||||
self.assertIsNone(self._runner.testFindClassWithPrefix())
|
||||
self.assertEqual(DeprecationWarning, capture[-1].category)
|
||||
observed = capture[-1].message
|
||||
expected = ("Plugin io.murano.extensions.io.murano.test.TestFixture "
|
||||
"was not found, but a io.murano.test.TestFixture was "
|
||||
"found instead and will be used. This could be caused by "
|
||||
"recent change in plugin naming scheme. If you are "
|
||||
"developing applications targeting this plugin consider "
|
||||
"changing its name")
|
||||
self.assertEqual(expected, six.text_type(observed))
|
||||
|
||||
def test_find_class_short_name(self):
|
||||
self.assertIsNone(self._runner.testFindClassShortName())
|
||||
|
||||
def test_class_with_prefix_not_found(self):
|
||||
observed = self.assertRaises(exceptions.NoClassFound,
|
||||
self._runner.testClassWithPrefixNotFound)
|
||||
expected = ('Class "io.murano.extensions.io.murano.test.TestFixture1" '
|
||||
'is not found in io.murano/0.0.0, tests/0.0.0')
|
||||
self.assertEqual(expected, six.text_type(observed))
|
|
@ -21,6 +21,7 @@ jsonpatch>=1.1 # BSD
|
|||
keystonemiddleware!=4.1.0,!=4.5.0,>=4.0.0 # Apache-2.0
|
||||
testtools>=1.4.0 # MIT
|
||||
yaql>=1.1.0 # Apache 2.0 License
|
||||
debtcollector>=1.2.0 # Apache-2.0
|
||||
|
||||
# For paste.util.template used in keystone.common.template
|
||||
Paste # MIT
|
||||
|
|
Loading…
Reference in New Issue