diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f146c31 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vagrant +Berksfile.lock +.kitchen/ +.kitchen.local.yml +Thumbs.db diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..87f4a09 --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,42 @@ +# (C) Copyright IBM Corporation 2016. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +--- +driver: + name: vagrant + +provisioner: + name: chef_zero + +verifier: + name: inspec + +platforms: + - name: ubuntu-14.04-chef-latest + provisioner: + require_chef_omnibus: 12.6.0 + driver: + box: opscode-ubuntu-14.04 + +suites: + - name: goodpath + attributes: + ibm_mq_test: + # You need to set up a web server with the MQ packages on for the + # tests to use, and reference the full URI as an environment variable. + source: "<%= ENV['MQ_URI'] %>" + queue_manager: + name: qm1 + run_list: + - recipe[apt::default] + - recipe[ibm_mq_test::install] diff --git a/Berksfile b/Berksfile new file mode 100644 index 0000000..b499744 --- /dev/null +++ b/Berksfile @@ -0,0 +1,8 @@ +source 'https://supermarket.chef.io' + +metadata + +group :integration do + cookbook 'apt' + cookbook 'ibm_mq_test', path: 'test/cookbooks/ibm_mq_test' +end diff --git a/CLA.md b/CLA.md new file mode 100644 index 0000000..5a26a0b --- /dev/null +++ b/CLA.md @@ -0,0 +1,32 @@ +IBM Contributor License Agreement +================================= + +Version 1.0.0 January 14, 2014 + +In order for You (as defined below) to make intellectual property Contributions (as defined below) now or in the future to IBM GitHub repositories, +You must agree to this Contributor License Agreement ("CLA"). + +Please read this CLA carefully before accepting its terms. By accepting the CLA, You are agreeing to be bound by its terms. +If You submit a Pull Request against an IBM repository on GitHub You must include in the Pull Request a statement of Your acceptance of this CLA. + +As used in this CLA: +(i) "You" (or "Your") shall mean the entity that is making this Agreement with IBM; +(ii)"Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is submitted by You to IBM for inclusion in, +or documentation of, any of the IBM GitHub repositories; +(iii) "Submit" (or "Submitted") means any form of communication sent to IBM (e.g. the content You post in a GitHub Issue or submit as part of a GitHub Pull Request). + +This agreement applies to all Contributions You Submit. + +This CLA, and the license(s) associated with the particular IBM GitHub repositories You are contributing to, provides a license to Your Contributions to IBM and downstream consumers, +but You still own Your Contributions, and except for the licenses provided for in this CLA, You reserve all right, title and interest in Your Contributions. + +IBM requires that each Contribution You Submit now or in the future comply with the following four commitments. + +1) You will only Submit Contributions where You have authored 100% of the content. +2) You will only Submit Contributions to which You have the necessary rights. This means that if You are employed You have received the necessary permissions from Your employer to make the +Contributions. +3) Whatever content You Contribute will be provided under the license(s) associated with the particular IBM GitHub repository You are contributing to. +4) You understand and agree that IBM GitHub repositories and Your contributions are public, and that a record of the contribution (including all personal information You submit with it) +is maintained indefinitely and may be redistributed consistent with the license(s) involved. +You will promptly notify IBM if You become aware of any facts or circumstances that would make these commitments inaccurate in any way. +To do so, please create an Issue in the appropriate GitHub repository. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5b5bc80 --- /dev/null +++ b/README.md @@ -0,0 +1,101 @@ +IBM MQ cookbook +=============== + +The IBM MQ cookbook is a library cookbook that provides custom resources for use in your own recipes. This cookbook is currently experimental, therefore we recommend that if you want to use this cookbook, that you either pin the version you use, or create your own fork first. + +Requirements +------------ +- Chef 12.6+ +- Network accessible web server hosting the MQ installer package + +Platform Support +---------------- +The following platforms have been tested with Test Kitchen: + +- Ubuntu 14.04 + +Cookbook Dependencies +--------------------- +- [limits](https://supermarket.chef.io/cookbooks/limits) +- [yum](https://supermarket.chef.io/cookbooks/yum) + +Usage +----- +1. Add ```depends 'ibm_mq'``` to your cookbook's metadata.rb +2. Use the resources shipped in cookbook in a recipe, the same way you'd + use core Chef resources (file, template, directory, package, etc). + +```ruby +ibm_mq_installation 'Installation1' do + source 'http://10.0.2.15:8000/WS_MQ_V8.0.0.4_LINUX_ON_X86_64_IM.tar.gz' + accept_license true +end + +ibm_mq_queue_manager 'qm1' do + action [:create, :start] +end +``` + +Resources +--------- + +## ibm_mq_installation +The `ibm_mq_installation` resource downloads an IBM MQ download package file, +specified by a URI. + +#### Example +```ruby +ibm_mq_installation 'Installation1' do + source 'http://10.0.2.15:8000/WS_MQ_V8.0.0.4_LINUX_ON_X86_64_IM.tar.gz' + accept_license true + action :create +end +``` + +#### Properties +- `source` - Path to network accessible IBM MQ installation package. +- `accept_license` - Set this to `true` if you accept the terms of the IBM MQ license. +- `packages` - An array of package names to install. Defaults to: + `%w(MQSeriesServer MQSeriesGSKit)` +- `uid` - The UID to use for the `mqm` user +- `gid` - The GID to use for the `mqm` user + +## ibm_mq_queue_manager +The `ibm_mq_queue_manager` resource creates and starts IBM MQ queue managers. + +#### Example +```ruby +ibm_mq_queue_manager 'qm1' do + action [:create, :start] +end +``` + +#### Properties +- `user` - User to run MQ commands as. Defaults to `mqm` + + +## Maintainers + +* Arthur Barr () + +## Developing +If you do submit a Pull Request related to this cookbook, please indicate in the Pull Request that you accept and agree to be bound by the terms of the [IBM Contributor License Agreement](CLA.md). + +In order to run the Test-Kitchen tests, you need to set an environment variable for the MQ download. For example, on Linux, you might do the following: + +```shell +export MQ_URI=http://10.0.2.15:8000/WS_MQ_V8.0.0.4_LINUX_ON_X86_64_IM.tar.gz +``` + +## License +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/chefignore b/chefignore new file mode 100644 index 0000000..e70452e --- /dev/null +++ b/chefignore @@ -0,0 +1,9 @@ +.vagrant +Berksfile +Berksfile.lock +.kitchen* +spec/* +test/* +.git +.gitignore +Thumbs.db diff --git a/metadata.rb b/metadata.rb new file mode 100644 index 0000000..85988bc --- /dev/null +++ b/metadata.rb @@ -0,0 +1,10 @@ +name 'ibm_mq' +maintainer 'IBM' +maintainer_email 'arthur.barr@uk.ibm.com' +license 'Apache 2.0' +description 'Installs/Configures IBM MQ' +long_description 'Installs/Configures IBM MQ' +version '0.1.0' +depends 'limits' +depends 'yum' +supports 'ubuntu' diff --git a/resources/installation.rb b/resources/installation.rb new file mode 100644 index 0000000..bca2180 --- /dev/null +++ b/resources/installation.rb @@ -0,0 +1,155 @@ +# (C) Copyright IBM Corporation 2016. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +property :source, kind_of: String, required: true +property :accept_license, kind_of: [TrueClass, FalseClass], default: false +property :packages, kind_of: Array, default: %w(MQSeriesServer MQSeriesGSKit) +property :default, kind_of: [TrueClass, FalseClass], default: false +property :uid, kind_of: [String, Integer], default: nil +property :gid, kind_of: [String, Integer], default: nil + +default_action :create + +# This action does the following: +# * Downloads the MQ install package +# * Extracts the install package +# * Adds a Yum repository pointing at the MQ RPM files +# * Accepts the license, as specified +# * Installs the MQ packages, as specified +# * Sets the default MQ installation, as specified +action :create do + fail 'You must accept the license to install IBM MQ.' unless accept_license + fail 'Non-default installations are not currently supported' unless default + + # include_recipe 'sysctl::ohai_plugin' + # + # sysctl_param 'fs.file-max' do + # value 524_289 + # only_if node['sys']['fs']['file-max'] < value + # end + + download_dir = "#{Chef::Config[:file_cache_path]}/ibm_mq" + download_path = "#{download_dir}/#{name}.tar.gz" + unpack_dir = "#{download_dir}/extract-#{name}" + + directory download_dir do + owner 'root' + group 'root' + mode '0755' + action :create + end + + directory unpack_dir do + owner 'root' + group 'root' + mode '0755' + action :create + end + + package %w(rpm yum createrepo) do + action :install + end + + remote_file download_path do + source new_resource.source + action :create + notifies :run, 'execute[extract-mq-package]', :immediately + notifies :run, 'execute[createrepo-mq]', :immediately + backup false + action :create + end + + execute 'extract-mq-package' do + command "tar -xvf #{download_path}" + cwd unpack_dir + # Only run after notified by remote_file download + action :nothing + end + + execute 'createrepo-mq' do + user 'root' + cwd "#{unpack_dir}/MQServer" + command 'createrepo .' + end + + group 'mqm' do + gid new_resource.gid + action :create + end + + user 'mqm' do + uid new_resource.uid + group 'mqm' + home '/var/mqm' + action :create + end + + set_limit 'mqm' do + type 'soft' + item 'nofile' + value 10_240 + end + + set_limit 'mqm' do + type 'hard' + item 'nofile' + value 10_240 + end + + execute 'Accept the mqlicense' do + user 'root' + cwd "#{unpack_dir}/MQServer" + command './mqlicense.sh -accept -text_only' + end + + # Work around bug in 'yum' cookbook + # See https://github.com/chef-cookbooks/yum/issues/144 + directory '/etc/yum.repos.d' do + owner 'root' + group 'root' + mode '0755' + action :create + end + + # Add a local yum repository + yum_repository "ibm-mq-chef-#{name}" do + description 'Packages for IBM MQ, used by Chef cookbook' + baseurl "file://#{unpack_dir}/MQServer" + gpgcheck false + action :create + end + + # Install MQ + yum_package packages do + action :install + end + + # TODO: Unset as default installation, if no longer default + execute 'setmqinst' do + command '/opt/mqm/bin/setmqinst -n Installation1 -i' + only_if { default } + end +end + +action :remove do + # Uninstall MQ + yum_package packages do + action :remove + end + + # Remove our Yum repository + yum_repository "ibm-mq-chef-#{name}" do + action :remove + end +end diff --git a/resources/queue_manager.rb b/resources/queue_manager.rb new file mode 100644 index 0000000..8a122a4 --- /dev/null +++ b/resources/queue_manager.rb @@ -0,0 +1,35 @@ +# (C) Copyright IBM Corporation 2016. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +property :user, kind_of: String, default: 'mqm' + +default_action :start + +action :create do + execute 'crtmqm' do + command "crtmqm #{new_resource.name}" + user new_resource.user + group 'mqm' + creates '/var/mqm/qmgrs/qm1/' + end +end + +action :start do + execute 'strmqm' do + command "strmqm #{new_resource.name}" + user new_resource.user + group 'mqm' + not_if "dspmq -m #{new_resource.name} -n | grep RUNNING" + end +end diff --git a/test/cookbooks/ibm_mq_test/README.md b/test/cookbooks/ibm_mq_test/README.md new file mode 100644 index 0000000..810a6d9 --- /dev/null +++ b/test/cookbooks/ibm_mq_test/README.md @@ -0,0 +1,3 @@ +# ibm_mq_test + +Tests for the ibm_mq cookbook diff --git a/test/cookbooks/ibm_mq_test/attributes/default.rb b/test/cookbooks/ibm_mq_test/attributes/default.rb new file mode 100644 index 0000000..a60355a --- /dev/null +++ b/test/cookbooks/ibm_mq_test/attributes/default.rb @@ -0,0 +1,3 @@ +default['ibm_mq_test']['uid'] = '1234' +default['ibm_mq_test']['gid'] = '1234' +default['ibm_mq_test']['accept_license'] = true diff --git a/test/cookbooks/ibm_mq_test/metadata.rb b/test/cookbooks/ibm_mq_test/metadata.rb new file mode 100644 index 0000000..cccbf8d --- /dev/null +++ b/test/cookbooks/ibm_mq_test/metadata.rb @@ -0,0 +1,8 @@ +name 'ibm_mq_test' +maintainer 'IBM' +maintainer_email 'arthur.barr@uk.ibm.com' +license 'Apache 2.0' +description 'Tests for ibm_mq cookbook' +version '0.1.0' +depends 'ibm_mq' +depends 'sysctl' diff --git a/test/cookbooks/ibm_mq_test/recipes/install.rb b/test/cookbooks/ibm_mq_test/recipes/install.rb new file mode 100644 index 0000000..38827c7 --- /dev/null +++ b/test/cookbooks/ibm_mq_test/recipes/install.rb @@ -0,0 +1,41 @@ +# (C) Copyright IBM Corporation 2016. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include_recipe 'sysctl::default' + +# This is done in the test cookbook (for now), so that we don't overwrite +# kernel settings without it being obvious what's happening +sysctl_param 'kernel.shmmni' do + value 4096 +end +sysctl_param 'kernel.shmmax' do + value 268_435_456 +end +sysctl_param 'kernel.shmall' do + value 2_097_152 +end +sysctl_param 'kernel.sem' do + value '32 4096 32 128' +end +sysctl_param 'kernel.threads-max' do + value 1000 +end +sysctl_param 'kernel.pid_max' do + value 12_000 +end +sysctl_param 'fs.file-max' do + value 524_288 +end + +include_recipe 'ibm_mq_test::install_mq' diff --git a/test/cookbooks/ibm_mq_test/recipes/install_mq.rb b/test/cookbooks/ibm_mq_test/recipes/install_mq.rb new file mode 100644 index 0000000..4430039 --- /dev/null +++ b/test/cookbooks/ibm_mq_test/recipes/install_mq.rb @@ -0,0 +1,35 @@ +# (C) Copyright IBM Corporation 2016. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ibm_mq_installation 'default' do + source node['ibm_mq_test']['source'] + accept_license node['ibm_mq_test']['accept_license'] + default true + uid node['ibm_mq_test']['uid'] + gid node['ibm_mq_test']['gid'] + action :create +end + +qmgr = node['ibm_mq_test']['queue_manager']['name'] + +ibm_mq_queue_manager qmgr do + # mqsc IO.read('password-security.erb') + action [:create, :start] +end + +execute 'runmqsc' do + command "echo 'define qlocal(foo) replace' | runmqsc #{qmgr}" + user 'mqm' + group 'mqm' +end diff --git a/test/integration/goodpath/inspec/mq_spec.rb b/test/integration/goodpath/inspec/mq_spec.rb new file mode 100644 index 0000000..3917775 --- /dev/null +++ b/test/integration/goodpath/inspec/mq_spec.rb @@ -0,0 +1,43 @@ +# (C) Copyright IBM Corporation 2016. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +describe file('/opt/mqm') do + it { should be_owned_by 'mqm' } +end + +describe file('/var/mqm') do + it { should be_owned_by 'mqm' } +end + +describe command('crtmqm').exist? do + it { should eq true } +end + +# Can't use "describe package" on Ubuntu +describe command('rpm -q MQSeriesServer') do + its('exit_status') { should eq 0 } +end + +describe command('rpm -q MQSeriesGSKit') do + its('exit_status') { should eq 0 } +end + +# Not specified by recipe, but should still be installed +describe command('rpm -q MQSeriesRuntime') do + its('exit_status') { should eq 0 } +end + +describe command('dspmq -n') do + its(:stdout) { should match %r{RUNNING} } +end