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

fix: Create host fails on 2.5.2 #240

Closed
wants to merge 1 commit into from
Closed

Conversation

tristanrobert
Copy link
Collaborator

Fixes #207

Replace #239

@tristanrobert tristanrobert added the bug Something isn't working label Dec 6, 2022
@tristanrobert tristanrobert added this to the 0.14.1 milestone Dec 6, 2022
@tristanrobert tristanrobert self-assigned this Dec 6, 2022
@tristanrobert tristanrobert added this to To do in ForemanFogProxmox plugin via automation Dec 6, 2022
@tristanrobert tristanrobert requested review from ekohl and removed request for ekohl December 6, 2022 15:06
ForemanFogProxmox plugin automation moved this from To do to Done Dec 6, 2022
Copy link
Member

@ekohl ekohl left a 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))
Copy link
Member

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

Copy link
Collaborator Author

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.

Copy link
Member

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).

Comment on lines +58 to +59
add_disk_options(disk, args) unless args.key?('options')
disk[:options] = args['options'] if args.key?('options')
Copy link
Member

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.

Copy link
Collaborator Author

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'),
Copy link
Member

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.

Copy link
Collaborator Author

@tristanrobert tristanrobert Dec 7, 2022

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.

Comment on lines +110 to +115
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
Copy link
Member

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

Suggested change
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

Copy link
Collaborator Author

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?
Copy link
Member

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:

Suggested change
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:

Suggested change
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'
Copy link
Member

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:

Suggested change
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
Copy link
Member

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

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging this pull request may close these issues.

Create host fails on 2.5.2
2 participants