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 #12566 - host_parameters_attributes accepts nested flag #2928

Closed
wants to merge 1 commit into from

Conversation

lzap
Copy link
Member

@lzap lzap commented Nov 23, 2015

This is for compatibility reasons. I wish we had an expectation for deprecation
warnings, so we can actually silence them and also test them! Should not be too
difficult to do I guess, ideas?

@@ -82,6 +82,12 @@ def show
param_group :host, :as => :create

def create
params[:host][:host_parameters_attributes] && params[:host] && params[:host][:host_parameters_attributes].each do |a|
Copy link
Contributor

Choose a reason for hiding this comment

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

Testing params[:host] after accessing its :host_parameters_attributes member is the wrong order, as the hypothetical error would be on the first condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, it's being tested twice - remove the first.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, use a longer variable name than a please (attribute?).

Copy link
Member Author

Choose a reason for hiding this comment

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

On Mon, Nov 23, 2015 at 07:23:51AM -0800, Dominic Cleal wrote:

@@ -82,6 +82,12 @@ def show
param_group :host, :as => :create

   def create
  •    params[:host][:host_parameters_attributes] && params[:host] && params[:host][:host_parameters_attributes].each do |a|
    

Oh, it's being tested twice - remove the first.

Yeah, completely screwed copy+paste operation :-)

Later,
Lukas #lzap Zapletal

@domcleal
Copy link
Contributor

I wish we had an expectation for deprecation
warnings, so we can actually silence them and also test them!

Expect it like any other method, i.e. Foreman::Deprecation.expects(:api_deprecation_warning).with(/foo/). No need to test the implementation in a functional test - if we need coverage of the inside, add it to test/unit/foreman_deprecation_test.rb.

Other comments:

  1. missing change to the v1 controller
  2. missing change to the update action on the v2 controller, use a filter like app/controllers/api/v2/operatingsystems_controller.rb (and others) to avoid duplication
  3. apipie parameter docs can specify the format of the hash inside the parameter I think, so it should be possible to add a description to say the inner parameter's deprecated

@lzap
Copy link
Member Author

lzap commented Nov 24, 2015

  1. missing change to the v1 controller
  2. missing change to the update action on the v2 controller, use a filter like app/controllers/api/v2/operatingsystems_controller.rb (and others) to avoid duplication
  3. apipie parameter docs can specify the format of the hash inside the parameter I think, so it should be possible to add a description to say the inner parameter's deprecated

All done, except the extra documentation desc field, I don't know
exactly what parameters are supported at the moment.

Later,
Lukas #lzap Zapletal

@domcleal
Copy link
Contributor

I don't know exactly what parameters are supported at the moment.

Attributes of Parameter (name, value) and attributes that accepts_nested supports (_destroy)?

@@ -1,6 +1,9 @@
module Api
module V1
class HostsController < V1::BaseController
include Api::CompatibilityChecker
before_filter :check_create_host_nested, :only => [:create]
Copy link
Contributor

Choose a reason for hiding this comment

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

Applicable for :update too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Applicable for :update too?

Pushed, without unit test tho, don't think it's necessary.

Later,
Lukas #lzap Zapletal

@domcleal
Copy link
Contributor

  1. This only works for an array style set of nested attributes, it didn't work for me when I tried it the usual UI way (nested hashes), which confused me. The iteration over attributes doesn't take this into account:
2015-11-27T11:42:40 [app] [I] Started POST "/api/v2/hosts" for 127.0.0.1 at 2015-11-27 11:42:40 +0000
2015-11-27T11:42:41 [app] [I] Processing by Api::V2::HostsController#create as JSON
2015-11-27T11:42:41 [app] [I]   Parameters: {"host"=>{"name"=>"test12566a", "hostgroup_name"=>"libvirt", "compute_resource_name"=>"localhost", "host_parameters_attributes"=>{"0"=>{"name"=>"myparam", "value"=>"[FILTERED]", "nested"=>"true"}}}, "apiv"=>"v2"}
...
 | ActiveRecord::UnknownAttributeError: unknown attribute: nested
  1. The tests aren't actually testing this change, only for parameters without the nested attribute.

  2. API docs missing still?

@lzap
Copy link
Member Author

lzap commented Nov 30, 2015

  1. API docs missing still?

How to document both array and hash input?

Later,
Lukas #lzap Zapletal

@domcleal
Copy link
Contributor

I don't know, you'll have to look at apipie-bindings. Documenting one is probably fine.

@lzap
Copy link
Member Author

lzap commented Nov 30, 2015

I don't know, you'll have to look at apipie-bindings. Documenting one is probably fine.

Right, documented the array with a comment for hash.

Pushed.

Later,
Lukas #lzap Zapletal

@ohadlevy
Copy link
Member

ohadlevy commented Nov 30, 2015 via email

@domcleal
Copy link
Contributor

There are test failures, please take a look.

@lzap
Copy link
Member Author

lzap commented Nov 30, 2015

do we want to support both array and a hash? AFAIR one is for create the
other for update?

We do support both now, the checker just deletes the attribute and
issues a warning, so not a big deal to do this on both. Eventually we
will remove this.

Later,
Lukas #lzap Zapletal

@lzap
Copy link
Member Author

lzap commented Nov 30, 2015

There are test failures, please take a look.

Strange, my rubocop was/is green. Fixed.

Later,
Lukas #lzap Zapletal

@domcleal
Copy link
Contributor

Strange, my rubocop was/is green. Fixed.

You may have to take into account that our Jenkins jobs are configured to test the PR when rebased/merged onto develop (to pick up any potential logical/non-patch conflicts). It's possible that a test passes on the branch but not when added to the current state of the base branch.

@lzap
Copy link
Member Author

lzap commented Nov 30, 2015

Damn squashed it into incorrect PR, hold on.

@lzap
Copy link
Member Author

lzap commented Nov 30, 2015

Pushed.

@@ -62,7 +65,10 @@ def show
param :owner_type, Host::Base::OWNER_TYPES, :desc => N_("Host's owner type")
param :puppet_ca_proxy_id, :number
param :image_id, :number
param :host_parameters_attributes, Array
param :host_parameters_attributes, Array, :desc => N_("Host's parameters (array or indexed hash)") do
param :name, String, :desc => "Name of the parameter", :required => true
Copy link
Contributor

Choose a reason for hiding this comment

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

missing string extraction here

@@ -45,7 +48,10 @@ def show
param :owner_id, :number
param :puppet_ca_proxy_id, :number
param :image_id, :number
param :host_parameters_attributes, Array
param :host_parameters_attributes, Array, :desc => N_("Host's parameters (array or indexed hash)") do
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation's off here, and there's no need for translations in the v1 controller

@domcleal
Copy link
Contributor

domcleal commented Jan 4, 2016

This missed 1.10.0 as the latest comment wasn't fixed, but remains on the .1 list. If you could rebase it and fix the comment, it'd be appreciated.

@domcleal
Copy link
Contributor

Hello? Quite a trival comment, but please fix it and rebase the PR.

@domcleal
Copy link
Contributor

Merged as and fixed up in 7ee381e.

@domcleal domcleal closed this Jan 14, 2016
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