puppet-retrospec 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -0
- data/CHANGELOG.md +11 -0
- data/DEVELOPMENT.md +3 -0
- data/Gemfile +10 -9
- data/Gemfile.lock +2 -0
- data/README.md +211 -273
- data/Rakefile +8 -8
- data/VERSION +1 -1
- data/lib/retrospec-puppet.rb +3 -3
- data/lib/retrospec/plugins/v1/plugin/conditional.rb +5 -6
- data/lib/retrospec/plugins/v1/plugin/exceptions.rb +17 -0
- data/lib/retrospec/plugins/v1/plugin/generators.rb +7 -0
- data/lib/retrospec/plugins/v1/plugin/generators/fact_generator.rb +18 -10
- data/lib/retrospec/plugins/v1/plugin/generators/function_generator.rb +187 -0
- data/lib/retrospec/plugins/v1/plugin/generators/module_generator.rb +25 -26
- data/lib/retrospec/plugins/v1/plugin/generators/{facter.rb → parsers/facter.rb} +28 -35
- data/lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb +91 -0
- data/lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb +79 -0
- data/lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb +107 -0
- data/lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb +221 -0
- data/lib/retrospec/plugins/v1/plugin/generators/type_generator.rb +118 -0
- data/lib/retrospec/plugins/v1/plugin/helpers.rb +3 -7
- data/lib/retrospec/plugins/v1/plugin/puppet.rb +141 -60
- data/lib/retrospec/plugins/v1/plugin/puppet_module.rb +29 -26
- data/lib/retrospec/plugins/v1/plugin/resource.rb +6 -7
- data/lib/retrospec/plugins/v1/plugin/spec_object.rb +5 -8
- data/lib/retrospec/plugins/v1/plugin/template_helpers.rb +9 -10
- data/lib/retrospec/plugins/v1/plugin/templates/clone-hook +15 -8
- data/lib/retrospec/plugins/v1/plugin/type_code.rb +4 -4
- data/lib/retrospec/plugins/v1/plugin/variable_store.rb +26 -30
- data/lib/retrospec/plugins/v1/plugin/version.rb +1 -1
- data/puppet-retrospec.gemspec +43 -4
- data/spec/fixtures/facts/oracle_controls.rb +38 -0
- data/spec/fixtures/fixture_modules/required_parameters/manifests/init.pp +8 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/facter/fix_installed.rb +11 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/awesome_parser.rb +13 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb +31 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/bad_sha1.rb +6 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/defined.rb +94 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/sha1.rb +6 -0
- data/spec/fixtures/fixture_modules/sample_module/spec/unit/facter/fix_installed_spec.rb +21 -0
- data/spec/fixtures/modules/tomcat/files/.gitkeep +0 -0
- data/spec/fixtures/modules/tomcat/templates/.gitkeep +0 -0
- data/spec/fixtures/modules/tomcat/tests/.gitkeep +0 -0
- data/spec/fixtures/providers/bmc/ipmitool.rb +188 -0
- data/spec/fixtures/providers/bmcuser/ipmitool.rb +140 -0
- data/spec/fixtures/types/bmc.rb +102 -0
- data/spec/fixtures/types/bmcuser.rb +46 -0
- data/spec/fixtures/types/db_opatch.rb +93 -0
- data/spec/integration/retrospec_spec.rb +1 -3
- data/spec/spec_helper.rb +33 -6
- data/spec/unit/conditional_spec.rb +12 -15
- data/spec/unit/generators/fact_generater_spec.rb +49 -17
- data/spec/unit/generators/function_generator_spec.rb +301 -0
- data/spec/unit/generators/function_spec.rb +67 -0
- data/spec/unit/generators/parsers/fact_spec.rb +62 -0
- data/spec/unit/generators/parsers/provider_spec.rb +44 -0
- data/spec/unit/generators/parsers/type_spec.rb +93 -0
- data/spec/unit/generators/provider_generator_spec.rb +120 -0
- data/spec/unit/generators/schema_generator_spec.rb +122 -0
- data/spec/unit/generators/type_generator_spec.rb +173 -0
- data/spec/unit/module_spec.rb +7 -10
- data/spec/unit/plugin_spec.rb +213 -15
- data/spec/unit/puppet-retrospec_spec.rb +81 -100
- data/spec/unit/resource_spec.rb +16 -17
- data/spec/unit/spec_object_spec.rb +46 -0
- data/spec/unit/type_code_spec.rb +9 -11
- data/spec/unit/variable_store_spec.rb +41 -43
- metadata +54 -4
- data/spec/unit/generators/fact_spec.rb +0 -58
data/puppet-retrospec.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "puppet-retrospec"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.12.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Corey Osman"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2016-01-26"
|
13
13
|
s.description = "Retrofits and generates valid puppet rspec test code to existing modules"
|
14
14
|
s.email = "corey@logicminds.biz"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,8 +19,10 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".rspec",
|
22
|
+
".rubocop.yml",
|
22
23
|
".travis.yml",
|
23
24
|
"CHANGELOG.md",
|
25
|
+
"DEVELOPMENT.md",
|
24
26
|
"Gemfile",
|
25
27
|
"Gemfile.lock",
|
26
28
|
"LICENSE",
|
@@ -29,9 +31,17 @@ Gem::Specification.new do |s|
|
|
29
31
|
"VERSION",
|
30
32
|
"lib/retrospec-puppet.rb",
|
31
33
|
"lib/retrospec/plugins/v1/plugin/conditional.rb",
|
34
|
+
"lib/retrospec/plugins/v1/plugin/exceptions.rb",
|
35
|
+
"lib/retrospec/plugins/v1/plugin/generators.rb",
|
32
36
|
"lib/retrospec/plugins/v1/plugin/generators/fact_generator.rb",
|
33
|
-
"lib/retrospec/plugins/v1/plugin/generators/
|
37
|
+
"lib/retrospec/plugins/v1/plugin/generators/function_generator.rb",
|
34
38
|
"lib/retrospec/plugins/v1/plugin/generators/module_generator.rb",
|
39
|
+
"lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb",
|
40
|
+
"lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb",
|
41
|
+
"lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb",
|
42
|
+
"lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb",
|
43
|
+
"lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb",
|
44
|
+
"lib/retrospec/plugins/v1/plugin/generators/type_generator.rb",
|
35
45
|
"lib/retrospec/plugins/v1/plugin/helpers.rb",
|
36
46
|
"lib/retrospec/plugins/v1/plugin/puppet.rb",
|
37
47
|
"lib/retrospec/plugins/v1/plugin/puppet_module.rb",
|
@@ -46,10 +56,19 @@ Gem::Specification.new do |s|
|
|
46
56
|
"spec/fixtures/facts/datacenter_facts.rb",
|
47
57
|
"spec/fixtures/facts/facts_with_methods.rb",
|
48
58
|
"spec/fixtures/facts/node_role.rb",
|
59
|
+
"spec/fixtures/facts/oracle_controls.rb",
|
49
60
|
"spec/fixtures/fixture_modules/one_resource_module/manifests/another_resource.pp",
|
50
61
|
"spec/fixtures/fixture_modules/one_resource_module/manifests/inherits_params.pp",
|
51
62
|
"spec/fixtures/fixture_modules/one_resource_module/manifests/one_resource_class.pp",
|
52
63
|
"spec/fixtures/fixture_modules/one_resource_module/manifests/params.pp",
|
64
|
+
"spec/fixtures/fixture_modules/required_parameters/manifests/init.pp",
|
65
|
+
"spec/fixtures/fixture_modules/sample_module/lib/facter/fix_installed.rb",
|
66
|
+
"spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/awesome_parser.rb",
|
67
|
+
"spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb",
|
68
|
+
"spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/bad_sha1.rb",
|
69
|
+
"spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/defined.rb",
|
70
|
+
"spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/sha1.rb",
|
71
|
+
"spec/fixtures/fixture_modules/sample_module/spec/unit/facter/fix_installed_spec.rb",
|
53
72
|
"spec/fixtures/fixture_modules/zero_resource_module/manifests/empty_class.pp",
|
54
73
|
"spec/fixtures/fixture_modules/zero_resource_module/manifests/not_a_resource_defination.pp",
|
55
74
|
"spec/fixtures/fixture_modules/zero_resource_module/metadata.json",
|
@@ -525,6 +544,7 @@ Gem::Specification.new do |s|
|
|
525
544
|
"spec/fixtures/modules/stdlib/tests/has_ip_address.pp",
|
526
545
|
"spec/fixtures/modules/stdlib/tests/has_ip_network.pp",
|
527
546
|
"spec/fixtures/modules/stdlib/tests/init.pp",
|
547
|
+
"spec/fixtures/modules/tomcat/.bundle/config",
|
528
548
|
"spec/fixtures/modules/tomcat/.gitignore",
|
529
549
|
"spec/fixtures/modules/tomcat/.puppet-lint.rc",
|
530
550
|
"spec/fixtures/modules/tomcat/.travis.yml",
|
@@ -543,6 +563,7 @@ Gem::Specification.new do |s|
|
|
543
563
|
"spec/fixtures/modules/tomcat/examples/instance_with_role_and_user.pp",
|
544
564
|
"spec/fixtures/modules/tomcat/examples/jsvc_install_from_source.pp",
|
545
565
|
"spec/fixtures/modules/tomcat/examples/multiple_instances.pp",
|
566
|
+
"spec/fixtures/modules/tomcat/files/.gitkeep",
|
546
567
|
"spec/fixtures/modules/tomcat/manifests/config/server.pp",
|
547
568
|
"spec/fixtures/modules/tomcat/manifests/config/server/connector.pp",
|
548
569
|
"spec/fixtures/modules/tomcat/manifests/config/server/context.pp",
|
@@ -562,15 +583,30 @@ Gem::Specification.new do |s|
|
|
562
583
|
"spec/fixtures/modules/tomcat/manifests/setenv/entry.pp",
|
563
584
|
"spec/fixtures/modules/tomcat/manifests/war.pp",
|
564
585
|
"spec/fixtures/modules/tomcat/metadata.json",
|
586
|
+
"spec/fixtures/modules/tomcat/templates/.gitkeep",
|
587
|
+
"spec/fixtures/modules/tomcat/tests/.gitkeep",
|
588
|
+
"spec/fixtures/providers/bmc/ipmitool.rb",
|
589
|
+
"spec/fixtures/providers/bmcuser/ipmitool.rb",
|
590
|
+
"spec/fixtures/types/bmc.rb",
|
591
|
+
"spec/fixtures/types/bmcuser.rb",
|
592
|
+
"spec/fixtures/types/db_opatch.rb",
|
565
593
|
"spec/integration/retrospec_spec.rb",
|
566
594
|
"spec/spec_helper.rb",
|
567
595
|
"spec/unit/conditional_spec.rb",
|
568
596
|
"spec/unit/generators/fact_generater_spec.rb",
|
569
|
-
"spec/unit/generators/
|
597
|
+
"spec/unit/generators/function_generator_spec.rb",
|
598
|
+
"spec/unit/generators/function_spec.rb",
|
599
|
+
"spec/unit/generators/parsers/fact_spec.rb",
|
600
|
+
"spec/unit/generators/parsers/provider_spec.rb",
|
601
|
+
"spec/unit/generators/parsers/type_spec.rb",
|
602
|
+
"spec/unit/generators/provider_generator_spec.rb",
|
603
|
+
"spec/unit/generators/schema_generator_spec.rb",
|
604
|
+
"spec/unit/generators/type_generator_spec.rb",
|
570
605
|
"spec/unit/module_spec.rb",
|
571
606
|
"spec/unit/plugin_spec.rb",
|
572
607
|
"spec/unit/puppet-retrospec_spec.rb",
|
573
608
|
"spec/unit/resource_spec.rb",
|
609
|
+
"spec/unit/spec_object_spec.rb",
|
574
610
|
"spec/unit/type_code_spec.rb",
|
575
611
|
"spec/unit/variable_store_spec.rb",
|
576
612
|
"vendor/gems/puppet-3.7.3/Gemfile",
|
@@ -1832,6 +1868,7 @@ Gem::Specification.new do |s|
|
|
1832
1868
|
s.add_runtime_dependency(%q<trollop>, [">= 0"])
|
1833
1869
|
s.add_runtime_dependency(%q<retrospec>, ["~> 0.4"])
|
1834
1870
|
s.add_runtime_dependency(%q<awesome_print>, [">= 0"])
|
1871
|
+
s.add_runtime_dependency(%q<facets>, [">= 0"])
|
1835
1872
|
s.add_development_dependency(%q<rspec>, ["~> 3.2"])
|
1836
1873
|
s.add_development_dependency(%q<puppet>, ["= 3.7.3"])
|
1837
1874
|
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
@@ -1844,6 +1881,7 @@ Gem::Specification.new do |s|
|
|
1844
1881
|
s.add_dependency(%q<trollop>, [">= 0"])
|
1845
1882
|
s.add_dependency(%q<retrospec>, ["~> 0.4"])
|
1846
1883
|
s.add_dependency(%q<awesome_print>, [">= 0"])
|
1884
|
+
s.add_dependency(%q<facets>, [">= 0"])
|
1847
1885
|
s.add_dependency(%q<rspec>, ["~> 3.2"])
|
1848
1886
|
s.add_dependency(%q<puppet>, ["= 3.7.3"])
|
1849
1887
|
s.add_dependency(%q<yard>, ["~> 0.7"])
|
@@ -1857,6 +1895,7 @@ Gem::Specification.new do |s|
|
|
1857
1895
|
s.add_dependency(%q<trollop>, [">= 0"])
|
1858
1896
|
s.add_dependency(%q<retrospec>, ["~> 0.4"])
|
1859
1897
|
s.add_dependency(%q<awesome_print>, [">= 0"])
|
1898
|
+
s.add_dependency(%q<facets>, [">= 0"])
|
1860
1899
|
s.add_dependency(%q<rspec>, ["~> 3.2"])
|
1861
1900
|
s.add_dependency(%q<puppet>, ["= 3.7.3"])
|
1862
1901
|
s.add_dependency(%q<yard>, ["~> 0.7"])
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
Facter.add(:oracle_controls) do
|
4
|
+
setcode do
|
5
|
+
confine :kernel => 'Linux'
|
6
|
+
confine :type => 'oracle'
|
7
|
+
script_data
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# returns boolean true if all the checks pass
|
12
|
+
Facter.add(:oracle_security_status) do
|
13
|
+
setcode do
|
14
|
+
confine :kernel => 'Linux'
|
15
|
+
confine :type => 'oracle'
|
16
|
+
# check all items in the hash and return true/false if any of them have failed
|
17
|
+
if script_data
|
18
|
+
! script_data.find { | item| item['status'] =~ /true/i }.empty? # negate because an empty array means all passing
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# return the data by running the check db script and store in a variable for later caching
|
24
|
+
# return nil if script cannot be run
|
25
|
+
def script_data
|
26
|
+
unless @script_data
|
27
|
+
script = '/some/script.sh'
|
28
|
+
return nil unless File.exists?(script)
|
29
|
+
cmd = "#{script}"
|
30
|
+
json_data = Facter::Core::Execution.execute("/bin/su -c '#{cmd}' - oracle", :on_fail => nil)
|
31
|
+
if json_data
|
32
|
+
@script_data = JSON.parse(json_data)
|
33
|
+
else
|
34
|
+
@script_data = nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
@script_data
|
38
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# extremely helpful documentation
|
2
|
+
# https://github.com/puppetlabs/puppet-specifications/blob/master/language/func-api.md#the-4x-api
|
3
|
+
Puppet::Functions.create_function(:awesome_parser) do
|
4
|
+
# the function below is called by puppet and and must match
|
5
|
+
# the name of the puppet function above. You can set your
|
6
|
+
# required parameters below and puppet 4 will enforce these
|
7
|
+
# change x and y to suit your needs although only one parameter is required
|
8
|
+
def awesome_parser(x,y)
|
9
|
+
x >= y ? x : y
|
10
|
+
end
|
11
|
+
|
12
|
+
# you can define other helper methods in this code block as well
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Puppet::Functions.create_function(:reduce) do
|
2
|
+
|
3
|
+
dispatch :reduce_without_memo do
|
4
|
+
param 'Any', :enumerable
|
5
|
+
block_param 'Callable[2,2]', :block
|
6
|
+
end
|
7
|
+
|
8
|
+
dispatch :reduce_with_memo do
|
9
|
+
param 'Any', :enumerable
|
10
|
+
param 'Any', :memo
|
11
|
+
block_param 'Callable[2,2]', :block
|
12
|
+
end
|
13
|
+
|
14
|
+
def reduce_without_memo(enumerable)
|
15
|
+
enum = asserted_enumerable(enumerable)
|
16
|
+
enum.reduce {|memo, x| yield(memo, x) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def reduce_with_memo(enumerable, given_memo)
|
20
|
+
enum = asserted_enumerable(enumerable)
|
21
|
+
enum.reduce(given_memo) {|memo, x| yield(memo, x) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def asserted_enumerable(obj)
|
25
|
+
unless enum = Puppet::Pops::Types::Enumeration.enumerator(obj)
|
26
|
+
raise ArgumentError, ("#{self.class.name}(): wrong argument type (#{obj.class}; must be something enumerable.")
|
27
|
+
end
|
28
|
+
enum
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# Test whether a given class or definition is defined
|
2
|
+
Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :arity => -2,
|
3
|
+
:doc => "Determine whether
|
4
|
+
a given class or resource type is defined. This function can also determine whether a
|
5
|
+
specific resource has been defined, or whether a variable has been assigned a value
|
6
|
+
(including `undef` - as opposed to never having been assigned anything). Returns `true`
|
7
|
+
or `false`. Accepts class names, type names, resource references, and variable
|
8
|
+
reference strings of the form `'$name'`. When more than one argument is
|
9
|
+
supplied, `defined()` returns `true` if any are defined.
|
10
|
+
|
11
|
+
The `defined` function checks both native and defined types, including types
|
12
|
+
provided as plugins via modules. Types and classes are both checked using their names:
|
13
|
+
|
14
|
+
defined(\"file\")
|
15
|
+
defined(\"customtype\")
|
16
|
+
defined(\"foo\")
|
17
|
+
defined(\"foo::bar\")
|
18
|
+
defined(\'$name\')
|
19
|
+
|
20
|
+
Resource declarations are checked using resource references, e.g.
|
21
|
+
`defined( File['/tmp/myfile'] )`. Checking whether a given resource
|
22
|
+
has been declared is, unfortunately, dependent on the evaluation order of
|
23
|
+
the configuration, and the following code will not work:
|
24
|
+
|
25
|
+
if defined(File['/tmp/foo']) {
|
26
|
+
notify { \"This configuration includes the /tmp/foo file.\":}
|
27
|
+
}
|
28
|
+
file { \"/tmp/foo\":
|
29
|
+
ensure => present,
|
30
|
+
}
|
31
|
+
|
32
|
+
However, this order requirement refers to evaluation order only, and ordering of
|
33
|
+
resources in the configuration graph (e.g. with `before` or `require`) does not
|
34
|
+
affect the behavior of `defined`.
|
35
|
+
|
36
|
+
You may also search using types:
|
37
|
+
|
38
|
+
defined(Resource[\'file\',\'/some/file\'])
|
39
|
+
defined(File[\'/some/file\'])
|
40
|
+
defined(Class[\'foo\'])
|
41
|
+
|
42
|
+
The `defined` function does not answer if 4.x data types (e.g. `Integer`) are defined. If
|
43
|
+
given the string 'integer' the result is false, and if given a non CatalogEntry type,
|
44
|
+
an error is raised.
|
45
|
+
|
46
|
+
The rules for asking for undef, empty strings, and the main class are different from 3.x
|
47
|
+
(non future parser) and 4.x (with future parser or in Puppet 4.0.0 and later):
|
48
|
+
|
49
|
+
defined('') # 3.x => true, 4.x => false
|
50
|
+
defined(undef) # 3.x => true, 4.x => error
|
51
|
+
defined('main') # 3.x => false, 4.x => true
|
52
|
+
|
53
|
+
With the future parser, it is also possible to ask specifically if a name is
|
54
|
+
a resource type (built in or defined), or a class, by giving its type:
|
55
|
+
|
56
|
+
defined(Type[Class['foo']])
|
57
|
+
defined(Type[Resource['foo']])
|
58
|
+
|
59
|
+
Which is different from asking:
|
60
|
+
|
61
|
+
defined('foo')
|
62
|
+
|
63
|
+
Since the later returns true if 'foo' is either a class, a built-in resource type, or a user defined
|
64
|
+
resource type, and a specific request like `Type[Class['foo']]` only returns true if `'foo'` is a class.
|
65
|
+
|
66
|
+
- Since 2.7.0
|
67
|
+
- Since 3.6.0 variable reference and future parser types
|
68
|
+
- Since 3.8.1 type specific requests with future parser") do |vals|
|
69
|
+
vals = [vals] unless vals.is_a?(Array)
|
70
|
+
vals.any? do |val|
|
71
|
+
case val
|
72
|
+
when String
|
73
|
+
if m = /^\$(.+)$/.match(val)
|
74
|
+
exist?(m[1])
|
75
|
+
else
|
76
|
+
find_resource_type(val) || find_definition(val) || find_hostclass(val)
|
77
|
+
end
|
78
|
+
when Puppet::Resource
|
79
|
+
compiler.findresource(val.type, val.title)
|
80
|
+
when Puppet::Pops::Types::PResourceType
|
81
|
+
raise ArgumentError, "The given resource type is a reference to all kind of types" if val.type_name.nil?
|
82
|
+
if val.title.nil?
|
83
|
+
find_builtin_resource_type(val.type_name) || find_definition(val.type_name)
|
84
|
+
else
|
85
|
+
compiler.findresource(val.type_name, val.title)
|
86
|
+
end
|
87
|
+
when Puppet::Pops::Types::PHostClassType
|
88
|
+
raise ArgumentError, "The given class type is a reference to all classes" if val.class_name.nil?
|
89
|
+
find_hostclass(val.class_name)
|
90
|
+
else
|
91
|
+
raise ArgumentError, "Invalid argument of type '#{val.class}' to 'defined'"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'facter'
|
3
|
+
|
4
|
+
describe :fix_installed, :type => :fact do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
# perform any action that should be run for the entire test suite
|
8
|
+
end
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
# perform any action that should be run before every test
|
12
|
+
Facter.clear
|
13
|
+
# This will mock the facts that confine uses to limit facts running under certain conditions
|
14
|
+
allow(Facter.fact(:kernel)).to receive(:value).and_return("windows")
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return a value' do
|
19
|
+
expect(Facter.fact(:fix_installed).value).to eq('value123') #<-- change the value to match your expectation
|
20
|
+
end
|
21
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,188 @@
|
|
1
|
+
Puppet::Type.type(:bmc).provide(:ipmitool) do
|
2
|
+
desc "Provides ipmitool support for the bmc type"
|
3
|
+
|
4
|
+
commands :ipmitoolcmd => 'ipmitool'
|
5
|
+
# if the open ipmi driver does not exist we can perform any of these configurations
|
6
|
+
# check to see that openipmi driver is loaded and ipmi device exists
|
7
|
+
confine :bmc_device_present => [:true, true]
|
8
|
+
|
9
|
+
mk_resource_methods
|
10
|
+
|
11
|
+
CHANNEL_LOOKUP = {
|
12
|
+
'Dell Inc.' => '1',
|
13
|
+
'FUJITSU' => '2',
|
14
|
+
'FUJITSU SIEMENS' => '2',
|
15
|
+
'HP' => '2',
|
16
|
+
'Intel Corporation' => '3',
|
17
|
+
}
|
18
|
+
def initialize(value={})
|
19
|
+
super(value)
|
20
|
+
@property_flush = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
# the flush method will be the last method called after applying all the other
|
24
|
+
# properties, by default nothing will be enabled or disabled unless the disable/enable are set to true
|
25
|
+
# if we ever move to a point were we can write all the settings via one big config file we
|
26
|
+
# would want to do that here.
|
27
|
+
def flush
|
28
|
+
if @property_flush
|
29
|
+
if @property_flush[:disable]
|
30
|
+
disable_channel #TODO is this needed?
|
31
|
+
elsif @property_flush[:enable]
|
32
|
+
enable_channel # TODO is this needed? what does this do ?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
# resets the interface
|
36
|
+
Puppet.debug('rebooting the bmc device')
|
37
|
+
ipmitoolcmd(['bmc', 'reset', 'cold'])
|
38
|
+
end
|
39
|
+
|
40
|
+
##### These are the default ensurable methods that must be implemented
|
41
|
+
def install
|
42
|
+
if resource[:ipsource] == :static
|
43
|
+
ip = resource[:ip]
|
44
|
+
netmask = resource[:netmask]
|
45
|
+
gateway = resource[:gateway]
|
46
|
+
end
|
47
|
+
|
48
|
+
ipsource = resource[:ipsource]
|
49
|
+
if resource[:vlanid]
|
50
|
+
vlanid = resource[:vlanid]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def remove
|
55
|
+
ipsource = "dhcp"
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def exists?
|
60
|
+
@property_hash[:ensure] == :present
|
61
|
+
end
|
62
|
+
|
63
|
+
# return all instances of this resource which really should only be one instance
|
64
|
+
def self.instances
|
65
|
+
info = self.laninfo
|
66
|
+
inst = new(
|
67
|
+
:name => info["mac address"],
|
68
|
+
:ensure => :present,
|
69
|
+
:ip => info["ip address"],
|
70
|
+
:netmask => info["subnet mask"],
|
71
|
+
:gateway => info["default gateway ip"],
|
72
|
+
:vlanid => info["802.1q vlan id"],
|
73
|
+
:ipsource => info["ip address source"]
|
74
|
+
)
|
75
|
+
[inst]
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.prefetch(resources)
|
79
|
+
devices = instances
|
80
|
+
if devices
|
81
|
+
resources.keys.each do | name|
|
82
|
+
if provider = devices.find{|device| device.name == name }
|
83
|
+
resources[name].provider = provider
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#def snmp
|
90
|
+
# # TODO implement how to get the snmp string even when the device doesn't support snmp lookups
|
91
|
+
#end
|
92
|
+
#
|
93
|
+
#def snmp=(community)
|
94
|
+
# ipmitoolcmd 'lan set 1 snmp', community
|
95
|
+
#end
|
96
|
+
|
97
|
+
# end - bmc parameters
|
98
|
+
|
99
|
+
def self.laninfo
|
100
|
+
landata = ipmitoolcmd([ "lan", "print", CHANNEL_LOOKUP.fetch(Facter.value(:manufacturer), '1') ])
|
101
|
+
info = {}
|
102
|
+
landata.lines.each do |line|
|
103
|
+
# clean up the data from spaces
|
104
|
+
item = line.split(':', 2)
|
105
|
+
key = item.first.strip.downcase
|
106
|
+
value = item.last.strip
|
107
|
+
info[key] = value
|
108
|
+
end
|
109
|
+
info
|
110
|
+
info['ip address source'] = convert_ip_source(info['ip address source'])
|
111
|
+
info["802.1q vlan id"] = convert_vlanid(info["802.1q vlan id"])
|
112
|
+
info
|
113
|
+
end
|
114
|
+
|
115
|
+
def gateway=(address)
|
116
|
+
ipmitoolcmd([ "lan", "set", channel, "defgw", "ipaddr", address ])
|
117
|
+
end
|
118
|
+
|
119
|
+
def ipsource=(source)
|
120
|
+
ipmitoolcmd([ "lan", "set", channel, "ipsrc", source.to_s ])
|
121
|
+
end
|
122
|
+
|
123
|
+
def ip=(address)
|
124
|
+
ipmitoolcmd([ "lan", "set", channel, "ipaddr", address ])
|
125
|
+
end
|
126
|
+
|
127
|
+
def netmask=(subnet)
|
128
|
+
ipmitoolcmd([ "lan", "set", channel, "netmask", subnet ])
|
129
|
+
end
|
130
|
+
|
131
|
+
def vlanid=(vid)
|
132
|
+
ipmitoolcmd([ "lan", "set", channel, "vlan", "id", vid ])
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.convert_vlanid(id)
|
136
|
+
if id =~ /Disabled/i
|
137
|
+
'off'
|
138
|
+
else
|
139
|
+
id
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.convert_ip_source(src)
|
144
|
+
case src
|
145
|
+
when /static/i
|
146
|
+
:static
|
147
|
+
when /dhcp/i
|
148
|
+
:dhcp
|
149
|
+
else
|
150
|
+
src
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def mac
|
157
|
+
lanconfig["mac address"]
|
158
|
+
end
|
159
|
+
|
160
|
+
def dhcp?
|
161
|
+
lanconfig["ip address source"].match(/dhcp/i) != nil
|
162
|
+
end
|
163
|
+
|
164
|
+
def static?
|
165
|
+
lanconfig["ip address source"].match(/static/i) != nil
|
166
|
+
end
|
167
|
+
|
168
|
+
def channel_enabled?
|
169
|
+
# TODO implement how to look up this info
|
170
|
+
true
|
171
|
+
end
|
172
|
+
|
173
|
+
def channel
|
174
|
+
CHANNEL_LOOKUP.fetch(Facter.value(:manufacturer), '1')
|
175
|
+
end
|
176
|
+
|
177
|
+
def enable_channel
|
178
|
+
ipmitoolcmd([ "lan", "set", channel, "access", "on" ])
|
179
|
+
end
|
180
|
+
|
181
|
+
def disable_channel
|
182
|
+
ipmitoolcmd([ "lan", "set", channel, "access", "off" ])
|
183
|
+
end
|
184
|
+
|
185
|
+
def lanconfig
|
186
|
+
@lanconfig ||= self.class.laninfo
|
187
|
+
end
|
188
|
+
end
|