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

Use OvirtSDK for the provisioning flow #2

Merged
merged 1 commit into from
Apr 25, 2017

Conversation

borod108
Copy link
Contributor

@borod108 borod108 commented Apr 7, 2017

Use OvirtSDK for the provisioning flow, this respects use_ovirt_engine_sdk setting
and will not use OvirtSDK if it is off.

This was a common effort with big contribution from @pkliczewski
and help from @jhernand and @masayag

@borod108
Copy link
Contributor Author

borod108 commented Apr 7, 2017

@durandom Moved the PR here.
(@pkliczewski, @oourfali )

@borod108
Copy link
Contributor Author

borod108 commented Apr 7, 2017

@miq-bot assign @durandom
@miq-bot add-label fine/yes

bdunne pushed a commit to bdunne/manageiq-providers-ovirt that referenced this pull request Apr 7, 2017
@durandom
Copy link
Member

This is a port of ManageIQ/manageiq#14402

@durandom
Copy link
Member

@gmcculloug @bdunne @syncrou could you review please?

This is to enable usage of v4 of the ovirt api. Part of this was already done in
ManageIQ/manageiq#14398
ManageIQ/manageiq#14399

We should get this into fine to enable customers to opt into v4 and let it be used in general.
Although this PR is quite huge, the v3 part is still using the old v3 code - although refactored into common places.

@borod108
Copy link
Contributor Author

@durandom Hi! was wondering if there are any news regarding this PR?

phase_context[:clone_task_ref] = vm.creation_status_link
end

def nics_for_(vm)
Copy link
Contributor

Choose a reason for hiding this comment

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

