From 2e2fe40d2a6a87eb6bbb31f33a92af174406ba9e Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Mon, 11 May 2020 22:45:19 -0400 Subject: [PATCH] Add options to ovirt inventory file (#4307) fixes schema differences from script add back in default groups from script change hostnames to reflect script add in some hostvars Generally allow giving plugin options from source variables allows testing with insecure connection with ovirt_insecure this is a behavior change from the script --- awx/main/models/inventory.py | 19 +++++++++++++++++++ .../inventory/plugins/rhv/files/ovirt.yml | 19 +++++++++++++++++++ .../test_inventory_source_injectors.py | 7 ++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 06fbd071e7..6e5ffce508 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -2500,6 +2500,25 @@ class rhv(PluginFileInjector): def script_name(self): return 'ovirt4.py' # exception + def inventory_as_dict(self, inventory_update, private_data_dir): + ret = super(rhv, self).inventory_as_dict(inventory_update, private_data_dir) + ret['ovirt_insecure'] = False # Default changed from script + # TODO: process strict option upstream + ret['compose'] = { + 'ansible_host': '(devices.values() | list)[0][0] if devices else None' + } + ret['keyed_groups'] = [] + for key in ('cluster', 'status'): + ret['keyed_groups'].append({'prefix': key, 'separator': '_', 'key': key}) + ret['keyed_groups'].append({'prefix': 'tag', 'separator': '_', 'key': 'tags'}) + ret['ovirt_hostname_preference'] = ['name', 'fqdn'] + source_vars = inventory_update.source_vars_dict + for key, value in source_vars.items(): + if key == 'plugin': + continue + ret[key] = value + return ret + class satellite6(PluginFileInjector): plugin_name = 'foreman' diff --git a/awx/main/tests/data/inventory/plugins/rhv/files/ovirt.yml b/awx/main/tests/data/inventory/plugins/rhv/files/ovirt.yml index 0c7dec7b16..67a94ae6de 100644 --- a/awx/main/tests/data/inventory/plugins/rhv/files/ovirt.yml +++ b/awx/main/tests/data/inventory/plugins/rhv/files/ovirt.yml @@ -1 +1,20 @@ +base_source_var: value_of_var +compose: + ansible_host: (devices.values() | list)[0][0] if devices else None +groups: + dev: '"dev" in tags' +keyed_groups: +- key: cluster + prefix: cluster + separator: _ +- key: status + prefix: status + separator: _ +- key: tags + prefix: tag + separator: _ +ovirt_hostname_preference: +- name +- fqdn +ovirt_insecure: false plugin: ovirt.ovirt.ovirt diff --git a/awx/main/tests/functional/test_inventory_source_injectors.py b/awx/main/tests/functional/test_inventory_source_injectors.py index 29b798cfd7..4e549e1be6 100644 --- a/awx/main/tests/functional/test_inventory_source_injectors.py +++ b/awx/main/tests/functional/test_inventory_source_injectors.py @@ -50,7 +50,6 @@ INI_TEST_VARS = { 'expand_hostvars': True, 'fail_on_errors': True }, - 'rhv': {}, # there are none 'tower': {}, # there are none 'vmware': { 'alias_pattern': "{{ config.foo }}", @@ -78,6 +77,12 @@ INI_TEST_VARS = { 'nest_tags': 'yes', 'suffix': '.ppt', 'prefer_ipv4': 'yes' + }, + 'rhv': { # options specific to the plugin + 'ovirt_insecure': False, + 'groups': { + 'dev': '"dev" in tags' + } } }