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

Update model to support network adapters #15371

Merged
merged 11 commits into from
Aug 30, 2017

Conversation

skovic
Copy link

@skovic skovic commented Jun 14, 2017

This PR updates the model to support network adapters which will be added as entries to the guest_devices table.

@skovic
Copy link
Author

skovic commented Jun 14, 2017

@miq-bot add_label wip

@miq-bot miq-bot changed the title Update model to support network adapters [WIP] Update model to support network adapters Jun 14, 2017
@miq-bot miq-bot added the wip label Jun 14, 2017
@skovic
Copy link
Author

skovic commented Jun 14, 2017

@miq-bot assign @blomquisg

@skovic
Copy link
Author

skovic commented Jun 22, 2017

@miq-bot remove_label wip

@miq-bot miq-bot changed the title [WIP] Update model to support network adapters Update model to support network adapters Jun 22, 2017
@miq-bot miq-bot removed the wip label Jun 22, 2017
@skovic
Copy link
Author

skovic commented Jun 27, 2017

@blomquisg Can you get someone to look at this PR? Thanks

@blomquisg blomquisg requested review from Fryguy and juliancheal June 28, 2017 19:24
@blomquisg
Copy link
Member

@skovic it looks like there needs to be an associated set of changes to the DB Schema.

Can you look into that and add the link to the associated PR when that's available.

Talk to @juliancheal about how to get started there if you have questions.

@skovic
Copy link
Author

skovic commented Jun 28, 2017

@blomquisg @juliancheal The schema changes have already been reviewed and merged. Please see manageiq-schema PR 16

@rodneyhbrown7
Copy link

Provider change have also been submitted for review in ManageIQ/manageiq-providers-lenovo#59 @juliancheal can you review?

@skovic
Copy link
Author

skovic commented Jul 24, 2017

@blomquisg Could you get someone to take a look at this PR? The schema changes are already in. Thanks

@@ -10,4 +11,7 @@ class GuestDevice < ApplicationRecord

has_one :network, :foreign_key => "device_id", :dependent => :destroy, :inverse_of => :guest_device
has_many :miq_scsi_targets, :dependent => :destroy

has_many :firmwares, :dependent => :destroy
has_many :child_devices, -> { where(:parent_device_id => ids) }, :foreign_key => "parent_device_id", :class_name => "GuestDevice", :dependent => :destroy
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 you could do something more bi-directional here, like the Rails docs show.

has_many :child_devices, class_name  => "GuestDevice", 
                         foreign_key => :parent_device_id,
                         dependent   => :destroy

belongs_to :parent_device, class_name => "GuestDevice"

This way, you could have a guest device, and list it's child devices, and also ask for it's parent device:

guest_device = GuestDevice.first
children = guest_device.child_devices
parent = guest_device.parent_device

I think the rest will fall into place with Rails magic.

/cc @Fryguy

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Author

Choose a reason for hiding this comment

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

@blomquisg I made the changes you suggested, and they seemed to work at first, but after I restarted the evm, one of the ports associated with the guest device was replaced by a duplicate of the other port in the table. For example, suppose we have guest device 1 that has port 1 and port 2. At first, the guest device and its associated ports are populated in the DB correctly. After a evm restart is performed, port 1 disappears from the table and there are now two duplicate port 2 entries with the same address and parent device. Any ideas why this is occurring? Does it have something to do with the save_inventory code? Including @juliancheal @Fryguy

Copy link
Member

Choose a reason for hiding this comment

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

That sounds like a bug in the refresh, honestly.

Can you update the PR with the changes you have in place, and maybe it will shed some light on what's going on.

Also, with the inventory refresher code... are you running what's on master? Or, do you have local changes to the inventory collection? It would help to see that, too.

Copy link
Author

Choose a reason for hiding this comment

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

@blomquisg @juliancheal I updated the PR with the suggested changes. The associated changes in the provider were merged, so they're in master which is what I'm testing with.

Copy link
Member

