summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-05-30 03:08:16 +0000
committerLuke Kanies <luke@madstop.com>2005-05-30 03:08:16 +0000
commitd42efbeb2b2772d8286756a2aedb40604a1b7f11 (patch)
tree3dd8f283a6c85e52256bd50d0ee9d3df146557a8
parent0ab9685383bc21d9903a06d62a01f6cb72d25610 (diff)
downloadpuppet-d42efbeb2b2772d8286756a2aedb40604a1b7f11.tar.gz
puppet-d42efbeb2b2772d8286756a2aedb40604a1b7f11.tar.xz
puppet-d42efbeb2b2772d8286756a2aedb40604a1b7f11.zip
done some more work on making components act like normal objects, but now i need to figure out how to spread events up the tree, rather than just point to point
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@284 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/blink/statechange.rb4
-rw-r--r--lib/blink/transaction.rb1
-rw-r--r--lib/blink/transportable.rb2
-rw-r--r--lib/blink/type.rb1
-rw-r--r--lib/blink/type/component.rb13
-rw-r--r--lib/blink/type/service.rb9
-rw-r--r--lib/blink/type/state.rb4
-rw-r--r--test/other/tc_transactions.rb65
-rw-r--r--test/types/tc_basic.rb2
-rw-r--r--test/types/tc_query.rb12
10 files changed, 91 insertions, 22 deletions
diff --git a/lib/blink/statechange.rb b/lib/blink/statechange.rb
index e5d27cc58..066f4b7b9 100644
--- a/lib/blink/statechange.rb
+++ b/lib/blink/statechange.rb
@@ -25,7 +25,7 @@ module Blink
#---------------------------------------------------------------
def go
if @state.noop
- Blink.notice "%s is noop" % @state
+ #Blink.notice "%s is noop" % @state
return nil
end
@@ -67,7 +67,7 @@ module Blink
#---------------------------------------------------------------
def forward
- Blink.notice "moving change forward"
+ #Blink.notice "moving change forward"
unless defined? @transaction
raise "StateChange '%s' tried to be executed outside of transaction" %
diff --git a/lib/blink/transaction.rb b/lib/blink/transaction.rb
index 7bf0c8557..56d1268b5 100644
--- a/lib/blink/transaction.rb
+++ b/lib/blink/transaction.rb
@@ -74,6 +74,7 @@ class Transaction
# now we have the entire list of objects to notify
else
+ Blink.notice "I'm not top-level"
# these are the objects that need to be refreshed
#return @refresh.uniq
end
diff --git a/lib/blink/transportable.rb b/lib/blink/transportable.rb
index 0834d6c9b..d7ca9d5e3 100644
--- a/lib/blink/transportable.rb
+++ b/lib/blink/transportable.rb
@@ -101,7 +101,7 @@ module Blink
#------------------------------------------------------------
# just a linear container for objects
class TransBucket < Array
- attr_accessor :name
+ attr_accessor :name, :type
def to_type
# this container will contain the equivalent of all objects at
diff --git a/lib/blink/type.rb b/lib/blink/type.rb
index 4f43921d3..57b9e0f3f 100644
--- a/lib/blink/type.rb
+++ b/lib/blink/type.rb
@@ -402,6 +402,7 @@ class Blink::Type < Blink::Element
self.send(("meta" + mname.id2name),value)
elsif stateklass = self.class.validstate(mname)
if value.is_a?(Blink::State)
+ Blink.debug "'%s' got handed a state for '%s'" % [self,mname]
@states[mname] = value
else
if @states.include?(mname)
diff --git a/lib/blink/type/component.rb b/lib/blink/type/component.rb
index c0e13e0ac..d675474f6 100644
--- a/lib/blink/type/component.rb
+++ b/lib/blink/type/component.rb
@@ -10,17 +10,22 @@ require 'blink/type'
require 'blink/transaction'
module Blink
- class Component < Blink::Element
+ class Component < Blink::Type
include Enumerable
@name = :container
+ @namevar = :name
+
+ @states = []
+ @parameters = [:name]
def each
@children.each { |child| yield child }
end
- def initialize
+ def initialize(*args)
@children = []
+ super
end
# now we decide whether a transaction is dumb, and just accepts
@@ -47,5 +52,9 @@ module Blink
child.retrieve
}
end
+
+ def to_s
+ return "component(%s)" % self.name
+ end
end
end
diff --git a/lib/blink/type/service.rb b/lib/blink/type/service.rb
index dbae98d9c..a4c822fc8 100644
--- a/lib/blink/type/service.rb
+++ b/lib/blink/type/service.rb
@@ -16,14 +16,11 @@ module Blink
# this whole thing is annoying
# i should probably just be using booleans, but for now, i'm not...
def should=(should)
- if should == false
+ case should
+ when false,0,"0":
should = 0
- elsif should == true
+ when true,1,"1":
should = 1
- elsif should == "1" or should == 1
- should = 1
- elsif should == "0" or should == 0
- should = 0
else
Blink.warning "%s: interpreting '%s' as false" %
[self.class,should]
diff --git a/lib/blink/type/state.rb b/lib/blink/type/state.rb
index 5b32ccd68..7bc0dfdd7 100644
--- a/lib/blink/type/state.rb
+++ b/lib/blink/type/state.rb
@@ -74,7 +74,7 @@ class Blink::State < Blink::Element
@is = nil
if should.length > 0 # we got passed an argument
- @should = should.shift
+ self.should = should.shift
else # we got passed no argument
# leave @should undefined
end
@@ -124,7 +124,7 @@ class Blink::State < Blink::Element
#---------------------------------------------------------------
def to_s
- return @parent.name.to_s + " -> " + self.name.to_s
+ return "%s(%s)" % [@parent.name,self.name]
end
#---------------------------------------------------------------
end
diff --git a/test/other/tc_transactions.rb b/test/other/tc_transactions.rb
index 710ee5a16..1ac5b4edb 100644
--- a/test/other/tc_transactions.rb
+++ b/test/other/tc_transactions.rb
@@ -24,6 +24,8 @@ class TestTransactions < Test::Unit::TestCase
assert_nothing_raised() {
Blink::Type.allclear
}
+
+ print "\n\n"
end
def newfile
@@ -54,10 +56,10 @@ class TestTransactions < Test::Unit::TestCase
}
end
- def newcomp(*args)
+ def newcomp(name,*args)
comp = nil
assert_nothing_raised() {
- comp = Blink::Component.new
+ comp = Blink::Component.new(:name => name)
}
args.each { |arg|
@@ -84,7 +86,7 @@ class TestTransactions < Test::Unit::TestCase
states[state] = file[state]
}
- component = newcomp(file)
+ component = newcomp("file",file)
assert_nothing_raised() {
file[:group] = @groups[1]
file[:mode] = "755"
@@ -113,7 +115,7 @@ class TestTransactions < Test::Unit::TestCase
service = newservice
service[:check] = [:running]
- component = newcomp(service)
+ component = newcomp("service",service)
assert_nothing_raised() {
service.retrieve
@@ -150,7 +152,7 @@ class TestTransactions < Test::Unit::TestCase
service[:running] = 1
service.sync
- component = newcomp(file,service)
+ component = newcomp("both",file,service)
# 'requires' expects an array of arrays
service[:require] = [[file.class.name,file.name]]
@@ -169,6 +171,7 @@ class TestTransactions < Test::Unit::TestCase
}
assert_nothing_raised() {
transaction = component.evaluate
+ transaction.toplevel = true
}
# this should cause a restart of the service
@@ -185,7 +188,59 @@ class TestTransactions < Test::Unit::TestCase
}
file.sync
}
+ end
+
+ def test_twocomps
+ transaction = nil
+ file = newfile()
+ service = newservice()
+ states = {}
+ check = [:group,:mode]
+ file[:check] = check
+
+ service[:running] = 1
+ service.sync
+
+ fcomp = newcomp("file",file)
+ scomp = newcomp("service",service)
+
+ component = newcomp("both",fcomp,scomp)
+
+ # 'requires' expects an array of arrays
+ #component[:require] = [[file.class.name,file.name]]
+ service[:require] = [[fcomp.class.name,fcomp.name]]
+
+ assert_nothing_raised() {
+ file.retrieve
+ service.retrieve
+ }
+
+ check.each { |state|
+ states[state] = file[state]
+ }
+ assert_nothing_raised() {
+ file[:group] = @groups[1]
+ file[:mode] = "755"
+ }
+ assert_nothing_raised() {
+ transaction = component.evaluate
+ transaction.toplevel = true
+ }
+ # this should cause a restart of the service
+ assert_nothing_raised() {
+ transaction.evaluate
+ }
+
+ # now set everything back to how it was
+ assert_nothing_raised() {
+ service[:running] = 0
+ service.sync
+ check.each { |state|
+ file[state] = states[state]
+ }
+ file.sync
+ }
end
end
diff --git a/test/types/tc_basic.rb b/test/types/tc_basic.rb
index b67cc0599..eed483e5d 100644
--- a/test/types/tc_basic.rb
+++ b/test/types/tc_basic.rb
@@ -21,7 +21,7 @@ class TestBasic < Test::Unit::TestCase
Blink[:debug] = 1
assert_nothing_raised() {
- @component = Blink::Component.new
+ @component = Blink::Component.new(:name => "component")
}
assert_nothing_raised() {
diff --git a/test/types/tc_query.rb b/test/types/tc_query.rb
index 9b18b86ac..66fb50b05 100644
--- a/test/types/tc_query.rb
+++ b/test/types/tc_query.rb
@@ -14,6 +14,12 @@ class TestBasic < Test::Unit::TestCase
Blink[:debug] = true
end
+ def teardown
+ assert_nothing_raised() {
+ Blink::Type.allclear
+ }
+ end
+
# hmmm
# this is complicated, because we store references to the created
# objects in a central store
@@ -48,9 +54,9 @@ class TestBasic < Test::Unit::TestCase
return @sleeper
end
- def component(*args)
+ def component(name,*args)
assert_nothing_raised() {
- @component = Blink::Component.new
+ @component = Blink::Component.new(:name => name)
}
args.each { |arg|
@@ -94,7 +100,7 @@ class TestBasic < Test::Unit::TestCase
end
def test_component
- component = component(file(),service())
+ component = component("a",file(),service())
assert_nothing_raised() {
component.retrieve