Open Renerick opened 11 months ago
Probably the most apparent demonstration of the issue. I put a breakpoint in the deploy file and printed config from the context and from the state.
Not sure if it's intended, but given that file operations don't works as expected, I assume it's not
I spend an evening and came up with this patch
diff --git a/pyinfra/api/state.py b/pyinfra/api/state.py
index e639d645..44413046 100644
--- a/pyinfra/api/state.py
+++ b/pyinfra/api/state.py
@@ -7,7 +7,7 @@ from uuid import uuid4
from gevent.pool import Pool
from paramiko import PKey
-from pyinfra import logger
+from pyinfra import logger, context
from .config import Config
from .exceptions import PyinfraError
@@ -365,4 +365,8 @@ class State:
if hash_filename:
hash_key = sha1_hash(hash_key)
- return "{0}/pyinfra-{1}".format(self.config.TEMP_DIR, hash_key)
+ config = self.config
+ if context.ctx_config.isset():
+ config = context.config
+
+ return "{0}/pyinfra-{1}".format(config.TEMP_DIR, hash_key)
It seems to works, and judging by the call sites of get_temp_filename
, I think there should be no concurrency issues. Is this a reasonable fix? If yes, I'm happy to submit a PR
Hrm, sorry this one has come back again @Renerick, this is very annoying! The idea behind the config copies is to keep a separate version by host to scope any changes that way. But I think this is meaning changes get lost.
But I’m still confused by the original example which should work. Will have a think about this, since it’s come up a few times before I want to put something in that provides guarantees on these things rather than patching it (again).
Going to fix this properly in v3 by making config a global instance again. It shouldn't be per-host and it leads to all sorts of confusion like this.
Just an updated, I've recently updated to 3.0b0, and it seems to be working as expected, but I'll keep an eye on it
Describe the bug
In the past I have already reported similar bug (#761) and it was fixed, but today I encountered it again
When trying to upload or template a file to remote host without /tmp access and when SUDO = True I receive an error that /tmp directory is not found even when other value of the TEMP_DIR setting is specified. Currently I'm experiencing this problem when trying to upload a configuration files to Synology NAS where direct SFTP has no access to file system other then user home directory
To Reproduce
It appears the issue is caused by TEMP_DIR config value are not being propagated to
get_temp_filename
method. I noticed that context object in_parallel_load_hosts
method contains correct valuesHowever, the state object that generates the temporary file name does not
It appears that the root cause of this issue is
state.config.copy()
call. The context object with copied config is being passed to the deploy files, but the state method uses the original instance of the config. In fact, this issue most likely affects every single configuration value, not onlyTEMP_DIR
. Changingstate.config.copy()
tostate.config
seems to fix the error with TEMP_DIR I'm facing at the moment, although I'm not sure if it breaks something somewhere else (probably state isolation between hosts). Regardless, it's quite lucky I didn't encounter this any sooner (probably because I was working with non-synology hosts and using explicit configuration values, passed as global arguments).I could look into this myself, but, again, not sure what this may break as I'm just occasionally debug pyinfra, not that familiar with all the internals
Expected behavior
Upload successful
Meta
Include output of
pyinfra --support
.-vv
and--debug
.