-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
fix: Create host fails on 2.5.2 #240
Conversation
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'd consider making a separate PR for the translations. There is a lot going on in this PR and that generally makes it harder to review & merge.
Personally I'd start with a PR that removes all translations from logger statements, then fix this and then a PR that adds translations.
@@ -52,12 +49,14 @@ def parsed_typed_volumes(args, type, parsed_vm) | |||
end | |||
|
|||
def parse_hard_disk_volume(args) | |||
logger.debug(format(_('parse_hard_disk_volume(): args=%<args>s'), args: args)) |
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.
As in the other PR: I wouldn't translate this
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 suggest I remove logger statements from translation in a PR focused on i18n.
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.
Agreed: I suggested the same in #240 (review).
add_disk_options(disk, args) unless args.key?('options') | ||
disk[:options] = args['options'] if args.key?('options') |
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'd reduce it to a simple if/else.
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 will see if theforeman-rubocop rules accept this style
logger.info(format(_('vm %<vmid>s extend volume %<volume_id>s to %<extension>s'), vmid: vm.identity, | ||
volume_id: id, extension: extension)) | ||
extension = '+' + diff_size.to_s + 'G' | ||
logger.info(format(_('vm %<vmid>s extend volume %<volume_id>s to %<extension>s'), |
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 realize it's not part of this PR, logger statements shouldn't be translated.
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 suggest I remove logger statements from translation in an another PR focused on i18n.
exists = false | ||
return exists unless disk | ||
|
||
exists = !volume_attributes['volid'].empty? if disk.hard_disk? || disk.cloud_init? | ||
exists = !volume_attributes['cdrom'].empty? if disk.cdrom? | ||
exists |
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'd be much more conservative on the guard clauses. IMHO they're a poor practice that should be avoided for non-trivial things. Instead I'd write this as
exists = false | |
return exists unless disk | |
exists = !volume_attributes['volid'].empty? if disk.hard_disk? || disk.cloud_init? | |
exists = !volume_attributes['cdrom'].empty? if disk.cdrom? | |
exists | |
if !disk | |
false | |
elsif disk.hard_disk? || disk.cloud_init? | |
volume_attributes['volid'].presence | |
elsif disk.cdrom? | |
volume_attributes['cdrom'].presence | |
else | |
false | |
end |
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 will see if theforeman-rubocop rules accept this style
@@ -36,7 +36,7 @@ def delete_volume(vm, id, volume_attributes) | |||
def volume_options(vm, id, volume_attributes) | |||
options = {} | |||
options.store(:mp, volume_attributes['mp']) if vm.container? && id != 'rootfs' | |||
options.store(:cache, volume_attributes['cache']) unless vm.container? | |||
options.store(:cache, volume_attributes['cache']) unless vm.container? || volume_attributes['cache'].empty? |
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'd be worried about volume_attributes['cache'] being nil
. In Rails you have .presence
which is a safer operator:
options.store(:cache, volume_attributes['cache']) unless vm.container? || volume_attributes['cache'].empty? | |
options.store(:cache, volume_attributes['cache']) unless vm.container? || !volume_attributes['cache'].presence |
And then personally I'd find this easier to follow the logic:
options.store(:cache, volume_attributes['cache']) unless vm.container? || volume_attributes['cache'].empty? | |
options.store(:cache, volume_attributes['cache']) if volume_attributes['cache'].presence && !vm.container? |
extension = '+' + (diff_size / GIGA).to_s + 'G' | ||
logger.info(format(_('vm %<vmid>s extend volume %<volume_id>s to %<extension>s'), vmid: vm.identity, | ||
volume_id: id, extension: extension)) | ||
extension = '+' + diff_size.to_s + 'G' |
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.
Also partly unrelated, but usually this is done using string interpolation:
extension = '+' + diff_size.to_s + 'G' | |
extension = "+#{diff_size}G" |
end | ||
next if vm.nil? | ||
logger.debug("found vm #{vmid} on node #{node.node}") | ||
break |
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.
You can write this method using find
:
def find_vm_by_uuid(uuid)
vmid = extract_vmid(uuid)
nodes.find do |node|
find_vm_in_servers_by_vmid(node.servers, vmid) || find_vm_in_servers_by_vmid(node.containers, vmid)
end
end
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 just realized after looking: my suggestion returns the node, not the found VM so I think you can ignore my suggestion.
Fixes #207
Replace #239