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

Anonymous FTP request single file prompt (vs 2) #69

Merged
merged 7 commits into from
Oct 23, 2018

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Oct 4, 2018

We were prompting for a local data filename and a remote url.
But since this is streaming, it does not make sense.

This now:

  • properly populates the :remote_file_name value
  • hides/shows the prompt selectively for dump, backup, restore
  • has configurable rake options

related to:

configuration has been tweaked:

  database_admin:
    menu_order:
    - local
    - ftp://ftp.example.com/incoming/
    local: Local file
    prompts:
      ftp.example.com:
        enabled_for: ["backup", "dump"]
        filename_text: "The case number dash (-) filename. (e.g.: 12345-db.backup)"
        filename_validator: "^[0-9]{4,}-..*"
        rake_options:
          skip_directory: true

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

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

I will have to look over this more in a bit, but this should be enough to get you started.

uri_filename = ask_custom_prompt(hostname, 'filename', "Target filename (e.g.: #{sample_case})")
@uri = server_uri.gsub(sample_case, uri_filename)
hostname = URI(server_uri).host
@filename = ask_custom_prompt(hostname, 'filename', "Target filename for backup")
Copy link
Member

Choose a reason for hiding this comment

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

I realize this was added in the previous PR, and I wasn't really the reviewer, but why are we "passing" the default prompt if this method is only used in one spot?

I was reviewing a similar PR that @carbonin was (where he asked to axe some constants), but this seems like it makes more sense to just have this as a constant, or a frozen string in the method itself instead of passing it from here.

Copy link
Member

Choose a reason for hiding this comment

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

Also (not part of this line of code), but I think you can delete the constants at the top of this file for LOCAL_FILE, NFS_FILE, etc. since we don't use them any more (as of #65).

Separate commit/PR maybe? I think you would have a lot of tests that would need to be updated, for what it is worth.

Copy link
Member Author

@kbrock kbrock Oct 4, 2018

Choose a reason for hiding this comment

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

ok, will make the prompt less generic.

Those constants are used all over the specs :( They have been simplified quite a bit (now just have 'ftp' vs the full text of the ftp string) -- we can hardcode phrases like "ftp" in the specs.

spec/database_admin_spec.rb Show resolved Hide resolved
@kbrock kbrock force-pushed the single_backup_prompt branch from efbac8b to d07b9f4 Compare October 4, 2018 18:54
@kbrock
Copy link
Member Author

kbrock commented Oct 4, 2018

ok

  • added the missing tests (they felt a little copy paste),
  • fixed custom_file prompt (removed the genericness)
  • removed the constants (that were only used in specs)

keep 'em comin'

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

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

Got a few things I need to look into yet (I think...), but a few more things I noticed.

@@ -38,6 +32,10 @@ def initialize(action = :restore, input = $stdin, output = $stdout)
@task_params = []
end

def local_backup?
backup_type == "local"
Copy link
Member

Choose a reason for hiding this comment

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

Pendantic: "local".freeze

Copy link
Member

Choose a reason for hiding this comment

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

But yes, I like this change. 👍

prompt_regex = prompts && prompts["#{prompt_name}_validator".to_sym]
def ask_custom_file_prompt(hostname)
# hostname has a period in it, so we need to look it up by [] instead of the traditional i18n method
prompts = I18n.t("database_admin.prompts", :default => nil).try(:[], hostname.to_sym)
Copy link
Member

Choose a reason for hiding this comment

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

Is the .try(:[], ...) necessary? I figured the .to_sym would handle and case you would be concerned about, and return a nil if nothing exists for it. Right?

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 would have to change the :default to {}, but I think this would work after that:

prompts = I18n.t("database_admin.prompts", :default => {})[hostname.to_sym]

@kbrock kbrock force-pushed the single_backup_prompt branch from d07b9f4 to 4dab261 Compare October 15, 2018 13:24
@kbrock
Copy link
Member Author

kbrock commented Oct 15, 2018

@NickLaMuro thanks - got in the freeze and the :default => {} -- very nice touch with that one.

We were prompting for a local data filename and a remote url.
But since this is streaming, it does not make sense.

this now properly populates the :remote_file_name value
@kbrock kbrock force-pushed the single_backup_prompt branch from 4dab261 to 1710eb3 Compare October 15, 2018 15:35
Copy link
Member

@carbonin carbonin 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 to me. That spec file is getting hard to read, but too many tests is a good problem to have IMO 😄

@NickLaMuro anything more to add here?

@kbrock kbrock changed the title Anonymous FTP request single file prompt (vs 2) [WIP] Anonymous FTP request single file prompt (vs 2) Oct 16, 2018
@miq-bot miq-bot added the wip label Oct 16, 2018
@kbrock
Copy link
Member Author

kbrock commented Oct 16, 2018

@NickLaMuro What I used to configure the appliance console in local development to act like the appliance vm and pickup my localization changes

$ pwd
/Users/kbrock/src/manageiq-appliance_console
$ cat ~/src/manageiq/productization/appliance_console/locales/appliance/en_productization.yml
---
en:
  database_admin:
    menu_order:
    - local
    - ftp://ftp.example.com/incoming
    local: Local file
    prompts:
      ftp.example.com:
        filename_text: "The case number dash (-) filename. (e.g.: 12345-db.backup)"
        filename_validator: "^[0-9]{4,}-..*"
$ bundle exec irb -I lib
irb> module ManageIQ; module ApplianceConsole; RAILS_ROOT = File.expand_path("../manageiq", Dir.pwd); end; end
# => "/Users/kbrock/src/manageiq"  
irb> require 'manageiq/appliance_console/i18n'
# => true  
irb> I18n.t("database_admin.prompts", :default => {})
# => {
  :"ftp.example.com"=>{
    :filename_text=>"The case number dash (-) filename. (e.g.: 12345-db.backup)",
    :filename_validator=>"^[0-9]{4,}-..*"
  }
}  
irb> I18n.load_path
# => [
  "/Users/kbrock/src/manageiq-appliance_console/locales/appliance/en.yml",
  "/Users/kbrock/src/manageiq/productization/appliance_console/locales/appliance/en_productization.yml"
]  

