mirror of https://github.com/ansible/ansible.git
Fix plugin names when loading all plugins. (#59950)
* Fix plugin names when loading all plugins. Add an integration test to verify plugin __package__ and __name__ are correct. * Make sure filter and test names are unique. * Remove __package__ test. On Python 2.x __package__ is not set, but it is on Python 3.x.pull/60305/head
parent
d3624cf4a4
commit
3777c2e93d
@ -0,0 +1 @@
|
||||
shippable/posix/group1
|
@ -0,0 +1,15 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
def filter_name(a):
|
||||
return __name__
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
def filters(self):
|
||||
filters = {
|
||||
'filter_name': filter_name,
|
||||
}
|
||||
|
||||
return filters
|
@ -0,0 +1,9 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
def run(self, terms, variables, **kwargs):
|
||||
return [__name__]
|
@ -0,0 +1,11 @@
|
||||
- set_fact:
|
||||
filter_name: "{{ 1 | filter_name }}"
|
||||
lookup_name: "{{ lookup('lookup_name') }}"
|
||||
test_name_ok: "{{ 1 is test_name_ok }}"
|
||||
|
||||
- assert:
|
||||
that:
|
||||
# filter names are prefixed with a unique hash value to prevent shadowing of other plugins
|
||||
- filter_name | regex_search('^ansible\.plugins\.filter\.[0-9]+_test_filter$')
|
||||
- lookup_name == 'ansible.plugins.lookup.lookup_name'
|
||||
- test_name_ok
|
@ -0,0 +1,16 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def test_name_ok(value):
|
||||
# test names are prefixed with a unique hash value to prevent shadowing of other plugins
|
||||
return bool(re.match(r'^ansible\.plugins\.test\.[0-9]+_test_test$', __name__))
|
||||
|
||||
|
||||
class TestModule:
|
||||
def tests(self):
|
||||
return {
|
||||
'test_name_ok': test_name_ok,
|
||||
}
|
Loading…
Reference in New Issue