Begin versioning Assigner configs#111
Conversation
13a2d49 to
ce993b6
Compare
| "name": "gitlab", | ||
| "token": "xxx gitlab token xxx", | ||
| "host": "https://git.gitlab.com", | ||
| }, |
There was a problem hiding this comment.
@brhoades What do you think of this configuration schema? If you like it, I'll update the rest of the code to work with it.
There was a problem hiding this comment.
The schema will go something like this: the backend field is a JSON object with at least one key, name. The remainder of the data will be something that we can pass to the Backend class and it will be able to pull what it needs out of that.
So, for the mock backend, the config would look like
"backend" : { "name" : "mock" }
Seem sensible?
There was a problem hiding this comment.
I want to make sure I understand you right. Are you referring to the schema here, where we double check the functions are properly enforcing schema version differences? Or do you mean in general :D?
There was a problem hiding this comment.
I mean for the newest schema, in preparation for #102 😄
There was a problem hiding this comment.
This looks good. Will allow nonbreaking backend additions.
There was a problem hiding this comment.
Cool -- in that case I'll propagate the change through BaseRepo et. al.
ccfbc36 to
7c8fada
Compare
| @@ -0,0 +1,282 @@ | |||
|
|
|||
| SCHEMAS = [ | |||
There was a problem hiding this comment.
I worry this would get unruly fast. It's less rigid but would make more sense to define INITIAL_SCHEMA, make that version 0/1, then copy it and modify what changed in two as part of the script. Then you only need to read blocks of code to determine changes rather than hunting for comments.
There was a problem hiding this comment.
You've got copy.deepcopy if you agree ;).
There was a problem hiding this comment.
I fear that writing diff functions rather than schemas will make it harder to write schemas (the proposed version 2 schema required some troubleshooting) and that it'll slow down startup -- if we could constexpr all of this that would be great...
There was a problem hiding this comment.
That's fine with me. I just feel there's a better way to orgfanize this. Maybe different files for each schema version?
There was a problem hiding this comment.
Yeah, we can do that!
| from assigner.config.upgrades import UPGRADES | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
There was a problem hiding this comment.
np: 2 spacesssssssssssssssssssssssssss
We need that flake8 linter.
|
|
||
|
|
||
| def validate(config, version=(len(SCHEMAS) - 1)): | ||
| assert version < len(SCHEMAS) |
There was a problem hiding this comment.
I've never seen this. I noticed it was a builtin but this makes sense.
There was a problem hiding this comment.
Yeah! I should rename this to _validate or rewrite this to throw...going to do the former.
| pass | ||
|
|
||
|
|
||
| def validate(config, version=(len(SCHEMAS) - 1)): |
There was a problem hiding this comment.
You can put expressions for parameter defaults?
| def test_validate(self): | ||
| for version, config in enumerate(CONFIGS): | ||
| try: | ||
| validate(config, version) |
There was a problem hiding this comment.
Two alternatives:
with self.assertRaises(ValidationError):
validate(config, version)or
self.assertRaises(validate, config, version)I prefer the former.
There was a problem hiding this comment.
Wait, I want the opposite of assertRaises. Does such a thing exist?
There was a problem hiding this comment.
Oh, yeah, just run the function :DD. If an exception is thrown, BAM. Assuming you're doing try: ... except: ... self.fail, that's fine.
| "name": "gitlab", | ||
| "token": "xxx gitlab token xxx", | ||
| "host": "https://git.gitlab.com", | ||
| }, |
There was a problem hiding this comment.
I want to make sure I understand you right. Are you referring to the schema here, where we double check the functions are properly enforcing schema version differences? Or do you mean in general :D?
7c8fada to
33d832b
Compare
| for version in range(current, latest): | ||
| config = UPGRADES[version](config) | ||
| assert get_version(config) == version + 1 | ||
| _validate(config, version) |
There was a problem hiding this comment.
So, validation is a tricky thing here. Ideally we'd like to detect when a config goes from valid -> invalid, but in the case that a config is invalid to begin with, what do we do? The primary case of an invalid config is when assigner is run with no _config.yml and defaults to an empty config.
I suppose we could require that upgrade functions have to succeed even if they're handed a malformed config (which is what they do right now) and test that upgrading an empty config succeeds (which is what we do right now).
47b36e1 to
75204e9
Compare
| @@ -0,0 +1,63 @@ | |||
| import logging | |||
There was a problem hiding this comment.
My merge conflict sense is tingling.
- Add schemas for versions 0, 1, and 2 - Schema validation - Upgrading configs from one version to the next
bf24a1d to
60308fd
Compare
TODO:
assignerto use v2 config