mirror of https://github.com/ansible/ansible.git
Replace incidental_inventory_aws_ec2 with intentional coverage (#77743)
* Add intentional test coverage for lib/ansible/plugins/inventory/__init__.py * Add intentional (integration) test coverage for lib/ansible/module_utils/common/network.py * Add ansible_release info test from https://github.com/ansible/ansible/pull/74673 ci_complete ci_coverage Co-authored-by: Rick Elrod <rick@elrod.me>pull/77883/head
parent
0f882d010f
commit
1eb7f71f0e
@ -0,0 +1,6 @@
|
||||
plugin: ansible.legacy.contructed_with_hostvars
|
||||
groups:
|
||||
host_var1_defined: host_var1 is defined
|
||||
keyed_groups:
|
||||
- key: host_var2
|
||||
prefix: host_var2
|
@ -0,0 +1,5 @@
|
||||
all:
|
||||
hosts:
|
||||
host1:
|
||||
host_var1: 'defined'
|
||||
host_var2: 'defined'
|
@ -0,0 +1,44 @@
|
||||
# Copyright (c) 2022 Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = '''
|
||||
name: constructed_with_hostvars
|
||||
options:
|
||||
plugin:
|
||||
description: the load name of the plugin
|
||||
extends_documentation_fragment:
|
||||
- constructed
|
||||
'''
|
||||
|
||||
from ansible.errors import AnsibleParserError
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
||||
|
||||
|
||||
class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||
|
||||
NAME = 'constructed_with_hostvars'
|
||||
|
||||
def verify_file(self, path):
|
||||
return super(InventoryModule, self).verify_file(path) and path.endswith(('constructed.yml', 'constructed.yaml'))
|
||||
|
||||
def parse(self, inventory, loader, path, cache=True):
|
||||
super(InventoryModule, self).parse(inventory, loader, path, cache)
|
||||
config = self._read_config_data(path)
|
||||
|
||||
strict = self.get_option('strict')
|
||||
try:
|
||||
for host in inventory.hosts:
|
||||
hostvars = {}
|
||||
|
||||
# constructed groups based on conditionals
|
||||
self._add_host_to_composed_groups(self.get_option('groups'), hostvars, host, strict=strict, fetch_hostvars=True)
|
||||
|
||||
# constructed groups based variable values
|
||||
self._add_host_to_keyed_groups(self.get_option('keyed_groups'), hostvars, host, strict=strict, fetch_hostvars=True)
|
||||
|
||||
except Exception as e:
|
||||
raise AnsibleParserError("failed to parse %s: %s " % (to_native(path), to_native(e)), orig_exc=e)
|
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright: (c) 2021, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.common.network import to_subnet
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(argument_spec=dict(
|
||||
subnet=dict(),
|
||||
))
|
||||
|
||||
subnet = module.params['subnet']
|
||||
|
||||
if subnet is not None:
|
||||
split_addr = subnet.split('/')
|
||||
if len(split_addr) != 2:
|
||||
module.fail_json("Invalid CIDR notation: expected a subnet mask (e.g. 10.0.0.0/32)")
|
||||
module.exit_json(resolved=to_subnet(split_addr[0], split_addr[1]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,10 @@
|
||||
- hosts: testhost
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- test_network:
|
||||
subnet: "10.0.0.2/24"
|
||||
register: subnet
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- subnet.resolved == "10.0.0.0/24"
|
@ -0,0 +1,2 @@
|
||||
shippable/posix/group1
|
||||
context/target
|
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright: (c) 2021, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: ansible_release
|
||||
short_description: Get ansible_release info from module_utils
|
||||
description: Get ansible_release info from module_utils
|
||||
author:
|
||||
- Ansible Project
|
||||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
#
|
||||
'''
|
||||
|
||||
RETURN = r'''
|
||||
#
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ansible_release import __version__, __author__, __codename__
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(argument_spec={})
|
||||
result = {
|
||||
'version': __version__,
|
||||
'author': __author__,
|
||||
'codename': __codename__,
|
||||
}
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,9 @@
|
||||
- name: Get module_utils ansible_release vars
|
||||
ansible_release:
|
||||
register: ansible_release
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- ansible_release['version'][0]|int != 0
|
||||
- ansible_release['author'] == 'Ansible, Inc.'
|
||||
- ansible_release['codename']|length > 0
|
Loading…
Reference in New Issue