From fdf94668fea9436b4041446b04c0650351748810 Mon Sep 17 00:00:00 2001 From: chadmf Date: Thu, 28 Mar 2024 19:03:43 -0500 Subject: [PATCH 01/13] WIP commit for AAP-22242 to add OpenShift Virtualization Inventory source option --- awx/main/models/inventory.py | 12 ++++++++++++ awx_collection/plugins/modules/inventory_source.py | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 228cef7d6c95..fe83423e9aed 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -933,6 +933,8 @@ class InventorySourceOptions(BaseModel): ('controller', _('Red Hat Ansible Automation Platform')), ('insights', _('Red Hat Insights')), ('terraform', _('Terraform State')), + ('openshift_virtualization', _('OpenShift Virtualization')), + ] # From the options of the Django management base command @@ -1693,6 +1695,16 @@ class insights(PluginFileInjector): use_fqcn = True +class openshift_virtualization(PluginFileInjector): + plugin_name = 'openshift_virtualization' + base_injector = 'template' + namespace = 'kubevirt' + collection = 'core' + downstream_namespace = 'redhat' + downstream_collection = 'openshift_virtualization' + use_fqcn = True + + class constructed(PluginFileInjector): plugin_name = 'constructed' namespace = 'ansible' diff --git a/awx_collection/plugins/modules/inventory_source.py b/awx_collection/plugins/modules/inventory_source.py index 216ebce3d8aa..738bf11bfd81 100644 --- a/awx_collection/plugins/modules/inventory_source.py +++ b/awx_collection/plugins/modules/inventory_source.py @@ -42,7 +42,7 @@ source: description: - The source to use for this group. - choices: [ "scm", "ec2", "gce", "azure_rm", "vmware", "satellite6", "openstack", "rhv", "controller", "insights", "terraform" ] + choices: [ "scm", "ec2", "gce", "azure_rm", "vmware", "satellite6", "openstack", "rhv", "controller", "insights", "terraform", "openshift_virtualization" ] type: str source_path: description: @@ -170,7 +170,7 @@ def main(): # # How do we handle manual and file? The controller does not seem to be able to activate them # - source=dict(choices=["scm", "ec2", "gce", "azure_rm", "vmware", "satellite6", "openstack", "rhv", "controller", "insights", "terraform"]), + source=dict(choices=["scm", "ec2", "gce", "azure_rm", "vmware", "satellite6", "openstack", "rhv", "controller", "insights", "terraform", "openshift_virtualization"]), source_path=dict(), source_vars=dict(type='dict'), enabled_var=dict(), From 162ebfb9a1fdbb28cc32a9b2027eed3ffb252fa9 Mon Sep 17 00:00:00 2001 From: chadmf Date: Fri, 29 Mar 2024 14:32:44 -0500 Subject: [PATCH 02/13] UI updates for AAP-22242 --- .../Inventory/InventorySourceAdd/InventorySourceAdd.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/awx/ui/src/screens/Inventory/InventorySourceAdd/InventorySourceAdd.test.js b/awx/ui/src/screens/Inventory/InventorySourceAdd/InventorySourceAdd.test.js index bfc572a4e83d..6627dccec8fd 100644 --- a/awx/ui/src/screens/Inventory/InventorySourceAdd/InventorySourceAdd.test.js +++ b/awx/ui/src/screens/Inventory/InventorySourceAdd/InventorySourceAdd.test.js @@ -56,6 +56,7 @@ describe('', () => { ['satellite6', 'Red Hat Satellite 6'], ['openstack', 'OpenStack'], ['rhv', 'Red Hat Virtualization'], + ['openshift_virtualization', 'Red Hat OpenShift Virtualization'], ['controller', 'Red Hat Ansible Automation Platform'], ], }, From 6022501d56da115af60c5899910c9d826af6954b Mon Sep 17 00:00:00 2001 From: chadmf Date: Fri, 29 Mar 2024 15:53:32 -0500 Subject: [PATCH 03/13] added UI elements for AAP-22242 --- .../OpenShiftVirtualizationSubForm.js | 60 +++++++++++++++++ .../OpenShiftVirtualizationSubForm.test.js | 65 +++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js create mode 100644 awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.test.js diff --git a/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js b/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js new file mode 100644 index 000000000000..38f57e3ceb5a --- /dev/null +++ b/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js @@ -0,0 +1,60 @@ +import React, { useCallback } from 'react'; +import { useField, useFormikContext } from 'formik'; +import { t } from '@lingui/macro'; +import { useConfig } from 'contexts/Config'; +import getDocsBaseUrl from 'util/getDocsBaseUrl'; +import CredentialLookup from 'components/Lookup/CredentialLookup'; +import { required } from 'util/validators'; +import { + OptionsField, + VerbosityField, + EnabledVarField, + EnabledValueField, + HostFilterField, + SourceVarsField, +} from './SharedFields'; +import getHelpText from '../Inventory.helptext'; + +const VirtualizationSubForm = ({ autoPopulateCredential }) => { + const helpText = getHelpText(); + const { setFieldValue, setFieldTouched } = useFormikContext(); + const [credentialField, credentialMeta, credentialHelpers] = + useField('credential'); + const config = useConfig(); + + const handleCredentialUpdate = useCallback( + (value) => { + setFieldValue('credential', value); + setFieldTouched('credential', true, false); + }, + [setFieldValue, setFieldTouched] + ); + + const docsBaseUrl = getDocsBaseUrl(config); + return ( + <> + credentialHelpers.setTouched()} + onChange={handleCredentialUpdate} + value={credentialField.value} + required + autoPopulate={autoPopulateCredential} + validate={required(t`Select a value for this field`)} + /> + + + + + + + + ); +}; + +export default OpenShiftVirtualizationSubForm; diff --git a/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.test.js b/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.test.js new file mode 100644 index 000000000000..6b289600a98c --- /dev/null +++ b/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.test.js @@ -0,0 +1,65 @@ +import React from 'react'; +import { act } from 'react-dom/test-utils'; +import { Formik } from 'formik'; +import { CredentialsAPI } from 'api'; +import { mountWithContexts } from '../../../../../testUtils/enzymeHelpers'; +import VirtualizationSubForm from './VirtualizationSubForm'; + +jest.mock('../../../../api'); + +const initialValues = { + credential: null, + overwrite: false, + overwrite_vars: false, + source_path: '', + source_project: null, + source_script: null, + source_vars: '---\n', + update_cache_timeout: 0, + update_on_launch: true, + verbosity: 1, +}; + +describe('', () => { + let wrapper; + + beforeEach(async () => { + CredentialsAPI.read.mockResolvedValue({ + data: { count: 0, results: [] }, + }); + + await act(async () => { + wrapper = mountWithContexts( + + + + ); + }); + }); + + afterAll(() => { + jest.clearAllMocks(); + }); + + test('should render subform fields', () => { + expect(wrapper.find('FormGroup[label="Credential"]')).toHaveLength(1); + expect(wrapper.find('FormGroup[label="Verbosity"]')).toHaveLength(1); + expect(wrapper.find('FormGroup[label="Update options"]')).toHaveLength(1); + expect( + wrapper.find('FormGroup[label="Cache timeout (seconds)"]') + ).toHaveLength(1); + expect( + wrapper.find('VariablesField[label="Source variables"]') + ).toHaveLength(1); + }); + + test('should make expected api calls', () => { + expect(CredentialsAPI.read).toHaveBeenCalledTimes(1); + expect(CredentialsAPI.read).toHaveBeenCalledWith({ + credential_type__namespace: 'rhv', + order_by: 'name', + page: 1, + page_size: 5, + }); + }); +}); From 9d8718f402bc946e4728d85d58b6b8f115f26201 Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:34:57 -0400 Subject: [PATCH 04/13] Fix various things (see description for detail) - generate migration for adding ovirt inventory source - fix python and UI linting issue - make the UI actually work --- ...4_alter_inventorysource_source_and_more.py | 61 +++++++++++++++++++ awx/main/models/inventory.py | 1 - .../InventorySourceAdd.test.js | 5 +- .../Inventory/shared/Inventory.helptext.js | 6 +- .../Inventory/shared/InventorySourceForm.js | 10 +++ .../OpenShiftVirtualizationSubForm.js | 8 ++- .../shared/InventorySourceSubForms/index.js | 1 + 7 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 awx/main/migrations/0194_alter_inventorysource_source_and_more.py diff --git a/awx/main/migrations/0194_alter_inventorysource_source_and_more.py b/awx/main/migrations/0194_alter_inventorysource_source_and_more.py new file mode 100644 index 000000000000..d6f399d71c5a --- /dev/null +++ b/awx/main/migrations/0194_alter_inventorysource_source_and_more.py @@ -0,0 +1,61 @@ +# Generated by Django 4.2.10 on 2024-06-12 19:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0193_alter_notification_notification_type_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='inventorysource', + name='source', + field=models.CharField( + choices=[ + ('file', 'File, Directory or Script'), + ('constructed', 'Template additional groups and hostvars at runtime'), + ('scm', 'Sourced from a Project'), + ('ec2', 'Amazon EC2'), + ('gce', 'Google Compute Engine'), + ('azure_rm', 'Microsoft Azure Resource Manager'), + ('vmware', 'VMware vCenter'), + ('satellite6', 'Red Hat Satellite 6'), + ('openstack', 'OpenStack'), + ('rhv', 'Red Hat Virtualization'), + ('controller', 'Red Hat Ansible Automation Platform'), + ('insights', 'Red Hat Insights'), + ('terraform', 'Terraform State'), + ('openshift_virtualization', 'OpenShift Virtualization'), + ], + default=None, + max_length=32, + ), + ), + migrations.AlterField( + model_name='inventoryupdate', + name='source', + field=models.CharField( + choices=[ + ('file', 'File, Directory or Script'), + ('constructed', 'Template additional groups and hostvars at runtime'), + ('scm', 'Sourced from a Project'), + ('ec2', 'Amazon EC2'), + ('gce', 'Google Compute Engine'), + ('azure_rm', 'Microsoft Azure Resource Manager'), + ('vmware', 'VMware vCenter'), + ('satellite6', 'Red Hat Satellite 6'), + ('openstack', 'OpenStack'), + ('rhv', 'Red Hat Virtualization'), + ('controller', 'Red Hat Ansible Automation Platform'), + ('insights', 'Red Hat Insights'), + ('terraform', 'Terraform State'), + ('openshift_virtualization', 'OpenShift Virtualization'), + ], + default=None, + max_length=32, + ), + ), + ] diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index fe83423e9aed..58e8c33c3d57 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -934,7 +934,6 @@ class InventorySourceOptions(BaseModel): ('insights', _('Red Hat Insights')), ('terraform', _('Terraform State')), ('openshift_virtualization', _('OpenShift Virtualization')), - ] # From the options of the Django management base command diff --git a/awx/ui/src/screens/Inventory/InventorySourceAdd/InventorySourceAdd.test.js b/awx/ui/src/screens/Inventory/InventorySourceAdd/InventorySourceAdd.test.js index 6627dccec8fd..3af847808f1e 100644 --- a/awx/ui/src/screens/Inventory/InventorySourceAdd/InventorySourceAdd.test.js +++ b/awx/ui/src/screens/Inventory/InventorySourceAdd/InventorySourceAdd.test.js @@ -56,7 +56,10 @@ describe('', () => { ['satellite6', 'Red Hat Satellite 6'], ['openstack', 'OpenStack'], ['rhv', 'Red Hat Virtualization'], - ['openshift_virtualization', 'Red Hat OpenShift Virtualization'], + [ + 'openshift_virtualization', + 'Red Hat OpenShift Virtualization', + ], ['controller', 'Red Hat Ansible Automation Platform'], ], }, diff --git a/awx/ui/src/screens/Inventory/shared/Inventory.helptext.js b/awx/ui/src/screens/Inventory/shared/Inventory.helptext.js index 2be9d8b54d5d..a77dc52c9908 100644 --- a/awx/ui/src/screens/Inventory/shared/Inventory.helptext.js +++ b/awx/ui/src/screens/Inventory/shared/Inventory.helptext.js @@ -23,6 +23,8 @@ const ansibleDocUrls = { 'https://docs.ansible.com/ansible/latest/collections/ansible/builtin/constructed_inventory.html', terraform: 'https://github.com/ansible-collections/cloud.terraform/blob/main/docs/cloud.terraform.terraform_state_inventory.rst', + openshift_virtualization: + 'https://kubevirt.io/kubevirt.core/latest/plugins/kubevirt.html', }; const getInventoryHelpTextStrings = () => ({ @@ -121,7 +123,7 @@ const getInventoryHelpTextStrings = () => ({
{value && (
- {t`If you want the Inventory Source to update on launch , click on Update on Launch, + {t`If you want the Inventory Source to update on launch , click on Update on Launch, and also go to `} {value.name} {t`and click on Update Revision on Launch.`} @@ -140,7 +142,7 @@ const getInventoryHelpTextStrings = () => ({
{value && (
- {t`If you want the Inventory Source to update on launch , click on Update on Launch, + {t`If you want the Inventory Source to update on launch , click on Update on Launch, and also go to `} {value.name} {t`and click on Update Revision on Launch`} diff --git a/awx/ui/src/screens/Inventory/shared/InventorySourceForm.js b/awx/ui/src/screens/Inventory/shared/InventorySourceForm.js index 06172d961a17..88c5a5072a8a 100644 --- a/awx/ui/src/screens/Inventory/shared/InventorySourceForm.js +++ b/awx/ui/src/screens/Inventory/shared/InventorySourceForm.js @@ -26,6 +26,7 @@ import { TerraformSubForm, VMwareSubForm, VirtualizationSubForm, + OpenShiftVirtualizationSubForm, } from './InventorySourceSubForms'; const buildSourceChoiceOptions = (options) => { @@ -231,6 +232,15 @@ const InventorySourceFormFields = ({ sourceOptions={sourceOptions} /> ), + openshift_virtualization: ( + + ), }[sourceField.value] } diff --git a/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js b/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js index 38f57e3ceb5a..b42281dc6c02 100644 --- a/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js +++ b/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js @@ -1,5 +1,6 @@ import React, { useCallback } from 'react'; import { useField, useFormikContext } from 'formik'; + import { t } from '@lingui/macro'; import { useConfig } from 'contexts/Config'; import getDocsBaseUrl from 'util/getDocsBaseUrl'; @@ -15,7 +16,7 @@ import { } from './SharedFields'; import getHelpText from '../Inventory.helptext'; -const VirtualizationSubForm = ({ autoPopulateCredential }) => { +const OpenShiftVirtualizationSubForm = ({ autoPopulateCredential }) => { const helpText = getHelpText(); const { setFieldValue, setFieldTouched } = useFormikContext(); const [credentialField, credentialMeta, credentialHelpers] = @@ -51,7 +52,10 @@ const VirtualizationSubForm = ({ autoPopulateCredential }) => { ); diff --git a/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/index.js b/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/index.js index 27bcf5a31556..3cd87cb7e591 100644 --- a/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/index.js +++ b/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/index.js @@ -9,3 +9,4 @@ export { default as ControllerSubForm } from './ControllerSubForm'; export { default as TerraformSubForm } from './TerraformSubForm'; export { default as VMwareSubForm } from './VMwareSubForm'; export { default as VirtualizationSubForm } from './VirtualizationSubForm'; +export { default as OpenShiftVirtualizationSubForm } from './OpenShiftVirtualizationSubForm'; From 28be12987b765e13f22d3bb7e2254178430e0cd7 Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:42:09 -0400 Subject: [PATCH 05/13] Fix collection sanity test --- .../plugins/modules/inventory_source.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/awx_collection/plugins/modules/inventory_source.py b/awx_collection/plugins/modules/inventory_source.py index 738bf11bfd81..76f1d4234eb2 100644 --- a/awx_collection/plugins/modules/inventory_source.py +++ b/awx_collection/plugins/modules/inventory_source.py @@ -42,7 +42,8 @@ source: description: - The source to use for this group. - choices: [ "scm", "ec2", "gce", "azure_rm", "vmware", "satellite6", "openstack", "rhv", "controller", "insights", "terraform", "openshift_virtualization" ] + choices: [ "scm", "ec2", "gce", "azure_rm", "vmware", "satellite6", "openstack", "rhv", "controller", "insights", "terraform", + "openshift_virtualization" ] type: str source_path: description: @@ -170,7 +171,22 @@ def main(): # # How do we handle manual and file? The controller does not seem to be able to activate them # - source=dict(choices=["scm", "ec2", "gce", "azure_rm", "vmware", "satellite6", "openstack", "rhv", "controller", "insights", "terraform", "openshift_virtualization"]), + source=dict( + choices=[ + "scm", + "ec2", + "gce", + "azure_rm", + "vmware", + "satellite6", + "openstack", + "rhv", + "controller", + "insights", + "terraform", + "openshift_virtualization", + ] + ), source_path=dict(), source_vars=dict(type='dict'), enabled_var=dict(), From ac4fec3479be1859c0e083b287b95d410c533dfc Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:45:42 -0400 Subject: [PATCH 06/13] Fix test_all_cloud_sources_covered --- awx/main/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/constants.py b/awx/main/constants.py index 115b0626043d..a12da39938fc 100644 --- a/awx/main/constants.py +++ b/awx/main/constants.py @@ -14,7 +14,7 @@ 'STANDARD_INVENTORY_UPDATE_ENV', ] -CLOUD_PROVIDERS = ('azure_rm', 'ec2', 'gce', 'vmware', 'openstack', 'rhv', 'satellite6', 'controller', 'insights', 'terraform') +CLOUD_PROVIDERS = ('azure_rm', 'ec2', 'gce', 'vmware', 'openstack', 'rhv', 'satellite6', 'controller', 'insights', 'terraform', 'openshift_virtualization') PRIVILEGE_ESCALATION_METHODS = [ ('sudo', _('Sudo')), ('su', _('Su')), From 1c400bbb10446657546e60660498b6c2eee27e56 Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Thu, 13 Jun 2024 14:09:30 -0400 Subject: [PATCH 07/13] switch to kubernetes_bearer_token for credential on UI --- .../InventorySourceSubForms/OpenShiftVirtualizationSubForm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js b/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js index b42281dc6c02..4f725c2522e2 100644 --- a/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js +++ b/awx/ui/src/screens/Inventory/shared/InventorySourceSubForms/OpenShiftVirtualizationSubForm.js @@ -35,7 +35,7 @@ const OpenShiftVirtualizationSubForm = ({ autoPopulateCredential }) => { return ( <> Date: Thu, 13 Jun 2024 14:10:08 -0400 Subject: [PATCH 08/13] questioning why we have so much validation... for credential of CLOUD_PROVIDER inventory source... --- awx/main/models/inventory.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 58e8c33c3d57..a4e80fa71557 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -1043,7 +1043,7 @@ def resolve_execution_environment(self): def cloud_credential_validation(source, cred): if not source: return None - if cred and source not in ('custom', 'scm'): + if cred and source not in ('custom', 'scm', 'openshift_virtualization'): # If a credential was provided, it's important that it matches # the actual inventory source being used (Amazon requires Amazon # credentials; Rackspace requires Rackspace credentials; etc...) @@ -1052,12 +1052,14 @@ def cloud_credential_validation(source, cred): # Allow an EC2 source to omit the credential. If Tower is running on # an EC2 instance with an IAM Role assigned, boto will use credentials # from the instance metadata instead of those explicitly provided. - elif source in CLOUD_PROVIDERS and source != 'ec2': + elif source in CLOUD_PROVIDERS and source not in ['ec2', 'openshift_virtualization']: return _('Credential is required for a cloud source.') elif source == 'custom' and cred and cred.credential_type.kind in ('scm', 'ssh', 'insights', 'vault'): return _('Credentials of type machine, source control, insights and vault are disallowed for custom inventory sources.') elif source == 'scm' and cred and cred.credential_type.kind in ('insights', 'vault'): return _('Credentials of type insights and vault are disallowed for scm inventory sources.') + elif source == 'openshift_virtualization' and cred and cred.credential_type.kind not in ('kubernetes'): + return _('Credentials of type kubernetes is requred for openshift_virtualization inventory sources.') return None def get_cloud_credential(self): From 31326f437bcc636a335eef25c267fd8cdd8a2cfa Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Thu, 13 Jun 2024 14:10:46 -0400 Subject: [PATCH 09/13] Add credential kind to source association for test --- awx/main/tests/functional/test_inventory_source_injectors.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/awx/main/tests/functional/test_inventory_source_injectors.py b/awx/main/tests/functional/test_inventory_source_injectors.py index 80bc5429c1d2..0df9a132260d 100644 --- a/awx/main/tests/functional/test_inventory_source_injectors.py +++ b/awx/main/tests/functional/test_inventory_source_injectors.py @@ -46,6 +46,8 @@ def generate_fake_var(element): def credential_kind(source): """Given the inventory source kind, return expected credential kind""" + if source == 'openshift_virtualization': + return 'kubernetes_bearer_token' return source.replace('ec2', 'aws') From 278fd59d052479ab99da92ff579af2500e4e1f4b Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Thu, 13 Jun 2024 14:57:24 -0400 Subject: [PATCH 10/13] Fix api-test --- .../data/inventory/plugins/openshift_virtualization/env.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 awx/main/tests/data/inventory/plugins/openshift_virtualization/env.json diff --git a/awx/main/tests/data/inventory/plugins/openshift_virtualization/env.json b/awx/main/tests/data/inventory/plugins/openshift_virtualization/env.json new file mode 100644 index 000000000000..a44de77b88cb --- /dev/null +++ b/awx/main/tests/data/inventory/plugins/openshift_virtualization/env.json @@ -0,0 +1,5 @@ +{ + "K8S_AUTH_HOST": "https://foo.invalid", + "K8S_AUTH_API_KEY": "fooo", + "K8S_AUTH_VERIFY_SSL": "False" +} From 575f48298fdcbb0b7f4d300082d5e17f90e68353 Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:43:05 -0400 Subject: [PATCH 11/13] Fix plugin name --- awx/main/models/inventory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index a4e80fa71557..998cda5e356c 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -1697,7 +1697,7 @@ class insights(PluginFileInjector): class openshift_virtualization(PluginFileInjector): - plugin_name = 'openshift_virtualization' + plugin_name = 'kubevirt' base_injector = 'template' namespace = 'kubevirt' collection = 'core' From bbb617ca6d503f0cc5cfd7f6e8840c3b25c4b080 Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Fri, 14 Jun 2024 11:48:47 -0400 Subject: [PATCH 12/13] Minor change --- awx/main/models/inventory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 998cda5e356c..2b96ed549f1f 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -1058,7 +1058,7 @@ def cloud_credential_validation(source, cred): return _('Credentials of type machine, source control, insights and vault are disallowed for custom inventory sources.') elif source == 'scm' and cred and cred.credential_type.kind in ('insights', 'vault'): return _('Credentials of type insights and vault are disallowed for scm inventory sources.') - elif source == 'openshift_virtualization' and cred and cred.credential_type.kind not in ('kubernetes'): + elif source == 'openshift_virtualization' and cred and cred.credential_type.kind != 'kubernetes': return _('Credentials of type kubernetes is requred for openshift_virtualization inventory sources.') return None From 2298920d83664f7446f01af8d16e4f1740dacf65 Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Fri, 14 Jun 2024 11:50:43 -0400 Subject: [PATCH 13/13] Add OPENSHIFT_VIRTUALIZATION_EXCLUDE_EMPTY_GROUPS fix ``` tools_awx_1 | 2024-06-14 15:39:23,424 ERROR [63b8bfcc] awx.main.tasks.jobs inventory_update 8 (running) Post run hook errored. tools_awx_1 | Traceback (most recent call last): tools_awx_1 | File "/awx_devel/awx/main/tasks/jobs.py", line 637, in run tools_awx_1 | self.post_run_hook(self.instance, status) tools_awx_1 | File "/awx_devel/awx/main/tasks/jobs.py", line 1669, in post_run_hook tools_awx_1 | if getattr(settings, '%s_EXCLUDE_EMPTY_GROUPS' % src.upper()): tools_awx_1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tools_awx_1 | File "/awx_devel/awx/conf/settings.py", line 540, in __getattr_without_cache__ tools_awx_1 | return getattr(self._wrapped, name) tools_awx_1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tools_awx_1 | File "/awx_devel/awx/conf/settings.py", line 441, in __getattr__ tools_awx_1 | return self._get_default(name) tools_awx_1 | ^^^^^^^^^^^^^^^^^^^^^^^ tools_awx_1 | File "/awx_devel/awx/conf/settings.py", line 415, in _get_default tools_awx_1 | return getattr(self.default_settings, name) tools_awx_1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tools_awx_1 | AttributeError: 'Settings' object has no attribute 'OPENSHIFT_VIRTUALIZATION_EXCLUDE_EMPTY_GROUPS' ``` --- awx/settings/defaults.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index d0fd7b115cad..93c6e6f60d1d 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -783,6 +783,11 @@ TERRAFORM_INSTANCE_ID_VAR = 'id' TERRAFORM_EXCLUDE_EMPTY_GROUPS = True +# ------------------------ +# OpenShift Virtualization +# ------------------------ +OPENSHIFT_VIRTUALIZATION_EXCLUDE_EMPTY_GROUPS = True + # --------------------- # ----- Custom ----- # ---------------------