@borod108
is the trailing underscore in the method name intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i just like this style but I can remove it and write nics_for_vm(vm) instead, but the double "vm" thing...

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I never saw a trailing underscore style in our code base (actually not even in ruby projects...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well rubocop did not complain!
so should I change it?

Copy link
Member

Choose a reason for hiding this comment

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

well rubocop did not complain!

probably no one ever had the idea 😄 - I'd change it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.

@@ -17,7 +17,7 @@ def host_targeted_refresh(target)
end

def vm_targeted_refresh(target)
ems.with_provider_connection(:version => 4) do |connection|
@ems.with_provider_connection(:version => 4) do |connection|
Copy link
Contributor

Choose a reason for hiding this comment

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

@borod108
Could we have used the old code as is because ems is an attr_reader method and it would have always returned @ems.

This also applies to the other @ems changes in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes definitely, by bad.

@@ -87,6 +87,8 @@ def collect_vms
def collect_vm_by_uuid(uuid)
vm = connection.system_service.vms_service.vm_service(uuid).get
[VmPreloadedAttributesDecorator.new(vm, connection)]
rescue OvirtSDK4::Error
[]
Copy link
Member

Choose a reason for hiding this comment

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

Seems odd to ignore this error and return an empty array. Can you explain the reasoning here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this is currently the right way to check if a VM exists using the oVirt Ruby SDK. The vm_service(uuid) method will always succeed, even if the VM doesn't exist. Calling the get method will then raise an exception, corresponding to the Not found HTTP code. The details of the error are in the exception message which isn't easy to parse.

I'd suggest to keep this code as it is. We will improve the SDK to provide a mechanism to check the kind of error, then this can be improved. For example:

begin
  ...
rescue OvirtSDK4::Error => e
  if e.code == 404
    []
  else
    raise
  end
end

I have opened the following oVirt SDK bug to track it:

[RFE] Add a mechanism to check the HTTP result code of errors
https://bugzilla.redhat.com/1443420

Copy link
Member

Choose a reason for hiding this comment

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

It would be great to rescue a more specific error like OvirtSDK4::ResourceNotFound

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, currently this not possible, please refer to Juans answer above, we will do it in future PRs

Copy link
Member

Choose a reason for hiding this comment

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

Please open an issue so that it isn't forgotten @borod108

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: #17

@@ -8,7 +8,7 @@ def initialize(args)
end

def host_targeted_refresh(target)
ems.with_provider_connection(:version => 4) do |connection|
@ems.with_provider_connection(:version => 4) do |connection|
Copy link
Member

Choose a reason for hiding this comment

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

Since this is in the v4.rb file would it make sense to make either the 4 or the whole hash a constant.

VERSION = 4
VERSION_HASH = {:version => VERSION}.freeze
...
@ems.with_provider_connection(VERSION_HASH) do |connection|

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, good idea!

nic_name = args[:nic_name]
interface = args[:interface]
vnic = args[:vnic]
logger = args[:logger]
Copy link
Member

Choose a reason for hiding this comment

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

I do not see any benefit to mapping most of these single-use variables. Just reference them directory from args in the method. The key names are clear.

Anything being referenced more then once it would make more sense to make a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The benefit of writing like this is that one can easily see args this method can receive.

Copy link
Member

Choose a reason for hiding this comment

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

@borod108 If that's what you're trying to accomplish, you may want to use keyword args

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

_log.info("#{log_header} Completed.")
end

class NicsDecorator < SimpleDelegator
Copy link
Member

Choose a reason for hiding this comment

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

Suggest moving classes into their own files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to do this in future refactoring.
There are several more refactoring steps on this code and this will be one of them, but currently will be just a bit easier to do while the classes are still here.

end
end

class GeneralUpdateMethodNamesDecorator < SimpleDelegator
Copy link
Member

Choose a reason for hiding this comment

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

Suggest moving classes into their own files.

@borod108 borod108 force-pushed the rfe/new_provider_provisioning branch from d540cf2 to af4b65c Compare April 19, 2017 09:49

def shutdown_guest(operation)
operation.with_provider_object(&:shutdown)
rescue Ovirt::VmIsNotRunning
Copy link
Contributor

Choose a reason for hiding this comment

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

@borod108 - I'm not understanding the value in suppressing exceptions, if there is a case for it - should there be some documentation around that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic was not changed from before. I found many things I do not like but kept the same logic because this is out of the scope of this PR.

Copy link
Member

Choose a reason for hiding this comment

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

@syncrou This pattern was initially added because the desired result in this case is for the VM to be off. If we sent shutdown_guest for a VM that is already off, the API would raise this error. So, it was simplest to just rescue the error and move on.

vm.with_provider_object do |rhevm_vm|
rhevm_vm.start { |action| action.use_cloud_init(true) if cloud_init }
end
rescue Ovirt::VmAlreadyRunning
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here in regards to suppressing exceptions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same.


def vm_stop(vm)
vm.with_provider_object(&:stop)
rescue Ovirt::VmIsNotRunning
Copy link
Contributor

Choose a reason for hiding this comment

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

And here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same.


def collect_disks_by_hrefs(disks)
vm_disks = []
ext_management_system.with_provider_connection(:version => 4) do |connection|
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we should generate a constant for :version => 4 to keep the process consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. Done.

@borod108 borod108 force-pushed the rfe/new_provider_provisioning branch 2 times, most recently from 3d60fb1 to 940fb86 Compare April 21, 2017 12:17
Copy link
Member

@durandom durandom left a comment

Choose a reason for hiding this comment

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

👍 to get it into fine

the mentioned cleanups will be done in future and smaller PRs

Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

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

In the future, it is much easier to review smaller PR's. If you feel it is necessary to keep all changes in one PR, multiple commits are helpful. I think the respond_to_missing? method is important.

nic_name = args[:nic_name]
interface = args[:interface]
vnic = args[:vnic]
logger = args[:logger]
Copy link
Member

Choose a reason for hiding this comment

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

@borod108 If that's what you're trying to accomplish, you may want to use keyword args


def shutdown_guest(operation)
operation.with_provider_object(&:shutdown)
rescue Ovirt::VmIsNotRunning
Copy link
Member

Choose a reason for hiding this comment

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

@syncrou This pattern was initially added because the desired result in this case is for the VM to be off. If we sent shutdown_guest for a VM that is already off, the API would raise this error. So, it was simplest to just rescue the error and move on.

end

class GeneralUpdateMethodNamesDecorator < SimpleDelegator
def method_missing(method_name, *args)
Copy link
Member

Choose a reason for hiding this comment

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

You need to also define respond_to_missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see the comment in the code, the problem is that the ovirt-gem does not actually define the respond_to_missing? so I can't really know without sending the method if it works or not. I do not see a clean way to do this.
In future PR we need to update the ovirt-gem and change this method_missing which is quite ugly. I will then be able to add the respond_to_missing? as well.

Copy link
Member

Choose a reason for hiding this comment

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

Please open an issue so that it is not forgotten @borod108

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: #18

{:network => network_name, :mac_address => nil},
{:network => network_name}
])
{:network => network_name, :mac_address => nil},
Copy link
Member

Choose a reason for hiding this comment

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

Why the whitespace addition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is how rubocop liked it...

@@ -12,6 +12,8 @@
allow(v).to receive(:with_provider_object).and_yield(rhevm_vm)
allow(ems).to receive(:with_disk_attachments_service).with(v).and_return(disk_attachments_service)
allow(ems).to receive(:with_provider_connection).and_return(false)
# TODO: (inventory) wirte for v4
Copy link
Member

Choose a reason for hiding this comment

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

typo: write

