Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 535f226

Browse files
committedJan 30, 2025·
Pass ident value in streaming
1 parent bcd1036 commit 535f226

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed
 

‎src/ansible_runner/config/_base.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class BaseConfig:
144144
fact_cache: str | None = field(metadata={MetaValues.TRANSMIT: False}, default=None)
145145
fact_cache_type: str = 'jsonfile'
146146
host_cwd: str | None = None
147-
ident: str | None = field(metadata={MetaValues.TRANSMIT: False}, default=None)
147+
ident: str | None = None
148148
json_mode: bool = False
149149
keepalive_seconds: int | None = field(metadata={MetaValues.TRANSMIT: False}, default=None)
150150
passwords: dict[str, str] | None = None
@@ -167,10 +167,22 @@ class BaseConfig:
167167
_CONTAINER_ENGINES = ('docker', 'podman')
168168

169169
def __post_init__(self) -> None:
170+
"""
171+
Completes object initialization after the Dataclass __init__() call is complete.
172+
173+
Finish initialization by setting other attribute defaults and normalize the path attributes
174+
by setting absolute paths. Also make sure that the private_data_dir and artifact directories
175+
exist, creating them if necessary.
176+
177+
The Runner, Transmitter, Worker and Processor objects all depend, in some manner, on this
178+
path normalization being completed when they are initialized (mostly for private_data_dir).
179+
180+
BaseConfig and RunnerConfig both make use of the ArtifactLoader object that is created here.
181+
"""
170182
# pylint: disable=W0613
171183

172184
self.command: list[str] = []
173-
self.registry_auth_path: str
185+
self.registry_auth_path: str = ""
174186
self.container_name: str = "" # like other properties, not accurate until prepare is called
175187
if self.container_image is None:
176188
self.container_image = ''

‎test/integration/test_transmit_worker_process.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,9 @@ def test_transmit_role(tmp_path, cli, project_fixtures):
398398
r = cli(['transmit', str(transmit_dir), '--role', 'hello_world'])
399399
data = json.loads(r.stdout.split('\n')[0])
400400
assert 'kwargs' in data
401-
assert len(data['kwargs']) == 1
401+
assert len(data['kwargs']) == 2
402402
assert 'playbook' in data['kwargs']
403+
assert 'ident' in data['kwargs']
403404

404405

405406
def test_worker_without_delete_no_dir(tmp_path, cli, transmit_stream): # pylint: disable=W0621

‎test/unit/config/test_runner.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,9 @@ def test_containerization_settings(tmp_path, runtime, mocker):
740740
def test_streamable_attributes_all_defaults():
741741
"""Test that all default values return an empty dict."""
742742
rc = RunnerConfig()
743-
assert not rc.streamable_attributes()
743+
attrs = rc.streamable_attributes()
744+
assert len(attrs) == 1
745+
assert 'ident' in attrs
744746

745747

746748
def test_streamable_attributes_non_default(tmp_path):
@@ -754,8 +756,10 @@ def test_streamable_attributes_non_default(tmp_path):
754756

755757
# Don't expect private_data_dir or keepalive_seconds since they are not streamable.
756758
# Don't expect playbook since it is an empty value.
757-
assert rc.streamable_attributes() == {
758-
"host_pattern": "hostA,",
759-
"json_mode": True,
760-
"verbosity": 3,
761-
}
759+
attrs = rc.streamable_attributes()
760+
assert attrs['host_pattern'] == 'hostA,'
761+
assert attrs['json_mode']
762+
assert attrs['verbosity'] == 3
763+
assert 'private_data_dir' not in attrs
764+
assert 'keepalive_seconds' not in attrs
765+
assert 'playbook' not in attrs

0 commit comments

Comments
 (0)
Please sign in to comment.