Repository navigation
Cache API tests & unifying behavior - #61229
Conversation
There was a bug in some of the lookups where it was looking at sub banks instead of the banks containing the leaf/key nodes. That was fixed. Also restored the original behaviors, only adding the updated functionality, namely adding timestamp key/values to redis.
Previously on X-Files. Wait nope. Previously on etcd cache files... :joy: if a path were 1/2/3 then etcd would break with IndexError, but when it was 1/2/3/4/5 then instead of returning the "file" (key?) 5 it would return `4/5` as the name. Which is probably not correct, and definitely inconsistent with localfs (and every other cache module). Now it will always only return the final segment of the cache (e.g. 7 for 1/2/3/4/5/6/7 and 5 for 1/2/5)
Comments were outdated, now they're gone or fixed. Also shifted around some of the test setup to make it a bit cleaner.
Fixed an inconsistency when flushing banks with None key. Also added to the test run. We may want to add other backing caches via alternate fixtures?
Added a force_reconnect function because I couldn't figure out how to remove the client from the context any other way. There may be a better way to do that, but there will probably be some loader changes anyway.
Saltfile never should have been added in the first place and the integration test wasn't really necessary, functional was better/lighter.
| data = (bank, key) | ||
| cur, _ = run_query(__context__["mysql_client"], query=query, args=data) |
There was a problem hiding this comment.
I could probably unify the names here - that is make data -> args everywhere.
| with container.started() as factory: | ||
| # TODO: May want to do the same thing for redis to ensure that service is up & running | ||
| # TODO: THIS IS HORRIBLE. THERE ARE BETTER WAYS TO DETECT SERVICE IS UP -W. Werner, 2021-10-12 | ||
|
|
||
| timer = Timer(timeout=10) | ||
| sleeptime = 0.1 | ||
| while not timer.expired: | ||
| try: | ||
| with socket.create_connection( | ||
| ("localhost", consul_port), timeout=1 | ||
| ) as cli: | ||
| cli.send(b"GET /v1/kv/fnord HTTP/1.1\n\n") | ||
| cli.recv(2048) | ||
| break | ||
| except ConnectionResetError as e: | ||
| if e.errno == 104: | ||
| time.sleep(sleeptime) | ||
| sleeptime += sleeptime | ||
| else: | ||
| assert False, "Timer expired before connecting to consul" | ||
| yield factory |
There was a problem hiding this comment.
@s0undt3ch do you know of a better way to wait/timeout for when a container service comes online? I learned that the container will come up but the process inside won't actually be ready for varying times. I hacked this together because I wasn't aware of a better way to do it... do you have any examples?
There was a problem hiding this comment.
There was a problem hiding this comment.
I don't think so - the ports can be open but the service isn't actually ready. This seems like the best option then, currently.
There was a problem hiding this comment.
Maybe we should investigating supporting making requests against services and assert on the responses if/when the service is up....
| pytest.skip( | ||
| "This is impossible with redis. Should we make localfs behave the same way?" | ||
| ) |
There was a problem hiding this comment.
This might be a question for the team - redis can't have an empty set, which is how the cache backend implements "folders". Localfs doesn't actually remove the bank (folder) when there are no files in the directory. Either we can update localfs, or just continue skipping this for now.
| pytest.skip( | ||
| "Skipping for now - etcd, redis, and mysql do not raise. Should ensure all backends behave consistently" | ||
| ) |
There was a problem hiding this comment.
This is another accidental API. It's only the localfs cache that raises but I'm pretty sure it should not.
Fixes saltstack#60272 - the import statement was totally incorrect. Now it will actually attempt to connect to a redis cluster.
From what I can tell, previously the query was being built in Python instead of using mysql to add the parameters, and this probably horked up the handling of binary strings. Unless some other version of the DB will be problematic...
s0undt3ch
left a comment
There was a problem hiding this comment.
As for the consistency questions, we should strive to be consistent across backends...
| with container.started() as factory: | ||
| # TODO: May want to do the same thing for redis to ensure that service is up & running | ||
| # TODO: THIS IS HORRIBLE. THERE ARE BETTER WAYS TO DETECT SERVICE IS UP -W. Werner, 2021-10-12 | ||
|
|
||
| timer = Timer(timeout=10) | ||
| sleeptime = 0.1 | ||
| while not timer.expired: | ||
| try: | ||
| with socket.create_connection( | ||
| ("localhost", consul_port), timeout=1 | ||
| ) as cli: | ||
| cli.send(b"GET /v1/kv/fnord HTTP/1.1\n\n") | ||
| cli.recv(2048) | ||
| break | ||
| except ConnectionResetError as e: | ||
| if e.errno == 104: | ||
| time.sleep(sleeptime) | ||
| sleeptime += sleeptime | ||
| else: | ||
| assert False, "Timer expired before connecting to consul" | ||
| yield factory |
There was a problem hiding this comment.
Maybe we should investigating supporting making requests against services and assert on the responses if/when the service is up....
I really really hate the way this is configured but I can't make pytest use fixtures as parameters in fixtures. I may have to struggle to come up with another way.
|
lint is failing |
This has been tested locally and it runs all of them. I'm sure with the CI environment it's possible that it fails for no particularly good reason. And it's definitely not worth blocking a PR for (though arguably it could be if *all* of the images fail, but...)
|
Lint should be good now, it was failing on one test for flakiness - just pushed a fix for that. The other one the whole centos 8 stream failed to even launch 🤷 We'll see if they all pass now... |
Hi! I'm your friendly PR bot!You might be wondering what I'm doing commenting here on your PR. Yes, as a matter of fact, I am... I'm just here to help us improve the documentation. I can't respond to Okay... so what do you do? I detect modules that are missing docstrings or "CLI Example" on existing docstrings! So what does that have to do with my PR? I noticed that in this PR there are some files changed that have some of these Okay, what are they? Well, my favorite, is that since you were making changes here I'm hoping that If I can, then what? Well, you can either add them to this PR or add them to another PR. Either way is fine! Well... what if I can't, or don't want to? That's also fine! We appreciate all contributions to the Salt Project. If you Whatever approach you decide to take, just drop a comment here letting us know! Detected Issues (click me)Check Known Missing Docstrings...........................................Failed - hook id: invoke - duration: 1.05s - exit code: 1 Thanks again! |
What does this PR do?
Adds API tests for caching, making it relatively trivial to add new cache backends that conform to the default/localfs cache behavior. It also fixes a few inconsistencies (in particular the missing
updatedfunctionality for a few of the backends.)This also functions as regression tests since it will ensure that any changes to cache backends that alter existing cache behavior will be exposed.
This will also be super useful when we upgrade mysql/redis/consul/etcd libraries and databases.
What issues does this PR fix or reference?
Closes #61081
Closes #60273
Closes #60272
Previous Behavior
Cache backends were somewhat inconsistent. Also almost completely untested.
New Behavior
All current cache backends behave identically and completely like the localfs cache backend
Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
Yes
Please review Salt's Contributing Guide for best practices.
See GitHub's page on GPG signing for more information about signing commits with GPG.