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

fixes #4198 - API v2 - add child nodes to show responses. Ex. architecture should show operating systems node #1208

Closed
wants to merge 3 commits into from

Conversation

isratrade
Copy link
Member

No description provided.

@@ -2,5 +2,6 @@ object @hostgroup

extends "api/v2/hostgroups/base"

attributes :subnet_id, :subnet_name, :operatingsystem_id, :operatingsystem_name, :domain_id, :domain_name, :environment_id, :environment_name,
:compute_profile_id, :compute_profile_name, :ancestry, :parameters, :puppetclass_ids
Copy link
Member Author

Choose a reason for hiding this comment

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

:parameters, :puppetclass_ids were removed here and moved to child nodes in show.json.rabl

@@ -11,3 +11,11 @@ end
child :operatingsystems, :object_root => false do
extends "api/v2/operatingsystems/base"
end

child :environments, :object_root => false do
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say either remove this, or add host groups here, since config templates are associated with env/host.

Because we have template combinations though, I'd prefer to remove environments.

Copy link
Member Author

Choose a reason for hiding this comment

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

@domcleal, removing environments

@domcleal
Copy link
Contributor

Could you check the test failure too please?

@domcleal
Copy link
Contributor

Do you want to address http://projects.theforeman.org/issues/4349 too, and add orgs/loc child nodes?

@isratrade
Copy link
Member Author

@domcleal, I was looking at this issue now.

@isratrade
Copy link
Member Author

@domcleal, fixed, rebased, and included commit for fixes #4349

@isratrade
Copy link
Member Author

this is really strange that the 2 failing tests pass locally for me. My is that SETTINGS[:locations_enabled] or SETTINGS[:organizations_enabled] is not being read as true.

@@ -20,6 +20,8 @@
# need to restart spork for it take effect.

ENV["RAILS_ENV"] = "test"
SETTINGS[:locations_enabled] = true
SETTINGS[:organizations_enabled] = true
Copy link
Member Author

Choose a reason for hiding this comment

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

re-committed after adding these two lines

@domcleal
Copy link
Contributor

@isratrade getting some test failures?

@isratrade
Copy link
Member Author

The test failures are strange since it passes locally. I thought adding SETTINGS[:locations_enabled] = true to test_helper.rb would work, but it doesn't. Any ideas what could be on my local setup that isn't on Jenkins??

@isratrade
Copy link
Member Author

@domcleal, I just ran the tests again and no failures on my local dev

@domcleal
Copy link
Contributor

Jenkins already sets locations/orgs_enabled in settings.yaml before running tests, so there shouldn't be anything different....

@domcleal
Copy link
Contributor

Something Bad happened on the last test run, I'd suggest running git commit --amend and re-pushing to get Jenkins to re-run.

In any case, I'm able to reproduce four test failures locally: https://gist.github.com/domcleal/9068336

@domcleal
Copy link
Contributor

Quick investigation into the first error shows this response being formed:

Rendered api/v1/errors/unprocessable_entity.json.rabl (1.7ms)
Body: {"config_template":{"id":1007981701,"errors":{"base":["centos5_3_pxelinux is used by #<OsDefaultTemplate:0x000    0000d605b28>","centos5_3_pxelinux is used by #<OsDefaultTemplate:0x0000000d7480d0>"]},"full_messages":["centos5_3_pxelinux is used by #<OsDefaultTemplate:0x0000000d605b28>","centos5_3_pxelinux is used by #<OsDefaultTemplate:0x0000000d7480d0>"]}}
Completed 422 Unprocessable Entity in 192.3ms (Views: 8.4ms | ActiveRecord: 3.2ms)