Choose a reason for hiding this comment

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

@skovic I'm having a look this afternoon, to see if I can find the root of the refresh issue.

Copy link
Author

Choose a reason for hiding this comment

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

@juliancheal Have you had a chance to look into this issue yet? Thanks

Copy link
Author

Choose a reason for hiding this comment

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

@blomquisg Could we just revert to my original changes (undo the change you recommended) and get this PR merged? Our provider changes for the network adapter support have already been merged but these changes have not. This partial implementation is causing the provider to not refresh properly. In addition, this PR is delaying the UI changes for network adapter support from being merged -- the PR is ready to go. We could always make another PR with your suggested changes and have it sit out there while someone investigates the database issues that occurring with the change. What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

@blomquisg I have reverted the guest device model in this PR to use my original changes (which do not have the database refresh problem), and I have moved the implementation of this suggestion to PR #15732. Please consider merging this PR (#15371), so we are unblocked. Thanks

Copy link
Member

Choose a reason for hiding this comment

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

K... Thanks for the update @skovic ... I'll remove my "request for changes" review and take another look.

We can try to figure out what's going on with this in a separate PR/thread.

@@ -6213,6 +6213,26 @@
:feature_type: view
:identifier: firmware_show

# Guest Devices
Copy link
Member

Choose a reason for hiding this comment

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

@dclarizio @Fryguy Do we want a Guest Devices section in the product_features? I'm not sure of all the impact that has.

Choose a reason for hiding this comment

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

@blomquisg if these are a new menu item in the navigation, we normally do add them into product_features so a role can be customized to show or not show them. If they are similar to the Firmwares item above, then I'd say yes. If not, then I'm not sure as I am not familiar with this addition.

@blomquisg blomquisg requested a review from imtayadeway July 24, 2017 21:12
@blomquisg
Copy link
Member

@imtayadeway Can you check on the API changes in this PR? Thanks!

Copy link
Member

@juliancheal juliancheal left a comment

Choose a reason for hiding this comment

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

LGTM, agree with @blomquisg's comment.

@skovic skovic force-pushed the network-adapter-model branch from f5b90b3 to 3d7b976 Compare July 26, 2017 20:07
@skovic skovic force-pushed the network-adapter-model branch from 3d7b976 to 10c1f46 Compare August 4, 2017 17:53
@blomquisg blomquisg dismissed their stale review August 7, 2017 16:49

The changes I recommended caused a problem in the refresher ... going to look at that separately and move this PR along.

@@ -19,7 +19,7 @@ class Hardware < ApplicationRecord
has_many :guest_devices, :dependent => :destroy
has_many :storage_adapters, -> { where "device_type = 'storage'" }, :class_name => "GuestDevice", :foreign_key => :hardware_id
has_many :nics, -> { where "device_type = 'ethernet'" }, :class_name => "GuestDevice", :foreign_key => :hardware_id
has_many :ports, -> { where "device_type != 'storage'" }, :class_name => "GuestDevice", :foreign_key => :hardware_id
has_many :ports, -> { where "device_type = 'ethernet port'" }, :class_name => "GuestDevice", :foreign_key => :hardware_id
Copy link
Member

Choose a reason for hiding this comment

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

I'm worried about this, but without any evidence...

The new implementation is much more "correct". I'm just worried that there were some old assumptions built into that previous relationship mapping based on != 'storage' that will come back to bite us.

Honestly, the only thing I can think of doing is letting it through and crossing our fingers.

Copy link
Member

Choose a reason for hiding this comment

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

Oops, I think I spoke to soon.

I can't find a device_type of "ethernet port". This means that whatever used to be classified as a port will no longer be.

And, if this is changed to just ethernet, then it simply overlaps with nics.

I need to look over the different ways we're collecting the device_type information to figure out whatdevice_type ports should really map to.

Copy link
Author

Choose a reason for hiding this comment

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