@kbrock kbrock changed the title [WIP] Anonymous FTP request single file prompt (vs 2) Anonymous FTP request single file prompt (vs 2) Oct 17, 2018
@miq-bot miq-bot removed the wip label Oct 17, 2018
Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

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

I think these comments are best left for another PR, if at all, but tossing them out there anyway.

Feel free to merge without the changes.

params[:remote_file_name] = filename if filename
params = {
:uri => uri,
:skip_directory => true,
Copy link
Member

Choose a reason for hiding this comment

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

I am fine with this for now, but I think in the end, this should be part of the configuration, and not hard coded in.

Copy link
Member

Choose a reason for hiding this comment

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

Along with this, I really feel we should be hiding this option, or allowing it to be configured to do so, for the restore options since this is ultimately being implemented for an endpoint you won't be able to restore from.

Might need a follow up, but just my two cents.

@kbrock kbrock changed the title Anonymous FTP request single file prompt (vs 2) [WIP] Anonymous FTP request single file prompt (vs 2) Oct 17, 2018
@kbrock
Copy link
Member Author

kbrock commented Oct 17, 2018

WIPping to find a more configurable way of adding flags for specific backup options

@miq-bot miq-bot added the wip label Oct 17, 2018
@kbrock
Copy link
Member Author

kbrock commented Oct 17, 2018

Along with this, I really feel we should be hiding this option, or allowing it to be configured to do so, for the restore options since this is ultimately being implemented for an endpoint you won't be able to restore from.
-- @NickLaMuro

Further clarifying this comment:

For our current use case, this option should be displayed for backup and dump, but should be hidden for the restore menu.
There are 2 possible solutions so far for configuration:

the dry solution <== winner

@NickLaMuro suggests dry. It is no fun to have duplicate lists - duplication tends to go wrong quickly.

We display menu_order for all entries, unless an entry has enable_for key and the key does not include the current menu name (i.e.: dump, backup, restore).

---
  database_admin:
    menu_order:
    - local
    - ftp://ftp.example.com/incoming/
    local: Local file
    prompts:
      ftp.example.com:
        enabled_for: [dump, backup]  ###### NEW FEATURE
        filename_text: "The case number dash (-) filename. (e.g.: 12345-db.backup)"
        filename_validator: "^[0-9]{4,}-.+"

the less logic solution

@kbrock suggests duplicating but removing special parameters that negate the list. Duplication stinks, but conditional logic is worse.

If {restore, backup, dump}_menu_order is available, display that. Otherwise fall back to display menu_order.

---
  database_admin:
    menu_order:
    - local
    - ftp://ftp.example.com/incoming/
    restore_menu_order:    ###### NEW FEATURE
    - local
    - ftp://ftp.example.com/incoming/
    local: Local file
    prompts:
      ftp.example.com:
        filename_text: "The case number dash (-) filename. (e.g.: 12345-db.backup)"
        filename_validator: "^[0-9]{4,}-.+"

call it ask_custom_file_prompts and don't pretend that we are going
to extend this
@kbrock kbrock force-pushed the single_backup_prompt branch from 1710eb3 to c8df718 Compare October 18, 2018 12:49
@kbrock kbrock changed the title [WIP] Anonymous FTP request single file prompt (vs 2) Anonymous FTP request single file prompt (vs 2) Oct 18, 2018
@miq-bot miq-bot removed the wip label Oct 18, 2018
@kbrock kbrock force-pushed the single_backup_prompt branch from c8df718 to 933c04e Compare October 18, 2018 12:54
These constants were useful at a time, but are currently only used
in tests. so they have been removed
some options are only available for restore vs backup

This allows an options to be available for only one of them
@kbrock kbrock force-pushed the single_backup_prompt branch from 933c04e to 28ca993 Compare October 18, 2018 13:05
@kbrock
Copy link
Member Author

kbrock commented Oct 18, 2018

added rake_options and made custom endpoints enabled for various options (backup, dump, restore)

Does this work for you now @NickLaMuro ?

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

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

I think this looks good. Thanks for taking the extra time on this!

Comments left are minor, and not required... unless you want to be shamed for merging in a typo 😉

hostname = URI(server_uri).host
uri_filename = ask_custom_prompt(hostname, 'filename', "Target filename (e.g.: #{sample_case})")
@uri = server_uri.gsub(sample_case, uri_filename)
hostname = URI(server_uri).host
Copy link
Member

Choose a reason for hiding this comment

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

This is minor:

I found this a bit confusing to me for a bit since I saw you parsing out the host from the server_uri, and thought that was being being assigned to @uri. Turns out that wasn't the case, but we also aren't using the hostname in any meaningful fashion except as a key. Seems like we could just as easily do this:

  database_admin:
    menu_order:
    - local
    - ftp://ftp.example.com/incoming/
    local: Local file
    prompts:
      ftp://ftp.example.com/incoming/:
        enabled_for: ["backup", "dump"]
        ...

And achieve the same affect by just passing around server_uri as the key.


Again, this is minor, just thought it was a bit confusing from both a code and configuration perspective since there is two different "keys" being passed around.

Copy link
Member Author

@kbrock kbrock Oct 23, 2018

Choose a reason for hiding this comment

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

Lets keep this as the host for now.
Using the full path would simplify the code and may be more clear
But I like reading the configuration for the host version

Copy link
Member

Choose a reason for hiding this comment

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

Works for me.

If the above wasn't clear to on lookers, my above critique is pretty subjective, and I don't hold a hard opinion on this.

it "displays custom ftp option with enabled array" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).at_least(:once).and_return(:"example.com" => { :enabled_for => %w(restore backup) })
Copy link
Member

