-
Notifications
You must be signed in to change notification settings - Fork 79
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
Adds MiqFtpLib #360
Adds MiqFtpLib #360
Conversation
@carbonin So this is just a portion of ManageIQ/manageiq#17549 that I eventually want to pull into this repo. I will eventually be making a But putting this together now since it will require a follow up PR and was taking a bit of a break from main effort of getting a decent splitting interface in place around the |
lib/gems/pending/util/miq_ftp_lib.rb
Outdated
def self.included(klass) | ||
klass.send(:attr_accessor, :ftp) | ||
|
||
klass.send(:attr_accessor, :uri) unless klass.instance_methods.include?(:uri=) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance it feels like there should be a better way to check if there is already an attr_accessor
for this. If nothing else maybe check for both the #uri=
and #uri
methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought so too. Again, this is a straight rip off of what I did in ManageIQ/manageiq#17549 (simply changed and relocated the module), so I didn't change anything there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, can we simplify this? Conditional attr_accessors feels complicated. I don't understand why it's conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrafanie Sorry, missed this when looking at this earlier, but please look at #360 (comment) for clarity on to why this is the way. Specifically the first bullet point.
Replying to #360 (comment) Live by the 📖 die by the 📖 I guess ...
Is the plan here to replace
Why make the interface a separate module in the namespace? I think I would rather have the
I'm not sure what this means. Will
Okay, so
Makes sense to me. I was just trying to simplify the logging bit. So as I understand it the design (which is really what this conversation ended up being) sounds like this.
This all sounds good to me. The only changes/refinements I would suggest are pushing the @NickLaMuro @Fryguy If you got this far does this make sense? Should we put this conversation somewhere else? |
For those following along at home, the answer was "yes", and "we did". Most of what we (@carbonin and myself) discussed out band should answer the questions above in the new PR (when I get something concrete to share), so I will save the summary for then, and try to remember to link back to here later (if I remember). |
7201948
to
0184546
Compare
baf329a
to
1cc26ac
Compare
@carbonin Do you have any reservations about what I am doing here still? I realize that your comment from before and the other one (I marked that one as resolved just because it got off topic a bit) are somewhat still as they were. #368 , however, now can provide some clarity (built off of #361 currently), so if there was any curiosity as to how this would be used, that would be the intended implementation. But to the comments you had previously (don't read if you are just going to merge anyway... or hate 📚):
|
Will be used for spinning up a local FTP server in the tests for specs that require one.
Context that make sure to spin up an FTP server when included, and will make some helper methods available. Uses the `ftpd` gem to handle the ftp server.
1cc26ac
to
965cc70
Compare
lib/gems/pending/util/miq_ftp_lib.rb
Outdated
# logging if not already done for the particular class (that follows the | ||
# VmdbLogger conventions, and setup a `uri` attr_accessor if that doesn't | ||
# already exist. | ||
module MiqFtpLib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we should make this a class around FTP interaction with its own logger. Then we also don't have to be responsible for what methods are defined on the model (or other thing) using this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's kind of both. I read that response a few days ago then re-read the whole mixin here and I'm still not comfortable with this being an included module.
I think there would be more value and stability in making this a standalone class than trying to fit this in as a mixin. The refactoring you would have to do in FileDepotFtp seems minimal and I think it would make this class much more stable and readable.
TLDR;
Make it a class, take a uri as a parameter to initialize, and give it a #logger=
method with a null logger as a default. That should take care of all of the meta-programming in .included
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there would be more value and stability...
Sure, maybe long term. But as a reminder, this came about from your original comment here:
ManageIQ/manageiq#17549 (comment)
In which I was trying to meet halfway in regards to making this DRY. But, to your comment that:
The refactoring you would have to do in FileDepotFtp seems minimal...
I disagree entirely. These methods are EXACTLY as they are in FileDepotFtp
, meaning there is next to zero risk on me doing what I originally had done in there as part of ManageIQ/manageiq#17549 which was gut these methods from FileDepotFTP
and replace them via include MiqFtpLib
(previously here).
With this suggestion, it is a re-write of FileDepotFtp
effectively, because half of the methods I am not using here still have their own _log
method that I would need to handle (or accept disparaging loggers for).
Also, @ftp
is no longer part of the class, as it would instead be a reference to this new class, and so everything that isn't a part of MiqFtpLib
as it is now that isn't removed from FileDepotFtp
basically going to be re-written as a result. The "specs" for FileDepotFtp
(which is about 90% mocking, and 10% actually testing things), would also probably completely need to be re-written as a result.
Not to mention basically re-working the main parts of ManageIQ/manageiq-gems-pending#368 as a result.
tl; dr No, this would not be easier to write this as a class. Unless you can convince "the powers that be" that this is worth said re-write that I didn't estimate for, I disagree with the suggestion.
Again [ref], if the meta-programming is an issue, I can basically remove most of the included
block (if not all of it), and just assume this is an "interface" module, and those methods inside of included
can then required by the "including" class. This goes for both the uri
bit and the _log
, and would have zero impact on FileDepotFtp
, and have a minor amount of impact on #368 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I prefer the method you mentioned about this being an "interface" module. The metaprogramming here just makes me a bit too uncomfortable, so if you can design this in a way that does less (or none) of that, I'm 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I kept attr_accessor :ftp
in since it has next to no meta-programming, but still tries to reach peak minimum LOC added, to appease @jrafanie ...
Edit: technically... I think it adds one more by doing this way... but whatever...
spec/util/miq_ftp_lib_spec.rb
Outdated
context "when the class already has a uri=" do | ||
subject { OtherFTPKlass.new } | ||
|
||
it "has a `uri` accessor" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yikes backticks...
spec/util/miq_ftp_lib_spec.rb
Outdated
expect(subject.ftp).to eq ftp_instance | ||
end | ||
|
||
it "has a `uri` accessor" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single quote instead of backtick?
lib/gems/pending/util/miq_ftp_lib.rb
Outdated
|
||
# Helper methods for net/ftp based classes and files. | ||
# | ||
# Will setup a `@ftp` attr_accessor to be used as the return value for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does rdoc treat backticks in comments differently than single quotes? I'm not sure why there's backticks in these comments and it seems like there's a good reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am treating backticks (here, and in your other comments) as you would in markdown to represent a portion of code
with that is being talked about inside of the comment/description (variables or methods that are contextually relevant).
Backticks inside a string have no execution, and are simply there for emphasis for specific identifiers, using a standard syntax I assume most would be familiar with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yard accepts markdown (and thus backticks) for comments, I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fryguy Yes, and so does just vanilla RDoc shipped with Ruby:
965cc70
to
afa4832
Compare
lib/gems/pending/util/miq_ftp_lib.rb
Outdated
# Will setup a `@ftp` attr_accessor to be used as the return value for | ||
# `.connect`, the main method being provided in this class. Will also setup | ||
# logging if not already done for the particular class (that follows the | ||
# VmdbLogger conventions, and setup a `uri` attr_accessor if that doesn't |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is out of date now, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! Good catch.
lib/gems/pending/util/miq_ftp_lib.rb
Outdated
@@ -0,0 +1,76 @@ | |||
require 'net/ftp' | |||
require 'logger' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this anymore as were just calling a _log
method which should have been defined on the including class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This is lifted from the FileDepotFtp code in the manageiq repo, and is just some shared methods around connecting to an FTP endpoint. Adds some tests around it as well.
afa4832
to
25baa0b
Compare
Some comments on commits NickLaMuro/manageiq-gems-pending@a1ac64c~...25baa0b spec/support/contexts/with_ftp_server.rb
|
Checked commits NickLaMuro/manageiq-gems-pending@a1ac64c~...25baa0b with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@carbonin Just an FYI about how I "addressed" this comment: I am still requiring 'logger' in the specs in the off chance it hasn't been included by something else. In classes that include this, I will also be including it, again, just as a safety measure. Example in a later PR: NickLaMuro/manageiq-gems-pending@ftp_object_storage~2...ftp_object_storage#diff-4cf23bcfce6b36adcd0045ffbd1b724e (EDIT: today I learned I can use |
@carbonin Yeah, looks like GHFM (GitHub Flavored Markdown) f'd with their own link:
That DOES work, but got fudged when it tried parsing out the ... so I guess TIL on that as well... |
Helper module for common FTP interactions that will be shared in multiple parts of the
manageiq
codebase.Lifted from
FileDepotFtp
, and will eventually replace some of the methods there (follow up PR).Links