@blomquisg Are supported device_types defined somewhere? The schema for guest_devices declares the device_type as a string, so it looks like anything will work -- maybe this should be an enumeration instead of a string? The Lenovo provider adds physical ports as a guest_device with a device_type of "ethernet port". Please see ManageIQ/manageiq-providers-lenovo#59

Copy link
Contributor

Choose a reason for hiding this comment

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

@blomquisg have you found the problem?

@skovic skovic force-pushed the network-adapter-model branch from 10c1f46 to 80a2245 Compare August 8, 2017 18:57
@skovic
Copy link
Author

skovic commented Aug 8, 2017

I moved the guest_devices REST API changes to ManageIQ/manageiq-api#7

@chargio
Copy link
Contributor

chargio commented Aug 10, 2017

Is there anything missing to have this PR merged? I can't see if that is the case from the comments, or whether this should be merged and an issue created (as the tests are green)

@rodneyhbrown7
Copy link

@blomquisg @juliancheal can we merge this PR?

@blomquisg
Copy link
Member

I need to look back at the device_type issue. I should have an answer today.

@blomquisg
Copy link
Member

blomquisg commented Aug 21, 2017

Here's what I'm seeing for guest_device and device_type.

  • Ovirt
    • ethernet
  • Scvmm
    • cdrom
    • ethernet
  • VMware
    • ethernet
    • storage

Based on this, it looks like the previous implementation would have included cdrom devices in the ports list.

Also, the UI is using the ports relationship to show networking information. From this you can see what type of information the UI is expecting to see on the guest_device. Specifically:

  • controller_type
  • device_name
  • location
  • address
  • filename
  • auto_detect

Here's how I think this should change.

Leave the ports relationship alone (even though it's technically wrong today, because it's going to pull in cdrom as well as ethernet). Then, create a new relationship specifically for physical ethernet ports. I suggest calling the relationship physical_ports and the device_type physical_ports instead of ethernet port. That way, it's clear why it's different from the original ports relationship.

This allows us to treat the two concepts differently. If we combined them today into a single field, and then later decide to treat them differently, it's going to be much harder to split them apart later. If we decide to combine them later, that should be much easier.

/cc @Fryguy @roliveri @juliancheal

Thoughts?

@chargio
Copy link
Contributor

chargio commented Aug 23, 2017

Hi @rodneyhbrown7,

Can you comment on the changes @blomquisg is suggesting? There are others PR depending on this one, and it seems that we need to work a little more on this. Is there any approach that would help us to make it faster?

@skovic
Copy link
Author

skovic commented Aug 23, 2017

@blomquisg I believe I have made the changes you requested. Please let me know if I missed anything. Also, as a result of these changes, I had to make an update to the provider in ManageIQ/manageiq-providers-lenovo#73

@miq-bot
Copy link
Member

miq-bot commented Aug 23, 2017

Checked commits skovic/manageiq@e34051c~...faed145 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 3 offenses detected

app/models/ems_refresh/save_inventory.rb

app/models/hardware.rb

@blomquisg blomquisg merged commit 9641a1b into ManageIQ:master Aug 30, 2017
@blomquisg blomquisg added this to the Sprint 68 Ending Sep 4, 2017 milestone Aug 30, 2017
kbrock added a commit to kbrock/manageiq that referenced this pull request Aug 17, 2023
The child_devices added unneeded scope.
This scope pulled back all ids from the guest devices table.

Since the foreign_key is added to the query, this did not do any harm.
But it adds an unneeded constraint an unneeded query.


This was introduce in ManageIQ#15371
The way the PR was batted around, it looked like this was not an intentional side effect.


Before
======

```ruby
has_many :child_devices, -> { where(:parent_device_id => ids) }, :foreign_key => "parent_device_id"
has_many :child_devices, -> { where(:parent_device_id => GuestDevice.ids) }, :foreign_key => "parent_device_id"

SELECT "guest_devices".*
FROM "guest_devices"
WHERE "guest_devices"."parent_device_id" = 26000000000035
  AND "guest_devices"."parent_device_id" IN (26000000000032, 26000000000033, 26000000000034, 26000000000035, 26000000000036, 26000000000037, 26000000000038)
```

