diff --git a/.gitignore b/.gitignore index cbccf1e..4d7a368 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ bin/* .kitchen/ .kitchen.local.yml +bundle diff --git a/.kitchen.travis.yml b/.kitchen.travis.yml new file mode 100644 index 0000000..06a21cb --- /dev/null +++ b/.kitchen.travis.yml @@ -0,0 +1,34 @@ +--- +driver: + name: proxy + host: localhost + reset_command: "exit 0" + port: <%= ENV["machine_port"] %> + username: <%= ENV["machine_user"] %> + password: <%= ENV["machine_pass"] %> + +provisioner: + name: chef_zero + +verifier: + name: inspec + +platforms: + - name: centos-6.6 + attributes: + orchestrator: + package: + version: 2.1.5-1 + url: 'https://github.com/kplimack/orchestrator-rpm/raw/master/orchestrator-2.1.5-1.x86_64.rpm' + checksum: 392a2d6b3d5cea85053dfad3b6c2dceae838674d56f267046c854e4d1ceee2a3 + - name: centos-7.2 + - name: debian-8.9 + attributes: + orchestrator: + package: + version: ~ + +suites: + - name: default + run_list: + - recipe[orchestrator::default] diff --git a/.kitchen.yml b/.kitchen.yml index 42edf83..d5a1b83 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -8,16 +8,25 @@ driver: provisioner: name: chef_zero + require_chef_omnibus: true + always_update_cookbooks: true + +verifier: + name: inspec + sudo: true platforms: - name: centos-6.6 - driver_config: - box: sendgrid_centos-6_chef-11 - box_url: http://repo.sjc1.sendgrid.net/images/vagrant/metadata/sendgrid_centos-6_chef-11.json + attributes: + orchestrator: + package: + version: 2.1.5-1 + url: 'https://github.com/kplimack/orchestrator-rpm/raw/master/orchestrator-2.1.5-1.x86_64.rpm' + checksum: 392a2d6b3d5cea85053dfad3b6c2dceae838674d56f267046c854e4d1ceee2a3 + - name: centos-7.2 + - name: debian-8.9 suites: - name: default run_list: - recipe[orchestrator::default] - - recipe[minitest-handler] - attributes: diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..cc87cd2 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,52 @@ +AllCops: + TargetRubyVersion: 2.1 + Exclude: + - bin/**/* + - script/**/* + - vendor/**/* + - cookbooks/**/* + - bundle/**/* + +ClassLength: + Enabled: false +CyclomaticComplexity: + Enabled: false +Documentation: + Enabled: false +Encoding: + Enabled: false +LineLength: + Enabled: false +MethodLength: + Enabled: false +Metrics/AbcSize: + Enabled: false +Metrics/ModuleLength: + Enabled: false +PerceivedComplexity: + Enabled: false +Style/SpaceBeforeFirstArg: + Enabled: true +Style/ClassAndModuleChildren: + Enabled: false +Style/EmptyLinesAroundBlockBody: + Enabled: true +Style/FileName: + Enabled: true +Style/RescueModifier: + Enabled: true +Style/StringLiterals: + Enabled: true +Metrics/BlockLength: + Enabled: false +Style/NumericLiterals: + Enabled: false +Style/ExtraSpacing: + Enabled: true + AllowForAlignment: false + ForceEqualSignAlignment: false +Style/SymbolArray: + Enabled: false +Style/PercentLiteralDelimiters: + PreferredDelimiters: + '%w': '()' diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..55bf029 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,22 @@ +language: ruby +env: + global: + - machine_user=travis + - machine_pass=travis + - machine_port=22 + - KITCHEN_YAML=.kitchen.travis.yml + +rvm: + - 2.3.4 + +gemfile: + - Gemfile + +sudo: required +dist: trusty + +before_install: + - sudo usermod -p "`openssl passwd -1 'travis'`" travis + +script: "bundle exec rake" + diff --git a/Berksfile b/Berksfile index 1350479..34fea21 100644 --- a/Berksfile +++ b/Berksfile @@ -1,4 +1,3 @@ -source :chef_server +source 'https://supermarket.chef.io' metadata -cookbook 'minitest-handler', git: 'https://github.com/btm/minitest-handler-cookbook.git' diff --git a/CHANGELOG.md b/CHANGELOG.md index 3daa976..eb183f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,57 +1,71 @@ -# 2.0.2 +# orchestrator + +## 2.1.0 +* use build-essential to install gcc,make, etc +* rubocop (.rubocop.yml added and files corrected) +* use generic centos-6 VM to test on, not internal sendgrid images +* alphabetize attributes +* replace ruby_block with file resource with sensitive +* add `Debian 8` support +* add `Centos 7` support +* add `travis-ci` config, Gemfile, etc +* allow for orchestrator package source/checksum to be defined and overridden +* replace `minitest` with `inspec`x + +## 2.0.2 Orchestrator has officially moved to Github -# 2.0.1 +## 2.0.1 Fix spelling mistake in ListenAddress -# 2.0.0 +## 2.0.0 Move to a single hash for all config values Use ruby to create the config from the hash -# 1.5.0 +## 1.5.0 Install orchestrator using package cloud repo (Thanks Shlomi for setting that up) Remove spec tests. Sticking with minitests only Update the kitchen platforms because it isn't 2012 anymore -# 1.4.1 +## 1.4.1 Add new config attribute for HostnameResolveMethod -# 1.4.0 +## 1.4.0 Add a new CLI only recipe installation Set some version constraints to the upstream dependencies Use supermarket for the cookbook API -# 1.3.3 +## 1.3.3 Add ReaadOnly to the config template -# 1.3.2 +## 1.3.2 Set a default auth method and actually set a default user and password Add the auth method to the config template -# 1.3.1 +## 1.3.1 GA release 1.2.10 is the default version now Set Orchestrator to read only by default Use local template variables in the config file Moved the minitest file location to match more recent versions of chef-minitest -# 1.3.0 +## 1.3.0 Refactored installation into a package recipe Made the version an attribute Use the service resource to manage Orchestrator (Thanks Shlomi for adding the init script) -# 1.2.0 +## 1.2.0 Added minitests -# 1.1.1 +## 1.1.1 Chefspec passes and 100% coverage -# 1.1.0 +## 1.1.0 Added Chefspec tests -# 1.0.0 +## 1.0.0 First real release. Now converged for both centos and Ubuntu -# 0.1.0 +## 0.1.0 Initial release of chef-orchestrator diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..b4a6524 --- /dev/null +++ b/Gemfile @@ -0,0 +1,17 @@ +source 'https://rubygems.org' + +gem 'berkshelf', '= 5.6.4' +gem 'chef', ' ~> 13' +gem 'foodcritic' +gem 'rake' +gem 'rubocop' + +group :integration do + gem 'kitchen-inspec' + gem 'test-kitchen' +end + +group :vagrant do + gem 'kitchen-vagrant' + gem 'vagrant-wrapper' +end diff --git a/README.md b/README.md index dc71b1f..ffec474 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,37 @@ +# chef-orchestrator-cookbook + +This cookbook sets up and runs [mysql-orchestror](https://github.com/github/orchestrator/). + [![Code Climate](https://codeclimate.com/github/silviabotros/chef-orchestrator/badges/gpa.svg)](https://codeclimate.com/github/silviabotros/chef-orchestrator) [![Issue Count](https://codeclimate.com/github/silviabotros/chef-orchestrator/badges/issue_count.svg)](https://codeclimate.com/github/silviabotros/chef-orchestrator) -# chef-orchestrator-cookbook - This cookbook sets up and runs mysql-orchestror (https://github.com/github/orchestrator/). +## Presumptions -## Presumptions: - The backend mysql for orchestrator is going to run on the same server as orchestrator itself -- That backend DB is going to use Percona MySQL which is setup using the chef-percona cookbook by Philiper (https://github.com/phlipper/chef-percona.git) -- That you, the end user, own adding privileges for orchestrator to access your existing DB infrastructure +- That backend DB is going to use Percona MySQL which is setup using the [chef-percona](https://github.com/phlipper/chef-percona) cookbook by [Philiper](https://github.com/phlipper) +- That you, the end user, own adding privileges for orchestrator to access your existing DB infrastructure - That you wrap this cookbook to use the CLI and add your production databases for discovery ## Supported Platforms -Tested with + - Centos 6.5 - Ubuntu 12.04 ## Attributes - - - - - - - - - - - - - -
KeyTypeDescriptionDefault
['orchestrator']['bacon']Booleanwhether to include bacontrue
+| Key | Type | Description | Default | +| --- | ---- | ----------- | ------- | +| ['orchestrator']['package']['version'] | nil | string | version to install, nil provides latest (and will upgrade) | +| ['orchestrator']['package']['url'] | nil | string | URL to download the RPM from | +| ['orchestrator']['package']['checksum'] | nil | string | Checksum for the file provided by URL | ## Usage +### Installation + +Starting in version _2.1.0_, the orchestrator cookbook now respects the `version` attribute. If set to `nil` (the default), the cookbook will perform the same steps as previous versions -- always upgrade to the latest version available via the repos available on a node. +Setting this attribute to a specific package version will result in that version being installed. If you want to install the package from an internal source, you can also specify the url and optional checksum to download the orchestrator package. + ### orchestrator::default Include `orchestrator` in your node's `run_list`: @@ -49,11 +47,11 @@ Include `orchestrator` in your node's `run_list`: ## Contributing 1. Fork the repository on Github -2. Create a named feature branch (i.e. `add-new-recipe`) -3. Write your change -4. Write tests for your change (if applicable) -5. Run the tests, ensuring they all pass -6. Submit a Pull Request +1. Create a named feature branch (i.e. `add-new-recipe`) +1. Write your change +1. Write tests for your change (if applicable) +1. Run the tests, ensuring they all pass +1. Submit a Pull Request ## License and Authors diff --git a/Rakefile b/Rakefile new file mode 100755 index 0000000..2483c0c --- /dev/null +++ b/Rakefile @@ -0,0 +1,70 @@ +#!/usr/bin/env rake +require 'rake' + +begin + require 'rspec/core/rake_task' + RSpec::Core::RakeTask.new(:spec) +rescue LoadError + warn 'It looks like the Chef DK is not configured. Download the Chef DK'\ + " via\nhttps://downloads.chef.io/chefdk. On Linux and"\ + " Mac OS X\nadd to $PATH with:\n"\ + ' eval "$(chef shell-init $SHELL)"' +end + +begin + require 'rubocop/rake_task' + RuboCop::RakeTask.new do |task| + task.fail_on_error = true + task.options = %w(--display-cop-names -c .rubocop.yml) + end +rescue LoadError + warn '>>>>> Rubocop gem not loaded, omitting tasks' +end + +begin + require 'foodcritic/rake_task' + require 'foodcritic' + task default: [:foodcritic] + FoodCritic::Rake::LintTask.new do |task| + task.options = { + fail_tags: ['any'] + } + end +rescue LoadError + warn '>>>>> foodcritic gem not loaded, omitting tasks' +end + +task default: 'test:quick' +namespace :test do + desc 'Run all the quick tests' + task :quick do + Rake::Task['rubocop'].invoke + Rake::Task['foodcritic'].invoke + Rake::Task['spec'].invoke + Rake::Task['kitchen:verify'].invoke + end +end + +namespace :kitchen do + desc 'converge' + task :converge do + sh 'kitchen converge' + end + desc 'debug' + task :converge do + sh 'kitchen converge -l debug' + end + desc 'run serverspec tests' + task :verify do + Rake::Task['kitchen:converge'].invoke + sh 'kitchen verify' + end + desc 'run serverspec tests and destroy if successful' + task :test do + sh 'kitchen test' + end + desc 'destroy test kitchen vms' + task :destroy do + sh 'kitchen destroy' + end +end diff --git a/Thorfile b/Thorfile deleted file mode 100644 index 0dfd835..0000000 --- a/Thorfile +++ /dev/null @@ -1,13 +0,0 @@ -# encoding: utf-8 - -require 'bundler' -require 'bundler/setup' -require 'thor/foodcritic' -require 'berkshelf/thor' - -begin - require 'kitchen/thor_tasks' - Kitchen::ThorTasks.new -rescue LoadError - puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI'] -end diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index dead9f2..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,85 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! -VAGRANTFILE_API_VERSION = '2' - -Vagrant.require_version '>= 1.5.0' - -Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - # All Vagrant configuration is done here. The most common configuration - # options are documented and commented below. For a complete reference, - # please see the online documentation at vagrantup.com. - - config.vm.hostname = 'chef-orchestrator-berkshelf' - - # Set the version of chef to install using the vagrant-omnibus plugin - config.omnibus.chef_version = :latest - - # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = 'opscode_ubuntu-12.04_provisionerless' - - # The url from where the 'config.vm.box' box will be fetched if it - # doesn't already exist on the user's system. - config.vm.box_url = 'https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box' - - # Assign this VM to a host-only network IP, allowing you to access it - # via the IP. Host-only networks can talk to the host machine as well as - # any other machines on the same network, but cannot be accessed (through this - # network interface) by any external networks. - config.vm.network :private_network, type: 'dhcp' - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. - - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - # config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - # config.vm.provider :virtualbox do |vb| - # # Don't boot with headless mode - # vb.gui = true - # - # # Use VBoxManage to customize the VM. For example to change memory: - # vb.customize ["modifyvm", :id, "--memory", "1024"] - # end - # - # View the documentation for the provider you're using for more - # information on available options. - - # The path to the Berksfile to use with Vagrant Berkshelf - # config.berkshelf.berksfile_path = "./Berksfile" - - # Enabling the Berkshelf plugin. To enable this globally, add this configuration - # option to your ~/.vagrant.d/Vagrantfile file - config.berkshelf.enabled = true - - # An array of symbols representing groups of cookbook described in the Vagrantfile - # to exclusively install and copy to Vagrant's shelf. - # config.berkshelf.only = [] - - # An array of symbols representing groups of cookbook described in the Vagrantfile - # to skip installing and copying to Vagrant's shelf. - # config.berkshelf.except = [] - - config.vm.provision :chef_solo do |chef| - chef.json = { - mysql: { - server_root_password: 'rootpass', - server_debian_password: 'debpass', - server_repl_password: 'replpass' - } - } - - chef.run_list = [ - 'recipe[chef-orchestrator::default]' - ] - end -end diff --git a/attributes/default.rb b/attributes/default.rb index 245a5f1..b4cd1ea 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,23 +1,39 @@ +# Percona include_attribute 'percona' default['percona']['skip_configure'] = true default['percona']['skip_passwords'] = true -default['orchestrator']['package']['version'] = '1.2.10' +default['percona']['apt']['key'] = '9334A25F8507EFA5' +default['percona']['apt']['keyserver'] = 'hkp://keyserver.ubuntu.com' +default['percona']['apt']['uri'] = 'https://repo.percona.com/apt' +default['percona']['use_chef_vault'] = false + +# keyserver +# Orchestrator +default['orchestrator']['path'] = '/usr/local/orchestrator' +default['orchestrator']['config']['AuditPageSize'] = 20 +default['orchestrator']['config']['AuthenticationMethod'] = 'Basic' +default['orchestrator']['config']['DiscoverByShowSlaveHosts'] = true +default['orchestrator']['config']['HTTPAuthPassword'] = 'secret' +default['orchestrator']['config']['HTTPAuthUser'] = 'admin' +default['orchestrator']['config']['HostnameResolveMethod'] = '@@hostname' +default['orchestrator']['config']['InstancePollSeconds'] = 60 default['orchestrator']['config']['ListenAddress'] = ':3000' -default['orchestrator']['root_db_pass'] = '' default['orchestrator']['config']['MySQLOrchestratorDatabase'] = 'orchestrator' -default['orchestrator']['config']['MySQLTopologyUser'] = 'orchestrator' -default['orchestrator']['config']['MySQLTopologyPassword'] = 'fakepass' -default['orchestrator']['config']['MySQLOrchestratorUser'] = 'orchestrator' default['orchestrator']['config']['MySQLOrchestratorPassword'] = 'fakerpass' -default['orchestrator']['config']['DiscoverByShowSlaveHosts'] = true -default['orchestrator']['config']['InstancePollSeconds'] = 60 -default['orchestrator']['config']['UnseenInstanceForgetHours'] = 240 -default['orchestrator']['config']['ReasonableReplicationLagSeconds'] = 10 +default['orchestrator']['config']['MySQLOrchestratorUser'] = 'orchestrator' +default['orchestrator']['config']['MySQLTopologyPassword'] = 'fakepass' +default['orchestrator']['config']['MySQLTopologyUser'] = 'orchestrator' +default['orchestrator']['config']['ReadOnly'] = true default['orchestrator']['config']['ReasonableMaintenanceReplicationLagSeconds'] = 20 -default['orchestrator']['config']['AuditPageSize'] = 20 +default['orchestrator']['config']['ReasonableReplicationLagSeconds'] = 10 default['orchestrator']['config']['SlaveStartPostWaitMilliseconds'] = 1000 -default['orchestrator']['config']['AuthenticationMethod'] = 'Basic' -default['orchestrator']['config']['HTTPAuthUser'] = 'admin' -default['orchestrator']['config']['HTTPAuthPassword'] = 'secret' -default['orchestrator']['config']['ReadOnly'] = true -default['orchestrator']['config']['HostnameResolveMethod'] = '@@hostname' +default['orchestrator']['config']['UnseenInstanceForgetHours'] = 240 +default['orchestrator']['root_db_pass'] = 'snakeoil' + +# leaving this set to 'nil' will set the package install to always "upgrade" to the latest version available. +# set this to a specific version in your wrapper-cookbook if you need a specific one. +default['orchestrator']['package'] = { + version: nil, + url: nil, + checksum: nil +} diff --git a/files/default/tests/default_test.rb b/files/default/tests/default_test.rb deleted file mode 100644 index 791e537..0000000 --- a/files/default/tests/default_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'minitest/spec' -require 'chef/mixin/shell_out' -# -# Cookbook Name:: orchestrator -# Spec:: default -# - -describe_recipe 'orchestrator::default' do - include Chef::Mixin::ShellOut - include Minitest::Chef::Assertions - include Minitest::Chef::Context - include Minitest::Chef::Resources - - describe 'runs orchestrator' do - it 'is running mysql' do - service('mysql').must_be_running - end - it 'has an orchestrator db' do - assert_sh('mysql -e "show databases" | grep orchestrator') - end - it 'has an orchestrator user' do - assert_sh('mysql -e "select user from mysql.user" | grep orchestrator') - end - it 'installs orchestrator' do - skip if node['orchestrator']['cli_only'] - package('orchestrator').must_be_installed - end - it 'installs just the CLI package' do - skip unless node['orchestrator']['cli_only'] - package('orchestrator-cli').must_be_installed - end - it 'creates the cfg file' do - file('/etc/orchestrator.conf.json').must_exist - end - it 'removes the packaged cfg file' do - file('/usr/local/orchestrator/conf/orchestrator.conf.json').wont_exist - end - it 'has a process named orchestrator running' do - assert_sh('ps aux | grep orchestrator | grep -v grep') - end - end -end diff --git a/libraries/helpers.rb b/libraries/helpers.rb new file mode 100644 index 0000000..1b69f08 --- /dev/null +++ b/libraries/helpers.rb @@ -0,0 +1,4 @@ + +def centos? + node['platform'] == 'centos' +end diff --git a/metadata.rb b/metadata.rb index 0b3cef0..2c69386 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,15 +1,21 @@ name 'orchestrator' maintainer 'Silvia Botros' maintainer_email 'silvia.botros@sendgrid.com' -license 'All rights reserved' +license 'Apache-2.0' description 'Installs/Configures chef-orchestrator' long_description 'Installs/Configures chef-orchestrator' -version '2.0.2' +source_url 'https://github.com/silviabotros/chef-orchestrator' +issues_url 'https://github.com/silviabotros/chef-orchestrator/issues' +chef_version '>= 12.5.0' +version '2.1.0' -depends 'yum' +depends 'apt' +depends 'build-essential' +depends 'database', '~> 6.1' depends 'packagecloud' -depends 'database', '~> 2.0' -depends 'percona', '~> 0.15.0' +depends 'percona', '~> 0.16' +depends 'yum' +depends 'yum-epel', '~> 2.1' supports 'centos' -supports 'ubuntu' +supports 'debian' diff --git a/recipes/_database_setup.rb b/recipes/_database_setup.rb index 7ae9b09..414ea8f 100644 --- a/recipes/_database_setup.rb +++ b/recipes/_database_setup.rb @@ -17,10 +17,26 @@ # limitations under the License. # +if node['platform_family'] == 'debian' + include_recipe 'apt' + execute 'add percona apt key' do + command 'apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9334A25F8507EFA5 && apt-get update' + not_if 'apt-key list | grep -i percona' + end +end + +include_recipe 'build-essential' include_recipe 'percona::server' include_recipe 'percona::client' -execute 'set root pass' do #~FC037 +package case node['platform_family'] + when 'rhel' + %w(ruby ruby-devel rubygems binutils) + when 'debian' + %w(ruby ruby-dev libperconaserverclient18.1-dev) + end + +execute 'set root pass' do # ~FC037 command "mysqladmin -u root password \"#{node['orchestrator']['root_db_pass']}\"" retries 5 only_if "mysql -u root -e 'show databases'" @@ -28,20 +44,17 @@ subscribes :start, 'service[mysql]' end -case node['platform'] -when 'debian', 'ubuntu' - package 'build-essential' -when 'redhat', 'centos', 'fedora' - package 'gcc' +gem_package 'mysql2' do + options '-- --with-mysql-dir=/usr' # if node['platform_family'] == 'rhel' end -gem_package 'mysql' +# for the database cookbook +chef_gem 'mysql2' service 'mysql' do action [:enable, :start] end -include_recipe 'database' mysql_connection_info = { host: 'localhost', port: 3306, @@ -54,7 +67,7 @@ action :create end -mysql_database_user node['orchestrator']['config']['MySQLOrchestratorUser'] do +mysql_database_user node['orchestrator']['config']['MySQLOrchestratorUser'] do connection mysql_connection_info password node['orchestrator']['config']['MySQLOrchestratorPassword'] host 'localhost' diff --git a/recipes/_package.rb b/recipes/_package.rb index 6f73257..0633c90 100644 --- a/recipes/_package.rb +++ b/recipes/_package.rb @@ -18,6 +18,21 @@ # include_recipe 'orchestrator::_database_setup' + +local_rpm = nil + +if centos? && !node['orchestrator']['package']['url'].nil? + local_rpm = File.join(Chef::Config['file_cache_path'], 'orchestrator.rpm') + remote_file local_rpm do + source node['orchestrator']['package']['url'] + checksum node['orchestrator']['package']['checksum'] + action :create_if_missing if node['orchestrator']['package']['checksum'].nil? + notifies :install, 'package[orchestrator]', :immediately + end +end + package 'orchestrator' do - action :upgrade + source local_rpm if centos? && !local_rpm.nil? + version node['orchestrator']['package']['version'] if centos? && !node['orchestrator']['package']['version'].nil? + action node['orchestrator']['package']['version'].nil? ? :upgrade : :install end diff --git a/recipes/default.rb b/recipes/default.rb index 41324da..3584a1b 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -16,25 +16,23 @@ # See the License for the specific language governing permissions and # limitations under the License. - -packagecloud_repo "github/orchestrator" +packagecloud_repo 'github/orchestrator' include_recipe 'orchestrator::_package' chef_gem 'json' -ruby_block 'create the config file from hash' do - block do - File.open("/etc/orchestrator.conf.json", "w") do |f| - f.write(JSON.pretty_generate(node['orchestrator']['config'])) - end - end +file '/etc/orchestrator.conf.json' do + sensitive true + content JSON.pretty_generate(node['orchestrator']['config']) end -file '/usr/local/orchestrator/conf/orchestrator.conf.json' do +# clean up config from legacy config path +file File.join(node['orchestrator']['path'], 'conf', 'orchestrator.conf.json') do action :delete end service 'orchestrator' do + provider Provider::Service::Redhat if centos? action :start end diff --git a/test/integration/default/default.rb b/test/integration/default/default.rb new file mode 100644 index 0000000..28d674f --- /dev/null +++ b/test/integration/default/default.rb @@ -0,0 +1,20 @@ + +control 'mysql is running' do + describe service('mysql') do + it { should be_running } + end +end + +sql = mysql_session('root', 'snakeoil') + +control 'database exists' do + describe sql.query('show databases like \'orchestrator\';') do + its('stdout') { should match(/orchestrator/) } + end +end + +control 'database user' do + describe sql.query('select user from mysql.user;') do + its('stdout') { should match(/orchestrator/) } + end +end diff --git a/test/integration/default/orchestrator.rb b/test/integration/default/orchestrator.rb new file mode 100644 index 0000000..b0fc084 --- /dev/null +++ b/test/integration/default/orchestrator.rb @@ -0,0 +1,39 @@ + +control 'orchestrator' do + describe package('orchestrator') do + it { should be_installed } + end +end + +control 'orchestator config' do + describe file '/etc/orchestrator.conf.json' do + it { should be_file } + its(:owner) { should eq 'root' } + its(:group) { should eq 'root' } + end + + describe json('/etc/orchestrator.conf.json') do + its(['DiscoverByShowSlaveHosts']) { should eq true } + its(['HTTPAuthPassword']) { should eq 'secret' } + its(['HTTPAuthUser']) { should eq 'admin' } + its(['HostnameResolveMethod']) { should eq '@@hostname' } + its(['InstancePollSeconds']) { should eq 60 } + its(['ListenAddress']) { should eq ':3000' } + its(['MySQLOrchestratorDatabase']) { should eq 'orchestrator' } + its(['MySQLOrchestratorPassword']) { should eq 'fakerpass' } + its(['MySQLOrchestratorUser']) { should eq 'orchestrator' } + its(['MySQLTopologyPassword']) { should eq 'fakepass' } + its(['MySQLTopologyUser']) { should eq 'orchestrator' } + its(['ReadOnly']) { should eq true } + its(['ReasonableMaintenanceReplicationLagSeconds']) { should eq 20 } + its(['ReasonableReplicationLagSeconds']) { should eq 10 } + its(['SlaveStartPostWaitMilliseconds']) { should eq 1000 } + its(['UnseenInstanceForgetHours']) { should eq 240 } + its(['AuditPageSize']) { should eq 20 } + its(['AuthenticationMethod']) { should eq 'Basic' } + end + + describe service('orchestrator') do + it { should be_running } + end +end