From c0a04fd46c26fb8cc76628514ef911827309dd1b Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Mon, 17 Mar 2014 22:22:02 +0200 Subject: [PATCH] Optional install Nailgun OSTF from PRM packages Change-Id: Ib73410ff8d3f06e7195e0b9d41862390588a212a --- deployment/puppet/nailgun/examples/site.pp | 23 +++- .../puppet/nailgun/files/supervisor-sysconfig | 4 +- .../puppet/nailgun/lib/facter/fuel_version.rb | 11 ++ deployment/puppet/nailgun/manifests/init.pp | 20 +++- deployment/puppet/nailgun/manifests/ostf.pp | 113 ++++++++++-------- .../puppet/nailgun/manifests/supervisor.pp | 3 +- deployment/puppet/nailgun/manifests/venv.pp | 103 +++++++++------- .../nailgun/templates/supervisord.conf.erb | 8 +- 8 files changed, 178 insertions(+), 107 deletions(-) create mode 100644 deployment/puppet/nailgun/lib/facter/fuel_version.rb diff --git a/deployment/puppet/nailgun/examples/site.pp b/deployment/puppet/nailgun/examples/site.pp index ad0dfbefd5..8d5b1b0706 100644 --- a/deployment/puppet/nailgun/examples/site.pp +++ b/deployment/puppet/nailgun/examples/site.pp @@ -1,4 +1,20 @@ $fuel_settings = parseyaml($astute_settings_yaml) +$fuel_version = parseyaml($fuel_version_yaml) + +if is_hash($::fuel_version) and $::fuel_version['VERSION'] and $::fuel_version['VERSION']['production'] { + $production = $::fuel_version['VERSION']['production'] +} +else { + $production = 'prod' +} + +if $production == 'prod'{ + $env_path = "/usr" + $staticdir = "/usr/share/nailgun/static" +} else { + $env_path = "/opt/nailgun" + $staticdir = "/opt/nailgun/share/nailgun/static" +} # this replaces removed postgresql version fact $postgres_default_version = '8.4' @@ -51,10 +67,11 @@ node default { class { "nailgun": package => "Nailgun", version => "0.1.0", + production => $production, astute_version => "0.0.2", nailgun_group => "nailgun", nailgun_user => "nailgun", - venv => "/opt/nailgun", + venv => $env_path, pip_index => "--no-index", pip_find_links => "-f file://${pip_repo}", @@ -69,8 +86,8 @@ node default { database_user => "nailgun", database_passwd => "nailgun", - staticdir => "/opt/nailgun/share/nailgun/static", - templatedir => "/opt/nailgun/share/nailgun/static", + staticdir => $staticdir, + templatedir => $staticdir, cobbler_url => "http://localhost/cobbler_api", cobbler_user => $cobbler_user, diff --git a/deployment/puppet/nailgun/files/supervisor-sysconfig b/deployment/puppet/nailgun/files/supervisor-sysconfig index 2845ada745..c183ad372e 100644 --- a/deployment/puppet/nailgun/files/supervisor-sysconfig +++ b/deployment/puppet/nailgun/files/supervisor-sysconfig @@ -1,9 +1,9 @@ # this is sourced by the supervisord init script # written by jkoppe -set -a +set -a -# should probably put both of these options as runtime arguments +# should probably put both of these options as runtime arguments OPTIONS="-c /etc/supervisord.conf" PIDFILE=/var/run/supervisord.pid diff --git a/deployment/puppet/nailgun/lib/facter/fuel_version.rb b/deployment/puppet/nailgun/lib/facter/fuel_version.rb new file mode 100644 index 0000000000..d31f67688c --- /dev/null +++ b/deployment/puppet/nailgun/lib/facter/fuel_version.rb @@ -0,0 +1,11 @@ +require 'facter' + +fuel_version_path = '/etc/nailgun/version.yaml' + +Facter.add('fuel_version_yaml') do + if File.exist?(fuel_version_path) + setcode { File.read(fuel_version_path) } + else + setcode { "none" } + end +end diff --git a/deployment/puppet/nailgun/manifests/init.pp b/deployment/puppet/nailgun/manifests/init.pp index 71ce1523f1..f322a29423 100644 --- a/deployment/puppet/nailgun/manifests/init.pp +++ b/deployment/puppet/nailgun/manifests/init.pp @@ -1,9 +1,10 @@ class nailgun( $package, $version, + $production, + $venv, $nailgun_group = "nailgun", $nailgun_user = "nailgun", - $venv = "/opt/nailgun", $repo_root = "/var/www/nailgun", $pip_index = "", @@ -17,8 +18,8 @@ class nailgun( $database_user = "nailgun", $database_passwd = "nailgun", - $staticdir = "/opt/nailgun/share/nailgun/static", - $templatedir = "/opt/nailgun/share/nailgun/static", + $staticdir, + $templatedir, $logdumpdir = "/var/www/nailgun/dump", $cobbler_url = "http://localhost/cobbler_api", @@ -110,6 +111,7 @@ class nailgun( package => $package, version => $version, pip_opts => "${pip_index} ${pip_find_links}", + production => $production, nailgun_user => $nailgun_user, nailgun_group => $nailgun_group, @@ -142,8 +144,17 @@ class nailgun( gem_source => $gem_source, } + if $production == 'prod' { + $nailgun_env = $venv + $ostf_env = $venv + } else { + $nailgun_env = '/opt/nailgun' + $ostf_env = '/opt/fuel_plugins/ostf' + } + class { "nailgun::supervisor": - venv => $venv, + nailgun_env => $nailgun_env, + ostf_env => $ostf_env, } class { "nailgun::nginx-repo": @@ -202,6 +213,7 @@ class nailgun( class { "nailgun::logrotate": } class { "nailgun::ostf": + production => $production, pip_opts => "${pip_index} ${pip_find_links}", } diff --git a/deployment/puppet/nailgun/manifests/ostf.pp b/deployment/puppet/nailgun/manifests/ostf.pp index d87d22fcf7..ba997abf70 100644 --- a/deployment/puppet/nailgun/manifests/ostf.pp +++ b/deployment/puppet/nailgun/manifests/ostf.pp @@ -1,5 +1,6 @@ class nailgun::ostf( $pip_opts, + $production, $venv = '/opt/fuel_plugins/ostf', $dbuser = 'ostf', $dbpass = 'ostf', @@ -19,53 +20,69 @@ class nailgun::ostf( grant => 'all', require => Class['::postgresql::server'], } - nailgun::venv::venv{'ostf-venv': - venv => $venv, - ensure => 'present', - opts => "--system-site-packages", - pip_opts => $pip_opts, - } - Nailgun::Venv::Pip { - venv => $venv, - opts => "$pip_opts", - require => [ - Nailgun::Venv::Venv['ostf-venv'], - Package['libevent-devel'], - Package['openssl-devel'], - Package['postgresql-devel'], - ], - } - file { "$venv/pip-requires.txt": - source => 'puppet:///modules/nailgun/venv-ostf.txt', - owner => 'root', - group => 'root', - mode => 0755, - }-> - nailgun::venv::pip { "${venv}_setuptools-git": - package => 'setuptools-git==1.0', - }-> - nailgun::venv::pip { "${venv}_d2to1": - package => 'd2to1==0.2.10', - }-> - nailgun::venv::pip { "${venv}_pbr": - package => 'pbr==0.5.21', - }-> - nailgun::venv::pip { "${venv}_ostf-req": - package => "-r $venv/pip-requires.txt", - }-> - nailgun::venv::pip { "${venv}_ostf": - package => 'fuel-ostf', - } - exec {'ostf-init': - command => "$venv/bin/ostf-server \ - --host=${host} --port=${port} --log_file=${logfile} \ - --dbpath '${dbengine}://${dbuser}:${dbpass}@${dbhost}:${dbport}/${dbname}' \ - --after-initialization-environment-hook || /bin/true", - require => [ - Postgresql::Db[$dbname], - Nailgun::Venv::Pip["${venv}_ostf-req"], - Nailgun::Venv::Pip["${venv}_ostf"], - ], - before => Class['nailgun::supervisor'], + if $production == 'prod' { + package{'fuel-ostf':} + + exec {'ostf-init': + command => "/usr/bin/ostf-server \ + --host=${host} --port=${port} --log_file=${logfile} \ + --dbpath '${dbengine}://${dbuser}:${dbpass}@${dbhost}:${dbport}/${dbname}' \ + --after-initialization-environment-hook || /bin/true", + require => [ + Package["fuel-ostf"], + Postgresql::Db[$dbname], + ], + before => Class['nailgun::supervisor'], + } + } else { + nailgun::venv::venv{'ostf-venv': + venv => $venv, + ensure => 'present', + opts => "--system-site-packages", + pip_opts => $pip_opts, + } + Nailgun::Venv::Pip { + venv => $venv, + opts => "$pip_opts", + require => [ + Nailgun::Venv::Venv['ostf-venv'], + Package['libevent-devel'], + Package['openssl-devel'], + Package['postgresql-devel'], + ], + } + file { "$venv/pip-requires.txt": + source => 'puppet:///modules/nailgun/venv-ostf.txt', + owner => 'root', + group => 'root', + mode => 0755, + }-> + nailgun::venv::pip { "${venv}_setuptools-git": + package => 'setuptools-git==1.0', + }-> + nailgun::venv::pip { "${venv}_d2to1": + package => 'd2to1==0.2.10', + }-> + nailgun::venv::pip { "${venv}_pbr": + package => 'pbr==0.5.21', + }-> + nailgun::venv::pip { "${venv}_ostf-req": + package => "-r $venv/pip-requires.txt", + }-> + nailgun::venv::pip { "${venv}_ostf": + package => 'fuel-ostf', + } + exec {'ostf-init': + command => "$venv/bin/ostf-server \ + --host=${host} --port=${port} --log_file=${logfile} \ + --dbpath '${dbengine}://${dbuser}:${dbpass}@${dbhost}:${dbport}/${dbname}' \ + --after-initialization-environment-hook || /bin/true", + require => [ + Postgresql::Db[$dbname], + Nailgun::Venv::Pip["${venv}_ostf-req"], + Nailgun::Venv::Pip["${venv}_ostf"], + ], + before => Class['nailgun::supervisor'], + } } } \ No newline at end of file diff --git a/deployment/puppet/nailgun/manifests/supervisor.pp b/deployment/puppet/nailgun/manifests/supervisor.pp index 74e244a049..4883b46306 100644 --- a/deployment/puppet/nailgun/manifests/supervisor.pp +++ b/deployment/puppet/nailgun/manifests/supervisor.pp @@ -1,5 +1,6 @@ class nailgun::supervisor( - $venv, + $nailgun_env, + $ostf_env, ) { file { "/etc/sysconfig/supervisord": diff --git a/deployment/puppet/nailgun/manifests/venv.pp b/deployment/puppet/nailgun/manifests/venv.pp index 171f3f6c12..649036672a 100644 --- a/deployment/puppet/nailgun/manifests/venv.pp +++ b/deployment/puppet/nailgun/manifests/venv.pp @@ -5,6 +5,7 @@ class nailgun::venv( $version, $pip_opts = "", + $production, $nailgun_user, $nailgun_group, @@ -34,47 +35,50 @@ class nailgun::venv( ) { - nailgun::venv::venv { $venv: - ensure => "present", - venv => $venv, - opts => $venv_opts, - require => Package["python-virtualenv"], - pip_opts => $pip_opts, - } + if $production == 'prod' { + package{'nailgun':} + } else { + nailgun::venv::venv { $venv: + ensure => "present", + venv => $venv, + opts => $venv_opts, + require => Package["python-virtualenv"], + pip_opts => $pip_opts, + } - Nailgun::Venv::Pip { - require => [ - Nailgun::Venv::Venv[$venv], - Package["python-devel"], - Package["gcc"], - Package["make"], - ], - opts => $pip_opts, - venv => $venv, - } + Nailgun::Venv::Pip { + require => [ + Nailgun::Venv::Venv[$venv], + Package["python-devel"], + Package["gcc"], + Package["make"], + ], + opts => $pip_opts, + venv => $venv, + } - nailgun::venv::pip { "${venv}_${package}": - package => "$package==$version", - } + nailgun::venv::pip { "${venv}_${package}": + package => "$package==$version", + } - nailgun::venv::pip { "${venv}_pbr": - package => "pbr==0.5.21", - require => [ - Nailgun::Venv::Venv[$venv], - ], - } + nailgun::venv::pip { "${venv}_pbr": + package => "pbr==0.5.21", + require => [ + Nailgun::Venv::Venv[$venv], + ], + } - nailgun::venv::pip { "${venv}_psycopg2": - package => "psycopg2==2.4.6", - require => [ - Package["postgresql-devel"], - Nailgun::Venv::Venv[$venv], - Package["python-devel"], - Package["gcc"], - Package["make"], - ], + nailgun::venv::pip { "${venv}_psycopg2": + package => "psycopg2==2.4.6", + require => [ + Package["postgresql-devel"], + Nailgun::Venv::Venv[$venv], + Package["python-devel"], + Package["gcc"], + Package["make"], + ], + } } - file { "/etc/nailgun": ensure => directory, owner => 'root', @@ -96,17 +100,26 @@ class nailgun::venv( file { "/usr/local/bin/fuel": ensure => link, target => "/opt/nailgun/bin/fuel", - require => Nailgun::Venv::Pip["${venv}_${package}"], } - exec {"nailgun_syncdb": - command => "${venv}/bin/nailgun_syncdb", - require => [ - File["/etc/nailgun/settings.yaml"], - Nailgun::Venv::Pip["${venv}_${package}"], - Nailgun::Venv::Pip["${venv}_psycopg2"], - Class["nailgun::database"], - ], + if $production == 'prod' { + exec {"nailgun_syncdb": + command => "${venv}/bin/nailgun_syncdb", + require => [ + File["/etc/nailgun/settings.yaml"], + Class["nailgun::database"], + ], + } + } else { + exec {"nailgun_syncdb": + command => "${venv}/bin/nailgun_syncdb", + require => [ + File["/etc/nailgun/settings.yaml"], + Nailgun::Venv::Pip["${venv}_${package}"], + Nailgun::Venv::Pip["${venv}_psycopg2"], + Class["nailgun::database"], + ], + } } exec {"nailgun_upload_fixtures": diff --git a/deployment/puppet/nailgun/templates/supervisord.conf.erb b/deployment/puppet/nailgun/templates/supervisord.conf.erb index ba7b28cf76..5c40f0fca1 100644 --- a/deployment/puppet/nailgun/templates/supervisord.conf.erb +++ b/deployment/puppet/nailgun/templates/supervisord.conf.erb @@ -15,7 +15,7 @@ childlogdir=/var/log/supervisor serverurl=unix:///var/run/supervisor.sock [program:nailgun] -command=<%= @venv %>/bin/nailgund +command=<%= @nailgun_env %>/bin/nailgund process_name=%(program_name)s numprocs=1 numprocs_start=0 @@ -33,7 +33,7 @@ stdout_events_enabled=false serverurl=AUTO [program:assassind] -command=<%= @venv %>/bin/assassind +command=<%= @nailgun_env %>/bin/assassind process_name=%(program_name)s numprocs=1 numprocs_start=0 @@ -51,7 +51,7 @@ stdout_events_enabled=false serverurl=AUTO [program:receiverd] -command=<%= @venv %>/bin/receiverd +command=<%= @nailgun_env %>/bin/receiverd process_name=%(program_name)s numprocs=1 numprocs_start=0 @@ -94,7 +94,7 @@ stderr_events_enabled=false serverurl=AUTO [program:ostf] -command=/opt/fuel_plugins/ostf/bin/ostf-server --host=127.0.0.1 --port=8777 --log_file=/var/log/ostf.log --dbpath postgresql+psycopg2://ostf:ostf@127.0.0.1:5432/ostf +command=<%= @ostf_env %>/bin/ostf-server --host=127.0.0.1 --port=8777 --log_file=/var/log/ostf.log --dbpath postgresql+psycopg2://ostf:ostf@127.0.0.1:5432/ostf process_name=%(program_name)s numprocs=1 numprocs_start=0