After
=====

```ruby
has_many :child_devices, :foreign_key => "parent_device_id"

SELECT "guest_devices".*
FROM "guest_devices"
WHERE "guest_devices"."parent_device_id" = 26000000000035
```
kbrock added a commit to kbrock/manageiq that referenced this pull request Aug 18, 2023
The child_devices added unneeded scope.
This scope pulled back all ids from the guest devices table.

Since the foreign_key is added to the query, this did not do any harm.
But it adds an unneeded constraint an unneeded query.

This was introduce in ManageIQ#15371
The way the PR was batted around, it looked like this was not an intentional side effect.

Before
======

```ruby
has_many :child_devices, -> { where(:parent_device_id => ids) }, :foreign_key => "parent_device_id"
has_many :child_devices, -> { where(:parent_device_id => GuestDevice.ids) }, :foreign_key => "parent_device_id"

SELECT "guest_devices".*
FROM "guest_devices"
WHERE "guest_devices"."parent_device_id" = 26000000000035
  AND "guest_devices"."parent_device_id" IN (26000000000032, 26000000000033, 26000000000034, 26000000000035, 26000000000036, 26000000000037, 26000000000038)
```

After
=====

```ruby
has_many :child_devices, :foreign_key => "parent_device_id"

SELECT "guest_devices".*
FROM "guest_devices"
WHERE "guest_devices"."parent_device_id" = 26000000000035
```
kbrock added a commit to kbrock/manageiq that referenced this pull request Aug 21, 2023
The child_devices added unneeded scope.
This scope pulled back all ids from the guest devices table.

Since the foreign_key is added to the query, this did not do any harm.
But it adds an unneeded constraint an unneeded query.

This was introduce in ManageIQ#15371
The way the PR was batted around, it looked like this was not an intentional side effect.

Before
======

```ruby
has_many :child_devices, -> { where(:parent_device_id => ids) }, :foreign_key => "parent_device_id"
has_many :child_devices, -> { where(:parent_device_id => GuestDevice.ids) }, :foreign_key => "parent_device_id"

SELECT "guest_devices".*
FROM "guest_devices"
WHERE "guest_devices"."parent_device_id" = 26000000000035
  AND "guest_devices"."parent_device_id" IN (26000000000032, 26000000000033, 26000000000034, 26000000000035, 26000000000036, 26000000000037, 26000000000038)
```

After
=====

```ruby
has_many :child_devices, :foreign_key => "parent_device_id"

SELECT "guest_devices".*
FROM "guest_devices"
WHERE "guest_devices"."parent_device_id" = 26000000000035
```
kbrock added a commit to kbrock/manageiq that referenced this pull request Aug 22, 2023
The child_devices added unneeded scope.
This scope pulled back all ids from the guest devices table.

Since the foreign_key is added to the query, this did not do any harm.
But it adds an unneeded constraint an unneeded query.

This was introduce in ManageIQ#15371
The way the PR was batted around, it looked like this was not an intentional side effect.

Before
======

```ruby
has_many :child_devices, -> { where(:parent_device_id => ids) }, :foreign_key => "parent_device_id"
has_many :child_devices, -> { where(:parent_device_id => GuestDevice.ids) }, :foreign_key => "parent_device_id"

SELECT "guest_devices".*
FROM "guest_devices"
WHERE "guest_devices"."parent_device_id" = 26000000000035
  AND "guest_devices"."parent_device_id" IN (26000000000032, 26000000000033, 26000000000034, 26000000000035, 26000000000036, 26000000000037, 26000000000038)
```

After
=====

```ruby
has_many :child_devices, :foreign_key => "parent_device_id"

SELECT "guest_devices".*
FROM "guest_devices"
WHERE "guest_devices"."parent_device_id" = 26000000000035
```
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