1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
#! /usr/bin/env ruby
require 'spec_helper'
describe Puppet::Type.type(:zone) do
let(:zone) { described_class.new(:name => 'dummy', :path => '/dummy', :provider => :solaris, :ip=>'if:1.2.3.4:2.3.4.5', :inherit=>'/', :dataset=>'tank') }
let(:provider) { zone.provider }
let(:ip) { zone.property(:ip) }
let(:inherit) { zone.property(:inherit) }
let(:dataset) { zone.property(:dataset) }
parameters = [:create_args, :install_args, :sysidcfg, :realhostname]
parameters.each do |parameter|
it "should have a #{parameter} parameter" do
described_class.attrclass(parameter).ancestors.should be_include(Puppet::Parameter)
end
end
properties = [:ip, :iptype, :autoboot, :pool, :shares, :inherit, :path]
properties.each do |property|
it "should have a #{property} property" do
described_class.attrclass(property).ancestors.should be_include(Puppet::Property)
end
end
describe "when trying to set a property that is empty" do
it "should verify that property.insync? of nil or :absent is true" do
[inherit, ip, dataset].each do |prop|
prop.stubs(:should).returns []
end
[inherit, ip, dataset].each do |prop|
prop.insync?(nil).should be_true
end
[inherit, ip, dataset].each do |prop|
prop.insync?(:absent).should be_true
end
end
end
describe "when trying to set a property that is non empty" do
it "should verify that property.insync? of nil or :absent is false" do
[inherit, ip, dataset].each do |prop|
prop.stubs(:should).returns ['a','b']
end
[inherit, ip, dataset].each do |prop|
prop.insync?(nil).should be_false
end
[inherit, ip, dataset].each do |prop|
prop.insync?(:absent).should be_false
end
end
end
describe "when trying to set a property that is non empty" do
it "insync? should return true or false depending on the current value, and new value" do
[inherit, ip, dataset].each do |prop|
prop.stubs(:should).returns ['a','b']
end
[inherit, ip, dataset].each do |prop|
prop.insync?(['b', 'a']).should be_true
end
[inherit, ip, dataset].each do |prop|
prop.insync?(['a']).should be_false
end
end
end
it "should be valid when only :path is given" do
described_class.new(:name => "dummy", :path => '/dummy', :provider => :solaris)
end
it "should be invalid when :ip is missing a \":\" and iptype is :shared" do
expect {
described_class.new(:name => "dummy", :ip => "if", :path => "/dummy", :provider => :solaris)
}.to raise_error(Puppet::Error, /ip must contain interface name and ip address separated by a ":"/)
end
it "should be invalid when :ip has a \":\" and iptype is :exclusive" do
expect {
described_class.new(:name => "dummy", :ip => "if:1.2.3.4", :iptype => :exclusive, :provider => :solaris)
}.to raise_error(Puppet::Error, /only interface may be specified when using exclusive IP stack/)
end
it "should be invalid when :ip has two \":\" and iptype is :exclusive" do
expect {
described_class.new(:name => "dummy", :ip => "if:1.2.3.4:2.3.4.5", :iptype => :exclusive, :provider => :solaris)
}.to raise_error(Puppet::Error, /only interface may be specified when using exclusive IP stack/)
end
it "should be valid when :iptype is :shared and using interface and ip" do
described_class.new(:name => "dummy", :path => "/dummy", :ip => "if:1.2.3.4", :provider => :solaris)
end
it "should be valid when :iptype is :shared and using interface, ip and default route" do
described_class.new(:name => "dummy", :path => "/dummy", :ip => "if:1.2.3.4:2.3.4.5", :provider => :solaris)
end
it "should be valid when :iptype is :exclusive and using interface" do
described_class.new(:name => "dummy", :path => "/dummy", :ip => "if", :iptype => :exclusive, :provider => :solaris)
end
it "should auto-require :dataset entries" do
fs = 'random-pool/some-zfs'
catalog = Puppet::Resource::Catalog.new
relationship_graph = Puppet::Graph::RelationshipGraph.new(Puppet::Graph::RandomPrioritizer.new)
zfs = Puppet::Type.type(:zfs).new(:name => fs)
catalog.add_resource zfs
zone = described_class.new(:name => "dummy",
:path => "/foo",
:ip => 'en1:1.0.0.0',
:dataset => fs,
:provider => :solaris)
catalog.add_resource zone
relationship_graph.populate_from(catalog)
relationship_graph.dependencies(zone).should == [zfs]
end
describe Puppet::Zone::StateMachine do
let (:sm) { Puppet::Zone::StateMachine.new }
before :each do
sm.insert_state :absent, :down => :destroy
sm.insert_state :configured, :up => :configure, :down => :uninstall
sm.insert_state :installed, :up => :install, :down => :stop
sm.insert_state :running, :up => :start
end
context ":insert_state" do
it "should insert state in correct order" do
sm.insert_state :dummy, :left => :right
sm.index(:dummy).should == 4
end
end
context ":alias_state" do
it "should alias state" do
sm.alias_state :dummy, :running
sm.name(:dummy).should == :running
end
end
context ":name" do
it "should get an aliased state correctly" do
sm.alias_state :dummy, :running
sm.name(:dummy).should == :running
end
it "should get an un aliased state correctly" do
sm.name(:dummy).should == :dummy
end
end
context ":index" do
it "should return the state index correctly" do
sm.insert_state :dummy, :left => :right
sm.index(:dummy).should == 4
end
end
context ":sequence" do
it "should correctly return the actions to reach state specified" do
sm.sequence(:absent, :running).map{|p|p[:up]}.should == [:configure,:install,:start]
end
it "should correctly return the actions to reach state specified(2)" do
sm.sequence(:running, :absent).map{|p|p[:down]}.should == [:stop, :uninstall, :destroy]
end
end
context ":cmp" do
it "should correctly compare state sequence values" do
sm.cmp?(:absent, :running).should == true
sm.cmp?(:running, :running).should == false
sm.cmp?(:running, :absent).should == false
end
end
end
end
|