From 56794f300acaf0c2dd46a0bac3830f7c90120670 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Mon, 26 Feb 2018 15:03:39 +0100 Subject: [PATCH] Move gnocchi api in wsgi back to python2 Canonical are packaging gnocchi-api package with apache and python3 by default. We cannot test it in CI since we cannot run py2 and py3 on the same node with apache wsgi. Canonical helped us by packaging python2 support back into python-gnocchi package so we change our wsgi usage to use this package and set the new wsgi script path. We still want users to be able to install only gnocchi-api since they might not run apache wsgi even though its installed by default. Adds installation of rados and redis packages for python3 when needed, this is because all gnocchi components will still be running in py3, also CLI such as gnocchi-upgrade but the gnocchi-api is in wsgi using py2. Because of that we still need to install the py2 packages. Enables acceptance testing for Debian based operating systems. Change-Id: I070f88dd40ca4129cbd3abf5b4f5ecb511b2895e --- manifests/api.pp | 1 + manifests/params.pp | 11 +++- manifests/storage.pp | 9 +++ manifests/storage/ceph.pp | 10 ++++ manifests/wsgi/apache.pp | 1 + spec/acceptance/basic_gnocchi_spec.rb | 71 +++++++++-------------- spec/classes/gnocchi_api_spec.rb | 34 ++++++++++- spec/classes/gnocchi_storage_ceph_spec.rb | 19 ++++++ spec/classes/gnocchi_storage_spec.rb | 24 +++++++- spec/classes/gnocchi_wsgi_apache_spec.rb | 7 ++- 10 files changed, 140 insertions(+), 47 deletions(-) diff --git a/manifests/api.pp b/manifests/api.pp index 865862ce..d168b7bc 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -120,6 +120,7 @@ class gnocchi::api ( } } elsif $service_name == 'httpd' { include ::apache::params + service { 'gnocchi-api': ensure => 'stopped', name => $::gnocchi::params::api_service_name, diff --git a/manifests/params.pp b/manifests/params.pp index c9634169..ca3bfe98 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -8,7 +8,6 @@ class gnocchi::params { $client_package_name = 'python-gnocchiclient' $rados_package_name = 'python-rados' $common_package_name = 'gnocchi-common' - $api_package_name = 'gnocchi-api' $api_service_name = 'gnocchi-api' $metricd_package_name = 'gnocchi-metricd' $metricd_service_name = 'gnocchi-metricd' @@ -18,6 +17,7 @@ class gnocchi::params { case $::osfamily { 'RedHat': { + $api_package_name = 'gnocchi-api' $sqlite_package_name = undef $indexer_package_name = 'openstack-gnocchi-indexer-sqlalchemy' $gnocchi_wsgi_script_path = '/var/www/cgi-bin/gnocchi' @@ -27,9 +27,16 @@ class gnocchi::params { $redis_package_name = 'python-redis' } 'Debian': { + if $::operatingsystem == 'Ubuntu' { + $api_package_name = 'python-gnocchi' + $gnocchi_wsgi_script_source = '/usr/bin/python2-gnocchi-api' + } else { + $api_package_name = 'gnocchi-api' + $gnocchi_wsgi_script_source = '/usr/share/gnocchi-common/app.wsgi' + } + $sqlite_package_name = 'python-pysqlite2' $gnocchi_wsgi_script_path = '/usr/lib/cgi-bin/gnocchi' - $gnocchi_wsgi_script_source = '/usr/share/gnocchi-common/app.wsgi' $pymysql_package_name = 'python-pymysql' $redis_package_name = 'python-redis' $cradox_package_name = undef diff --git a/manifests/storage.pp b/manifests/storage.pp index 09ff4061..00528587 100644 --- a/manifests/storage.pp +++ b/manifests/storage.pp @@ -49,6 +49,15 @@ class gnocchi::storage( name => $::gnocchi::params::redis_package_name, tag => 'openstack', }) + + # NOTE(tobias.urdin): Gnocchi components are packaged with py3 in Ubuntu + # from Queens. + if $::operatingsystem == 'Ubuntu' { + ensure_resource('package', 'python3-redis', { + name => 'python3-redis', + tag => 'openstack', + }) + } } } } diff --git a/manifests/storage/ceph.pp b/manifests/storage/ceph.pp index bae178dc..2c800f12 100644 --- a/manifests/storage/ceph.pp +++ b/manifests/storage/ceph.pp @@ -105,6 +105,16 @@ class gnocchi::storage::ceph( 'name' => $::gnocchi::params::rados_package_name, 'tag' => ['openstack','gnocchi-package'], }) + + # NOTE(tobias.urdin): Gnocchi components are packaged with py3 in Ubuntu + # from Queens. + if $::operatingsystem == 'Ubuntu' { + ensure_packages('python3-rados', { + 'ensure' => 'present', + 'name' => 'python3-rados', + 'tag' => ['openstack','gnocchi-package'], + }) + } } } } diff --git a/manifests/wsgi/apache.pp b/manifests/wsgi/apache.pp index 895dac23..3d058354 100644 --- a/manifests/wsgi/apache.pp +++ b/manifests/wsgi/apache.pp @@ -159,5 +159,6 @@ class gnocchi::wsgi::apache ( access_log_format => $access_log_format, error_log_file => $error_log_file, custom_wsgi_process_options => $custom_wsgi_process_options, + require => Anchor['gnocchi::install::end'], } } diff --git a/spec/acceptance/basic_gnocchi_spec.rb b/spec/acceptance/basic_gnocchi_spec.rb index 906d4dd5..e4e7bddb 100644 --- a/spec/acceptance/basic_gnocchi_spec.rb +++ b/spec/acceptance/basic_gnocchi_spec.rb @@ -5,7 +5,7 @@ describe 'basic gnocchi' do context 'default parameters' do it 'should work with no errors' do - pp= <<-EOS + pp = <<-EOS include ::openstack_integration include ::openstack_integration::repos include ::openstack_integration::mysql @@ -17,55 +17,42 @@ describe 'basic gnocchi' do class { '::gnocchi::keystone::auth': password => 'a_big_secret', } - case $::osfamily { - 'Debian': { - warning('Gnocchi is not yet packaged on Ubuntu systems.') - } - 'RedHat': { - class { '::gnocchi': - debug => true, - database_connection => 'mysql+pymysql://gnocchi:a_big_secret@127.0.0.1/gnocchi?charset=utf8', - } - class { '::gnocchi::keystone::authtoken': - password => 'a_big_secret', - } - class { '::gnocchi::api': - enabled => true, - service_name => 'httpd', - sync_db => true, - } - class { '::gnocchi::metricd': } - class { '::gnocchi::storage': } - class { '::gnocchi::storage::file': } - include ::apache - class { '::gnocchi::wsgi::apache': - ssl => false, - } - class { '::gnocchi::statsd': - archive_policy_name => 'high', - flush_delay => '100', - resource_id => '07f26121-5777-48ba-8a0b-d70468133dd9', - user_id => 'f81e9b1f-9505-4298-bc33-43dfbd9a973b', - project_id => '203ef419-e73f-4b8a-a73f-3d599a72b18d', - } - class { '::gnocchi::client': } - } - default: { - fail("Unsupported osfamily (${::osfamily})") - } + class { '::gnocchi': + debug => true, + database_connection => 'mysql+pymysql://gnocchi:a_big_secret@127.0.0.1/gnocchi?charset=utf8', } + class { '::gnocchi::keystone::authtoken': + password => 'a_big_secret', + } + class { '::gnocchi::api': + enabled => true, + service_name => 'httpd', + sync_db => true, + } + class { '::gnocchi::metricd': } + class { '::gnocchi::storage': } + class { '::gnocchi::storage::file': } + include ::apache + class { '::gnocchi::wsgi::apache': + ssl => false, + } + class { '::gnocchi::statsd': + archive_policy_name => 'high', + flush_delay => '100', + resource_id => '07f26121-5777-48ba-8a0b-d70468133dd9', + user_id => 'f81e9b1f-9505-4298-bc33-43dfbd9a973b', + project_id => '203ef419-e73f-4b8a-a73f-3d599a72b18d', + } + class { '::gnocchi::client': } 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(8041) do - it { is_expected.to be_listening } - end + describe port(8041) do + it { is_expected.to be_listening } end end diff --git a/spec/classes/gnocchi_api_spec.rb b/spec/classes/gnocchi_api_spec.rb index 076d1eb8..d7c31447 100644 --- a/spec/classes/gnocchi_api_spec.rb +++ b/spec/classes/gnocchi_api_spec.rb @@ -18,6 +18,31 @@ describe 'gnocchi::api' do } end + shared_examples_for 'gnocchi-api wsgi' do + context 'with gnocchi-api in wsgi' do + before do + params.merge!({ :service_name => 'httpd' }) + end + + let :pre_condition do + "include ::apache + include ::gnocchi::db + class { 'gnocchi': } + class { '::gnocchi::keystone::authtoken': + password => 'gnocchi-passw0rd', + }" + end + + it 'installs gnocchi-api package' do + is_expected.to contain_package('gnocchi-api').with( + :ensure => 'latest', + :name => platform_params[:api_package_name], + :tag => ['openstack', 'gnocchi-package'], + ) + end + end + end + shared_examples_for 'gnocchi-api' do it { is_expected.to contain_class('gnocchi::deps') } @@ -149,9 +174,16 @@ describe 'gnocchi::api' do end let(:platform_params) do - { :api_package_name => 'gnocchi-api', + if facts[:operatingsystem] == 'Ubuntu' then + package_name = 'python-gnocchi' + else + package_name = 'gnocchi-api' + end + { :api_package_name => package_name, :api_service_name => 'gnocchi-api' } end + + it_behaves_like 'gnocchi-api wsgi' it_behaves_like 'gnocchi-api' end end diff --git a/spec/classes/gnocchi_storage_ceph_spec.rb b/spec/classes/gnocchi_storage_ceph_spec.rb index 70c7e78e..3d8d749a 100644 --- a/spec/classes/gnocchi_storage_ceph_spec.rb +++ b/spec/classes/gnocchi_storage_ceph_spec.rb @@ -86,6 +86,7 @@ describe 'gnocchi::storage::ceph' do it { is_expected.to contain_package('python-cradox').with(:ensure => 'present') } it { is_expected.not_to contain_package('python-rados') } + it { is_expected.not_to contain_package('python3-rados') } end end @@ -104,6 +105,20 @@ describe 'gnocchi::storage::ceph' do end end + shared_examples 'gnocchi storage ceph ubuntu' do + context 'with manage_rados set to true installs python3-rados on Ubuntu' do + before do + params.merge!({ + :manage_cradox => false, + :manage_rados => true, + }) + end + + it { is_expected.to contain_package('python3-rados').with(:ensure => 'present') } + + end + end + on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| @@ -119,6 +134,10 @@ describe 'gnocchi::storage::ceph' do it_behaves_like 'gnocchi storage ceph cradox redhat' end + if facts[:operatingsystem] == 'Ubuntu' then + it_behaves_like 'gnocchi storage ceph ubuntu' + end + it_behaves_like 'gnocchi storage ceph' end end diff --git a/spec/classes/gnocchi_storage_spec.rb b/spec/classes/gnocchi_storage_spec.rb index 14f72056..efc833e3 100644 --- a/spec/classes/gnocchi_storage_spec.rb +++ b/spec/classes/gnocchi_storage_spec.rb @@ -33,6 +33,24 @@ describe 'gnocchi::storage' do end end + shared_examples_for 'gnocchi-storage ubuntu' do + context 'with coordination set on ubuntu' do + before do + params.merge!({ + :coordination_url => 'redis://localhost:6379', + :metric_processing_delay => 30, + }) + end + + it 'installs python3-redis package' do + is_expected.to contain_package('python3-redis').with( + :name => 'python3-redis', + :tag => 'openstack' + ) + end + end + end + on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| @@ -48,7 +66,11 @@ describe 'gnocchi::storage' do when 'RedHat' { :redis_package_name => 'python-redis' } end - end + end + + if facts[:operatingsystem] == 'Ubuntu' then + it_behaves_like 'gnocchi-storage ubuntu' + end it_behaves_like 'gnocchi-storage' end diff --git a/spec/classes/gnocchi_wsgi_apache_spec.rb b/spec/classes/gnocchi_wsgi_apache_spec.rb index 412d1422..50290016 100644 --- a/spec/classes/gnocchi_wsgi_apache_spec.rb +++ b/spec/classes/gnocchi_wsgi_apache_spec.rb @@ -92,11 +92,16 @@ describe 'gnocchi::wsgi::apache' do let(:platform_params) do case facts[:osfamily] when 'Debian' + if facts[:operatingsystem] == 'Ubuntu' then + script_source = '/usr/bin/python2-gnocchi-api' + else + script_source = '/usr/share/gnocchi-common/app.wsgi' + end { :httpd_service_name => 'apache2', :httpd_ports_file => '/etc/apache2/ports.conf', :wsgi_script_path => '/usr/lib/cgi-bin/gnocchi', - :wsgi_script_source => '/usr/share/gnocchi-common/app.wsgi' + :wsgi_script_source => script_source } when 'RedHat' {