Skip to content

Instantly share code, notes, and snippets.

@danielsdeleo
Created January 21, 2011 20:08
Show Gist options
  • Save danielsdeleo/790311 to your computer and use it in GitHub Desktop.
Save danielsdeleo/790311 to your computer and use it in GitHub Desktop.
# Check to see if there is a entry in /etc/fstab. Last entry for a volume wins.
enabled = false
::File.foreach("/etc/fstab") do |line|
case line
when /^[#\s]/
next
when /^#{device_fstab_regex}\s+#{Regexp.escape(@new_resource.mount_point)}\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/
enabled = true
@current_resource.fstype($1)
@current_resource.options($2)
@current_resource.dump($3.to_i)
@current_resource.pass($4.to_i)
Chef::Log.debug("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab")
when /^[\/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}/
enabled = false
Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab")
end
end
@current_resource.enabled(enabled)
# test that I wrote that should show the error, but doesn't.
it "should set enabled to true if the mount point is not last in fstab" do
fstab = "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n"
fstab << "/dev/sdy1 /tmp/foo ext3 defaults 1 2\n"
fstab << "/dev/sdy1 /tmp/foo/bar ext3 defaults 1 2\n"
::File.stub!(:foreach).with("/etc/fstab").and_yield fstab
@provider.load_current_resource
@provider.current_resource.enabled.should be_true
end
#
# Author:: Joshua Timberman (<joshua@opscode.com>)
# Copyright:: Copyright (c) 2008 OpsCode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
require 'ostruct'
describe Chef::Provider::Mount::Mount do
before(:each) do
@node = Chef::Node.new
@run_context = Chef::RunContext.new(@node, {})
@new_resource = Chef::Resource::Mount.new("/")
@new_resource.device "/dev/sdz1"
@new_resource.device_type :device
@new_resource.fstype "ext3"
@new_resource.supports :remount => false
@provider = Chef::Provider::Mount::Mount.new(@new_resource, @run_context)
::File.stub!(:exists?).with("/dev/sdz1").and_return true
::File.stub!(:exists?).with("/").and_return true
end
describe "when discovering the current fs state" do
before do
@provider.stub!(:shell_out!).and_return(OpenStruct.new(:stdout => ''))
::File.stub!(:foreach).with("/etc/fstab")
end
it "should set enabled to true if the mount point is not last in fstab" do
fstab = "/dev/sdz1 / ext3 defaults 1 2\n"
fstab2 ="/dev/sdy1 / ext3 defaults 1 2\n"
fstab3 ="/dev/sdy1 /tmp/foo ext3 defaults 1 2\n"
::File.stub!(:foreach).with("/etc/fstab").and_yield(fstab).and_yield(fstab2).and_yield(fstab3)
@provider.load_current_resource
@provider.current_resource.enabled.should be_true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment