Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nixops aws compat #1355

Merged
merged 5 commits into from Jul 7, 2020
Merged

Nixops aws compat #1355

merged 5 commits into from Jul 7, 2020

Conversation

adisbladis
Copy link
Member

Some changes required for NixOS/nixops-aws#103 to land.

Copy link
Member

@grahamc grahamc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor nits, but generally lgtm!

Comment on lines 145 to 199
def get_typed_resource(
self, name: str, type: str
) -> nixops.resources.GenericResourceState:
self, name: str, type_name: str, type: Type[TypedResource]
) -> TypedResource:
res = self.active_resources.get(name, None)
if not res:
raise Exception("resource ‘{0}’ does not exist".format(name))
if res.get_type() != type:
raise Exception("resource ‘{0}’ is not of type ‘{1}’".format(name, type))
return res
if res.get_type() != type_name:
raise Exception(
"resource ‘{0}’ is not of type ‘{1}’".format(name, type_name)
)
return res # type:ignore

def get_machine(self, name: str) -> nixops.resources.GenericResourceState:
def get_machine(self, name: str, type: Type[TypedResource]) -> TypedResource:
res = self.active_resources.get(name, None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should have a get_generic_machine/resource, and a get_typed_machine/resource. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering returning to

def get_machine(self, name: str) -> nixops.resources.GenericResourceState:

and let the caller use cast instead.

This results in exactly the same type safety as

def get_machine(self, name: str, type: Type[TypedResource]) -> TypedResource:

with only some slight inconvenience for the caller.

Wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the second option much better. It is really awkward to use in other libraries: https://github.com/input-output-hk/nixops-packet/pull/21/files#diff-78f3655b013910dfdb430d53dae85085R11-R18 this feels like something that should definitely be implemented in core, to provide a safe API.

nixops/diff.py Outdated
@@ -188,7 +188,7 @@ def retrieve_def(d):
name = d[4:].split(".")[0]
res_type = d.split(".")[1]
k = d.split(".")[2] if len(d.split(".")) > 2 else key
res = self._depl.get_typed_resource(name, res_type)
res = self._depl.get_typed_resource(name, res_type, Any)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the _generic method would solve this one a bit nicer I think.

Comment on lines +106 to +110
# While this looks like a rookie mistake where the list is going get shared
# across all class instances it's not... It's working around a Mypy crash.
#
# We're overriding this value in __init__.
# It's safe despite there being a shared list on the class level
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include a link to a bug ref, and/or a version number, or some more specific information for future spelunkers to explain exactly what code is related to this, and what they can delete once it is fixed?

Comment on lines +157 to +167
# Support Sequence[ImmutableValidatedObject]
if isinstance(value, tuple) and not isinstance(ann, str):
new_value = []
for v in value:
for subann in ann.__args__:
if inspect.isclass(subann) and issubclass(
subann, ImmutableValidatedObject
):
new_value.append(subann(**v))
else:
new_value.append(v)
value = tuple(new_value)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a test for this?

@adisbladis adisbladis force-pushed the nixops-aws-compat branch 2 times, most recently from 4f99b53 to 76873ac Compare July 7, 2020 13:08
`_wait_for: List["ResourceState"] = []` Results in every instance
sharing the same list, causing a resource to wait for itself before destruction.
@adisbladis adisbladis merged commit 9dd426a into NixOS:master Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants