diff --git a/.gitignore b/.gitignore index 9e9b3ab..be75e51 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ pkg/ -Gemfile.lock -.vendor +vendor/ spec/fixtures/ .vagrant/ .bundle/ @@ -11,3 +10,7 @@ Puppetfile.lock .librarian/ log Vagrantfile +.DS_Store +Gemfile.local +.idea/ +Gemfile.lock diff --git a/.rubocop.ruby-1.8.7.yml b/.rubocop.ruby-1.8.7.yml new file mode 100644 index 0000000..207d68a --- /dev/null +++ b/.rubocop.ruby-1.8.7.yml @@ -0,0 +1,20 @@ +# Ruby 1.8.7 needs the . on chain of method calls at the end of a line +Style/DotPosition: + EnforcedStyle: trailing + +# Ruby 1.8.7 doesn't have the -> lambda +Style/Lambda: + Enabled: false + +# Ruby 1.8.7 doesn't have 1.9 style hash syntax +Style/HashSyntax: + EnforcedStyle: hash_rockets + +Style/StringLiterals: + Enabled: false + +Style/Documentation: + Enabled: false + +Metrics/LineLength: + Max: 140 diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..bd54733 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,6 @@ +AllCops: + Exclude: + - 'vendor/**/*' + +Metrics/LineLength: + Max: 140 diff --git a/.travis.yml b/.travis.yml index 67dde71..5742408 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,19 +8,28 @@ addons: packages: - libaugeas-dev - libxml2-dev -bundler_args: --without development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle} + - libgmp3-dev +bundler_args: "--without development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}" cache: bundler script: bundle exec rake test -before_install: rm -f Gemfile.lock +before_install: + - 'bundler --version || gem install bundler' # TODO:Remove if fixed - travis-ci/travis-ci#5578 + - 'rm -f Gemfile.lock' matrix: fast_finish: true include: - rvm: '1.8' env: PUPPET_VERSION="~> 2.7.0" FACTER_VERSION="~> 1.6.0" + gemfile: gemfiles/Gemfile18.facter16 + bundler_args: "--without development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-../vendor/bundle}" - rvm: '1.8' env: PUPPET_VERSION="~> 2.7.0" FACTER_VERSION="~> 1.7.0" + gemfile: gemfiles/Gemfile18.facter17 + bundler_args: "--without development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-../vendor/bundle}" - rvm: '1.9' env: PUPPET_VERSION="~> 3.0" + gemfile: gemfiles/Gemfile19 + bundler_args: "--without development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-../vendor/bundle}" - rvm: '2.0' env: PUPPET_VERSION="~> 3.0" - rvm: '2.1' @@ -30,18 +39,24 @@ matrix: - rvm: '2.1' sudo: required services: docker - env: PUPPET_VERSION="3.8.4" RS_SET="centos-6-x86_64-docker" + env: PUPPET_VERSION="3.8.5" RS_SET="centos-6-x86_64-docker" script: bundle exec rake acceptance - rvm: '2.1' sudo: required services: docker - env: PUPPET_VERSION="3.8.4" RS_SET="debian-7-x86_64-docker" + env: PUPPET_VERSION="3.8.5" RS_SET="debian-7-x86_64-docker" script: bundle exec rake acceptance - rvm: '2.1' sudo: required services: docker - env: PUPPET_VERSION="3.8.4" RS_SET="ubuntu-14.04-x86_64-docker" + env: PUPPET_VERSION="3.8.5" RS_SET="ubuntu-14.04-x86_64-docker" script: bundle exec rake acceptance # FIXME: GH Issue #3 - Activate acceptance tests on Travis CI for Puppet Enterprise, at least 2.8.8 and 3.8.2 notifications: email: false + slack: + rooms: + secure: jKciSvj0RpuEcUSuEG4jXTsfWKo3sN1eYzdy9fdeO6ku7PCVkbLWunfrED7zEHGbfiiiAkdUoMqrgxQIz+iyEmS/kusa3/3II4J4NYcQE3jJz4+57ovfoMEJY1NWGofohW06NHkg+c9VwPKdtdUDWEcJ9jVvntXcPlMyJkoSk7I+EWyonyR/hzhDn8EjYGA+PQ+xdFAvBr1hN+1AFUGVwOub91Kv5UGjT6A/kqKx0uNUqF1raiizmpx2AZDixGnDRv2RpDDKjdUjA34RIHXxTrJvP4GIDInEho9Cnt11/OJtk7xm65wBS7vA3eCKse/QoPmbTpO21+HG0/pwKDujZL9mcbCGofRpfTtrDS5Fd0y3VxC3iyJN3fOUP9hxk3u+SZDWXFQAFVoR12LI9FMNSV5p4Kb0HoZ+6y7rk72ET0a76ubHu+r04pH14g8JTWi2ILI4DTvXOixmNZZIYbk8iodLUcxoubyIDcKkvaJ1MjXlEF3ZVg3+HYtk42xyir6uSKjA9OTHuHJkmxzSkjLaGh5SayhTTCf9FKiPcjztM2dHyZ18F0ZwCWAqmiMtSgKS9NkIBL1xJJWa8NAo8q5XOi1dlGUqLrQIxuA0aRoICxHjXF31hg7qRzzCZMM0MptNbkNxtxFtzg1n9tGQyepJBZyWJxvvk31N1sLHhdxFrDQ= + on_success: always + on_failure: always + on_start: always diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ab580eb..aaa173d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,10 +34,12 @@ you must set an environment variable such as: export PUPPET_VERSION="~> 3.2.0" -Install the dependencies like so... (you can also ass `--path /fs/path/for/deps` to fetch dependencies to other directory) +Install the dependencies like so... (you can also pass `--path /fs/path/for/deps` to fetch dependencies to other directory) bundle install +If you want to use Ruby 1.8 that we still support you have to pass `--gemfile gemfiles/Gemfile18.facter17` to download correct versions of gems that we use. + ## Syntax and style The test suite will run [Puppet Lint](http://puppet-lint.com/) and diff --git a/Gemfile b/Gemfile index 87f38cb..a533d30 100644 --- a/Gemfile +++ b/Gemfile @@ -1,35 +1,25 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' group :test do - gem 'rake', :require => false - gem 'rspec-puppet', :require => false + gem 'rake', :require => false unless dependencies.map {|dep| dep.name}.include?('rake') + # TODO: Remove this explicitly pinned version by the time ticket gh-org/puppet-jboss#84 is closed. + gem 'rspec-puppet', '2.3.2', :require => false gem 'puppetlabs_spec_helper', :require => false gem 'puppet-lint', :require => false gem 'metadata-json-lint', :require => false - gem 'json', :require => false - - if RUBY_VERSION >= '1.9.0' - gem 'beaker', :require => false - gem 'beaker-rspec', :require => false - gem 'docker-api', :require => false - gem 'coveralls', :require => false - gem 'codeclimate-test-reporter', :require => false - gem 'simplecov', :require => false - end + gem 'os', :require => false + gem 'beaker', :require => false + gem 'beaker-rspec', :require => false + gem 'docker-api', :require => false + gem 'coveralls', :require => false + gem 'codeclimate-test-reporter', :require => false + gem 'simplecov', :require => false if facterver = ENV['FACTER_VERSION'] gem 'facter', facterver, :require => false else gem 'facter', :require => false end - puppetver = if RUBY_VERSION < '1.9.0' then '~> 2.7.0' else ENV['PUPPET_VERSION'] end - if puppetver - gem 'puppet', puppetver, :require => false - if Gem::Requirement.new(puppetver) =~ Gem::Version.new('2.7.0') - gem 'hiera-puppet', :require => false - end - else - gem 'puppet', '~> 3.0', :require => false - end + gem 'puppet', '~> 3.0', :require => false gem 'ruby-augeas', :require => false gem 'augeas', :require => false end @@ -37,19 +27,9 @@ end group :development do gem 'inch', :require => false gem 'vagrant-wrapper', :require => false - if RUBY_VERSION >= '1.9.0' - gem 'travis', :require => false - gem 'puppet-blacksmith', :require => false - gem 'guard-rake', :require => false - if RUBY_VERSION >= '2.0.0' - gem 'pry-byebug', :require => false - else - gem 'pry-debugger', :require => false - end - end + gem 'travis', :require => false + gem 'puppet-blacksmith', :require => false + gem 'pry-byebug', :require => false end -eval(IO.read(File.join(File.dirname(__FILE__), 'Gemfile.ruby19')), binding) if RUBY_VERSION < '2.0.0' and RUBY_VERSION >= '1.9.0' -eval(IO.read(File.join(File.dirname(__FILE__), 'Gemfile.ruby18')), binding) if RUBY_VERSION < '1.9.0' - # vim:ft=ruby diff --git a/Gemfile.ruby18 b/Gemfile.ruby18 deleted file mode 100644 index 2a524d2..0000000 --- a/Gemfile.ruby18 +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env ruby -# This is extra Gemfile for dependencies in old Ruby 1.8.x - -group :test do - gem 'rspec-its', :require => false - gem 'rspec', '~> 3.1.0', :require => false - - gem 'tins', '~> 1.6.0', :require => false if RUBY_VERSION < '1.9.0' and RUBY_VERSION >= '1.8.0' -end - -group :development do - gem 'pry', '~> 0.9.12.0', :require => false -end diff --git a/Gemfile.ruby19 b/Gemfile.ruby19 deleted file mode 100644 index 1dac4df..0000000 --- a/Gemfile.ruby19 +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby -# This is extra Gemfile for dependencies in old Ruby 1.9.x - -group :test do - gem 'tins', '~> 1.6.0', require: false if RUBY_VERSION < '2.0.0' and RUBY_VERSION >= '1.9.0' -end diff --git a/README.md b/README.md index e853091..51ea301 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### ...with configuration management of resources and deployment in domain and stand-alone modes -[![Build Status](https://travis-ci.org/coi-gov-pl/puppet-jboss.svg?branch=develop)](https://travis-ci.org/coi-gov-pl/puppet-jboss) [![Puppet Forge](https://img.shields.io/puppetforge/v/coi/jboss.svg)](https://forge.puppetlabs.com/coi/jboss) [![Code Climate](https://codeclimate.com/github/coi-gov-pl/puppet-jboss/badges/gpa.svg)](https://codeclimate.com/github/coi-gov-pl/puppet-jboss) [![Dependency Status](https://gemnasium.com/coi-gov-pl/puppet-jboss.svg)](https://gemnasium.com/coi-gov-pl/puppet-jboss) [![Coverage Status](https://coveralls.io/repos/coi-gov-pl/puppet-jboss/badge.svg?branch=develop&service=github)](https://coveralls.io/github/coi-gov-pl/puppet-jboss?branch=develop) [![Inline docs](http://inch-ci.org/github/coi-gov-pl/puppet-jboss.svg?branch=develop)](http://inch-ci.org/github/coi-gov-pl/puppet-jboss) +[![Build Status](https://travis-ci.org/coi-gov-pl/puppet-jboss.svg?branch=develop)](https://travis-ci.org/coi-gov-pl/puppet-jboss) [![Puppet Forge](https://img.shields.io/puppetforge/v/coi/jboss.svg)](https://forge.puppetlabs.com/coi/jboss) [![Code Climate](https://codeclimate.com/github/coi-gov-pl/puppet-jboss/badges/gpa.svg)](https://codeclimate.com/github/coi-gov-pl/puppet-jboss) [![Dependency Status](https://gemnasium.com/coi-gov-pl/puppet-jboss.svg)](https://gemnasium.com/coi-gov-pl/puppet-jboss) [![Coverage Status](https://coveralls.io/repos/coi-gov-pl/puppet-jboss/badge.svg?branch=develop&service=github)](https://coveralls.io/github/coi-gov-pl/puppet-jboss?branch=develop) [![Inline docs](http://inch-ci.org/github/coi-gov-pl/puppet-jboss.svg?branch=develop)](http://inch-ci.org/github/coi-gov-pl/puppet-jboss) [![Join the chat at https://gitter.im/coi-gov-pl/puppet-jboss](https://badges.gitter.im/coi-gov-pl/puppet-jboss.svg)](https://gitter.im/coi-gov-pl/puppet-jboss?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) #### Table of Contents @@ -42,7 +42,9 @@ The module allows user to perform all necessary operations for JBoss servers. He In addition to the above list, you can also configure any JBoss CLI reachable configuration, with the entire set of parameters. This allows you to configure any parameter supported by JBoss. -Take a look. We will be happy to receive your feedback. +### Got questions? + +We will be happy to receive your feedback. Ask as about everything releated to this module on [Gitter.im chat](https://gitter.im/coi-gov-pl/puppet-jboss?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)! ## Setup @@ -419,8 +421,8 @@ This module is explicitly tested on: With servers: * JBoss AS 7.1 - * JBoss EAP 6.1 - 6.4, - * WildFly 8.x + * JBoss EAP 6.1 - 6.4, 7.0 + * WildFly 8.x, 9.x Should be fully compatible with those operating systems: diff --git a/Rakefile b/Rakefile index 0df64dd..1418fa5 100644 --- a/Rakefile +++ b/Rakefile @@ -10,7 +10,12 @@ rescue LoadError end PuppetLint.configuration.send('disable_80chars') -PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] +PuppetLint.configuration.ignore_paths = [ + "spec/**/*.pp", + "pkg/**/*.pp", + "tests/**/*.pp", + "vendor/**/*.pp" +] PuppetLint.configuration.fail_on_warnings = true desc "Validate manifests, templates, and ruby files" @@ -65,7 +70,7 @@ end desc "Run syntax, lint, and spec tests." task :test => [ - :metadata, + :metadata_lint, :lint, :validate, :clean_fixtures, diff --git a/files/jbxml.aug b/files/jbxml.aug index c950462..4596b26 100644 --- a/files/jbxml.aug +++ b/files/jbxml.aug @@ -2,6 +2,8 @@ Author: Francis Giraldeau Reference: http://www.w3.org/TR/2006/REC-xml11-20060816/ + + This file is based on xml.aug lens from augeas v0.10.0 *) module JBXml = @@ -92,7 +94,7 @@ let doctype = decl_def /!DOCTYPE/ (decl_outer|id_def) let attributes = [ label "#attribute" . [ sep_spc . key nmtoken . sep_eq . sto_dquote ]+ ] let attributes_sq = [ label "#attribute" . - [ sep_spc . key nmtoken . sep_eq . sto_squote ]+ ] + [ sep_spc . key nmtoken . sep_eq . (sto_dquote|sto_squote) ]+ ] let prolog = [ label "#declaration" . diff --git a/gemfiles/Gemfile18.facter16 b/gemfiles/Gemfile18.facter16 new file mode 100644 index 0000000..450e002 --- /dev/null +++ b/gemfiles/Gemfile18.facter16 @@ -0,0 +1,36 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +group :test do + gem 'rake', '~> 10.0.0', :require => false unless dependencies.map {|dep| dep.name}.include?('rake') + # TODO: Remove this explicitly pinned version by the time ticket gh-org/puppet-jboss#84 is closed. + gem 'rspec-puppet', '2.3.2', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'puppet-lint', :require => false + gem 'metadata-json-lint', :require => false + # This package drops support for 1.8 + gem 'json', '1.8.3', :require => false + gem 'os', :require => false + gem 'specinfra', '2.59.0', :require => false + gem 'net-ssh', '2.9.4', :require => false + # This package drops support for 1.8 + gem 'json_pure', '1.8.3', :require => false + gem 'rspec-its', :require => false + gem 'rspec', '~> 3.1.0', :require => false + + gem 'tins', '~> 1.6.0', :require => false + + gem 'facter', '~> 1.6.18', :require => false + gem 'puppet', '~> 2.7.0', :require => false + gem 'hiera-puppet', :require => false + + gem 'ruby-augeas', :require => false + gem 'augeas', :require => false +end + +group :development do + gem 'inch', :require => false + gem 'vagrant-wrapper', :require => false + gem 'pry', '~> 0.9.12.0', :require => false +end + +# vim:ft=ruby diff --git a/gemfiles/Gemfile18.facter16.lock b/gemfiles/Gemfile18.facter16.lock new file mode 100644 index 0000000..8ab2206 --- /dev/null +++ b/gemfiles/Gemfile18.facter16.lock @@ -0,0 +1,107 @@ +GEM + remote: https://rubygems.org/ + specs: + augeas (0.6.4) + coderay (1.1.1) + diff-lcs (1.2.5) + facter (1.6.18) + hiera (1.3.4) + json_pure + hiera-puppet (1.0.0) + hiera (~> 1.0) + inch (0.7.1) + pry + sparkr (>= 0.2.0) + term-ansicolor + yard (~> 0.8.7.5) + json (1.8.3) + json_pure (1.8.3) + metaclass (0.0.4) + metadata-json-lint (0.0.11) + json + spdx-licenses (~> 1.0) + method_source (0.8.2) + mocha (1.1.0) + metaclass (~> 0.0.1) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (2.9.4) + net-telnet (0.1.1) + os (0.9.6) + pry (0.9.12.6) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + puppet (2.7.26) + facter (~> 1.5) + puppet-lint (2.0.0) + puppet-syntax (2.1.0) + rake + puppetlabs_spec_helper (1.1.1) + mocha + puppet-lint + puppet-syntax + rake + rspec-puppet + rake (10.0.4) + rspec (3.1.0) + rspec-core (~> 3.1.0) + rspec-expectations (~> 3.1.0) + rspec-mocks (~> 3.1.0) + rspec-core (3.1.7) + rspec-support (~> 3.1.0) + rspec-expectations (3.1.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.1.0) + rspec-its (1.2.0) + rspec-core (>= 3.0.0) + rspec-expectations (>= 3.0.0) + rspec-mocks (3.1.3) + rspec-support (~> 3.1.0) + rspec-puppet (2.3.2) + rspec + rspec-support (3.1.2) + ruby-augeas (0.5.0) + sfl (2.2) + slop (3.6.0) + sparkr (0.4.1) + spdx-licenses (1.1.0) + specinfra (2.59.0) + net-scp + net-ssh (>= 2.7, < 4.0) + net-telnet + sfl + term-ansicolor (1.3.2) + tins (~> 1.0) + tins (1.6.0) + vagrant-wrapper (2.0.3) + yard (0.8.7.6) + +PLATFORMS + ruby + +DEPENDENCIES + augeas + facter (~> 1.6.18) + hiera-puppet + inch + json (= 1.8.3) + json_pure (= 1.8.3) + metadata-json-lint + net-ssh (= 2.9.4) + os + pry (~> 0.9.12.0) + puppet (~> 2.7.0) + puppet-lint + puppetlabs_spec_helper + rake (~> 10.0.0) + rspec (~> 3.1.0) + rspec-its + rspec-puppet (= 2.3.2) + ruby-augeas + specinfra (= 2.59.0) + tins (~> 1.6.0) + vagrant-wrapper + +BUNDLED WITH + 1.12.5 diff --git a/gemfiles/Gemfile18.facter17 b/gemfiles/Gemfile18.facter17 new file mode 100644 index 0000000..2c915b0 --- /dev/null +++ b/gemfiles/Gemfile18.facter17 @@ -0,0 +1,37 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +group :test do + gem 'rake', '~> 10.0.0', :require => false unless dependencies.map {|dep| dep.name}.include?('rake') + # TODO: Remove this explicitly pinned version by the time ticket gh-org/puppet-jboss#84 is closed. + gem 'rspec-puppet', '2.3.2', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'puppet-lint', :require => false + gem 'metadata-json-lint', :require => false + # This package drops support for 1.8 + gem 'json', '1.8.3', :require => false + gem 'os', :require => false + gem 'specinfra', '2.59.0', :require => false + gem 'net-ssh', '2.9.4', :require => false + # This package drops support for 1.8 + gem 'json_pure', '1.8.3', :require => false + gem 'rspec-its', :require => false + gem 'rspec', '~> 3.1.0', :require => false + + gem 'tins', '~> 1.6.0', :require => false + + gem 'facter', '1.7.0', :require => false + + gem 'puppet', '~> 2.7.0', :require => false + gem 'hiera-puppet', :require => false + + gem 'ruby-augeas', :require => false + gem 'augeas', :require => false +end + +group :development do + gem 'inch', :require => false + gem 'vagrant-wrapper', :require => false + gem 'pry', '~> 0.9.12.0', :require => false +end + +# vim:ft=ruby diff --git a/gemfiles/Gemfile18.facter17.lock b/gemfiles/Gemfile18.facter17.lock new file mode 100644 index 0000000..10ae30f --- /dev/null +++ b/gemfiles/Gemfile18.facter17.lock @@ -0,0 +1,107 @@ +GEM + remote: https://rubygems.org/ + specs: + augeas (0.6.4) + coderay (1.1.1) + diff-lcs (1.2.5) + facter (1.7.0) + hiera (1.3.4) + json_pure + hiera-puppet (1.0.0) + hiera (~> 1.0) + inch (0.7.1) + pry + sparkr (>= 0.2.0) + term-ansicolor + yard (~> 0.8.7.5) + json (1.8.3) + json_pure (1.8.3) + metaclass (0.0.4) + metadata-json-lint (0.0.11) + json + spdx-licenses (~> 1.0) + method_source (0.8.2) + mocha (1.1.0) + metaclass (~> 0.0.1) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (2.9.4) + net-telnet (0.1.1) + os (0.9.6) + pry (0.9.12.6) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + puppet (2.7.26) + facter (~> 1.5) + puppet-lint (2.0.0) + puppet-syntax (2.1.0) + rake + puppetlabs_spec_helper (1.1.1) + mocha + puppet-lint + puppet-syntax + rake + rspec-puppet + rake (10.0.4) + rspec (3.1.0) + rspec-core (~> 3.1.0) + rspec-expectations (~> 3.1.0) + rspec-mocks (~> 3.1.0) + rspec-core (3.1.7) + rspec-support (~> 3.1.0) + rspec-expectations (3.1.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.1.0) + rspec-its (1.2.0) + rspec-core (>= 3.0.0) + rspec-expectations (>= 3.0.0) + rspec-mocks (3.1.3) + rspec-support (~> 3.1.0) + rspec-puppet (2.3.2) + rspec + rspec-support (3.1.2) + ruby-augeas (0.5.0) + sfl (2.2) + slop (3.6.0) + sparkr (0.4.1) + spdx-licenses (1.1.0) + specinfra (2.59.0) + net-scp + net-ssh (>= 2.7, < 4.0) + net-telnet + sfl + term-ansicolor (1.3.2) + tins (~> 1.0) + tins (1.6.0) + vagrant-wrapper (2.0.3) + yard (0.8.7.6) + +PLATFORMS + ruby + +DEPENDENCIES + augeas + facter (= 1.7.0) + hiera-puppet + inch + json (= 1.8.3) + json_pure (= 1.8.3) + metadata-json-lint + net-ssh (= 2.9.4) + os + pry (~> 0.9.12.0) + puppet (~> 2.7.0) + puppet-lint + puppetlabs_spec_helper + rake (~> 10.0.0) + rspec (~> 3.1.0) + rspec-its + rspec-puppet (= 2.3.2) + ruby-augeas + specinfra (= 2.59.0) + tins (~> 1.6.0) + vagrant-wrapper + +BUNDLED WITH + 1.12.5 diff --git a/gemfiles/Gemfile19 b/gemfiles/Gemfile19 new file mode 100644 index 0000000..ecbf425 --- /dev/null +++ b/gemfiles/Gemfile19 @@ -0,0 +1,45 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +group :test do + gem 'rake', :require => false unless dependencies.map {|dep| dep.name}.include?('rake') + # TODO: Remove this explicitly pinned version by the time ticket gh-org/puppet-jboss#84 is closed. + gem 'rspec-puppet', '2.3.2', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'puppet-lint', :require => false + gem 'metadata-json-lint', :require => false + gem 'json', '1.8.3', :require => false + gem 'os', :require => false + gem 'specinfra', '2.59.0', :require => false + gem 'net-ssh', '2.9.4', :require => false + gem 'mime-types', '2.99.2', :require => false + gem 'tins', '~> 1.6.0', :require => false + gem 'rspec-core', '3.4.4', :require => false + + gem 'beaker', :require => false + gem 'beaker-rspec', :require => false + gem 'docker-api', :require => false + gem 'coveralls', :require => false + gem 'codeclimate-test-reporter', :require => false + gem 'simplecov', :require => false + + if facterver = ENV['FACTER_VERSION'] + gem 'facter', facterver, :require => false + else + gem 'facter', :require => false + end + + gem 'puppet', '~> 3.0', :require => false + + gem 'ruby-augeas', :require => false + gem 'augeas', :require => false +end + +group :development do + gem 'inch', :require => false + gem 'vagrant-wrapper', :require => false + gem 'travis', :require => false + gem 'puppet-blacksmith', :require => false + gem 'pry-debugger', :require => false +end + +# vim:ft=ruby diff --git a/gemfiles/Gemfile19.lock b/gemfiles/Gemfile19.lock new file mode 100644 index 0000000..ebf4f3d --- /dev/null +++ b/gemfiles/Gemfile19.lock @@ -0,0 +1,398 @@ +GEM + remote: https://rubygems.org/ + specs: + CFPropertyList (2.2.8) + addressable (2.4.0) + augeas (0.6.4) + aws-sdk (1.66.0) + aws-sdk-v1 (= 1.66.0) + aws-sdk-v1 (1.66.0) + json (~> 1.4) + nokogiri (>= 1.4.4) + backports (3.6.8) + beaker (2.46.0) + aws-sdk (~> 1.57) + beaker-answers (~> 0.0) + beaker-hiera (~> 0.0) + beaker-pe (~> 0.0) + docker-api + fission (~> 0.4) + fog (~> 1.25, < 1.35.0) + fog-google (~> 0.0.9) + google-api-client (~> 0.8, < 0.9.5) + hocon (~> 1.0) + inifile (~> 2.0) + json (~> 1.8) + mime-types (~> 2.99) + minitest (~> 5.4) + net-scp (~> 1.2) + net-ssh (~> 2.9) + open_uri_redirections (~> 0.2.1) + rbvmomi (~> 1.8) + rsync (~> 1.0.9) + stringify-hash (~> 0.0) + unf (~> 0.1) + beaker-answers (0.8.0) + hocon (~> 1.0) + require_all (~> 1.3.2) + stringify-hash (~> 0.0.0) + beaker-hiera (0.1.1) + stringify-hash (~> 0.0.0) + beaker-pe (0.6.0) + stringify-hash (~> 0.0.0) + beaker-rspec (5.6.0) + beaker (~> 2.0) + rspec + serverspec (~> 2) + specinfra (~> 2) + builder (3.2.2) + codeclimate-test-reporter (0.6.0) + simplecov (>= 0.7.1, < 1.0.0) + coderay (1.1.1) + columnize (0.9.0) + coveralls (0.8.14) + json (>= 1.8, < 3) + simplecov (~> 0.12.0) + term-ansicolor (~> 1.3) + thor (~> 0.19.1) + tins (~> 1.6.0) + debugger (1.6.8) + columnize (>= 0.3.1) + debugger-linecache (~> 1.2.0) + debugger-ruby_core_source (~> 1.3.5) + debugger-linecache (1.2.0) + debugger-ruby_core_source (1.3.8) + diff-lcs (1.2.5) + docile (1.1.5) + docker-api (1.29.0) + excon (>= 0.38.0) + json + domain_name (0.5.20160615) + unf (>= 0.0.5, < 1.0.0) + ethon (0.9.0) + ffi (>= 1.3.0) + excon (0.51.0) + facter (2.4.6) + CFPropertyList (~> 2.2.6) + faraday (0.9.2) + multipart-post (>= 1.2, < 3) + faraday_middleware (0.10.0) + faraday (>= 0.7.4, < 0.10) + ffi (1.9.14) + fission (0.5.0) + CFPropertyList (~> 2.2) + fog (1.34.0) + fog-atmos + fog-aws (>= 0.6.0) + fog-brightbox (~> 0.4) + fog-core (~> 1.32) + fog-dynect (~> 0.0.2) + fog-ecloud (~> 0.1) + fog-google (>= 0.0.2) + fog-json + fog-local + fog-powerdns (>= 0.1.1) + fog-profitbricks + fog-radosgw (>= 0.0.2) + fog-riakcs + fog-sakuracloud (>= 0.0.4) + fog-serverlove + fog-softlayer + fog-storm_on_demand + fog-terremark + fog-vmfusion + fog-voxel + fog-xml (~> 0.1.1) + ipaddress (~> 0.5) + nokogiri (~> 1.5, >= 1.5.11) + fog-atmos (0.1.0) + fog-core + fog-xml + fog-aws (0.9.4) + fog-core (~> 1.38) + fog-json (~> 1.0) + fog-xml (~> 0.1) + ipaddress (~> 0.8) + fog-brightbox (0.11.0) + fog-core (~> 1.22) + fog-json + inflecto (~> 0.0.2) + fog-core (1.42.0) + builder + excon (~> 0.49) + formatador (~> 0.2) + fog-dynect (0.0.3) + fog-core + fog-json + fog-xml + fog-ecloud (0.3.0) + fog-core + fog-xml + fog-google (0.0.9) + fog-core + fog-json + fog-xml + fog-json (1.0.2) + fog-core (~> 1.0) + multi_json (~> 1.10) + fog-local (0.3.0) + fog-core (~> 1.27) + fog-powerdns (0.1.1) + fog-core (~> 1.27) + fog-json (~> 1.0) + fog-xml (~> 0.1) + fog-profitbricks (0.0.5) + fog-core + fog-xml + nokogiri + fog-radosgw (0.0.5) + fog-core (>= 1.21.0) + fog-json + fog-xml (>= 0.0.1) + fog-riakcs (0.1.0) + fog-core + fog-json + fog-xml + fog-sakuracloud (1.7.5) + fog-core + fog-json + fog-serverlove (0.1.2) + fog-core + fog-json + fog-softlayer (1.1.2) + fog-core + fog-json + fog-storm_on_demand (0.1.1) + fog-core + fog-json + fog-terremark (0.1.0) + fog-core + fog-xml + fog-vmfusion (0.1.0) + fission + fog-core + fog-voxel (0.1.0) + fog-core + fog-xml + fog-xml (0.1.2) + fog-core + nokogiri (~> 1.5, >= 1.5.11) + formatador (0.2.5) + gh (0.14.0) + addressable + backports + faraday (~> 0.8) + multi_json (~> 1.0) + net-http-persistent (>= 2.7) + net-http-pipeline + google-api-client (0.9.4) + addressable (~> 2.3) + googleauth (~> 0.5) + httpclient (~> 2.7) + hurley (~> 0.1) + memoist (~> 0.11) + mime-types (>= 1.6) + representable (~> 2.3.0) + retriable (~> 2.0) + thor (~> 0.19) + googleauth (0.5.1) + faraday (~> 0.9) + jwt (~> 1.4) + logging (~> 2.0) + memoist (~> 0.12) + multi_json (~> 1.11) + os (~> 0.9) + signet (~> 0.7) + hiera (1.3.4) + json_pure + highline (1.7.8) + hocon (1.1.1) + http-cookie (1.0.2) + domain_name (~> 0.5) + httpclient (2.8.0) + hurley (0.2) + inch (0.7.1) + pry + sparkr (>= 0.2.0) + term-ansicolor + yard (~> 0.8.7.5) + inflecto (0.0.2) + inifile (2.0.2) + ipaddress (0.8.3) + json (1.8.3) + json_pure (2.0.1) + jwt (1.5.4) + launchy (2.4.3) + addressable (~> 2.3) + little-plugger (1.1.4) + logging (2.1.0) + little-plugger (~> 1.1) + multi_json (~> 1.10) + memoist (0.14.0) + metaclass (0.0.4) + metadata-json-lint (0.0.11) + json + spdx-licenses (~> 1.0) + method_source (0.8.2) + mime-types (2.99.2) + mini_portile2 (2.1.0) + minitest (5.9.0) + mocha (1.1.0) + metaclass (~> 0.0.1) + multi_json (1.12.1) + multipart-post (2.0.0) + net-http-persistent (2.9.4) + net-http-pipeline (1.0.1) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (2.9.4) + net-telnet (0.1.1) + netrc (0.11.0) + nokogiri (1.6.8) + mini_portile2 (~> 2.1.0) + pkg-config (~> 1.1.7) + open_uri_redirections (0.2.1) + os (0.9.6) + pkg-config (1.1.7) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-debugger (0.2.3) + debugger (~> 1.3) + pry (>= 0.9.10, < 0.11.0) + puppet (3.8.7) + facter (> 1.6, < 3) + hiera (~> 1.0) + json_pure + puppet-blacksmith (3.4.0) + puppet (>= 2.7.16) + rest-client (~> 1.8.0) + puppet-lint (2.0.0) + puppet-syntax (2.1.0) + rake + puppetlabs_spec_helper (1.1.1) + mocha + puppet-lint + puppet-syntax + rake + rspec-puppet + pusher-client (0.6.2) + json + websocket (~> 1.0) + rake (11.2.2) + rbvmomi (1.8.2) + builder + nokogiri (>= 1.4.1) + trollop + representable (2.3.0) + uber (~> 0.0.7) + require_all (1.3.3) + rest-client (1.8.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) + retriable (2.1.0) + rspec (3.4.0) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-core (3.4.4) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-its (1.2.0) + rspec-core (>= 3.0.0) + rspec-expectations (>= 3.0.0) + rspec-mocks (3.4.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-puppet (2.3.2) + rspec + rspec-support (3.4.1) + rsync (1.0.9) + ruby-augeas (0.5.0) + serverspec (2.36.0) + multi_json + rspec (~> 3.0) + rspec-its + specinfra (~> 2.53) + sfl (2.2) + signet (0.7.3) + addressable (~> 2.3) + faraday (~> 0.9) + jwt (~> 1.5) + multi_json (~> 1.10) + simplecov (0.12.0) + docile (~> 1.1.0) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) + slop (3.6.0) + sparkr (0.4.1) + spdx-licenses (1.1.0) + specinfra (2.59.0) + net-scp + net-ssh (>= 2.7, < 4.0) + net-telnet + sfl + stringify-hash (0.0.2) + term-ansicolor (1.3.2) + tins (~> 1.0) + thor (0.19.1) + tins (1.6.0) + travis (1.8.2) + backports + faraday (~> 0.9) + faraday_middleware (~> 0.9, >= 0.9.1) + gh (~> 0.13) + highline (~> 1.6) + launchy (~> 2.1) + pusher-client (~> 0.4) + typhoeus (~> 0.6, >= 0.6.8) + trollop (2.1.2) + typhoeus (0.8.0) + ethon (>= 0.8.0) + uber (0.0.15) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.2) + vagrant-wrapper (2.0.3) + websocket (1.2.3) + yard (0.8.7.6) + +PLATFORMS + ruby + +DEPENDENCIES + augeas + beaker + beaker-rspec + codeclimate-test-reporter + coveralls + docker-api + facter + inch + json (= 1.8.3) + metadata-json-lint + mime-types (= 2.99.2) + net-ssh (= 2.9.4) + os + pry-debugger + puppet (~> 3.0) + puppet-blacksmith + puppet-lint + puppetlabs_spec_helper + rake + rspec-core (= 3.4.4) + rspec-puppet (= 2.3.2) + ruby-augeas + simplecov + specinfra (= 2.59.0) + tins (~> 1.6.0) + travis + vagrant-wrapper + +BUNDLED WITH + 1.12.5 diff --git a/lib/facter/jboss_virtual.rb b/lib/facter/jboss_virtual.rb new file mode 100644 index 0000000..a55f82d --- /dev/null +++ b/lib/facter/jboss_virtual.rb @@ -0,0 +1,8 @@ +Facter.add(:jboss_virtual) do + setcode do + virtual = Facter.value(:virtual) + ret = virtual + ret = 'docker' if virtual == 'physical' and Puppet_X::Coi::Jboss::Facts.dockerized? + ret + end +end diff --git a/lib/puppet/provider/jboss_deploy/jbosscli.rb b/lib/puppet/provider/jboss_deploy/jbosscli.rb index 207c0e7..729a307 100644 --- a/lib/puppet/provider/jboss_deploy/jbosscli.rb +++ b/lib/puppet/provider/jboss_deploy/jbosscli.rb @@ -1,9 +1,8 @@ require File.expand_path(File.join(File.dirname(__FILE__), '../../../puppet_x/coi/jboss')) Puppet::Type.type(:jboss_deploy).provide(:jbosscli, - :parent => Puppet_X::Coi::Jboss::Provider::AbstractJbossCli) do + :parent => Puppet_X::Coi::Jboss::Provider::AbstractJbossCli) do desc 'JBoss CLI deploy provider' - include Puppet_X::Coi::Jboss::Provider::Deploy end diff --git a/lib/puppet/type/jboss_deploy.rb b/lib/puppet/type/jboss_deploy.rb index 91af0fb..993bac4 100644 --- a/lib/puppet/type/jboss_deploy.rb +++ b/lib/puppet/type/jboss_deploy.rb @@ -12,9 +12,9 @@ desc "Path to the EAR/WAR file." end - newparam(:redeploy, :boolean => true) do + newparam(:redeploy_on_refresh, :boolean => true) do desc "Force redeployment" - defaultto false + defaultto true end newproperty(:servergroups, :array_matching => :all) do @@ -25,7 +25,15 @@ desc "Indicate that server is in domain mode" defaultto true end - + + newparam(:runtime_name) do + desc "Set the runtime-name" + validate do |value| + fail('Invalid file extension, module only supports: .jar, .war, .ear, .rar') if (value =~ /.+(\.ear|\.zip|\.war|\.jar)$/) == nil + end + end + + newparam(:controller) do desc "Domain controller host:port address" validate do |value| @@ -52,5 +60,10 @@ desc "Retry timeout in seconds" defaultto 1 end - + + # Native method that triggers when resource is changed + def refresh + provider.redeploy_on_refresh + end + end diff --git a/lib/puppet_x/coi/jboss.rb b/lib/puppet_x/coi/jboss.rb index 2124137..7ddf552 100644 --- a/lib/puppet_x/coi/jboss.rb +++ b/lib/puppet_x/coi/jboss.rb @@ -16,21 +16,40 @@ def self.require_relative(relative_path, lvl = 0) module Jboss # JBoss provider module module Provider - + end + # Module that contains internal classes + module Internal + # Executor module + module Executor end + # Module that contains states + module State end end end end end - # Ruby default kernel module module Kernel define_method(:require_relative) { |rel| Puppet_X::Coi::require_relative(rel, lvl = 1) } unless Kernel.respond_to? :require_relative end +require_relative 'jboss/internal/executor/shell_executor' +require_relative 'jboss/provider/abstract_jboss_cli' +require_relative 'jboss/internal/sanitizer' +require_relative 'jboss/provider/securitydomain' +require_relative 'jboss/internal/logic_creator' +require_relative 'jboss/internal/execution_state_wrapper' +require_relative 'jboss/internal/cli_executor' +require_relative 'jboss/internal/securitydomain_auditor' +require_relative 'jboss/internal/command_compilator' +require_relative 'jboss/internal/state/execution_state' +require_relative 'jboss/internal/state/securitydomain_state' +require_relative 'jboss/internal/securitydomain_destroyer' + require_relative 'jboss/constants' require_relative 'jboss/buildins_utils' require_relative 'jboss/configuration' require_relative 'jboss/facts' +require_relative 'jboss/factsrefresher' require_relative 'jboss/functions/jboss_basename' require_relative 'jboss/functions/jboss_dirname' @@ -40,13 +59,15 @@ module Kernel require_relative 'jboss/functions/jboss_to_s' require_relative 'jboss/functions/jboss_type_version' -require_relative 'jboss/provider/abstract_jboss_cli' require_relative 'jboss/provider/datasource' require_relative 'jboss/provider/datasource/post_wildfly_provider' require_relative 'jboss/provider/datasource/pre_wildfly_provider' require_relative 'jboss/provider/datasource/static' require_relative 'jboss/provider/confignode' require_relative 'jboss/provider/deploy' -require_relative 'jboss/provider/securitydomain' + +require_relative 'jboss/provider/securitydomain/abstract_provider' +require_relative 'jboss/provider/securitydomain/post_wildfly_provider' +require_relative 'jboss/provider/securitydomain/pre_wildfly_provider' require_relative 'jboss/provider/jmsqueue' require_relative 'jboss/provider/jdbcdriver' diff --git a/lib/puppet_x/coi/jboss/configuration.rb b/lib/puppet_x/coi/jboss/configuration.rb index 2fc0456..2fc647e 100644 --- a/lib/puppet_x/coi/jboss/configuration.rb +++ b/lib/puppet_x/coi/jboss/configuration.rb @@ -80,6 +80,7 @@ def config_value(key) ret end + # Method that reads file def read_raw_profile_d File.read('/etc/profile.d/jboss.sh') end diff --git a/lib/puppet_x/coi/jboss/facts.rb b/lib/puppet_x/coi/jboss/facts.rb index 509c101..38cd45f 100644 --- a/lib/puppet_x/coi/jboss/facts.rb +++ b/lib/puppet_x/coi/jboss/facts.rb @@ -3,26 +3,44 @@ # A class for JBoss facts class Puppet_X::Coi::Jboss::Facts class << self - def define_fullconfig_fact - config = Puppet_X::Coi::Jboss::Configuration::read - unless config.nil? - config.each do |key, value| - fact_symbol = "jboss_#{key}".to_sym - Facter.add(fact_symbol) do - setcode { value } - end - end - Facter.add(:jboss_fullconfig) do - setcode do - if Puppet_X::Coi::Jboss::Configuration.ruby_version < '1.9.0' - class << config - define_method(:to_s, proc { self.inspect }) - end + # Add settings of jboss configuration file to facts + def define_fullconfig_fact + config = Puppet_X::Coi::Jboss::Configuration::read + unless config.nil? + config.each do |key, value| + fact_symbol = "jboss_#{key}".to_sym + add_fact fact_symbol, value + end + Facter.add(:jboss_fullconfig) do + setcode do + if Puppet_X::Coi::Jboss::Configuration.ruby_version < '1.9.0' + class << config + define_method(:to_s, proc { self.inspect }) end - config end + config end end end + end + + # Check if is running inside Docker container + # Implementation is taken from Facter 2.1.x + # @deprecated TODO: remove after dropping support for Puppet 2.x + # @return {boolean} true if running inside container + def dockerized? + path = Pathname.new('/proc/1/cgroup') + return false unless path.readable? + in_docker = path.readlines.any? {|l| l.split(":")[2].to_s.start_with? '/docker/' } + return true if in_docker + return false + end + + # Add new fact with name and value taken from function parameters + # @param {name} name of the fact to be added + # @param {value} value of fact to be added + def add_fact name, value + Facter.add(name.to_sym) { setcode { value } } + end end end diff --git a/lib/puppet_x/coi/jboss/factsrefresher.rb b/lib/puppet_x/coi/jboss/factsrefresher.rb new file mode 100644 index 0000000..5a650a7 --- /dev/null +++ b/lib/puppet_x/coi/jboss/factsrefresher.rb @@ -0,0 +1,44 @@ +require_relative 'facts' + +class Puppet_X::Coi::Jboss::FactsRefresher + class << self + + # Method to refresh given facts + # @param {[Symbol]} list of fact symbols to be refreshed + def refresh_facts value + facts = Facter.list # get list of symbols of facts in the system + config = Puppet_X::Coi::Jboss::Configuration::read + + value.each do |val| + raise Puppet::Error, 'You can only delete fact that are made by jboss_module(start with jboss_)' unless validate_fact_name val + delete_resolves val + delete_value val + + fact_value = config[val.to_sym] + Puppet_X::Coi::Jboss::Facts::add_fact(val.to_sym, fact_value) + end + end + + # Method used to delete resolves in given fact + # @param {String} fact_symbol that resolves should be deleted + def delete_resolves fact_symbol + fct = Facter.fact fact_symbol + fct.instance_variable_set(:@resolves, []) + end + + # Method used to delete values in given fact + # @param {String} fact_symbol that value should be deleted + def delete_value fact_symbol + fct = Facter.fact fact_symbol + fct.instance_variable_set(:@value, {}) + end + + private + # Method used to validate if fact is system or module fact + # @param {String} name of the fact to be validated + # @return {true} if fact name is from jboss module + def validate_fact_name value + value.to_s.start_with? 'jboss_' + end + end +end diff --git a/lib/puppet_x/coi/jboss/internal/cli_executor.rb b/lib/puppet_x/coi/jboss/internal/cli_executor.rb new file mode 100644 index 0000000..396fad3 --- /dev/null +++ b/lib/puppet_x/coi/jboss/internal/cli_executor.rb @@ -0,0 +1,189 @@ +# Class that will handle executions of commands +class Puppet_X::Coi::Jboss::Internal::CliExecutor + # Constructor + # @param {Puppet_X::Coi::Jboss::Internal::ExecutionStateWrapper} execution_state_wrapper handles command execution + def initialize(execution_state_wrapper) + @execution_state_wrapper = execution_state_wrapper + @sanitizer = Puppet_X::Coi::Jboss::Internal::Sanitizer.new + end + + # Standard settter for execution_state_wrapper + attr_writer :execution_state_wrapper + + # Method that allows us to setup shell executor, used in tests + def shell_executor=(shell_executor) + @execution_state_wrapper.shell_executor = shell_executor + end + + # Standard getter for shell_executor + def shell_executor + @execution_state_wrapper.shell_executor + end + + # Method that executes command, if method fails it prints log message + # @param {String} typename name of resource + # @param {String} cmd command that will be executed + # @param {String} way bring up|bring down to for logging + # @param {Hash} resource standard puppet resource object + def executeWithFail(typename, cmd, way, resource) + executed = wrap_execution(cmd, resource) + unless executed[:result] + ex = "\n#{typename} failed #{way}:\n[CLI command]: #{executed[:cmd]}\n[Error message]: #{executed[:lines]}" + unless $add_log.nil? and $add_log > 0 + ex = "#{ex}\n#{printlog $add_log}" + end + raise ex + end + executed + end + + # Method that executes command and returns outut + # @param {String} cmd command that will be executed + # @param {Boolean} runasdomain if command will be executen in comain instance + # @param {Hash} ctrlcfg hash with configuration + # @param {Number} retry_count number of retry after failed command + # @param {Number} retry_timeout timeout after failed command + def executeAndGet(cmd, runasdomain, ctrlcfg, retry_count, retry_timeout) + ret = run_command(cmd, runasdomain, ctrlcfg, retry_count, retry_timeout) + unless ret[:result] + return { + :result => false, + :data => ret[:lines] + } + end + + begin + evaluated_output = @sanitizer.sanitize(ret[:lines]) + undefined = nil + evalines = eval(evaluated_output) + return { + :result => evalines['outcome'] == 'success', + :data => (evalines['outcome'] == 'success' ? evalines['result'] : evalines['failure-description']) + } + + rescue Exception => e + Puppet.err e + return { + :result => false, + :data => ret[:lines] + } + end + end + + # Method that prepares command to be executed + # @param {String} path path for execution + # @param {Hash} ctrlcfg hash with configuration that is need to execute command + def prepare_command(path, ctrlcfg) + home = Puppet_X::Coi::Jboss::Configuration.config_value :home + ENV['JBOSS_HOME'] = home + + jboss_home = "#{home}/bin/jboss-cli.sh" + + cmd = "#{jboss_home} #{timeout_cli} --connect --file=#{path} --controller=#{ctrlcfg[:controller]}" + cmd += " --user=#{ctrlcfg[:ctrluser]}" unless ctrlcfg[:ctrluser].nil? + cmd + end + + # Method that will prepare and delegate execution of command + # @param {String} jbosscmd command to be executeAndGet + # @param {Boolean} runasdomain if jboss is run in domain mode + # @param {Hash} ctrlcfg configuration Hash + # @param {Integer} retry_count number of retries after command failure-description + # @param {Integer} retry_timeout time after command is timeouted + # @return {Hash} hash with result of command executed, output and command + def run_command(jbosscmd, runasdomain, ctrlcfg, retry_count, retry_timeout) + file = Tempfile.new 'jbosscli' + path = file.path + file.close + file.unlink + + File.open(path, 'w') { |f| f.write(jbosscmd + "\n") } + + cmd = prepare_command(path, ctrlcfg) + + environment = ENV.to_hash + + unless ctrlcfg[:ctrlpasswd].nil? + environment['__PASSWD'] = ctrlcfg[:ctrlpasswd] + cmd += ' --password=$__PASSWD' + end + + retries = 0 + result = '' + lines = '' + begin + if retries > 0 + Puppet.warning "JBoss CLI command failed, try #{retries}/#{retry_count}, last status: #{result}, message: #{lines}" + sleep retry_timeout.to_i + end + + Puppet.debug 'Command send to JBoss CLI: ' + jbosscmd + Puppet.debug('Cmd to be executed %s' % cmd) + + execution_state = @execution_state_wrapper.execute(cmd, jbosscmd, environment) + result = execution_state.ret_code + lines = execution_state.output + + retries += 1 + end while (result != 0 && retries <= retry_count) + Puppet.debug('Output from JBoss CLI [%s]: %s' % [result.inspect, lines]) + # deletes the temp file + File.unlink path + { + :cmd => jbosscmd, + :result => result, + :lines => lines + } + end + + private + + # Method that deletes execution of command by aading configurion + # @param {String} cmd jbosscmd + # @param {resource} standard Puppet resource + def wrap_execution(cmd, resource) + conf = { + :controller => resource[:controller], + :ctrluser => resource[:ctrluser], + :ctrlpasswd => resource[:ctrlpasswd] + } + + run_command(cmd, resource[:runasdomain], conf, 0, 0) + end + + # method that return timeout parameter if we are running Jboss AS + # @return {String} timeout_cli + def timeout_cli + '--timeout=50000' unless jbossas? + end + + # Method that return refreshes facts that are available in the system or returns jboss_product + def jbossas? + # jboss_product fact is not set on first run, so that + # calls to jboss-cli can fail (if jboss-as is installed) + if jboss_product.nil? + Puppet_X::Coi::Jboss::FactsRefresher.refresh_facts [:jboss_product] + end + jboss_product == 'jboss-as' + end + + # Method that return value of fact jboss_product + def jboss_product + Facter.value(:jboss_product) + end + + $add_log = nil + + # Standard setter for isprintinglog + def isprintinglog=(setting) + $add_log = setting + end + + def getlog(lines) + last_lines = `tail -n #{lines} #{jbosslog}` + end + + def printlog(lines) + " ---\n JBoss AS log (last #{lines} lines): \n#{getlog lines}" + end +end diff --git a/lib/puppet_x/coi/jboss/internal/command_compilator.rb b/lib/puppet_x/coi/jboss/internal/command_compilator.rb new file mode 100644 index 0000000..05a34bc --- /dev/null +++ b/lib/puppet_x/coi/jboss/internal/command_compilator.rb @@ -0,0 +1,15 @@ +# Class that handles compilation of commands +class Puppet_X::Coi::Jboss::Internal::CommandCompilator + # Method that adds profile and neccesary stuff + # @param {Boolean} runasdomain if jbosss in in domain module + # @param {String} profile name of profile + # @param {String} cmd command that will be executed + # @return {String} command that is ready to be executed + def compile(runasdomain, profile, cmd) + out = cmd.to_s + convr = Puppet_X::Coi::Jboss::BuildinsUtils::ToBooleanConverter.new(runasdomain) + asdomain = convr.to_bool + out = "/profile=#{profile}#{out}" if asdomain && out[0..9] == '/subsystem' + out + end +end diff --git a/lib/puppet_x/coi/jboss/internal/execution_state_wrapper.rb b/lib/puppet_x/coi/jboss/internal/execution_state_wrapper.rb new file mode 100644 index 0000000..15f7b40 --- /dev/null +++ b/lib/puppet_x/coi/jboss/internal/execution_state_wrapper.rb @@ -0,0 +1,61 @@ +# System executor responsible of executing provided commands +class Puppet_X::Coi::Jboss::Internal::ExecutionStateWrapper + + # Standard constructor + # @param {Puppet_X::Coi::Jboss::Internal::Executor::ShellExecutor} shell_executor + def initialize(shell_executor) + @shell_executor = shell_executor + end + + # Standard setter for shell_executor + attr_accessor :shell_executor + + # Method that handles delegation to system executor + # @param {String} cmd cmd to be executed + # @param {String} jbosscmd to be executed + # @param {Hash} environment hash that hold informations about configuration + # @return {Puppet_X::Coi::Jboss::Internal::ExecutionState} execution state that hold + # information about result of execution + def execute(cmd, jbosscmd, environment) + lines = exec_command(cmd, environment) + result = last_execute_result + + code = result.exitstatus + success = result.success? + + Puppet.debug 'execution state begins' + + exececution_state(jbosscmd, code, success, lines) + end + + # Method that returns status of last command executed + # @return {Process::Status} result of last command + def last_execute_result + @result + end + + private + + # Runs prepared commands + # @param {String} cmd command that will be executed + # @param {Hash} environment hash with proccess environment + # @return {String} output of executed command + # The location of withenv changed from Puppet 2.x to 3.x + def exec_command(cmd, environment) + withenv = Puppet::Util.method(:withenv) if Puppet::Util.respond_to?(:withenv) + withenv = Puppet::Util::Execution.method(:withenv) if Puppet::Util::Execution.respond_to?(:withenv) + raise("Cannot set custom environment #{environment}") if environment && !withenv + + withenv.call environment do + @output = @shell_executor.run_command(cmd) + @result = @shell_executor.child_status + end + @output + end + + # Method that make and execution state object with given parameters + # @return {Puppet_X::Coi::Jboss::Internal::ExecutionState} execution state that contains informations about result of command execution + def exececution_state(jbosscmd, code, success, lines) + Puppet_X::Coi::Jboss::Internal::State::ExecutionState.new(code, success, lines, jbosscmd) + end +end diff --git a/lib/puppet_x/coi/jboss/internal/executor/shell_executor.rb b/lib/puppet_x/coi/jboss/internal/executor/shell_executor.rb new file mode 100644 index 0000000..aad3bc9 --- /dev/null +++ b/lib/puppet_x/coi/jboss/internal/executor/shell_executor.rb @@ -0,0 +1,14 @@ +# Class that handles shell command execution +class Puppet_X::Coi::Jboss::Internal::Executor::ShellExecutor + # Method that executes method by real system command execution + # @param {String} cmd command that will be executed + def run_command(cmd) + `#{cmd}` + end + + # Method to check return code from last command that was executed + # @return {Process::Status} result of last command + def child_status + $? + end +end diff --git a/lib/puppet_x/coi/jboss/internal/logic_creator.rb b/lib/puppet_x/coi/jboss/internal/logic_creator.rb new file mode 100644 index 0000000..cda3967 --- /dev/null +++ b/lib/puppet_x/coi/jboss/internal/logic_creator.rb @@ -0,0 +1,32 @@ +# Class that will decide what cammands should be send to cli to set up security domain +class Puppet_X::Coi::Jboss::Internal::LogicCreator + # @param [Puppet_X::Coi::Jboss::Internal::JbossSecurityDomainState] state current state of + # securitydomain configuration + # @param [Puppet_X::Coi::Jboss::Provider::SecurityDomain::Provider] provider that indicates if + # we need to use diffrent paths to setup securitydomain + def initialize(auditor, resource, provider, compilator) + @auditor = auditor + @resource = resource + @provider = provider + @compilator = compilator + end + + # Method that will return list of commands based on current state + # @param {Puppet_X::Coi::Jboss::Provider::SecurityDomain::PreWildFlyProvider| Puppet_X::Coi::Jboss::Provider::SecurityDomain::PostWildFlyProvider} + # @return [Hash] commands Hash with commands that will be executed, key is message that will + # be displayed and value is command + def decide + state = @auditor.fetch_securtydomain_state + commands = [] + unless state.cache_default? + command = @compilator.compile(@resource[:runasdomain], + @resource[:profile], "/subsystem=security/security-domain=#{@resource[:name]}:add(cache-type=default)") + + commands.push(['Security Domain Cache Type', command]) + end + provided_commands = @provider.get_commands(state, @resource) + provided_commands = [] if provided_commands.nil? + commands + provided_commands + end + +end diff --git a/lib/puppet_x/coi/jboss/internal/sanitizer.rb b/lib/puppet_x/coi/jboss/internal/sanitizer.rb new file mode 100644 index 0000000..b757ce6 --- /dev/null +++ b/lib/puppet_x/coi/jboss/internal/sanitizer.rb @@ -0,0 +1,78 @@ +# Class that evaluates given content, jboss console output, and replaces every tuple entry with curly braces +class Puppet_X::Coi::Jboss::Internal::Sanitizer + # It`s some kind of magic: https://regex101.com/r/uE3vD6/1 + REGEXP = Regexp.new('[\n\s]*=>[\n\s]*\[[\n\s]*(\([^\]]+\))[\n\s]*\]', Regexp::MULTILINE) + # Method that evaluate given String + # @param {String} content String that will be evaluated + # @return {Hash} output hash that is a result of eval on given parameter + def sanitize(content) + # JBoss expression and Long value handling + content.gsub!(/expression \"(.+)\",/, '\'\1\',') + content.gsub!(/=> (\d+)L/, '=> \1') + evaluate(content) + end + + private + + # Private method that replaces brackets so it can be evaluated to Ruby style hash + # @param {String} content String that has braces to be replaced + # @param {String} output String without brackets + def evaluate(content) + double_quoteless = replace_double_quotas(content) + + output = double_quoteless.scan(REGEXP) + + left_param = [] + output.each do |elem| + left_param.push(elem[0].gsub!(/\(/, '{')) + end + + right_param = [] + + left_param.each do |elem| + right_param.push(elem.gsub!(/\)/, '}')) + end + + replace(content, REGEXP, right_param) + end + + # Private method that change every double quote for single quote + # @param {String} content String in which we want ot replace + def replace_double_quotas(content) + content.gsub(/\"/, "'") + end + + # Method that replaces text + # @param {Hash} data hash with incorrect and correct values + # @param {String} content string with output from jboss console + def substitue(data, content) + sanitized_content = content + data.each do | old_match, sanitized_match | + sanitized_content = sanitized_content.sub(old_match, sanitized_match) + end + sanitized_content + end + + # Method that delegates substitution of given content + # @param {String} content with text to be repalaced + # @param {Regexp} regexp that will be used to search for text + # @param {List} sanitized_content is a list with correct text + def replace(content, regexp, sanitized_content) + data = make_data_structure(regexp, content, sanitized_content) + substitue(data, content) + end + + # Method that makes hash with old match as key and sanitized content as output + # @param {Regexp} regexp that is used to search for forbidden text + # @param {String} content with text that contains forbidden text + # @param {List} list of sanitized text + def make_data_structure(regexp, content, sanitized_content) + match_sanitized = {} + i = 0 + content.scan(regexp) do |match| + match_sanitized[match[0]] = sanitized_content[i] + i = i + 1 + end + match_sanitized + end +end diff --git a/lib/puppet_x/coi/jboss/internal/securitydomain_auditor.rb b/lib/puppet_x/coi/jboss/internal/securitydomain_auditor.rb new file mode 100644 index 0000000..8005575 --- /dev/null +++ b/lib/puppet_x/coi/jboss/internal/securitydomain_auditor.rb @@ -0,0 +1,178 @@ +# Internal class to audits what is the state of securitydomain in Jboss instance +# Do not use outside of securitydomain provider +class Puppet_X::Coi::Jboss::Internal::SecurityDomainAuditor + # Standard constructor + # @param {Hash} resource standard puppet resource object + # @param {Puppet_X::Coi::Jboss::Internal::CliExecutor} cli_executor that will handle execution of command + # @param {Puppet_X::Coi::Jboss::Internal::CommandCompilator} compilator object that handles + # compilaton of command to be executed + # @param {Puppet_X::Coi::Jboss::Internal::SecurityDomainDestroyer} destroyer object that handles removing of + # securitydomain + def initialize(resource, cli_executor, compilator, destroyer) + @resource = resource + @cli_executor = cli_executor + @compilator = compilator + @destroyer = destroyer + end + + attr_reader :state + + # Method that checks if securitydomain exists + # @return {Boolean} returns true if security-domain exists in any state + def exists? + raw_result = read_resource_recursive + + unless raw_result[:result] + Puppet.debug 'Security Domain does NOT exist' + return false + end + Puppet.debug("Raw result: #{raw_result.inspect}") + result = resolve_state(raw_result[:data], @resource) + result + end + + # Internal mathod that saves current state of every subpath of securitydomain + def fetch_securtydomain_state + data = state + if data['security-domain'][(@resource[:name]).to_s] + fetched_state = Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState.new + if data['security-domain'][(@resource[:name]).to_s]['cache-type'].nil? + Puppet.debug('cache-type is nil') + fetched_state.is_cache_default = false + else + fetched_state.is_cache_default = true + end + auth = data['security-domain'][(@resource[:name]).to_s]['authentication'] + if auth.nil? + Puppet.debug('Authentication is nil') + fetched_state.is_authentication = false + else + fetched_state.is_authentication = true + end + if !auth.nil? && (data['security-domain'][(@resource[:name]).to_s]['authentication']['classic']['login-modules'].nil? || data['security-domain'][(@resource[:name]).to_s]['authentication']['classic']['login-modules'][0]['module-options'].nil?) + Puppet.debug('Login modules are nil') + fetched_state.is_login_modules = false + end + else + fetched_state = Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState.new + end + + fetched_state + end + + private + + # Method prepares lines outputed by JBoss CLI tool, changing output to be readable in Ruby + # @param {string[]} lines + def preparelines(lines) + lines. + gsub(/\((\"[^\"]+\") => (\"[^\"]+\")\)/, '\1 => \2'). + gsub(/\[((?:[\n\s]*\"[^\"]+\" => \"[^\"]+\",?[\n\s]*)+)\]/m, '{\1}') + end + # Method that handles execution of command + def read_resource_recursive + cmd = @compilator.compile(@resource[:runasdomain], + @resource[:profile], + '/subsystem=security:read-resource(recursive=true)' + ) + conf = { + :controller => @resource[:controller], + :ctrluser => @resource[:ctrluser], + :ctrlpasswd => @resource[:ctrlpasswd] + } + @cli_executor.executeAndGet(cmd, @resource[:runasdomain], conf, 0, 0) + end + + + # Method that checks current situation of security-domain in Jboss instance + # @param {Hash} actual_data output of recursive read of security-domain resource + # @param {Hash} resource reference to standard puppet resource object + # @return {Boolean} return true if security-domain with given name exists in any state + def resolve_state(actual_data, resource) + @state = actual_data + unless actual_data.key? 'security-domain' + Puppet.debug('There is no securitydomain at all') + return false + end + + Puppet.debug "Security Domain exists: #{actual_data.inspect}" + + givenhash = build_givenhash(resource) + + path_in_state = ['security-domain', + resource[:name].to_s, + 'authentication', + 'classic', + 'login-modules', + 0, + 'module-options'] + + nil_checker = get_nillable_from_hash_iterative(actual_data, path_in_state) + + Puppet.debug("Value of nil checker: #{nil_checker}") + return false if nil_checker.nil? + + state_login_modules = array_keys_to_hash_value(actual_data, path_in_state) + existinghash = build_existinghash(state_login_modules) + + if !existinghash.nil? && !givenhash.nil? && existinghash != givenhash + diff = givenhash.to_a - existinghash.to_a + Puppet.notice("Security domain should be recreated. Diff: #{diff.inspect}") + Puppet.debug("Security domain moduleoptions existing hash => #{existinghash.inspect}") + Puppet.debug("Security domain moduleoptions given hash => #{givenhash.inspect}") + @destroyer.destroy(resource) + return false + end + true + end + + # Method that will build hash that holds informations about state that is desired + # @param {Hash} data + # @return {Hash} givenhash with informations about setting of security-domain + def build_givenhash(data) + givenhash = {} + unless data[:moduleoptions].nil? + data[:moduleoptions].each do |key, value| + givenhash[key.to_s] = value.to_s.tr("\n", ' ').strip + end + end + givenhash + end + + # Method that will build hash that holds informations about actual settings of security-domain + # @param {Hash} data + # @return {Hash} existinghash with informations about desired setting of security-domain + def build_existinghash(data) + existinghash = {} + data.each do |key, value| + existinghash[key.to_s] = value.to_s.tr("\n", ' ').strip + end + existinghash + end + + # Method that return value of last given in param + # @param {Hash} data hash that holds desired information + # @param {Array} keys array of keys in correct order that will be used to exctract value + # @return {Object} tmp_data value of last key in keys parameter + def array_keys_to_hash_value(data, keys) + tmp_data = data + keys.each do |key| + tmp_data = tmp_data[key] + end + tmp_data + end + + # Iterative method that check if there is nil value in given hash under keys that are given + # as parameters + # @param {Hash} hash hash that will be checked + # @param {Array} keys keys that will be used to check if their value is null + # @return {nil|String} result will be nil if there is nill value under key in given hash + # or true if there is no nill value + def get_nillable_from_hash_iterative(hash, keys) + data = hash + keys.each do |key| + return nil if data[key].nil? + data = data[key] + end + end +end diff --git a/lib/puppet_x/coi/jboss/internal/securitydomain_destroyer.rb b/lib/puppet_x/coi/jboss/internal/securitydomain_destroyer.rb new file mode 100644 index 0000000..492255b --- /dev/null +++ b/lib/puppet_x/coi/jboss/internal/securitydomain_destroyer.rb @@ -0,0 +1,24 @@ +# Class that handles removing securitydomain from jboss instance +class Puppet_X::Coi::Jboss::Internal::SecurityDomainDestroyer + # Standard constructor + # @param {Puppet_X::Coi::Jboss::Internal::CliExecutor} cli_executor executor that will handle + # command execution + # @param {Puppet_X::Coi::Jboss::Internal::CommandCompilator} compilator handles compilation of + # commands + # @param {Hash} resource standard Puppet resource object + def initialize(cli_executor, compilator, resource) + @cli_executor = cli_executor + @compilator = compilator + @resource = resource + end + + # Method that compiles jboss command and executes destroy command + # @param {resource} resource standard Puppet resource + def destroy(resource) + Puppet.debug('Destroy method') + compiled_cmd = @compilator.compile(@resource[:runasdomain], + @resource[:profile], + "/subsystem=security/security-domain=#{@resource[:name]}/authentication=classic:remove()") + @cli_executor.executeWithFail('SecurityDomain', compiled_cmd, 'to destroy', resource) + end +end diff --git a/lib/puppet_x/coi/jboss/internal/state/execution_state.rb b/lib/puppet_x/coi/jboss/internal/state/execution_state.rb new file mode 100644 index 0000000..5005745 --- /dev/null +++ b/lib/puppet_x/coi/jboss/internal/state/execution_state.rb @@ -0,0 +1,17 @@ +# Wrapper that holds informations about result of command execution +class Puppet_X::Coi::Jboss::Internal::State::ExecutionState + # Constructor that creates execution state object + # @param {Int} ret_code return code of command execution + # @param {Boolean} succes value that represents if command execution was succesfull + # @param {String} output result of command execution + # @param {String} command command that was executed + def initialize(ret_code, success, output, command) + @ret_code = ret_code + @success = success + @output = output + @command = command + end + + # Standard getters for ret_code, success, output and command + attr_reader :ret_code, :success, :output, :command +end diff --git a/lib/puppet_x/coi/jboss/internal/state/securitydomain_state.rb b/lib/puppet_x/coi/jboss/internal/state/securitydomain_state.rb new file mode 100644 index 0000000..7a4c680 --- /dev/null +++ b/lib/puppet_x/coi/jboss/internal/state/securitydomain_state.rb @@ -0,0 +1,50 @@ +# Class that holds information about current state of securitydomain +class Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState + + # Standard constructor + # @param {Boolean} is_cache_default true if there is cache default in system + # @param {Boolean} is_authentication true if there is authentication in system + # @param {Boolean} is_login_modules true if there are login modules in system + def initialize(is_cache_default = false, is_authentication = false, is_login_modules = false) + @is_cache_default = is_cache_default + @is_authentication = is_authentication + @is_login_modules = is_login_modules + @compilator = Puppet_X::Coi::Jboss::Internal::CommandCompilator.new + end + + # Standard getter for cache_default + # @return {Boolean} true if there is cache_default set + def cache_default? + @is_cache_default + end + + # Standard setter fot cache_default + # @param {Boolean} value + def is_cache_default=(value) + @is_cache_default = value + end + + # Standard getter for authentication + # @return {Boolean} true if there is authentication set + def is_authentication + @is_authentication + end + + # Standard setter fot authenticationg + # @param {Boolean} value + def is_authentication=(value) + @is_authentication = value + end + + # Standard getter for login modules + # @return {Boolean} true if there are login modules set + def is_login_modules + @is_login_modules + end + + # Standard setter fot login modules + # @param {Boolean} value + def is_login_modules=(value) + @is_login_modules = value + end +end diff --git a/lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb b/lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb index 5d6efa2..acc19eb 100644 --- a/lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb +++ b/lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb @@ -5,134 +5,171 @@ # Base class for all JBoss providers class Puppet_X::Coi::Jboss::Provider::AbstractJbossCli < Puppet::Provider + DEFAULT_SHELL_EXECUTOR = Puppet_X::Coi::Jboss::Internal::Executor::ShellExecutor.new + + # Default constructor that will also initialize 3 external object, system_runner, compilator and command executor + # @param {Puppet::Resource} resource, standard Puppet resource that we need to call super + def initialize(resource=nil) + super(resource) + @compilator = Puppet_X::Coi::Jboss::Internal::CommandCompilator.new + @cli_executor = nil + ensure_cli_executor + end + @@bin = "bin/jboss-cli.sh" @@contents = nil - class << self - def jbossclibin - home = self.jbosshome - path = "#{home}/#{@@bin}" - return path - end + # Method that returns jboss-cli command path + # @return {String} jboss-cli command path + def jbossclibin + home = self.jbosshome + path = "#{home}/#{@@bin}" + path + end - def jbosshome - Puppet_X::Coi::Jboss::Configuration::config_value :home - end + # CONFIGURATION VALUES - def jbosslog - Puppet_X::Coi::Jboss::Configuration::config_value :console_log - end + # Method that returns jboss home value + # @return {String} home value + def jbosshome + Puppet_X::Coi::Jboss::Configuration::config_value :home + end - def config_runasdomain - Puppet_X::Coi::Jboss::Configuration::config_value :runasdomain - end + # Method that returns value of log + # @return {String} value of configuration for console log + def jbosslog + Puppet_X::Coi::Jboss::Configuration::config_value :console_log + end - def config_controller - Puppet_X::Coi::Jboss::Configuration::config_value :controller - end + # Method that returns value that teels us if we need to run jboss in domain + # @return {Boolean} runasdomain indicates if we want to run jboss in domain mode + def config_runasdomain + Puppet_X::Coi::Jboss::Configuration::config_value :runasdomain + end - def config_profile - Puppet_X::Coi::Jboss::Configuration::config_value :profile - end + # Method that returns name of the controller that we will use when connecting to jboss instance + # @return {String} controller + def config_controller + Puppet_X::Coi::Jboss::Configuration::config_value :controller + end + # Method that return name of the profile that we need to add at the start of jboss command + # @return {String} profile + def config_profile + Puppet_X::Coi::Jboss::Configuration::config_value :profile end # TODO: Uncomment for defered provider confinment after droping support for Puppet < 3.0 # commands :jbosscli => Puppet_X::Coi::Jboss::Provider::AbstractJbossCli.jbossclibin - def runasdomain? + # Method that tells us if we want to run jboss in domain mode + # @return {Boolean} + def is_runasdomain @resource[:runasdomain] end - def getlog(lines) - last_lines = `tail -n #{lines} #{jbosslog}` + # Method that delegates execution of command + # @param {String} typename is a name of resource + # @param {String} cmd command that will be executed + def bringUp(typename, cmd) + executeWithFail(typename, cmd, 'to create') end - def printlog(lines) - return " ---\n JBoss AS log (last #{lines} lines): \n#{getlog lines}" + # Method that delegates execution of command + # @param {String} typename is a name of resource + # @param {String} cmd jboss command that will be executed + def bringDown(typename, cmd) + executeWithFail(typename, cmd, 'to remove') end - def execute jbosscmd + # Method that configures every variable that is needed to execute the provided command + # @param {String} jbosscmd jboss command that will be executed + def execute(jbosscmd) retry_count = @resource[:retry] retry_timeout = @resource[:retry_timeout] - ctrlcfg = Puppet_X::Coi::Jboss::Provider::AbstractJbossCli.controllerConfig @resource - return Puppet_X::Coi::Jboss::Provider::AbstractJbossCli.execute jbosscmd, runasdomain?, ctrlcfg, retry_count, retry_timeout + ctrlcfg = controllerConfig @resource + @cli_executor.run_command(jbosscmd, is_runasdomain, ctrlcfg, retry_count, retry_timeout) end - def executeWithoutRetry jbosscmd - ctrlcfg = Puppet_X::Coi::Jboss::Provider::AbstractJbossCli.controllerConfig @resource - return Puppet_X::Coi::Jboss::Provider::AbstractJbossCli.execute jbosscmd, runasdomain?, ctrlcfg, 0, 0 + # Method that executes command without any retry if command fails + # @param {String} jbosscmd jboss command + def executeWithoutRetry(jbosscmd) + ctrlcfg = controllerConfig @resource + @cli_executor.run_command(jbosscmd, is_runasdomain, ctrlcfg, 0, 0) end - def executeAndGet jbosscmd - ctrlcfg = Puppet_X::Coi::Jboss::Provider::AbstractJbossCli.controllerConfig @resource - return Puppet_X::Coi::Jboss::Provider::AbstractJbossCli.executeAndGet jbosscmd, runasdomain?, ctrlcfg, 0, 0 + # Method that executes command without any retry if command fails + # @param {String} jbosscmd jboss command + def executeAndGet(jbosscmd) + ctrlcfg = controllerConfig @resource + executeAndGetResult(jbosscmd, is_runasdomain, ctrlcfg, 0, 0) end - def self.controllerConfig resource - conf = { - :controller => resource[:controller], - :ctrluser => resource[:ctrluser], - :ctrlpasswd => resource[:ctrlpasswd], - } - return conf + # Method that executes command and if command fails it prints information + # @param {String} typename name of resource + # @param {String} cmd jboss command + # @param {String} way name of the action + def executeWithFail(typename, cmd, way) + executed = execute(cmd) + if not executed[:result] + ex = "\n#{typename} failed #{way}:\n[CLI command]: #{executed[:cmd]}\n[Error message]: #{executed[:lines]}" + if not $add_log.nil? and $add_log > 0 + ex = "#{ex}\n#{printlog $add_log}" + end + raise ex + end + executed end - def self.last_execute_status - $? + # Method that delegates compilation of jboss command + # @param {String} jboss command + # @return {String} compiled jboss command + def compilecmd(cmd) + @compilator.compile(@resource[:runasdomain], @resource[:profile], cmd) end - def self.execshell(cmd) - `#{cmd}` + # Method that delegates execution of command to cli_executor + # @param {String} cmd is a jboss command + # @param {Boolean} runasdomain if we want to run jboss in domain mode + # @param {Hash} ctrlcfg configuration hash + # @param {Integer} retry_count is a number of times we want to retry execution of command after failure + # @param {Integer} retry_timeout timmeout after which we assume that command failed to execute + def executeAndGetResult(cmd, runasdomain, ctrlcfg, retry_count, retry_timeout) + @cli_executor.executeAndGet(cmd, runasdomain, ctrlcfg, retry_count, retry_timeout) end - def self.jbossas? - Facter.value(:jboss_product) == 'jboss-as' + # Method that will prepare and delegate execution of command + def run_command(jbosscmd, runasdomain, ctrlcfg, retry_count, retry_timeout) + @cli_executor.run_command(jbosscmd, runasdomain, ctrlcfg, retry_count, retry_timeout) end - def self.timeout_cli - '--timeout=50000' unless jbossas? + # Method that make configuration hash from resource + # @param {Hash} resource standard Puppet resource + # @return {Hash} conf hash that contains information that are need to execute command + def controllerConfig resource + conf = { + :controller => resource[:controller], + :ctrluser => resource[:ctrluser], + :ctrlpasswd => resource[:ctrlpasswd], + } + conf end - def self.execute jbosscmd, runasdomain, ctrlcfg, retry_count, retry_timeout - file = Tempfile.new 'jbosscli' - path = file.path - file.close - file.unlink - - File.open(path, 'w') {|f| f.write(jbosscmd + "\n") } + # Standard getter for jboss_product + # @return {String} jboss_product + def jboss_product + @cli_executor.jboss_product + end - ENV['JBOSS_HOME'] = self.jbosshome - cmd = "#{self.jbossclibin} #{timeout_cli} --connect --file=#{path} --controller=#{ctrlcfg[:controller]}" - unless ctrlcfg[:ctrluser].nil? - cmd += " --user=#{ctrlcfg[:ctrluser]}" - end - unless ctrlcfg[:ctrlpasswd].nil? - ENV['__PASSWD'] = ctrlcfg[:ctrlpasswd] - cmd += " --password=$__PASSWD" - end + # Standard getter for jbossas + # @return {String} jbossas + def jbossas? + @cli_executor.jbossas? + end - retries = 0 - result = '' - lines = '' - begin - if retries > 0 - Puppet.warning "JBoss CLI command failed, try #{retries}/#{retry_count}, last status: #{result.exitstatus.to_s}, message: #{lines}" - sleep retry_timeout.to_i - end - Puppet.debug "Command send to JBoss CLI: " + jbosscmd - lines = self.execshell(cmd) - result = self.last_execute_status - retries += 1 - end while (result.exitstatus != 0 && retries <= retry_count) - Puppet.debug "Output from JBoss CLI [%s]: %s" % [result.inspect, lines] - # deletes the temp file - File.unlink path - return { - :cmd => jbosscmd, - :result => result.exitstatus == 0, - :lines => lines - } + # Standard getter for timeout_cli + def timeout_cli + @cli_executor.timeout_cli end def setattribute(path, name, value) @@ -140,6 +177,9 @@ def setattribute(path, name, value) setattribute_raw(path, name, escaped) end + # Low level set attribute method that sets value to property hash + # + # @return {Object} actually set value def setattribute_raw(path, name, value) Puppet.debug "#{name.inspect} setting to #{value.inspect} for path: #{path}" if value.nil? @@ -147,7 +187,7 @@ def setattribute_raw(path, name, value) else cmd = "#{path}:write-attribute(name=\"#{name.to_s}\", value=#{value})" end - if runasdomain? + if is_runasdomain cmd = "/profile=#{@resource[:profile]}#{cmd}" end res = executeAndGet(cmd) @@ -158,20 +198,6 @@ def setattribute_raw(path, name, value) @property_hash[name] = value end - def bringUp(typename, args) - return executeWithFail(typename, args, 'to create') - end - - def bringDown(typename, args) - return executeWithFail(typename, args, 'to remove') - end - - $add_log = nil - - def isprintinglog=(setting) - $add_log = setting - end - def trace method Puppet.debug '%s[%s] > IN > %s' % [self.class, @resource[:name], method] end @@ -180,72 +206,41 @@ def traceout method, retval Puppet.debug '%s[%s] > OUT > %s: %s' % [self.class, @resource[:name], method, retval.inspect] end - def self.escape value + def escape value if value.respond_to? :to_str str = value.gsub(/([^\\])\"/, '\1\\"') else str = value end - return str.inspect + str.inspect end - def escape value - Puppet_X::Coi::Jboss::Provider::AbstractJbossCli.escape(value) + # Standard setter for shell_executor + # @param {Puppet_X::Coi::Jboss::Internal::Executor::ShellExecutor} shell_executor + def shell_executor=(shell_executor) + @cli_executor.shell_executor = shell_executor end - def executeWithFail(typename, passed_args, way) - executed = execute(passed_args) - if not executed[:result] - ex = "\n#{typename} failed #{way}:\n[CLI command]: #{executed[:cmd]}\n[Error message]: #{executed[:lines]}" - if not $add_log.nil? and $add_log > 0 - ex = "#{ex}\n#{printlog $add_log}" - end - raise ex - end - return executed + # Standard getter for shell executor + def shell_executor + @cli_executor.shell_executor end - def compilecmd cmd - Puppet_X::Coi::Jboss::Provider::AbstractJbossCli.compilecmd @resource[:runasdomain], @resource[:profile], cmd + # Standard setter for execution state wrapper + # @param {Puppet_X::Coi::Jboss::Internal::ExecutionStateWrapper} execution_state_wrapper + def execution_state_wrapper=(execution_state_wrapper) + @cli_executor.execution_state_wrapper = execution_state_wrapper end - def self.compilecmd runasdomain, profile, cmd - out = cmd.to_s - convr = Puppet_X::Coi::Jboss::BuildinsUtils::ToBooleanConverter.new(runasdomain) - asdomain = convr.to_bool - if asdomain && out[0..9] == '/subsystem' - out = "/profile=#{profile}#{out}" - end - return out - end + protected - def self.executeAndGet cmd, runasdomain, ctrlcfg, retry_count, retry_timeout - ret = self.execute cmd, runasdomain, ctrlcfg, retry_count, retry_timeout - if not ret[:result] - return { - :result => false, - :data => ret[:lines] - } - end - # Giving JBoss `undefine` value in Ruby - undefined = nil - # JBoss expression and Long value handling - ret[:lines].gsub!(/expression \"(.+)\",/, '\'\1\',') - ret[:lines].gsub!(/=> (\d+)L/, '=> \1') - begin - evalines = eval ret[:lines] - Puppet.debug evalines.inspect - return { - :result => evalines["outcome"] == "success", - :data => (evalines["outcome"] == "success" ? evalines["result"] : evalines["failure-description"]) - } - rescue Exception => e - Puppet.err e - return { - :result => false, - :data => ret[:lines] - } + # Method taht ensures that there is cli executor, if not it will create default one + # @return {Puppet_X::Coi::Jboss::Internal::CliExecutor} cli_executor + def ensure_cli_executor + if @cli_executor.nil? + execution_state_wrapper = Puppet_X::Coi::Jboss::Internal::ExecutionStateWrapper.new(DEFAULT_SHELL_EXECUTOR) + @cli_executor = Puppet_X::Coi::Jboss::Internal::CliExecutor.new(execution_state_wrapper) end + @cli_executor end - end diff --git a/lib/puppet_x/coi/jboss/provider/confignode.rb b/lib/puppet_x/coi/jboss/provider/confignode.rb index 1365477..94bea1e 100644 --- a/lib/puppet_x/coi/jboss/provider/confignode.rb +++ b/lib/puppet_x/coi/jboss/provider/confignode.rb @@ -1,6 +1,7 @@ # A module for ConfigNode module Puppet_X::Coi::Jboss::Provider::ConfigNode + # Method that creates ConfigNode def create trace 'create' if exists? @@ -8,9 +9,10 @@ def create end ret = bringUp 'Configuration node', "#{compiledpath}:add(#{compileprops})" invalidate - return ret + ret end + # Method that destroy config node def destroy trace 'destroy' if not exists? @@ -21,9 +23,10 @@ def destroy end ret = bringDown 'Configuration node', "#{compiledpath}:remove()" invalidate - return ret + ret end + # Method that checks if config node is present in the system def exists? trace 'exists?' if @clean @@ -38,6 +41,7 @@ def exists? end end + Puppet.debug 'Excute and get in config node' res = executeAndGet "#{compiledpath}:read-resource(include-runtime=true, include-defaults=false)" if res[:result] @data = {} @@ -61,6 +65,7 @@ def exists? return false end + # Method that returns status def status trace 'status' meth = self.method 'ensure' @@ -69,6 +74,7 @@ def status return ret end + # Getter for current status of resource def ensure trace 'ensure' @@ -113,6 +119,7 @@ def ensure end end + # Setter for ensure def ensure= value trace 'ensure=(%s)' % [ value.inspect ] case value @@ -127,6 +134,7 @@ def ensure= value return value end + # Getter for properties def properties trace 'properties()' @@ -148,6 +156,7 @@ def properties end end + # Setter for properties def properties= newprops trace 'properties=(%s)' % newprops.inspect diff --git a/lib/puppet_x/coi/jboss/provider/datasource.rb b/lib/puppet_x/coi/jboss/provider/datasource.rb index b05088c..96b43f2 100644 --- a/lib/puppet_x/coi/jboss/provider/datasource.rb +++ b/lib/puppet_x/coi/jboss/provider/datasource.rb @@ -4,6 +4,8 @@ module Puppet_X::Coi::Jboss::Provider::Datasource include Puppet_X::Coi::Jboss::Constants include Puppet_X::Coi::Jboss::BuildinsUtils + + # Method that creates datasource in JBoss instance def create cmd = [ "#{create_delete_cmd} add --name=#{@resource[:name]}" ] jta_opt(cmd) @@ -27,13 +29,13 @@ def create setenabled true end + # Method that remove datasource from JBoss instance def destroy cmd = "#{create_delete_cmd} remove --name=#{@resource[:name]}" bringDown 'Datasource', cmd end - - + # Method that control whether given data source should be enabled or not def setenabled setting Puppet.debug "setenabled #{setting.inspect}" cmd = compilecmd "#{datasource_path}:read-attribute(name=enabled)" @@ -50,6 +52,8 @@ def setenabled setting end end + # Method that prepares resource that will be used later + # @return {hash} resource def prepare_resource if @resource.nil? @resource = {} @@ -71,6 +75,8 @@ def prepare_resource end end + # Method that checks if resource is present in the system + # @return {Boolean} true if there is such resource def exists? prepare_resource if @resource[:dbname].nil? @@ -92,6 +98,8 @@ def name @property_hash[:name] end + # Method get properties. + # @param {String} name a key for representing name. def getproperty name, default=nil if @property_hash.nil? or (@property_hash.respond_to? :key? and not @property_hash.key? name) or @property_hash[name].nil? return default @@ -106,6 +114,10 @@ def xa return xa? end end + + # Method indicate that given data source should XA or Non-XA + # Default is equal to 'false' + # @param {Boolean} value a value of xa, can be true or false def xa= value actual = getproperty :xa, false if actual.to_s != value.to_s @@ -113,68 +125,91 @@ def xa= value create end end + + # Standard getter for domain controller def controller getproperty :controller end + + # Standard getter for domain profile in JBoss server def profile getproperty :profile, default_profile end + + # Standard getter for runasdomain def runasdomain getproperty :runasdomain end + # Standard getter for jndiname under wich the datasource wrapper will be bound def jndiname getattrib 'jndi-name' end + # Standard setter def jndiname= value setattrib 'jndi-name', value end + + # Standard getter def drivername getattrib 'driver-name' end + # Standard setter def drivername= value setattrib 'driver-name', value end + + # Standard getter def minpoolsize getattrib('min-pool-size').to_s end + # Standard setter def minpoolsize= value setattrib 'min-pool-size', value end + # Standard getter def maxpoolsize getattrib('max-pool-size').to_s end + # Standard setter def maxpoolsize= value setattrib 'max-pool-size', value end + + # Standard getter def username getattrib('user-name') end + # Standard setter def username= value setattrib 'user-name', value end + # Standard getter def password getattrib('password') end + # Standard setter def password= value setattrib 'password', value end + # Standard getter def options managed_fetched_options end + # Standard setter def options= value managed_fetched_options.each do |key, fetched_value| if ABSENTLIKE.include?(value) @@ -192,6 +227,7 @@ def enabled getattrib('enabled').to_s end + # Standard setter def enabled= value Puppet.debug "Enabling datasource #{@resource[:name]} to #{value}" setenabled value @@ -201,14 +237,17 @@ def jdbcscheme connectionHash()[:Scheme] end + # Standard setter def jdbcscheme= value writeConnection :Scheme, value end + def host connectionHash()[:ServerName].to_s end + # Standard setter def host= value writeConnection :ServerName, value end @@ -217,6 +256,7 @@ def port connectionHash()[:PortNumber].to_i end + # Standard setter def port= value writeConnection :PortNumber, value end @@ -225,6 +265,7 @@ def dbname connectionHash()[:DatabaseName] end + # Standard setter def dbname= value writeConnection :DatabaseName, value end @@ -249,10 +290,13 @@ def jta provider_impl.jta end + # Standard setter for jta def jta= value provider_impl.jta = value end + # Method that checks if we want to run xa resource + # @return {Boolean} def xa? if not @resource[:xa].nil? return @resource[:xa] @@ -261,10 +305,12 @@ def xa? end end + # Standard setter for xa_datasource_properties_wrapper def xa_datasource_properties_wrapper(parameters) provider_impl.xa_datasource_properties_wrapper(parameters) end + # Standard setter for jta_opt def jta_opt(cmd) provider_impl.jta_opt(cmd) end diff --git a/lib/puppet_x/coi/jboss/provider/datasource/post_wildfly_provider.rb b/lib/puppet_x/coi/jboss/provider/datasource/post_wildfly_provider.rb index 8448c32..85e9a82 100644 --- a/lib/puppet_x/coi/jboss/provider/datasource/post_wildfly_provider.rb +++ b/lib/puppet_x/coi/jboss/provider/datasource/post_wildfly_provider.rb @@ -1,12 +1,20 @@ # A class for JBoss post WildFly datasource provider class Puppet_X::Coi::Jboss::Provider::Datasource::PostWildFlyProvider + # Standard constructor + # @param {Hash} provider standard Puppet provider def initialize(provider) @provider = provider end + + # Method that wraps given parameter in curly braces + # @param {List} parameters lsit of parameters that will be wrapped + # @return {String} def xa_datasource_properties_wrapper(parameters) "{#{parameters}}" end + # Method that return true if we need xa r else returns value of jta attribute + # @return {String|String} def jta if @provider.xa? true.to_s @@ -15,11 +23,16 @@ def jta end end + # Method that sets value of jta + # @param {Object} value def jta= value Puppet.warning 'JTA does not make sense in XA Datasource as distributed transaction is being used' if @provider.xa? @provider.setattrib('jta', value.to_s) unless @provider.xa? end + # Method that adds jta options to command + # @param {String} cmd jboss command + # @return {String} command with jta parameter def jta_opt(cmd) cmd.push "--jta=#{@provider.resource[:jta].inspect}" unless @provider.xa? end diff --git a/lib/puppet_x/coi/jboss/provider/datasource/pre_wildfly_provider.rb b/lib/puppet_x/coi/jboss/provider/datasource/pre_wildfly_provider.rb index e0a05ce..8ea0474 100644 --- a/lib/puppet_x/coi/jboss/provider/datasource/pre_wildfly_provider.rb +++ b/lib/puppet_x/coi/jboss/provider/datasource/pre_wildfly_provider.rb @@ -1,21 +1,33 @@ # A class for JBoss pre WildFly datasource provider class Puppet_X::Coi::Jboss::Provider::Datasource::PreWildFlyProvider + # Standard constructor + # @param {Hash} provider standard Puppet provider def initialize(provider) @provider = provider end + # Method that wraps given parameter in curly braces + # @param {List} parameters lsit of parameters that will be wrapped + # @return {String} def xa_datasource_properties_wrapper(parameters) "[#{parameters}]" end + # Method that return true if we need xa r else returns value of jta attribute + # @return {String|String} def jta @provider.getattrib('jta').to_s end + # Method that sets value of jta + # @param {Object} value def jta=(value) @provider.setattrib('jta', value.to_s) end + # Method that adds jta options to command + # @param {String} cmd jboss command + # @return {String} command with jta parameter def jta_opt(cmd) cmd.push "--jta=#{@provider.resource[:jta].inspect}" end diff --git a/lib/puppet_x/coi/jboss/provider/datasource/static.rb b/lib/puppet_x/coi/jboss/provider/datasource/static.rb index f109564..6a4dc5c 100644 --- a/lib/puppet_x/coi/jboss/provider/datasource/static.rb +++ b/lib/puppet_x/coi/jboss/provider/datasource/static.rb @@ -1,45 +1,13 @@ -# A module that holds JBoss datasource provider static metod +# A module that holds JBoss datasource provider lib metod +# This module should be loaded staticly +# class << self +# include Puppet_X::Coi::Jboss::Provider::Datasource::Static +# end module Puppet_X::Coi::Jboss::Provider::Datasource::Static - def instances - runasdomain = self.config_runasdomain - profile = self.config_profile - controller = self.config_controller - ctrlconfig = self.controllerConfig({ :controller => controller }) - list = [] - cmd = self.compilecmd runasdomain, profile, "/subsystem=datasources:read-children-names(child-type=#{self.datasource_type true})" - res = self.executeAndGet cmd, runasdomain, ctrlconfig, 0, 0 - if res[:result] - res[:data].each do |name| - inst = self.create_rubyobject name, true, runasdomain, profile, controller - list.push inst - end - end - cmd = self.compilecmd runasdomain, profile, "/subsystem=datasources:read-children-names(child-type=#{self.datasource_type false})" - res = self.executeAndGet cmd, runasdomain, ctrlconfig, 0, 0 - if res[:result] - res[:data].each do |name| - inst = self.create_rubyobject name, false, runasdomain, profile, controller - list.push inst - end - end - return list - end - - def create_rubyobject(name, xa, runasdomain, profile, controller) - props = { - :name => name, - :ensure => :present, - :provider => :jbosscli, - :xa => xa, - :runasdomain => runasdomain, - :profile => profile, - :controller => controller - } - obj = new(props) - return obj - end - + # Method that decides about type of datasource + # @param {Boolean} xa value that holds information that we want to use xa datasource + # @return {String} type of datasource def datasource_type(xa) if xa "xa-data-source" diff --git a/lib/puppet_x/coi/jboss/provider/deploy.rb b/lib/puppet_x/coi/jboss/provider/deploy.rb index 3992917..3a0cd5e 100644 --- a/lib/puppet_x/coi/jboss/provider/deploy.rb +++ b/lib/puppet_x/coi/jboss/provider/deploy.rb @@ -1,36 +1,31 @@ # A class for JBoss deploy module Puppet_X::Coi::Jboss::Provider::Deploy + + # Method that creates deploy Java artifacts to JBoss server def create - cmd = "deploy #{@resource[:source]} --name=#{@resource[:name]}" - if @resource[:runasdomain] - groups = @resource[:servergroups] - if groups.nil? or groups.empty? or groups == [''] - cmd = "#{cmd} --all-server-groups" - else - cmd = "#{cmd} --server-groups=#{groups.join(',')}" - end - end - if @resource[:redeploy] - cmd = "#{cmd} --force" - end - isprintinglog = 100 - bringUp 'Deployment', cmd + deploy end + # Method that remove deploy from JBoss instance def destroy - cmd = "undeploy #{@resource[:name]}" - if @resource[:runasdomain] - groups = @resource[:servergroups] - if groups.nil? or groups.empty? or groups == [''] - cmd = "#{cmd} --all-relevant-server-groups" - else - cmd = "#{cmd} --server-groups=#{groups.join(',')}" - end - end - isprintinglog = 0 - bringDown 'Deployment', cmd + undeploy + end + + # Method that force redeploy of already deployed archive + def redeploy_on_refresh + Puppet.debug('Refresh event from deploy') + undeploy if @resource[:redeploy_on_refresh] + deploy + end + + # Method that returs true + # @return {Boolean} + def is_exact_deployment? + true end + # Method that checks if resource is present in system + # @return {Boolean} def exists? if name_exists? is_exact_deployment? @@ -39,58 +34,93 @@ def exists? end end + # Method that checks actual server group to deploy the archive def servergroups - if not @resource[:runasdomain] - return @resource[:servergroups] - end + return @resource[:servergroups] unless @resource[:runasdomain] servergroups = @resource[:servergroups] res = execute("deployment-info --name=#{@resource[:name]}") - if not res[:result] - return [] - end + return [] unless res[:result] groups = [] for line in res[:lines] - line.strip! - depinf = line.split - if(depinf[1] == "enabled" || depinf[1] == "added") - groups.push(depinf[0]) - end + line.strip! + depinf = line.split + groups.push(depinf[0]) if depinf[1] == 'enabled' || depinf[1] == 'added' end - if servergroups.nil? or servergroups.empty? or servergroups == [''] + if servergroups.nil? || servergroups.empty? || servergroups == [''] return servergroups end - return groups + groups end def servergroups=(value) - if not @resource[:runasdomain] - return nil - end - current = servergroups() - Puppet.debug(current.inspect()) - Puppet.debug(value.inspect()) + return nil unless @resource[:runasdomain] + current = servergroups + Puppet.debug(current.inspect) + Puppet.debug(value.inspect) toset = value - current - cmd = "deploy --name=#{@resource[:name]} --server-groups=#{toset.join(',')}" + cmd = "deploy --name=#{@resource[:name]} --server-groups=#{toset.join(',')}#{runtime_name_param_with_space_or_empty_string}" res = bringUp('Deployment', cmd) end private + + def runtime_name_param + if @resource[:runtime_name].nil? + '' + else + "--runtime-name=#{@resource[:runtime_name]}" + end + end + + def runtime_name_param_with_space_or_empty_string + if @resource[:runtime_name].nil? + '' + else + " #{runtime_name_param}" + end + end + + # Method to deploy Java artifacts to JBoss server + def deploy + cmd = "deploy #{@resource[:source]} --name=#{@resource[:name]}#{runtime_name_param_with_space_or_empty_string}" + if @resource[:runasdomain] + servergroups = @resource[:servergroups] + cmd = if servergroups.nil? || servergroups.empty? || servergroups == [''] + "#{cmd} --all-server-groups" + else + "#{cmd} --server-groups=#{servergroups.join(',')}" + end + end + cmd = "#{cmd} --force" if @resource[:redeploy_on_refresh] + isprintinglog = 100 + bringUp 'Deployment', cmd + end + + # Method to undeploy Java artifacts from JBoss server + def undeploy + cmd = "undeploy #{@resource[:name]}" + if @resource[:runasdomain] + servergroups = @resource[:servergroups] + cmd = if servergroups.nil? || servergroups.empty? || servergroups == [''] + "#{cmd} --all-relevant-server-groups" + else + "#{cmd} --server-groups=#{servergroups.join(',')}" + end + end + isprintinglog = 0 + bringDown 'Deployment', cmd + end + + # Method calls read-resource to validate if deployment resource is present def name_exists? res = executeWithoutRetry "/deployment=#{@resource[:name]}:read-resource()" - if res[:outcome] == 'failed' - return false - end + return false if res[:outcome] == 'failed' unless res[:name].nil? Puppet.debug "Deployment found: #{res[:name]}" return true end Puppet.debug "No deployment matching #{@resource[:name]} found." - return false - end - - def is_exact_deployment? - true + false end - end diff --git a/lib/puppet_x/coi/jboss/provider/jdbcdriver.rb b/lib/puppet_x/coi/jboss/provider/jdbcdriver.rb index 482568e..fc8c9f8 100644 --- a/lib/puppet_x/coi/jboss/provider/jdbcdriver.rb +++ b/lib/puppet_x/coi/jboss/provider/jdbcdriver.rb @@ -1,6 +1,7 @@ # A module for Jdbcdriver module Puppet_X::Coi::Jboss::Provider::Jdbcdriver + # Method that creates Jdbcdriver in JBoss instance def create name = @resource[:name] map = get_attribs_map @@ -9,11 +10,14 @@ def create bringUp 'JDBC-Driver', cmd end + # Method to remove jdbc-driver from Jboss instance. def destroy cmd = compilecmd "/subsystem=datasources/jdbc-driver=#{@resource[:name]}:remove" bringDown 'JDBC-Driver', cmd end + # Method to check if there is jdbc-driver. + # Method calls recursive read-resource to validate if jdbc-driver is present. def exists? @data = {} cmd = compilecmd "/subsystem=datasources/jdbc-driver=#{@resource[:name]}:read-resource(recursive=true)" @@ -27,6 +31,11 @@ def exists? return true end + # Methods set attributes for datasources to jdbc-driver + # + # @param {String} name a key of representing name. + # @param {Object} value a value of attribute + # @return a new name and value @data hash def setattrib name, value Puppet.debug(name + ' setting to ' + value) cmd = compilecmd "/subsystem=datasources/jdbc-driver=#{@resource[:name]}:write-attribute(name=#{name}, value=#{value})" @@ -38,40 +47,53 @@ def setattrib name, value @data[name] = value end + # Standard getter for driver Java class name def classname @data['driver-class-name'] end + # Method set attribute for classname value + # @param {Object} value a value of classname def classname= value setattrib 'driver-class-name', value end + # Standard getter for driver module name def modulename @data['driver-module-name'] end + # Method set attribute for modulename value + # @param {Object} value a value of modulename def modulename= value setattrib 'driver-module-name', value end + # Standard getter for datasource Java class name def datasourceclassname @data['driver-datasource-class-name'] end + # Method set attribute for datasourceclassname value + # @param {Object} value a value of datasourceclassname def datasourceclassname= value setattrib 'driver-datasource-class-name', value end + # Standard getter for XA datasource Java class name def xadatasourceclassname @data['driver-xa-datasource-class-name'] end + # Method set attribute for xadatasourceclassname value + # @param {Object} value a value of xadatasourceclassname def xadatasourceclassname= value setattrib 'driver-xa-datasource-class-name', value end private + # Method get attributes map def get_attribs_map name = @resource[:name] modulename = @resource[:modulename] @@ -88,6 +110,9 @@ def get_attribs_map map end + # Method that prepares attributes from hash to be included in command + # @param {Hash} input + # @return {List} def cmdlize_attribs_map input list = [] input.keys.sort.each do |key| diff --git a/lib/puppet_x/coi/jboss/provider/jmsqueue.rb b/lib/puppet_x/coi/jboss/provider/jmsqueue.rb index b3397e4..215d0cf 100644 --- a/lib/puppet_x/coi/jboss/provider/jmsqueue.rb +++ b/lib/puppet_x/coi/jboss/provider/jmsqueue.rb @@ -1,8 +1,10 @@ # A module for Jmsqueue module Puppet_X::Coi::Jboss::Provider::Jmsqueue include Puppet_X::Coi::Jboss::BuildinsUtils + + # Method that creates jms-queue in JBoss instance. def create - if runasdomain? + if is_runasdomain profile = "--profile=#{@resource[:profile]}" else profile = '' @@ -30,8 +32,9 @@ def create bringUp "JMS Queue", cmd end + # Method to remove jms-queue from Jboss instance. def destroy - if runasdomain? + if is_runasdomain profile = "--profile=#{@resource[:profile]}" else profile = '' @@ -40,7 +43,7 @@ def destroy bringDown "JMS Queue", cmd end - # + # Method to check if there is jms-queue. Methods calls read-resource to validate if jms-queue is present. def exists? $data = nil cmd = compilecmd "/subsystem=messaging/hornetq-server=default/jms-queue=#{@resource[:name]}:read-resource()" @@ -54,6 +57,7 @@ def exists? return true end + # Standard getter for durable value. def durable trace 'durable' Puppet.debug "Durable given: #{@resource[:durable].inspect}" @@ -61,16 +65,23 @@ def durable ToBooleanConverter.new($data['durable']).to_bool.to_s end + # Standard setter for durable value. + # + # @param {Boolean} value a value of durable, can be true or false def durable= value trace 'durable= %s' % value.to_s setattr 'durable', ('"%s"' % ToBooleanConverter.new(value).to_bool) end + # Standard getter for entries value. def entries trace 'entries' $data['entries'] end + # Standard setter for entries value. + # + # @param {Array} value a value of entries def entries= value trace 'entries= %s' % value.inspect entries = value.join '", "' @@ -84,6 +95,9 @@ def entries= value private + # Methods set attributes for messaging to default hornetq-server + # @param {String} name a key for representing name. + # @param {Object} value a value of attribute def setattr name, value setattribute_raw "/subsystem=messaging/hornetq-server=default/jms-queue=#{@resource[:name]}", name, value end diff --git a/lib/puppet_x/coi/jboss/provider/securitydomain.rb b/lib/puppet_x/coi/jboss/provider/securitydomain.rb index 353c8fb..8a5d5d0 100644 --- a/lib/puppet_x/coi/jboss/provider/securitydomain.rb +++ b/lib/puppet_x/coi/jboss/provider/securitydomain.rb @@ -1,69 +1,79 @@ # A class for JBoss security domain provider module Puppet_X::Coi::Jboss::Provider::SecurityDomain + # Method to check if there is security domain. Method calls recursive read-resource on security + # subsystem to validate + # if security domain is present. In the procces method also checks if authentication is set. + def exists? + auditor = ensure_auditor + auditor.exists? + end + + # Method that creates security-domain in Jboss instance. When invoked it will execute 3 commands, + # add cache-type with value 'default', add authentication with value classic, add login-modules. + # Depends on the version of server it will use correct path to set security domain def create - cmd = "/subsystem=security/security-domain=#{@resource[:name]}/authentication=classic:add(login-modules=[{code=>\"#{@resource[:code]}\",flag=>\"#{@resource[:codeflag]}\",module-options=>[" - options = [] - @resource[:moduleoptions].keys.sort.each do |key| - value = @resource[:moduleoptions][key] - val = value.to_s.gsub(/\n/, ' ').strip - options << '%s => "%s"' % [key, val] + commands = fetch_commands + Puppet.debug("Commands: #{commands}") + + commands.each do |message, command| + bringUp(message, command) end - cmd += options.join(',') + "]}])" - cmd = compilecmd(cmd) - cmd2 = compilecmd "/subsystem=security/security-domain=#{@resource[:name]}:add(cache-type=default)" - bringUp('Security Domain Cache Type', cmd2)[:result] - bringUp('Security Domain', cmd)[:result] end + # Method to remove security-domain from Jboss instance def destroy - cmd = compilecmd "/subsystem=security/security-domain=#{@resource[:name]}:remove()" - bringDown('Security Domain', cmd)[:result] + destroyer = ensure_destroyer + destroyer.destroy(@resource)[:result] end - def exists? - cmd = compilecmd "/subsystem=security/security-domain=#{@resource[:name]}/authentication=classic:read-resource()" - res = executeWithoutRetry cmd - if not res[:result] - Puppet.debug "Security Domain does NOT exist" - return false - end - undefined = nil - lines = preparelines res[:lines] - data = eval(lines)['result'] - Puppet.debug "Security Domain exists: #{data.inspect}" - - existinghash = Hash.new - givenhash = Hash.new + private - unless @resource[:moduleoptions].nil? - @resource[:moduleoptions].each do |key, value| - givenhash["#{key}"] = value.to_s.gsub(/\n/, ' ').strip - end - end + # Method that ensures that destroyer is present in the system, if not it creates one + # @return {Puppet_X::Coi::Jboss::Internal::SecurityDomainDestroyer} destroyer + def ensure_destroyer + cli_executor = ensure_cli_executor + @secdom_destroyer = Puppet_X::Coi::Jboss::Internal::SecurityDomainDestroyer.new(cli_executor, + @compilator, + @resource) if @secdom_destroyer.nil? + @secdom_destroyer + end - data['login-modules'][0]['module-options'].each do |key, value| - existinghash[key.to_s] = value.to_s.gsub(/\n/, ' ').strip - end + # Method that ensures that auditor is present in the system, if not it creates one + # @return {Puppet_X::Coi::Jboss::Internal::SecurityDomainAuditor} auditor + def ensure_auditor + destroyer = ensure_destroyer + cli_executor = ensure_cli_executor + @auditor = Puppet_X::Coi::Jboss::Internal::SecurityDomainAuditor.new(@resource, + cli_executor, + @compilator, + destroyer) if @auditor.nil? + @auditor + end - if !existinghash.nil? && !givenhash.nil? && existinghash != givenhash - diff = givenhash.to_a - existinghash.to_a - Puppet.notice "Security domain should be recreated. Diff: #{diff.inspect}" - Puppet.debug "Security domain moduleoptions existing hash => #{existinghash.inspect}" - Puppet.debug "Security domain moduleoptions given hash => #{givenhash.inspect}" - destroy - return false - end - return true + # Method that fetches commands that need to be executed to setup security-domain + # @return {List} commands list of commands that are going to be executed + def fetch_commands + auditor = ensure_auditor + provider = provider_impl + logic_creator = Puppet_X::Coi::Jboss::Internal::LogicCreator.new(auditor, @resource, provider, @compilator) + logic_creator.decide end - private + # Method that provides information about which command template should be used + # @return {Puppet_X::Coi::Jboss::Provider::SecurityDomain::PreWildFlyProvider| + # Puppet_X::Coi::Jboss::Provider::SecurityDomain::PostWildFlyProvider} + # provider with correct command template + def provider_impl + require_relative 'securitydomain/pre_wildfly_provider' + require_relative 'securitydomain/post_wildfly_provider' - # Method prepares lines outputed by JBoss CLI tool, changing output to be readable in Ruby - # - # @param {string[]} lines - def preparelines lines - lines. - gsub(/\((\"[^\"]+\") => (\"[^\"]+\")\)/, '\1 => \2'). - gsub(/\[((?:[\n\s]*\"[^\"]+\" => \"[^\"]+\",?[\n\s]*)+)\]/m, '{\1}') + if @impl.nil? + if Puppet_X::Coi::Jboss::Configuration::is_pre_wildfly? + @impl = Puppet_X::Coi::Jboss::Provider::SecurityDomain::PreWildFlyProvider.new(@resource, @compilator) + else + @impl = Puppet_X::Coi::Jboss::Provider::SecurityDomain::PostWildFlyProvider.new(@resource, @compilator) + end + end + @impl end end diff --git a/lib/puppet_x/coi/jboss/provider/securitydomain/abstract_provider.rb b/lib/puppet_x/coi/jboss/provider/securitydomain/abstract_provider.rb new file mode 100644 index 0000000..2f5b345 --- /dev/null +++ b/lib/puppet_x/coi/jboss/provider/securitydomain/abstract_provider.rb @@ -0,0 +1,64 @@ +# A module for JBoss security domain common abstract resource +class Puppet_X::Coi::Jboss::Provider::SecurityDomain::AbstractProvider + + # Standard constructor + # @param {Hash} resource standard Puppet resource + # @param {Puppet_X::Coi::Jboss::Internal::CommandCompilator} compilator that is used to compile jboss command + def initialize(resource, compilator) + @resource = resource + @compilator = compilator + end + + COMMAND_SPLITTER = ',' + NEWLINE_REPLACEMENT = ' ' + + # Creates a parametrized command to be executed by resource + # @return {String} a complete command without profile + def build_main_command + res = @resource + correct_cmd = correct_command_template_begining(res) + options = [] + res[:moduleoptions].keys.sort.each do |key| + value = res[:moduleoptions][key] + val = value + # FIXME: After coi-gov-pl/puppet-jboss#59 is resolved the fallowing lines + # should be moved to mungle function in securitydomain type not resource + val = 'undefined' if val.nil? + val = val.to_s if val.is_a?(Symbol) + # New lines in values are not supported, they can't be passed to JBoss CLI + val = val.gsub(/\n/, NEWLINE_REPLACEMENT).strip if val.is_a?(String) + options << module_option_template % [key.inspect, val.inspect] + end + correct_cmd += options.join(COMMAND_SPLITTER) + correct_command_template_ending + end + + # Method that decides about what commands should be executed + # @param {Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState} state of security domain + # @return {List} commands + def get_commands(state, resource) + decide(resource, state) + end + + # Methods that compiles jboss command + # @param {String} command jboss command that will be executed + # @return {String} comamnd with profile if needed + def compile_command(base_command, resource) + @compilator.compile(resource[:runasdomain], resource[:profile], base_command) + end + + protected + + ABSTRACT_MESSAGE = 'Abstract class, implement ths method' + + def correct_command_template_begining(resource) + raise ABSTRACT_MESSAGE + end + + def correct_command_template_ending + raise ABSTRACT_MESSAGE + end + + def module_option_template + raise ABSTRACT_MESSAGE + end +end diff --git a/lib/puppet_x/coi/jboss/provider/securitydomain/post_wildfly_provider.rb b/lib/puppet_x/coi/jboss/provider/securitydomain/post_wildfly_provider.rb new file mode 100644 index 0000000..6082ae4 --- /dev/null +++ b/lib/puppet_x/coi/jboss/provider/securitydomain/post_wildfly_provider.rb @@ -0,0 +1,52 @@ +# A module for JBoss post WildFly security domain resource that provides command to be executed +class Puppet_X::Coi::Jboss::Provider::SecurityDomain::PostWildFlyProvider < + Puppet_X::Coi::Jboss::Provider::SecurityDomain::AbstractProvider + + # This is a default constructor + # @param {Hash} resource standard Puppet resource + # @param {Puppet_X::Coi::Jboss::Internal::CommandCompilator} compilator that is used to compile jboss command + def initialize(resource, compilator) + @resource = resource + @compilator = compilator + end + + protected + + # Method that hold first part of securitydomain jboss command + # @param {Hash} resource standard Puppet resource + # @return {String} begining security-domain command + def correct_command_template_begining(resource) + "/subsystem=security/security-domain=#{resource[:name]}/authentication=classic/login-module=#{resource[:name]}:add" + + "(code=#{resource[:code].inspect},flag=#{resource[:codeflag].inspect},module-options=[" + end + + # Method that holds end of security-domain jboss command + # @return {String} ending of security-domain jboss command + def correct_command_template_ending + '])' + end + + # Method that holds template for module options in security-domain + # @return {String} template + def module_option_template + '(%s=>%s)' + end + + # Method that decides what commands should be added to command execution list + # @param {Hash} resource standard Puppet resource + # @param {Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState} state that holds informations about current state of security domain + # @return {List} commands + def decide(resource, state) + commands = [] + unless state.is_authentication + command = compile_command("/subsystem=security/security-domain=#{resource[:name]}/authentication=classic:add()", resource) + commands.push(['Security Domain Authentication', command]) + end + unless state.is_login_modules + main_cmd = build_main_command + command = compile_command(main_cmd, resource) + commands.push(['Security Domain Login Modules', command]) + end + commands + end +end diff --git a/lib/puppet_x/coi/jboss/provider/securitydomain/pre_wildfly_provider.rb b/lib/puppet_x/coi/jboss/provider/securitydomain/pre_wildfly_provider.rb new file mode 100644 index 0000000..c2e87d0 --- /dev/null +++ b/lib/puppet_x/coi/jboss/provider/securitydomain/pre_wildfly_provider.rb @@ -0,0 +1,53 @@ +# A module for JBoss pre WildFly security domain provider +class Puppet_X::Coi::Jboss::Provider::SecurityDomain::PreWildFlyProvider < + Puppet_X::Coi::Jboss::Provider::SecurityDomain::AbstractProvider + + # This is a default constructor + # @param {Hash} resource standard Puppet resource + # @param {Puppet_X::Coi::Jboss::Internal::CommandCompilator} compilator that is used to compile jboss command + def initialize(resource, compilator) + @resource = resource + @compilator = compilator + end + + protected + + # Method that hold first part of securitydomain jboss command + # @param {Hash} resource standard Puppet resource + # @return {String} begining security-domain command + def correct_command_template_begining(resource) + "/subsystem=security/security-domain=#{resource[:name]}/authentication=classic:add(login-modules=[{code=>#{resource[:code].inspect},flag=>#{resource[:codeflag].inspect},module-options=>[" + end + + # Method that holds end of security-domain jboss command + # @return {String} ending of security-domain jboss command + def correct_command_template_ending + ']}])' + end + + # Method that holds template for module options in security-domain + # @return {String} template + def module_option_template + '%s=>%s' + end + + # Method that decides what commands should be added to command execution list + # @param {Hash} resource standard Puppet resource + # @param {Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState} state that holds informations about current state of security domain + # @return {List} commands + def decide(resource, state) + unless everything_is_set?(state) + commands = [] + main_cmd = build_main_command + command = compile_command(main_cmd, resource) + commands.push(['Security Domain Login Modules', command]) + end + end + + # Method that return boolean value if everything in security domain in set + # @param {Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState} state that holds informations about current state of security domain + # @return {Boolean} + def everything_is_set?(state) + state.is_authentication && state.is_login_modules + end +end diff --git a/manifests/deploy.pp b/manifests/deploy.pp index 4d9cbb3..252d0fe 100644 --- a/manifests/deploy.pp +++ b/manifests/deploy.pp @@ -13,35 +13,41 @@ # [*jndi*] # **This is the namevar**. The JNDI name of deployed archive. # [*redeploy*] -# This parameter can be used to force redeployment of already deployed archive. By default it +# This parameter can be used to force redeployment of already deployed archive. By default it # is equals for false # [*servergroups*] -# In domain mode, you need to pass here actual server group name on which you wish to deploy +# In domain mode, you need to pass here actual server group name on which you wish to deploy # the archive. # define jboss::deploy ( $path, - $ensure = 'present', - $jndi = $name, - $redeploy = false, - $servergroups = hiera('jboss::deploy::servergroups', undef), - $controller = $::jboss::controller, - $runasdomain = $::jboss::runasdomain, + $ensure = 'present', + $jndi = $name, + $redeploy_on_refresh = true, + $servergroups = hiera('jboss::deploy::servergroups', undef), + $controller = $::jboss::controller, + $runasdomain = $::jboss::runasdomain, + $runtime_name = undef, ) { include jboss include jboss::internal::runtime::node + if $runtime_name != undef { + validate_re($runtime_name, '.+(\.ear|\.zip|\.war|\.jar)$', 'Invalid file extension, module only supports: .jar, .war, .ear, .rar') + } + jboss_deploy { $jndi: - ensure => $ensure, - source => $path, - runasdomain => $runasdomain, - redeploy => $redeploy, - servergroups => $servergroups, - controller => $controller, - ctrluser => $jboss::internal::runtime::node::username, - ctrlpasswd => $jboss::internal::runtime::node::password, - require => [ - Anchor['jboss::service::end'], + ensure => $ensure, + source => $path, + runasdomain => $runasdomain, + redeploy_on_refresh => $redeploy_on_refresh, + servergroups => $servergroups, + controller => $controller, + ctrluser => $jboss::internal::runtime::node::username, + ctrlpasswd => $jboss::internal::runtime::node::password, + runtime_name => $runtime_name, + require => [ + Anchor['jboss::end'], Exec['jboss::service::restart'], ], } diff --git a/manifests/init.pp b/manifests/init.pp index 44089e1..bc1506b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -70,7 +70,7 @@ $jboss_user = $jboss::params::jboss_user, $jboss_group = $jboss::params::jboss_group, $version = $jboss::params::version, - $download_url = $jboss::params::download_url, + $download_url = undef, $java_autoinstall = $jboss::params::java_autoinstall, $java_version = $jboss::params::java_version, $java_package = $jboss::params::java_package, @@ -85,6 +85,9 @@ $home = "${install_dir}/${product}-${version}" + include jboss::internal::defaults + include jboss::internal::runtime + include jboss::internal::compatibility $controller = "${controller_host}:${jboss::internal::compatibility::controller_port}" @@ -94,12 +97,18 @@ $servicename = $jboss::internal::service::servicename + $full_download_url = $jboss::internal::runtime::download_url + + if $full_download_url == undef { + fail Puppet::Errorr, 'Full download url cannot be undef' + } + class { 'jboss::internal::package': version => $version, product => $product, jboss_user => $jboss_user, jboss_group => $jboss_group, - download_url => $download_url, + download_url => $full_download_url, java_autoinstall => $java_autoinstall, java_version => $java_version, java_package => $java_package, diff --git a/manifests/interface.pp b/manifests/interface.pp index a1183e0..0f753e8 100644 --- a/manifests/interface.pp +++ b/manifests/interface.pp @@ -1,7 +1,7 @@ # == Define: jboss::interface # # This defined type can be used to setup JBoss interfaces. It can add, remove or change -# existing interfaces. +# existing interfaces. # # More info about interfaces may be found here: https://docs.jboss.org/author/display/WFLY9/Interfaces+and+ports # @@ -19,73 +19,76 @@ # Parameters listed here are exclusive. Only one of them can be set at once. # # [*any_address*] -# This is boolean parameter. If set to `true` JBoss will bind network to any network ip. +# This is boolean parameter. If set to `true` JBoss will bind network to any network ip. # Bassicly its the same as passing `0.0.0.0` as inet address. # [*any_ipv4_address*] # This is boolean parameter. If set to `true` JBoss will bind network to any ipv4 network ip. -# It is similar as passing `0.0.0.0` as inet address +# It is similar as passing `0.0.0.0` as inet address. +# This parameter is deprecated for JBoss EAP 7.x and WildFly 9.x and later. # [*any_ipv6_address*] -# This is boolean parameter. If set to `true` JBoss will bind network to any ipv6 network ip. -# It's should be the same as passing `::` +# This is boolean parameter. If set to `true` JBoss will bind network to any ipv6 network ip. +# It's should be the same as passing `::`. +# This parameter is deprecated for JBoss EAP 7.x and WildFly 9.x and later. # [*inet_address*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this -# interface should be whether or not the address matches the given value. Value is either a IP -# address in IPv6 or IPv4 dotted decimal notation, or a hostname that can be resolved to an IP -# address. An `undef` value means this attribute is not relevant to the IP address selection. +# Attribute indicating that part of the selection criteria for choosing an IP address for this +# interface should be whether or not the address matches the given value. Value is either a IP +# address in IPv6 or IPv4 dotted decimal notation, or a hostname that can be resolved to an IP +# address. An `undef` value means this attribute is not relevant to the IP address selection. # For ex.: `172.20.0.1` # [*link_local_addres*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this +# Attribute indicating that part of the selection criteria for choosing an IP address for this # interface should be whether or not the address is link-local. An `undef` or `false` value # means this attribute is not relevant to the IP address selection. # [*loopback*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this -# interface should be whether or not it is a loopback address. An `undef` or `false` value +# Attribute indicating that part of the selection criteria for choosing an IP address for this +# interface should be whether or not it is a loopback address. An `undef` or `false` value # means this attribute is not relevant to the IP address selection. # [*loopback_address*] -# Attribute indicating that the IP address for this interface should be the given value, if a -# loopback interface exists on the machine. A 'loopback address' may not actually be configured -# on the machine's loopback interface. Differs from inet-address in that the given value will -# be used even if no NIC can be found that has the IP specified address associated with it. -# An `undef` or `false` value means this attribute is not relevant to the IP address +# Attribute indicating that the IP address for this interface should be the given value, if a +# loopback interface exists on the machine. A 'loopback address' may not actually be configured +# on the machine's loopback interface. Differs from inet-address in that the given value will +# be used even if no NIC can be found that has the IP specified address associated with it. +# An `undef` or `false` value means this attribute is not relevant to the IP address # selection. For ex. `127.0.1.1` # [*multicast*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this -# interface should be whether or not its network interface supports multicast. An `undef` +# Attribute indicating that part of the selection criteria for choosing an IP address for this +# interface should be whether or not its network interface supports multicast. An `undef` # or `false` value means this attribute is not relevant to the IP address selection. # [*nic*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this -# interface should be whether its network interface has the given name. The name of a network -# interface (e.g. eth0, eth1, lo). An `undef` value means this attribute is not relevant to +# Attribute indicating that part of the selection criteria for choosing an IP address for this +# interface should be whether its network interface has the given name. The name of a network +# interface (e.g. eth0, eth1, lo). An `undef` value means this attribute is not relevant to # the IP address selection. For ex.: `eth3` # [*nic_match*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this -# interface should be whether its network interface has a name that matches the given regular -# expression. Value is a regular expression against which the names of the network interfaces -# available on the machine can be matched to find an acceptable interface. An `undef` value -# means this attribute is not relevant to the IP address selection. For ex.: `^eth?$` +# Attribute indicating that part of the selection criteria for choosing an IP address for this +# interface should be whether its network interface has a name that matches the given regular +# expression. Value is a regular expression against which the names of the network interfaces +# available on the machine can be matched to find an acceptable interface. An `undef` value +# means this attribute is not relevant to the IP ad${home}/bin/add-user.sh --silent --user '${name}' +# --password \"\$__PASSWD\dress selection. For ex.: `^eth?$` # [*point_to_point*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this -# interface should be whether or not its network interface is a point-to-point interface. An +# Attribute indicating that part of the selection criteria for choosing an IP address for this +# interface should be whether or not its network interface is a point-to-point interface. An # `undef` or `false` value means this attribute is not relevant to the IP address selection # [*public_address*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this +# Attribute indicating that part of the selection criteria for choosing an IP address for this # interface should be whether or not it is a publicly routable address. An `undef` or `false` # value means this attribute is not relevant to the IP address selection # [*site_local_addres*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this -# interface should be whether or it is a site-local address. An `undef` or `false` value +# Attribute indicating that part of the selection criteria for choosing an IP address for this +# interface should be whether or it is a site-local address. An `undef` or `false` value # means this attribute is not relevant to the IP address selection # [*subnet_match*] # Attribite indicating that part of the selection criteria for choosing an IP address for this # interface should be evaluated from regular expression against a subnets of all interfaces. An # example: `192.168.0.0/24` # [*up*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this +# Attribute indicating that part of the selection criteria for choosing an IP address for this # interface should be whether its network interface is currently up. An `undef` or `false` # value means this attribute is not relevant to the IP address selection # [*virtual*] -# Attribute indicating that part of the selection criteria for choosing an IP address for this -# interface should be whether its network interface is a virtual interface. An `undef` or +# Attribute indicating that part of the selection criteria for choosing an IP address for this +# interface should be whether its network interface is a virtual interface. An `undef` or # `false` value means this attribute is not relevant to the IP address selection # define jboss::interface ( @@ -115,10 +118,8 @@ include jboss::internal::augeas include jboss::internal::runtime - $bind_variables = { + $basic_bind_variables = { 'any-address' => $any_address, # undef, bool - 'any-ipv4-address' => $any_ipv4_address, # undef, bool - 'any-ipv6-address' => $any_ipv6_address, # undef, bool 'inet-address' => $inet_address, # '${jboss.bind.address:127.0.0.1}', string 'link-local-address' => $link_local_address,# undef, bool 'loopback' => $loopback, # undef, string @@ -134,6 +135,27 @@ 'virtual' => $virtual, # undef, bool } + $legacy_bind_variables = { + 'any-ipv4-address' => $any_ipv4_address, # undef, bool + 'any-ipv6-address' => $any_ipv6_address, # undef, bool + } + + if ($jboss::product == 'wildfly' and versioncmp($jboss::version, '9.0.0') >= 0) + or ($jboss::product == 'jboss-eap' and versioncmp($jboss::version, '7.0.0') >= 0) { + $bind_variables = $basic_bind_variables + $warning_ipv4_before = 'Interface configuration parameter any_ipv4_address is deprecated for' + $warning_ipv6_before = 'Interface configuration parameter any_ipv6_address is deprecated for' + if $any_ipv4_address { + warning("${warning_ipv4_before} ${jboss::product} server version ${jboss::version}. Ignored.") + } + if $any_ipv6_address { + warning("${warning_ipv6_before} ${jboss::product} server version ${jboss::version}. Ignored.") + } + } + else { + $bind_variables = merge($basic_bind_variables, $legacy_bind_variables) + } + if jboss_to_bool($::jboss_running) { Jboss::Clientry { ensure => $ensure, diff --git a/manifests/internal/compatibility.pp b/manifests/internal/compatibility.pp index 586174f..4804dff 100644 --- a/manifests/internal/compatibility.pp +++ b/manifests/internal/compatibility.pp @@ -4,13 +4,13 @@ case $jboss::product { 'wildfly': { - if versioncmp($jboss::version, '8.0.0') < 0 or versioncmp($jboss::version, '9.0.0') >= 0 { - fail("Unsupported version ${jboss::product} ${jboss::version}. Supporting only: Wildfly 8.x series") + if versioncmp($jboss::version, '8.0.0') < 0 or versioncmp($jboss::version, '10.0.0') >= 0 { + fail("Unsupported version ${jboss::product} ${jboss::version}. Supporting only: Wildfly 8.x and 9.x series") } } 'jboss-eap': { - if versioncmp($jboss::version, '6.0.0') < 0 or versioncmp($jboss::version, '7.0.0') >= 0 { - fail("Unsupported version ${jboss::product} ${jboss::version}. Supporting only: JBoss EAP 6.x series") + if versioncmp($jboss::version, '6.0.0') < 0 or versioncmp($jboss::version, '8.0.0') >= 0 { + fail("Unsupported version ${jboss::product} ${jboss::version}. Supporting only: JBoss EAP 6.x and 7.x series") } } 'jboss-as': { diff --git a/manifests/internal/defaults.pp b/manifests/internal/defaults.pp new file mode 100644 index 0000000..2399fbd --- /dev/null +++ b/manifests/internal/defaults.pp @@ -0,0 +1,20 @@ +# == Class: jboss::internal::defaults +# +class jboss::internal::defaults { + + include jboss + + # Base URL for downloading Jboss Application Server installation package + $download_urlbase = hiera('jboss::params::download_urlbase', 'http://download.jboss.org') + + if $jboss::product == 'jboss-as' { + $__as_version = jboss_short_version($jboss::version) + $__tr_pname = regsubst($jboss::product, '-', '') + $download_url = hiera('jboss::params::download_url', + "${download_urlbase}/${__tr_pname}/${__as_version}/${jboss::product}-${jboss::version}/${jboss::product}-${jboss::version}.zip") + } else { + # Full URL for downloading JBoss Application Server installation package + $download_url = hiera('jboss::params::download_url', + "${download_urlbase}/${jboss::product}/${jboss::version}/${jboss::product}-${jboss::version}.zip") + } +} diff --git a/manifests/internal/module/assemble.pp b/manifests/internal/module/assemble.pp index 6334676..05fc659 100644 --- a/manifests/internal/module/assemble.pp +++ b/manifests/internal/module/assemble.pp @@ -6,6 +6,8 @@ $dependencies = [], ) { include jboss + include jboss::internal::params + include jboss::internal::relationship::module_user $replaced = regsubst($modulename, '\.', '/', 'G') $dir = "modules/system/layers/${layer}/${replaced}/main" @@ -19,9 +21,10 @@ exec { "jboss::module::assemble::${name}(dir=${dir})": command => "/bin/mkdir -p ${jboss::home}/${dir}", unless => "test -d ${jboss::home}/${dir}", - path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + path => $jboss::internal::params::syspath, notify => Service[$jboss::product], require => Anchor['jboss::package::end'], + before => Anchor['jboss::internal::relationship::module_user'], } file { "jboss::module::assemble::${name}(dir=${dir})": @@ -33,6 +36,7 @@ Anchor['jboss::package::end'], Exec["jboss::module::assemble::${name}(dir=${dir})"] ], + before => Anchor['jboss::internal::relationship::module_user'], } file { "jboss::module::assemble::${name}(module.xml)": @@ -41,16 +45,18 @@ content => template('jboss/module/module.xml.erb'), notify => Service[$jboss::product], require => Anchor['jboss::package::end'], + before => Anchor['jboss::internal::relationship::module_user'], } jboss::internal::module::assemble::process_artifacts { $artifacts: dir => $dir, notify => Service[$jboss::product], require => Anchor['jboss::package::end'], + before => Anchor['jboss::internal::relationship::module_user'], } jboss::internal::module::registerlayer { "jboss::module::assemble::${name}(${layer})": - layer => $layer, + layer => $layer, + before => Anchor['jboss::internal::relationship::module_user'], } - } diff --git a/manifests/internal/module/registerlayer.pp b/manifests/internal/module/registerlayer.pp index 5c4ef45..47fd9e6 100644 --- a/manifests/internal/module/registerlayer.pp +++ b/manifests/internal/module/registerlayer.pp @@ -3,6 +3,7 @@ $layer = name, ) { include jboss + include jboss::internal::params File { mode => '0640', @@ -11,9 +12,13 @@ } if (!defined(Exec["jboss::module::layer::${layer}"])) { + $command_1 = "awk -F'=' 'BEGIN {ins = 0} /^layers=/ { ins = ins + 1; print \$1=${layer},\$2 } END " + $command_2 = "{if(ins == 0) print \"layers=${layer},base\"}' > ${jboss::home}/modules/layers.conf" exec { "jboss::module::layer::${layer}": - command => "/bin/awk -F'=' 'BEGIN {ins = 0} /^layers=/ { ins = ins + 1; print \$1=${layer},\$2 } END {if(ins == 0) print \"layers=${layer},base\"}' > ${jboss::home}/modules/layers.conf", - unless => "/bin/egrep -e '^layers=.*${layer}.*' ${jboss::home}/modules/layers.conf", + command => "${command_1}${command_2}", + unless => "egrep -e '^layers=.*${layer}.*' ${jboss::home}/modules/layers.conf", + path => $jboss::internal::params::syspath, + user => $jboss::jboss_user, require => Anchor['jboss::installed'], notify => Service[$jboss::product], } diff --git a/manifests/internal/package.pp b/manifests/internal/package.pp index fb624d4..8a0a867 100644 --- a/manifests/internal/package.pp +++ b/manifests/internal/package.pp @@ -1,19 +1,21 @@ # Internal class that installs JBoss class jboss::internal::package ( - $download_url, $prerequisites, $jboss_user, $jboss_group, + $download_url = $jboss::internal::runtime::download_url, $product = $jboss::params::product, $version = $jboss::params::version, $java_autoinstall = $jboss::params::java_autoinstall, $java_version = $jboss::params::java_version, $java_package = $jboss::params::java_package, $install_dir = $jboss::params::install_dir, + $java_dist = $jboss::params::java_dist, # Prerequisites class, that can be overwritten ) inherits jboss::params { include jboss include jboss::internal::runtime + include jboss::internal::params include jboss::internal::compatibility $download_rootdir = $jboss::internal::params::download_rootdir @@ -43,7 +45,7 @@ } Exec { - path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + path => $jboss::internal::params::syspath, logoutput => 'on_failure', } @@ -74,7 +76,7 @@ if $java_autoinstall { class { 'java': - distribution => 'jdk', + distribution => $java_dist, version => $java_version, package => $java_package, notify => Service[$jboss::product], @@ -86,6 +88,10 @@ ensure => 'directory', } + if $download_file == undef { + fail Puppet::Error, 'Download_url cannot be undef' + } + jboss::internal::util::fetch::file { $download_file: address => $download_url, fetch_dir => $download_dir, diff --git a/manifests/internal/params.pp b/manifests/internal/params.pp index b28610c..d710248 100644 --- a/manifests/internal/params.pp +++ b/manifests/internal/params.pp @@ -8,4 +8,10 @@ include jboss::internal::params::socketbinding include jboss::internal::params::memorydefaults + + # Util System PATH variable to avoid mocking in tests + $syspath = $::path ? { + undef => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + default => $::path, + } } diff --git a/manifests/internal/prerequisites.pp b/manifests/internal/prerequisites.pp index af36e82..c157944 100644 --- a/manifests/internal/prerequisites.pp +++ b/manifests/internal/prerequisites.pp @@ -7,7 +7,5 @@ # None # class jboss::internal::prerequisites { - if ! defined(Package['unzip']) { - ensure_packages(['unzip']) - } + ensure_packages(['unzip']) } diff --git a/manifests/internal/quirks/etc_initd_functions.pp b/manifests/internal/quirks/etc_initd_functions.pp index 2c1c551..231ab6d 100644 --- a/manifests/internal/quirks/etc_initd_functions.pp +++ b/manifests/internal/quirks/etc_initd_functions.pp @@ -1,6 +1,7 @@ # Internal class - Quircks for /etc/init.d/functions loading from RHEL even on Debian like systems class jboss::internal::quirks::etc_initd_functions { include jboss + include jboss::internal::params include jboss::internal::service include jboss::internal::compatibility @@ -19,7 +20,7 @@ onlyif => "test \"$(head -n 1 ${jboss::internal::compatibility::initd_file})\" = '#!/bin/sh'", require => Anchor['jboss::package::end'], notify => Service[$jboss::internal::service::servicename], - path => $::path, + path => $jboss::internal::params::syspath, } } } diff --git a/manifests/internal/relationship/module_user.pp b/manifests/internal/relationship/module_user.pp new file mode 100644 index 0000000..936553f --- /dev/null +++ b/manifests/internal/relationship/module_user.pp @@ -0,0 +1,6 @@ +# == Class jboss::internal::relationship::module_before_user +# Class that contains relationship beetwen modules and user, all modules have to be assembled before user is made +class jboss::internal::relationship::module_user { + + anchor { 'jboss::internal::relationship::module_user': } +} diff --git a/manifests/internal/runtime.pp b/manifests/internal/runtime.pp index bdfa433..62ea96f 100644 --- a/manifests/internal/runtime.pp +++ b/manifests/internal/runtime.pp @@ -2,6 +2,13 @@ class jboss::internal::runtime { include jboss + include jboss::internal::defaults + + $download_url = $jboss::download_url ? { + undef => $jboss::internal::defaults::download_url, + default => $jboss::download_url + } + $runasdomain = $jboss::runasdomain $profile = $jboss::profile diff --git a/manifests/internal/service.pp b/manifests/internal/service.pp index 98dc938..1aac090 100644 --- a/manifests/internal/service.pp +++ b/manifests/internal/service.pp @@ -4,19 +4,25 @@ include jboss include jboss::params include jboss::internal::configuration + include jboss::internal::params Exec { - path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + path => $jboss::internal::params::syspath, logoutput => 'on_failure', } anchor { 'jboss::service::begin': } $servicename = $jboss::product + # TODO: change to $::virtual after dropping support for Puppet 2.x + $enable = $::jboss_virtual ? { + 'docker' => undef, + default => true, + } service { $servicename: ensure => running, - enable => true, + enable => $enable, hasstatus => true, hasrestart => true, subscribe => [ diff --git a/manifests/internal/util/download.pp b/manifests/internal/util/download.pp index d579255..c59dd1d 100644 --- a/manifests/internal/util/download.pp +++ b/manifests/internal/util/download.pp @@ -9,6 +9,7 @@ $filename = undef, $install_wget = true, ) { + include jboss::internal::params if $filename == undef { $base = jboss_basename($uri) @@ -42,7 +43,7 @@ exec { "wget -q '${uri}' -O '${dest}' && chmod ${mode} '${dest}' && chown ${owner}:${group} '${dest}'": alias => "download ${name}", logoutput => 'on_failure', - path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + path => $jboss::internal::params::syspath, creates => $dest, timeout => $timeout, require => [ diff --git a/manifests/internal/util/fetch/file.pp b/manifests/internal/util/fetch/file.pp index 09112e3..1277b4c 100644 --- a/manifests/internal/util/fetch/file.pp +++ b/manifests/internal/util/fetch/file.pp @@ -12,11 +12,11 @@ if defined(Class['jboss']) { include jboss - $actualOwner = $owner ? { + $actual_owner = $owner ? { undef => $jboss::jboss_user, default => $owner } - $actualGroup = $group ? { + $actual_group = $group ? { undef => $jboss::jboss_group, default => $group } @@ -26,11 +26,11 @@ } } else { include jboss::params - $actualOwner = $owner ? { + $actual_owner = $owner ? { undef => $jboss::params::jboss_user, default => $owner } - $actualGroup = $group ? { + $actual_group = $group ? { undef => $jboss::params::jboss_group, default => $group } @@ -46,8 +46,8 @@ 'filename' => $filename, 'fetch_dir' => $fetch_dir, 'mode' => $mode, - 'owner' => $actualOwner, - 'group' => $actualGroup, + 'owner' => $actual_owner, + 'group' => $actual_group, }) $emptyhack = '' diff --git a/manifests/params.pp b/manifests/params.pp index 26fcc06..425a141 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -5,7 +5,7 @@ $product = hiera('jboss::params::product', 'wildfly') # Version of JBoss Application Server - $version = hiera('jboss::params::version', '8.2.0.Final') + $version = hiera('jboss::params::version', '9.0.2.Final') # Deprcated, will deleted in next major version include jboss::internal::quirks::autoinstall @@ -21,18 +21,15 @@ # Java package version, undef, jdk, jre $java_package = hiera('jboss::params::java_package', undef) + # Java distribution: jre or jdk + $java_dist = hiera('jboss::params::java_dist', 'jre') + # User for Jboss Application Server $jboss_user = hiera('jboss::params::jboss_user', 'jboss') # Group for Jboss Application Server $jboss_group = hiera('jboss::params::jboss_group', 'jboss') - # Base URL for downloading Jboss Application Server installation package - $download_urlbase = hiera('jboss::params::download_urlbase', 'http://download.jboss.org') - - # Full URL for downloading JBoss Application Server installation package - $download_url = hiera('jboss::params::download_url', "${download_urlbase}/${product}/${version}/${product}-${version}.zip") - # Target installation directory root $install_dir = hiera('jboss::params::install_dir', '/usr/lib') diff --git a/manifests/resourceadapter.pp b/manifests/resourceadapter.pp index 5cacc9c..48af3a0 100644 --- a/manifests/resourceadapter.pp +++ b/manifests/resourceadapter.pp @@ -1,10 +1,10 @@ # == Define: jboss::resourceadapter # -# This defined type can be used to add and remove JBoss resource adapters. A resource adapter +# This defined type can be used to add and remove JBoss resource adapters. A resource adapter # is a deployable Java EE component that provides communication between a Java EE application -# and an Enterprise Information System (EIS) using the Java Connector Architecture (JCA) +# and an Enterprise Information System (EIS) using the Java Connector Architecture (JCA) # specification -# +# # See here: https://docs.oracle.com/javaee/6/tutorial/doc/bncjh.html # # === Parameters diff --git a/manifests/user.pp b/manifests/user.pp index 9fbeae8..81b5478 100644 --- a/manifests/user.pp +++ b/manifests/user.pp @@ -26,6 +26,8 @@ include jboss require jboss::internal::package include jboss::internal::service + include jboss::internal::params + include jboss::internal::relationship::module_user $home = $jboss::home @@ -53,6 +55,9 @@ $filepath = "${home}/${dir}/configuration/${file}" $filepath_roles = "${home}/${dir}/configuration/application-roles.properties" $jbossuserfix = '2>&1 | awk \'BEGIN{a=0}{if (/Error/){a=1};print}END{if (a==1) exit 1}\'' + Exec { + path => $jboss::internal::params::syspath, + } case $ensure { 'present': { @@ -63,14 +68,19 @@ # By default the properties realm expects the entries to be in the format: - # username=HEX( MD5( username ':' realm ':' password)) $mangledpasswd = md5("${name}:${realm}:${password}") + $command_1 = "${home}/bin/add-user.sh --silent --user '${name}' --password \"\$__PASSWD\"" + $command_2 = " --realm '${realm}' ${rolesstr} ${extraarg} ${jbossuserfix}" exec { "jboss::user::add(${realm}/${name})": environment => [ "JBOSS_HOME=${home}", "__PASSWD=${password}" ], - command => "${home}/bin/add-user.sh --silent --user '${name}' --password \"\$__PASSWD\" --realm '${realm}' ${rolesstr} ${extraarg} ${jbossuserfix}", + command => "${command_1}${command_2}", unless => "/bin/egrep -e '^${name}=${mangledpasswd}' ${filepath}", - require => Anchor['jboss::package::end'], + require => [ + Anchor['jboss::package::end'], + Anchor['jboss::internal::relationship::module_user'], + ], notify => Service[$jboss::internal::service::servicename], logoutput => true, } @@ -80,7 +90,10 @@ path => $filepath_roles, line => "${name}=${roles}", match => "${name}=.*", - require => Exec["jboss::user::add(${realm}/${name})"], + require => [ + Exec["jboss::user::add(${realm}/${name})"], + Anchor['jboss::internal::relationship::module_user'], + ], notify => Service[$jboss::internal::service::servicename], } } @@ -89,7 +102,10 @@ exec { "jboss::user::remove(${realm}/${name})": command => "/bin/sed -iE 's/^${name}=.*$//g' ${filepath}", onlyif => "/bin/egrep -e '^${name}=' ${filepath}", - require => Anchor['jboss::package::end'], + require => [ + Anchor['jboss::package::end'], + Anchor['jboss::internal::relationship::module_user'], + ], logoutput => 'on_failure', notify => Service[$jboss::internal::service::servicename], } @@ -97,7 +113,10 @@ exec { "jboss::user::roles::remove(${realm}/${name})": command => "/bin/sed -iE 's/^${name}=.*$//g' ${filepath_roles}", onlyif => "/bin/egrep -e '^${name}=' ${filepath_roles}", - require => Anchor['jboss::package::end'], + require => [ + Anchor['jboss::package::end'], + Anchor['jboss::internal::relationship::module_user'], + ], logoutput => 'on_failure', notify => Service[$jboss::internal::service::servicename], } diff --git a/metadata.json b/metadata.json index 84ebc41..e3a1f69 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "coi/jboss", - "version": "1.0.3", + "version": "1.1.0", "author": "Center of Information Technology COI.gov.pl", "summary": "Installs JBoss EAP and WildFly application servers and manage their resources and applications in either a domain or a stand-alone mode", "license": "Apache-2.0", diff --git a/spec/acceptance/001_init_spec.rb b/spec/acceptance/001_init_spec.rb deleted file mode 100644 index cd606e9..0000000 --- a/spec/acceptance/001_init_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'jboss class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do - describe 'executing with defaults' do - - pp = <<-eos - class { 'jboss': } - eos - - it 'should work without errors' do - apply_manifest(pp, :catch_failures => true) - end - it 'should not make any changes when executed twice' do - apply_manifest(pp, :expect_changes => false) - end - describe service('wildfly') do - it { should be_running } - end - - end -end \ No newline at end of file diff --git a/spec/acceptance/clientry_spec.rb b/spec/acceptance/clientry_spec.rb new file mode 100644 index 0000000..d361cd9 --- /dev/null +++ b/spec/acceptance/clientry_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_acceptance' + +describe 'clientry smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:baseserver) { Testing::Acceptance::SmokeTestReader.smoke_pp :init } + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :clientry } + + it 'should install base server with no errors' do + apply_manifest(baseserver, :catch_failures => true) + end + it 'should add CLI entry with no errors' do + apply_manifest(pp, :catch_failures => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true) + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/datasource_spec.rb b/spec/acceptance/datasource_spec.rb new file mode 100644 index 0000000..4b84ead --- /dev/null +++ b/spec/acceptance/datasource_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_acceptance' + +describe 'datasource smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:baseserver) { Testing::Acceptance::SmokeTestReader.smoke_pp :init } + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :datasource } + + it 'should install base server with no errors' do + apply_manifest(baseserver, :catch_failures => true) + end + it 'should add datasource with no errors' do + apply_manifest(pp, :catch_failures => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true) + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/deploy_spec.rb b/spec/acceptance/deploy_spec.rb new file mode 100644 index 0000000..9e79da7 --- /dev/null +++ b/spec/acceptance/deploy_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper_acceptance' + +describe 'deploy smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:baseserver) { Testing::Acceptance::SmokeTestReader.smoke_pp :init } + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :deploy } + + it 'should install base server with no errors' do + apply_manifest(baseserver, :catch_failures => true) + end + it 'should deploy artifact with no errors' do + apply_manifest(pp, :catch_failures => true) + end + context 'verifing idempotency' do + before(:each) { skip('This not work, GH issue: coi-gov-pl/puppet-jboss#71') } + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true) + end + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/init_spec.rb b/spec/acceptance/init_spec.rb new file mode 100644 index 0000000..5c2161b --- /dev/null +++ b/spec/acceptance/init_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper_acceptance' + +describe 'init smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :init } + + it 'should install WildFly 9.x with no errors' do + apply_manifest(pp, :catch_failures => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true) + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/interface_spec.rb b/spec/acceptance/interface_spec.rb new file mode 100644 index 0000000..e11b894 --- /dev/null +++ b/spec/acceptance/interface_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_acceptance' + +describe 'interface smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:baseserver) { Testing::Acceptance::SmokeTestReader.smoke_pp :init } + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :interface } + + it 'should install base server with no errors' do + apply_manifest(baseserver, :catch_failures => true) + end + it 'should add insterface with no errors' do + apply_manifest(pp, :catch_failures => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true) + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/jboss/as7_spec.rb b/spec/acceptance/jboss/as7_spec.rb new file mode 100644 index 0000000..fa27588 --- /dev/null +++ b/spec/acceptance/jboss/as7_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper_acceptance' + +describe 'jboss::as7 smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :'jboss::as7' } + + it 'should add install JBoss AS 7 with no errors' do + apply_manifest(pp, :expect_changes => true, :trace => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true, :trace => true) + end + describe service('jboss-as') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('jboss-as') + end +end diff --git a/spec/acceptance/jboss/wildfly8_spec.rb b/spec/acceptance/jboss/wildfly8_spec.rb new file mode 100644 index 0000000..a22c834 --- /dev/null +++ b/spec/acceptance/jboss/wildfly8_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper_acceptance' + +describe 'jboss::wildfly8 smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :'jboss::wildfly8' } + + it 'should add install WildFly 8 with no errors' do + apply_manifest(pp, :expect_changes => true, :trace => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true, :trace => true) + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/jboss/wildfly9_spec.rb b/spec/acceptance/jboss/wildfly9_spec.rb new file mode 100644 index 0000000..c64899d --- /dev/null +++ b/spec/acceptance/jboss/wildfly9_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper_acceptance' + +describe 'jboss::wildfly9 smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :'jboss::wildfly9' } + + it 'should add install WildFly 9 with no errors' do + apply_manifest(pp, :expect_changes => true, :trace => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true, :trace => true) + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/jmsqueue_spec.rb b/spec/acceptance/jmsqueue_spec.rb new file mode 100644 index 0000000..aa9ac47 --- /dev/null +++ b/spec/acceptance/jmsqueue_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_acceptance' + +describe 'jmsqueue smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:baseserver) { Testing::Acceptance::SmokeTestReader.smoke_pp :init } + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :jmsqueue } + + it 'should install base server with no errors' do + apply_manifest(baseserver, :catch_failures => true) + end + it 'should add jmsqueue with no errors' do + apply_manifest(pp, :catch_failures => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true) + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/module_spec.rb b/spec/acceptance/module_spec.rb new file mode 100644 index 0000000..dd6068f --- /dev/null +++ b/spec/acceptance/module_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_acceptance' + +describe 'module smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:baseserver) { Testing::Acceptance::SmokeTestReader.smoke_pp :init } + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :module } + + it 'should install base server with no errors' do + apply_manifest(baseserver, :catch_failures => true, :trace => true) + end + it 'should add module with no errors' do + apply_manifest(pp, :catch_failures => true, :trace => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true, :trace => true) + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/nodesets/centos-5-x86_64-docker.yml b/spec/acceptance/nodesets/centos-5-x86_64-docker.yml deleted file mode 100644 index f31fc23..0000000 --- a/spec/acceptance/nodesets/centos-5-x86_64-docker.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - centos-5-x64: - platform: el-5-x86_64 - hypervisor : docker - image: centos:5 - docker_preserve_image: true - docker_cmd: '["/sbin/init"]' - docker_image_commands: - - 'yum install -y crontabs tar wget' -CONFIG: - type: foss - log_level: debug diff --git a/spec/acceptance/nodesets/centos-6-x86_64-docker.yml b/spec/acceptance/nodesets/centos-6-x86_64-docker.yml index 6fbea74..d4d9922 100644 --- a/spec/acceptance/nodesets/centos-6-x86_64-docker.yml +++ b/spec/acceptance/nodesets/centos-6-x86_64-docker.yml @@ -4,9 +4,8 @@ HOSTS: hypervisor : docker image: centos:6 docker_preserve_image: true - docker_cmd: '["/sbin/init"]' docker_image_commands: - - 'yum install -y crontabs tar wget' + - 'yum install -y crontabs wget' CONFIG: type: foss log_level: debug diff --git a/spec/acceptance/nodesets/centos-6-x86_64-pe288-docker.yml b/spec/acceptance/nodesets/centos-6-x86_64-pe288-docker.yml index 36d256d..a6fe6b7 100644 --- a/spec/acceptance/nodesets/centos-6-x86_64-pe288-docker.yml +++ b/spec/acceptance/nodesets/centos-6-x86_64-pe288-docker.yml @@ -9,8 +9,8 @@ HOSTS: image: centos:centos6 hypervisor: docker docker_preserve_image: true - docker_image_commands: - - 'yum install -y tar vim' + docker_image_commands: + - 'yum install -y crontabs wget' CONFIG: type: pe pe_ver: 2.8.8 @@ -18,4 +18,4 @@ CONFIG: log_level: verbose ssh: password: root - auth_methods: ["password"] \ No newline at end of file + auth_methods: ["password"] diff --git a/spec/acceptance/nodesets/centos-6-x86_64-pe382-docker.yml b/spec/acceptance/nodesets/centos-6-x86_64-pe382-docker.yml index 2866714..a4e6ecb 100644 --- a/spec/acceptance/nodesets/centos-6-x86_64-pe382-docker.yml +++ b/spec/acceptance/nodesets/centos-6-x86_64-pe382-docker.yml @@ -9,8 +9,8 @@ HOSTS: image: centos:centos6 hypervisor: docker docker_preserve_image: true - docker_image_commands: - - 'yum install -y tar vim' + docker_image_commands: + - 'yum install -y crontabs wget' CONFIG: type: pe pe_ver: 3.8.2 @@ -18,4 +18,4 @@ CONFIG: log_level: verbose ssh: password: root - auth_methods: ["password"] \ No newline at end of file + auth_methods: ["password"] diff --git a/spec/acceptance/nodesets/centos-7-x86_64-docker.yml b/spec/acceptance/nodesets/centos-7-x86_64-docker.yml index 5d5150b..5988d13 100644 --- a/spec/acceptance/nodesets/centos-7-x86_64-docker.yml +++ b/spec/acceptance/nodesets/centos-7-x86_64-docker.yml @@ -6,7 +6,7 @@ HOSTS: docker_preserve_image: true docker_cmd: '["/usr/sbin/init"]' docker_image_commands: - - 'yum install -y crontabs tar wget' + - 'yum install -y crontabs wget' CONFIG: type: foss log_level: debug diff --git a/spec/acceptance/nodesets/debian-6-x86_64-docker.yml b/spec/acceptance/nodesets/debian-6-x86_64-docker.yml index ac13e21..bffefad 100644 --- a/spec/acceptance/nodesets/debian-6-x86_64-docker.yml +++ b/spec/acceptance/nodesets/debian-6-x86_64-docker.yml @@ -6,7 +6,7 @@ HOSTS: docker_preserve_image: true docker_cmd: '["/sbin/init"]' docker_image_commands: - - 'apt-get install -y wget' + - 'apt-get update && apt-get install -y cron locales-all net-tools wget' CONFIG: type: foss log_level: debug diff --git a/spec/acceptance/nodesets/debian-7-x86_64-docker.yml b/spec/acceptance/nodesets/debian-7-x86_64-docker.yml index f522b17..0ffd7b4 100644 --- a/spec/acceptance/nodesets/debian-7-x86_64-docker.yml +++ b/spec/acceptance/nodesets/debian-7-x86_64-docker.yml @@ -6,7 +6,7 @@ HOSTS: docker_preserve_image: true docker_cmd: '["/sbin/init"]' docker_image_commands: - - 'apt-get install -y cron locales-all net-tools wget' + - 'apt-get update && apt-get install -y cron locales-all net-tools wget' CONFIG: type: foss log_level: debug diff --git a/spec/acceptance/nodesets/debian-8-x86_64-docker.yml b/spec/acceptance/nodesets/debian-8-x86_64-docker.yml index c8e457f..c29830e 100644 --- a/spec/acceptance/nodesets/debian-8-x86_64-docker.yml +++ b/spec/acceptance/nodesets/debian-8-x86_64-docker.yml @@ -6,7 +6,7 @@ HOSTS: docker_preserve_image: true docker_cmd: '["/sbin/init"]' docker_image_commands: - - 'apt-get install -y cron locales-all net-tools wget' + - 'apt-get update && apt-get install -y cron locales-all net-tools wget' - 'rm -f /usr/sbin/policy-rc.d' CONFIG: type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml index 6fbea74..d4d9922 100644 --- a/spec/acceptance/nodesets/default.yml +++ b/spec/acceptance/nodesets/default.yml @@ -4,9 +4,8 @@ HOSTS: hypervisor : docker image: centos:6 docker_preserve_image: true - docker_cmd: '["/sbin/init"]' docker_image_commands: - - 'yum install -y crontabs tar wget' + - 'yum install -y crontabs wget' CONFIG: type: foss log_level: debug diff --git a/spec/acceptance/nodesets/ubuntu-10.04-x86_64-docker.yml b/spec/acceptance/nodesets/ubuntu-10.04-x86_64-docker.yml deleted file mode 100644 index 94a51b1..0000000 --- a/spec/acceptance/nodesets/ubuntu-10.04-x86_64-docker.yml +++ /dev/null @@ -1,10 +0,0 @@ -HOSTS: - ubuntu-1004-x64: - platform: ubuntu-10.04-amd64 - hypervisor : docker - image: ubuntu:10.04 - # This stops the image from being deleted on completion, speeding up the process. - docker_preserve_image: true -CONFIG: - type: foss - log_level: debug diff --git a/spec/acceptance/nodesets/ubuntu-12.04-x86_64-docker.yml b/spec/acceptance/nodesets/ubuntu-12.04-x86_64-docker.yml index 0d53cbf..c73068a 100644 --- a/spec/acceptance/nodesets/ubuntu-12.04-x86_64-docker.yml +++ b/spec/acceptance/nodesets/ubuntu-12.04-x86_64-docker.yml @@ -4,9 +4,8 @@ HOSTS: hypervisor : docker image: ubuntu:12.04 docker_preserve_image: true - docker_cmd: '["/sbin/init"]' docker_image_commands: - - 'apt-get install -y net-tools wget' + - 'apt-get update && apt-get install -y net-tools ca-certificates wget' - 'locale-gen en_US.UTF-8' CONFIG: type: foss diff --git a/spec/acceptance/nodesets/ubuntu-14.04-x86_64-docker.yml b/spec/acceptance/nodesets/ubuntu-14.04-x86_64-docker.yml index 31f8329..346bf34 100644 --- a/spec/acceptance/nodesets/ubuntu-14.04-x86_64-docker.yml +++ b/spec/acceptance/nodesets/ubuntu-14.04-x86_64-docker.yml @@ -4,11 +4,10 @@ HOSTS: hypervisor : docker image: ubuntu:14.04 docker_preserve_image: true - docker_cmd: '["/sbin/init"]' docker_image_commands: - 'rm /usr/sbin/policy-rc.d' - 'rm /sbin/initctl; dpkg-divert --rename --remove /sbin/initctl' - - 'apt-get install -y net-tools wget' + - 'apt-get update && apt-get install -y net-tools ca-certificates wget' - 'locale-gen en_US.UTF-8' CONFIG: type: foss diff --git a/spec/acceptance/nodesets/ubuntu-14.10-x86_64-docker.yml b/spec/acceptance/nodesets/ubuntu-14.10-x86_64-docker.yml index 86e1dd2..fdd22cc 100644 --- a/spec/acceptance/nodesets/ubuntu-14.10-x86_64-docker.yml +++ b/spec/acceptance/nodesets/ubuntu-14.10-x86_64-docker.yml @@ -4,11 +4,10 @@ HOSTS: hypervisor : docker image: ubuntu:14.10 docker_preserve_image: true - docker_cmd: '["/sbin/init"]' docker_image_commands: - 'rm /usr/sbin/policy-rc.d' - 'rm /sbin/initctl; dpkg-divert --rename --remove /sbin/initctl' - - 'apt-get install -y net-tools wget' + - 'apt-get update && apt-get install -y net-tools ca-certificates wget' - 'locale-gen en_US.UTF-8' CONFIG: type: foss diff --git a/spec/acceptance/nodesets/ubuntu-15.04-x86_64-docker.yml b/spec/acceptance/nodesets/ubuntu-15.04-x86_64-docker.yml index fd28fd0..b872fdc 100644 --- a/spec/acceptance/nodesets/ubuntu-15.04-x86_64-docker.yml +++ b/spec/acceptance/nodesets/ubuntu-15.04-x86_64-docker.yml @@ -6,7 +6,7 @@ HOSTS: docker_preserve_image: true docker_cmd: '["/sbin/init"]' docker_image_commands: - - 'apt-get install -y net-tools wget' + - 'apt-get update && apt-get install -y net-tools ca-certificates wget' - 'locale-gen en_US.UTF-8' CONFIG: type: foss diff --git a/spec/acceptance/resourceadapter_spec.rb b/spec/acceptance/resourceadapter_spec.rb new file mode 100644 index 0000000..027d426 --- /dev/null +++ b/spec/acceptance/resourceadapter_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper_acceptance' + +describe 'resourceadapter smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:baseserver) { Testing::Acceptance::SmokeTestReader.smoke_pp :init } + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :resourceadapter } + + it 'should install base server with no errors' do + apply_manifest(baseserver, :catch_failures => true) + end + it 'should add resource adapter with no errors' do + apply_manifest(pp, :catch_failures => true) + end + context 'verifing idempotency' do + before(:each) { skip('This not work, GH issue: coi-gov-pl/puppet-jboss#70') } + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true) + end + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/securitydomain_spec.rb b/spec/acceptance/securitydomain_spec.rb new file mode 100644 index 0000000..3e09e6a --- /dev/null +++ b/spec/acceptance/securitydomain_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_acceptance' + +describe 'securitydomain smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:baseserver) { Testing::Acceptance::SmokeTestReader.smoke_pp :init } + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :securitydomain } + + it 'should install base server with no errors' do + apply_manifest(baseserver, :catch_failures => true, :trace => true) + end + it 'should add securitydomain with no errors' do + apply_manifest(pp, :catch_failures => true, :trace => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true, :trace => true) + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/acceptance/user_spec.rb b/spec/acceptance/user_spec.rb new file mode 100644 index 0000000..05f1332 --- /dev/null +++ b/spec/acceptance/user_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_acceptance' + +describe 'user smoke test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + let(:baseserver) { Testing::Acceptance::SmokeTestReader.smoke_pp :init } + let(:pp) { Testing::Acceptance::SmokeTestReader.smoke_pp :user } + + it 'should install base server with no errors' do + apply_manifest(baseserver, :catch_failures => true) + end + it 'should add user with no errors' do + apply_manifest(pp, :catch_failures => true) + end + it 'should work idempotently' do + apply_manifest(pp, :catch_changes => true) + end + describe service('wildfly') do + it { is_expected.to be_running } + end + after(:all) do + extend Testing::Acceptance::Cleaner + remove_jboss_installation('wildfly') + end +end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index dc836d0..171ec93 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,22 +1,15 @@ require 'spec_helper_puppet' describe 'jboss', :type => :class do - let(:facts) do - { - :operatingsystem => 'OracleLinux', - :osfamily => 'RedHat', - :ipaddress => '192.168.0.1', - :concat_basedir => '/root/concat', - :puppetversion => Puppet.version - } - end + + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + extend Testing::RspecPuppet::SharedExamples context 'with defaults for all parameters' do it { is_expected.to compile } it do is_expected.to contain_class('jboss').with({ :product => 'wildfly', - :version => '8.2.0.Final', - :download_url => 'http://download.jboss.org/wildfly/8.2.0.Final/wildfly-8.2.0.Final.zip' + :version => '9.0.2.Final', }) end it { is_expected.to contain_anchor 'jboss::begin' } @@ -31,12 +24,19 @@ it { is_expected.to contain_anchor 'jboss::service::started' } it { is_expected.to contain_user 'jboss' } it { is_expected.to contain_group 'jboss' } + it { is_expected.to contain_class('jboss::internal::package').with({ + :version => '9.0.2.Final', + :product => 'wildfly', + :jboss_user => 'jboss', + :jboss_group => 'jboss', + :java_version => 'latest' + })} end context 'with product => jboss-eap and version => 6.4.0.GA parameters set' do let(:params) do { :product => 'jboss-eap', :version => '6.4.0.GA' } end - + it { is_expected.to compile } it { is_expected.to contain_class 'jboss' } it { is_expected.to contain_user 'jboss' } @@ -46,7 +46,7 @@ let(:params) do { :jboss_user => 'appserver' } end - + it { is_expected.to compile } it { is_expected.to contain_class 'jboss' } it { is_expected.to contain_user 'appserver' } @@ -62,5 +62,13 @@ :download_url => 'file:///tmp/wildfly-8.2.0.Final.zip' }) end + it { is_expected.to contain_class 'jboss::params' } + it { is_expected.to contain_class 'jboss::internal::compatibility' } + it { is_expected.to contain_class 'jboss::internal::configuration' } + it { is_expected.to contain_class 'jboss::internal::service' } + + it_behaves_like common_interfaces + it_behaves_like common_anchors + end end diff --git a/spec/classes/internal/augeas_spec.rb b/spec/classes/internal/augeas_spec.rb new file mode 100644 index 0000000..4323f83 --- /dev/null +++ b/spec/classes/internal/augeas_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::augeas', :type => :class do + DEFAULT_VERSION = '9.0.2.Final' + DEFAULT_PRODUCT = 'wildfly' + + shared_examples 'contains self' do + it { is_expected.to contain_class('jboss') } + it { is_expected.to contain_class 'jboss::internal::lenses' } + it { is_expected.to contain_class 'jboss::internal::augeas' } + it { is_expected.to contain_file("/usr/lib/#{DEFAULT_PRODUCT}-#{DEFAULT_VERSION}/lenses/jbxml.aug") } + end + + context 'On RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-augeas' } + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + + it_behaves_like 'contains self' + end + + context 'On Debian os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-augeas' } + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + it_behaves_like 'contains self' + end +end diff --git a/spec/classes/internal/configuration_spec.rb b/spec/classes/internal/configuration_spec.rb new file mode 100644 index 0000000..f623eb1 --- /dev/null +++ b/spec/classes/internal/configuration_spec.rb @@ -0,0 +1,88 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::configuration', :type => :class do + + shared_examples 'contains basic class structure' do + it { is_expected.to contain_class('jboss') } + it { is_expected.to contain_class('jboss::params') } + it { is_expected.to contain_class('jboss::internal::params') } + it { is_expected.to contain_class('jboss::internal::runtime') } + it { is_expected.to contain_class('jboss::internal::augeas') } + it { is_expected.to contain_class('jboss::internal::configure::interfaces') } + it { is_expected.to contain_class('jboss::internal::quirks::etc_initd_functions') } + it { is_expected.to contain_class('jboss::internal::configuration') } + end + + shared_examples 'contains basic anchor structure' do + it { is_expected.to contain_anchor('jboss::configuration::begin') } + it { is_expected.to contain_anchor('jboss::configuration::end') } + end + + shared_examples 'contains file structure' do + it { is_expected.to contain_file('/etc/profile.d/jboss.sh').with({ + :ensure => 'file', + :mode => '0644' + }) } + + it { is_expected.to contain_file('/var/log/wildfly/console.log').with({ + :ensure => 'file', + :alias => 'jboss::logfile', + :owner => 'root', + :group => 'jboss', + :mode => '0660' + }) } + + it { is_expected.to contain_file('/etc/jboss-as').with({ + :ensure => 'directory', + :mode => '2770', + :owner => 'jboss', + :group => 'jboss' + }) } + + it { is_expected.to contain_file('/etc/jboss-as/jboss-as.conf'). + with_ensure('link'). + that_comes_before('Anchor[jboss::configuration::end]') } + + it { is_expected.to contain_file('/etc/default').with_ensure('directory') } + + it { is_expected.to contain_file('/etc/default/wildfly.conf'). + with_ensure('link'). + that_comes_before('Anchor[jboss::configuration::end]') } + end + + shared_examples 'contains self' do + it { is_expected.to contain_concat('/etc/wildfly/wildfly.conf').with({ + :alias => 'jboss::jboss-as.conf', + :mode => '0644' + }) } + it { is_expected.to contain_concat__fragment('jboss::jboss-as.conf::defaults').with({ + :order => '000' + }) } + end + + context 'On RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-configuration' } + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + + it_behaves_like 'contains self' + it_behaves_like 'contains basic class structure' + it_behaves_like 'contains basic anchor structure' + it_behaves_like 'contains file structure' + + it { is_expected.to contain_file('/etc/sysconfig/wildfly.conf') } + end + + context 'On Debian os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-configuration' } + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + + it_behaves_like 'contains self' + it_behaves_like 'contains basic class structure' + it_behaves_like 'contains basic anchor structure' + it_behaves_like 'contains file structure' + + it { is_expected.to contain_file('/etc/default/wildfly') } + end +end diff --git a/spec/classes/internal/configure/interfaces_spec.rb b/spec/classes/internal/configure/interfaces_spec.rb new file mode 100644 index 0000000..f05de7b --- /dev/null +++ b/spec/classes/internal/configure/interfaces_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::configure::interfaces', :type => :define do + shared_examples 'contains self' do + it { is_expected.to contain_class 'jboss::internal::configure::interfaces' } + it { is_expected.to contain_class('jboss') } + it { is_expected.to contain_class('jboss::params') } + it { is_expected.to contain_class('jboss::internal::runtime::dc') } + end + + context 'On RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-conf-interfaces' } + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + + it_behaves_like 'contains self' + end + + context 'On Debian os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-conf-interfaces' } + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + + it_behaves_like 'contains self' + end +end diff --git a/spec/classes/internal/lenses_spec.rb b/spec/classes/internal/lenses_spec.rb new file mode 100644 index 0000000..e7b495a --- /dev/null +++ b/spec/classes/internal/lenses_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::lenses', :type => :class do + DEFAULT_VERSION = '9.0.2.Final' + DEFAULT_PRODUCT = 'wildfly' + + shared_examples 'completly working define' do + it { is_expected.to contain_class 'jboss::internal::lenses' } + it { is_expected.to contain_class 'jboss' } + it { is_expected.to contain_file("/usr/lib/#{DEFAULT_PRODUCT}-#{DEFAULT_VERSION}/lenses/jbxml.aug").with({ + :ensure => 'file', + :source => 'puppet:///modules/jboss/jbxml.aug', + })} + it { is_expected.to contain_file("/usr/lib/#{DEFAULT_PRODUCT}-#{DEFAULT_VERSION}/lenses/jbxml.aug").that_requires( + "File[/usr/lib/#{DEFAULT_PRODUCT}-#{DEFAULT_VERSION}/lenses/]" + )} + it { is_expected.to contain_file("/usr/lib/#{DEFAULT_PRODUCT}-#{DEFAULT_VERSION}/lenses").with({ + :ensure => 'directory', + :owner => 'jboss', + }) } + it { is_expected.to contain_file("/usr/lib/#{DEFAULT_PRODUCT}-#{DEFAULT_VERSION}/lenses").that_requires( + 'Anchor[jboss::configuration::begin]' + )} + end + + context 'On RedHat os family' do + let(:title) { 'test-lenses' } + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + it_behaves_like 'completly working define' + end + + context 'On Debian os family' do + let(:title) { 'test-lenses' } + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + it_behaves_like 'completly working define' + end +end diff --git a/spec/classes/internal/prerequisites_spec.rb b/spec/classes/internal/prerequisites_spec.rb new file mode 100644 index 0000000..e1c27d8 --- /dev/null +++ b/spec/classes/internal/prerequisites_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::prerequisites', :type => :define do + shared_examples 'completly working define' do + it { is_expected.to compile } + it { is_expected.to contain_class 'jboss::internal::prerequisites' } + it { is_expected.to contain_package('unzip') } + end + + context 'On RedHat os family' do + let(:title) { 'test-prerequisites' } + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + it_behaves_like 'completly working define' + end + context 'On Debian os family' do + let(:title) { 'test-module' } + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + it_behaves_like 'completly working define' + end +end diff --git a/spec/classes/internal/quirks/etc_initd_functions_spec.rb b/spec/classes/internal/quirks/etc_initd_functions_spec.rb new file mode 100644 index 0000000..3fdebcc --- /dev/null +++ b/spec/classes/internal/quirks/etc_initd_functions_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::quirks::etc_initd_functions', :type => :define do + shared_examples 'contains class structure' do + it { is_expected.to contain_class 'jboss::internal::quirks::etc_initd_functions' } + it { is_expected.to contain_class('jboss') } + it { is_expected.to contain_class('jboss::internal::service') } + it { is_expected.to contain_class('jboss::internal::compatibility') } + end + + context 'On RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-etc_initd_functions' } + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + + it_behaves_like 'contains class structure' + + end + + context 'On Debian os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-etc_initd_functions' } + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + + it_behaves_like 'contains class structure' + + end +end diff --git a/spec/classes/internal/service_spec.rb b/spec/classes/internal/service_spec.rb new file mode 100644 index 0000000..9b940a7 --- /dev/null +++ b/spec/classes/internal/service_spec.rb @@ -0,0 +1,107 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::service', :type => :class do + shared_examples 'containg service anchors' do + it { is_expected.to contain_anchor('jboss::service::begin') } + it { is_expected.to contain_anchor('jboss::service::end') } + it { is_expected.to contain_anchor('jboss::service::started') } + end + shared_examples 'containg class structure' do + it { is_expected.to contain_class 'jboss::internal::service' } + it { is_expected.to contain_class('jboss') } + it { is_expected.to contain_class('jboss::params') } + it { is_expected.to contain_class('jboss::internal::configuration') } + end + shared_examples 'containg service execs' do + it do + is_expected.to contain_exec('jboss::service::test-running'). + with( + :loglevel => 'emerg', + :command => 'tail -n 50 /var/log/wildfly/console.log && exit 1', + :unless => 'ps aux | grep wildfly | grep -vq grep', + :logoutput => true + ) + end + it do + is_expected.to contain_exec('jboss::service::restart'). + with( + :command => 'service wildfly stop ; pkill -9 -f "^java.*jboss" ; service wildfly start', + :refreshonly => true + ) + end + end + + context 'on RedHat os family' do + context 'on Docker container' do + let(:facts) do + Testing::RspecPuppet::SharedFacts.oraclelinux_facts( + :jboss_virtual => 'docker' + ) + end + it_behaves_like 'containg service anchors' + it_behaves_like 'containg service execs' + it_behaves_like 'containg class structure' + it { is_expected.to contain_service('wildfly'). + with( + :ensure => 'running', + :enable => nil, + :hasstatus => true, + :hasrestart => true + ) } + end + context 'on non-Docker machine' do + let(:facts) do + Testing::RspecPuppet::SharedFacts.oraclelinux_facts( + :jboss_virtual => 'phisycal' + ) + end + it_behaves_like 'containg service anchors' + it_behaves_like 'containg service execs' + it_behaves_like 'containg class structure' + it { is_expected.to contain_service('wildfly'). + with( + :ensure => 'running', + :enable => true, + :hasstatus => true, + :hasrestart => true + ) } + end + end + + context 'on Debian os family' do + context 'on Docker container' do + let(:facts) do + Testing::RspecPuppet::SharedFacts.ubuntu_facts( + :jboss_virtual => 'docker' + ) + end + it_behaves_like 'containg service anchors' + it_behaves_like 'containg service execs' + it_behaves_like 'containg class structure' + it { is_expected.to contain_service('wildfly'). + with( + :ensure => 'running', + :enable => nil, + :hasstatus => true, + :hasrestart => true + ) } + end + context 'on non-Docker machine' do + let(:facts) do + Testing::RspecPuppet::SharedFacts.ubuntu_facts( + :jboss_virtual => 'vmware' + ) + end + it_behaves_like 'containg service anchors' + it_behaves_like 'containg service execs' + it_behaves_like 'containg class structure' + it { is_expected.to contain_service('wildfly'). + with( + :ensure => 'running', + :enable => true, + :hasstatus => true, + :hasrestart => true + ) } + end + end +end diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb index e17ec64..edd93dd 100644 --- a/spec/classes/params_spec.rb +++ b/spec/classes/params_spec.rb @@ -3,5 +3,10 @@ describe 'jboss::params', :type => :class do it { is_expected.to compile } - -end \ No newline at end of file + it { is_expected.to contain_class 'jboss::params' } + it { is_expected.to contain_class 'jboss::internal::params' } + it { is_expected.to contain_class 'jboss::internal::quirks::autoinstall' } + it { is_expected.to contain_class 'jboss::internal::params::socketbinding' } + it { is_expected.to contain_class 'jboss::internal::params::memorydefaults' } + +end diff --git a/spec/defines/clientry_spec.rb b/spec/defines/clientry_spec.rb new file mode 100644 index 0000000..3de6d24 --- /dev/null +++ b/spec/defines/clientry_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper_puppet' + +describe 'jboss::clientry', :type => :define do + + shared_examples 'contain self' do + it do + is_expected.to contain_jboss_confignode(title).with({ + :ensure => 'present', + :path => 'profile/test' + }) + end + it { is_expected.to contain_jboss_confignode(title).that_requires('Anchor[jboss::package::end]') } + it do + is_expected.to contain_jboss__clientry(title).with({ + :ensure => 'present', + :path => 'profile/test', + }) + end + end + + context 'on RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + + let(:title) { 'test-clientry' } + let(:params) { { :path => 'profile/test', } } + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + + it_behaves_like containing_basic_class_structure + + it_behaves_like 'contain self' + end + + context 'on Debian os family' do + extend Testing::RspecPuppet::SharedExamples + + let(:title) { 'test-clientry' } + let(:params) { { :path => 'profile/test', } } + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + + it_behaves_like containing_basic_class_structure + + it_behaves_like 'contain self' + end +end diff --git a/spec/defines/datasource_spec.rb b/spec/defines/datasource_spec.rb index a0a8be5..50340a0 100644 --- a/spec/defines/datasource_spec.rb +++ b/spec/defines/datasource_spec.rb @@ -1,88 +1,162 @@ require 'spec_helper_puppet' describe 'jboss::datasource', :type => :define do - def merge_params(hash = {}) - hash.merge({ - :username => 'test-username', - :password => 'test-password', - :jdbcscheme => 'test-scheme', - :host => 'example.com', - :port => '1234', - :driver => { - 'name' => 'test-driver', - 'classname' => 'com.example.TestDriver', - 'modulename' => 'test-driver', - }, - }) - end - let(:title) { 'test-datasource' } - let(:params) { merge_params } - let(:facts) do - { - :osfamily => "RedHat", - :operatingsystem => "OracleLinux", - :'jboss::profile' => "domain", - :'jboss::controller' => "controller.example.com", - :concat_basedir => "/tmp/", - :jboss_product => 'wildfly', - :jboss_version => '8.2.0.Final', - } - end + context 'on RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + def merge_params(hash = {}) + hash.merge({ + :username => 'test-username', + :password => 'test-password', + :jdbcscheme => 'test-scheme', + :host => 'example.com', + :port => '1234', + :driver => { + 'name' => 'test-driver', + 'classname' => 'com.example.TestDriver', + 'modulename' => 'test-driver', + }, + }) + end - it { is_expected.to compile.with_all_deps } - it do - is_expected.to contain_jboss_jdbcdriver('test-driver'). - with_classname('com.example.TestDriver').with_modulename('test-driver') - end - it { is_expected.to contain_jboss_datasource('test-datasource') } - it { is_expected.to contain_jboss__datasource('test-datasource') } + let(:title) { 'test-datasource' } + let(:params) { merge_params } + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } - it do - is_expected.to contain_jboss_datasource('test-datasource'). - with_port(1234) - end - - it do - is_expected.to contain_jboss_datasource('test-datasource'). - with_xa(false) - end + it { is_expected.to compile.with_all_deps } + it_behaves_like containing_basic_class_structure + + it do + is_expected.to contain_jboss_jdbcdriver('test-driver'). + with_classname('com.example.TestDriver').with_modulename('test-driver') + end + it { is_expected.to contain_jboss_datasource('test-datasource') } + it { is_expected.to contain_jboss__datasource('test-datasource') } - context 'with option prepared-statements-cache-size set to 46' do - let(:options) do { - 'prepared-statements-cache-size' => 46 - } + it do + is_expected.to contain_jboss_datasource('test-datasource'). + with_port(1234) end - context 'in XA mode' do - let(:params) do - merge_params({ :options => options, :xa => true }) + + it do + is_expected.to contain_jboss_datasource('test-datasource'). + with_xa(false) + end + + context 'with option prepared-statements-cache-size set to 46' do + let(:options) do { + 'prepared-statements-cache-size' => 46 + } end - - it { is_expected.to contain_jboss_datasource('test-datasource').with_xa(true) } - it do is_expected.to contain_jboss_datasource('test-datasource').with_options({ - "validate-on-match"=>false, - "background-validation"=>false, - "share-prepared-statements"=>false, - "prepared-statements-cache-size"=>46, - "same-rm-override"=>true, - "wrap-xa-resource"=>true - }) + context 'in XA mode' do + let(:params) do + merge_params({ :options => options, :xa => true }) + end + + it { is_expected.to contain_jboss_datasource('test-datasource').with_xa(true) } + it do is_expected.to contain_jboss_datasource('test-datasource').with_options({ + "validate-on-match"=>false, + "background-validation"=>false, + "share-prepared-statements"=>false, + "prepared-statements-cache-size"=>46, + "same-rm-override"=>true, + "wrap-xa-resource"=>true + }) + end end + context 'in non-XA mode' do + let(:params) do + merge_params({ :options => options, :xa => false }) + end + + it { is_expected.to contain_jboss_datasource('test-datasource').with_xa(false) } + it do is_expected.to contain_jboss_datasource('test-datasource').with_options({ + "validate-on-match"=>false, + "background-validation"=>false, + "share-prepared-statements"=>false, + "prepared-statements-cache-size"=>46 + }) + end + end + end + end + + context 'on Ubuntu os family' do + extend Testing::RspecPuppet::SharedExamples + def merge_params(hash = {}) + hash.merge({ + :username => 'test-username', + :password => 'test-password', + :jdbcscheme => 'test-scheme', + :host => 'example.com', + :port => '1234', + :driver => { + 'name' => 'test-driver', + 'classname' => 'com.example.TestDriver', + 'modulename' => 'test-driver', + }, + }) + end + + let(:title) { 'test-datasource' } + let(:params) { merge_params } + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + + it { is_expected.to compile.with_all_deps } + it_behaves_like containing_basic_class_structure + + it do + is_expected.to contain_jboss_jdbcdriver('test-driver'). + with_classname('com.example.TestDriver').with_modulename('test-driver') + end + it { is_expected.to contain_jboss_datasource('test-datasource') } + it { is_expected.to contain_jboss__datasource('test-datasource') } + + it do + is_expected.to contain_jboss_datasource('test-datasource'). + with_port(1234) end - context 'in non-XA mode' do - let(:params) do - merge_params({ :options => options, :xa => false }) + + it do + is_expected.to contain_jboss_datasource('test-datasource'). + with_xa(false) + end + + context 'with option prepared-statements-cache-size set to 46' do + let(:options) do { + 'prepared-statements-cache-size' => 46 + } end - - it { is_expected.to contain_jboss_datasource('test-datasource').with_xa(false) } - it do is_expected.to contain_jboss_datasource('test-datasource').with_options({ - "validate-on-match"=>false, - "background-validation"=>false, - "share-prepared-statements"=>false, - "prepared-statements-cache-size"=>46 - }) + context 'in XA mode' do + let(:params) do + merge_params({ :options => options, :xa => true }) + end + + it { is_expected.to contain_jboss_datasource('test-datasource').with_xa(true) } + it do is_expected.to contain_jboss_datasource('test-datasource').with_options({ + "validate-on-match"=>false, + "background-validation"=>false, + "share-prepared-statements"=>false, + "prepared-statements-cache-size"=>46, + "same-rm-override"=>true, + "wrap-xa-resource"=>true + }) + end + end + context 'in non-XA mode' do + let(:params) do + merge_params({ :options => options, :xa => false }) + end + + it { is_expected.to contain_jboss_datasource('test-datasource').with_xa(false) } + it do is_expected.to contain_jboss_datasource('test-datasource').with_options({ + "validate-on-match"=>false, + "background-validation"=>false, + "share-prepared-statements"=>false, + "prepared-statements-cache-size"=>46 + }) + end end end end end - diff --git a/spec/defines/deploy_spec.rb b/spec/defines/deploy_spec.rb new file mode 100644 index 0000000..59902a9 --- /dev/null +++ b/spec/defines/deploy_spec.rb @@ -0,0 +1,74 @@ +require 'spec_helper_puppet' + +describe 'jboss::deploy', :type => :define do + + shared_examples 'containing class structure' do + it { is_expected.to contain_class('jboss') } + it { is_expected.to contain_class('jboss::internal::runtime::node') } + it { is_expected.to contain_jboss_deploy(title).with({ + :ensure => 'present', + :source => '/tmp/jboss.war' + }) } + end + + shared_examples 'containing self' do + it { is_expected.to contain_jboss__deploy(title).with({ + :ensure => 'present', + :jndi => title + }) } + end + + shared_examples 'raise error' do + it { is_expected.to raise_error(Puppet::Error, /Invalid file extension, module only supports: .jar, .war, .ear, .rar/) } + end + + context 'On RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + context 'valid runtime_name' do + let(:title) { 'test-deploy' } + let(:params) { { + :path => '/tmp/jboss.war', + :runtime_name => 'foobar-app.war'} + } + + it_behaves_like 'containing class structure' + it_behaves_like 'containing self' + end + + context 'invalid runtime name' do + let(:title) { 'test-deploy' } + let(:params) { { + :path => '/tmp/jboss.war', + :runtime_name => 'foobar-app'} + } + + it_behaves_like 'raise error' + end + + end + + context 'On Debian os family' do + extend Testing::RspecPuppet::SharedExamples + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + + context 'valid runtime_name' do + let(:title) { 'test-deploy' } + let(:params) { { :path => '/tmp/jboss.war', } } + + + it_behaves_like 'containing class structure' + it_behaves_like 'containing self' + end + + context 'invalid runtime_name' do + let(:title) { 'test-deploy' } + let(:params) { { + :path => '/tmp/jboss.war', + :runtime_name => 'foobar-app'} + } + + it_behaves_like 'raise error' + end + end +end diff --git a/spec/defines/interface_spec.rb b/spec/defines/interface_spec.rb new file mode 100644 index 0000000..572ff6f --- /dev/null +++ b/spec/defines/interface_spec.rb @@ -0,0 +1,164 @@ +require 'spec_helper_puppet' + +describe 'jboss::interface', :type => :define do + + shared_examples 'basic class structure' do + it { is_expected.to contain_class('jboss') } + it { is_expected.to contain_class('jboss::internal::augeas') } + it { is_expected.to contain_class('jboss::internal::runtime') } + end + + basic_bind_variables_list = [ + "inet-address", "link-local-address", + "loopback", "loopback-address", "multicast", + "nic", "nic-match", "point-to-point", "public-address", + "site-local-address", "subnet-match", "up", "virtual" + ] + legacy_bind_variables_list = [ "any-ipv4-address", "any-ipv6-address" ] + + let(:title) { 'test-interface' } + + let(:generic_params) {{ :any_address => 'true' }} + let(:any_addr_property) {{ 'any-address' => 'true' }} + let(:basic_bind_variables) { Hash[basic_bind_variables_list.map {|x| [x, :undef]}] } + let(:legacy_bind_variables) { Hash[legacy_bind_variables_list.map {|x| [x, :undef]}] } + + shared_examples 'completly working define' do + it { is_expected.to contain_jboss__interface(title) } + it { is_expected.to contain_augeas("ensure present interface #{title}") } + it { is_expected.to contain_augeas("interface #{title} set any-address") } + it { is_expected.to contain_jboss__internal__interface__foreach("#{title}:any-address") } + basic_bind_variables_list.each do |var| + it { is_expected.to contain_augeas("interface #{title} rm #{var}") } + it { is_expected.to contain_jboss__internal__interface__foreach("#{title}:#{var}") } + end + end + + shared_examples 'a define with properly configured interface' do + context 'with jboss_running => true and runasdomain => false parameters set' do + let(:facts) { generic_facts.merge({ :jboss_running => 'true' })} + let(:params) { generic_params.merge({ :runasdomain => 'false' })} + let(:pre_condition) { "class { jboss: product => '#{product}', version => '#{version}'}" } + + context 'with product => wildfly and version => 9.0.2.Final parameters set' do + let(:product) {'wildfly'} + let(:version) {'9.0.2.Final'} + + it { is_expected.to contain_jboss__clientry("/interface=#{title}").with_properties( + basic_bind_variables.merge(any_addr_property) + )} + end + context 'with product => wildfly and version => 8.2.1.Final parameters set' do + let(:product) {'wildfly'} + let(:version) {'8.2.1.Final'} + + it { is_expected.to contain_jboss__clientry("/interface=#{title}").with_properties( + basic_bind_variables.merge(legacy_bind_variables).merge(any_addr_property) + )} + end + context 'with product => jboss-eap and version => 7.0.0.Beta parameters set' do + let(:product) {'jboss-eap'} + let(:version) {'7.0.0.Beta'} + + it { is_expected.to contain_jboss__clientry("/interface=#{title}").with_properties( + basic_bind_variables.merge(any_addr_property) + )} + end + context 'with product => wildfly and version => 15.0.0.Final parameters set' do + let(:product) {'wildfly'} + let(:version) {'15.0.0.Final'} + + it { is_expected.to raise_error(Puppet::Error, /Unsupported version wildfly 15.0.0.Final/) } + end + end + + context 'with jboss_running => false and runasdomain => false parameters set' do + let(:facts) { generic_facts.merge({ :jboss_running => 'false' })} + let(:params) { generic_params.merge({ :runasdomain => 'false' })} + let(:pre_condition) { "class { jboss: product => '#{product}', version => '#{version}'}" } + + context 'with product => wildfly and version => 9.0.2.Final parameters set' do + let(:product) {'wildfly'} + let(:version) {'9.0.2.Final'} + + basic_bind_variables_list.each do |var| + it { is_expected.to contain_augeas("interface #{title} rm #{var}") } + it { is_expected.to contain_jboss__internal__interface__foreach("#{title}:#{var}").with_bind_variables( + basic_bind_variables.merge(any_addr_property) + )} + end + end + context 'with product => wildfly and version => 8.2.1.Final parameters set' do + let(:product) {'wildfly'} + let(:version) {'8.2.1.Final'} + + basic_bind_variables_list.each do |var| + it { is_expected.to contain_augeas("interface #{title} rm #{var}") } + it { is_expected.to contain_jboss__internal__interface__foreach("#{title}:#{var}").with_bind_variables( + basic_bind_variables.merge(legacy_bind_variables).merge(any_addr_property) + )} + end + legacy_bind_variables_list.each do |var| + it { is_expected.to contain_augeas("interface #{title} rm #{var}") } + it { is_expected.to contain_augeas("interface public rm #{var}") } + it { is_expected.to contain_jboss__internal__interface__foreach("#{title}:#{var}").with_bind_variables( + basic_bind_variables.merge(legacy_bind_variables).merge(any_addr_property) + )} + it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with_bind_variables( + basic_bind_variables.merge(legacy_bind_variables).merge(any_addr_property) + )} + end + end + context 'with product => jboss-eap and version => 7.0.0.Beta parameters set' do + let(:product) {'jboss-eap'} + let(:version) {'7.0.0.Beta'} + + basic_bind_variables_list.each do |var| + it { is_expected.to contain_augeas("interface #{title} rm #{var}") } + it { is_expected.to contain_jboss__internal__interface__foreach("#{title}:#{var}").with_bind_variables( + basic_bind_variables.merge(any_addr_property) + )} + end + end + end + end + + context 'On RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + let(:generic_facts) do + { + :operatingsystem => 'OracleLinux', + :osfamily => 'RedHat', + :ipaddress => '192.168.0.1', + :concat_basedir => '/root/concat', + :puppetversion => Puppet.version + } + end + let(:facts) {generic_facts} + let(:params) {generic_params} + + it_behaves_like 'basic class structure' + + it_behaves_like 'completly working define' + it_behaves_like 'a define with properly configured interface' + end + + context 'On Debian os family' do + extend Testing::RspecPuppet::SharedExamples + let(:generic_facts) do + { + :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :ipaddress => '192.168.0.1', + :concat_basedir => '/root/concat', + :lsbdistcodename => 'trusty', + :puppetversion => Puppet.version + } + end + let(:facts) {generic_facts} + let(:params) {generic_params} + + it_behaves_like 'completly working define' + it_behaves_like 'a define with properly configured interface' + end +end diff --git a/spec/defines/jmsqueue_spec.rb b/spec/defines/jmsqueue_spec.rb new file mode 100644 index 0000000..bb44559 --- /dev/null +++ b/spec/defines/jmsqueue_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper_puppet' + +describe 'jboss::jmsqueue', :type => :define do + shared_examples 'contains self' do + it { is_expected.to contain_jboss_jmsqueue(title).with({ + :ensure => 'present', + :entries => [ + 'queue/app-mails', + 'java:jboss/exported/jms/queue/app-mails'] + }) } + it { is_expected.to contain_jboss_jmsqueue(title). + that_requires('Anchor[jboss::package::end]') } + it { is_expected.to contain_jboss__jmsqueue(title).with({ + :ensure => 'present', + :entries => [ + 'queue/app-mails', + 'java:jboss/exported/jms/queue/app-mails'] + }) } + end + + context 'On RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-jmsqueue' } + let(:params) { { :entries => [ + 'queue/app-mails', + 'java:jboss/exported/jms/queue/app-mails'], } } + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + + it_behaves_like containing_basic_class_structure + it_behaves_like 'contains self' + end + + context 'On Debian os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-jmsqueue' } + let(:params) { { :entries => [ + 'queue/app-mails', + 'java:jboss/exported/jms/queue/app-mails'], } } + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + + it_behaves_like containing_basic_class_structure + it_behaves_like 'contains self' + end +end diff --git a/spec/defines/logging/async_spec.rb b/spec/defines/logging/async_spec.rb new file mode 100644 index 0000000..d258823 --- /dev/null +++ b/spec/defines/logging/async_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper_puppet' + +describe 'jboss::logging::async', :type => :define do + let(:title) { 'test-handler' } + let(:facts) { { + :osfamily => "RedHat", + :operatingsystem => "RedHat", + :concat_basedir => "/tmp/" + } } + + it { is_expected.to compile } + it { is_expected.to contain_jboss__logging__async(title) } + it { is_expected.to contain_jboss_confignode("/subsystem=logging/async-handler=#{title}") } + it do + is_expected.to contain_jboss__clientry("/subsystem=logging/async-handler=#{title}"). + with_ensure('present'). + with_properties({ + 'level' => 'INFO', + 'formatter' => '%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n', + 'subhandlers' => [ 'CONSOLE', 'FILE' ], + 'overflow-action' => 'BLOCK', + 'queue-length' => '1024', + }) + end +end diff --git a/spec/defines/logging/console_spec.rb b/spec/defines/logging/console_spec.rb new file mode 100644 index 0000000..d788082 --- /dev/null +++ b/spec/defines/logging/console_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_puppet' + +describe 'jboss::logging::console', :type => :define do + let(:title) { 'test-handler' } + let(:facts) { { + :osfamily => "RedHat", + :operatingsystem => "RedHat", + :concat_basedir => "/tmp/" + } } + + it { is_expected.to compile } + it { is_expected.to contain_jboss__logging__console(title) } + it { is_expected.to contain_jboss_confignode("/subsystem=logging/console-handler=#{title}") } + it do + is_expected.to contain_jboss__clientry("/subsystem=logging/console-handler=#{title}"). + with_ensure('present'). + with_properties({ + 'level' => 'INFO', + 'target' => 'System.out', + 'formatter' => '%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n', + }) + end +end diff --git a/spec/defines/logging/file_spec.rb b/spec/defines/logging/file_spec.rb new file mode 100644 index 0000000..d9b18c9 --- /dev/null +++ b/spec/defines/logging/file_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper_puppet' + +describe 'jboss::logging::file', :type => :define do + let(:title) { 'test-handler' } + let(:facts) { { + :osfamily => "RedHat", + :operatingsystem => "RedHat", + :concat_basedir => "/tmp/" + } } + + it { is_expected.to compile } + it { is_expected.to contain_jboss__logging__file(title) } + it { is_expected.to contain_jboss_confignode("/subsystem=logging/periodic-rotating-file-handler=#{title}") } + it do + is_expected.to contain_jboss__clientry("/subsystem=logging/periodic-rotating-file-handler=#{title}"). + with_ensure('present'). + with_properties({ + 'level' => 'INFO', + 'formatter' => '%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n', + 'suffix' => '.yyyy-MM-dd', + 'file' => { + 'relative-to' => 'jboss.server.log.dir', + 'path' => 'server.log', + } + }) + end +end diff --git a/spec/defines/logging/logger_spec.rb b/spec/defines/logging/logger_spec.rb new file mode 100644 index 0000000..f3ca238 --- /dev/null +++ b/spec/defines/logging/logger_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper_puppet' + +describe 'jboss::logging::logger', :type => :define do + let(:title) { 'test-handler' } + let(:facts) { { + :osfamily => "RedHat", + :operatingsystem => "RedHat", + :concat_basedir => "/tmp/" + } } + + it { is_expected.to compile } + it { is_expected.to contain_jboss__logging__logger(title) } + it { is_expected.to contain_jboss_confignode("/subsystem=logging/logger=#{title}") } + it do + is_expected.to contain_jboss__clientry("/subsystem=logging/logger=#{title}"). + with_ensure('present'). + with_properties({ + 'level' => 'INFO', + 'use-parent-handlers' => true, + }) + end +end diff --git a/spec/defines/logging/root_spec.rb b/spec/defines/logging/root_spec.rb new file mode 100644 index 0000000..ceaa2b2 --- /dev/null +++ b/spec/defines/logging/root_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper_puppet' + +describe 'jboss::logging::root', :type => :define do + let(:title) { 'test-handler' } + let(:facts) { { + :osfamily => "RedHat", + :operatingsystem => "RedHat", + :concat_basedir => "/tmp/" + } } + + it { is_expected.to compile } + it { is_expected.to contain_jboss__logging__root(title) } + it { is_expected.to contain_jboss_confignode("/subsystem=logging/root-logger=#{title}") } + it do + is_expected.to contain_jboss__clientry("/subsystem=logging/root-logger=#{title}"). + with_ensure('present'). + with_properties({ + 'level' => 'INFO', + 'handlers' => [ 'CONSOLE', 'FILE' ], + }) + end +end diff --git a/spec/defines/logging/syslog_spec.rb b/spec/defines/logging/syslog_spec.rb index 6d64421..5f33314 100644 --- a/spec/defines/logging/syslog_spec.rb +++ b/spec/defines/logging/syslog_spec.rb @@ -12,7 +12,9 @@ } } it { is_expected.to compile } - it do + it { is_expected.to contain_jboss__logging__syslog(title) } + it { is_expected.to contain_jboss_confignode("/subsystem=logging/syslog-handler=#{title}") } + it do is_expected.to contain_jboss__clientry("/subsystem=logging/syslog-handler=#{title}"). with_ensure('present'). with_properties({ @@ -24,4 +26,3 @@ }) end end - diff --git a/spec/defines/module_spec.rb b/spec/defines/module_spec.rb new file mode 100644 index 0000000..74e7b19 --- /dev/null +++ b/spec/defines/module_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper_puppet' + +describe 'jboss::module', :type => :define do + shared_examples 'contains self' do + it { is_expected.to contain_class('jboss') } + + it { is_expected.to contain_jboss__internal__module__assemble(title).with({ + :layer => 'jdbc', + :artifacts => ["https://jdbc.postgresql.org/download/postgresql-9.4-1204.jdbc41.jar"], + :dependencies => ["javax.transaction.api", "javax.api"] + })} + it { is_expected.to contain_jboss__module(title).with({ + :layer => 'jdbc', + :artifacts => ["https://jdbc.postgresql.org/download/postgresql-9.4-1204.jdbc41.jar"] + }) } + end + + context 'On RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-module' } + let(:params) do + { + :layer => 'jdbc', + :artifacts => ['https://jdbc.postgresql.org/download/postgresql-9.4-1204.jdbc41.jar'], + :dependencies => ['javax.transaction.api', 'javax.api'] + } + end + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + + it_behaves_like 'contains self' + end + + context 'On Debian os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-module' } + let(:params) do + { + :layer => 'jdbc', + :artifacts => ['https://jdbc.postgresql.org/download/postgresql-9.4-1204.jdbc41.jar'], + :dependencies => ['javax.transaction.api', 'javax.api'] + } + end + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + + it_behaves_like 'contains self' + end +end diff --git a/spec/defines/registerlayer_spec.rb b/spec/defines/registerlayer_spec.rb new file mode 100644 index 0000000..2a05aea --- /dev/null +++ b/spec/defines/registerlayer_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_puppet' + +describe 'jboss::internal::module::registerlayer', :type => :define do + let(:title) { 'testlayer' } + let(:params) { { :layer => title, } } + let(:pre_condition) { "class { jboss: product => '#{product}', version => '#{version}', jboss_user => '#{user}', jboss_group => '#{group}', install_dir => '#{dir}' }" } + let(:product) {'wildfly'} + let(:version) {'9.0.2.Final'} + let(:dir) {'/jboss'} + let(:user) {'test-user'} + let(:group) {'test-group'} + let(:facts) do + { + :osfamily => 'RedHat', + :operatingsystem => 'OracleLinux', + :concat_basedir => '/tmp/' + } + end + + it { is_expected.to compile } + it { is_expected.to contain_class 'jboss' } + it { is_expected.to contain_jboss__internal__module__registerlayer("#{title}") } + it { is_expected.to contain_exec("jboss::module::layer::#{title}").with({ + :command => "awk -F'=' 'BEGIN {ins = 0} /^layers=/ { ins = ins + 1; print \$1=testlayer,\$2 } END {if(ins == 0) print \"layers=testlayer,base\"}' > #{dir}/#{product}-#{version}/modules/layers.conf", + :unless => "egrep -e '^layers=.*testlayer.*' #{dir}/#{product}-#{version}/modules/layers.conf", + :user => 'test-user' + }) } + it { + is_expected.to contain_file("#{dir}/#{product}-#{version}/modules/system/layers/#{title}").with({ + :ensure => 'directory', + :owner => 'test-user', + :group => 'test-group', + :mode => '0640' + }) } +end diff --git a/spec/defines/resourceadapter_spec.rb b/spec/defines/resourceadapter_spec.rb new file mode 100644 index 0000000..6c1dd2f --- /dev/null +++ b/spec/defines/resourceadapter_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper_puppet' + +describe 'jboss::resourceadapter', :type => :define do + shared_examples 'contains self' do + + it { is_expected.to contain_jboss_resourceadapter(title).with({ + :ensure => 'present', + :archive => 'jca-filestore.rar' + })} + it { is_expected.to contain_jboss_resourceadapter(title). + that_requires('Anchor[jboss::package::end]') } + it { is_expected.to contain_jboss__resourceadapter(title).with({ + :ensure => 'present', + :archive => 'jca-filestore.rar', + :transactionsupport => 'LocalTransaction', + :classname => 'org.example.jca.FileSystemConnectionFactory', + }) } + end + + context 'On RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-resourceadapter' } + let(:params) do + { + :jndiname => 'java:/jboss/jca/photos', + :archive => 'jca-filestore.rar', + :transactionsupport => 'LocalTransaction', + :classname => 'org.example.jca.FileSystemConnectionFactory', + } + end + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + + it_behaves_like containing_basic_class_structure + it_behaves_like 'contains self' + end + + context 'On Debian os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-resourceadapter' } + let(:params) do + { + :jndiname => 'java:/jboss/jca/photos', + :archive => 'jca-filestore.rar', + :transactionsupport => 'LocalTransaction', + :classname => 'org.example.jca.FileSystemConnectionFactory', + } + end + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + + it_behaves_like containing_basic_class_structure + it_behaves_like 'contains self' + end +end diff --git a/spec/defines/securitydomain_spec.rb b/spec/defines/securitydomain_spec.rb new file mode 100644 index 0000000..a66c3a1 --- /dev/null +++ b/spec/defines/securitydomain_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper_puppet' + +describe 'jboss::securitydomain', :type => :define do + + shared_examples 'contains class structure' do + it { is_expected.to contain_class('jboss') } + it { is_expected.to contain_class('jboss::internal::service') } + it { is_expected.to contain_class('jboss::internal::runtime::node') } + it do + is_expected.to contain_jboss_securitydomain(title).with({ + :ensure => 'present', + :controller => '127.0.0.1', + }) + end + end + + shared_examples 'contains self' do + it { is_expected.to contain_jboss__securitydomain('test-securitydomain') } + end + + context 'On RedHat os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-securitydomain' } + let(:params) {{ + :controller => '127.0.0.1' + } + } + let(:facts) { Testing::RspecPuppet::SharedFacts.oraclelinux_facts } + + it_behaves_like 'contains class structure' + it_behaves_like 'contains self' + + end + + context 'On Debian os family' do + extend Testing::RspecPuppet::SharedExamples + let(:title) { 'test-securitydomain' } + let(:params) {{ + :controller => '127.0.0.1' + } + } + let(:facts) { Testing::RspecPuppet::SharedFacts.ubuntu_facts } + + it_behaves_like 'contains class structure' + it_behaves_like 'contains self' + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cadf4b8..5b1ca18 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,6 +44,14 @@ # do nothing end +module Testing + module Mock end +end + +require 'puppet_x/coi/jboss' +require 'testing/mock/mocked_execution_state_wrapper' +require 'testing/mock/mocked_shell_executor' + require 'rspec-puppet' RSpec.configure do |c| @@ -67,5 +75,3 @@ PuppetlabsSpec::Files.cleanup end end - -require 'puppet_x/coi/jboss' diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 5397f7d..011750e 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -10,10 +10,10 @@ foss_opts = { :default_action => 'gem_install' } foss_opts[:version] = puppetver unless puppetver.nil? foss_opts[:facter_version] = facterver unless facterver.nil? - + if default.is_pe? install_pe - else + else install_puppet foss_opts end @@ -37,6 +37,12 @@ UNSUPPORTED_PLATFORMS = ['AIX','windows','Solaris', 'Suse'] +module Testing + module Acceptance end +end +require 'testing/acceptance/cleaner' +require 'testing/acceptance/smoke_test_reader' + RSpec.configure do |c| # Project root proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) @@ -44,15 +50,14 @@ # Configure all nodes in nodeset c.before :suite do # Install module and dependencies - install_dev_puppet_module(:source => proj_root, :module_name => 'jboss') - hosts.each do |host| on host, "/bin/touch #{default['puppetpath']}/hiera.yaml" on host, 'chmod 755 /root' - on host, puppet('module','install','puppetlabs-stdlib', '--version', '3.2.0'), { :acceptable_exit_codes => [0,1] } - on host, puppet('module','install','puppetlabs-java', '--version', '1.3.0'), { :acceptable_exit_codes => [0,1] } - on host, puppet('module','install','puppetlabs-concat', '--version', '1.0.0'), { :acceptable_exit_codes => [0,1] } + # Installs module for dependencies and then removes it + on host, puppet('module','install','coi/jboss'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module','uninstall','coi/jboss'), { :acceptable_exit_codes => [0,1] } end - + install_dev_puppet_module(:source => proj_root, :module_name => 'jboss') + hosts.each { |host| on host, puppet('module', 'list'), { :acceptable_exit_codes => [0,1] } } end -end \ No newline at end of file +end diff --git a/spec/spec_helper_puppet.rb b/spec/spec_helper_puppet.rb index 8d74cb0..2d41024 100644 --- a/spec/spec_helper_puppet.rb +++ b/spec/spec_helper_puppet.rb @@ -1,5 +1,10 @@ $executing_puppet = true require 'spec_helper' +module Testing + module RspecPuppet end +end +require 'testing/rspec_puppet/shared_facts' +require 'testing/rspec_puppet/shared_examples' at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/testing/acceptance/cleaner.rb b/spec/testing/acceptance/cleaner.rb new file mode 100644 index 0000000..524f50c --- /dev/null +++ b/spec/testing/acceptance/cleaner.rb @@ -0,0 +1,10 @@ +module Testing::Acceptance::Cleaner + def remove_jboss_installation(serv) + shell "service #{serv} stop" + rm_sprecs = [ + '/usr/lib', '/etc', '/etc/init.d', + '/etc/sysconfig', '/etc/default', '/var/log' + ].map { |e| "#{e}/#{serv}*" }.join(' ') + shell "rm -rf #{rm_sprecs} /etc/jboss-as /etc/profile.d/jboss.sh" + end +end diff --git a/spec/testing/acceptance/smoke_test_reader.rb b/spec/testing/acceptance/smoke_test_reader.rb new file mode 100644 index 0000000..d3e699f --- /dev/null +++ b/spec/testing/acceptance/smoke_test_reader.rb @@ -0,0 +1,18 @@ +module Testing::Acceptance::SmokeTestReader + class << self + def smoke_pp(pp_symbol) + path = smokedir.join(pp_symbol.to_s.gsub(/::/, '/') + '.pp') + path.read + end + + private + + def smokedir + rootdir.join('tests') + end + + def rootdir + Pathname.new(__FILE__).parent.parent.parent.parent.realpath + end + end +end diff --git a/spec/testing/files/evaluated.txt b/spec/testing/files/evaluated.txt new file mode 100644 index 0000000..8c2506d --- /dev/null +++ b/spec/testing/files/evaluated.txt @@ -0,0 +1,63 @@ +{ + "outcome" => "success", + "result" => { + "deep-copy-subject-mode" => false, + "vault" => undefined, + "security-domain" => { + "jboss-web-policy" => { + "acl" => undefined, + "audit" => undefined, + "authentication" => undefined, + "cache-type" => "default", + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined, + "authorization" => {"classic" => {"policy-modules" => [{ + "code" => "Delegating", + "flag" => "required", + "module-options" => undefined + }]}} + }, + "other" => { + "acl" => undefined, + "audit" => undefined, + "authorization" => undefined, + "cache-type" => "default", + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined, + "authentication" => {"classic" => {"login-modules" => [ + { + "code" => "Remoting", + "flag" => "optional", + "module-options" => [("password-stacking" => "useFirstPass")] + }, + { + "code" => "RealmUsersRoles", + "flag" => "required", + "module-options" => [ + ("usersProperties" => "$(jboss.server.config.dir)/application-users.properties"), + ("rolesProperties" => "$(jboss.server.config.dir)/application-roles.properties"), + ("realm" => "ApplicationRealm"), + ("password-stacking" => "useFirstPass") + ] + } + ]}} + }, + "jboss-ejb-policy" => { + "acl" => undefined, + "audit" => undefined, + "authentication" => undefined, + "cache-type" => "default", + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined, + "authorization" => {"classic" => {"policy-modules" => [{ + "code" => "Delegating", + "flag" => "required", + "module-options" => undefined + }]}} + } + } + } + } diff --git a/spec/testing/mock/mocked_execution_state_wrapper.rb b/spec/testing/mock/mocked_execution_state_wrapper.rb new file mode 100644 index 0000000..2cd42ec --- /dev/null +++ b/spec/testing/mock/mocked_execution_state_wrapper.rb @@ -0,0 +1,35 @@ +require 'spec_helper' +require 'ostruct' +class Testing::Mock::ExecutionStateWrapper < Puppet_X::Coi::Jboss::Internal::ExecutionStateWrapper + def initialize + @commands = {} + @last_excuted_command = nil + end + + def register_command(command, expected_status, expected_lines, expected_result) + execution_state = Puppet_X::Coi::Jboss::Internal::State::ExecutionState.new(expected_result, + expected_status, + expected_lines, + command + ) + @commands[command] = execution_state + end + + def execute(_cmd, jbosscmd, _environment) + get_command_outcome(jbosscmd) + @last_excuted_command = jbosscmd + @commands[jbosscmd] + end + + def verify_commands_executed + @commands.each do |command, outcome| + raise ArgumentError, "Command #{command} was not executed but was expected" unless outcome[:executed] + end + end + + private + + def get_command_outcome(command) + raise ArgumentError, "Commmand #{command} has not been registered in mocked execution stack" unless @commands.include? command + end +end diff --git a/spec/testing/mock/mocked_shell_executor.rb b/spec/testing/mock/mocked_shell_executor.rb new file mode 100644 index 0000000..7f95530 --- /dev/null +++ b/spec/testing/mock/mocked_shell_executor.rb @@ -0,0 +1,22 @@ +require 'ostruct' +class Testing::Mock::MockedShellExecutor + def initialize + @commands = {} + @last_exetuded_command = nil + end + def register_command(cmd, output, existstatus, success) + result = OpenStruct.new(:exitstatus => existstatus, :success? => success) + @last_exetuded_command = result + @commands[cmd] = output + end + + def run_command(cmd) + raise ArgumentError, "Commmand #{cmd} has not been registered in mocked execution stack" unless @commands.include? cmd + result = @commands[cmd] + result[cmd] + end + + def child_status + @last_exetuded_command + end +end diff --git a/spec/testing/rspec_puppet/shared_examples.rb b/spec/testing/rspec_puppet/shared_examples.rb new file mode 100644 index 0000000..e0fcf2d --- /dev/null +++ b/spec/testing/rspec_puppet/shared_examples.rb @@ -0,0 +1,86 @@ +module Testing::RspecPuppet::SharedExamples + DEFAULT_VERSION = '9.0.2.Final' + DEFAULT_PRODUCT = 'wildfly' + DEFAULT_WITH = [ + :anchors, + :interfaces, + :packages + ] + DEFAULT_OPTIONS = { + :product => DEFAULT_PRODUCT, + :version => DEFAULT_VERSION, + :with => DEFAULT_WITH + } + + + def containing_basic_class_structure + name = "containing basic class structure" + shared_examples(name) do + it { is_expected.to compile } + it { is_expected.to contain_class 'jboss' } + it { is_expected.to contain_class 'jboss::internal::service' } + it { is_expected.to contain_class 'jboss::internal::runtime::node' } + end + name + end + + def common_anchors + anchor_list = [ + "begin", "end", "configuration::begin", "configuration::end", + "installed", "package::begin", "package::end", + "service::begin", "service::end", "service::started"].map {|item| "jboss::#{item}"} + name = 'having common anchors' + shared_examples(name) do + anchor_list.each do |item| + it { is_expected.to contain_anchor("#{item}") } + end + end + name + end + + def common_interfaces(version = DEFAULT_VERSION, product = DEFAULT_PRODUCT) + basic_bind_variables_list = [ + "inet-address", "link-local-address", + "loopback", "loopback-address", "multicast", + "nic", "nic-match", "point-to-point", "public-address", + "site-local-address", "subnet-match", "up", "virtual" ] + name = 'common interfaces' + shared_examples(name) do + it { is_expected.to contain_class 'jboss::internal::configure::interfaces' } + it { is_expected.to contain_jboss__interface('public').with({ + :ensure => 'present', + :inet_address => nil + }) } + it { is_expected.to contain_augeas('ensure present interface public').with({ + :context => "/files/usr/lib/#{product}-#{version}/standalone/configuration/standalone-full.xml/", + :changes => "set server/interfaces/interface[last()+1]/#attribute/name public", + :onlyif => "match server/interfaces/interface[#attribute/name='public'] size == 0" + }) } + it { is_expected.to contain_augeas('interface public set any-address').with({ + :context => "/files/usr/lib/#{product}-#{version}/standalone/configuration/standalone-full.xml/", + :changes => "set server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value 'true'", + :onlyif => "get server/interfaces/interface[#attribute/name='public']/any-address/#attribute/value != 'true'" + }) } + it { is_expected.to contain_jboss__internal__interface__foreach("public:any-address").with({ + :cfg_file => "/usr/lib/#{product}-#{version}/standalone/configuration/standalone-full.xml", + :path => 'server/interfaces' + }) } + it { is_expected.to contain_service(product).with({ + :ensure => 'running', + :enable => true + }) } + basic_bind_variables_list.each do |var| + it { is_expected.to contain_augeas("interface public rm #{var}").with({ + :context => "/files/usr/lib/#{product}-#{version}/standalone/configuration/standalone-full.xml/", + :changes => "rm server/interfaces/interface[#attribute/name='public']/#{var}", + :onlyif => "match server/interfaces/interface[#attribute/name='public']/#{var} size != 0" + }) } + it { is_expected.to contain_jboss__internal__interface__foreach("public:#{var}").with({ + :cfg_file => "/usr/lib/#{product}-#{version}/standalone/configuration/standalone-full.xml", + :path => 'server/interfaces' + }) } + end + end + name + end +end diff --git a/spec/testing/rspec_puppet/shared_facts.rb b/spec/testing/rspec_puppet/shared_facts.rb new file mode 100644 index 0000000..3a0ba16 --- /dev/null +++ b/spec/testing/rspec_puppet/shared_facts.rb @@ -0,0 +1,40 @@ +class Testing::RspecPuppet::SharedFacts + DEFAULT_IP = '192.168.0.1' + DEFAULT_CONCAT_DIR = '/root/concat' + + DEFAULT_ORACLELINUX_FACTS = { + :operatingsystem => 'OracleLinux', + :osfamily => 'RedHat', + :ipaddress => DEFAULT_IP, + :concat_basedir => DEFAULT_CONCAT_DIR, + :operatingsystemrelease => '6.7', + :operatingsystemmajrelease => '6', + :puppetversion => Puppet.version.to_s, + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' + } + DEFAULT_UBUNTU_RELEASE = '14.04' + DEFAULT_UBUNTU_FACTS = { + :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :ipaddress => DEFAULT_IP, + :concat_basedir => DEFAULT_CONCAT_DIR, + :operatingsystemmajrelease => DEFAULT_UBUNTU_RELEASE, + :operatingsystemrelease => DEFAULT_UBUNTU_RELEASE, + :lsbdistcodename => 'trusty', + :lsbdistdescription => 'Ubuntu 14.04.3 LTS', + :lsbdistid => 'Ubuntu', + :lsbdistrelease => DEFAULT_UBUNTU_RELEASE, + :lsbmajdistrelease => DEFAULT_UBUNTU_RELEASE, + :puppetversion => Puppet.version.to_s, + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' + } + class << self + def ubuntu_facts(override = {}) + DEFAULT_UBUNTU_FACTS.merge(override) + end + + def oraclelinux_facts(override = {}) + DEFAULT_ORACLELINUX_FACTS.merge(override) + end + end +end diff --git a/spec/unit/facter/facts_spec.rb b/spec/unit/facter/facts_spec.rb new file mode 100644 index 0000000..0f73ef3 --- /dev/null +++ b/spec/unit/facter/facts_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +describe Puppet_X::Coi::Jboss::FactsRefresher do + context 'basic test to check if fact is deleted' do + before :each do + fct = Facter.add(:test_fact) { setcode { 'test value' } } + end + + after :each do + fct = Facter.fact :test_fact + fct.instance_variable_set(:@value, nil) + fct.instance_variable_set(:@resolves, []) + end + + describe '#delete_resolves' do + subject { described_class.delete_resolves(fact) } + + context 'delete selfmade fact' do + + after :each do + fct = Facter.fact fact + facter_value = fct.instance_variable_get(:@resolves) + expect(facter_value).to eq([]) + end + + let(:fact) { :jboss_fact } + it { expect(subject).to eq([]) } + end + end + + describe '#delete value' do + subject { described_class.delete_value(fact) } + + context '#delete_value selfmade fact' do + + after :each do + fct = Facter.fact fact + facter_value = fct.instance_variable_get(:@value) + expect(facter_value).to eq({}) + end + + let(:fact) { :jboss_fact } + it { expect(subject).to eq({}) } + end + end + end + + context 'tests for refreshing facts' do + describe '#refresh_facts' do + subject { described_class.refresh_facts(facts) } + + context 'refresh facts from correct list of facts' do + before :each do + expect(Facter).to receive(:list).and_return(['test_fact', 'jboss_test_fact']) + expect(Puppet_X::Coi::Jboss::Configuration).to receive(:read).at_least(1).times.and_return({ :jboss_test_fact => 'test' }) + end + let(:facts) { [:jboss_test_fact] } + it { expect(subject).to eq([:jboss_test_fact]) } + end + end + end +end diff --git a/spec/unit/facter/jboss_virtual_spec.rb b/spec/unit/facter/jboss_virtual_spec.rb new file mode 100644 index 0000000..9bdabbf --- /dev/null +++ b/spec/unit/facter/jboss_virtual_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe 'jboss_virtual', :type => :fact do + let(:lines) do + lines = <<-EOS + 11:name=systemd:/ + 10:hugetlb:/docker/715a4a76b43c6d67a4900f2cd3f718191671c19b09699c0a16a4fbc48bc69004 + 9:perf_event:/docker/715a4a76b43c6d67a4900f2cd3f718191671c19b09699c0a16a4fbc48bc69004 + 8:blkio:/docker/715a4a76b43c6d67a4900f2cd3f718191671c19b09699c0a16a4fbc48bc69004 + 7:freezer:/docker/715a4a76b43c6d67a4900f2cd3f718191671c19b09699c0a16a4fbc48bc69004 + 6:devices:/docker/715a4a76b43c6d67a4900f2cd3f718191671c19b09699c0a16a4fbc48bc69004 + 5:memory:/docker/715a4a76b43c6d67a4900f2cd3f718191671c19b09699c0a16a4fbc48bc69004 + 4:cpuacct:/docker/715a4a76b43c6d67a4900f2cd3f718191671c19b09699c0a16a4fbc48bc69004 + 3:cpu:/docker/715a4a76b43c6d67a4900f2cd3f718191671c19b09699c0a16a4fbc48bc69004 + 2:cpuset:/docker/715a4a76b43c6d67a4900f2cd3f718191671c19b09699c0a16a4fbc48bc69004 + EOS + lines.split(/\n/) + end + let(:docker_pathname) { double(:readable? => true, :readlines => lines) } + let(:nondocker_pathname) { double(:readable? => true, :readlines => []) } + before(:each) do + allow(Facter).to receive(:value).with(:jboss_virtual).and_call_original + allow(Facter).to receive(:value).with(:virtual).and_return('physical') + end + after :each do + fct = Facter.fact :jboss_virtual + fct.instance_variable_set(:@value, nil) + end + subject { Facter.value(:jboss_virtual) } + context 'on Docker container' do + before(:each) do + allow(Pathname).to receive(:new).and_call_original + allow(Pathname).to receive(:new).with('/proc/1/cgroup').and_return(docker_pathname) + end + it { expect { subject }.not_to raise_error } + it { expect(subject).to eq('docker') } + end + context 'on non-Docker machine' do + before(:each) do + allow(Pathname).to receive(:new).and_call_original + allow(Pathname).to receive(:new).with('/proc/1/cgroup').and_return(nondocker_pathname) + end + it { expect { subject }.not_to raise_error } + it { expect(subject).to eq('physical') } + end +end diff --git a/spec/unit/internal/execution_state_wrapper_spec.rb b/spec/unit/internal/execution_state_wrapper_spec.rb new file mode 100644 index 0000000..a5cdcb4 --- /dev/null +++ b/spec/unit/internal/execution_state_wrapper_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe Puppet_X::Coi::Jboss::Internal::ExecutionStateWrapper do + context 'execute method' do + let(:mocked_shell_executor) { Testing::Mock::MockedShellExecutor.new } + + let(:instance) { described_class.new(mocked_shell_executor) } + subject { instance.execute(cmd, jbosscmd, environment) } + + context 'destroy method' do + before :each do + mocked_shell_executor.register_command( + '/profille=full-ha/subsystem=securitydomain:remove()', + 'asdads', + true, + true) + end + let(:cmd) { '/profille=full-ha/subsystem=securitydomain:remove()' } + let(:jbosscmd) { 'asd' } + let(:environment) { { :password => 'password' } } + it { expect(subject.success).to eq(true) } + end + + context 'read method' do + before :each do + mocked_shell_executor.register_command( + '/profille=full-ha/subsystem=securitydomain:read-resource(recursive=true)', + 'result => succes, asdadass', + true, + true) + end + let(:cmd) { '/profille=full-ha/subsystem=securitydomain:read-resource(recursive=true)' } + let(:jbosscmd) { 'asd' } + let(:environment) { { :password => 'password' } } + it { expect(subject.success).to eq(true) } + end + end +end diff --git a/spec/unit/internal/jboss_systemexec_spec.rb b/spec/unit/internal/jboss_systemexec_spec.rb new file mode 100644 index 0000000..1f8b822 --- /dev/null +++ b/spec/unit/internal/jboss_systemexec_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' +require 'os' + +describe Puppet_X::Coi::Jboss::Internal::Executor::ShellExecutor do + describe '#run_command' do + let(:instance) { described_class.new } + subject { instance.run_command(cmd) } + + context 'with correct command' do + if OS.windows? + let(:cmd) { 'dir' } + it { expect { subject }.to_not raise_error } + elsif OS.osx? + let(:cmd) { 'ls' } + it { expect { subject }.to_not raise_error } + elsif OS.linux? + let(:cmd) { 'ls' } + it { expect { subject }.to_not raise_error } + end + end + end + + describe '#child_status' do + before :each do + instance.instance_variable_set(:@result, 'mocked result') + end + + let(:instance) { described_class.new } + subject { instance.child_status } + + it { expect(subject).to be_truthy } + end +end diff --git a/spec/unit/internal/logic_creator_spec.rb b/spec/unit/internal/logic_creator_spec.rb new file mode 100644 index 0000000..cc841c7 --- /dev/null +++ b/spec/unit/internal/logic_creator_spec.rb @@ -0,0 +1,98 @@ +require "spec_helper" + +describe Puppet_X::Coi::Jboss::Internal::LogicCreator do + + let(:resource) do + { + :name => 'testing', + :code => 'Database', + :codeflag => true, + :moduleoptions => { + 'principalsQuery' => "select 'password' from users u where u.login = ?", + 'hashUserPassword' => false + } + } + end + let(:system_executor) {Puppet_X::Coi::Jboss::Internal::Executor::ShellExecutor.new } + let(:system_runner) { Puppet_X::Coi::Jboss::Internal::ExecutionStateWrapper.new(system_executor) } + let(:runner) { Puppet_X::Coi::Jboss::Internal::CliExecutor.new(system_runner) } + let(:compilator) { Puppet_X::Coi::Jboss::Internal::CommandCompilator.new } + let(:destroyer) { Puppet_X::Coi::Jboss::Internal::SecurityDomainDestroyer.new(runner, compilator, resource) } + let(:auditor) { Puppet_X::Coi::Jboss::Internal::SecurityDomainAuditor.new(resource, runner, compilator, destroyer) } + + let(:instance) { described_class.new(auditor, resource, provider, compilator) } + subject { instance.decide } + + describe 'pre wildfly provider' do + let(:provider) { Puppet_X::Coi::Jboss::Provider::SecurityDomain::PreWildFlyProvider.new(resource, compilator) } + context '#calculate_state with everything set to true' do + before(:each) do + state = Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState.new(true, true, true) + expect(auditor).to receive(:fetch_securtydomain_state).and_return(state) + end + it { expect(subject).to eq([]) } + end + + context '#calculate_state with everything false' do + before(:each) do + state = Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState.new + expect(auditor).to receive(:fetch_securtydomain_state).and_return(state) + end + it { expect(subject).to eq([["Security Domain Cache Type", "/subsystem=security/security-domain=testing:add(cache-type=default)"], ["Security Domain Login Modules", "/subsystem=security/security-domain=testing/authentication=classic:add(login-modules=[{code=>\"Database\",flag=>true,module-options=>[\"hashUserPassword\"=>false,\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\"]}])"]]) } + end + + context '#calculate_state with cache type and authentication set' do + before(:each) do + state = Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState.new(true, true) + expect(auditor).to receive(:fetch_securtydomain_state).and_return(state) + end + it { expect(subject).to eq([["Security Domain Login Modules", "/subsystem=security/security-domain=testing/authentication=classic:add(login-modules=[{code=>\"Database\",flag=>true,module-options=>[\"hashUserPassword\"=>false,\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\"]}])"]])} + end + + context '#calculate_state with cache type' do + before(:each) do + state = Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState.new(true) + expect(auditor).to receive(:fetch_securtydomain_state).and_return(state) + end + it { expect(subject).to eq([["Security Domain Login Modules", "/subsystem=security/security-domain=testing/authentication=classic:add(login-modules=[{code=>\"Database\",flag=>true,module-options=>[\"hashUserPassword\"=>false,\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\"]}])"]]) } + end + + end + + describe 'post wildfly provider' do + let(:provider) { Puppet_X::Coi::Jboss::Provider::SecurityDomain::PostWildFlyProvider.new(resource, compilator) } + + context '#calculate state with everything set' do + before(:each) do + state = Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState.new(true, true, true) + expect(auditor).to receive(:fetch_securtydomain_state).and_return(state) + end + it { expect(subject).to eq([]) } + end + + context '#calculate state with everything not set' do + before(:each) do + state = Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState.new + expect(auditor).to receive(:fetch_securtydomain_state).and_return(state) + end + it { expect(subject).to eq([["Security Domain Cache Type", "/subsystem=security/security-domain=testing:add(cache-type=default)"], ["Security Domain Authentication", "/subsystem=security/security-domain=testing/authentication=classic:add()"], ["Security Domain Login Modules", "/subsystem=security/security-domain=testing/authentication=classic/login-module=testing:add(code=\"Database\",flag=true,module-options=[(\"hashUserPassword\"=>false),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\")])"]]) } + + end + + context '#calculate_state with cache type and authentication set' do + before(:each) do + state = Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState.new(true, true) + expect(auditor).to receive(:fetch_securtydomain_state).and_return(state) + end + it { expect(subject).to eq([["Security Domain Login Modules", "/subsystem=security/security-domain=testing/authentication=classic/login-module=testing:add(code=\"Database\",flag=true,module-options=[(\"hashUserPassword\"=>false),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\")])"]]) } + end + + context '#calculate_state with cache type' do + before(:each) do + state = Puppet_X::Coi::Jboss::Internal::State::SecurityDomainState.new(true) + expect(auditor).to receive(:fetch_securtydomain_state).and_return(state) + end + it { expect(subject).to eq([["Security Domain Authentication", "/subsystem=security/security-domain=testing/authentication=classic:add()"], ["Security Domain Login Modules", "/subsystem=security/security-domain=testing/authentication=classic/login-module=testing:add(code=\"Database\",flag=true,module-options=[(\"hashUserPassword\"=>false),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\")])"]]) } + end + end +end diff --git a/spec/unit/internal/sanitize_output_spec.rb b/spec/unit/internal/sanitize_output_spec.rb new file mode 100644 index 0000000..5bff08c --- /dev/null +++ b/spec/unit/internal/sanitize_output_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe Puppet_X::Coi::Jboss::Internal::Sanitizer do + + let(:instance) { described_class.new } + let(:file_location) { File.dirname(__FILE__) } + let(:content) { File.read("#{file_location}/../../testing/files/evaluated.txt") } + + context 'Should evaluate given input' do + let(:test_content) { content.dup } + subject { instance.sanitize(test_content) } + it { expect(subject).to eq("{\n \"outcome\" => \"success\",\n \"result\" => {\n \"deep-copy-subject-mode\" => false,\n \"vault\" => undefined,\n \"security-domain\" => {\n \"jboss-web-policy\" => {\n \"acl\" => undefined,\n \"audit\" => undefined,\n \"authentication\" => undefined,\n \"cache-type\" => \"default\",\n \"identity-trust\" => undefined,\n \"jsse\" => undefined,\n \"mapping\" => undefined,\n \"authorization\" => {\"classic\" => {\"policy-modules\" => [{\n \"code\" => \"Delegating\",\n \"flag\" => \"required\",\n \"module-options\" => undefined\n }]}}\n },\n \"other\" => {\n \"acl\" => undefined,\n \"audit\" => undefined,\n \"authorization\" => undefined,\n \"cache-type\" => \"default\",\n \"identity-trust\" => undefined,\n \"jsse\" => undefined,\n \"mapping\" => undefined,\n \"authentication\" => {\"classic\" => {\"login-modules\" => [\n {\n \"code\" => \"Remoting\",\n \"flag\" => \"optional\",\n \"module-options\" => [{'password-stacking' => 'useFirstPass'}]\n },\n {\n \"code\" => \"RealmUsersRoles\",\n \"flag\" => \"required\",\n \"module-options\" => [\n {'usersProperties' => '${jboss.server.config.dir}/application-users.properties'},\n {'rolesProperties' => '${jboss.server.config.dir}/application-roles.properties'},\n {'realm' => 'ApplicationRealm'},\n {'password-stacking' => 'useFirstPass'}\n ]\n }\n ]}}\n },\n \"jboss-ejb-policy\" => {\n \"acl\" => undefined,\n \"audit\" => undefined,\n \"authentication\" => undefined,\n \"cache-type\" => \"default\",\n \"identity-trust\" => undefined,\n \"jsse\" => undefined,\n \"mapping\" => undefined,\n \"authorization\" => {\"classic\" => {\"policy-modules\" => [{\n \"code\" => \"Delegating\",\n \"flag\" => \"required\",\n \"module-options\" => undefined\n }]}}\n }\n }\n }\n }\n") } + end + + context 'should make no changes' do + let(:data) { '"other" => { + "acl" => undefined, + "audit" => undefined, + "authorization" => undefined, + "cache-type" => "default", + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined, + "authentication" => {"classic" => {"login-modules" => [ + { + "code" => "Remoting", + "flag" => "optional", + "module-options" => [{"password-stacking" => "useFirstPass"}] + }, + { + "code" => "RealmUsersRoles", + "flag" => "required", + "module-options" => [ + {"usersProperties" => "${jboss.server.config.dir}/application-users.properties"}, + {"rolesProperties" => "${jboss.server.config.dir}/application-roles.properties"}, + {"realm" => "ApplicationRealm"}, + {"password-stacking" => "useFirstPass"} + ] + } + ]}} + },'} + subject { instance.sanitize(data) } + it { expect(subject).to eq(data) } + end +end diff --git a/spec/unit/lib/provider/securitydomain/abstract_provider_spec.rb b/spec/unit/lib/provider/securitydomain/abstract_provider_spec.rb new file mode 100644 index 0000000..921223d --- /dev/null +++ b/spec/unit/lib/provider/securitydomain/abstract_provider_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe Puppet_X::Coi::Jboss::Provider::SecurityDomain::AbstractProvider do + let(:instance) { described_class.new } + let(:message) { /Abstract class, implement this method/ } + describe '#correct_command_template_begining' do + subject { instance.send(:correct_command_template_begining, 'sample') } + it { expect { subject }.to raise_error(ArgumentError) } + end + describe '#correct_command_template_ending' do + subject { instance.send(:correct_command_template_ending) } + it { expect { subject }.to raise_error(ArgumentError) } + end + describe '#module_option_template' do + subject { instance.send(:module_option_template) } + it { expect { subject }.to raise_error(ArgumentError) } + end +end diff --git a/spec/unit/lib/provider/securitydomain/post_wildfly_provider_spec.rb b/spec/unit/lib/provider/securitydomain/post_wildfly_provider_spec.rb new file mode 100644 index 0000000..65dda9a --- /dev/null +++ b/spec/unit/lib/provider/securitydomain/post_wildfly_provider_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe Puppet_X::Coi::Jboss::Provider::SecurityDomain::PostWildFlyProvider do + let(:resource) do + { + :name => 'testing', + :code => 'Database', + :codeflag => true, + :moduleoptions => { + 'principalsQuery' => "select 'password' from users u where u.login = ?", + 'hashUserPassword' => false + } + } + end + + let(:provider) { double('mock', :resource => resource) } + let(:compilator) { Puppet_X::Coi::Jboss::Internal::CommandCompilator.new } + let(:instance) { described_class.new(provider, compilator) } + + describe '#create_parametrized_cmd with post wildfly' do + + subject { instance.make_command_templates } + + before :each do + result = ["subsystem=security", "security-domain=testing", "authentication=classic", "login-module=UsersRoles:add(code=\"Database\",flag=true,module-options=[(\"hashUserPassword\"=>false),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\")])"] + + expect(instance).to receive(:make_command_templates).and_return(result) + end + let(:cli_command) do + ["subsystem=security", "security-domain=testing", "authentication=classic", "login-module=UsersRoles:add(code=\"Database\",flag=true,module-options=[(\"hashUserPassword\"=>false),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\")])"] + + end + it { is_expected.to eq cli_command } + end +end diff --git a/spec/unit/lib/provider/securitydomain/pre_wildfly_provider_spec.rb b/spec/unit/lib/provider/securitydomain/pre_wildfly_provider_spec.rb new file mode 100644 index 0000000..6bbfeb2 --- /dev/null +++ b/spec/unit/lib/provider/securitydomain/pre_wildfly_provider_spec.rb @@ -0,0 +1,32 @@ +require "spec_helper" + +describe Puppet_X::Coi::Jboss::Provider::SecurityDomain::PreWildFlyProvider do + let(:resource) do + { + :name => 'testing-is-awesome', + :code => 'DB', + :codeflag => false, + :moduleoptions => { + 'hashUserPassword' => true, + 'principalsQuery' => 'select passwd from users where login = ?', + } + } + end + + let(:provider) { double('mock', :resource => resource) } + let(:compilator) { Puppet_X::Coi::Jboss::Internal::CommandCompilator.new } + let(:instance) { described_class.new(provider, compilator) } + + describe '#create_parametrized_cmd with pre wildfly' do + subject { instance.make_command_templates } + + before :each do + result = ["subsystem=security", "security-domain=testing-is-awesome", "authentication=classic:add(login-modules=[{code=>\"DB\",flag=>false,module-options=>[\"hashUserPassword\"=>true,\"principalsQuery\"=>\"select passwd from users where login = ?\"]}])"] + expect(instance).to receive(:make_command_templates).and_return(result) + end + let(:cli_command) do + ["subsystem=security", "security-domain=testing-is-awesome", "authentication=classic:add(login-modules=[{code=>\"DB\",flag=>false,module-options=>[\"hashUserPassword\"=>true,\"principalsQuery\"=>\"select passwd from users where login = ?\"]}])"] + end + it { is_expected.to eq cli_command } + end +end diff --git a/spec/unit/provider/jboss_confignode/confignode_spec.rb b/spec/unit/provider/jboss_confignode/confignode_spec.rb index 12bae4a..795eecc 100644 --- a/spec/unit/provider/jboss_confignode/confignode_spec.rb +++ b/spec/unit/provider/jboss_confignode/confignode_spec.rb @@ -45,7 +45,7 @@ Puppet::Type.type(:jboss_confignode).new(raw) end - + let(:provider) do resource.provider end @@ -64,7 +64,6 @@ expected_output = { :result => false, } - expect(provider).to receive(:executeAndGet).with(cmd).and_return(expected_output) end diff --git a/spec/unit/provider/jboss_datasource/jbosscli_spec.rb b/spec/unit/provider/jboss_datasource/jbosscli_spec.rb index 6aa83fb..8ea4328 100644 --- a/spec/unit/provider/jboss_datasource/jbosscli_spec.rb +++ b/spec/unit/provider/jboss_datasource/jbosscli_spec.rb @@ -47,47 +47,6 @@ allow(provider.class).to receive(:suitable?).and_return(true) end - describe 'Result of self.instances()' do - let(:xa_result) do - <<-eos - { - "outcome" => "success", - "result" => [] - } - eos - end - let(:nonxa_result) do - <<-eos - { - "outcome" => "success", - "result" => [ - "ExampleDS", - "test-datasource" - ] - } - eos - end - let(:status) { double(:exitstatus => 0) } - before :each do - re = /.*bin\/jboss-cli.sh --timeout=50000 --connect --file=.+jbosscli.* --controller=127.0.0.1:9999/ - expect(Puppet_X::Coi::Jboss::Provider::AbstractJbossCli).to receive(:last_execute_status). - at_least(:once).and_return(status) - expect(Puppet_X::Coi::Jboss::Provider::AbstractJbossCli).to receive(:execshell). - at_least(:once).with(re).and_return(xa_result, nonxa_result) - end - it { expect(provider.class.instances).not_to be_empty } - context 'its size' do - subject { provider.class.instances.size } - it { expect(subject).to eq(2) } - end - context 'for second result, parameter' do - subject { provider.class.instances[1] } - its(:class) { should eq(Puppet::Type::Jboss_datasource::ProviderJbosscli) } - its(:name) { should eq('test-datasource') } - its(:xa) { should eq(false) } - end - end - context 'Given `testing` Non-XA datasource using h2:mem' do let(:command) do '/subsystem=datasources/data-source=testing:read-resource(recursive=true)' @@ -168,8 +127,8 @@ "testing;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" end before :each do - expect(Puppet_X::Coi::Jboss::Provider::AbstractJbossCli).to receive(:executeAndGet). - with(command, runasdomain, ctrlcfg, retry_count, timeout).and_return(result) + expect(provider).to receive(:executeAndGet). + with("/subsystem=datasources/data-source=testing:read-resource(recursive=true)").and_return(result) end describe 'result of dbname()' do diff --git a/spec/unit/provider/jboss_deploy/jboss_deploy_spec.rb b/spec/unit/provider/jboss_deploy/jboss_deploy_spec.rb index e972eb7..03af589 100644 --- a/spec/unit/provider/jboss_deploy/jboss_deploy_spec.rb +++ b/spec/unit/provider/jboss_deploy/jboss_deploy_spec.rb @@ -45,14 +45,11 @@ resource.provider end - before :each do - allow(provider.class).to receive(:suitable?).and_return(true) - end - describe '#create with servergroups nill' do before :each do bringDownName = 'Deployment' - cmd = 'deploy /usr/src/super-crm-1.1.0.war --name=super-crm-1.1.0 --all-server-groups' + cmd = 'deploy /usr/src/super-crm-1.1.0.war --name=super-crm-1.1.0 --all-server-groups --force' + expect(provider).to receive(:bringUp).with(bringDownName, cmd ).and_return('asd') end subject { provider.create } @@ -62,9 +59,9 @@ describe '#create wit servergroups not nill' do before :each do bringDownName = 'Deployment' - cmd = 'deploy /usr/src/super-crm-1.1.0.war --name=super-crm-1.1.0 --server-groups=crm-servers' + cmd = 'deploy /usr/src/super-crm-1.1.0.war --name=super-crm-1.1.0 --server-groups=crm-servers --force' - expect(provider).to receive(:bringUp).with(bringDownName, cmd ).and_return('asd') + expect(provider).to receive(:bringUp).with(bringDownName, cmd).and_return('asd') end let(:extended_repl) { { @@ -75,15 +72,15 @@ it { expect(subject).to eq('asd') } end - describe '#create with redeploy' do + describe '#create with redeploy_on_refresh' do before :each do bringDownName = 'Deployment' cmd = 'deploy /usr/src/super-crm-1.1.0.war --name=super-crm-1.1.0 --all-server-groups --force' - expect(provider).to receive(:bringUp).with(bringDownName, cmd ).and_return('asd') + expect(provider).to receive(:bringUp).with(bringDownName, cmd).and_return('asd') end let(:extended_repl) { { - :redeploy => true, + :redeploy_on_refresh => true, } } subject { provider.create } it { expect(subject).to eq('asd') } @@ -292,5 +289,45 @@ it { expect(subject).to eq(["super-crm", "super-crm-1"]) } end + describe '#redeploy_on_refresh' do + + context 'with default value' do + before :each do + + bringDownName = 'Deployment' + cmd = 'undeploy super-crm-1.1.0 --all-relevant-server-groups' + + bringUpName = 'Deployment' + cmd2 = 'deploy /usr/src/super-crm-1.1.0.war --name=super-crm-1.1.0 --all-server-groups --force' + + expect(provider).to receive(:bringDown).with(bringDownName, cmd).and_return('asd') + expect(provider).to receive(:bringUp).with(bringDownName, cmd2).and_return('asd') + + end + + let(:extended_repl) { { + :redeploy_on_refresh => true, + } } + + subject { provider.redeploy_on_refresh } + it { expect(subject).to eq('asd') } + end + + context 'with value set to false' do + before :each do + + bringUpName = 'Deployment' + cmd = 'deploy /usr/src/super-crm-1.1.0.war --name=super-crm-1.1.0 --all-server-groups' + + expect(provider).to receive(:bringUp).with(bringUpName, cmd).and_return('asd') + end + let(:extended_repl) { { + :redeploy_on_refresh => false, + } } + + subject { provider.redeploy_on_refresh } + it { expect(subject).to eq('asd') } + end + end end end diff --git a/spec/unit/provider/jboss_jdbcdriver/jbosscli_spec.rb b/spec/unit/provider/jboss_jdbcdriver/jbosscli_spec.rb index a6e0bb7..f4e57cf 100644 --- a/spec/unit/provider/jboss_jdbcdriver/jbosscli_spec.rb +++ b/spec/unit/provider/jboss_jdbcdriver/jbosscli_spec.rb @@ -101,5 +101,45 @@ it { expect(subject).to eq(true)} end + describe 'exists? when result is flse' do + before :each do + cmd = "/subsystem=datasources/jdbc-driver=#{resource[:name]}:read-resource(recursive=true)" + compiledcmd = "/profile=full-ha/#{cmd}" + expected_output = { + :result => false, + } + + expect(provider).to receive(:compilecmd).with(cmd).and_return(compiledcmd) + expect(provider).to receive(:executeAndGet).with(compiledcmd).and_return(expected_output) + end + + subject { provider.exists? } + it { expect(subject).to eq(false)} + end + + describe 'setattrib' do + + before :each do + cmd = "/subsystem=datasources/jdbc-driver=app-mails:write-attribute(name=super-name, value=driver-xa-datasource-class-name)" + compiledcmd = "/profile=full-ha/#{cmd}" + + data = { + :asd => '1', + } + + expected_res = { + :cmd => compiledcmd, + :result => res_result, + :lines => data + } + expect(provider).to receive(:compilecmd).with(cmd).and_return(compiledcmd) + expect(provider).to receive(:executeAndGet).with(compiledcmd).and_return(expected_res) + end + + subject { provider.setattrib 'super-name', 'driver-xa-datasource-class-name' } + let(:res_result) { false } + it { expect {subject}.to raise_error(RuntimeError) } + end + end end diff --git a/spec/unit/provider/jboss_jmsqueue/jbosscli_spec.rb b/spec/unit/provider/jboss_jmsqueue/jbosscli_spec.rb index d3bfb2b..14eed22 100644 --- a/spec/unit/provider/jboss_jmsqueue/jbosscli_spec.rb +++ b/spec/unit/provider/jboss_jmsqueue/jbosscli_spec.rb @@ -71,7 +71,7 @@ execCMD2 = '/extension=org.jboss.as.messaging:add()' # line 4 - expect(provider).to receive(:runasdomain?).and_return(true) + expect(provider).to receive(:is_runasdomain).and_return(true) # line 17 expect(provider).to receive(:execute).with(execCMD).and_return(execCMD_expected_output) @@ -116,7 +116,7 @@ describe '#destroy' do before :each do - expect(provider).to receive(:runasdomain?).and_return(true) + expect(provider).to receive(:is_runasdomain).and_return(true) cmd = "jms-queue --profile=#{resource[:profile]} remove --queue-address=#{resource[:name]}" bringDownName = 'JMS Queue' expect(provider).to receive(:bringDown).with(bringDownName, cmd).and_return(true) diff --git a/spec/unit/provider/jboss_securitydomain/jbosscli_spec.rb b/spec/unit/provider/jboss_securitydomain/jbosscli_spec.rb index f0d4bef..013b03d 100644 --- a/spec/unit/provider/jboss_securitydomain/jbosscli_spec.rb +++ b/spec/unit/provider/jboss_securitydomain/jbosscli_spec.rb @@ -1,12 +1,11 @@ -require "spec_helper" - -context "mocking default values" do +require 'spec_helper' +context 'mocking default values for SecurityDomain' do let(:mock_values) do { :product => 'jboss-eap', :version => '6.4.0.GA', - :controller => '127.0.0.1:9999', + :controller => '127.0.0.1:9999' } end @@ -19,19 +18,25 @@ end describe 'Puppet::Type::Jboss_securitydomain::ProviderJbosscli' do - let(:described_class) do Puppet::Type.type(:jboss_securitydomain).provider(:jbosscli) end let(:sample_repl) do { - :name => 'testing', + :controller => '127.0.0.1:9999', + :ctrluser => 'root', + :ctrlpasswd => 'password', + :name => 'db-auth-default', :code => 'Database', - :codeflag => 'true', - :moduleoptions => { - 'principalsQuery' => 'select \'password\' from users u where u.login = ?', - 'hashUserPassword' => false, + :codeflag => false, + :moduleoptions => { + 'dsJndiName' => ':jboss/datasources/default-db', + 'hashStorePassword' => 'false', + 'hashUserPassword' => 'true', + 'principalsQuery' => "select 'password' from users u where u.login = ?", + 'rolesQuery' => "select r.name, 'Roles' from users" }, + :profile => 'full' } end @@ -47,108 +52,415 @@ before :each do allow(provider.class).to receive(:suitable?).and_return(true) + allow(Puppet_X::Coi::Jboss::Configuration).to receive(:read).and_return(:jboss_product => 'as') end - describe '#create' do - before :each do - moduleoptions = 'hashUserPassword => "false",principalsQuery => "select \'password\' from users u where u.login = ?"' + let(:mocked_execution_state_wrapper) { Testing::Mock::ExecutionStateWrapper.new } + + context 'before 6.4' do + describe 'exists? when everything is set' do + before :each do + output = <<-eos + { + "outcome" => "success", + "result" => { + "deep-copy-subject-mode" => false, + "security-domain" => { + "db-auth-default" => { + "cache-type" => "default", + "acl" => undefined, + "audit" => undefined, + "authentication" => {"classic" => { + "login-modules" => [{ + "code" => "asdasd", + "flag" => "required", + "module" => undefined, + "module-options" => { + "dsJndiName" => ":jboss/datasources/default-db", + "hashStorePassword" => "false", + "hashUserPassword" => "true", + "principalsQuery" => "select 'password' from users u where u.login = ?", + "rolesQuery" => "select r.name, 'Roles' from users" + } + }], + "login-module" => {"db-auth-default" => { + "code" => "asdasd", + "flag" => "required", + "module" => undefined, + "module-options" => { + "dsJndiName" => ":jboss/datasources/default-db", + "hashStorePassword" => "false", + "hashUserPassword" => "true", + "principalsQuery" => "select 'password' from users u where u.login = ?", + "rolesQuery" => "select r.name, 'Roles' from users" + } + }} + }}, + "authorization" => undefined, + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined + } + }, + "vault" => undefined + } + } + eos + + mocked_execution_state_wrapper.register_command( + '/profile=full/subsystem=security:read-resource(recursive=true)', + true, + output, + true) + provider.execution_state_wrapper = mocked_execution_state_wrapper + end + subject { provider.exists? } + it { expect(subject).to eq(true) } + end - cmd = "/subsystem=security/security-domain=#{resource[:name]}/authentication=classic:add(login-modules=[{code=>\"#{resource[:code]}\",flag=>\"#{resource[:codeflag]}\",module-options=>[#{moduleoptions}]}])" - compilecmd = "/profile=full-ha/#{cmd}" + context 'exists? with securitydomain not present in system' do + before :each do + output = <<-eos + { + "outcome" => "success", + "result" => { + "deep-copy-subject-mode" => false, + "other" => { + "testing" => { + "cache-type" => "default", + "acl" => undefined, + "audit" => undefined, + "authentication" => undefined, + "authorization" => undefined, + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined + } + }, + "vault" => undefined + } + } + eos - cmd2 = "/subsystem=security/security-domain=#{resource[:name]}:add(cache-type=default)" - compilecmd2 = "/profile=full-ha/#{cmd2}" + mocked_execution_state_wrapper.register_command( + '/profile=full/subsystem=security:read-resource(recursive=true)', + true, + output, + true) + provider.execution_state_wrapper = mocked_execution_state_wrapper + end - expect(provider).to receive(:compilecmd).with(cmd).and_return(compilecmd) - expect(provider).to receive(:compilecmd).with(cmd2).and_return(compilecmd2) + subject { provider.exists? } + it { expect(subject).to eq(false) } + end - bringUpName = 'Security Domain Cache Type' - bringUpName2 = 'Security Domain' - expected_output = { :result => 'asdfhagfgaskfagbfjbgk' } - expected_output2 = { :result => 'dffghbdfnmkbsdkj' } + context 'exists? with login-modules not present in system' do + before :each do + output = <<-eos + { + "outcome" => "success", + "result" => { + "deep-copy-subject-mode" => false, + "security-domain" => { + "db-auth-default" => { + "cache-type" => "default", + "acl" => undefined, + "audit" => undefined, + "authentication" => {"classic" => { + "login-modules" => [{ + "code" => "asdasd", + "flag" => "required", + "module" => undefined, + "module-options" => undefined, + }], + "login-module" => {"db-auth-default" => { + "code" => "asdasd", + "flag" => "required", + "module" => undefined, + "module-options" => { + "dsJndiName" => ":jboss/datasources/default-db", + "hashStorePassword" => "false", + "hashUserPassword" => "true", + "principalsQuery" => "select 'password' from users u where u.login = ?", + "rolesQuery" => "select r.name, 'Roles' from users" + } + }} + }}, + "authorization" => undefined, + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined + } + }, + "vault" => undefined + } + } + eos + mocked_execution_state_wrapper.register_command( + '/profile=full/subsystem=security:read-resource(recursive=true)', + true, + output, + true) + provider.execution_state_wrapper = mocked_execution_state_wrapper + end - expect(provider).to receive(:bringUp).with(bringUpName, compilecmd2).and_return(expected_output) - expect(provider).to receive(:bringUp).with(bringUpName2, compilecmd).and_return(expected_output) + subject { provider.exists? } + it { expect(subject).to eq(false) } end - subject { provider.create } - it {expect(subject).to eq('asdfhagfgaskfagbfjbgk') } - end - describe '#destroy' do - before :each do - cmd = "/subsystem=security/security-domain=#{resource[:name]}:remove()" - compilecmd = "/profile=full-ha/#{cmd}" + context 'destroy method' do + before :each do + output = <<-eos + { + "outcome" => "success", + "result" => { + "deep-copy-subject-mode" => false, + "security-domain" => { + "db-auth-default" => { + "cache-type" => "default", + "acl" => undefined, + "audit" => undefined, + "authentication" => {"classic" => { + "login-modules" => [{ + "code" => "asdasd", + "flag" => "required", + "module" => undefined, + "module-options" => undefined, + }], + "login-module" => {"db-auth-default" => { + "code" => "asdasd", + "flag" => "required", + "module" => undefined, + "module-options" => { + "dsJndiName" => ":jboss/datasources/default-db", + "hashStorePassword" => "false", + "hashUserPassword" => "true", + "principalsQuery" => "select 'password' from users u where u.login = ?", + "rolesQuery" => "select r.name, 'Roles' from users" + } + }} + }}, + "authorization" => undefined, + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined + } + }, + "vault" => undefined + } + } + eos - bringDownName = 'Security Domain' - expected_output = { :result => 'asda'} + mocked_execution_state_wrapper.register_command( + '/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic:remove()', + true, + output, + true) + provider.execution_state_wrapper = mocked_execution_state_wrapper + end - expect(provider).to receive(:compilecmd).with(cmd).and_return(compilecmd) - expect(provider).to receive(:bringDown).with(bringDownName, compilecmd).and_return(expected_output) + subject { provider.destroy } + it { expect(subject).to eq(true) } end - subject { provider.destroy } - it { expect(subject).to eq('asda') } end - describe '#exist?' do - before :each do - cmd = "/subsystem=security/security-domain=#{resource[:name]}/authentication=classic:read-resource()" - compilecmd = "/profile=full-ha/#{cmd}" - - lines = 'asd' - - bringDownName = 'Security Domain' - content = <<-eos - { - "rolesQuery" => "select r.name, 'Roles' from users u join user_roles ur on ur.user_id = u.id join roles r on r.id = ur.role_id where u.login = ?", - "hashStorePassword" => "false", - "principalsQuery" => "select 'haslo' from uzytkownik u where u.login = upper(?)", - "hashUserPassword" => "false", - "dsJndiName" => "java:jboss/datasources/datasources_auth" - } - eos - - expected_lines = <<-eos - { - "outcome" => "success", - "result" => { - "login-modules" => [{ - "code" => "Database", - "flag" => "required", - "module" => undefined, - "module-options" => #{content} - }], - "login-module" => {"Database" => undefined} + context 'create methods' do + context 'create? when there is no login modules' do + before :each do + output = <<-eos + { + "outcome" => "success", + "result" => { + "deep-copy-subject-mode" => false, + "security-domain" => { + "db-auth-default" => { + "cache-type" => "default", + "acl" => undefined, + "audit" => undefined, + "authentication" => {"classic" => { + "login-modules" => [{ + "code" => "asdasd", + "flag" => "required", + "module" => undefined, + "module-options" => undefined, + }], + "login-module" => {"db-auth-default" => { + "code" => "asdasd", + "flag" => "required", + "module" => undefined, + "module-options" => { + "dsJndiName" => ":jboss/datasources/default-db", + "hashStorePassword" => "false", + "hashUserPassword" => "true", + "principalsQuery" => "select 'password' from users u where u.login = ?", + "rolesQuery" => "select r.name, 'Roles' from users" + } + }} + }}, + "authorization" => undefined, + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined } - } - eos + }, + "vault" => undefined + } + } + eos - expected_res = { - :cmd => compilecmd, - :result => res_result, - :lines => expected_lines - } + mocked_execution_state_wrapper.register_command( + '/profile=full/subsystem=security:read-resource(recursive=true)', + true, + output, + true) + provider.execution_state_wrapper = mocked_execution_state_wrapper + provider.exists? - expect(provider).to receive(:compilecmd).with(cmd).and_return(compilecmd) - expect(provider).to receive(:executeWithoutRetry).with(compilecmd).and_return(expected_res) + mocked_execution_state_wrapper.register_command( + "/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic/login-module=db-auth-default:add(code=\"Database\",flag=false,module-options=[(\"dsJndiName\"=>\":jboss/datasources/default-db\"),(\"hashStorePassword\"=>\"false\"),(\"hashUserPassword\"=>\"true\"),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\"),(\"rolesQuery\"=>\"select r.name, 'Roles' from users\")])", + true, + 'asd', + true + ) + end + + subject { provider.create } + it { expect(subject).to eq([['Security Domain Login Modules', "/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic/login-module=db-auth-default:add(code=\"Database\",flag=false,module-options=[(\"dsJndiName\"=>\":jboss/datasources/default-db\"),(\"hashStorePassword\"=>\"false\"),(\"hashUserPassword\"=>\"true\"),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\"),(\"rolesQuery\"=>\"select r.name, 'Roles' from users\")])"]]) } end - subject { provider.exists? } + context 'create? when there is no authentication' do + before :each do + output = <<-eos + { + "outcome" => "success", + "result" => { + "deep-copy-subject-mode" => false, + "security-domain" => { + "db-auth-default" => { + "cache-type" => "default", + "acl" => undefined, + "audit" => undefined, + "authentication" => undefined, + "authorization" => undefined, + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined + } + }, + "vault" => undefined + } + } + eos + + mocked_execution_state_wrapper.register_command( + '/profile=full/subsystem=security:read-resource(recursive=true)', + true, + output, + true) + provider.execution_state_wrapper = mocked_execution_state_wrapper + provider.exists? - context 'with res[:result] => true and existinghash && givenhash are not nil' do - let(:res_result) { true } + mocked_execution_state_wrapper.register_command( + '/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic:add()', + true, + 'asd', + true + ) + mocked_execution_state_wrapper.register_command( + "/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic/login-module=db-auth-default:add(code=\"Database\",flag=false,module-options=[(\"dsJndiName\"=>\":jboss/datasources/default-db\"),(\"hashStorePassword\"=>\"false\"),(\"hashUserPassword\"=>\"true\"),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\"),(\"rolesQuery\"=>\"select r.name, 'Roles' from users\")])", + true, + 'asd', + true + ) + end + + subject { provider.create } + it { expect(subject).to eq([["Security Domain Authentication", "/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic:add()"], ["Security Domain Login Modules", "/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic/login-module=db-auth-default:add(code=\"Database\",flag=false,module-options=[(\"dsJndiName\"=>\":jboss/datasources/default-db\"),(\"hashStorePassword\"=>\"false\"),(\"hashUserPassword\"=>\"true\"),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\"),(\"rolesQuery\"=>\"select r.name, 'Roles' from users\")])"]]) } + end + context 'create? when there is no securitydomain' do before :each do - expect(provider).to receive(:destroy).and_return(nil) + output = <<-eos + { + "outcome" => "success", + "result" => { + "deep-copy-subject-mode" => false, + "security-domain" => { + "other" => { + "cache-type" => "default", + "acl" => undefined, + "audit" => undefined, + "authentication" => {"classic" => { + "login-modules" => [{ + "code" => "asdasd", + "flag" => "required", + "module" => undefined, + "module-options" => undefined, + }], + "login-module" => {"db-auth-default" => { + "code" => "asdasd", + "flag" => "required", + "module" => undefined, + "module-options" => { + "dsJndiName" => ":jboss/datasources/default-db", + "hashStorePassword" => "false", + "hashUserPassword" => "true", + "principalsQuery" => "select 'password' from users u where u.login = ?", + "rolesQuery" => "select r.name, 'Roles' from users " + } + }} + }}, + "authorization" => undefined, + "identity-trust" => undefined, + "jsse" => undefined, + "mapping" => undefined + } + }, + "vault" => undefined + } + } + eos + + mocked_execution_state_wrapper.register_command( + '/profile=full/subsystem=security:read-resource(recursive=true)', + true, + output, + true) + provider.execution_state_wrapper = mocked_execution_state_wrapper + provider.exists? + + + mocked_execution_state_wrapper.register_command( + '/profile=full/subsystem=security/security-domain=db-auth-default:add(cache-type=default)', + true, + 'asd', + true + ) + + mocked_execution_state_wrapper.register_command( + '/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic:add()', + true, + 'asd', + true + ) + + mocked_execution_state_wrapper.register_command( + "/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic/login-module=db-auth-default:add(code=\"Database\",flag=false,module-options=[(\"dsJndiName\"=>\":jboss/datasources/default-db\"),(\"hashStorePassword\"=>\"false\"),(\"hashUserPassword\"=>\"true\"),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\"),(\"rolesQuery\"=>\"select r.name, 'Roles' from users\")])", + true, + 'asd', + true + ) + end - it { expect(subject).to eq(false) } + subject { provider.create } + it { expect(subject).to eq([["Security Domain Cache Type", "/profile=full/subsystem=security/security-domain=db-auth-default:add(cache-type=default)"], ["Security Domain Authentication", "/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic:add()"], ["Security Domain Login Modules", "/profile=full/subsystem=security/security-domain=db-auth-default/authentication=classic/login-module=db-auth-default:add(code=\"Database\",flag=false,module-options=[(\"dsJndiName\"=>\":jboss/datasources/default-db\"),(\"hashStorePassword\"=>\"false\"),(\"hashUserPassword\"=>\"true\"),(\"principalsQuery\"=>\"select 'password' from users u where u.login = ?\"),(\"rolesQuery\"=>\"select r.name, 'Roles' from users\")])"]]) } end - context 'with [:result] => false' do - let(:res_result) { false } - it { expect(subject).to eq(false) } + end + + context 'after 6.4' do end end -end -end + end diff --git a/spec/unit/types/jboss_deploy_spec.rb b/spec/unit/types/jboss_deploy_spec.rb index c8c2236..2c1c6ae 100644 --- a/spec/unit/types/jboss_deploy_spec.rb +++ b/spec/unit/types/jboss_deploy_spec.rb @@ -29,4 +29,14 @@ def extend_params(given) end end + describe ':runtime_name' do + context 'given invalid input' do + let(:params) { extend_params( :runtime_name => 'not_valid_runtime_name' ) } + it do + expect { type }.to raise_error(ex_class, + 'Parameter runtime_name failed on Jboss_deploy[spec-artifact]: Invalid file extension, module only supports: .jar, .war, .ear, .rar') + end + end + end + end diff --git a/tests/README.md b/tests/README.md index 06ca814..0dbd71a 100644 --- a/tests/README.md +++ b/tests/README.md @@ -3,8 +3,9 @@ This folder contains standard Puppet smoke tests that can be run with ``` -puppet apply tests/nameoffile.pp --noop +puppet apply tests/[name-of-test].pp --noop ``` -All files should execute without any problems, except for those in folder `tests/examples/`. -Examples in that folder require additional resources such as files or wars and we consider that placing them in repository is bad habit. If you want to run tests provide files via for example wget or some other technique. +All files should execute without any problems. + +**CAUTION!** `deploy.pp` and `resourceadapter.pp` smoke tests fetches some example artifacts from Maven Central repository using `wget`. diff --git a/tests/deploy.pp b/tests/deploy.pp new file mode 100644 index 0000000..e000135 --- /dev/null +++ b/tests/deploy.pp @@ -0,0 +1,25 @@ +include jboss + +ensure_packages(['wget']) + +$sourcedir = '/usr/src' +$version = '2.22.2' +$artifact = 'servlet3-webapp' +$group = 'org/glassfish/jersey/examples' +$file = "${artifact}-${version}.war" +$fullpath = "${sourcedir}/${file}" + +exec { "wget https://repo1.maven.org/maven2/${group}/${artifact}/${version}/${file}": + alias => 'wget', + path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin', + cwd => $sourcedir, + creates => $fullpath, + require => Package['wget'], +} + +jboss::deploy { $file: + ensure => 'present', + path => $fullpath, + subscribe => Exec['wget'], + # servergroup => 'foobar-group', # on domain mode +} diff --git a/tests/examples/deploy.pp b/tests/examples/deploy.pp deleted file mode 100644 index d127963..0000000 --- a/tests/examples/deploy.pp +++ /dev/null @@ -1,7 +0,0 @@ -include jboss - -jboss::deploy { 'foobar-app': - ensure => 'present', - servergroup => 'foobar-group', - path => '/usr/src/foobar-app-1.0.0.war', -} \ No newline at end of file diff --git a/tests/examples/resourceadapter.pp b/tests/examples/resourceadapter.pp deleted file mode 100644 index ceffa73..0000000 --- a/tests/examples/resourceadapter.pp +++ /dev/null @@ -1,13 +0,0 @@ -include jboss - -jboss::deploy { 'jca-filestore.rar': - path => '/usr/src/jca-filestore.rar', - require => JBoss::Resourceadapter['jca-filestore.rar'], -} - -jboss::resourceadapter { 'jca-filestore.rar': - archive => 'jca-filestore.rar', - transactionsupport => 'LocalTransaction', - classname => 'org.example.jca.FileSystemConnectionFactory', - jndiname => 'java:/jboss/jca/photos', -} diff --git a/tests/jboss-as.pp b/tests/jboss-as.pp deleted file mode 100644 index 62eed9c..0000000 --- a/tests/jboss-as.pp +++ /dev/null @@ -1,6 +0,0 @@ -class { 'jboss': - product => 'jboss-as', - version => '7.1.1.Final', - download_url => 'http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.zip', - enableconsole => true, -} diff --git a/tests/jboss/as7.pp b/tests/jboss/as7.pp new file mode 100644 index 0000000..c152372 --- /dev/null +++ b/tests/jboss/as7.pp @@ -0,0 +1,4 @@ +class { 'jboss': + product => 'jboss-as', + version => '7.1.1.Final', +} diff --git a/tests/jboss/wildfly8.pp b/tests/jboss/wildfly8.pp new file mode 100644 index 0000000..295cc70 --- /dev/null +++ b/tests/jboss/wildfly8.pp @@ -0,0 +1,4 @@ +class { 'jboss': + product => 'wildfly', + version => '8.2.1.Final', +} diff --git a/tests/jboss/wildfly9.pp b/tests/jboss/wildfly9.pp new file mode 100644 index 0000000..7f77b55 --- /dev/null +++ b/tests/jboss/wildfly9.pp @@ -0,0 +1,4 @@ +class { 'jboss': + product => 'wildfly', + version => '9.0.2.Final', +} diff --git a/tests/resourceadapter.pp b/tests/resourceadapter.pp new file mode 100644 index 0000000..60d6508 --- /dev/null +++ b/tests/resourceadapter.pp @@ -0,0 +1,33 @@ +include jboss + +ensure_packages(['wget']) + +$sourcedir = '/usr/src' +$version = '2.1.0' +$artifact = 'genericconnector-rar' +$group = 'ch/maxant' +$file = "${artifact}-${version}.rar" +$fullpath = "${sourcedir}/${file}" + +exec { "wget https://repo1.maven.org/maven2/${group}/${artifact}/${version}/${file}": + alias => 'wget', + path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin', + cwd => $sourcedir, + creates => $fullpath, + require => Package['wget'], +} + +jboss::resourceadapter { 'genericconnector.rar': + archive => 'genericconnector.rar', + transactionsupport => 'XATransaction', + classname => 'ch.maxant.generic_jca_adapter.ManagedTransactionAssistanceFactory', + jndiname => 'java:/jboss/jca-generic', +} + +jboss::deploy { 'genericconnector.rar': + path => $fullpath, + require => [ + JBoss::Resourceadapter['genericconnector.rar'], + Exec['wget'], + ], +} diff --git a/tests/securitydomain.pp b/tests/securitydomain.pp index 550145f..8856318 100644 --- a/tests/securitydomain.pp +++ b/tests/securitydomain.pp @@ -9,9 +9,6 @@ 'principalsQuery' => 'select \'password\' from users u where u.login = ?', 'hashUserPassword' => false, 'hashStorePassword' => false, - 'rolesQuery' => 'select r.name, \'Roles\' from users u -join user_roles ur on ur.user_id = u.id -join roles r on r.id = ur.role_id -where u.login = ?', + 'rolesQuery' => 'select r.name, \'Roles\' from users', }, -} \ No newline at end of file +}