But then later in the request, the error handling throws an error too, causing the response code to change to 500!

  1 resource have no errors (RuntimeError)
  2 /home/dcleal/code/foreman/foreman/app/controllers/api/base_controller.rb:74:in `process_resource_error'
  3 /home/dcleal/code/foreman/foreman/app/controllers/api/base_controller.rb:93:in `process_response'
  4 /home/dcleal/code/foreman/foreman/app/controllers/api/v1/config_templates_controller.rb:72:in `destroy'

@domcleal
Copy link
Contributor

Hmm, I get entirely different failures to Jenkins, strange.

@isratrade
Copy link
Member Author

created new branch from develop. cherry-picked and --amend both commits. all tests pass locally. let's hope they pass on our good friend jenkins

@isratrade
Copy link
Member Author

still same 2 failing tests, can any else download this patch and run the tests locally. It's hard to debug when it passes for me locally. @GregSutcliffe, @elobato

@dLobatog
Copy link
Member

Tested it locally, maybe this will shed some light on this:

(rdb:1) Domain.first.locations
[#<Location id: 255093256, name: "Location 1", type: "Location", created_at: "2014-02-18 20:08:44", updated_at: "2014-02-18 20:08:44", ignore_types: []>]
(rdb:1) Domain.first.organizations
[#<Organization id: 447626438, name: "Organization 1", type: "Organization", created_at: "2014-02-18 20:08:44", updated_at: "2014-02-18 20:08:44", ignore_types: []>]
   88        debugger
=> 89        assert show_response.keys.include?(node), "'#{node}' child node should be in response but was not"
   90      end
   91    end
   92  
   93  end
(rdb:1) show_response
{"id"=>22495316, "name"=>"mydomain.net", "fullname"=>nil, "dns_id"=>113629430, "created_at"=>"2014-02-18T20:08:44Z", "updated_at"=>"2014-02-18T20:08:44Z", "parameters"=>[{"id"=>665394701, "name"=>"parameter", "value"=>"value1"}], "interfaces"=>[], "taxonomies"=>[{"id"=>447626438, "name"=>"Organization 1"}], "subnets"=>[]}

The "taxonomies" subnode is created by

partial("api/v2/taxonomies/children_nodes", :object => domain)

instead of "organizations" and "locations".

@isratrade
Copy link
Member Author

@elobato, here is what I get when I inspect show_response

{"id"=>22495316, "name"=>"mydomain.net", "fullname"=>nil, "dns_id"=>113629430, "created_at"=>"2014-02-19T07:36:03Z", "updated_at"=>"2014-02-19T07:36:03Z", "parameters"=>[{"id"=>665394701, "name"=>"parameter", "value"=>"value1"}], "interfaces"=>[], "locations"=>[{"id"=>255093256, "name"=>"Location 1"}], "organizations"=>[{"id"=>447626438, "name"=>"Organization 1"}], "subnets"=>[]}

I have nodes organizations" and "locations" and no node "taxonomies" like you have. I wonder what the difference in our code base.
I'm using rabl-0.8.6. I'll update it and see what happens.

@@ -15,7 +15,7 @@ gem 'scoped_search', '>= 2.5'
gem 'net-ldap'
gem 'uuidtools'
gem "apipie-rails", "~> 0.0.23"
gem 'rabl', '>= 0.7.5', '<= 0.9.0'
gem 'rabl', '>= 0.7.5', '< 0.9.0'
Copy link
Member Author

Choose a reason for hiding this comment

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

@elobato, here's the culprit. It fails with rabl 0.9.0. @domcleal, the latest rabl version is 0.9.3. Let's prevent users from using 0.9.x

Copy link
Contributor

Choose a reason for hiding this comment

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

@isratrade hm, this could be a problem as I know @jlsherrill updated the rabl RPM to 0.9.0 recently to fix something else. Can we dig in a bit deeper and identify the issue on 0.9.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

@domcleal, will do, but in that case, let's allow all 0.9.x. Any reason to limit to 0.9.0?

Copy link
Contributor

Choose a reason for hiding this comment

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

@isratrade good point, I don't know why that was. I don't mind shipping a newer version, should be easy to build.

…x. architecture should show operating systems node
@@ -0,0 +1,11 @@
if SETTINGS[:locations_enabled]
child :locations => :locations do
Copy link
Member Author

Choose a reason for hiding this comment

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

This should do the trick.

+  child :locations => :locations

I tried tries, but it causes an error and apparently :object_root => false isn't needed like I thought.

  child :locations => :locations, :object_root => false

Somebody else also reported this issue from 0.9 to 0.9 on STI models nesquena/rabl#505

…nodes to user, domain, subnet, etc show json templates
@isratrade
Copy link
Member Author

@elobato, @domcleal, passing tests on jenkins now, finally :)

@domcleal
Copy link
Contributor

@isratrade nice one. There are still a few unresolved comments above, particularly for interfaces and environments versus template combinations - could you double check these please?

@isratrade
Copy link
Member Author

@domcleal, changes per your and @GregSutcliffe's comments.
I removed all :object_root => false, since it doesn't seem to matter. I remember that it did previously, so I hope this doesn't come back to bite me.
You (or I) can squash last commit after your review.

@@ -2,22 +2,30 @@ object @operatingsystem

extends "api/v2/operatingsystems/main"

child :media, :object_root => false do
node do |operatingsystem|
{ :parameters => partial("api/v2/parameters/base", :object => operatingsystem.parameters) }
Copy link
Contributor

Choose a reason for hiding this comment

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

[fixed] What's going on here, shouldn't this be a child node?

@domcleal
Copy link
Contributor

Merged as d8b61e3, 8d113bd for Foreman 1.5.0, thanks @isratrade.

@domcleal domcleal closed this Feb 21, 2014
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.

4 participants