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

Ability to see/save Config settings for Region and Zone records. #3967

Merged

Conversation

h-kataria
Copy link
Contributor

@h-kataria h-kataria commented May 21, 2018

Exposed 'Advanced' tab for Region/Zone nodes.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1082155

Before:

server_before

zone_before

region_before

After, Note has been updated on the Server level. Exposed Advanced tab on Region and Zone level:

server_after

zone_after

region_after

Dependent upon core PR: Core PR: ManageIQ/manageiq#17458

@h-kataria
Copy link
Contributor Author

@Fryguy need help with saving of config settings for Zone/Region record, please see spec test failure

OpsController OpsController::Settings::Common #settings_update_save save config settings for selected zone
     Failure/Error: resource.set_config(config)
     
     NoMethodError:
       undefined method `set_config' for #<Zone:0x0000000034193370>
     # ./spec/manageiq/lib/vmdb/config.rb:56:in `save'
     # ./spec/manageiq/lib/vmdb/config.rb:76:in `save_file'
     # ./app/controllers/ops_controller/settings/common.rb:263:in `save_advanced_settings'
     # ./app/controllers/ops_controller/settings/common.rb:459:in `settings_update_save'
     # ./spec/controllers/ops_controller/settings/common_spec.rb:342:in `block (5 levels) in <top (required)>'

@carbonin
Copy link
Member

To fix this spec failure, can we use resource.add_settings_for_resource(@edit[:new][:file_data]) here instead of ManageIQ/manageiq#17458 ?

@Fryguy
Copy link
Member

Fryguy commented May 21, 2018

I agree with @carbonin. Technically set_config is a deprecated method, and add_settings_for_resource is preferred.

Scratch that. save_file is indeed the correct method to call because it also handles validation and error reporting. save_file itself should probably be changed to not support set_config, but the way it does it now is kind of convoluted and I don't expect you to change that for this change.

So, again back to my original question...what methods are needed from MiqServer::ConfigurationManagement?

@h-kataria
Copy link
Contributor Author

@carbonin i can't use resource.add_settings_for_resource(@edit[:new][:file_data]) directly from controller, because add_settings_for_resource does not expect settings in yaml format so i think we do need ManageIQ/manageiq#17458

@Fryguy
Copy link
Member

Fryguy commented May 29, 2018

I created a new backend PR ManageIQ/manageiq#17494, which handles the various nuances better.

@Fryguy
Copy link
Member

Fryguy commented May 29, 2018

@h-kataria With the new backend PR, you should also be able to remove the get_file and save_file references with something like the following diff:

diff --git a/app/controllers/ops_controller/settings/common.rb b/app/controllers/ops_controller/settings/common.rb
index 08bcff353..7b256ae84 100644
--- a/app/controllers/ops_controller/settings/common.rb
+++ b/app/controllers/ops_controller/settings/common.rb
@@ -253,16 +253,17 @@ module OpsController::Settings::Common
 
   def fetch_advanced_settings(resource)
     @edit = {}
-    @edit[:current] = {:file_data => VMDB::Config.get_file(resource)}
+    @edit[:current] = {:file_data => resource.settings_for_resource_yaml}
     @edit[:new] = copy_hash(@edit[:current])
     @edit[:key] = "#{@sb[:active_tab]}_edit__#{@sb[:selected_server_id]}"
     @in_a_form = true
   end
 
   def save_advanced_settings(resource)
-    result = VMDB::Config.save_file(@edit[:new][:file_data], resource) # Save the config file
-    if result != true # Result contains errors?
-      result.each do |field, msg|
+    begin
+      resource.add_settings_for_resource_yaml(@edit[:new][:file_data])
+    rescue Vmdb::Settings::ConfigurationInvalid => err
+      err.errors.each do |field, msg|
         add_flash("#{field.to_s.titleize}: #{msg}", :error)
       end
       @changed = (@edit[:new] != @edit[:current])

@h-kataria
Copy link
Contributor Author

@Fryguy made suggested changes to use new methods from ManageIQ/manageiq#17494

@Fryguy
Copy link
Member

Fryguy commented May 30, 2018

core PR is merged

resource = if selected?(x_node, "z")
Zone.find(nodes.last)
elsif selected?(x_node, "svr")
MiqServer.find(@sb[:selected_server_id])
Copy link
Member

