-
Notifications
You must be signed in to change notification settings - Fork 90
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
[MSYS-649] Fix InSpec file size in Windows, refactor File classes #193
[MSYS-649] Fix InSpec file size in Windows, refactor File classes #193
Conversation
Please only open a PR when you believe your code is complete and you are ready for a review. Thank you! |
@adamleff that one line of change has fixed the issue which is mentioned on card but I need review on this since I am not very much familiar with code flow and specs are failing. Also I want to know how should I run all specs. |
OK - i'll re-open and edit your description. it stated it was still "in progress" and we do not keep PRs open that are not ready for review or in the process of being reviewed. Thank you :) |
@Vasu1105 to run the tests, you can do the following in the project top-level directory:
That will run the unit tests and the lint tests, both of which are what are run via Travis. Thanks! |
@adamleff I observed that using inspec file resource when I do check for file exist? for windows os it does not call file_window.rb in train for executing exist. It calls load_file executes https://github.com/chef/train/blob/master/lib/train/transports/local_file.rb#L17 line of code. So I am using the same approach but not sure why test cases are failing. Please add your inputs on this. I am using following profile for testing title 'filetest' |
Thank you @Vasu1105 for highlighting this issue. Unfortunately, I think the issue is a little bit more complex:
|
We probably want to combine this with #190 |
@chris-rock After conversation with @btm I am taking up the work for fixing larger issue as you mentioned since there is no movement on #190
May be I will need some inputs from you to understand code flow of train. Also what is the use case of local_file.rb |
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 we need to rethink the file classes a bit as a result of this change. @chris-rock is correct in that LocalFile cannot depend on LinuxFile, but we shouldn't overload FileCommon as a result.
This is just my opinion but I think we could be much clearer in the names of our classes (and even the file layout) to make this easier. For example, calling things "Extras" makes it seem like it's not important, but the code in there is really critical, and the hierachy isn't clear.
So here's how I'd resolve this in terms of class layout:
Train::File
├── Local
│ ├── Unix
│ └── Windows
└── Remote
├── Unix
│ ├── AIX
│ └── Linux
└── Windows
A quick explanation:
Train::File
is the currentFileCommon
class; it defines all the methods every other implementation of aTrain::File
must implement, including populating them with araise NotImplementedError
as needed. The class as-is is probably just fine.Train::File::Local
would define all the methods fromTrain::File
with the appropriate calls from the Ruby stdlib. I think much of the content ofTrain::Transports::Local::Connection::File
should actually move in here.Train::File::Local::Unix
andWindows
can be used to override any of those methods as needed. These are likely not even necessary and I would not initially implement them.Train::File::Remote::Unix
andWindows
would define all theTrain::File
methods but using the appropriate remote calls. They can further be subclasses like we do today (Linux off of Unix because of the different method for getting file content). The current contents of theTrains::Extras::UnixFile
and friends would move in here.
Then essentially, the transport would instantiate the right class depending on the transport and the OS:
Train::File::Local
Train::File::Remote::AIX
Train::File::Remote::Unix
Train::File::Remote::Linux
Train::File::Remote::Windows
... and Train::Transports::Local::Connection::File
would go away so that all file-related logic is contained within the Train::File
hierarchy, no matter the transport.
@chris-rock, would love your input on this. Yes, this is VERY similar to what we have now, but it consolidates things and makes the intentions clearer.
lib/train/extras/file_common.rb
Outdated
@@ -20,6 +20,14 @@ class FileCommon # rubocop:disable Metrics/ClassLength | |||
end | |||
end | |||
|
|||
COMMON_FILE_METHODS = %w{exist? socket? directory? symlink? pipe?}.freeze | |||
|
|||
COMMON_FILE_METHODS.each do |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.
I don't believe these belong here. FileCommon
should provide the interface that the other classes should implement. These methods are very specific to local files.
The structure @adamleff proposes makes a lot of sense to me! What we need to watch is the overlap between local and remote. We should try to keep the overlap as high as possible. |
@adamleff and @chris-rock I am starting work on structural changes and will update the same PR after I am done with the changes. Thank you for the inputs. |
@Vasu1105 thank you for taking on this challenge! It will help the stability and clarity of this part of the Train codebase. Please reach out if you have any questions or need any assistance. |
so @adamleff the implementation under extras for file will go off right ? And all this will be classes right ? |
Yes, the file-related code under |
49b4e6a
to
627c79e
Compare
7012db5
to
86a217e
Compare
5cb3af3
to
5d359fe
Compare
@adamleff & @chris-rock this PR is ready for review |
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.
@Vasu1105 this is such a great improvement! Upon a quick review, I found a couple of clean-up things. But overall, this is precisely how I hoped it would look. Thank you!
lib/train/file.rb
Outdated
end | ||
|
||
def linked_to?(dst) | ||
link_path == dst | ||
# TODO: This methods needs to raise error if not implemented currently it set to nil since conversion |
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 this is a "TODO" - this is a design choice. Since only Windows will populate this field and it's nil by default, this is a totally acceptable implementation. I think the comment should read something like:
# product_version is primarily used by Windows operating systems only and will be overwritten
# in Windows-related classes. Since this field is returned for all file objects, the acceptable
# default value is nil
lib/train/file.rb
Outdated
end | ||
|
||
def link_path | ||
symlink? ? path : nil | ||
# TODO: This methods needs to raise error if not implemented currently it set to nil since conversion |
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.
Same as above comment re: product_version
lib/train/file/local/unix.rb
Outdated
end | ||
|
||
def stat | ||
return @stat if defined? @stat |
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.
Slight nitpick, but we should be consistent with wrapping method arguments with parentheses...
return @stat if defined?(@stat)
lib/train/file/local/windows.rb
Outdated
end | ||
|
||
def stat | ||
return @stat if defined? @stat |
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.
Same comment re: wrapping arguments with parentheses.
end | ||
end | ||
end | ||
# it 'gets file contents' 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.
Can we remove these commented-out tests?
@adamleff Thank you :). Fixed review comments |
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.
@Vasu1105 this looks really good. Before I provide my approval, can you please rebase your changes against the latest master? It appears you have some merge conflict. Thank you!
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
4071a54
to
c50add7
Compare
7ba5a32
to
a622ce0
Compare
… changes as per new structure Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
a622ce0
to
b465802
Compare
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.
Looks great, @Vasu1105 - thanks!
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 great work and makes the code more structured. Thank you @Vasu1105
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.
Amazing improvements and change overall, really great work!!
I need a tiny iteration to see if we can't get out of indentation hell, but may not block it. Found a few tiny things, i'll look again tomorrow :)
it 'has no file_version' do | ||
file.file_version.must_equal(nil) | ||
it 'has no product_version' do | ||
file.file_version.must_be_nil |
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.
the description talks about product_version vs the test looking at file version 😉
end | ||
|
||
it 'has no file_version' do | ||
file.file_version.must_equal(nil) | ||
it 'has no product_version' 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.
ditto
end | ||
|
||
it 'has no file_version' do | ||
file.file_version.must_equal(nil) | ||
it 'has no product_version' 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.
ditto
end | ||
|
||
it 'has no file_version' do | ||
file.file_version.must_equal(nil) | ||
it 'has no product_version' 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.
ditto
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
Thank you @chris-rock @arlimus :) . @arlimus I have fixed the review comments. |
Sweet thank you so much @Vasu1105 i'll take another look today on one more point i was interested in. Almost at the finish line :D |
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.
Thank you for the adjustments!!
Thank you @adamleff , @stevendanna and @chris-rock, @arlimus and all others for help for this work :) |
Great work @Vasu1105 ! |
During the file refactor in #193, an error was made in class names that caused AIX file operations to be severely limited and QNX file support was broken. This restores the AIX and QNX remote file functionality and adds unit tests for each of those classes. Signed-off-by: Adam Leff <adam@leff.co>
During the file refactor in #193, an error was made in class names that caused AIX file operations to be severely limited and QNX file support was broken. This restores the AIX and QNX remote file functionality and adds unit tests for each of those classes. Signed-off-by: Adam Leff <adam@leff.co>
During the file refactor in #193, an error was made in class names that caused AIX file operations to be severely limited and QNX file support was broken. This restores the AIX and QNX remote file functionality and adds unit tests for each of those classes. Signed-off-by: Adam Leff <adam@leff.co>
Issue Ref: https://getchef.zendesk.com/agent/#/tickets/15734
Signed-off-by: Vasu1105 vasundhara.jagdale@msystechnologies.com