mirror of
https://github.com/ansible/awx.git
synced 2026-10-29 22:03:20 -02:30
Remove EE container after awx-manage inventory_import
inventory_import builds its own podman run command and omits --rm, unlike ansible-runner which always passes it. Each CLI import leaves an exited container behind, eventually filling disk. Related: AAPRFE-370
This commit is contained in:
@@ -75,7 +75,18 @@ class AnsibleInventoryLoader(object):
|
|||||||
self.verbosity = verbosity
|
self.verbosity = verbosity
|
||||||
|
|
||||||
def get_base_args(self):
|
def get_base_args(self):
|
||||||
bargs = ['podman', 'run', '--user=root', '--quiet']
|
"""
|
||||||
|
Build base Podman arguments for running ansible-inventory in a container.
|
||||||
|
|
||||||
|
Returns a list of command-line arguments for executing ansible-inventory
|
||||||
|
inside the default execution environment container. Includes volume mounts
|
||||||
|
for the inventory source, environment variables, and the --rm flag to
|
||||||
|
automatically remove the container after execution.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: Base command arguments for Podman container execution
|
||||||
|
"""
|
||||||
|
bargs = ['podman', 'run', '--rm', '--user=root', '--quiet']
|
||||||
bargs.extend(['-v', '{0}:{0}:Z'.format(self.source)])
|
bargs.extend(['-v', '{0}:{0}:Z'.format(self.source)])
|
||||||
for key, value in STANDARD_INVENTORY_UPDATE_ENV.items():
|
for key, value in STANDARD_INVENTORY_UPDATE_ENV.items():
|
||||||
bargs.extend(['-e', '{0}={1}'.format(key, value)])
|
bargs.extend(['-e', '{0}={1}'.format(key, value)])
|
||||||
|
|||||||
@@ -2,13 +2,15 @@
|
|||||||
# All Rights Reserved
|
# All Rights Reserved
|
||||||
|
|
||||||
# Python
|
# Python
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.management.base import CommandError
|
from django.core.management.base import CommandError
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.management.commands.inventory_import import Command
|
from awx.main.management.commands.inventory_import import AnsibleInventoryLoader, Command
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.inventory_import
|
@pytest.mark.inventory_import
|
||||||
@@ -34,3 +36,15 @@ class TestInvalidOptions:
|
|||||||
cmd.handle(inventory_id=42)
|
cmd.handle(inventory_id=42)
|
||||||
assert '--source' in str(err.value)
|
assert '--source' in str(err.value)
|
||||||
assert 'required' in str(err.value)
|
assert 'required' in str(err.value)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.inventory_import
|
||||||
|
def test_base_args_remove_container_on_exit():
|
||||||
|
ee = mock.Mock(image='quay.io/ansible/awx-ee:latest', credential=None)
|
||||||
|
with (
|
||||||
|
mock.patch('awx.main.management.commands.inventory_import.get_default_execution_environment', return_value=ee),
|
||||||
|
mock.patch('awx.main.management.commands.inventory_import.settings') as s,
|
||||||
|
):
|
||||||
|
s.IS_K8S = False
|
||||||
|
bargs = AnsibleInventoryLoader('/tmp/inv').get_base_args()
|
||||||
|
assert bargs[:3] == ['podman', 'run', '--rm']
|
||||||
|
|||||||
Reference in New Issue
Block a user