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

etc_fstab resource: test contents of the /etc/fstab file #2064

Merged
merged 12 commits into from
Sep 11, 2017

Conversation

dromazmj
Copy link
Contributor

@dromazmj dromazmj commented Aug 14, 2017

Signed-off-by: dromazos [email protected]

@adamleff adamleff changed the title New Resource - etc_fstab etc_fstab resource: test contents of the /etc/fstab file Aug 17, 2017
Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

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

Hi @dromazmj - thanks for your PR. I've left you some feedback. Please let me know if you have any questions.

Use the where clause to match a property to one or more rules in the fstab file.

describe etc_fstab.where { device_name == 'value' } do
its ( 'mount_point' ) { should eq ['hostname'] }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change this to use the cmp matcher? should cmp 'hostname' since the cmp matcher will strip a single array item out of the Array.


describe etc_fstab.where { device_name == 'value' } do
its ( 'mount_point' ) { should eq ['hostname'] }
its ( 'file_system_type' ) { should eq [['list']] }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change all of these to be cmp matchers as well? Shouldn't need the double-array treatment.

Use the optional constructor parameter to give an alternative path to fstab file

describe etc_fstab(hosts_path).where { device_name == 'value' } do
its ( 'mount_point' ) { should eq ['hostname'] }
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here re: cmp matcher instead of the eq matcher

where

* `device_name` is the name associated with the device.
* `mount_point` is the default directory the device will be mounted if one is not specified in the mount command.
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than talk about how the mount command works in its ability to override the fstab, how about:

"mount_point is the directory at which the filesystem is configured to be mounted"


### device_name(String)

`device_name` returns an array of strings that matches the where condition of the filter table.
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have to use the where condition to write effective tests with FilterTable, so can we change the documentation of each of these examples to eliminate the "where condition of the filter table"?

End-users don't need to know what a FilterTable is and we don't really define it anywhere in the docs either. Let's keep it focused on a great user experience.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, for all of these examples, especially ones that return an array that is likely to be 1 item, let's switch to the cmp matcher please and get rid of the unnecessary Array syntax.

where { mount_point == '/home' }.entries[0].mount_options
end

def mounted?(point)
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think this is a bit of a misleading method name... this isn't actually testing if it's mounted, but rather configured to be mounted.

I think configured? might be a better method name. If so, we will need to update the examples/documentation as well. I'm open to other suggestions, but it's totally possible to have something in /etc/fstab that's not actually mounted.


raw_conf = file.content
if raw_conf.empty? && !file.empty?
return skip_resource("File is empty. If this is the correct file,
Copy link
Contributor

Choose a reason for hiding this comment

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

This skip_resource string is misleading. The file is specifically NOT empty but we couldn't read it. Let's remove reference to "access control" and instead make this something like:

"Unable to read file - check file permissions."

def read_file(conf_path = @conf_path)
file = inspec.file(conf_path)
if !file.file?
return skip_resource "Can't find file. If this is the correct path,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove reference to access control.

"Cannot find file #{conf_path}" is a sufficient error message.

_(entries.file_system_options).must_equal [0]
end

it 'Verify etc_hosts filtering by `mount_point`' do
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually don't think you need this test, of the tests starting at lines 27, 36, 45, or 57. These tests are all fundamentally testing FilterTable, not really testing your custom resource.

These are the tests I would want to see:

  • basic support of parsing the file
  • parsing an entry where mount_options is a single item
  • parsing an entry where mount_options has multiple items.
  • test that home_mount_options returns something when there is a /home mount configured
  • test that home_mount_options returns nil when there isn't a /home mount configured
  • that that nfs_file_systems returns the correct entries

_(entries.dump_options).must_equal [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
end

it 'verify etc_fstab can detect if a partition is mounted' do
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't actually testing anything - it's creating a stub handler but it's never used.

@dromazmj dromazmj requested a review from a team as a code owner August 18, 2017 14:26
Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

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

This is super-close, @dromazmj! Just a bit of cleanup and then I think it's ready for final review.

Use the where clause to match a property to one or more rules in the fstab file.

describe etc_fstab.where { device_name == 'value' } do
its ( 'mount_point' ) { should cmp 'hostname' }
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistent Ruby style, please update these examples so that there are only spaces between the its parameter and the beginning of the block, as well as inside the block:

its('foo') { should cmp 'foo' }

Please make that change across all your pending PRs and the rest of the examples in this resource. Thank you!

### Check if a partition is mounted at a point.

describe etc_fstab.where { mount_point == '/home' } do
it { should be_mounted }
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be be_configured now, right?

@dromazmj
Copy link
Contributor Author

dromazmj commented Aug 25, 2017 via email

@dromazmj dromazmj closed this Sep 5, 2017
Signed-off-by: Adam Leff <[email protected]>
Signed-off-by: dromazmj <[email protected]>
@dromazmj dromazmj reopened this Sep 5, 2017
Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

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

This looks to be in good shape. Thanks, @dromazmj!

Copy link
Contributor

@arlimus arlimus left a comment

Choose a reason for hiding this comment

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

Amazing new resource, thank you so much @dromazmj !!

@arlimus arlimus merged commit 70548ab into inspec:master Sep 11, 2017
@arlimus
Copy link
Contributor

arlimus commented Sep 11, 2017

Thank you for guiding this through @adamleff 😄

adamleff added a commit that referenced this pull request Sep 11, 2017
This commit/PR is to re-run the Expeditor actions for #2064 (changelog, automated build), etc.

While we would normally manually re-run the actions through our bot, the expeditor config
in the squashed commit for #2064 is not correct.

Signed-off-by: Adam Leff <[email protected]>
adamleff added a commit that referenced this pull request Sep 11, 2017
This commit/PR is to re-run the Expeditor actions for #2064 (changelog, automated build), etc.

While we would normally manually re-run the actions through our bot, the expeditor config
in the squashed commit for #2064 is not correct.

Signed-off-by: Adam Leff <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants