Merge "Add support for symlinked agent virtualenv"

This commit is contained in:
Jenkins 2016-01-15 17:06:39 +00:00 committed by Gerrit Code Review
commit 4bf61277bd
8 changed files with 219 additions and 79 deletions

View File

@ -0,0 +1 @@
monasca-agent

View File

@ -96,14 +96,20 @@
# port of the syslog server
#
# [*virtual_env*]
# directory of python virtual environment
# path of python virtual environment symlink
#
# [*virtual_env_dir*]
# directory for python virtual environments
#
# [*virtual_env_reqs*]
# requirements file for the agent venv
#
# [*virtual_envs*]
# a hash of virtual envs to build
#
# [*agent_user*]
# name of the monasca agent user
#
# [*agent_ensure*]
# install ensure option (present, latest..)
#
# [*install_python_deps*]
# flag for whether or not to install python dependencies
#
@ -145,8 +151,10 @@ class monasca::agent(
$syslog_host = undef ,
$syslog_port = undef,
$virtual_env = '/var/lib/monasca-agent',
$virtual_env_dir = '/var/lib/monasca-agent-venvs',
$virtual_env_reqs = 'puppet:///modules/monasca/agent_requirements.txt',
$virtual_envs = {'default'=> {'venv_active'=> true}},
$agent_user = 'monasca-agent',
$agent_ensure = 'latest',
$install_python_deps = true,
$python_dep_ensure = 'present',
$pip_install_args = '',
@ -158,29 +166,27 @@ class monasca::agent(
$additional_checksd = "${agent_dir}/checks.d"
$conf_dir = "${agent_dir}/conf.d"
if $::monasca::params::agent_package {
if $install_python_deps {
package { ['python-virtualenv', 'python-dev']:
ensure => $python_dep_ensure,
before => Python::Virtualenv[$virtual_env],
}
}
python::virtualenv { $virtual_env :
owner => 'root',
group => 'root',
require => [Package['python-virtualenv'],Package['python-dev']],
before => Python::Pip['monasca-agent'],
}
python::pip { 'monasca-agent' :
ensure => $agent_ensure,
pkgname => $::monasca::params::agent_package,
virtualenv => $virtual_env,
owner => 'root',
install_args => $pip_install_args,
if $install_python_deps {
package { ['python-virtualenv', 'python-dev']:
ensure => $python_dep_ensure,
}
}
file { $virtual_env_dir:
ensure => 'directory',
owner => 'root',
group => 'root',
mode => '0755',
}
$defaults = {
symlink => $virtual_env,
basedir => $virtual_env_dir,
venv_extra_args => $pip_install_args,
venv_requirements => $virtual_env_reqs,
}
create_resources('::monasca::virtualenv::agent_instance', $virtual_envs,
$defaults)
user { $agent_user:
ensure => present,
groups => $::monasca::group,
@ -244,16 +250,6 @@ class monasca::agent(
group => 'root',
mode => '0755',
content => template('monasca/monasca-agent.init.erb'),
require => Python::Pip['monasca-agent'],
before => Service['monasca-agent'],
}
file { "${virtual_env}/share/monasca/agent/supervisor.conf":
owner => 'root',
group => 'root',
mode => '0644',
content => template('monasca/supervisor.conf.erb'),
require => Python::Pip['monasca-agent'],
before => Service['monasca-agent'],
}

View File

@ -1,6 +1,7 @@
# == Class: monasca::checks::libvirt
#
# Sets up the monasca libvirt check.
# Requires lxml, libvirt-python and python-novaclient
#
# === Parameters
#
@ -41,7 +42,6 @@ class monasca::checks::libvirt(
$nova_refresh = '14400'
){
$conf_dir = $::monasca::agent::conf_dir
$virtual_env = $::monasca::agent::virtual_env
File["${conf_dir}/libvirt.yaml"] ~> Service['monasca-agent']
@ -60,29 +60,4 @@ class monasca::checks::libvirt(
# libvirt-dev and pkg-config are needed libvirt-python
ensure_packages('libvirt-dev')
ensure_packages('pkg-config')
python::pip { 'lxml' :
virtualenv => $virtual_env,
owner => 'root',
require => [Package['libxslt1-dev'],Package['libxml2-dev'],Package['zlib1g-dev'],
Python::Virtualenv[$virtual_env]],
before => Service['monasca-agent'],
install_args => $::monasca::agent::pip_install_args,
}
python::pip { 'libvirt-python' :
virtualenv => $virtual_env,
owner => 'root',
require => [Package['libvirt-dev'],Package['pkg-config'],
Python::Virtualenv[$virtual_env]],
before => Service['monasca-agent'],
install_args => $::monasca::agent::pip_install_args,
}
python::pip { 'python-novaclient' :
virtualenv => $virtual_env,
owner => 'root',
require => Python::Virtualenv[$virtual_env],
before => Service['monasca-agent'],
install_args => $::monasca::agent::pip_install_args,
}
}

View File

@ -1,6 +1,7 @@
# == Class: monasca::checks::mysql
#
# Sets up the monasca mysql check.
# Requires MySQL-python
#
# === Parameters
#
@ -28,7 +29,6 @@ class monasca::checks::mysql(
$instances = undef,
){
$conf_dir = $::monasca::agent::conf_dir
$virtual_env = $::monasca::agent::virtual_env
if($instances){
Concat["${conf_dir}/mysql.yaml"] ~> Service['monasca-agent']
@ -46,12 +46,4 @@ class monasca::checks::mysql(
}
create_resources('monasca::checks::instances::mysql', $instances)
}
python::pip { 'MySQL-python' :
virtualenv => $virtual_env,
owner => 'root',
require => Python::Virtualenv[$virtual_env],
before => Service['monasca-agent'],
install_args => $::monasca::agent::pip_install_args,
}
}

View File

@ -188,19 +188,19 @@ class monasca::keystone::auth (
ensure => present,
password => $admin_password,
email => $admin_email,
before => Python::Pip['monasca-agent'],
before => Service['monasca-agent'],
}
keystone_user { $agent_name:
ensure => present,
password => $agent_password,
email => $agent_email,
before => Python::Pip['monasca-agent'],
before => Service['monasca-agent'],
}
keystone_user { $user_name:
ensure => present,
password => $user_password,
email => $user_email,
before => Python::Pip['monasca-agent'],
before => Service['monasca-agent'],
}
}
@ -249,18 +249,18 @@ class monasca::keystone::auth (
ensure => present,
roles => [$role_agent, $role_delegate],
require => $real_user_roles_agent,
before => Python::Pip['monasca-agent'],
before => Service['monasca-agent'],
}
keystone_user_role { "${admin_name}@${tenant}":
ensure => present,
roles => $real_user_roles_admin,
before => Python::Pip['monasca-agent'],
before => Service['monasca-agent'],
}
keystone_user_role { "${user_name}@${tenant}":
ensure => present,
roles => [$role_user],
require => $real_user_roles_user,
before => Python::Pip['monasca-agent'],
before => Service['monasca-agent'],
}
}

View File

@ -0,0 +1,70 @@
# == Define: virtualenv::agent_instance
#
# Sets up a virtualenv instance and handles agent specific setup in the venv.
# See the instance class for details on using virtualenv instances
#
# === Parameters
#
# [*ensure*] (required) Whether or not the package should be removed or
# installed. Should be 'present', or 'absent'. For package installs, other
# values such as a version number or 'latest' are also acceptable.
#
# [*venv_active*] (optional) Whether or not the virtualenv should be made
# active by managing symlinks into it and restarting services if the links are
# changed. Only one virtualenv can be active at a time. Defaults to false.
#
# [*basedir*] (required) Base directory for storing virtualenvs.
#
# [*symlink*] (required if venv_active is true) The path to link to the venv_dir
#
# [*venv_prefix*] Prefix to give to virtualenv directories
# This can be specified to provide more meaningful names, or to have multiple
# virtualenvs installed at the same time. Defaults to $name
#
# [*venv_requirements*] (required) Python requirements.txt to pass to pip when
# populating the virtualenv. Required if the instance is ensured to be present.
#
# [*venv_extra_args*] (optional) Extra arguments that will be passed to `pip
# install` when creating the virtualenv.
define monasca::virtualenv::agent_instance(
$basedir,
$venv_prefix = $name,
$ensure = 'present',
$symlink = undef,
$venv_requirements = undef,
$venv_active = false,
$venv_extra_args = undef,
) {
validate_string($ensure)
$valid_values = [
'^present$',
'^absent$',
]
validate_re($ensure, $valid_values,
"Unknown value '${ensure}' for ensure, must be present or absent")
$req_dest = "${basedir}/${venv_prefix}-requirements.txt"
$venv_path = "${basedir}/${venv_prefix}-venv"
monasca::virtualenv::instance { $name:
ensure => $ensure,
basedir => $basedir,
venv_prefix => $venv_prefix,
symlink => $symlink,
venv_requirements => $venv_requirements,
venv_active => $venv_active,
venv_extra_args => $venv_extra_args,
require => [File[$basedir],Package['python-virtualenv'],
Package['python-dev']],
}
->
file { "${venv_path}/share/monasca/agent/supervisor.conf":
ensure => $ensure,
owner => 'root',
group => 'root',
mode => '0644',
content => template('monasca/supervisor.conf.erb'),
notify => Service['monasca-agent'],
}
}

View File

@ -0,0 +1,106 @@
# == Define: virtualenv::instance
#
# This class will manage the installation of the monasca agent into a Python
# virtualenv. It will also manage the config files needed by that software,
# with different policies for packages and virtualenvs. By default the config
# files will be copied from the template files internal to the module. This
# behavior can be overridden by providing a $config_files hash.
#
# Virtualenv installations are built by installing packages from a given
# requirements.txt file. For production use you will normally want to override
# the requirements.txt and provide one that contains pinned module versions,
# and possibly include information about a local pypi mirror in the
# requirements.txt.
#
# This module explicitly supports provisioning multiple virtualenv based
# installations in order to make upgrades and rollbacks easier. To take
# advantage of this, you can define additional instances of
# monasca::virtualenv::instance type with the active flag set to false
# and with different $venv_prefix options. The monasca::agent class will allow
# configuring multiple virtualenvs via hiera.
#
# If using virtualenv based installations it's *strongly* recommended that
# virtualenvs be treated as immutable once created. Behavior with changing
# requirements.txt or code may not be what you expect, since the existing
# virtualenv will be updated, not rebuilt when requirements.txt or the git
# revision changes.
#
# === Parameters
#
# [*ensure*] (required) Whether or not the package should be removed or
# installed. Should be 'present', or 'absent'. For package installs, other
# values such as a version number or 'latest' are also acceptable.
#
# [*venv_active*] (optional) Whether or not the virtualenv should be made
# active by managing symlinks into it and restarting services if the links are
# changed. Only one virtualenv can be active at a time. Defaults to false.
#
# [*basedir*] (required) Base directory for storing virtualenvs.
#
# [*symlink*] (required if venv_active is true) The path to link to the venv_dir
#
# [*venv_prefix*] Prefix to give to virtualenv directories
# This can be specified to provide more meaningful names, or to have multiple
# virtualenvs installed at the same time. Defaults to $name
#
# [*venv_requirements*] (required) Python requirements.txt to pass to pip when
# populating the virtualenv. Required if the instance is ensured to be present.
#
# [*venv_extra_args*] (optional) Extra arguments that will be passed to `pip
# install` when creating the virtualenv.
define monasca::virtualenv::instance(
$basedir,
$venv_prefix = $name,
$ensure = 'present',
$symlink = undef,
$venv_requirements = undef,
$venv_active = false,
$venv_extra_args = undef,
) {
validate_string($ensure)
$valid_values = [
'^present$',
'^absent$',
]
validate_re($ensure, $valid_values,
"Unknown value '${ensure}' for ensure, must be present or absent")
$req_dest = "${basedir}/${venv_prefix}-requirements.txt"
$venv_dir = "${basedir}/${venv_prefix}-venv"
$venv_name = "${venv_prefix}-${name}"
if $ensure == 'present' {
validate_string($venv_requirements)
file { $req_dest:
ensure => 'file',
owner => 'root',
group => 'root',
mode => '0644',
source => $venv_requirements,
before => Python::Virtualenv[$venv_name],
}
} else {
file { $req_dest:
ensure => 'absent',
}
}
python::virtualenv { $venv_name:
ensure => $ensure,
venv_dir => $venv_dir,
requirements => $req_dest,
extra_pip_args => $venv_extra_args,
owner => 'root',
group => 'root',
}
if $venv_active {
file { $symlink:
ensure => 'link',
force => true,
target => $venv_dir,
}
}
}

View File

@ -18,7 +18,7 @@ pidfile = /var/run/monasca-agent-supervisord.pid
logfile_backups = 10
[program:collector]
command=<%= @virtual_env %>/bin/monasca-collector foreground
command=<%= @venv_path %>/bin/monasca-collector foreground
stdout_logfile=NONE
stderr_logfile=NONE
priority=999
@ -26,7 +26,7 @@ startsecs=2
user=monasca-agent
[program:forwarder]
command=<%= @virtual_env %>/bin/monasca-forwarder
command=<%= @venv_path %>/bin/monasca-forwarder
stdout_logfile=NONE
stderr_logfile=NONE
startsecs=3
@ -34,7 +34,7 @@ priority=998
user=monasca-agent
[program:monstatsd]
command=<%= @virtual_env %>/bin/monasca-statsd
command=<%= @venv_path %>/bin/monasca-statsd
stdout_logfile=NONE
stderr_logfile=NONE
startsecs=3