Skip to content

Commit f649de4

Browse files
committed
New provider parsed for oratab
The provider parses the /var/opt/oracle/oratab on Solaris and the file /etc/oratab on other operating systems.
1 parent df0b110 commit f649de4

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

lib/puppet/provider/oratab/parsed.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require 'puppet/provider/parsedfile'
2+
3+
oratab = case Facter.value(:operatingsystem)
4+
when 'Solaris'
5+
'/var/opt/oracle/oratab'
6+
else
7+
'/etc/oratab'
8+
end
9+
10+
Puppet::Type.type(:oratab).provide(:parsed, :parent => Puppet::Provider::ParsedFile, :default_target => oratab, :filetype => :flat) do
11+
12+
text_line :comment, :match => /^\s*#/
13+
text_line :blank, :match => /^\s*$/
14+
15+
record_line :parsed, :fields => %w{name home atboot description},
16+
:optional => %w{description},
17+
:match => /^\s*(.*?):(.*?):(.*?)\s*(?:#\s*(.*))?$/,
18+
:post_parse => proc { |h|
19+
h[:atboot] = :yes if h[:atboot] == 'Y'
20+
h[:atboot] = :no if h[:atboot] == 'N'
21+
h
22+
},
23+
:pre_gen => proc { |h|
24+
h[:atboot] = 'Y' if h[:atboot] == :yes
25+
h[:atboot] = 'N' if h[:atboot] == :no
26+
h
27+
},
28+
:to_line => proc { |h|
29+
str = "#{h[:name]}:#{h[:home]}:#{h[:atboot]}"
30+
if h[:description] and h[:description] != :absent
31+
str += " # #{description}"
32+
end
33+
str
34+
}
35+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# some comments to
2+
# explain what this file is used for
3+
# parsed should ignore these comments an the next line
4+
5+
TEST:/app/oracle/db/11.2/db_1:N # line added by Agent
6+
PROD:/app/oracle/db/11.2/db_2:Y
7+
#OLDPROD:/app/oracle/db/11.2/db_3:N # line added by Agent
8+
9+
10+
DR:/app/oracle/db/11.2/db_4:N#i am still # an inline comment
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'spec_helper'
4+
5+
describe Puppet::Type.type(:oratab).provider(:parsed) do
6+
7+
before :each do
8+
described_class.stubs(:suitable?).returns true
9+
described_class.stubs(:default_target).returns my_fixture('oratab')
10+
Puppet::Type.type(:oratab).stubs(:defaultprovider).returns described_class
11+
@resource = Puppet::Type.type(:oratab).new(
12+
:name => 'TEST01',
13+
:ensure => :present,
14+
:home => '/u01/app/oracle/product/9.2.0.1.0',
15+
:atboot => :yes,
16+
:description => 'managed by puppet'
17+
)
18+
@provider = described_class.new(@resource)
19+
end
20+
21+
[:destroy, :create, :exists?].each do |method|
22+
it "should respond to #{method}" do
23+
@provider.should respond_to method
24+
end
25+
end
26+
27+
[:home, :atboot, :description].each do |property|
28+
it "should have getter and setter for property #{property}" do
29+
@provider.should respond_to property
30+
@provider.should respond_to "#{property}=".intern
31+
end
32+
end
33+
34+
describe "when parsing a line" do
35+
36+
describe "with no description" do
37+
it "should capture the name" do
38+
described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:N')[:name].should == 'TEST'
39+
described_class.parse_line('TEST_01:/app/oracle/db/11.2/db_1:N')[:name].should == 'TEST_01'
40+
end
41+
42+
it "should capture the home directory" do
43+
described_class.parse_line('TEST:/db_1:N')[:home].should == '/db_1'
44+
described_class.parse_line('TEST:/db_1:Y')[:home].should == '/db_1'
45+
described_class.parse_line('TEST_01:/app/oracle/db/11.2/db_1:Y')[:home].should == '/app/oracle/db/11.2/db_1'
46+
end
47+
48+
it "should capture the atboot flag" do
49+
described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:N')[:atboot].should == :no
50+
described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:Y')[:atboot].should == :yes
51+
end
52+
end
53+
54+
describe "with a description" do
55+
it "should capture the name" do
56+
described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:N # fancy comment')[:name].should == 'TEST'
57+
described_class.parse_line('TEST_01:/app/oracle/db/11.2/db_1:N # even ## fancier')[:name].should == 'TEST_01'
58+
end
59+
it "should capture the home directory" do
60+
described_class.parse_line('TEST:/db_1:N # fancy comment')[:home].should == '/db_1'
61+
described_class.parse_line('TEST_01:/app/oracle/db/11.2/db_1:Y# even ## fancier')[:home].should == '/app/oracle/db/11.2/db_1'
62+
end
63+
it "should capture the atboot flag" do
64+
described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:N # fancy comment')[:atboot].should == :no
65+
described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:Y## even ## fancier')[:atboot].should == :yes
66+
end
67+
it "should capture the description" do
68+
described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:N # fancy comment')[:description].should == 'fancy comment'
69+
described_class.parse_line('TEST:/app/oracle/db/11.2/db_1:Y## even ## fancier')[:description].should == '# even ## fancier'
70+
end
71+
end
72+
end
73+
74+
describe "when calling instances" do
75+
before :each do
76+
@instances = described_class.instances
77+
@instances.size.should == 3
78+
end
79+
80+
it "should be able to get the first entry" do
81+
@instances[0].get(:name).should == 'TEST'
82+
@instances[0].get(:home).should == '/app/oracle/db/11.2/db_1'
83+
@instances[0].get(:atboot).should == :no
84+
@instances[0].get(:description).should == 'line added by Agent'
85+
end
86+
87+
it "should be able to get the second entry" do
88+
@instances[1].get(:name).should == 'PROD'
89+
@instances[1].get(:home).should == '/app/oracle/db/11.2/db_2'
90+
@instances[1].get(:atboot).should == :yes
91+
@instances[1].get(:description).should == :absent
92+
end
93+
94+
it "should be able to get the third entry" do
95+
@instances[2].get(:name).should == 'DR'
96+
@instances[2].get(:home).should == '/app/oracle/db/11.2/db_4'
97+
@instances[2].get(:atboot).should == :no
98+
@instances[2].get(:description).should == 'i am still # an inline comment'
99+
end
100+
end
101+
102+
end

0 commit comments

Comments
 (0)