vnic.nil? ? get_provider_destination.create_nic(options) : vnic.apply_options!(options)
ems.ovirt_services.configure_vnic(
:vm => destination,
:mac_addr => mac_addr,
Copy link
Member

Choose a reason for hiding this comment

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

Is mac_address required now? IIRC, if we passed a nil, it would try to set it to nil. That was the reason for the delete_blanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is required for v4, so the delete blanks moved into the ovirt_services/strategies/v3

@@ -87,6 +87,8 @@ def collect_vms
def collect_vm_by_uuid(uuid)
vm = connection.system_service.vms_service.vm_service(uuid).get
[VmPreloadedAttributesDecorator.new(vm, connection)]
rescue OvirtSDK4::Error
[]
Copy link
Member

Choose a reason for hiding this comment

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

It would be great to rescue a more specific error like OvirtSDK4::ResourceNotFound

@borod108 borod108 changed the title Use OvirtSDK for the provisioning flow [WIP]Use OvirtSDK for the provisioning flow Apr 23, 2017
@miq-bot miq-bot added the wip label Apr 23, 2017
@borod108 borod108 force-pushed the rfe/new_provider_provisioning branch 2 times, most recently from b71245b to 66cd51e Compare April 24, 2017 06:01
@borod108
Copy link
Contributor Author

Please note the PR is currently back to WIP because we want to test fully after all the changes.

@borod108 borod108 force-pushed the rfe/new_provider_provisioning branch from 66cd51e to dee68de Compare April 24, 2017 08:18
@miq-bot
Copy link
Member

miq-bot commented Apr 24, 2017

This pull request is not mergeable. Please rebase and repush.

@borod108 borod108 changed the title [WIP]Use OvirtSDK for the provisioning flow Use OvirtSDK for the provisioning flow Apr 24, 2017
@borod108
Copy link
Contributor Author

@bdunne thank you for the review! I tried to address your comments.

@miq-bot miq-bot removed the wip label Apr 24, 2017
Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

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

It looks like you merged master into your branch rather than rebasing your branch. This can cause problems when commits on master reference bugzillas since all commits in the PR that have a bugzilla reference will be updated with a link to this PR. In this case I think it's okay ¯\_(ツ)_/¯ since that one commit doesn't have a bugzilla reference, but please be aware of this in the future.

@borod108
Copy link
Contributor Author

Hi please do not merge for the next few hours, we would like to make a final round of tests and internal review.
@miq-bot add-label wip

@miq-bot miq-bot changed the title Use OvirtSDK for the provisioning flow [WIP] Use OvirtSDK for the provisioning flow Apr 25, 2017
@miq-bot miq-bot added the wip label Apr 25, 2017
…e_sdk setting

and will not use OvirtSDK if it is off.

This was a common effort with big contribution from @pkliczewski
and help from @jhernand and @masayag
@borod108 borod108 force-pushed the rfe/new_provider_provisioning branch from a2776a7 to 83f887a Compare April 25, 2017 04:54
@borod108
Copy link
Contributor Author

@miq-bot remove-label wip

@miq-bot
Copy link
Member

miq-bot commented Apr 25, 2017

Some comments on commit borod108@83f887a

spec/models/manageiq/providers/redhat/infra_manager/provision/configuration_spec.rb

  • ⚠️ - 13 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 14 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.

spec/models/manageiq/providers/redhat/infra_manager/provision_spec.rb

  • ⚠️ - 117 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.

1 similar comment
@miq-bot
Copy link
Member

miq-bot commented Apr 25, 2017

Some comments on commit borod108@83f887a

spec/models/manageiq/providers/redhat/infra_manager/provision/configuration_spec.rb

  • ⚠️ - 13 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 14 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.

spec/models/manageiq/providers/redhat/infra_manager/provision_spec.rb

  • ⚠️ - 117 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.

@miq-bot
Copy link
Member

miq-bot commented Apr 25, 2017

Checked commit borod108@83f887a with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
33 files checked, 10 offenses detected

app/models/manageiq/providers/redhat/infra_manager.rb

app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v3.rb

app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v4.rb

@miq-bot miq-bot changed the title [WIP] Use OvirtSDK for the provisioning flow Use OvirtSDK for the provisioning flow Apr 25, 2017
@miq-bot miq-bot removed the wip label Apr 25, 2017
@durandom durandom merged commit 8857220 into ManageIQ:master Apr 25, 2017
@durandom durandom added this to the Sprint 59 Ending Apr 24, 2017 milestone Apr 25, 2017
@durandom
Copy link
Member

👏 finally 😅

everybody thanks for your patience and efforts

@simaishi
Copy link
Contributor

Fine backport (to manageiq repo) details:

$ git log -1
commit d15e29742e87b34d13ec97904bc9d8971b668b95
Author: Marcel Hild <[email protected]>
Date:   Tue Apr 25 08:48:51 2017 +0200

    Merge pull request #2 from borod108/rfe/new_provider_provisioning
    
    Use OvirtSDK for the provisioning flow
    (cherry picked from commit 88572201c6afd204f255dafe612098e85a582d13)

@borod108 borod108 deleted the rfe/new_provider_provisioning branch December 4, 2018 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants