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 defaults for immutability of MiddlewareServers #14822

Merged
merged 1 commit into from
Apr 25, 2017

Conversation

cfcosta
Copy link

@cfcosta cfcosta commented Apr 20, 2017

This fixes BZ https://bugzilla.redhat.com/show_bug.cgi?id=1443881 by providing a saner default for server mutability.

@abonas
Copy link
Member

abonas commented Apr 20, 2017

@miq-bot add_label bug, providers/hawkular

@abonas
Copy link
Member

abonas commented Apr 20, 2017

@miq-bot assign @Jiri-Kremser

@abonas
Copy link
Member

abonas commented Apr 20, 2017

@mtho11 @Jiri-Kremser please review

# reimplement this method if necessary.
def immutable?
true
false
Copy link
Member

Choose a reason for hiding this comment

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

Changing the hard-coded value from true to false will result in another issue. Running the power ops on dockerized servers. But agent doesn't allow that, so the MiQ ui will allow that but it fails. Why is the value hard-coded and not read from the properties? The idea is that all the hawkular servers running in the docker container have the immutable flag and they told it about themselves in the properties.

I don't get why there is always true or false, or is this method overriden somewhere?

Copy link
Author

Choose a reason for hiding this comment

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

It is overwritten here: https://github.com/ManageIQ/manageiq-providers-hawkular/blob/master/app/models/manageiq/providers/hawkular/middleware_manager/middleware_server.rb

As of now I'm tracking what might be the error where this class is not being instantiated on miq-core, so this change would only change the default if the provider does not have a different implementation.

Copy link
Member

Choose a reason for hiding this comment

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

I see, I was doing the grep only over this repo

@abonas
Copy link
Member

abonas commented Apr 25, 2017

@miq-bot add_label fine/yes
for now lets wait for @durandom before merging, for the chance of getting to the bottom of the issue and potentially issuing a cleaner solution

@durandom
Copy link
Member

As of now I'm tracking what might be the error where this class is not being instantiated on miq-core

Thats right, but actually that has never been the case 😟
Because the schema is missing a STI column

So while you can ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer.new.save it wont be the subclass if you load it from the db again.
You'll have to include the NewWithTypeStiMixin in the base class and add a type column to the db.
Maybe this is also broken/missing for other models?

So, to fix this, you'll have to move the method implementation over here. like:

def immutable?
  if properties.has_key? 'Immutable'
   properties['Immutable'] == 'true'
  else
   true
  end
end

@durandom
Copy link
Member

@cfcosta you should probably use the factory in the specs for immutable and reload the object from db. That should give you a failing spec

@abonas
Copy link
Member

abonas commented Apr 25, 2017

@durandom thanks a lot for investigating this.

Thats right, but actually that has never been the case 😟
Because the schema is missing a STI column

So while you can ManageIQ::Providers::Hawkular::MiddlewareManager::MiddlewareServer.new.save it wont be the subclass if you load it from the db again.
You'll have to include the NewWithTypeStiMixin in the base class and add a type column to the db.
Maybe this is also broken/missing for other models?

the above should be done after 'fine' release as the fine branch no longer receives db changes.

So, to fix this, you'll have to move the method implementation over here. like:

the below should be done now in order to fix it in 'fine'.
Looks like it should be in this PR.
@cfcosta wdyt?

def immutable?
if properties.has_key? 'Immutable'
properties['Immutable'] == 'true'
else
true
end
end

@durandom
Copy link
Member

When you are doing the follow up PR, maybe you want to lead the way and namespace all middleware_ models under Middleware? So MiddlewareServer would become Middleware::Server

I see that could be of use for containers and storage and other models too.

@abonas
Copy link
Member

abonas commented Apr 25, 2017

@miq-bot assign @durandom
@cfcosta , @Jiri-Kremser @durandom please work on resolving this asap without the STI fix so it can enter the 'fine' branch. and we'll definitely need the "right" STI solution afterwards

@miq-bot miq-bot assigned durandom and unassigned jkremser Apr 25, 2017
This commit backports the change extracted to
manageiq-providers-hawkular, for use with the 5.8 release of CloudForms.
It is meant to be replaced later with a type column in the affected
models, allowing the proper use of STI.
@cfcosta cfcosta force-pushed the fix-immutability-defaults-for-ms branch from 9cb08a9 to be1592d Compare April 25, 2017 14:43
@miq-bot
Copy link
Member

miq-bot commented Apr 25, 2017

Checked commit cfcosta@be1592d with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks good. 🏆

@cfcosta
Copy link
Author

cfcosta commented Apr 25, 2017

@durandom @Jiri-Kremser @abonas did the changes you suggested. I'm creating a followup PR for doing the migration of the data and implementing STI correctly, will post later today and we can discuss how to proceed for the next version.

@durandom
Copy link
Member

@miq-bot assign @blomquisg
@blomquisg please merge, follow up PRs will do this properly

@miq-bot miq-bot assigned blomquisg and unassigned durandom Apr 25, 2017
@@ -42,11 +42,11 @@ def in_domain?

# Returns whether a server is immutable or not.
#
# By default, we define all servers as being immutable, so that power
# operations are not allowed, and it is the provider responsability to
# By default, we define all servers as being mutable, so that power
Copy link
Member

Choose a reason for hiding this comment

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

The changed code in this method looks fine, but the comment here seems wrong.

It doesn't look like it's defaulting to mutable. It looks like it's defaulting to whatever the properties are.

Copy link
Member

Choose a reason for hiding this comment

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

too much boolean logic here.
the default is an empty {}, which does not have the property and hence returns false which is not immutable which is mutable

so the comment is right... once you meditate long enough 😄

maybe drop or rephrase it in a later pr

Copy link
Member

Choose a reason for hiding this comment

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

Ha! K, thanks for the logic test @durandom :)

@blomquisg blomquisg merged commit 16c4345 into ManageIQ:master Apr 25, 2017
@blomquisg blomquisg added this to the Sprint 60 Ending May 8, 2017 milestone Apr 25, 2017
simaishi pushed a commit that referenced this pull request Apr 27, 2017
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit d1f688853c1b4d697dcf95b8294d394a99e8332f
Author: Greg Blomquist <blomquisg@gmail.com>
Date:   Tue Apr 25 14:06:45 2017 -0400

    Merge pull request #14822 from cfcosta/fix-immutability-defaults-for-ms
    
    Fix defaults for immutability of MiddlewareServers
    (cherry picked from commit 16c43457b788ae12d49929ce1e696fd1f3e445cb)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1446387

@cfcosta cfcosta deleted the fix-immutability-defaults-for-ms branch May 4, 2017 16:39
cfcosta pushed a commit to cfcosta/manageiq that referenced this pull request May 23, 2017
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1443094, and is a followup
to ManageIQ#14822. It adds a type column to all classes related to Middleware, thus
enabling Single Table Inheritance from Rails.
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.

8 participants