Choose a reason for hiding this comment

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

Pedantic: Wouldn't this be a known quantity of .once or .twice? Would save some characters and would be more explicit with those since this shouldn't be a variable number of calls as far as I can tell.

Copy link
Member

Choose a reason for hiding this comment

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

Also, since this line is pretty long, could the prompt options be saved in a let(:prompt_options) to allow this to be more visable?

Copy link
Member Author

Choose a reason for hiding this comment

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

The actual value for enabled_for are different for most tests. I'll make a helper for this.

I'll make the twice more explicit


it "displays custom ftp option with enabled array" do
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt))
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file")
Copy link
Member

Choose a reason for hiding this comment

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

Pedantic: These above two seem like they could be tossed in a before hook to save them being defined twice.

PROMPT
end

it "hids custom ftp option with disabled string" do
Copy link
Member

Choose a reason for hiding this comment

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

Typo: s/hids/hides

end

it "cancels when CANCEL option is choosen" do
say "6"
expect { subject.ask_file_location }.to raise_error signal_error
end

# this is the complete implementation. the other 2 are paired down version of this
context "with localized file upload" do
Copy link
Member

Choose a reason for hiding this comment

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

Pedantic: maybe "with I18n custom menu configs"?

If changed, make sure to change in the other two spots.

some prompts need custom options.
--skip-directory=true is one option.
We had it hardcoded before.

this PR extracts it into its own configuration option
@kbrock kbrock force-pushed the single_backup_prompt branch 3 times, most recently from 738ba47 to b60b334 Compare October 23, 2018 18:55
@kbrock kbrock force-pushed the single_backup_prompt branch from b60b334 to 542178a Compare October 23, 2018 19:29
@miq-bot
Copy link
Member

miq-bot commented Oct 23, 2018

Checked commits kbrock/manageiq-appliance_console@e26f76d~...542178a with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🍪

@carbonin carbonin self-assigned this Oct 23, 2018
@carbonin carbonin merged commit cd6f786 into ManageIQ:master Oct 23, 2018
@carbonin carbonin added this to the Sprint 98 Ending Nov 5, 2018 milestone Oct 23, 2018
@kbrock kbrock deleted the single_backup_prompt branch October 23, 2018 20:59
@kbrock
Copy link
Member Author

kbrock commented Oct 23, 2018

@miq-bot tag hammer/yes

@miq-bot
Copy link
Member

miq-bot commented Oct 23, 2018

@kbrock unrecognized command 'tag', ignoring...

Accepted commands are: add_label, add_reviewer, assign, close_issue, move_issue, remove_label, rm_label, set_milestone

@carbonin
Copy link
Member

@kbrock The console is actually a released gem so at some point when the backup/dump work stabilizes, we'll cut a release and include that in the hammer branch of manageiq-appliance

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