-
Notifications
You must be signed in to change notification settings - Fork 0
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
Added 4 more methods #10
base: master
Are you sure you want to change the base?
Conversation
Tested on schAlpha with two devices and different test cases.
resin_release_tool/releaser.py
Outdated
all_devices = self.models.device.get_all_by_application_id(app_info['id']) | ||
tags_per_device = [] | ||
for device in all_devices: | ||
tags_per_device.append({'uuid':device['uuid'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can use something like this, so you don't have that many api calls, https://github.com/mobilityhouse/resin-release-tool/blob/master/resin_release_tool/releaser.py#L18
You are setting every tag to env and should be get all the tags of the devices in a dict and set it to RESIN_TAG_LIST, using json.dumps |
So RESIN_TAG_LIST should look like: {'STATUS': 'not commissioned', 'COLOR';'orange', etc} right? |
@@ -21,6 +23,69 @@ def get_canaries(self): | |||
if tag['tag_key'] == 'CANARY'] | |||
return canaries | |||
|
|||
def get_tags_per_device(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it makes it clearer to have a short docstring here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
…a string containing all the tags. NOTE: During this bug fix we've found that variable names starting with "BALENA_" or "RESIN_" are forbidden.
@Roger please check the latest commit. I already tested it on schAlpha and it works. |
resin_release_tool/releaser.py
Outdated
|
||
def get_app_env_vars(self): | ||
allvars = self.models.environment_variables.application.get_all(int(self.app_id)) | ||
list_of_app_env_vars = [{'id':var['id'], var['name']:var['value']} for var in allvars] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason this format was chosen?
If I'm understanding things right, it's:
[{"id": 1234, "something": "its value"}, {"id": 2345, "foobar": "baz"}]
Which seems odd to me, using var['name']
as dictionary key makes it hard to access stuff programmatically (you'd have to iterate over the dictionary's keys and exclude the one named "id" to access the actual key/value pair)
It would make things simpler to either keep the original format returned by get_all()
(since the name is reliably in the dictionary key named 'name') or rearrange it into a dictionary like this:
{"something": {"id": 1234, "value": "its value"}, "foobar": {"id": 2345, "value": "baz"}}
So you can just access dict["something"]["value"] without for loops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been refactored now, thanks for your help!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function looks the same to me though.
list_of_env_vars_per_device = [] | ||
for device in self.uuid_list: | ||
allvars = self.models.environment_variables.device.get_all(device) | ||
list_of_vars = [{'id':var['id'], var['name']:var['value']} for var in allvars] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems very similar to the code in get_app_env_vars, consider putting that in a separate function.
for device in self.uuid_list: | ||
allvars = self.models.environment_variables.device.get_all(device) | ||
list_of_vars = [{'id':var['id'], var['name']:var['value']} for var in allvars] | ||
list_of_env_vars_per_device.append({device:list_of_vars}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much the comment on structure as above: Any particular reason to choose this...
[{"some_device_id": [...list...]}, {"other_device_id": [...list...]}]
over just this?
{"some_device_id": [...list...], "other_device_id": [...list...]}
value = json.dumps(device['tags']) | ||
self.models.environment_variables.device.create(device['uuid'], 'DEVICE_TAG_LIST', value) | ||
print("creating/overriding var: ", device['uuid'], 'DEVICE_TAG_LIST', value) | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "except" is too broad and could hide other problems.
This is something pylint would point out, I think this project is missing some integration there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, for sure it will require some more refactoring and integrations in the future but for now I think we can merge it since we need to provide the tags to the ops team.
Thanks @dequis @OrangeTux for the review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the pylint stuff is out of scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this isn't resolved, the except is still too broad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've some minor comments. Also look at @dequis his comments.
value = json.dumps(device['tags']) | ||
self.models.environment_variables.device.create(device['uuid'], 'DEVICE_TAG_LIST', value) | ||
print("creating/overriding var: ", device['uuid'], 'DEVICE_TAG_LIST', value) | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some things are still not addressed (that self.uuid_list is still there)
please squash before merge! and thanks for the changes :) |
…a string containing all the tags. NOTE: During this bug fix we've found that variable names starting with "BALENA_" or "RESIN_" are forbidden. Refactored "get_tags_per_device", now it is cleaner and shorter. Solved empty uuid list and got rid of "self.uuid_list"
…-tool into env_vars_mod Squashed last 5 commits
|
||
def get_app_env_vars(self): | ||
all_vars = self.models.environment_variables.application.get_all(int(self.app_id)) | ||
return [{'id':var['id'], var['name']:var['value']} for var in all_vars] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh the original line got refactored but #10 (comment) still applies
if uuid in elem: | ||
list_of_env_vars = elem[uuid] | ||
for var in list_of_env_vars: | ||
if 'DEVICE_TAG_LIST' in var: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to refactor this whole loop after get_app_env_vars returns a plain dict.
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
4. set_device_env_vars: Override ENV VARS with new values taken from the tags
Tested on schAlpha with two devices and different test cases.