diff --git a/README.md b/README.md new file mode 100644 index 0000000..bb82365 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Detached watcher role +Plugin to deploy watcher on separate node diff --git a/deployment_scripts/manifests/watcher.pp b/deployment_scripts/manifests/watcher.pp new file mode 100644 index 0000000..a685634 --- /dev/null +++ b/deployment_scripts/manifests/watcher.pp @@ -0,0 +1,141 @@ +notice('MODULAR: watcher/watcher.pp') + +prepare_network_config(hiera_hash('network_scheme', {})) + +$watcher_hash = hiera_hash('watcher_plugin', {}) +$watcher_plugins = pick($watcher_hash['plugins'], {}) +$rabbit_hash = hiera_hash('rabbit', {}) +$neutron_config = hiera_hash('neutron_config', {}) +$public_ssl_hash = hiera_hash('public_ssl', {}) +$ssl_hash = hiera_hash('use_ssl', {}) +$external_dns = hiera_hash('external_dns', {}) +$primary_watcher = roles_include(['primary-watcher-node', 'primary-controller']) +$public_ip = hiera('public_vip') +$database_ip = hiera('database_vip') +$management_ip = hiera('management_vip') +$region = hiera('region', 'RegionOne') +$use_neutron = hiera('use_neutron', false) +$service_endpoint = hiera('service_endpoint') +$syslog_log_facility_watcher = hiera('syslog_log_facility_watcher') +$debug = pick($watcher_hash['debug'], hiera('debug', false)) +$verbose = pick($watcher_hash['verbose'], hiera('verbose', true)) +$default_log_levels = hiera_hash('default_log_levels', {}) +$use_syslog = hiera('use_syslog', true) +$use_stderr = hiera('use_stderr', false) +$rabbit_ha_queues = hiera('rabbit_ha_queues', false) +$amqp_port = hiera('amqp_port') +$amqp_hosts = hiera('amqp_hosts') + +$internal_auth_protocol = get_ssl_property($ssl_hash, {}, 'keystone', 'internal', 'protocol', 'http') +$internal_auth_address = get_ssl_property($ssl_hash, {}, 'keystone', 'internal', 'hostname', [hiera('keystone_endpoint', ''), $service_endpoint, $management_ip]) +$admin_auth_protocol = get_ssl_property($ssl_hash, {}, 'keystone', 'admin', 'protocol', 'http') +$admin_auth_address = get_ssl_property($ssl_hash, {}, 'keystone', 'admin', 'hostname', [hiera('keystone_endpoint', ''), $service_endpoint, $management_ip]) +$api_bind_host = get_network_role_property('management', 'ipaddr') + +$region_name = pick(hiera('region_name'), 'RegionOne') + +$firewall_rule = '214 watcher-api' +$api_bind_port = '9322' + +$watcher_user = pick($watcher_hash['user'], 'watcher') +$watcher_password = $watcher_hash['user_password'] + +$mysql_hash = hiera_hash('mysql', {}) +$mysql_root_password = $mysql_hash['root_password'] + +$db_type = 'mysql' +$db_user = pick($watcher_hash['db_user'], 'watcher') +$db_name = pick($watcher_hash['db_name'], 'watcher') +$db_password = pick($watcher_hash['root_password'], $mysql_root_password) +$db_host = pick($watcher_hash['db_host'], $database_ip) +# LP#1526938 - python-mysqldb supports this, python-pymysql does not +if $::os_package_type == 'debian' { + $extra_params = { 'charset' => 'utf8', 'read_timeout' => 60 } +} else { + $extra_params = { 'charset' => 'utf8' } +} +$db_connection = os_database_connection({ + 'dialect' => $db_type, + 'host' => $db_host, + 'database' => $db_name, + 'username' => $db_user, + 'password' => $db_password, + 'extra' => $extra_params +}) + +notice($db_connection) + +####### Disable upstart startup on install ####### +tweaks::ubuntu_service_override { ['watcher-api', 'watcher-engine']: + package_name => 'watcher', +} + +include ::firewall +firewall { $firewall_rule : + dport => $api_bind_port, + proto => 'tcp', + action => 'accept', +} + +$nova_scheduler_default_filters = 'RetryFilter,AvailabilityZoneFilter,AggregateRamFilter,AggregateCoreFilter,DiskFilter,ComputeFilter,AggregateInstanceExtraSpecsFilter,ImagePropertiesFilter,ServerGroupAntiAffinityFilter,ServerGroupAffinityFilter,AggregateMetaDataIsolation' +$nova_ram_allocation_ratio = '1.5' +$nova_scheduler_driver = 'nova.scheduler.filter_scheduler.FilterScheduler' +$nova_disk_allocation_ratio = '1.0' +$nova_cpu_allocation_ratio = '8.0' +$nova_max_instances_per_host = '50' +$nova_scheduler_available_filters = 'nova.scheduler.filters.all_filters' + +class { '::watcher' : + ensure_package => 'latest', + database_connection => $db_connection, + notification_driver => 'messagingv2', + password => $watcher_password, + username => $watcher_user, + admin_user => $watcher_user, + admin_password => $watcher_password, + auth_uri => "${internal_auth_protocol}://${internal_auth_address}:5000/", + auth_url => "${admin_auth_protocol}://${admin_auth_address}:35357/v3", + identity_uri => "${internal_auth_protocol}://${internal_auth_address}:35357/", + region_name => $region_name, + rabbit_os_host => $amqp_hosts, + rabbit_os_user => $rabbit_hash['user'], + rabbit_os_password => $rabbit_hash['password'], + rabbit_ha_queues => true, + nova_scheduler_default_filters => $nova_scheduler_default_filters, + nova_ram_allocation_ratio => $nova_ram_allocation_ratio, + nova_scheduler_driver => $nova_scheduler_driver, + nova_disk_allocation_ratio => $nova_disk_allocation_ratio, + nova_cpu_allocation_ratio =>$nova_cpu_allocation_ratio, + nova_max_instances_per_host => $nova_max_instances_per_host, + nova_scheduler_available_filters => $nova_scheduler_available_filters, +} + +class { '::watcher::api': + watcher_client_auth_uri => "${internal_auth_protocol}://${internal_auth_address}:5000/", + watcher_client_auth_url => "${admin_auth_protocol}://${admin_auth_address}:35357/", + watcher_client_username => $watcher_user, + watcher_client_password => $watcher_password, + watcher_api_bind_host => $api_bind_host, + watcher_api_port => $api_bind_port, + package_ensure => 'latest', + create_db_schema => true, + upgrade_db => true +} + +class { '::watcher::applier' : + package_ensure => 'latest', +} + +class { '::watcher::decision_engine' : + package_ensure => 'latest', + planner => 'forced_order', +} + +#class { '::watcher::policy': } + +package { 'python-watcherclient': + ensure => 'latest', + tag => ['openstack', 'watcher-package'], +} + +Firewall[$firewall_rule] -> Class['watcher::api'] diff --git a/deployment_scripts/manifests/watcher_db.pp b/deployment_scripts/manifests/watcher_db.pp new file mode 100644 index 0000000..10b07d8 --- /dev/null +++ b/deployment_scripts/manifests/watcher_db.pp @@ -0,0 +1,45 @@ +notice('MODULAR: watcher/watcher_db.pp') + +$watcher_hash = hiera_hash('watcher_plugin', {}) +$mysql_hash = hiera_hash('mysql', {}) +$management_vip = hiera('management_vip', undef) +$database_vip = hiera('database_vip') + +$mysql_root_user = pick($mysql_hash['root_user'], 'root') +$mysql_db_create = pick($mysql_hash['db_create'], true) +$mysql_root_password = $mysql_hash['root_password'] + +$db_user = pick($watcher_hash['db_user'], 'watcher') +$db_name = pick($watcher_hash['db_name'], 'watcher') +$db_password = pick($watcher_hash['db_password'], $mysql_root_password) + +$db_host = pick($watcher_hash['db_host'], $database_vip) +$db_create = pick($watcher_hash['db_create'], $mysql_db_create) +$db_root_user = pick($watcher_hash['root_user'], $mysql_root_user) +$db_root_password = pick($watcher_hash['root_password'], $mysql_root_password) + +$allowed_hosts = [ 'localhost', '127.0.0.1', '%' ] + +class { '::openstack::galera::client': + custom_setup_class => hiera('mysql_custom_setup_class', 'galera'), +} + +class { 'watcher::db::mysql': + user => $db_user, + password => $db_password, + dbname => $db_name, + allowed_hosts => $allowed_hosts, +} + +class { 'osnailyfacter::mysql_access': + db_host => $db_host, + db_user => $db_root_user, + db_password => $db_root_password, +} + +Class['openstack::galera::client'] -> + Class['osnailyfacter::mysql_access'] -> + Class['watcher::db::mysql'] + +class mysql::server {} +include mysql::server \ No newline at end of file diff --git a/deployment_scripts/manifests/watcher_haproxy.pp b/deployment_scripts/manifests/watcher_haproxy.pp new file mode 100644 index 0000000..68f207c --- /dev/null +++ b/deployment_scripts/manifests/watcher_haproxy.pp @@ -0,0 +1,39 @@ +notice('MODULAR: watcher/watcher_haproxy.pp') + +$watcher_hash = hiera_hash('watcher_plugin',{}) +$public_ssl_hash = hiera_hash('public_ssl', {}) +$ssl_hash = hiera_hash('use_ssl', {}) +$external_lb = hiera('external_lb', false) + +if (!$external_lb) { + $public_ssl = get_ssl_property($ssl_hash, $public_ssl_hash, 'watcher', 'public', 'usage', false) + $public_ssl_path = get_ssl_property($ssl_hash, $public_ssl_hash, 'watcher', 'public', 'path', ['']) + $internal_ssl = get_ssl_property($ssl_hash, {}, 'watcher', 'internal', 'usage', false) + $internal_ssl_path = get_ssl_property($ssl_hash, {}, 'watcher', 'internal', 'path', ['']) + + $server_names = $watcher_hash['watcher_nodes'] + $ipaddresses = $watcher_hash['watcher_ipaddresses'] + $public_virtual_ip = hiera('public_vip') + $internal_virtual_ip = hiera('management_vip') + + Openstack::Ha::Haproxy_service { + internal_virtual_ip => $internal_virtual_ip, + ipaddresses => $ipaddresses, + public_virtual_ip => $public_virtual_ip, + server_names => $server_names, + public => true, + } + + openstack::ha::haproxy_service { 'watcher-api': + order => '214', + listen_port => 9322, + public_ssl => $public_ssl, + public_ssl_path => $public_ssl_path, + internal_ssl => $internal_ssl, + internal_ssl_path => $internal_ssl_path, + require_service => 'watcher_api', + haproxy_config_options => { + 'http-request' => 'set-header X-Forwarded-Proto https if { ssl_fc }', + }, + } +} diff --git a/deployment_scripts/manifests/watcher_hiera_override.pp b/deployment_scripts/manifests/watcher_hiera_override.pp new file mode 100644 index 0000000..5d24551 --- /dev/null +++ b/deployment_scripts/manifests/watcher_hiera_override.pp @@ -0,0 +1,66 @@ +notice('MODULAR: watcher/watcher_hiera_override.pp') + +$watcher_plugin = hiera('fuel-plugin-watcher', undef) +$hiera_dir = '/etc/hiera/plugins' +$plugin_name = 'fuel-plugin-watcher' +$plugin_yaml = "${plugin_name}.yaml" + +if $watcher_plugin { + $network_metadata = hiera_hash('network_metadata') + $watcher_base_hash = hiera_hash('watcher', {}) + $user_password = $watcher_plugin['user_password'] + $watcher_role_exists = empty(nodes_with_roles(['primary-watcher-node'])) ? { + true => false, + default => true, + } + if $watcher_role_exists { + $watcher_nodes = get_nodes_hash_by_roles($network_metadata, ['primary-watcher-node', 'watcher-node']) + $watcher_address_map = get_node_to_ipaddr_map_by_network_role($watcher_nodes, 'management') + $watcher_nodes_ips = values($watcher_address_map) + $watcher_nodes_names = keys($watcher_address_map) + } else { + $watcher_nodes = get_nodes_hash_by_roles($network_metadata, ['primary-controller', 'controller']) + $watcher_address_map = get_node_to_ipaddr_map_by_network_role($watcher_nodes, 'management') + $watcher_nodes_ips = values($watcher_address_map) + $watcher_nodes_names = keys($watcher_address_map) + } + + $syslog_log_facility_watcher = hiera('syslog_log_facility_watcher', 'LOG_LOCAL0') + $default_log_levels = hiera('default_log_levels') + + ################### + $calculated_content = inline_template(' +watcher_plugin: + user_password: <%= @user_password %> + watcher_standalone: <%= @watcher_role_exists %> + watcher_ipaddresses: +<% +@watcher_nodes_ips.each do |watcherip| +%> - <%= watcherip %> +<% end -%> + watcher_nodes: +<% +@watcher_nodes_names.each do |watchername| +%> - <%= watchername %> +<% end -%> +syslog_log_facility_watcher: <%= @syslog_log_facility_watcher %> +"watcher::logging::default_log_levels": +<% +@default_log_levels.each do |k,v| +%> <%= k %>: <%= v %> +<% end -%> +') + + ################### + file {'/etc/hiera/override': + ensure => directory, + } -> + file { "${hiera_dir}/${plugin_yaml}": + ensure => file, + content => "${calculated_content}", + } + + package {'ruby-deep-merge': + ensure => 'installed', + } +} diff --git a/deployment_scripts/manifests/watcher_keystone.pp b/deployment_scripts/manifests/watcher_keystone.pp new file mode 100644 index 0000000..4d8d65d --- /dev/null +++ b/deployment_scripts/manifests/watcher_keystone.pp @@ -0,0 +1,33 @@ +notice('watcher PLUGIN: watcher_keystone.pp') + +$watcher_hash = hiera_hash('watcher_plugin', {}) +$public_ip = hiera('public_vip') +$management_ip = hiera('management_vip') +$region = hiera('region', 'RegionOne') +$public_ssl_hash = hiera('public_ssl') +$ssl_hash = hiera_hash('use_ssl', {}) + +$public_protocol = get_ssl_property($ssl_hash, $public_ssl_hash, 'watcher', 'public', 'protocol', 'http') +$public_address = get_ssl_property($ssl_hash, $public_ssl_hash, 'watcher', 'public', 'hostname', [$public_ip]) +$internal_protocol = get_ssl_property($ssl_hash, {}, 'watcher', 'internal', 'protocol', 'http') +$internal_address = get_ssl_property($ssl_hash, {}, 'watcher', 'internal', 'hostname', [$management_ip]) +$admin_protocol = get_ssl_property($ssl_hash, {}, 'watcher', 'admin', 'protocol', 'http') +$admin_address = get_ssl_property($ssl_hash, {}, 'watcher', 'admin', 'hostname', [$management_ip]) + +$api_bind_port = '9322' +$tenant = pick($watcher_hash['tenant'], 'services') +$public_url = "${public_protocol}://${public_address}:${api_bind_port}" +$internal_url = "${internal_protocol}://${internal_address}:${api_bind_port}" +$admin_url = "${admin_protocol}://${admin_address}:${api_bind_port}" + +class {'::osnailyfacter::wait_for_keystone_backends':} +class { 'watcher::keystone::auth': + password => pick($watcher_hash['user_password'], 'watcher'), + region => $region, + tenant => $tenant, + public_url => $public_url, + internal_url => $internal_url, + admin_url => $admin_url, +} + +Class['::osnailyfacter::wait_for_keystone_backends'] -> Class['watcher::keystone::auth'] diff --git a/deployment_scripts/manifests/watcher_logging.pp b/deployment_scripts/manifests/watcher_logging.pp new file mode 100644 index 0000000..733fe15 --- /dev/null +++ b/deployment_scripts/manifests/watcher_logging.pp @@ -0,0 +1,13 @@ +notice('MODULAR: watcher/watcher_logging.pp') + +$content=':syslogtag, contains, "watcher" -/var/log/watcher-all.log +### stop further processing for the matched entries +& ~' + +include ::rsyslog::params + +::rsyslog::snippet { '57-watcher': + content => $content, +} + +Rsyslog::Snippet['57-watcher'] ~> Service[$::rsyslog::params::service_name] diff --git a/deployment_scripts/manifests/watcher_pin_plugin_repo.pp b/deployment_scripts/manifests/watcher_pin_plugin_repo.pp new file mode 100644 index 0000000..285a71b --- /dev/null +++ b/deployment_scripts/manifests/watcher_pin_plugin_repo.pp @@ -0,0 +1,15 @@ +notice('MODULAR: watcher/watcher_pin_plugin_repo.pp') + +$master_ip = pick(hiera('master_ip'), 'localhost') +$location = "http://${master_ip}:8080/watcher" + +apt::source { 'watcher': + location => $location, + release => 'mos9.0-watcher', + repos => 'main', +} + +apt::pin { 'watcher': + release => 'mos9.0-watcher', + priority => 1300, +} \ No newline at end of file diff --git a/deployment_scripts/manifests/watcher_timezone.pp b/deployment_scripts/manifests/watcher_timezone.pp new file mode 100644 index 0000000..a8f9bf6 --- /dev/null +++ b/deployment_scripts/manifests/watcher_timezone.pp @@ -0,0 +1,6 @@ +notice('MODULAR: watcher/watcher_timezone.pp') + +#TODO: customize timezone +exec {'moscow_timezone': + command => '/usr/bin/timedatectl set-timezone Europe/Moscow' +} ~> service { 'rsyslog': } diff --git a/deployment_scripts/modules/watcher/Gemfile b/deployment_scripts/modules/watcher/Gemfile new file mode 100644 index 0000000..a87f006 --- /dev/null +++ b/deployment_scripts/modules/watcher/Gemfile @@ -0,0 +1,21 @@ +source ENV['GEM_SOURCE'] || "https://rubygems.org" + +group :development, :test, :system_tests do + gem 'puppet-openstack_spec_helper', + :git => 'https://git.openstack.org/openstack/puppet-openstack_spec_helper', + :require => 'false' +end + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion, :require => false +else + gem 'facter', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/deployment_scripts/modules/watcher/LICENSE b/deployment_scripts/modules/watcher/LICENSE new file mode 100644 index 0000000..e7cb8c0 --- /dev/null +++ b/deployment_scripts/modules/watcher/LICENSE @@ -0,0 +1,14 @@ +Copyright 2016 OVH Group +Copyright 2016 OpenStack Foundation + +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/deployment_scripts/modules/watcher/README.md b/deployment_scripts/modules/watcher/README.md new file mode 100644 index 0000000..4cb50a7 --- /dev/null +++ b/deployment_scripts/modules/watcher/README.md @@ -0,0 +1,85 @@ +Team and repository tags +======================== + +[![Team and repository tags](http://governance.openstack.org/badges/puppet-watcher.svg)](http://governance.openstack.org/reference/tags/index.html) + + + +watcher +======= + +#### Table of Contents + +1. [Overview - What is the watcher module?](#overview) +2. [Module Description - What does the module do?](#module-description) +3. [Setup - The basics of getting started with watcher](#setup) +4. [Implementation - An under-the-hood peek at what the module is doing](#implementation) +5. [Limitations - OS compatibility, etc.](#limitations) +6. [Development - Guide for contributing to the module](#development) +7. [Contributors - Those with commits](#contributors) + +Overview +-------- + +The watcher module is a part of [OpenStack](https://www.openstack.org), an effort by the OpenStack infrastructure team to provide continuous integration testing and code review for OpenStack and OpenStack community projects not part of the core software. The module its self is used to flexibly configure and manage the Watcher service for OpenStack. + +Module Description +------------------ + +The watcher module is a thorough attempt to make Puppet capable of managing the entirety of watcher. This includes manifests to provision region specific endpoint and database connections. Types are shipped as part of the watcher module to assist in manipulation of configuration files. + +Setup +----- + +**What the watcher module affects** + +* [Watcher](https://wiki.openstack.org/wiki/Watcher), the Watcher service for OpenStack. + +### Installing watcher + + watcher is not currently in Puppet Forge, but is anticipated to be added soon. Once that happens, you'll be able to install watcher with: + puppet module install openstack/watcher + +### Beginning with watcher + +To utilize the watcher module's functionality you will need to declare multiple resources. + +Implementation +-------------- + +### watcher + +watcher is a combination of Puppet manifest and ruby code to delivery configuration and extra functionality through types and providers. + +Limitations +------------ + +* All the watcher types use the CLI tools and so need to be ran on the watcher node. + +Beaker-Rspec +------------ + +This module has beaker-rspec tests + +To run the tests on the default vagrant node: + +```shell +bundle install +bundle exec rake acceptance +``` + +For more information on writing and running beaker-rspec tests visit the documentation: + +* https://github.com/puppetlabs/beaker-rspec/blob/master/README.md + +Development +----------- + +Developer documentation for the entire puppet-openstack project. + +* http://docs.openstack.org/developer/puppet-openstack-guide/ + +Contributors +------------ + +* https://github.com/openstack/puppet-watcher/graphs/contributors diff --git a/deployment_scripts/modules/watcher/Rakefile b/deployment_scripts/modules/watcher/Rakefile new file mode 100644 index 0000000..168d108 --- /dev/null +++ b/deployment_scripts/modules/watcher/Rakefile @@ -0,0 +1 @@ +require 'puppet-openstack_spec_helper/rake_tasks' diff --git a/deployment_scripts/modules/watcher/lib/puppet/provider/watcher_config/ini_setting.rb b/deployment_scripts/modules/watcher/lib/puppet/provider/watcher_config/ini_setting.rb new file mode 100644 index 0000000..b2188d4 --- /dev/null +++ b/deployment_scripts/modules/watcher/lib/puppet/provider/watcher_config/ini_setting.rb @@ -0,0 +1,10 @@ +Puppet::Type.type(:watcher_config).provide( + :ini_setting, + :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) +) do + + def self.file_path + '/etc/watcher/watcher.conf' + end + +end diff --git a/deployment_scripts/modules/watcher/lib/puppet/type/watcher_config.rb b/deployment_scripts/modules/watcher/lib/puppet/type/watcher_config.rb new file mode 100644 index 0000000..acc57d9 --- /dev/null +++ b/deployment_scripts/modules/watcher/lib/puppet/type/watcher_config.rb @@ -0,0 +1,53 @@ +Puppet::Type.newtype(:watcher_config) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from watcher.conf' + newvalues(/\S+\/\S+/) + end + + newproperty(:value) do + desc 'The value of the setting to be defined.' + munge do |value| + value = value.to_s.strip + value.capitalize! if value =~ /^(true|false)$/i + value + end + newvalues(/^[\S ]*$/) + + def is_to_s( currentvalue ) + if resource.secret? + return '[old secret redacted]' + else + return currentvalue + end + end + + def should_to_s( newvalue ) + if resource.secret? + return '[new secret redacted]' + else + return newvalue + end + end + end + + newparam(:secret, :boolean => true) do + desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' + + newvalues(:true, :false) + + defaultto false + end + + newparam(:ensure_absent_val) do + desc 'A value that is specified as the value property will behave as if ensure => absent was specified' + defaultto('') + end + + autorequire(:package) do + 'watcher' + end + +end diff --git a/deployment_scripts/modules/watcher/manifests/api.pp b/deployment_scripts/modules/watcher/manifests/api.pp new file mode 100644 index 0000000..481bc5c --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/api.pp @@ -0,0 +1,241 @@ +# == Class: watcher::api +# +# Configure Watcher API service. +# +# === Parameters: +# +# All options are optional unless specified otherwise. +# All options defaults to $::os_service_default and +# the default values from the service are used. +# +# === Watcher configuration section: watcher_clients_auth +# +# [*watcher_client_password*] +# (required) User's password +# +# [*watcher_client_username*] +# (optional) The name of the auth user +# Defaults to watcher. +# +# [*watcher_client_auth_uri*] +# (Optional) Public Identity API endpoint. +# Defaults to 'http://localhost:5000/' +# +# [*watcher_client_auth_url*] +# Specifies the admin Identity URI for Watcher to use. +# Default 'http://localhost:35357/' +# +# [*package_ensure*] +# (Optional)Ensure state of the openstackclient package. +# Defaults to 'present'. +# +# [*enabled*] +# (Optional) Whether the watcher api service will be run +# Defaults to true +# +# [*manage_service*] +# (Optional) Whether the service should be managed by Puppet. +# Defaults to true. +# +# [*validate*] +# (Optional) Whether to validate the service is working after any service +# refreshes +# Defaults to false +# +# [*watcher_api_port*] +# (Optional) The port on which the watcher API will listen. +# Defaults to 9322. +# +# [*watcher_api_max_limit*] +# (Optional)The maximum number of items returned in a single response from a +# collection resource. +# Defaults to $::os_service_default +# +# [*watcher_api_bind_host*] +# (Optional) Listen IP for the watcher API server. +# Defaults to '0.0.0.0'. +# +# [*watcher_api_workers*] +# (Optional) Number of worker processors to for the Watcher API service. +# Defaults to $::os_workers. +# +# [*watcher_api_enable_ssl_api*] +# (Optional) Enable the integrated stand-alone API to service requests via HTTPS instead +# of HTTP. If there is a front-end service performing HTTPS offloading from the +# service, this option should be False; note, you will want to change public +# API endpoint to represent SSL termination URL with 'public_endpoint' option. +# Defaults to $::os_service_default. +# +# [*watcher_client_default_domain_name*] +# (Optional)domain name to use with v3 API and v2 parameters. It will +# be used for both the user and project domain in v3 and ignored in v2 +# authentication. +# Defaults to $::os_service_default +# +# [*watcher_client_project_name*] +# (Optional) Service project name. +# Defaults to undef +# +# [*watcher_client_certfile*] +# (Optional) PEM encoded client certificate cert file. +# Defaults to undef +# +# [*watcher_client_cafile*] +# (Optional)PEM encoded Certificate Authority to use when verifying HTTPs +# connections. +# Defaults to undef +# +# [*watcher_client_project_domain_name*] +# (Optional) Domain name containing project. +# Defaults to undef +# +# [*watcher_client_insecure*] +# (Optional) Verify HTTPS connections. +# Defaults to undef +# +# [*watcher_client_keyfile*] +# (Optional) PEM encoded client certificate key file. +# Defaults to undef +# +# [*watcher_client_auth_type*] +# (Optional) Authentication type to load. +# Defaults to undef +# +# === Watcher API service validation +# +# [*validation_options*] +# (Optional) Service validation options +# Should be a hash of options defined in openstacklib::service_validation +# If empty, defaults values are taken from openstacklib function. +# Require validate set at True. +# Defaults to {} +# +# === DB managment +# +# [*create_db_schema*] +# (Optional) Run watcher-db-manage create_schema on api nodes after +# installing the package. +# Defaults to false +# +# [*upgrade_db*] +# (Optional) Run watcher-db-manage upgrade on api nodes after +# installing the package. +# Defaults to false +# +# [*auth_strategy*] +# (optional) Type of authentication to be used. +# Defaults to 'keystone' +# +class watcher::api ( + $watcher_client_password, + $watcher_client_username = 'watcher', + $watcher_client_auth_uri = 'http://localhost:5000/', + $watcher_client_auth_url = 'http://localhost:35357/', + $package_ensure = 'present', + $enabled = true, + $manage_service = true, + $validate = false, + $watcher_api_port = '9322', + $watcher_api_max_limit = $::os_service_default, + $watcher_api_bind_host = '0.0.0.0', + $watcher_api_workers = $::os_workers, + $watcher_api_enable_ssl_api = $::os_service_default, + $watcher_client_default_domain_name = $::os_service_default, + $watcher_client_project_name = 'services', + $watcher_client_certfile = $::os_service_default, + $watcher_client_cafile = $::os_service_default, + $watcher_client_project_domain_name = $::os_service_default, + $watcher_client_insecure = $::os_service_default, + $watcher_client_keyfile = $::os_service_default, + $watcher_client_auth_type = 'password', + $validation_options = {}, + $create_db_schema = false, + $upgrade_db = false, + $auth_strategy = 'keystone', +) { + + include ::watcher::params + include ::watcher::policy + include ::watcher::deps + + #if $auth_strategy == 'keystone' { + # include ::watcher::keystone::authtoken + #} + + validate_string($watcher_client_password) + + package { 'watcher-api': + ensure => $package_ensure, + name => $::watcher::params::api_package_name, + tag => ['openstack', 'watcher-package'], + } + + if $manage_service { + if $enabled { + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } + } + + if $create_db_schema { + include ::watcher::db::create_schema + } + + if $upgrade_db { + include ::watcher::db::upgrade + } + + # NOTE(danpawlik) Watcher doesn't support db_sync command. + service { 'watcher-api': + ensure => $service_ensure, + name => $::watcher::params::api_service_name, + enable => $enabled, + hasstatus => true, + hasrestart => true, + tag => [ 'watcher-service', + 'watcher-db-manage-create_schema', + 'watcher-db-manage-upgrade'], + } + + if $enabled { + watcher_config { + 'api/port': value => $watcher_api_port; + 'api/max_limit': value => $watcher_api_max_limit; + 'api/host': value => $watcher_api_bind_host; + 'api/workers': value => $watcher_api_workers; + 'api/enable_ssl_api': value => $watcher_api_enable_ssl_api; + } + } + + # NOTE(danpawlik) Watcher and other core Openstack services are using + # keystone_authtoken section and also another similar section used to + # configure client auth credentials. So these parameters are similar to + # parameters in watcher::keystone::authtoken. + watcher_config { + 'watcher_clients_auth/username': value => $watcher_client_username; + 'watcher_clients_auth/password': value => $watcher_client_password, secret => true; + 'watcher_clients_auth/auth_url': value => $watcher_client_auth_url; + 'watcher_clients_auth/auth_uri': value => $watcher_client_auth_uri; + 'watcher_clients_auth/project_name': value => $watcher_client_project_name; + 'watcher_clients_auth/project_domain_name': value => $watcher_client_project_domain_name; + 'watcher_clients_auth/insecure': value => $watcher_client_insecure; + 'watcher_clients_auth/auth_type': value => $watcher_client_auth_type; + 'watcher_clients_auth/cafile': value => $watcher_client_cafile; + 'watcher_clients_auth/certfile': value => $watcher_client_certfile; + 'watcher_clients_auth/keyfile': value => $watcher_client_keyfile; + } + + if $validate { + $defaults = { + 'watcher-api' => { + # lint:ignore:140chars + 'command' => "watcher --os-auth-url ${watcher_client_auth_url} --os-project-name ${watcher_client_project_name} --os-username ${watcher_client_username} --os-password ${watcher_client_password} goal list", + # lint:endignore + } + } + $validation_options_hash = merge($defaults, $validation_options) + create_resources('openstacklib::service_validation', $validation_options_hash, {'subscribe' => 'Anchor[watcher::service::end]'}) + } + +} diff --git a/deployment_scripts/modules/watcher/manifests/applier.pp b/deployment_scripts/modules/watcher/manifests/applier.pp new file mode 100644 index 0000000..911cdcc --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/applier.pp @@ -0,0 +1,84 @@ +# == Class: watcher::applier +# +# === Parameters +# +# [*package_ensure*] +# (Optional) The state of the package. +# Defaults to 'present'. +# +# [*enabled*] +# (Optional) The state of the service +# Defaults to 'true'. +# +# [*manage_service*] +# (Optional) Whether to start/stop the service. +# Defaults to 'true'. +# +# [*applier_workers*] +# (Optional) Number of workers for watcher applier service. +# Defaults to $::os_service_default +# +# [*applier_conductor_topic*] +# (Optional) The topic name used forcontrol events, this topic used +# for rpc call +# Defaults to $::os_service_default +# +# [*applier_status_topic*] +# (Optional) The topic name used for status events, this topic is used +# so as to notifythe others components of the system +# Defaults to $::os_service_default +# +# [*applier_publisher_id*] +# (Optional) The identifier used by watcher module on the message broker +# Defaults to $::os_service_default +# +# [*applier_workflow_engine*] +# (Optional) Select the engine to use to execute the workflow +# Defaults to $::os_service_default +# +class watcher::applier ( + $package_ensure = 'present', + $enabled = true, + $manage_service = true, + $applier_workers = $::os_service_default, + $applier_conductor_topic = $::os_service_default, + $applier_status_topic = $::os_service_default, + $applier_publisher_id = $::os_service_default, + $applier_workflow_engine = $::os_service_default, +) { + + include ::watcher::params + include ::watcher::deps + + package { 'watcher-applier': + ensure => $package_ensure, + name => $::watcher::params::applier_package_name, + tag => ['openstack', 'watcher-package'], + } + + if $manage_service { + if $enabled { + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } + } + + service { 'watcher-applier': + ensure => $service_ensure, + name => $::watcher::params::applier_service_name, + enable => $enabled, + hasstatus => true, + hasrestart => true, + tag => ['watcher-service'], + } + + watcher_config { + 'watcher_applier/workers': value => $applier_workers; + 'watcher_applier/conductor_topic': value => $applier_conductor_topic; + 'watcher_applier/status_topic': value => $applier_status_topic; + 'watcher_applier/publisher_id': value => $applier_publisher_id; + 'watcher_applier/workflow_engine': value => $applier_workflow_engine; + } + +} diff --git a/deployment_scripts/modules/watcher/manifests/config.pp b/deployment_scripts/modules/watcher/manifests/config.pp new file mode 100644 index 0000000..65a07a6 --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/config.pp @@ -0,0 +1,32 @@ +# == Class: watcher::config +# +# This class is used to manage arbitrary watcher configurations. +# +# === Parameters +# +# [*watcher_config*] +# (optional) Allow configuration of arbitrary watcher configurations. +# The value is an hash of watcher_config resources. Example: +# { 'DEFAULT/foo' => { value => 'fooValue'}, +# 'DEFAULT/bar' => { value => 'barValue'} +# } +# In yaml format, Example: +# watcher_config: +# DEFAULT/foo: +# value: fooValue +# DEFAULT/bar: +# value: barValue +# +# NOTE: The configuration MUST NOT be already handled by this module +# or Puppet catalog compilation will fail with duplicate resources. +# +class watcher::config ( + $watcher_config = {}, +) { + + include ::watcher::deps + + validate_hash($watcher_config) + + create_resources('watcher_config', $watcher_config) +} diff --git a/deployment_scripts/modules/watcher/manifests/db.pp b/deployment_scripts/modules/watcher/manifests/db.pp new file mode 100644 index 0000000..b7e7165 --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/db.pp @@ -0,0 +1,75 @@ +# == Class: watcher::db +# +# Configure the watcher database +# +# === Parameters +# +# [*database_connection*] +# (Optional) Url used to connect to database. +# Defaults to "sqlite:////var/lib/watcher/watcher.sqlite". +# +# [*database_idle_timeout*] +# (Optional) Timeout when db connections should be reaped. +# Defaults to $::os_service_default +# +# [*database_db_max_retries*] +# (optional) Maximum retries in case of connection error or deadlock error +# before error is raised. Set to -1 to specify an infinite retry count. +# Defaults to $::os_service_default +# +# [*database_max_retries*] +# (Optional) Maximum number of database connection retries during startup. +# Setting -1 implies an infinite retry count. +# Defaults to $::os_service_default +# +# [*database_retry_interval*] +# (Optional) Interval between retries of opening a database connection. +# Defaults to $::os_service_default +# +# [*database_min_pool_size*] +# (Optional) Minimum number of SQL connections to keep open in a pool. +# Defaults to $::os_service_default +# +# [*database_max_pool_size*] +# (Optional) Maximum number of SQL connections to keep open in a pool. +# Defaults to $::os_service_default +# +# [*database_max_overflow*] +# (Optional) If set, use this value for max_overflow with sqlalchemy. +# Defaults to $::os_service_default +# +class watcher::db ( + $database_connection = 'sqlite://var/lib/watcher/watcher.sqlite', + $database_idle_timeout = $::os_service_default, + $database_min_pool_size = $::os_service_default, + $database_max_pool_size = $::os_service_default, + $database_db_max_retries = $::os_service_default, + $database_max_retries = $::os_service_default, + $database_retry_interval = $::os_service_default, + $database_max_overflow = $::os_service_default, +) { + $database_connection_real = pick($::watcher::database_connection, $database_connection) + $database_idle_timeout_real = pick($::watcher::database_idle_timeout, $database_idle_timeout) + $database_min_pool_size_real = pick($::watcher::database_min_pool_size, $database_min_pool_size) + $database_max_pool_size_real = pick($::watcher::database_max_pool_size, $database_max_pool_size) + $database_max_retries_real = pick($::watcher::database_max_retries, $database_max_retries) + $database_retry_interval_real = pick($::watcher::database_retry_interval, $database_retry_interval) + $database_max_overflow_real = pick($::watcher::database_max_overflow, $database_max_overflow) + + include ::watcher::deps + notice($database_connection) + + #validate_re($database_connection, + # '^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') + + watcher_config { + 'database/connection': value => $database_connection_real; + 'database/idle_timeout': value => $database_idle_timeout_real; + 'database/min_pool_size': value => $database_min_pool_size_real; + 'database/db_max_retries': value => $database_db_max_retries_real; + 'database/max_retries': value => $database_max_retries_real; + 'database/retry_interval': value => $database_retry_interval_real; + 'database/max_pool_size': value => $database_max_pool_size_real; + 'database/max_overflow': value => $database_max_overflow_real; + } +} diff --git a/deployment_scripts/modules/watcher/manifests/db/create_schema.pp b/deployment_scripts/modules/watcher/manifests/db/create_schema.pp new file mode 100644 index 0000000..a592191 --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/db/create_schema.pp @@ -0,0 +1,30 @@ +# +# Class to execute watcher-db-manage create_schema +# +# == Parameters +# +# [*extra_params*] +# (optional) String of extra command line parameters to append +# to the watcher-db-manage create_schema command. +# Defaults to '--config-file /etc/watcher/watcher.conf' +# +class watcher::db::create_schema( + $extra_params = '--config-file /etc/watcher/watcher.conf', +) { + + include ::watcher::deps + + exec { 'watcher-db-manage-create_schema': + command => "watcher-db-manage ${extra_params} create_schema", + path => '/usr/bin', + user => 'watcher', + refreshonly => true, + subscribe => [ + Anchor['watcher::install::end'], + Anchor['watcher::config::end'], + Anchor['watcher::db::create_schema::begin'] + ], + notify => Anchor['watcher::db::create_schema::end'], + } + +} diff --git a/deployment_scripts/modules/watcher/manifests/db/mysql.pp b/deployment_scripts/modules/watcher/manifests/db/mysql.pp new file mode 100644 index 0000000..6503fcc --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/db/mysql.pp @@ -0,0 +1,74 @@ +# The watcher::db::mysql class implements mysql backend for watcher +# +# This class can be used to create tables, users and grant +# privilege for a mysql watcher database. +# +# == parameters +# +# [*password*] +# (Mandatory) Password to connect to the database. +# Defaults to 'false'. +# +# [*dbname*] +# (Optional) Name of the database. +# Defaults to 'watcher'. +# +# [*user*] +# (Optional) User to connect to the database. +# Defaults to 'watcher'. +# +# [*host*] +# (Optional) The default source host user is allowed to connect from. +# Defaults to '127.0.0.1' +# +# [*allowed_hosts*] +# (Optional) Other hosts the user is allowed to connect from. +# Defaults to 'undef'. +# +# [*charset*] +# (Optional) The database charset. +# Defaults to 'utf8' +# +# [*collate*] +# (Optional) The database collate. +# Only used with mysql modules >= 2.2. +# Defaults to 'utf8_general_ci' +# +# == Dependencies +# Class['mysql::server'] +# +# == Examples +# +# == Authors +# +# == Copyright +# +class watcher::db::mysql( + $password, + $dbname = 'watcher', + $user = 'watcher', + $host = '127.0.0.1', + $charset = 'utf8', + $collate = 'utf8_general_ci', + $allowed_hosts = undef +) { + + include ::watcher::deps + + validate_string($password) + + ::openstacklib::db::mysql { 'watcher': + user => $user, + password_hash => mysql_password($password), + dbname => $dbname, + host => $host, + charset => $charset, + collate => $collate, + allowed_hosts => $allowed_hosts, + } + + Anchor['watcher::db::begin'] + ~> Class['watcher::db::mysql'] + ~> Anchor['watcher::db::end'] + +} diff --git a/deployment_scripts/modules/watcher/manifests/db/postgresql.pp b/deployment_scripts/modules/watcher/manifests/db/postgresql.pp new file mode 100644 index 0000000..44f81b4 --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/db/postgresql.pp @@ -0,0 +1,57 @@ +# == Class: watcher::db::postgresql +# +# Class that configures postgresql for watcher +# Requires the Puppetlabs postgresql module. +# +# === Parameters +# +# [*password*] +# (Required) Password to connect to the database. +# +# [*dbname*] +# (Optional) Name of the database. +# Defaults to 'watcher'. +# +# [*user*] +# (Optional) User to connect to the database. +# Defaults to 'watcher'. +# +# [*encoding*] +# (Optional) The charset to use for the database. +# Default to undef. +# +# [*privileges*] +# (Optional) Privileges given to the database user. +# Default to 'ALL' +# +# == Dependencies +# +# == Examples +# +# == Authors +# +# == Copyright +# +class watcher::db::postgresql( + $password, + $dbname = 'watcher', + $user = 'watcher', + $encoding = undef, + $privileges = 'ALL', +) { + + include ::watcher::deps + + ::openstacklib::db::postgresql { 'watcher': + password_hash => postgresql_password($user, $password), + dbname => $dbname, + user => $user, + encoding => $encoding, + privileges => $privileges, + } + + Anchor['watcher::db::begin'] + ~> Class['watcher::db::postgresql'] + ~> Anchor['watcher::db::end'] + +} diff --git a/deployment_scripts/modules/watcher/manifests/db/upgrade.pp b/deployment_scripts/modules/watcher/manifests/db/upgrade.pp new file mode 100644 index 0000000..89bc7df --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/db/upgrade.pp @@ -0,0 +1,32 @@ +# +# Class to execute watcher-db-manage upgrade +# It's because watcher-db-manage doesn't support sync db. +# +# == Parameters +# +# [*extra_params*] +# (optional) String of extra command line parameters to append +# to the watcher-db-manage upgrade command. +# Defaults to '--config-file /etc/watcher/watcher.conf' +# +class watcher::db::upgrade( + $extra_params = '--config-file /etc/watcher/watcher.conf', +) { + + include ::watcher::deps + + exec { 'watcher-db-manage-upgrade': + command => "watcher-db-manage ${extra_params} upgrade", + path => '/usr/bin', + user => 'watcher', + refreshonly => true, + subscribe => [ + Anchor['watcher::install::end'], + Anchor['watcher::config::end'], + Anchor['watcher::db::create_schema::end'], + Anchor['watcher::db::upgrade::begin'] + ], + notify => Anchor['watcher::db::upgrade::end'], + } + +} diff --git a/deployment_scripts/modules/watcher/manifests/decision_engine.pp b/deployment_scripts/modules/watcher/manifests/decision_engine.pp new file mode 100644 index 0000000..c7e1189 --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/decision_engine.pp @@ -0,0 +1,122 @@ +# == Class: watcher::decision_engine +# +# === Parameters +# +# [*package_ensure*] +# (Optional) The state of the package. +# Defaults to 'present'. +# +# [*enabled*] +# (Optional) The state of the service +# Defaults to 'true'. +# +# [*manage_service*] +# (Optional) Whether to start/stop the service. +# Defaults to 'true'. +# +# [*decision_engine_conductor_topic*] +# (Optional) The topic name used forcontrol events, this topic used +# for rpc call +# Defaults to $::os_service_default +# +# [*decision_engine_status_topic*] +# (Optional) The topic name used for status events, this topic is used +# so as to notifythe others components of the system +# Defaults to $::os_service_default +# +# [*decision_engine_notification_topics*] +# (Optional) The topic names from which notification events will be +# listened to (list value) +# Defaults to $::os_service_default +# +# [*decision_engine_publisher_id*] +# (Optional) The identifier used by watcher module on the message broker +# Defaults to $::os_service_default +# +# [*decision_engine_workers*] +# (Optional) The maximum number of threads that can be used to execute +# strategies +# Defaults to $::os_service_default +# +# [*planner*] +# (Optional) The selected planner used to schedule the actions (string value) +# Defaults to $::os_service_default +# +# [*weights*] +# (Optional) Hash of weights used to schedule the actions (dict value). +# The key is an action, value is an order number. +# Defaults to $::os_service_default +# Example: +# { 'change_nova_service_state' => '2', +# 'migrate' => '3', 'nop' => '0', 'sleep' => '1' } +# +# +class watcher::decision_engine ( + $package_ensure = 'present', + $enabled = true, + $manage_service = true, + $decision_engine_conductor_topic = $::os_service_default, + $decision_engine_status_topic = $::os_service_default, + $decision_engine_notification_topics = $::os_service_default, + $decision_engine_publisher_id = $::os_service_default, + $decision_engine_workers = $::os_service_default, + $planner = $::os_service_default, + $weights = $::os_service_default, +) { + + include ::watcher::params + include ::watcher::deps + + if !is_service_default($weights) { + validate_hash($weights) + $weights_real = join(sort(join_keys_to_values($weights, ':')), ',') + } else { + $weights_real = $weights + } + + if !is_service_default($decision_engine_notification_topics) or + empty($decision_engine_notification_topics) { + warning('$decision_engine_notification_topics needs to be an array') + $decision_engine_notification_topics_real = any2array($decision_engine_notification_topics) + } else { + $decision_engine_notification_topics_real = $decision_engine_notification_topics + } + + package { 'watcher-decision-engine': + ensure => $package_ensure, + name => $::watcher::params::decision_engine_package_name, + tag => ['openstack', 'watcher-package'], + } + + if $manage_service { + if $enabled { + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } + } + + service { 'watcher-decision-engine': + ensure => $service_ensure, + name => $::watcher::params::decision_engine_service_name, + enable => $enabled, + hasstatus => true, + hasrestart => true, + tag => ['watcher-service'], + } + + watcher_config { + 'watcher_decision_engine/conductor_topic': value => $decision_engine_conductor_topic; + 'watcher_decision_engine/status_topic': value => $decision_engine_status_topic; + 'watcher_decision_engine/notification_topics': value => $decision_engine_notification_topics_real; + 'watcher_decision_engine/publisher_id': value => $decision_engine_publisher_id; + 'watcher_decision_engine/max_workers': value => $decision_engine_workers; + 'watcher_decision_engine/continuous_audit_interval': value => 30; + } + + watcher_config { + 'watcher_planner/planner': value => $planner; + 'watcher_planners.default/weights': value => $weights_real; + } + +} diff --git a/deployment_scripts/modules/watcher/manifests/deps.pp b/deployment_scripts/modules/watcher/manifests/deps.pp new file mode 100644 index 0000000..07ea460 --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/deps.pp @@ -0,0 +1,34 @@ +# == Class: watcher::deps +# +# watcher anchors and dependency management +# +class watcher::deps { + anchor { 'watcher::install::begin': } + -> Package<| tag == 'watcher-package'|> + ~> anchor { 'watcher::install::end': } + -> anchor { 'watcher::config::begin': } + -> Watcher_config<||> + ~> anchor { 'watcher::config::end': } + ~> anchor { 'watcher::db::begin': } + ~> anchor { 'watcher::db::end': } + ~> anchor { 'watcher::db::create_schema::begin': } + ~> anchor { 'watcher::db::create_schema::end': } + ~> anchor { 'watcher::db::upgrade::begin': } + ~> anchor { 'watcher::db::upgrade::end': } + ~> anchor { 'watcher::service::begin': } + ~> Service<| tag == 'watcher-service' |> + ~> anchor { 'watcher::service::end': } + + # policy config should occur in the config block also. + Anchor['watcher::config::begin'] + -> Openstacklib::Policy::Base<||> + ~> Anchor['watcher::config::end'] + + Anchor['watcher::install::end'] ~> Anchor['watcher::service::begin'] + Anchor['watcher::config::end'] ~> Anchor['watcher::service::begin'] + + anchor { 'watcher-start': + require => Anchor['watcher::install::end'], + before => Anchor['watcher::config::begin'], + } +} diff --git a/deployment_scripts/modules/watcher/manifests/init.pp b/deployment_scripts/modules/watcher/manifests/init.pp new file mode 100644 index 0000000..93fa57b --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/init.pp @@ -0,0 +1,471 @@ +# == Class: watcher +# +# Full description of class watcher here. +# +# === Parameters: +# +# [*use_ssl*] +# (required) Enable SSL on the API server. +# Defaults to false. +# +# [*ceilometer_client_api_version*] +# (required) Version of Ceilometer API to use in ceilometerclient. +# Default is 2. +# +# [*cinder_client_api_version*] +# (required) Version of Cinder API to use in cinderclient. +# Default is 2. +# +# [*glance_client_api_version*] +# (required) Version of Glance API to use in glanceclient. +# Default is 2. +# +# [*neutron_client_api_version*] +# (required) Version of Neutron API to use in neutronclient. +# Default is 2. +# +# [*nova_client_api_version*] +# (required) Version of Nova API to use in novaclient. +# Default is 2. +# +# [*rpc_backend*] +# (optional) The messaging driver to use, defaults to rabbit. Other drivers +# include amqp and zmq. +# Defaults to 'rabbit'. +# +# [*ensure_package*] +# (optional) Whether the watcher api package will be installed +# Defaults to 'present' +# +# [*rabbit_login_method*] +# (optional) The RabbitMQ login method. (string value) +# Defaults to $::os_service_default +# +# [*rabbit_retry_interval*] +# (Optional) How frequently to retry connecting with RabbitMQ. +# (integer value) +# Defaults to $::os_service_default +# +# [*rabbit_retry_backoff*] +# (Optional) How long to backoff for between retries when connecting +# to RabbitMQ. (integer value) +# Defaults to $::os_service_default +# +# [*rabbit_interval_max*] +# (Optional) Maximum interval of RabbitMQ connection retries. (integer value) +# Defaults to $::os_service_default +# +# [*rabbit_max_retries*] +# (Optional) Maximum number of RabbitMQ connection retries. (integer value) +# Defaults to $::os_service_default +# +# [*rabbit_use_ssl*] +# (optional) Connect over SSL for RabbitMQ. +# Defaults to $::os_service_default +# +# [*rabbit_heartbeat_rate*] +# (optional) ow often times during the heartbeat_timeout_threshold we +# check the heartbeat. +# Defaults to $::os_service_default +# +# [*rabbit_ha_queues*] +# (optional) Use HA queues in RabbitMQ (x-ha-policy: all). If you change this +# option, you must wipe the RabbitMQ database. +# Defaults to $::os_service_default +# +# [*rabbit_transient_queues_ttl*] +# (Optional) Positive integer representing duration in seconds for +# queue TTL (x-expires). Queues which are unused for the duration +# of the TTL are automatically deleted. +# The parameter affects only reply and fanout queues. (integer value) +# Min to 1 +# Defaults to $::os_service_default +# +# [*rabbit_heartbeat_timeout_threshold*] +# (Optional) Number of seconds after which the Rabbit broker is +# considered down if heartbeat's keep-alive fails +# (0 disable the heartbeat). EXPERIMENTAL. (integer value) +# Defaults to $::os_service_default +# +# [*kombu_ssl_ca_certs*] +# (optional) SSL certification authority file (valid only if SSL enabled). +# Defaults to $::os_service_default +# +# [*kombu_ssl_certfile*] +# (optional) SSL cert file (valid only if SSL enabled). +# Defaults to $::os_service_default +# +# [*kombu_ssl_keyfile*] +# (optional) SSL key file (valid only if SSL enabled). +# Defaults to $::os_service_default +# +# [*kombu_ssl_version*] +# (optional) SSL version to use (valid only if SSL enabled). Valid values are +# TLSv1 and SSLv23. SSLv2, SSLv3, TLSv1_1, and TLSv1_2 may be +# available on some distributions. +# Defaults to $::os_service_default +# +# [*kombu_reconnect_delay*] +# (optional) How long to wait before reconnecting in response to an AMQP +# consumer cancel notification. +# Defaults to $::os_service_default +# +# [*kombu_missing_consumer_retry_timeout*] +# (optional)How long to wait a missing client beforce abandoning to send it +# its replies. This value should not be longer than rpc_response_timeout. +# Defaults to $::os_service_default +# +# [*kombu_failover_strategy*] +# (Optional) Determines how the next RabbitMQ node is chosen in case the one +# we are currently connected to becomes unavailable. Takes effect only if +# more than one RabbitMQ node is provided in config. (string value) +# Defaults to $::os_service_default +# +# [*kombu_compression*] +# (optional) Possible values are: gzip, bz2. If not set compression will not +# be used. This option may notbe available in future versions. EXPERIMENTAL. +# (string value) +# Defaults to $::os_service_default +# +# [*amqp_durable_queues*] +# (optional) Use durable queues in AMQP. +# Defaults to $::os_service_default +# +# [*default_transport_url*] +# (Optional) A URL representing the messaging driver to use and its full +# configuration. If not set, we fall back to the rpc_backend option +# and driver specific configuration. +# Defaults to $::os_service_default +# +# [*rpc_response_timeout*] +# (Optional) Seconds to wait for a response from a call. +# Defaults to $::os_service_default +# +# [*control_exchange*] +# (Optional) The default exchange under which topics are scoped. May be +# overridden by an exchange name specified in the transport_url +# option. +# Defaults to $::os_service_default +# +# [*amqp_password*] +# (Optional) Password for message broker authentication. +# Defaults to $::os_service_default +# +# [*amqp_username*] +# (Optional) User name for message broker authentication. +# Defaults to $::os_service_default +# +# [*amqp_ssl_ca_file*] +# (Optional) CA certificate PEM file to verify server certificate. +# Defaults to $::os_service_default +# +# [*amqp_ssl_key_file*] +# (Optional) Private key PEM file used to sign cert_file certificate. +# Defaults to $::os_service_default +# +# [*amqp_container_name*] +# (Optional) Name for the AMQP container. +# Defaults to $::os_service_default +# +# [*amqp_sasl_mechanisms*] +# (Optional) Space separated list of acceptable SASL mechanisms. +# Defaults to $::os_service_default +# +# [*amqp_server_request_prefix*] +# (Optional) Address prefix used when sending to a specific server. +# Defaults to $::os_service_default +# +# [*amqp_ssl_key_password*] +# (Optional) Password for decrypting ssl_key_file (if encrypted). +# Defaults to $::os_service_default +# +# [*amqp_idle_timeout*] +# (Optional) Timeout for inactive connections (in seconds). +# Defaults to $::os_service_default +# +# [*amqp_ssl_cert_file*] +# (Optional) Identifying certificate PEM file to present to clients. +# Defaults to $::os_service_default +# +# [*amqp_broadcast_prefix*] +# (Optional) Address prefix used when broadcasting to all servers. +# Defaults to $::os_service_default +# +# [*amqp_trace*] +# (Optional) Debug: dump AMQP frames to stdout. +# Defaults to $::os_service_default +# +# [*amqp_allow_insecure_clients*] +# (Optional) Accept clients using either SSL or plain TCP. +# Defaults to $::os_service_default +# +# [*amqp_sasl_config_name*] +# (Optional) Name of configuration file (without .conf suffix). +# Defaults to $::os_service_default +# +# [*amqp_sasl_config_dir*] +# (Optional) Path to directory that contains the SASL configuration. +# Defaults to $::os_service_default +# +# [*amqp_group_request_prefix*] +# (Optional) Address prefix when sending to any server in group. +# Defaults to $::os_service_default +# +# [*rpc_cast_timeout*] +# (optional) Seconds to wait before a cast expires (TTL). +# The default value of -1 specifies an infinite linger +# period. The value of 0 specifies no linger period. +# Pending messages shall be discarded immediately +# when the socket is closed. Only supported by impl_zmq. +# Defaults to $::os_service_default. +# +# [*rpc_poll_timeout*] +# (optional) The default number of seconds that poll should wait. +# Poll raises timeout exception when timeout expired. +# Defaults to $::os_service_default. +# +# [*rpc_zmq_bind_address*] +# (optional) ZeroMQ bind address. +# Should be a wildcard (*), an ethernet interface, or IP. +# The "host" option should point or resolve to this address. +# Defaults to $::os_service_default. +# +# [*rpc_zmq_bind_port_retries*] +# (optional) Number of retries to find free port number +# before fail with ZMQBindError. +# Defaults to $::os_service_default. +# +# [*rpc_zmq_concurrency*] +# (optional) Type of concurrency used. +# Either "native" or "eventlet". +# Defaults to $::os_service_default. +# +# [*rpc_zmq_contexts*] +# (optional) Number of ZeroMQ contexts. +# Defaults to $::os_service_default. +# +# [*rpc_zmq_host*] +# (optional) Name of this node. +# Must be a valid hostname, FQDN, or IP address. +# Must match "host" option, if running Nova. +# Defaults to $::os_service_default. +# +# [*rpc_zmq_ipc_dir*] +# (optional) Directory for holding IPC sockets. +# Defaults to $::os_service_default. +# +# [*rpc_zmq_matchmaker*] +# (optional) MatchMaker driver. +# Defaults to $::os_service_default. +# +# [*rpc_zmq_max_port*] +# (optional) Maximal port number for random ports range. +# Defaults to $::os_service_default. +# +# [*rpc_zmq_min_port*] +# (optional) Minimal port number for random ports range. +# Defaults to $::os_service_default. +# +# [*rpc_zmq_topic_backlog*] +# (optional) Maximum number of ingress messages to locally buffer per topic. +# Defaults to $::os_service_default. +# +# [*use_pub_sub*] +# (optional) Use PUB/SUB pattern for fanout methods. +# PUB/SUB always uses proxy. +# Defaults to $::os_service_default. +# +# [*zmq_target_expire*] +# (optional) Expiration timeout in seconds of a name service +# record about existing target ( < 0 means no timeout). +# Defaults to $::os_service_default. +# +# [*notification_transport_url*] +# (optional) A URL representing the messaging driver to use for notifications +# and its full configuration. Transport URLs take the form: +# transport://user:pass@host1:port[,hostN:portN]/virtual_host +# Defaults to $::os_service_default +# +# [*notification_driver*] +# (optional) Driver or drivers to handle sending notifications. +# Value can be a string or a list. +# Defaults to $::os_service_default +# +# [*notification_topics*] +# (optional) AMQP topic used for OpenStack notifications +# Defaults to $::os_service_default +# +# [*purge_config*] +# (optional) Whether to set only the specified config options +# in the watcher config. +# Defaults to false. +# +# === Authors +# +# Daniel Pawlik +# +class watcher ( + $purge_config = false, + $use_ssl = false, + $ceilometer_client_api_version = '2', + $cinder_client_api_version = '2', + $glance_client_api_version = '2', + $neutron_client_api_version = '2', + $nova_client_api_version = '2', + $rpc_backend = 'rabbit', + $ensure_package = 'present', + $database_connection = undef, + $database_idle_timeout = undef, + $database_min_pool_size = undef, + $database_max_pool_size = undef, + $database_max_retries = undef, + $database_retry_interval = undef, + $database_max_overflow = undef, + $rabbit_os_user, + $rabbit_os_password, + $rabbit_os_host, + $rabbit_login_method = $::os_service_default, + $rabbit_retry_interval = $::os_service_default, + $rabbit_retry_backoff = $::os_service_default, + $rabbit_interval_max = $::os_service_default, + $rabbit_max_retries = $::os_service_default, + $rabbit_use_ssl = $::os_service_default, + $rabbit_heartbeat_rate = $::os_service_default, + $rabbit_ha_queues = $::os_service_default, + $rabbit_transient_queues_ttl = $::os_service_default, + $rabbit_heartbeat_timeout_threshold = $::os_service_default, + $kombu_ssl_ca_certs = $::os_service_default, + $kombu_ssl_certfile = $::os_service_default, + $kombu_ssl_keyfile = $::os_service_default, + $kombu_ssl_version = $::os_service_default, + $kombu_reconnect_delay = $::os_service_default, + $kombu_missing_consumer_retry_timeout = $::os_service_default, + $kombu_failover_strategy = $::os_service_default, + $kombu_compression = $::os_service_default, + $amqp_durable_queues = $::os_service_default, + $default_transport_url = $::os_service_default, + $rpc_response_timeout = $::os_service_default, + $control_exchange = $::os_service_default, + # amqp + $amqp_username = $::os_service_default, + $amqp_password = $::os_service_default, + $amqp_ssl_ca_file = $::os_service_default, + $amqp_ssl_key_file = $::os_service_default, + $amqp_container_name = $::os_service_default, + $amqp_sasl_mechanisms = $::os_service_default, + $amqp_server_request_prefix = $::os_service_default, + $amqp_ssl_key_password = $::os_service_default, + $amqp_idle_timeout = $::os_service_default, + $amqp_ssl_cert_file = $::os_service_default, + $amqp_broadcast_prefix = $::os_service_default, + $amqp_trace = $::os_service_default, + $amqp_allow_insecure_clients = $::os_service_default, + $amqp_sasl_config_name = $::os_service_default, + $amqp_sasl_config_dir = $::os_service_default, + $amqp_group_request_prefix = $::os_service_default, + # zmq + $rpc_cast_timeout = $::os_service_default, + $rpc_poll_timeout = $::os_service_default, + $rpc_zmq_bind_address = $::os_service_default, + $rpc_zmq_bind_port_retries = $::os_service_default, + $rpc_zmq_concurrency = $::os_service_default, + $rpc_zmq_contexts = $::os_service_default, + $rpc_zmq_host = $::os_service_default, + $rpc_zmq_ipc_dir = $::os_service_default, + $rpc_zmq_matchmaker = $::os_service_default, + $rpc_zmq_max_port = $::os_service_default, + $rpc_zmq_min_port = $::os_service_default, + $rpc_zmq_topic_backlog = $::os_service_default, + $use_pub_sub = $::os_service_default, + $zmq_target_expire = $::os_service_default, + # messaging + $notification_transport_url = $::os_service_default, + $notification_driver = $::os_service_default, + $notification_topics = $::os_service_default, + $auth_uri = $::os_service_default, + $auth_url = $::os_service_default, + $identity_uri = $::os_service_default, + $admin_user = 'watcher', + $admin_password = $::os_service_default, + $username = $::os_service_default, + $password = $::os_service_default, + $admin_tenant_name = 'services', + $user_domain_name = 'Default', + $project_domain_name = 'Default', + $region_name = $::os_service_default, + $nova_scheduler_default_filters = $::os_service_default, + $nova_ram_allocation_ratio = $::os_service_default, + $nova_scheduler_driver = $::os_service_default, + $nova_disk_allocation_ratio = $::os_service_default, + $nova_cpu_allocation_ratio = $::os_service_default, + $nova_max_instances_per_host = $::os_service_default, + $nova_scheduler_available_filters = $::os_service_default, +) { + + include ::openstacklib::openstackclient + + include ::watcher::deps + include ::watcher::params + include ::watcher::policy + include ::watcher::db + include ::watcher::logging + + package { 'watcher': + ensure => $ensure_package, + name => $::watcher::params::common_package_name, + tag => ['openstack', 'watcher-package'], + } + + resources { 'watcher_config': + purge => $purge_config, + } + + if $rpc_backend == 'rabbit' { + + watcher_config { + 'oslo_messaging_rabbit/rabbit_userid' : value => $rabbit_os_user; + 'oslo_messaging_rabbit/rabbit_password' : value => $rabbit_os_password; + 'oslo_messaging_rabbit/rabbit_hosts' : value => $rabbit_os_host; + 'oslo_messaging_rabbit/rabbit_ha_queues': value => $rabbit_ha_queues; + } + } else { + watcher_config { 'DEFAULT/rpc_backend': value => $rpc_backend } + } + + + watcher_config { + 'DEFAULT/scheduler_default_filters': value => $nova_scheduler_default_filters; + 'DEFAULT/ram_allocation_ratio': value => $nova_ram_allocation_ratio; + 'DEFAULT/scheduler_driver': value => $nova_scheduler_driver; + 'DEFAULT/disk_allocation_ratio': value => $nova_disk_allocation_ratio; + 'DEFAULT/cpu_allocation_ratio': value => $nova_cpu_allocation_ratio; + 'DEFAULT/max_instances_per_host': value => $nova_max_instances_per_host; + 'DEFAULT/scheduler_available_filters': value => $nova_scheduler_available_filters; + 'keystone_authtoken/region_name': value => $region_name; + 'keystone_authtoken/auth_uri' : value => $auth_uri; + 'keystone_authtoken/auth_url' : value => $auth_url; + 'keystone_authtoken/identity_uri' : value => $identity_uri; + 'keystone_authtoken/admin_user' : value => $admin_user; + 'keystone_authtoken/admin_password' : value => $admin_password; + 'keystone_authtoken/username' : value => $username; + 'keystone_authtoken/project_name' : value => $admin_tenant_name; + 'keystone_authtoken/admin_tenant_name' : value => $admin_tenant_name; + 'keystone_authtoken/password' : value => $password; + 'keystone_authtoken/user_domain_name' : value => $user_domain_name; + 'keystone_authtoken/project_domain_name' : value => $project_domain_name; + } + + + watcher_config { + 'oslo_messaging_default/transport_url': value => $default_transport_url; + 'oslo_messaging_default/rpc_response_timeout': value => $rpc_response_timeout; + 'oslo_messaging_default/control_exchange': value => $control_exchange; + } + + watcher_config { + 'oslo_messaging_notification/transport_url': value => $notification_transport_url; + 'oslo_messaging_notification/driver': value => $notification_driver; + 'oslo_messaging_notification/topics': value => $notification_topics; + } +} + diff --git a/deployment_scripts/modules/watcher/manifests/keystone/auth.pp b/deployment_scripts/modules/watcher/manifests/keystone/auth.pp new file mode 100644 index 0000000..94a6667 --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/keystone/auth.pp @@ -0,0 +1,101 @@ +# == Class: watcher::keystone::auth +# +# Configures watcher user, service and endpoint in Keystone. +# +# === Parameters +# +# [*password*] +# (required) Password for watcher user. +# +# [*auth_name*] +# Username for watcher service. Defaults to 'watcher'. +# +# [*email*] +# Email for watcher user. Defaults to 'watcher@localhost'. +# +# [*tenant*] +# Tenant for watcher user. Defaults to 'services'. +# +# [*configure_endpoint*] +# Should watcher endpoint be configured? Defaults to 'true'. +# +# [*configure_user*] +# (Optional) Should the service user be configured? +# Defaults to 'true'. +# +# [*configure_user_role*] +# (Optional) Should the admin role be configured for the service user? +# Defaults to 'true'. +# +# [*service_type*] +# Type of service. Defaults to 'key-manager'. +# +# [*region*] +# Region for endpoint. Defaults to 'RegionOne'. +# +# [*service_name*] +# (optional) Name of the service. +# Defaults to the value of auth_name. +# +# [*service_description*] +# (optional) Description of the service. +# Default to 'watcher API Service' +# +# [*public_url*] +# (optional) The endpoint's public url. (Defaults to 'http://127.0.0.1:9322') +# This url should *not* contain any trailing '/'. +# +# [*admin_url*] +# (optional) The endpoint's admin url. (Defaults to 'http://127.0.0.1:9322') +# This url should *not* contain any trailing '/'. +# +# [*internal_url*] +# (optional) The endpoint's internal url. (Defaults to 'http://127.0.0.1:9322') +# +class watcher::keystone::auth ( + $password, + $auth_name = 'watcher', + $email = 'watcher@localhost', + $tenant = 'services', + $configure_endpoint = true, + $configure_user = true, + $configure_user_role = true, + $service_name = undef, + $service_description = 'Infrastructure Optimization service', + $service_type = 'infra-optim', + $region = 'RegionOne', + $public_url = 'http://127.0.0.1:9322', + $admin_url = 'http://127.0.0.1:9322', + $internal_url = 'http://127.0.0.1:9322', +) { + + include ::watcher::deps + + $real_service_name = pick($service_name, $auth_name) + + if $configure_user_role { + Keystone_user_role["${auth_name}@${tenant}"] ~> Anchor['watcher::service::end'] + } + + if $configure_endpoint { + Keystone_endpoint["${region}/${real_service_name}::${service_type}"] ~> Anchor['watcher::service::end'] + } + + keystone::resource::service_identity { 'watcher': + configure_user => $configure_user, + configure_user_role => $configure_user_role, + configure_endpoint => $configure_endpoint, + service_name => $real_service_name, + service_type => $service_type, + service_description => $service_description, + region => $region, + auth_name => $auth_name, + password => $password, + email => $email, + tenant => $tenant, + public_url => $public_url, + internal_url => $internal_url, + admin_url => $admin_url, + } + +} diff --git a/deployment_scripts/modules/watcher/manifests/keystone/authtoken.pp b/deployment_scripts/modules/watcher/manifests/keystone/authtoken.pp new file mode 100644 index 0000000..2d7d1aa --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/keystone/authtoken.pp @@ -0,0 +1,274 @@ +# == Class: watcher::keystone::authtoken +# +# Configure the keystone_authtoken section in the configuration file +# +# === Parameters: +# +# [*password*] +# (Optional) Password to create for the service user +# Defaults to $::os_service_default +# +# [*username*] +# (Optional) The name of the service user +# Defaults to 'watcher' +# +# [*auth_url*] +# (Optional) The URL to use for authentication. +# Defaults to 'http://localhost:35357' +# +# [*project_name*] +# (Optional) Service project name +# Defaults to 'services' +# +# [*user_domain_name*] +# (Optional) Name of domain for $username +# Defaults to $::os_service_default +# +# [*project_domain_name*] +# (Optional) Name of domain for $project_name +# Defaults to $::os_service_default +# +# [*insecure*] +# (Optional) If true, explicitly allow TLS without checking server cert +# against any certificate authorities. WARNING: not recommended. Use with +# caution. +# Defaults to $:os_service_default +# +# [*auth_section*] +# (Optional) Config Section from which to load plugin specific options +# Defaults to $::os_service_default. +# +# [*auth_type*] +# (Optional) Authentication type to load +# Defaults to 'password' +# +# [*auth_uri*] +# (Optional) Complete public Identity API endpoint. +# Defaults to 'http://localhost:5000' +# +# [*auth_version*] +# (Optional) API version of the admin Identity API endpoint. +# Defaults to $::os_service_default. +# +# [*cache*] +# (Optional) Env key for the swift cache. +# Defaults to $::os_service_default. +# +# [*cafile*] +# (Optional) A PEM encoded Certificate Authority to use when verifying HTTPs +# connections. +# Defaults to $::os_service_default. +# +# [*certfile*] +# (Optional) Required if identity server requires client certificate +# Defaults to $::os_service_default. +# +# [*check_revocations_for_cached*] +# (Optional) If true, the revocation list will be checked for cached tokens. +# This requires that PKI tokens are configured on the identity server. +# boolean value. +# Defaults to $::os_service_default. +# +# [*delay_auth_decision*] +# (Optional) Do not handle authorization requests within the middleware, but +# delegate the authorization decision to downstream WSGI components. Boolean +# value +# Defaults to $::os_service_default. +# +# [*enforce_token_bind*] +# (Optional) Used to control the use and type of token binding. Can be set +# to: "disabled" to not check token binding. "permissive" (default) to +# validate binding information if the bind type is of a form known to the +# server and ignore it if not. "strict" like "permissive" but if the bind +# type is unknown the token will be rejected. "required" any form of token +# binding is needed to be allowed. Finally the name of a binding method that +# must be present in tokens. String value. +# Defaults to $::os_service_default. +# +# [*hash_algorithms*] +# (Optional) Hash algorithms to use for hashing PKI tokens. This may be a +# single algorithm or multiple. The algorithms are those supported by Python +# standard hashlib.new(). The hashes will be tried in the order given, so put +# the preferred one first for performance. The result of the first hash will +# be stored in the cache. This will typically be set to multiple values only +# while migrating from a less secure algorithm to a more secure one. Once all +# the old tokens are expired this option should be set to a single value for +# better performance. List value. +# Defaults to $::os_service_default. +# +# [*http_connect_timeout*] +# (Optional) Request timeout value for communicating with Identity API +# server. +# Defaults to $::os_service_default. +# +# [*http_request_max_retries*] +# (Optional) How many times are we trying to reconnect when communicating +# with Identity API Server. Integer value +# Defaults to $::os_service_default. +# +# [*include_service_catalog*] +# (Optional) Indicate whether to set the X-Service-Catalog header. If False, +# middleware will not ask for service catalog on token validation and will +# not set the X-Service-Catalog header. Boolean value. +# Defaults to $::os_service_default. +# +# [*keyfile*] +# (Optional) Required if identity server requires client certificate +# Defaults to $::os_service_default. +# +# [*memcache_pool_conn_get_timeout*] +# (Optional) Number of seconds that an operation will wait to get a memcached +# client connection from the pool. Integer value +# Defaults to $::os_service_default. +# +# [*memcache_pool_dead_retry*] +# (Optional) Number of seconds memcached server is considered dead before it +# is tried again. Integer value +# Defaults to $::os_service_default. +# +# [*memcache_pool_maxsize*] +# (Optional) Maximum total number of open connections to every memcached +# server. Integer value +# Defaults to $::os_service_default. +# +# [*memcache_pool_socket_timeout*] +# (Optional) Number of seconds a connection to memcached is held unused in +# the +# pool before it is closed. Integer value +# Defaults to $::os_service_default. +# +# [*memcache_pool_unused_timeout*] +# (Optional) Number of seconds a connection to memcached is held unused in +# the +# pool before it is closed. Integer value +# Defaults to $::os_service_default. +# +# [*memcache_secret_key*] +# (Optional, mandatory if memcache_security_strategy is defined) This string +# is used for key derivation. +# Defaults to $::os_service_default. +# +# [*memcache_security_strategy*] +# (Optional) If defined, indicate whether token data should be authenticated +# or authenticated and encrypted. If MAC, token data is authenticated (with +# HMAC) in the cache. If ENCRYPT, token data is encrypted and authenticated +# in the cache. If the value is not one of these options or empty, +# auth_token will raise an exception on initialization. +# Defaults to $::os_service_default. +# +# [*memcache_use_advanced_pool*] +# (Optional) Use the advanced (eventlet safe) memcached client pool. The +# advanced pool will only work under python 2.x Boolean value +# Defaults to $::os_service_default. +# +# [*memcached_servers*] +# (Optional) Optionally specify a list of memcached server(s) to use for +# caching. If left undefined, tokens will instead be cached in-process. +# Defaults to $::os_service_default. +# +# [*manage_memcache_package*] +# (Optional) Whether to install the python-memcache package. +# Defaults to false. +# +# [*region_name*] +# (Optional) The region in which the identity server can be found. +# Defaults to $::os_service_default. +# +# [*revocation_cache_time*] +# (Optional) Determines the frequency at which the list of revoked tokens is +# retrieved from the Identity service (in seconds). A high number of +# revocation events combined with a low cache duration may significantly +# reduce performance. Only valid for PKI tokens. Integer value +# Defaults to $::os_service_default. +# +# [*token_cache_time*] +# (Optional) In order to prevent excessive effort spent validating tokens, +# the middleware caches previously-seen tokens for a configurable duration +# (in seconds). Set to -1 to disable caching completely. Integer value +# Defaults to $::os_service_default. +# +class watcher::keystone::authtoken ( + $password = $::os_service_default, + $username = 'watcher', + $auth_url = 'http://localhost:35357', + $project_name = 'services', + $user_domain_name = $::os_service_default, + $project_domain_name = $::os_service_default, + $insecure = $::os_service_default, + $auth_section = $::os_service_default, + $auth_type = 'password', + $auth_uri = 'http://localhost:5000', + $auth_version = $::os_service_default, + $cache = $::os_service_default, + $cafile = $::os_service_default, + $certfile = $::os_service_default, + $check_revocations_for_cached = $::os_service_default, + $delay_auth_decision = $::os_service_default, + $enforce_token_bind = $::os_service_default, + $hash_algorithms = $::os_service_default, + $http_connect_timeout = $::os_service_default, + $http_request_max_retries = $::os_service_default, + $include_service_catalog = $::os_service_default, + $keyfile = $::os_service_default, + $memcache_pool_conn_get_timeout = $::os_service_default, + $memcache_pool_dead_retry = $::os_service_default, + $memcache_pool_maxsize = $::os_service_default, + $memcache_pool_socket_timeout = $::os_service_default, + $memcache_secret_key = $::os_service_default, + $memcache_security_strategy = $::os_service_default, + $memcache_use_advanced_pool = $::os_service_default, + $memcache_pool_unused_timeout = $::os_service_default, + $memcached_servers = $::os_service_default, + $manage_memcache_package = false, + $region_name = $::os_service_default, + $revocation_cache_time = $::os_service_default, + $token_cache_time = $::os_service_default, +) { + + include ::watcher::deps + + if is_service_default($password) and ! $::watcher::api::watcher_client_password { + fail('Please set password for watcher service user') + } + + validate_string($password) + + keystone::resource::authtoken { 'watcher_config': + password => $password, + username => $username, + project_name => $project_name, + auth_url => $auth_url, + auth_uri => $auth_uri, + auth_version => $auth_version, + auth_type => $auth_type, + auth_section => $auth_section, + user_domain_name => $user_domain_name, + project_domain_name => $project_domain_name, + insecure => $insecure, + cache => $cache, + cafile => $cafile, + certfile => $certfile, + check_revocations_for_cached => $check_revocations_for_cached, + delay_auth_decision => $delay_auth_decision, + enforce_token_bind => $enforce_token_bind, + hash_algorithms => $hash_algorithms, + http_connect_timeout => $http_connect_timeout, + http_request_max_retries => $http_request_max_retries, + include_service_catalog => $include_service_catalog, + keyfile => $keyfile, + memcache_pool_conn_get_timeout => $memcache_pool_conn_get_timeout, + memcache_pool_dead_retry => $memcache_pool_dead_retry, + memcache_pool_maxsize => $memcache_pool_maxsize, + memcache_pool_socket_timeout => $memcache_pool_socket_timeout, + memcache_secret_key => $memcache_secret_key, + memcache_security_strategy => $memcache_security_strategy, + memcache_use_advanced_pool => $memcache_use_advanced_pool, + memcache_pool_unused_timeout => $memcache_pool_unused_timeout, + memcached_servers => $memcached_servers, + manage_memcache_package => $manage_memcache_package, + region_name => $region_name, + revocation_cache_time => $revocation_cache_time, + token_cache_time => $token_cache_time, + } + +} diff --git a/deployment_scripts/modules/watcher/manifests/logging.pp b/deployment_scripts/modules/watcher/manifests/logging.pp new file mode 100644 index 0000000..ca34a18 --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/logging.pp @@ -0,0 +1,118 @@ +# Class watcher::logging +# +# watcher logging configuration +# +# == parameters +# +# [*debug*] +# (Optional) Should the daemons log debug messages +# Defaults to $::os_service_default +# +# [*use_syslog*] +# (Optional) Use syslog for logging. +# Defaults to $::os_service_default +# +# [*use_stderr*] +# (optional) Use stderr for logging +# Defaults to $::os_service_default +# +# [*syslog_log_facility*] +# (Optional) Syslog facility to receive log lines. +# Defaults to $::os_service_default +# +# [*log_dir*] +# (optional) Directory where logs should be stored. +# If set to $::os_service_default, it will not log to any directory. +# Defaults to '/var/log/watcher'. +# +# [*log_file*] +# (optional) File where logs should be stored. +# Defaults to '/var/log/watcher/watcher.log' +# +# [*logging_context_format_string*] +# (optional) Format string to use for log messages with context. +# Defaults to $::os_service_default +# Example: '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s\ +# [%(request_id)s %(user_identity)s] %(instance)s%(message)s' +# +# [*logging_default_format_string*] +# (optional) Format string to use for log messages without context. +# Defaults to $::os_service_default +# Example: '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s\ +# [-] %(instance)s%(message)s' +# +# [*logging_debug_format_suffix*] +# (optional) Formatted data to append to log format when level is DEBUG. +# Defaults to $::os_service_default +# Example: '%(funcName)s %(pathname)s:%(lineno)d' +# +# [*logging_exception_prefix*] +# (optional) Prefix each line of exception output with this format. +# Defaults to $::os_service_default +# Example: '%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s' +# +# [*log_config_append*] +# (optional) The name of an additional logging configuration file. +# Defaults to $::os_service_default +# See https://docs.python.org/2/howto/logging.html +# +# [*default_log_levels*] +# (optional) Hash of logger (keys) and level (values) pairs. +# Defaults to $::os_service_default +# Example: +# { 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN', +# 'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO', +# 'oslo.messaging' => 'INFO', 'iso8601' => 'WARN', +# 'requests.packages.urllib3.connectionpool' => 'WARN', +# 'urllib3.connectionpool' => 'WARN', +# 'websocket' => 'WARN', 'watchermiddleware' => 'WARN', +# 'routes.middleware' => 'WARN', stevedore => 'WARN' } +# +# [*publish_errors*] +# (optional) Publish error events (boolean value). +# Defaults to $::os_service_default +# +# [*fatal_deprecations*] +# (optional) Make deprecations fatal (boolean value) +# Defaults to $::os_service_default +# +# [*instance_format*] +# (optional) If an instance is passed with the log message, format it +# like this (string value). +# Defaults to undef. +# Example: '[instance: %(uuid)s] ' +# +# [*instance_uuid_format*] +# (optional) If an instance UUID is passed with the log message, format +# it like this (string value). +# Defaults to $::os_service_default +# Example: instance_uuid_format='[instance: %(uuid)s] ' +# +# [*log_date_format*] +# (optional) Format string for %%(asctime)s in log records. +# Defaults to $::os_service_default +# Example: 'Y-%m-%d %H:%M:%S' + +class watcher::logging( + $use_syslog = $::os_service_default, + $use_stderr = $::os_service_default, + $syslog_log_facility = $::os_service_default, + $log_dir = '/var/log/watcher', + $log_file = '/var/log/watcher/watcher.log', + $debug = $::os_service_default, + $logging_context_format_string = $::os_service_default, + $logging_default_format_string = $::os_service_default, + $logging_debug_format_suffix = $::os_service_default, + $logging_exception_prefix = $::os_service_default, + $log_config_append = $::os_service_default, + $default_log_levels = $::os_service_default, + $publish_errors = $::os_service_default, + $fatal_deprecations = $::os_service_default, + $instance_format = $::os_service_default, + $instance_uuid_format = $::os_service_default, + $log_date_format = $::os_service_default, +) { + + include ::watcher::deps + +} diff --git a/deployment_scripts/modules/watcher/manifests/params.pp b/deployment_scripts/modules/watcher/manifests/params.pp new file mode 100644 index 0000000..8d1ac98 --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/params.pp @@ -0,0 +1,29 @@ +# Parameters for puppet-watcher +# +class watcher::params { + + case $::osfamily { + 'RedHat': { + $api_service_name = 'openstack-watcher-api' + $api_package_name = 'openstack-watcher-api' + $common_package_name = 'openstack-watcher-common' + $applier_package_name = 'openstack-watcher-applier' + $applier_service_name = 'openstack-watcher-applier' + $decision_engine_package_name = 'openstack-watcher-decision-engine' + $decision_engine_service_name = 'openstack-watcher-decision-engine' + } + 'Debian': { + $api_service_name = 'watcher-api' + $api_package_name = 'watcher-api' + $common_package_name = 'watcher-common' + $applier_package_name = 'watcher-applier' + $applier_service_name = 'watcher-applier' + $decision_engine_package_name = 'watcher-decision-engine' + $decision_engine_service_name = 'watcher-decision-engine' + } + default: { + fail("Unsupported osfamily: ${::osfamily} operatingsystem") + } + + } # Case $::osfamily +} diff --git a/deployment_scripts/modules/watcher/manifests/policy.pp b/deployment_scripts/modules/watcher/manifests/policy.pp new file mode 100644 index 0000000..21dd93f --- /dev/null +++ b/deployment_scripts/modules/watcher/manifests/policy.pp @@ -0,0 +1,42 @@ +# == Class: watcher::policy +# +# Configure the watcher policies +# +# === Parameters +# +# [*policies*] +# (optional) Set of policies to configure for watcher +# Example : +# { +# 'watcher-context_is_admin' => { +# 'key' => 'context_is_admin', +# 'value' => 'true' +# }, +# 'watcher-default' => { +# 'key' => 'default', +# 'value' => 'rule:admin_or_owner' +# } +# } +# Defaults to empty hash. +# +# [*policy_path*] +# (optional) Path to the nova policy.json file +# Defaults to /etc/watcher/policy.json +# +class watcher::policy ( + $policies = {}, + $policy_path = '/etc/watcher/policy.json', +) { + + include ::watcher::deps + + validate_hash($policies) + + Openstacklib::Policy::Base { + file_path => $policy_path, + } + + create_resources('openstacklib::policy::base', $policies) + + +} diff --git a/deployment_scripts/modules/watcher/metadata.json b/deployment_scripts/modules/watcher/metadata.json new file mode 100644 index 0000000..f72cefe --- /dev/null +++ b/deployment_scripts/modules/watcher/metadata.json @@ -0,0 +1,67 @@ +{ + "name": "openstack-watcher", + "version": "10.3.0", + "author": "OpenStack Contributors", + "summary": "Puppet module for OpenStack Watcher", + "license": "Apache-2.0", + "source": "git://github.com/openstack/puppet-watcher.git", + "project_page": "https://launchpad.net/puppet-watcher", + "issues_url": "https://bugs.launchpad.net/puppet-watcher", + "description": "Installs and configures OpenStack Watcher.", + "requirements": [ + { + "name": "pe", + "version_requirement": "4.x" + }, + { + "name": "puppet", + "version_requirement": "4.x" + } + ], + "operatingsystem_support": [ + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "8" + ] + }, + { + "operatingsystem": "Fedora", + "operatingsystemrelease": [ + "21", + "22" + ] + }, + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "7" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "14.04", + "16.04" + ] + } + ], + "dependencies": [ + { + "name": "puppetlabs/inifile", + "version_requirement": ">=1.0.0 <2.0.0" + }, + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 4.2.0 <5.0.0" + }, + { + "name": "openstack/openstacklib", + "version_requirement": ">=10.3.0 <11.0.0" + }, + { + "name": "openstack/oslo", + "version_requirement": ">=10.3.0 <11.0.0" + } + ] +} diff --git a/deployment_scripts/modules/watcher/releasenotes/source/_static/.placeholder b/deployment_scripts/modules/watcher/releasenotes/source/_static/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/deployment_scripts/modules/watcher/releasenotes/source/conf.py b/deployment_scripts/modules/watcher/releasenotes/source/conf.py new file mode 100644 index 0000000..dea0d42 --- /dev/null +++ b/deployment_scripts/modules/watcher/releasenotes/source/conf.py @@ -0,0 +1,262 @@ +# -*- coding: utf-8 -*- +# 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. +# + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'oslosphinx', + 'reno.sphinxext', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'puppet-watcher Release Notes' +copyright = u'2016, Puppet OpenStack Developers' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '10.3.0' +# The full version, including alpha/beta/rc tags. +release = '10.3.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'puppet-watcherReleaseNotesdoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ('index', 'puppet-watcherReleaseNotes.tex', u'puppet-watcher Release Notes Documentation', + u'2016, Puppet OpenStack Developers', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'puppet-watcherreleasenotes', u'puppet-watcher Release Notes Documentation', + [u'2016, Puppet OpenStack Developers'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'puppet-watcherReleaseNotes', u'puppet-watcher Release Notes Documentation', + u'2016, Puppet OpenStack Developers', 'puppet-watcherReleaseNotes', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False + +# -- Options for Internationalization output ------------------------------ +locale_dirs = ['locale/'] diff --git a/deployment_scripts/modules/watcher/releasenotes/source/index.rst b/deployment_scripts/modules/watcher/releasenotes/source/index.rst new file mode 100644 index 0000000..33cc3da --- /dev/null +++ b/deployment_scripts/modules/watcher/releasenotes/source/index.rst @@ -0,0 +1,18 @@ +======================================== +Welcome to puppet-watcher Release Notes! +======================================== + +Contents +======== + +.. toctree:: + :maxdepth: 2 + + unreleased + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`search` diff --git a/deployment_scripts/modules/watcher/releasenotes/source/unreleased.rst b/deployment_scripts/modules/watcher/releasenotes/source/unreleased.rst new file mode 100644 index 0000000..2334dd5 --- /dev/null +++ b/deployment_scripts/modules/watcher/releasenotes/source/unreleased.rst @@ -0,0 +1,5 @@ +============================== + Current Series Release Notes +============================== + + .. release-notes:: diff --git a/deployment_scripts/modules/watcher/setup.cfg b/deployment_scripts/modules/watcher/setup.cfg new file mode 100644 index 0000000..0112e0b --- /dev/null +++ b/deployment_scripts/modules/watcher/setup.cfg @@ -0,0 +1,13 @@ +[metadata] +name = puppet-watcher +summary = Puppet module for OpenStack Watcher +description-file = + README.md +author = Puppet Labs and OpenStack Contributors +author-email = openstack-dev@lists.openstack.org +home-page = http://docs.openstack.org/developer/puppet-openstack-guide +classifier = + Intended Audience :: Developers + Intended Audience :: System Administrators + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux diff --git a/deployment_scripts/modules/watcher/setup.py b/deployment_scripts/modules/watcher/setup.py new file mode 100644 index 0000000..70c2b3f --- /dev/null +++ b/deployment_scripts/modules/watcher/setup.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# 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. + +# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import setuptools + +setuptools.setup( + setup_requires=['pbr'], + pbr=True) diff --git a/deployment_scripts/modules/watcher/spec/acceptance/nodesets/centos-70-x64.yml b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/centos-70-x64.yml new file mode 100644 index 0000000..5f097e9 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/centos-70-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + centos-server-70-x64: + roles: + - master + platform: el-7-x86_64 + box: puppetlabs/centos-7.0-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/centos-7.0-64-nocm + hypervisor: vagrant +CONFIG: + log_level: debug + type: foss diff --git a/deployment_scripts/modules/watcher/spec/acceptance/nodesets/default.yml b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..486b6a3 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/default.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-server-14.04-amd64: + roles: + - master + platform: ubuntu-14.04-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm + hypervisor: vagrant +CONFIG: + type: foss diff --git a/deployment_scripts/modules/watcher/spec/acceptance/nodesets/nodepool-centos7.yml b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/nodepool-centos7.yml new file mode 100644 index 0000000..c552874 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/nodepool-centos7.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-70-x64: + roles: + - master + platform: el-7-x86_64 + hypervisor: none + ip: 127.0.0.1 +CONFIG: + type: foss + set_env: false diff --git a/deployment_scripts/modules/watcher/spec/acceptance/nodesets/nodepool-trusty.yml b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/nodepool-trusty.yml new file mode 100644 index 0000000..9fc624e --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/nodepool-trusty.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-14.04-amd64: + roles: + - master + platform: ubuntu-14.04-amd64 + hypervisor: none + ip: 127.0.0.1 +CONFIG: + type: foss + set_env: false diff --git a/deployment_scripts/modules/watcher/spec/acceptance/nodesets/nodepool-xenial.yml b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/nodepool-xenial.yml new file mode 100644 index 0000000..99dd318 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/nodepool-xenial.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-16.04-amd64: + roles: + - master + platform: ubuntu-16.04-amd64 + hypervisor: none + ip: 127.0.0.1 +CONFIG: + type: foss + set_env: false diff --git a/deployment_scripts/modules/watcher/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml new file mode 100644 index 0000000..8001929 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + ubuntu-server-14.04-amd64: + roles: + - master + platform: ubuntu-14.04-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm + hypervisor: vagrant +CONFIG: + log_level: debug + type: foss diff --git a/deployment_scripts/modules/watcher/spec/acceptance/watcher_spec.rb b/deployment_scripts/modules/watcher/spec/acceptance/watcher_spec.rb new file mode 100644 index 0000000..e7708ab --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/acceptance/watcher_spec.rb @@ -0,0 +1,77 @@ +require 'spec_helper_acceptance' + +describe 'basic watcher' do + + context 'default parameters' do + + it 'should work with no errors' do + pp= <<-EOS + include ::openstack_integration + include ::openstack_integration::repos + include ::openstack_integration::rabbitmq + include ::openstack_integration::mysql + include ::openstack_integration::keystone + + rabbitmq_user { 'watcher': + admin => true, + password => 'my_secret', + provider => 'rabbitmqctl', + require => Class['rabbitmq'], + } + + rabbitmq_user_permissions { 'watcher@/': + configure_permission => '.*', + write_permission => '.*', + read_permission => '.*', + provider => 'rabbitmqctl', + require => Class['rabbitmq'], + } + + # TODO(aschultz): fix after Ubuntu ocata-m3/rc1. watcher-db-manage is + # broken + if ($::osfamily == 'RedHat') { + class { '::watcher::db::mysql': + password => 'a_big_secret', + } + class { '::watcher::db': + database_connection => 'mysql+pymysql://watcher:a_big_secret@127.0.0.1/watcher?charset=utf8', + } + class { '::watcher::keystone::auth': + password => 'a_big_secret', + } + class { '::watcher::keystone::authtoken': + password => 'a_big_secret', + } + class { '::watcher::logging': + debug => true, + } + class { '::watcher': + default_transport_url => 'rabbit://watcher:my_secret@127.0.0.1:5672/', + } + class { '::watcher::api': + watcher_client_password => 'a_big_secret', + create_db_schema => true, + upgrade_db => true, + } + class { '::watcher::applier': + applier_workers => '2', + } + class { '::watcher::decision_engine': + decision_engine_workers => '2', + } + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + if os[:family].casecmp('RedHat') == 0 + describe port(9322) do + it { is_expected.to be_listening } + end + end + end + +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_api_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_api_spec.rb new file mode 100644 index 0000000..40ddcef --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_api_spec.rb @@ -0,0 +1,161 @@ +require 'spec_helper' + +describe 'watcher::api' do + + let :params do + { :watcher_client_password => 'password', + :manage_service => true, + :enabled => true, + :package_ensure => 'latest', + } + end + + shared_examples 'watcher-api' do + + context 'without required parameter watcher_client_password' do + before { params.delete(:watcher_client_password) } + it { expect { is_expected.to raise_error(Puppet::Error) } } + end + + it { is_expected.to contain_class('watcher::params') } + it { is_expected.to contain_class('watcher::deps') } + + it 'installs watcher-api package' do + is_expected.to contain_package('watcher-api').with( + :ensure => 'latest', + :name => platform_params[:api_package_name], + :tag => ['openstack', 'watcher-package'], + ) + end + + [{:enabled => true}, {:enabled => false}].each do |param_hash| + context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do + before do + params.merge!(param_hash) + end + + it 'configures watcher-api service' do + is_expected.to contain_service('watcher-api').with( + :ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped', + :name => platform_params[:api_service_name], + :enable => params[:enabled], + :hasstatus => true, + :hasrestart => true, + :tag => ['watcher-service', + 'watcher-db-manage-create_schema', + 'watcher-db-manage-upgrade'], + ) + end + end + end + + context 'with default api configuration' do + it 'should configure the api configurations section when enabled' do + is_expected.to contain_watcher_config('api/port').with_value('9322') + is_expected.to contain_watcher_config('api/max_limit').with_value('') + is_expected.to contain_watcher_config('api/host').with_value('0.0.0.0') + is_expected.to contain_watcher_config('api/workers').with_value(2) + is_expected.to contain_watcher_config('api/enable_ssl_api').with_value('') + end + end + + context 'with disabled service managing' do + before do + params.merge!({ + :manage_service => false, + :enabled => false }) + end + + it 'configures watcher-api service' do + is_expected.to contain_service('watcher-api').with( + :ensure => nil, + :name => platform_params[:api_service_name], + :enable => false, + :hasstatus => true, + :hasrestart => true, + :tag => ['watcher-service', + 'watcher-db-manage-create_schema', + 'watcher-db-manage-upgrade'], + ) + end + + it 'should not configure the api configurations section when disabled' do + is_expected.to_not contain_watcher_config('api/port') + is_expected.to_not contain_watcher_config('api/max_limit') + is_expected.to_not contain_watcher_config('api/host') + is_expected.to_not contain_watcher_config('api/workers') + is_expected.to_not contain_watcher_config('api/enable_ssl_api') + end + + end + + context 'watcher clients auth section with default parameters' do + it 'configures watcher clients auth' do + is_expected.to contain_watcher_config('watcher_clients_auth/username').with_value('watcher') + is_expected.to contain_watcher_config('watcher_clients_auth/password').with_value( params[:watcher_client_password] ) + is_expected.to contain_watcher_config('watcher_clients_auth/auth_url').with_value('http://localhost:35357/') + is_expected.to contain_watcher_config('watcher_clients_auth/auth_uri').with_value('http://localhost:5000/') + is_expected.to contain_watcher_config('watcher_clients_auth/project_name').with_value('service') + is_expected.to contain_watcher_config('watcher_clients_auth/project_domain_name').with_value('') + is_expected.to contain_watcher_config('watcher_clients_auth/insecure').with_value('') + is_expected.to contain_watcher_config('watcher_clients_auth/auth_type').with_value('password') + is_expected.to contain_watcher_config('watcher_clients_auth/cafile').with_value('') + is_expected.to contain_watcher_config('watcher_clients_auth/certfile').with_value('') + is_expected.to contain_watcher_config('watcher_clients_auth/keyfile').with_value('') + end + end + + context 'watcher clients auth section with overridden parameters' do + before do + params.merge! ({ + :watcher_client_username => 'watcher_user', + :watcher_client_password => 'PassWoRD', + :watcher_client_auth_uri => 'http://localhost:5001/', + :watcher_client_auth_url => 'http://localhost:35358/', + :watcher_client_project_name => 'ProjectZero', + :watcher_client_project_domain_name => 'WatcherDomain', + :watcher_client_insecure => 'true', + :watcher_client_auth_type => 'password', + :watcher_client_cafile => '/tmp/ca.crt', + :watcher_client_certfile => '/tmp/watcher.com.crt', + :watcher_client_keyfile => '/tmp/key.pm', + }) + end + it 'configures watcher clients auth' do + is_expected.to contain_watcher_config('watcher_clients_auth/username').with_value( params[:watcher_client_username] ) + is_expected.to contain_watcher_config('watcher_clients_auth/password').with_value( params[:watcher_client_password] ) + is_expected.to contain_watcher_config('watcher_clients_auth/auth_uri').with_value('http://localhost:5001/') + is_expected.to contain_watcher_config('watcher_clients_auth/auth_url').with_value('http://localhost:35358/') + is_expected.to contain_watcher_config('watcher_clients_auth/project_name').with_value( params[:watcher_client_project_name] ) + is_expected.to contain_watcher_config('watcher_clients_auth/project_domain_name').with_value( params[:watcher_client_project_domain_name] ) + is_expected.to contain_watcher_config('watcher_clients_auth/insecure').with_value( params[:watcher_client_insecure] ) + is_expected.to contain_watcher_config('watcher_clients_auth/auth_type').with_value( params[:watcher_client_auth_type] ) + is_expected.to contain_watcher_config('watcher_clients_auth/cafile').with_value( params[:watcher_client_cafile] ) + is_expected.to contain_watcher_config('watcher_clients_auth/certfile').with_value( params[:watcher_client_certfile] ) + is_expected.to contain_watcher_config('watcher_clients_auth/keyfile').with_value( params[:watcher_client_keyfile] ) + end + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :api_package_name => 'watcher-api', + :api_service_name => 'watcher-api' } + when 'RedHat' + { :api_package_name => 'openstack-watcher-api', + :api_service_name => 'openstack-watcher-api' } + end + end + it_behaves_like 'watcher-api' + end + end + +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_applier_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_applier_spec.rb new file mode 100644 index 0000000..f5b98dd --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_applier_spec.rb @@ -0,0 +1,93 @@ +require 'spec_helper' + +describe 'watcher::applier' do + + shared_examples 'watcher-applier' do + + context 'with default parameters' do + + it 'installs packages' do + is_expected.to contain_package('watcher-applier').with( + :name => platform_params[:watcher_applier_package], + :ensure => 'present', + :tag => ['openstack', 'watcher-package'] + ) + end + + it 'configures watcher applier service' do + is_expected.to contain_watcher_config('watcher_applier/workers').with_value('') + is_expected.to contain_watcher_config('watcher_applier/conductor_topic').with_value('') + is_expected.to contain_watcher_config('watcher_applier/status_topic').with_value('') + is_expected.to contain_watcher_config('watcher_applier/publisher_id').with_value('') + is_expected.to contain_watcher_config('watcher_applier/workflow_engine').with_value('') + end + end + + [{:enabled => true}, {:enabled => false}].each do |param_hash| + context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do + let :params do + { :enabled => true, + :manage_service => true, + } + end + before do + params.merge!(param_hash) + end + + it 'configures watcher applier service' do + is_expected.to contain_service('watcher-applier').with( + :ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped', + :name => platform_params[:applier_service_name], + :enable => params[:enabled], + :hasstatus => true, + :hasrestart => true, + :tag => ['watcher-service'], + ) + end + end + end + + context 'with overridden parameters' do + let :params do + { + :package_ensure => '2012.1.1-15.el6', + :applier_workers => '10', + :applier_conductor_topic => 'applier123', + :applier_status_topic => 'someStatus', + :applier_publisher_id => '20120101', + :applier_workflow_engine => 'taskFloooow', + } + end + it 'configures watcher applier' do + is_expected.to contain_watcher_config('watcher_applier/workers').with_value('10') + is_expected.to contain_watcher_config('watcher_applier/conductor_topic').with_value('applier123') + is_expected.to contain_watcher_config('watcher_applier/status_topic').with_value('someStatus') + is_expected.to contain_watcher_config('watcher_applier/publisher_id').with_value('20120101') + is_expected.to contain_watcher_config('watcher_applier/workflow_engine').with_value('taskFloooow') + end + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :watcher_applier_package => 'watcher-applier', + :applier_service_name => 'watcher-applier', + } + when 'RedHat' + { :watcher_applier_package => 'openstack-watcher-applier', + :applier_service_name => 'openstack-watcher-applier', + } + end + end + it_behaves_like 'watcher-applier' + end + end +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_db_create_schema_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_db_create_schema_spec.rb new file mode 100644 index 0000000..c946e5c --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_db_create_schema_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe 'watcher::db::create_schema' do + + shared_examples_for 'watcher-db-manage-create_schema' do + + it 'runs watcher-db-manage' do + is_expected.to contain_exec('watcher-db-manage-create_schema').with( + :command => 'watcher-db-manage --config-file /etc/watcher/watcher.conf create_schema', + :path => '/usr/bin', + :user => 'watcher', + :refreshonly => 'true', + :subscribe => [ + 'Anchor[watcher::install::end]', + 'Anchor[watcher::config::end]', + 'Anchor[watcher::db::create_schema::begin]' + ], + :notify => 'Anchor[watcher::db::create_schema::end]', + ) + end + + describe 'overriding extra_params' do + let :params do + { + :extra_params => '--config-file /etc/watcher/watcher01.conf', + } + end + + it { + is_expected.to contain_exec('watcher-db-manage-create_schema').with( + :command => 'watcher-db-manage --config-file /etc/watcher/watcher01.conf create_schema', + :path => '/usr/bin', + :user => 'watcher', + :refreshonly => 'true', + :subscribe => [ + 'Anchor[watcher::install::end]', + 'Anchor[watcher::config::end]', + 'Anchor[watcher::db::create_schema::begin]' + ], + :notify => 'Anchor[watcher::db::create_schema::end]', + ) + } + end + + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + it_configures 'watcher-db-manage-create_schema' + end + end + +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_db_mysql_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_db_mysql_spec.rb new file mode 100644 index 0000000..545307d --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_db_mysql_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' + +describe 'watcher::db::mysql' do + + let :pre_condition do + 'include mysql::server' + end + + let :required_params do + { :password => 'fooboozoo_default_password', } + end + + shared_examples_for 'watcher-db-mysql' do + context 'with only required params' do + let :params do + required_params + end + + it { is_expected.to contain_openstacklib__db__mysql('watcher').with( + :user => 'watcher', + :password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206', + :dbname => 'watcher', + :host => '127.0.0.1', + :charset => 'utf8', + :collate => 'utf8_general_ci', + )} + end + + context 'overriding allowed_hosts param to array' do + let :params do + { :allowed_hosts => ['127.0.0.1','%'] }.merge(required_params) + end + + it { is_expected.to contain_openstacklib__db__mysql('watcher').with( + :user => 'watcher', + :password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206', + :dbname => 'watcher', + :host => '127.0.0.1', + :charset => 'utf8', + :collate => 'utf8_general_ci', + :allowed_hosts => ['127.0.0.1','%'] + )} + end + + describe 'overriding allowed_hosts param to string' do + let :params do + { :allowed_hosts => '192.168.1.1' }.merge(required_params) + end + + it { is_expected.to contain_openstacklib__db__mysql('watcher').with( + :user => 'watcher', + :password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206', + :dbname => 'watcher', + :host => '127.0.0.1', + :charset => 'utf8', + :collate => 'utf8_general_ci', + :allowed_hosts => '192.168.1.1' + )} + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_behaves_like 'watcher-db-mysql' + end + end +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_db_postgresql_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_db_postgresql_spec.rb new file mode 100644 index 0000000..de26cd3 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_db_postgresql_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe 'watcher::db::postgresql' do + + let :pre_condition do + 'include postgresql::server' + end + + let :required_params do + { :password => 'pw' } + end + + shared_examples_for 'watcher-db-postgresql' do + context 'with only required parameters' do + let :params do + required_params + end + + it { is_expected.to contain_postgresql__server__db('watcher').with( + :user => 'watcher', + :password => 'md5bb8678c96047fcce9b899ad5da021642' + )} + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts({ :concat_basedir => '/var/lib/puppet/concat' })) + end + + it_behaves_like 'watcher-db-postgresql' + end + end +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_db_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_db_spec.rb new file mode 100644 index 0000000..38a07c0 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_db_spec.rb @@ -0,0 +1,117 @@ +require 'spec_helper' + +describe 'watcher::db' do + + shared_examples 'watcher::db' do + context 'with default parameters' do + it { is_expected.to contain_watcher_config('database/connection').with_value('sqlite:////var/lib/watcher/watcher.sqlite') } + it { is_expected.to contain_watcher_config('database/idle_timeout').with_value('') } + it { is_expected.to contain_watcher_config('database/min_pool_size').with_value('') } + it { is_expected.to contain_watcher_config('database/db_max_retries').with_value('') } + it { is_expected.to contain_watcher_config('database/max_retries').with_value('') } + it { is_expected.to contain_watcher_config('database/retry_interval').with_value('') } + it { is_expected.to contain_watcher_config('database/max_pool_size').with_value('') } + it { is_expected.to contain_watcher_config('database/max_overflow').with_value('') } + end + + context 'with specific parameters' do + let :params do + { :database_connection => 'mysql+pymysql://watcher:watcher@localhost/watcher', + :database_idle_timeout => '3601', + :database_min_pool_size => '2', + :database_db_max_retries => '-1', + :database_max_retries => '11', + :database_retry_interval => '11', + :database_max_pool_size => '11', + :database_max_overflow => '21', + } + end + + it { is_expected.to contain_watcher_config('database/connection').with_value('mysql+pymysql://watcher:watcher@localhost/watcher') } + it { is_expected.to contain_watcher_config('database/idle_timeout').with_value('3601') } + it { is_expected.to contain_watcher_config('database/min_pool_size').with_value('2') } + it { is_expected.to contain_watcher_config('database/db_max_retries').with_value('-1') } + it { is_expected.to contain_watcher_config('database/max_retries').with_value('11') } + it { is_expected.to contain_watcher_config('database/retry_interval').with_value('11') } + it { is_expected.to contain_watcher_config('database/max_pool_size').with_value('11') } + it { is_expected.to contain_watcher_config('database/max_overflow').with_value('21') } + end + + context 'with postgresql backend' do + let :params do + { :database_connection => 'postgresql://watcher:watcher@localhost/watcher', } + end + + it 'install the proper backend package' do + is_expected.to contain_package('python-psycopg2').with(:ensure => 'present') + end + + end + + context 'with MySQL-python library as backend package' do + let :params do + { :database_connection => 'mysql://watcher:watcher@localhost/watcher', } + end + + it { is_expected.to contain_package('python-mysqldb').with(:ensure => 'present') } + end + + context 'with incorrect database_connection string' do + let :params do + { :database_connection => 'foodb://watcher:watcher@localhost/watcher', } + end + + it_raises 'a Puppet::Error', /validate_re/ + end + + context 'with incorrect pymysql database_connection string' do + let :params do + { :database_connection => 'foo+pymysql://watcher:watcher@localhost/watcher', } + end + + it_raises 'a Puppet::Error', /validate_re/ + end + + end + + shared_examples_for 'watcher::db on Debian' do + context 'using pymysql driver' do + let :params do + { :database_connection => 'mysql+pymysql://watcher:watcher@localhost/watcher', } + end + + it 'install the proper backend package' do + is_expected.to contain_package('db_backend_package').with( + :ensure => 'present', + :name => 'python-pymysql', + :tag => 'openstack' + ) + end + end + end + + shared_examples_for 'watcher::db on RedHat' do + context 'using pymysql driver' do + let :params do + { :database_connection => 'mysql+pymysql://watcher:watcher@localhost/watcher', } + end + + it 'install the proper backend package' do + is_expected.not_to contain_package('db_backend_package') + end + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_configures 'watcher::db' + it_configures "watcher::db on #{facts[:osfamily]}" + end + end +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_db_upgrade_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_db_upgrade_spec.rb new file mode 100644 index 0000000..dc8504c --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_db_upgrade_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe 'watcher::db::upgrade' do + + shared_examples_for 'watcher-db-manage-upgrade' do + + it 'runs watcher-db-manage' do + is_expected.to contain_exec('watcher-db-manage-upgrade').with( + :command => 'watcher-db-manage --config-file /etc/watcher/watcher.conf upgrade', + :path => '/usr/bin', + :user => 'watcher', + :refreshonly => 'true', + :subscribe => [ + 'Anchor[watcher::install::end]', + 'Anchor[watcher::config::end]', + 'Anchor[watcher::db::create_schema::end]', + 'Anchor[watcher::db::upgrade::begin]' + ], + :notify => 'Anchor[watcher::db::upgrade::end]', + ) + end + + describe 'overriding extra_params' do + let :params do + { + :extra_params => '--config-file /etc/watcher/watcher01.conf', + } + end + + it { + is_expected.to contain_exec('watcher-db-manage-upgrade').with( + :command => 'watcher-db-manage --config-file /etc/watcher/watcher01.conf upgrade', + :path => '/usr/bin', + :user => 'watcher', + :refreshonly => 'true', + :subscribe => [ + 'Anchor[watcher::install::end]', + 'Anchor[watcher::config::end]', + 'Anchor[watcher::db::create_schema::end]', + 'Anchor[watcher::db::upgrade::begin]' + ], + :notify => 'Anchor[watcher::db::upgrade::end]', + ) + } + end + + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + it_configures 'watcher-db-manage-upgrade' + end + end + +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_decision_engine_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_decision_engine_spec.rb new file mode 100644 index 0000000..8cca0bd --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_decision_engine_spec.rb @@ -0,0 +1,101 @@ +require 'spec_helper' + +describe 'watcher::decision_engine' do + + shared_examples 'watcher-decision-engine' do + + context 'with default parameters' do + + it 'installs packages' do + is_expected.to contain_package('watcher-decision-engine').with( + :name => platform_params[:watcher_decision_engine_package], + :ensure => 'present', + :tag => ['openstack', 'watcher-package'] + ) + end + + it 'configures watcher decision engine service' do + is_expected.to contain_watcher_config('watcher_decision_engine/conductor_topic').with_value('') + is_expected.to contain_watcher_config('watcher_decision_engine/status_topic').with_value('') + is_expected.to contain_watcher_config('watcher_decision_engine/notification_topics').with_value(['']) + is_expected.to contain_watcher_config('watcher_decision_engine/publisher_id').with_value('') + is_expected.to contain_watcher_config('watcher_decision_engine/max_workers').with_value('') + is_expected.to contain_watcher_config('watcher_planner/planner').with_value('') + is_expected.to contain_watcher_config('watcher_planners.default/weights').with_value('') + end + end + + [{:enabled => true}, {:enabled => false}].each do |param_hash| + context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do + let :params do + { :enabled => true, + :manage_service => true, + } + end + before do + params.merge!(param_hash) + end + + it 'configures watcher decision engine service' do + is_expected.to contain_service('watcher-decision-engine').with( + :ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped', + :name => platform_params[:decision_engine_service_name], + :enable => params[:enabled], + :hasstatus => true, + :hasrestart => true, + :tag => ['watcher-service'], + ) + end + end + end + + context 'with overridden parameters' do + let :params do + { + :package_ensure => '2012.1.1-15.el6', + :decision_engine_conductor_topic => 'test_conductor_topic', + :decision_engine_status_topic => 'niceTopic', + :decision_engine_notification_topics => ['topic_1','topic_2'], + :decision_engine_publisher_id => '123456', + :decision_engine_workers => '10', + :planner => 'NoPlanner', + :weights => {'foo' => 'fooValue', + 'foo2' => 'fooValue2'}, + } + end + it 'configures watcher decision engine' do + is_expected.to contain_watcher_config('watcher_decision_engine/conductor_topic').with_value('test_conductor_topic') + is_expected.to contain_watcher_config('watcher_decision_engine/status_topic').with_value('niceTopic') + is_expected.to contain_watcher_config('watcher_decision_engine/notification_topics').with_value(['topic_1','topic_2']) + is_expected.to contain_watcher_config('watcher_decision_engine/publisher_id').with_value('123456') + is_expected.to contain_watcher_config('watcher_decision_engine/max_workers').with_value('10') + is_expected.to contain_watcher_config('watcher_planner/planner').with_value('NoPlanner') + is_expected.to contain_watcher_config('watcher_planners.default/weights').with_value('foo2:fooValue2,foo:fooValue') + end + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + + facts.merge!(OSDefaults.get_facts()) + end + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :watcher_decision_engine_package => 'watcher-decision-engine', + :decision_engine_service_name => 'watcher-decision-engine', + } + when 'RedHat' + { :watcher_decision_engine_package => 'openstack-watcher-decision-engine', + :decision_engine_service_name => 'openstack-watcher-decision-engine', + } + end + end + it_behaves_like 'watcher-decision-engine' + end + end +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_init_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_init_spec.rb new file mode 100644 index 0000000..94b3fcd --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_init_spec.rb @@ -0,0 +1,299 @@ +require 'spec_helper' + +describe 'watcher' do + + shared_examples 'watcher' do + + context 'with default parameters' do + let :params do + { :purge_config => false } + end + + it 'contains the logging class' do + is_expected.to contain_class('watcher::logging') + end + + it 'contains the db class' do + is_expected.to contain_class('watcher::db') + end + + it 'installs packages' do + is_expected.to contain_package('watcher').with( + :name => platform_params[:watcher_common_package], + :ensure => 'present', + :tag => ['openstack', 'watcher-package'] + ) + end + + it { is_expected.to contain_class('watcher::policy') } + it { is_expected.to contain_class('watcher::deps') } + + it 'configures rabbit' do + is_expected.to contain_watcher_config('DEFAULT/rpc_backend').with_value('rabbit') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_login_method').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_retry_interval').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_retry_backoff').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_interval_max').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_max_retries').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_transient_queues_ttl').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/heartbeat_rate').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_compression').with_value('') + is_expected.to contain_watcher_config('DEFAULT/transport_url').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_response_timeout').with_value('') + is_expected.to contain_watcher_config('DEFAULT/control_exchange').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_notifications/transport_url').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_notifications/driver').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_notifications/topics').with_value('') + end + + it 'passes purge to resource' do + is_expected.to contain_resources('watcher_config').with({ + :purge => false + }) + end + + end + + context 'with overridden parameters' do + let :params do + { + :default_transport_url => 'rabbit://rabbit_user:password@localhost:5673', + :rabbit_ha_queues => 'undef', + :rabbit_heartbeat_timeout_threshold => '60', + :rabbit_heartbeat_rate => '10', + :kombu_compression => 'gzip', + :notification_transport_url => 'rabbit://rabbit_user:password@localhost:5673', + :notification_topics => 'notifications', + :ensure_package => '2012.1.1-15.el6', + } + end + it 'configures rabbit' do + is_expected.to contain_watcher_config('DEFAULT/rpc_backend').with_value('rabbit') + is_expected.to contain_watcher_config('DEFAULT/transport_url').with_value('rabbit://rabbit_user:password@localhost:5673') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('60') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/heartbeat_rate').with_value('10') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_login_method').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_retry_interval').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_retry_backoff').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_interval_max').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_max_retries').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_transient_queues_ttl').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_compression').with_value('gzip') + end + + it 'configures various things' do + is_expected.to contain_watcher_config('oslo_messaging_notifications/transport_url').with_value('rabbit://rabbit_user:password@localhost:5673') + is_expected.to contain_watcher_config('oslo_messaging_notifications/topics').with_value('notifications') + end + + end + + context 'with kombu_reconnect_delay set to 5.0' do + let :params do + { :kombu_reconnect_delay => '5.0' } + end + + it 'configures rabbit' do + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('5.0') + end + end + + context 'with rabbit_ha_queues set to true' do + let :params do + { :rabbit_ha_queues => 'true' } + end + + it 'configures rabbit' do + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) + end + end + + context 'with rabbit_ha_queues set to false' do + let :params do + { :rabbit_ha_queues => 'false' } + end + + it 'configures rabbit' do + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(false) + end + end + + context 'with amqp_durable_queues parameter' do + let :params do + { :amqp_durable_queues => 'true' } + end + + it 'configures rabbit' do + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/amqp_durable_queues').with_value(true) + end + end + + context 'with rabbit ssl enabled with kombu' do + let :params do + { :rabbit_use_ssl => true, + :kombu_ssl_ca_certs => '/etc/ca.cert', + :kombu_ssl_certfile => '/etc/certfile', + :kombu_ssl_keyfile => '/etc/key', + :kombu_ssl_version => 'TLSv1', } + end + + it 'configures rabbit' do + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/etc/ca.cert') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/etc/certfile') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/etc/key') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') + end + end + + context 'with rabbit ssl enabled without kombu' do + let :params do + { :rabbit_use_ssl => true, } + end + + it 'configures rabbit' do + is_expected.to contain_watcher_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('') + end + end + + context 'with amqp rpc_backend' do + let :params do + { :rpc_backend => 'amqp', + :default_transport_url => 'amqp://amqp_user:password@localhost:5672', } + end + + context 'with default parameters' do + it 'configures amqp' do + is_expected.to contain_watcher_config('DEFAULT/rpc_backend').with_value('amqp') + is_expected.to contain_watcher_config('DEFAULT/transport_url').with_value('amqp://amqp_user:password@localhost:5672') + is_expected.to contain_watcher_config('oslo_messaging_amqp/server_request_prefix').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/broadcast_prefix').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/group_request_prefix').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/container_name').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/idle_timeout').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/trace').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/ssl_ca_file').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/ssl_cert_file').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/ssl_key_file').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/ssl_key_password').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/allow_insecure_clients').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/sasl_mechanisms').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/sasl_config_dir').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/sasl_config_name').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/username').with_value('') + is_expected.to contain_watcher_config('oslo_messaging_amqp/password').with_value('') + end + end + end + + context 'with overriden amqp parameters' do + let :params do + { :rpc_backend => 'amqp', + :default_transport_url => 'amqp://amqp_user:password@localhost:5672', + :amqp_idle_timeout => '60', + :amqp_trace => true, + :amqp_ssl_ca_file => '/etc/ca.cert', + :amqp_ssl_cert_file => '/etc/certfile', + :amqp_ssl_key_file => '/etc/key', + :amqp_username => 'amqp_user', + :amqp_password => 'password', + } + end + + it 'configures amqp' do + is_expected.to contain_watcher_config('DEFAULT/rpc_backend').with_value('amqp') + is_expected.to contain_watcher_config('DEFAULT/transport_url').with_value('amqp://amqp_user:password@localhost:5672') + is_expected.to contain_watcher_config('oslo_messaging_amqp/idle_timeout').with_value('60') + is_expected.to contain_watcher_config('oslo_messaging_amqp/trace').with_value('true') + is_expected.to contain_watcher_config('oslo_messaging_amqp/ssl_ca_file').with_value('/etc/ca.cert') + is_expected.to contain_watcher_config('oslo_messaging_amqp/ssl_cert_file').with_value('/etc/certfile') + is_expected.to contain_watcher_config('oslo_messaging_amqp/ssl_key_file').with_value('/etc/key') + is_expected.to contain_watcher_config('oslo_messaging_amqp/username').with_value('amqp_user') + is_expected.to contain_watcher_config('oslo_messaging_amqp/password').with_value('password') + end + end + + context 'with zmq rpc_backend' do + let :params do + { :rpc_backend => 'zmq' } + end + + context 'with default parameters' do + it 'configures zmq' do + is_expected.to contain_watcher_config('DEFAULT/rpc_cast_timeout').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_poll_timeout').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_bind_address').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_bind_port_retries').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_concurrency').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_contexts').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_host').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_ipc_dir').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_matchmaker').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_max_port').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_min_port').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_topic_backlog').with_value('') + is_expected.to contain_watcher_config('DEFAULT/use_pub_sub').with_value('') + is_expected.to contain_watcher_config('DEFAULT/zmq_target_expire').with_value('') + end + end + end + + context 'with overriden zmq parameters' do + let :params do + { :rpc_backend => 'zmq', + :default_transport_url => 'zmq://zmq_user:password@localhost:5555', + :rpc_zmq_min_port => '49200', + :rpc_zmq_max_port => '65000', + :rpc_zmq_bind_port_retries => '120', + :rpc_zmq_contexts => '2', + :rpc_zmq_host => 'localhost', + } + end + + it 'configures zmq' do + is_expected.to contain_watcher_config('DEFAULT/transport_url').with_value('zmq://zmq_user:password@localhost:5555') + is_expected.to contain_watcher_config('DEFAULT/rpc_cast_timeout').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_poll_timeout').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_bind_address').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_bind_port_retries').with_value('120') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_concurrency').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_contexts').with_value('2') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_host').with_value('localhost') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_ipc_dir').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_matchmaker').with_value('') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_max_port').with_value('65000') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_min_port').with_value('49200') + is_expected.to contain_watcher_config('DEFAULT/rpc_zmq_topic_backlog').with_value('') + is_expected.to contain_watcher_config('DEFAULT/use_pub_sub').with_value('') + is_expected.to contain_watcher_config('DEFAULT/zmq_target_expire').with_value('') + end + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { :watcher_common_package => 'watcher-common' } + when 'RedHat' + { :watcher_common_package => 'openstack-watcher-common' } + end + end + it_behaves_like 'watcher' + end + end + +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_keystone_auth_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_keystone_auth_spec.rb new file mode 100644 index 0000000..42c60fe --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_keystone_auth_spec.rb @@ -0,0 +1,128 @@ +# +# Unit tests for watcher::keystone::auth +# + +require 'spec_helper' + +describe 'watcher::keystone::auth' do + shared_examples_for 'watcher-keystone-auth' do + context 'with default class parameters' do + let :params do + { :password => 'watcher_password', + :tenant => 'foobar' } + end + + it { is_expected.to contain_keystone_user('watcher').with( + :ensure => 'present', + :password => 'watcher_password', + ) } + + it { is_expected.to contain_keystone_user_role('watcher@foobar').with( + :ensure => 'present', + :roles => ['admin'] + )} + + it { is_expected.to contain_keystone_service('watcher::infra-optim').with( + :ensure => 'present', + :description => 'Infrastructure Optimization service' + ) } + + it { is_expected.to contain_keystone_endpoint('RegionOne/watcher::infra-optim').with( + :ensure => 'present', + :public_url => 'http://127.0.0.1:9322', + :admin_url => 'http://127.0.0.1:9322', + :internal_url => 'http://127.0.0.1:9322', + ) } + end + + context 'when overriding URL parameters' do + let :params do + { :password => 'watcher_password', + :public_url => 'https://10.10.10.10:80', + :internal_url => 'http://10.10.10.11:81', + :admin_url => 'http://10.10.10.12:81', } + end + + it { is_expected.to contain_keystone_endpoint('RegionOne/watcher::infra-optim').with( + :ensure => 'present', + :public_url => 'https://10.10.10.10:80', + :internal_url => 'http://10.10.10.11:81', + :admin_url => 'http://10.10.10.12:81', + ) } + end + + context 'when overriding auth name' do + let :params do + { :password => 'foo', + :auth_name => 'watchery' } + end + + it { is_expected.to contain_keystone_user('watchery') } + it { is_expected.to contain_keystone_user_role('watchery@services') } + it { is_expected.to contain_keystone_service('watchery::infra-optim') } + it { is_expected.to contain_keystone_endpoint('RegionOne/watchery::infra-optim') } + end + + context 'when overriding service name' do + let :params do + { :service_name => 'watcher_service', + :auth_name => 'watcher', + :password => 'watcher_password' } + end + + it { is_expected.to contain_keystone_user('watcher') } + it { is_expected.to contain_keystone_user_role('watcher@services') } + it { is_expected.to contain_keystone_service('watcher_service::infra-optim') } + it { is_expected.to contain_keystone_endpoint('RegionOne/watcher_service::infra-optim') } + end + + context 'when disabling user configuration' do + + let :params do + { + :password => 'watcher_password', + :configure_user => false + } + end + + it { is_expected.not_to contain_keystone_user('watcher') } + it { is_expected.to contain_keystone_user_role('watcher@services') } + it { is_expected.to contain_keystone_service('watcher::infra-optim').with( + :ensure => 'present', + :description => 'Infrastructure Optimization service' + ) } + + end + + context 'when disabling user and user role configuration' do + + let :params do + { + :password => 'watcher_password', + :configure_user => false, + :configure_user_role => false + } + end + + it { is_expected.not_to contain_keystone_user('watcher') } + it { is_expected.not_to contain_keystone_user_role('watcher@services') } + it { is_expected.to contain_keystone_service('watcher::infra-optim').with( + :ensure => 'present', + :description => 'Infrastructure Optimization service' + ) } + + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_behaves_like 'watcher-keystone-auth' + end + end +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_keystone_authtoken_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_keystone_authtoken_spec.rb new file mode 100644 index 0000000..62e0f44 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_keystone_authtoken_spec.rb @@ -0,0 +1,151 @@ +require 'spec_helper' + +describe 'watcher::keystone::authtoken' do + + let :params do + { :password => 'watcher_password', } + end + + shared_examples_for 'watcher authtoken' do + + context 'without required password parameter' do + before { params.delete(:password) } + it { expect { is_expected.to raise_error(Puppet::Error) } } + end + + context 'with default parameters' do + it 'configure keystone_authtoken' do + is_expected.to contain_watcher_config('keystone_authtoken/username').with_value('watcher') + is_expected.to contain_watcher_config('keystone_authtoken/password').with_value('watcher_password') + is_expected.to contain_watcher_config('keystone_authtoken/auth_url').with_value('http://localhost:35357') + is_expected.to contain_watcher_config('keystone_authtoken/project_name').with_value('services') + is_expected.to contain_watcher_config('keystone_authtoken/user_domain_name').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/project_domain_name').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/insecure').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/auth_section').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/auth_type').with_value('password') + is_expected.to contain_watcher_config('keystone_authtoken/auth_uri').with_value('http://localhost:5000') + is_expected.to contain_watcher_config('keystone_authtoken/auth_version').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/cache').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/cafile').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/certfile').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/check_revocations_for_cached').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/delay_auth_decision').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/enforce_token_bind').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/hash_algorithms').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/http_connect_timeout').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/http_request_max_retries').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/include_service_catalog').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/keyfile').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/memcache_pool_conn_get_timeout').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/memcache_pool_dead_retry').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/memcache_pool_maxsize').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/memcache_pool_socket_timeout').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/memcache_pool_unused_timeout').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/memcache_secret_key').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/memcache_security_strategy').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/memcache_use_advanced_pool').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/memcached_servers').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/region_name').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/revocation_cache_time').with_value('') + is_expected.to contain_watcher_config('keystone_authtoken/token_cache_time').with_value('') + end + end + + context 'when overriding parameters' do + before do + params.merge!({ + :auth_uri => 'https://10.0.0.1:9999/', + :username => 'myuser', + :password => 'mypasswd', + :auth_url => 'http://:127.0.0.1:35357', + :project_name => 'service_project', + :user_domain_name => 'domainX', + :project_domain_name => 'domainX', + :insecure => false, + :auth_section => 'new_section', + :auth_type => 'password', + :auth_version => 'v3', + :cache => 'somevalue', + :cafile => '/opt/stack/data/cafile.pem', + :certfile => 'certfile.crt', + :check_revocations_for_cached => false, + :delay_auth_decision => false, + :enforce_token_bind => 'permissive', + :hash_algorithms => 'md5', + :http_connect_timeout => '300', + :http_request_max_retries => '3', + :include_service_catalog => true, + :keyfile => 'keyfile', + :memcache_pool_conn_get_timeout => '9', + :memcache_pool_dead_retry => '302', + :memcache_pool_maxsize => '11', + :memcache_pool_socket_timeout => '2', + :memcache_pool_unused_timeout => '61', + :memcache_secret_key => 'secret_key', + :memcache_security_strategy => 'ENCRYPT', + :memcache_use_advanced_pool => true, + :memcached_servers => ['memcached01:11211','memcached02:11211'], + :manage_memcache_package => true, + :region_name => 'region2', + :revocation_cache_time => '11', + :token_cache_time => '301', + }) + end + + it 'configure keystone_authtoken' do + is_expected.to contain_watcher_config('keystone_authtoken/auth_uri').with_value('https://10.0.0.1:9999/') + is_expected.to contain_watcher_config('keystone_authtoken/username').with_value(params[:username]) + is_expected.to contain_watcher_config('keystone_authtoken/password').with_value(params[:password]).with_secret(true) + is_expected.to contain_watcher_config('keystone_authtoken/auth_url').with_value(params[:auth_url]) + is_expected.to contain_watcher_config('keystone_authtoken/project_name').with_value(params[:project_name]) + is_expected.to contain_watcher_config('keystone_authtoken/user_domain_name').with_value(params[:user_domain_name]) + is_expected.to contain_watcher_config('keystone_authtoken/project_domain_name').with_value(params[:project_domain_name]) + is_expected.to contain_watcher_config('keystone_authtoken/insecure').with_value(params[:insecure]) + is_expected.to contain_watcher_config('keystone_authtoken/auth_section').with_value(params[:auth_section]) + is_expected.to contain_watcher_config('keystone_authtoken/auth_type').with_value(params[:auth_type]) + is_expected.to contain_watcher_config('keystone_authtoken/auth_version').with_value(params[:auth_version]) + is_expected.to contain_watcher_config('keystone_authtoken/cache').with_value(params[:cache]) + is_expected.to contain_watcher_config('keystone_authtoken/cafile').with_value(params[:cafile]) + is_expected.to contain_watcher_config('keystone_authtoken/certfile').with_value(params[:certfile]) + is_expected.to contain_watcher_config('keystone_authtoken/check_revocations_for_cached').with_value(params[:check_revocations_for_cached]) + is_expected.to contain_watcher_config('keystone_authtoken/delay_auth_decision').with_value(params[:delay_auth_decision]) + is_expected.to contain_watcher_config('keystone_authtoken/enforce_token_bind').with_value(params[:enforce_token_bind]) + is_expected.to contain_watcher_config('keystone_authtoken/hash_algorithms').with_value(params[:hash_algorithms]) + is_expected.to contain_watcher_config('keystone_authtoken/http_connect_timeout').with_value(params[:http_connect_timeout]) + is_expected.to contain_watcher_config('keystone_authtoken/http_request_max_retries').with_value(params[:http_request_max_retries]) + is_expected.to contain_watcher_config('keystone_authtoken/include_service_catalog').with_value(params[:include_service_catalog]) + is_expected.to contain_watcher_config('keystone_authtoken/keyfile').with_value(params[:keyfile]) + is_expected.to contain_watcher_config('keystone_authtoken/memcache_pool_conn_get_timeout').with_value(params[:memcache_pool_conn_get_timeout]) + is_expected.to contain_watcher_config('keystone_authtoken/memcache_pool_dead_retry').with_value(params[:memcache_pool_dead_retry]) + is_expected.to contain_watcher_config('keystone_authtoken/memcache_pool_maxsize').with_value(params[:memcache_pool_maxsize]) + is_expected.to contain_watcher_config('keystone_authtoken/memcache_pool_socket_timeout').with_value(params[:memcache_pool_socket_timeout]) + is_expected.to contain_watcher_config('keystone_authtoken/memcache_pool_unused_timeout').with_value(params[:memcache_pool_unused_timeout]) + is_expected.to contain_watcher_config('keystone_authtoken/memcache_secret_key').with_value(params[:memcache_secret_key]) + is_expected.to contain_watcher_config('keystone_authtoken/memcache_security_strategy').with_value(params[:memcache_security_strategy]) + is_expected.to contain_watcher_config('keystone_authtoken/memcache_use_advanced_pool').with_value(params[:memcache_use_advanced_pool]) + is_expected.to contain_watcher_config('keystone_authtoken/memcached_servers').with_value('memcached01:11211,memcached02:11211') + is_expected.to contain_watcher_config('keystone_authtoken/region_name').with_value(params[:region_name]) + is_expected.to contain_watcher_config('keystone_authtoken/revocation_cache_time').with_value(params[:revocation_cache_time]) + is_expected.to contain_watcher_config('keystone_authtoken/token_cache_time').with_value(params[:token_cache_time]) + end + + it 'installs python memcache package' do + is_expected.to contain_package('python-memcache') + end + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_configures 'watcher authtoken' + end + end + +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_logging_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_logging_spec.rb new file mode 100644 index 0000000..12ca93f --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_logging_spec.rb @@ -0,0 +1,139 @@ +require 'spec_helper' + +describe 'watcher::logging' do + + let :params do + { + } + end + + let :log_params do + { + :logging_context_format_string => '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [%(request_id)s %(user_identity)s] %(instance)s%(message)s', + :logging_default_format_string => '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [-] %(instance)s%(message)s', + :logging_debug_format_suffix => '%(funcName)s %(pathname)s:%(lineno)d', + :logging_exception_prefix => '%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s', + :log_config_append => '/etc/watcher/logging.conf', + :publish_errors => true, + :default_log_levels => { + 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN', + 'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO', + 'iso8601' => 'WARN', + 'requests.packages.urllib3.connectionpool' => 'WARN' }, + :fatal_deprecations => true, + :instance_format => '[instance: %(uuid)s] ', + :instance_uuid_format => '[instance: %(uuid)s] ', + :log_date_format => '%Y-%m-%d %H:%M:%S', + :use_syslog => true, + :use_stderr => false, + :syslog_log_facility => 'LOG_FOO', + :log_dir => '/var/log', + :log_file => '/var/log/watcher.log', + :debug => true, + } + end + + shared_examples_for 'watcher-logging' do + + context 'with basic logging options and default settings' do + it_configures 'basic default logging settings' + end + + context 'with basic logging options and non-default settings' do + before { params.merge!( log_params ) } + it_configures 'basic non-default logging settings' + end + + context 'with extended logging options' do + before { params.merge!( log_params ) } + it_configures 'logging params set' + end + + context 'without extended logging options' do + it_configures 'logging params unset' + end + + end + + shared_examples 'basic default logging settings' do + it 'configures watcher logging settins with default values' do + is_expected.to contain_watcher_config('DEFAULT/use_syslog').with(:value => '') + is_expected.to contain_watcher_config('DEFAULT/use_stderr').with(:value => '') + is_expected.to contain_watcher_config('DEFAULT/syslog_log_facility').with(:value => '') + is_expected.to contain_watcher_config('DEFAULT/log_dir').with(:value => '/var/log/watcher') + is_expected.to contain_watcher_config('DEFAULT/log_file').with(:value => '/var/log/watcher/watcher.log') + is_expected.to contain_watcher_config('DEFAULT/debug').with(:value => '') + end + end + + shared_examples 'basic non-default logging settings' do + it 'configures watcher logging settins with non-default values' do + is_expected.to contain_watcher_config('DEFAULT/use_syslog').with(:value => 'true') + is_expected.to contain_watcher_config('DEFAULT/use_stderr').with(:value => 'false') + is_expected.to contain_watcher_config('DEFAULT/syslog_log_facility').with(:value => 'LOG_FOO') + is_expected.to contain_watcher_config('DEFAULT/log_dir').with(:value => '/var/log') + is_expected.to contain_watcher_config('DEFAULT/log_file').with(:value => '/var/log/watcher.log') + is_expected.to contain_watcher_config('DEFAULT/debug').with(:value => 'true') + end + end + + shared_examples_for 'logging params set' do + it 'enables logging params' do + is_expected.to contain_watcher_config('DEFAULT/logging_context_format_string').with_value( + '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [%(request_id)s %(user_identity)s] %(instance)s%(message)s') + + is_expected.to contain_watcher_config('DEFAULT/logging_default_format_string').with_value( + '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [-] %(instance)s%(message)s') + + is_expected.to contain_watcher_config('DEFAULT/logging_debug_format_suffix').with_value( + '%(funcName)s %(pathname)s:%(lineno)d') + + is_expected.to contain_watcher_config('DEFAULT/logging_exception_prefix').with_value( + '%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s') + + is_expected.to contain_watcher_config('DEFAULT/log_config_append').with_value( + '/etc/watcher/logging.conf') + is_expected.to contain_watcher_config('DEFAULT/publish_errors').with_value( + true) + + is_expected.to contain_watcher_config('DEFAULT/default_log_levels').with_value( + 'amqp=WARN,amqplib=WARN,boto=WARN,iso8601=WARN,qpid=WARN,requests.packages.urllib3.connectionpool=WARN,sqlalchemy=WARN,suds=INFO') + + is_expected.to contain_watcher_config('DEFAULT/fatal_deprecations').with_value( + true) + + is_expected.to contain_watcher_config('DEFAULT/instance_format').with_value( + '[instance: %(uuid)s] ') + + is_expected.to contain_watcher_config('DEFAULT/instance_uuid_format').with_value( + '[instance: %(uuid)s] ') + + is_expected.to contain_watcher_config('DEFAULT/log_date_format').with_value( + '%Y-%m-%d %H:%M:%S') + end + end + + + shared_examples_for 'logging params unset' do + [ :logging_context_format_string, :logging_default_format_string, + :logging_debug_format_suffix, :logging_exception_prefix, + :log_config_append, :publish_errors, + :default_log_levels, :fatal_deprecations, + :instance_format, :instance_uuid_format, + :log_date_format, ].each { |param| + it { is_expected.to contain_watcher_config("DEFAULT/#{param}").with_value('') } + } + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_behaves_like 'watcher-logging' + end + end +end diff --git a/deployment_scripts/modules/watcher/spec/classes/watcher_policy_spec.rb b/deployment_scripts/modules/watcher/spec/classes/watcher_policy_spec.rb new file mode 100644 index 0000000..267cc2b --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/classes/watcher_policy_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe 'watcher::policy' do + shared_examples_for 'watcher-policies' do + let :params do + { + :policy_path => '/etc/watcher/policy.json', + :policies => { + 'context_is_admin' => { + 'key' => 'context_is_admin', + 'value' => 'foo:bar' + } + } + } + end + + it 'set up the policies' do + is_expected.to contain_openstacklib__policy__base('context_is_admin').with({ + :key => 'context_is_admin', + :value => 'foo:bar' + }) + is_expected.to contain_watcher_config('oslo_policy/policy_file').with_value('/etc/watcher/policy.json') + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_behaves_like 'watcher-policies' + end + end +end diff --git a/deployment_scripts/modules/watcher/spec/shared_examples.rb b/deployment_scripts/modules/watcher/spec/shared_examples.rb new file mode 100644 index 0000000..fec0eac --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/shared_examples.rb @@ -0,0 +1,5 @@ +shared_examples_for "a Puppet::Error" do |description| + it "with message matching #{description.inspect}" do + expect { is_expected.to have_class_count(1) }.to raise_error(Puppet::Error, description) + end +end diff --git a/deployment_scripts/modules/watcher/spec/spec_helper.rb b/deployment_scripts/modules/watcher/spec/spec_helper.rb new file mode 100644 index 0000000..cad00b1 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/spec_helper.rb @@ -0,0 +1,10 @@ +require 'puppetlabs_spec_helper/module_spec_helper' +require 'shared_examples' +require 'puppet-openstack_spec_helper/facts' + +RSpec.configure do |c| + c.alias_it_should_behave_like_to :it_configures, 'configures' + c.alias_it_should_behave_like_to :it_raises, 'raises' +end + +at_exit { RSpec::Puppet::Coverage.report! } diff --git a/deployment_scripts/modules/watcher/spec/spec_helper_acceptance.rb b/deployment_scripts/modules/watcher/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..9196bc9 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/spec_helper_acceptance.rb @@ -0,0 +1 @@ +require 'puppet-openstack_spec_helper/beaker_spec_helper' diff --git a/deployment_scripts/modules/watcher/spec/unit/provider/watcher_config/ini_setting_spec.rb b/deployment_scripts/modules/watcher/spec/unit/provider/watcher_config/ini_setting_spec.rb new file mode 100644 index 0000000..3b9947a --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/unit/provider/watcher_config/ini_setting_spec.rb @@ -0,0 +1,68 @@ +# +# these tests are a little concerning b/c they are hacking around the +# modulepath, so these tests will not catch issues that may eventually arise +# related to loading these plugins. +# I could not, for the life of me, figure out how to programatcally set the modulepath +$LOAD_PATH.push( + File.join( + File.dirname(__FILE__), + '..', + '..', + '..', + 'fixtures', + 'modules', + 'inifile', + 'lib') +) +$LOAD_PATH.push( + File.join( + File.dirname(__FILE__), + '..', + '..', + '..', + 'fixtures', + 'modules', + 'openstacklib', + 'lib') +) +require 'spec_helper' +provider_class = Puppet::Type.type(:watcher_config).provider(:ini_setting) +describe provider_class do + + it 'should default to the default setting when no other one is specified' do + resource = Puppet::Type::Watcher_config.new( + {:name => 'DEFAULT/foo', :value => 'bar'} + ) + provider = provider_class.new(resource) + expect(provider.section).to eq('DEFAULT') + expect(provider.setting).to eq('foo') + end + + it 'should allow setting to be set explicitly' do + resource = Puppet::Type::Watcher_config.new( + {:name => 'dude/foo', :value => 'bar'} + ) + provider = provider_class.new(resource) + expect(provider.section).to eq('dude') + expect(provider.setting).to eq('foo') + end + + it 'should ensure absent when is specified as a value' do + resource = Puppet::Type::Watcher_config.new( + {:name => 'dude/foo', :value => ''} + ) + provider = provider_class.new(resource) + provider.exists? + expect(resource[:ensure]).to eq :absent + end + + it 'should ensure absent when value matches ensure_absent_val' do + resource = Puppet::Type::Watcher_config.new( + {:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' } + ) + provider = provider_class.new(resource) + provider.exists? + expect(resource[:ensure]).to eq :absent + end + +end diff --git a/deployment_scripts/modules/watcher/spec/unit/type/watcher_config_spec.rb b/deployment_scripts/modules/watcher/spec/unit/type/watcher_config_spec.rb new file mode 100644 index 0000000..703a8f1 --- /dev/null +++ b/deployment_scripts/modules/watcher/spec/unit/type/watcher_config_spec.rb @@ -0,0 +1,64 @@ +require 'puppet' +require 'puppet/type/watcher_config' +describe 'Puppet::Type.type(:watcher_config)' do + before :each do + @watcher_config = Puppet::Type.type(:watcher_config).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should require a name' do + expect { + Puppet::Type.type(:watcher_config).new({}) + }.to raise_error(Puppet::Error, 'Title or name must be provided') + end + + it 'should not expect a name with whitespace' do + expect { + Puppet::Type.type(:watcher_config).new(:name => 'f oo') + }.to raise_error(Puppet::Error, /Parameter name failed/) + end + + it 'should fail when there is no section' do + expect { + Puppet::Type.type(:watcher_config).new(:name => 'foo') + }.to raise_error(Puppet::Error, /Parameter name failed/) + end + + it 'should not require a value when ensure is absent' do + Puppet::Type.type(:watcher_config).new(:name => 'DEFAULT/foo', :ensure => :absent) + end + + it 'should accept a valid value' do + @watcher_config[:value] = 'bar' + expect(@watcher_config[:value]).to eq('bar') + end + + it 'should not accept a value with whitespace' do + @watcher_config[:value] = 'b ar' + expect(@watcher_config[:value]).to eq('b ar') + end + + it 'should accept valid ensure values' do + @watcher_config[:ensure] = :present + expect(@watcher_config[:ensure]).to eq(:present) + @watcher_config[:ensure] = :absent + expect(@watcher_config[:ensure]).to eq(:absent) + end + + it 'should not accept invalid ensure values' do + expect { + @watcher_config[:ensure] = :latest + }.to raise_error(Puppet::Error, /Invalid value/) + end + + it 'should autorequire the package that install the file' do + catalog = Puppet::Resource::Catalog.new + package = Puppet::Type.type(:package).new(:name => 'watcher') + catalog.add_resource package, @watcher_config + dependency = @watcher_config.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@watcher_config) + expect(dependency[0].source).to eq(package) + end + + +end diff --git a/deployment_scripts/modules/watcher/test-requirements.txt b/deployment_scripts/modules/watcher/test-requirements.txt new file mode 100644 index 0000000..baa2346 --- /dev/null +++ b/deployment_scripts/modules/watcher/test-requirements.txt @@ -0,0 +1,5 @@ +# this is required for the docs build jobs +sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 +oslosphinx>=2.5.0 # Apache-2.0 +# FIXME: reno is manually pinned to !=2.0.0 because of bug #1651995 +reno>=0.1.1,!=2.0.0 # Apache-2.0 diff --git a/deployment_scripts/modules/watcher/tests/init.pp b/deployment_scripts/modules/watcher/tests/init.pp new file mode 100644 index 0000000..96d76eb --- /dev/null +++ b/deployment_scripts/modules/watcher/tests/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# http://docs.puppetlabs.com/guides/tests_smoke.html +# +include ::watcher diff --git a/deployment_scripts/modules/watcher/tox.ini b/deployment_scripts/modules/watcher/tox.ini new file mode 100644 index 0000000..aea06c8 --- /dev/null +++ b/deployment_scripts/modules/watcher/tox.ini @@ -0,0 +1,8 @@ +[tox] +minversion = 1.6 +skipsdist = True +envlist = releasenotes + +[testenv:releasenotes] +deps = -rtest-requirements.txt +commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html diff --git a/deployment_tasks.yaml b/deployment_tasks.yaml new file mode 100644 index 0000000..20bf6a9 --- /dev/null +++ b/deployment_tasks.yaml @@ -0,0 +1,129 @@ +- id: primary-watcher-node + type: group + role: [primary-watcher-node] + tasks: &common_tasks + - hiera + - setup_repositories + - fuel_pkgs + - globals + - tools + - logging + - hiera_default_route + - netconfig + - hosts + required_for: [deploy_end] + requires: [primary-controller] + parameters: + strategy: + type: one_by_one + +- id: watcher-node + type: group + role: [watcher-node] + tasks: *common_tasks + required_for: [deploy_end] + requires: [primary-watcher-node] + parameters: + strategy: + type: parallel + +- id: hiera-watcher-override + version: 2.1.0 + type: puppet + groups: ['primary-controller', 'controller', 'primary-watcher-node', 'watcher-node'] + required_for: [logging] + requires: [globals] + parameters: + puppet_manifest: manifests/watcher_hiera_override.pp + puppet_modules: /etc/puppet/modules + timeout: 120 + # reexecute_on is needed for scale-down operations + reexecute_on: + - deploy_changes + +- id: pin-watcher-plugin-repo + version: 2.1.0 + type: puppet + groups: ['primary-watcher-node', 'watcher-node' ] + required_for: [hiera-watcher-override] + requires: [globals] + parameters: + puppet_manifest: manifests/watcher_pin_plugin_repo.pp + puppet_modules: /etc/puppet/modules + timeout: 120 + +- id: watcher-keystone-endpoints + version: 2.1.0 + type: puppet + groups: ['primary-controller'] + required_for: [watcher-controller-end] + requires: [primary-keystone, keystone] + parameters: + puppet_manifest: manifests/watcher_keystone.pp + puppet_modules: modules:/etc/puppet/modules + timeout: 1800 + +- id: watcher-database + version: 2.1.0 + type: puppet + groups: ['primary-controller'] + cross-depends: + - name: /(primary-)?database/ + required_for: [watcher-controller-end] + requires: [primary-database, database] + parameters: + puppet_manifest: manifests/watcher_db.pp + puppet_modules: modules:/etc/puppet/modules + timeout: 1800 + +- id: watcher-controller-end + version: 2.1.0 + type: skipped + groups: ['primary-controller','controller'] + required_for: [deploy_end] + requires: [] + +- id: watcher-haproxy + version: 2.1.0 + type: puppet + groups: ['primary-controller', 'controller'] + required_for: [watcher-controller-end] + requires: [deploy_start, primary-cluster-haproxy, cluster-haproxy] + parameters: + puppet_manifest: manifests/watcher_haproxy.pp + puppet_modules: /etc/puppet/modules + timeout: 300 + +- id: watcher-logging + version: 2.1.0 + type: puppet + groups: ['primary-controller', 'controller', 'primary-watcher-node', 'watcher-node'] + required_for: [watcher-services] + requires: [logging] + parameters: + puppet_manifest: manifests/watcher_logging.pp + puppet_modules: /etc/puppet/modules + timeout: 1800 + +- id: watcher-services + version: 2.1.0 + type: puppet + groups: ['primary-watcher-node', 'watcher-node'] + required_for: [deploy_end] + requires: [hosts] + cross-depends: + - name: watcher-controller-end + parameters: + puppet_manifest: manifests/watcher.pp + puppet_modules: modules:/etc/puppet/modules + timeout: 3600 + +- id: watcher-timezone + version: 2.1.0 + type: puppet + groups: ['primary-watcher-node', 'watcher-node'] + required_for: [watcher-services] + parameters: + puppet_manifest: manifests/watcher_timezone.pp + puppet_modules: /etc/puppet/modules + timeout: 300 diff --git a/environment_config.yaml b/environment_config.yaml new file mode 100644 index 0000000..71e8741 --- /dev/null +++ b/environment_config.yaml @@ -0,0 +1,10 @@ +attributes: + metadata: + group: other + label: "Detach Watcher Plugin" + user_password: + type: "hidden" + weight: 5 + label: "watcher password" + value: + generator: "password" \ No newline at end of file diff --git a/functions.sh b/functions.sh new file mode 100644 index 0000000..9d0c891 --- /dev/null +++ b/functions.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# Copyright 2016 Mirantis, Inc. +# +# 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. + +set -eux + +ROOT="$(dirname "$(readlink -f "$0")")" +MODULES_DIR="${ROOT}"/deployment_scripts/modules +RPM_REPO="${ROOT}"/repositories/centos/ +DEB_REPO="${ROOT}"/repositories/ubuntu/ + +# Download RPM or DEB packages and store them in the local repository directory +function download_package { + local package_type=$1 + local url=$2 + local wget_lvl=${3:-4} + if [[ "$package_type" == 'deb' ]]; then + REPO=$DEB_REPO + elif [[ "$package_type" == 'rpm' ]]; then + REPO=$RPM_REPO + else + echo "Invalid package type: $1" + fi + + wget -P "$REPO" -A "$package_type" -nd -r -l ${wget_lvl} "$url" +} + +# Download official Puppet module and store it in the local directory +function download_puppet_module { + local m_dir=$1 + local git_repo=$2 + local git_branch=$3 + + rm -rvf "${MODULES_DIR:?}"/"$m_dir" + git clone "${git_repo}" --single-branch -b "${git_branch}" "${MODULES_DIR}/${m_dir}" +} + +# Generate version file in format: +# Build: $build_date +# FUEL_PLUGIN_COMMIT=$sha +# $pkg_name=$pkg_version +function generate_deb_version_file { + local version_file="${1:-build_version}" + local tmp_file=$(mktemp) + echo "# Build: $(date +%Y-%m-%d-%H-%M-%S)" >> "${version_file}" + echo "FUEL_PLUGIN_REF=$(git rev-parse --abbrev-ref HEAD)" >> "${version_file}" + echo "FUEL_PLUGIN_COMMIT=$(git rev-parse HEAD)" >> "${version_file}" + while read -d '' -r pkg; do + dpkg-deb -I "${pkg}"| awk '/Package:/{name=$2}/Version:/{ver=$2;print name"="ver}' >> "${tmp_file}" + done < <(find "repositories/ubuntu" -name '*.deb' -print0) + cat "${tmp_file}" | sort >> "${version_file}" + rm -vf "${tmp_file}" +} diff --git a/metadata.yaml b/metadata.yaml new file mode 100644 index 0000000..09bc3f0 --- /dev/null +++ b/metadata.yaml @@ -0,0 +1,20 @@ +name: fuel-plugin-watcher +title: Watcher standalone +version: '0.0.5' +description: Install Watcher +fuel_version: ['9.0'] +licenses: ['Apache License, Version 2.0'] +authors: + - Ilya Popov +homepage: https://github.com/sbrf-clouddev/fuel-plugin-watcher +groups: [network] +is_hotpluggable: true + +releases: + - os: ubuntu + version: mitaka-9.0 + mode: ['ha'] + deployment_scripts_path: deployment_scripts/ + repository_path: repositories/ubuntu + +package_version: '4.0.0' diff --git a/network_roles.yaml b/network_roles.yaml new file mode 100644 index 0000000..a5c987a --- /dev/null +++ b/network_roles.yaml @@ -0,0 +1,12 @@ +- id: 'watcher_public_vip' + default_mapping: 'public' + properties: + subnet: true + gateway: false + vip: + - name: 'watcher_public_vip' + namespace: 'haproxy' + alias: 'watcher_vip' + node_roles: + - 'watcher' + - 'primary-watcher' \ No newline at end of file diff --git a/node_roles.yaml b/node_roles.yaml new file mode 100644 index 0000000..a2d51a0 --- /dev/null +++ b/node_roles.yaml @@ -0,0 +1,6 @@ +watcher-node: + name: "Watcher node" + description: "" + has_primary: true + public_ip_required: false + weight: 100 diff --git a/repositories/centos/.gitkeep b/repositories/centos/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/repositories/ubuntu/.gitkeep b/repositories/ubuntu/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/volumes.yaml b/volumes.yaml new file mode 100644 index 0000000..9801120 --- /dev/null +++ b/volumes.yaml @@ -0,0 +1,4 @@ +volumes: [] +volumes_roles_mapping: + watcher-node: + - {allocate_size: "min", id: "os"} \ No newline at end of file