[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585

Andrew Shafer andrew at reductivelabs.com
Fri Jan 23 14:21:09 UTC 2009


The following commit has been merged in the master branch:
commit 4a863c38ced0e2581454888b15275aa1eb381e56
Author: Andrew Shafer <andrew at reductivelabs.com>
Date:   Wed Oct 1 17:23:14 2008 -0600

    Adding user_attr util to parse attributes on solaris
    
    read /etc/user_attr and makes a hash based on the file contents

diff --git a/lib/puppet/util/user_attr.rb b/lib/puppet/util/user_attr.rb
new file mode 100644
index 0000000..db8fb81
--- /dev/null
+++ b/lib/puppet/util/user_attr.rb
@@ -0,0 +1,21 @@
+class UserAttr
+    def self.get_attributes_by_name(name)
+        attributes = nil
+
+        File.readlines('/etc/user_attr').each do |line|
+            next if line =~ /^#/
+
+            token = line.split(':')
+
+            if token[0] == name
+                attributes = {:name => name}
+                token[4].split(';').each do |attr|
+                    key_value = attr.split('=')
+                    attributes[key_value[0].intern] = key_value[1].strip
+                end
+                break
+            end
+        end
+        return attributes
+    end
+end
diff --git a/spec/unit/util/user_attr.rb b/spec/unit/util/user_attr.rb
new file mode 100644
index 0000000..57787b1
--- /dev/null
+++ b/spec/unit/util/user_attr.rb
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+require 'puppet/util/user_attr'
+
+describe UserAttr do
+    before do
+        user_attr = ["foo::::type=role", "bar::::type=normal;profile=foobar"]
+        File.stubs(:readlines).returns(user_attr)
+    end
+
+    describe "when getting attributes by name" do
+        it "should return nil if there is no entry for that name" do
+            UserAttr.get_attributes_by_name('baz').should == nil
+        end
+
+        it "should return a hash if there is an entry in /etc/user_attr" do
+            UserAttr.get_attributes_by_name('foo').class.should == Hash
+        end
+
+        it "should return a hash with the name value from /etc/user_attr" do
+             UserAttr.get_attributes_by_name('foo')[:name].should == 'foo'
+        end
+
+        #this test is contrived
+        #there are a bunch of possible parameters that could be in the hash
+        #the role/normal is just a the convention of the file
+        describe "when the name is a role" do
+            it "should contain :type = role" do
+                UserAttr.get_attributes_by_name('foo')[:type].should == 'role'
+            end
+        end
+
+        describe "when the name is not a role" do
+            it "should contain :type = normal" do
+                UserAttr.get_attributes_by_name('bar')[:type].should == 'normal'
+            end
+        end
+
+        describe "when the name has more attributes" do
+            it "should contain all the attributes" do
+                UserAttr.get_attributes_by_name('bar')[:profile].should == 'foobar'
+            end
+        end
+    end
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list