Choose a reason for hiding this comment

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

You still have the wrong number of indent here and on 2 lines above.

= _("Caution: Manual changes to configuration files can disable the Server!")
- warning_msg = _("Caution: Manual changes to configuration files can disable the #{selected_node_title}!")
- if selected?(x_node, "z") || selected?(x_node, "svr")
- warning_msg << _(" Changes made to any individual settings will overwrite settings inherited from the #{selected_node_parent_title}")
Copy link
Member

Choose a reason for hiding this comment

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

I think you need a period or exclamation point at the end of this sentence.

:id => 'advanced')
data = {}
data.store_path(:api, :token_ttl, "1.day")
data = data.to_yaml
Copy link
Member

@Fryguy Fryguy May 30, 2018

Choose a reason for hiding this comment

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

These 3 lines can be simplified to data = {:api => {:token_ttl => "1.day"}}

@Fryguy
Copy link
Member

Fryguy commented May 30, 2018

@h-kataria I made a few minor comments, and please take care of the rubocops, but otherwise this LGTM.

@h-kataria h-kataria force-pushed the advanced_config_for_zone_and_region branch 4 times, most recently from d5c8d93 to 8040f11 Compare May 30, 2018 15:04
@h-kataria h-kataria removed the wip label May 30, 2018
@h-kataria h-kataria changed the title [WIP] - Ability to see/save Config settings for Region and Zone records. Ability to see/save Config settings for Region and Zone records. May 30, 2018
@h-kataria h-kataria assigned dclarizio and unassigned mzazrivec May 30, 2018
@h-kataria h-kataria requested a review from lgalis May 30, 2018 17:17
Copy link
Member

@Fryguy Fryguy left a comment

Choose a reason for hiding this comment

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

LGTM...Have one minor comment but I wouldn't hold up a merge for it.

@@ -6,7 +6,10 @@
%span.pficon.pficon-error-octagon
%span.pficon.pficon-error-exclamation
%strong
= _("Caution: Manual changes to configuration files can disable the Server!")
- warning_msg = _("Caution: Manual changes to configuration files can disable the #{selected_node_title}!")
- if selected?(x_node, "z") || selected?(x_node, "svr")
Copy link
Member

Choose a reason for hiding this comment

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

Minor, but technically this logic is duplicated here and in the selected_node_parent_title. You could de-dup that logic by changing selected_node_parent_title to return nil for regions, and then there just do if selected_node_parent_title

MiqServer.find(@sb[:selected_server_id])
else
MiqRegion.my_region
end
Copy link
Member

Choose a reason for hiding this comment

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

Also minor, but this is also a duplicated pattern with the selected_node_title methods. I think this would be cleaner extracted as a selected_node method that lives with the rest in ops_helper (if possible). In this way all of the "if selected?(x_node..." logic lives in one place.

@h-kataria h-kataria force-pushed the advanced_config_for_zone_and_region branch from 8040f11 to c1c0bdb Compare May 30, 2018 19:20
@miq-bot
Copy link
Member

miq-bot commented May 30, 2018

Checked commit h-kataria@c1c0bdb with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. ⭐

Copy link
Contributor

@lgalis lgalis left a comment

Choose a reason for hiding this comment

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

Looks good - tested saving the settings on region/server/zone.

@dclarizio dclarizio merged commit 52b3fdb into ManageIQ:master May 31, 2018
@dclarizio dclarizio added this to the Sprint 87 Ending Jun 4, 2018 milestone May 31, 2018
@@ -6,7 +6,10 @@
%span.pficon.pficon-error-octagon
%span.pficon.pficon-error-exclamation
%strong
= _("Caution: Manual changes to configuration files can disable the Server!")
- warning_msg = _("Caution: Manual changes to configuration files can disable the #{selected_node_title}!")
Copy link
Contributor

Choose a reason for hiding this comment

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

May I add that string interpolation will not work in gettext strings. Also, it's not usually a good idea to concatenate strings that are meant to be translated (since it complicates work for translators).

#4018

h-kataria added a commit to h-kataria/manageiq-ui-classic that referenced this pull request May 31, 2018
@h-kataria h-kataria mentioned this pull request May 31, 2018
@h-kataria h-kataria deleted the advanced_config_for_zone_and_region branch July 23, 2018 16:07
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.

7 participants