Remove pre/post test framework

It's not used and most likely will never be
it only garbages the repository

Change-Id: Ic84dec528d13ee24836a8eabfa85cc13a4f62587
Related-Bug: 1462997
Related-Bug: 1525242
This commit is contained in:
Dmitry Ilyin 2016-04-08 15:58:11 +03:00
parent 0d73db0241
commit 6b43a18979
71 changed files with 0 additions and 2254 deletions

View File

@ -1,37 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
PORT = 8042
PROCESSES = %w(
aodh-notifier
aodh-evaluator
aodh-listener
aodh-api
)
if TestCommon::Facts.osfamily == 'Debian'
PACEMAKER_SERVICES = %w(
p_aodh-evaluator
)
end
class AodhControllerPostTest < Test::Unit::TestCase
def test_aodh_processes_running
PROCESSES.each do |process|
assert TestCommon::Process.running?(process), "'#{process}' is not running!"
end
end
def test_haproxy_aodh_backend_online
assert TestCommon::HAProxy.backend_up?('aodh'), "HAProxy backend 'aodh' is not online!"
end
def test_pacemaker_services_running
return unless PACEMAKER_SERVICES
PACEMAKER_SERVICES.each do |service|
assert TestCommon::Pacemaker.primitive_started?(service), "Pacemaker service '#{service}' is not running!"
end
end
end

View File

@ -1,8 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class AodhPreTest < Test::Unit::TestCase
def test_amqp_accessible
assert TestCommon::AMQP.connection?, 'Cannot connect to AMQP server!'
end
end

View File

@ -1,17 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
PORT = 8777
PROCESSES = %w(
ceilometer-polling
)
class CeilometerComputePostTest < Test::Unit::TestCase
def test_ceilometer_processes_running
PROCESSES.each do |process|
assert TestCommon::Process.running?(process), "'#{process}' is not running!"
end
end
end

View File

@ -1,12 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class CeilometerComputePreTest < Test::Unit::TestCase
def test_amqp_accessible
host = TestCommon::Settings.amqp_hosts.split(':').first
user = TestCommon::Settings.rabbit['user']
password = TestCommon::Settings.rabbit['password']
assert TestCommon::AMQP.connection?(user, password, host), 'Cannot connect to AMQP server!'
end
end

View File

@ -1,50 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
PORT = 8777
PROCESSES = %w(
ceilometer-collector
ceilometer-polling
ceilometer-agent-notification
ceilometer-alarm-notifier
ceilometer-alarm-evaluator
ceilometer-api
)
if TestCommon::Facts.osfamily == 'RedHat'
PACEMAKER_SERVICES = %w(
p_openstack-ceilometer-central
p_openstack-ceilometer-alarm-evaluator
)
elsif TestCommon::Facts.osfamily == 'Debian'
PACEMAKER_SERVICES = %w(
p_ceilometer-agent-central
p_ceilometer-alarm-evaluator
)
end
class CeilometerControllerPostTest < Test::Unit::TestCase
def test_ceilometer_processes_running
PROCESSES.each do |process|
assert TestCommon::Process.running?(process), "'#{process}' is not running!"
end
end
def test_haproxy_ceilometer_backend_online
assert TestCommon::HAProxy.backend_up?('ceilometer'), "HAProxy backend 'ceilometer' is not online!"
end
def test_ceilometer_meter_list_run
cmd = '. /root/openrc && ceilometer meter-list'
assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!"
end
def test_pacemaker_services_running
return unless PACEMAKER_SERVICES
PACEMAKER_SERVICES.each do |service|
assert TestCommon::Pacemaker.primitive_started?(service), "Pacemaker service '#{service}' is not running!"
end
end
end

View File

@ -1,15 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
BACKEND = 'ceilometer'
class CeilometerControllerPreTest < Test::Unit::TestCase
def test_ceilometer_backend_present
assert TestCommon::HAProxy.backend_present?(BACKEND), "There is no '#{BACKEND}' HAProxy backend!"
end
def test_amqp_accessible
assert TestCommon::AMQP.connection?, 'Cannot connect to AMQP server!'
end
end

View File

@ -1,39 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
PORT = [9292,9494]
class GlancePostTest < Test::Unit::TestCase
def test_glance_api_is_running
assert TestCommon::Process.running?('/usr/bin/glance-api'), 'Glance API is not running!'
end
def test_glance_gistry_is_running
assert TestCommon::Process.running?('/usr/bin/glance-registry'), 'Glance Registry is not running!'
end
def test_glance_glare_is_running
assert TestCommon::Process.running?('/usr/bin/glance-glare'), 'Glance Glare is not running!'
end
def test_glance_public_url_accessible
PORTS.each do |PORT|
url = "https://#{TestCommon::Settings.public_vip}:#{PORT}"
assert TestCommon::Network.url_accessible?(url), "Public Glance URL '#{url}' is not accessible!"
end
end
def test_glance_admin_url_accessible
PORTS.each do |PORT|
url = "http://#{TestCommon::Settings.management_vip}:#{PORT}"
assert TestCommon::Network.url_accessible?(url), "Management Glance URL '#{url}' is not accessible!"
end
end
def test_keystone_endpoint_list_run
TestCommon::Cmd.openstack_auth
cmd = 'glance image-list'
assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!"
end
end

View File

@ -1,17 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
BACKENDS = ['glance-api', 'glance-glare']
class GlancePreTest < Test::Unit::TestCase
def test_haproxy_glance_backend_present
BACKENDS.each do |BACKEND|
assert TestCommon::HAProxy.backend_present?(BACKEND), "There is no '#{BACKEND}' HAProxy backend!"
end
end
def test_amqp_accessible
assert TestCommon::AMQP.connection?, 'Cannot connect to AMQP server!'
end
end

View File

@ -1,71 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
PROCESSES = %w(
heat-api
heat-api-cfn
heat-api-cloudwatch
heat-engine
)
BACKENDS = %w(
heat-api
heat-api-cfn
heat-api-cloudwatch
)
HOSTS = {
'http' => TestCommon::Settings.public_vip,
'http' => TestCommon::Settings.management_vip,
}
PORTS = {
'api' => 8004,
'api-cfn' => 8003,
'api-cloudwatch' => 8000,
}
class HeatPostTest < Test::Unit::TestCase
def self.create_tests
PROCESSES.each do |process|
method_name = "test_process_#{process}_running"
define_method method_name do
assert TestCommon::Process.running?(process), "Process '#{process}' is not running!"
end
end
BACKENDS.each do |backend|
method_name = "test_backend_#{backend}_online"
define_method method_name do
assert TestCommon::HAProxy.backend_up?(backend), "HAProxy backend '#{backend}' is not online!"
end
end
HOSTS.each do |host_type, ip|
PORTS.each do |port_type, port|
method_name = "test_#{host_type}_heat_#{port_type}_accessible"
define_method method_name do
url = "#{host_type}://#{ip}:#{port}"
assert TestCommon::Network.url_accessible?(url), "URL '#{url}' is unaccessible?"
end
end
end
def test_heat_stack_list_run
assert TestCommon::Process.run_successful?('. /root/openrc && heat stack-list'), 'Could not run heat-stack list!'
end
def test_heat_trusts_present
assert TestCommon::Config.value?('/etc/heat/heat.conf', 'deferred_auth_method', 'trusts'), 'deferred_auth_method is not found in heat.conf'
assert TestCommon::Config.value?('/etc/heat/heat.conf', 'trusts_delegated_roles', nil), 'trusts_delegated_roles is found in heat.conf'
end
def test_heat_domain_present
password = TestCommon::Settings.heat['user_password']
assert TestCommon::Config.value?('/etc/heat/heat.conf', 'stack_domain_admin', 'heat_admin'), 'stack_domain_admin is not found in heat.conf'
assert TestCommon::Config.value?('/etc/heat/heat.conf', 'stack_domain_admin_password', password), 'stack_domain_admin_password is not found in heat.conf'
end
end
end
HeatPostTest.create_tests

View File

@ -1,13 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class HeatPostTest < Test::Unit::TestCase
def test_amqp_accessible
assert TestCommon::AMQP.connection?, 'Cannot connect to AMQP server!'
end
def test_keystone_haproxy_backend_online
assert TestCommon::HAProxy.backend_up?('keystone-1'), 'Keystone-1 backend is not up!'
assert TestCommon::HAProxy.backend_up?('keystone-2'), 'Keystone-2 backend is not up!'
end
end

View File

@ -1,8 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class HorizonPostTest < Test::Unit::TestCase
def test_horizon_backend_online
assert TestCommon::HAProxy.backend_up?('horizon'), 'Haproxy horizon backend is not online!'
end
end

View File

@ -1,12 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class HorizonPreTest < Test::Unit::TestCase
def test_memcached_is_running
assert TestCommon::Process.running?('memcached'), 'Memcached is not running!'
end
def test_memcached_on_localhost
ip = TestCommon::Settings.internal_address
assert TestCommon::Network.connection?(ip, 11211), 'Can not connect to memcached on this host!'
end
end

View File

@ -1,40 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
PUBLIC_PORT = 5000
ADMIN_PORT = 35357
class KeystonePostTest < Test::Unit::TestCase
def test_keystone_is_running
assert TestCommon::Process.running?('/usr/sbin/apache2'), 'Keystone is not running!'
end
def test_keystone_public_url_accessible
url = "https://#{TestCommon::Settings.public_vip}:#{PUBLIC_PORT}"
assert TestCommon::Network.url_accessible?(url), "Public Keystone URL '#{url}' is not accessible!"
end
def test_keystone_admin_url_accessible
url = "http://#{TestCommon::Settings.management_vip}:#{ADMIN_PORT}"
assert TestCommon::Network.url_accessible?(url), "Admin Keystone URL '#{url}' is not accessible!"
end
def test_keystone_endpoint_list_run
TestCommon::Cmd.openstack_auth
cmd = 'keystone endpoint-list'
assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!"
end
def test_root_openrc_file_present
assert File.exist?('/root/openrc'), '/root/openrc is missing!'
end
def test_os_user_openrc_file_present
assert File.exist?("#{TestCommon::Settings.operator_user_homedir}/openrc"), "#{TestCommon::Settings.operator_user_homedir}/openrc is missing!"
end
def test_svc_openrc_file_present
assert File.exist?("#{TestCommon::Settings.service_user_homedir}/openrc"), "#{TestCommon::Settings.service_user_homedir}/openrc is missing!"
end
end

View File

@ -1,20 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
PUBLIC_BACKEND = 'keystone-1'
ADMIN_BACKEND = 'keystone-2'
class KeystonePreTest < Test::Unit::TestCase
def test_haproxy_public_backend_present
assert TestCommon::HAProxy.backend_present?(PUBLIC_BACKEND), "There is no '#{PUBLIC_BACKEND}' HAProxy backend!"
end
def test_haproxy_admin_backend_present
assert TestCommon::HAProxy.backend_present?(ADMIN_BACKEND), "There is no '#{ADMIN_BACKEND}' HAProxy backend!"
end
def test_amqp_accessible
assert TestCommon::AMQP.connection?, 'Cannot connect to AMQP server!'
end
end

View File

@ -1,35 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class MuranoPostTest < Test::Unit::TestCase
def test_murano_is_running
assert TestCommon::Process.running?('murano-api'), 'Murano-api is not running!'
end
def test_murano_engine_pacemaker_service_running
assert TestCommon::Pacemaker.primitive_started?('p_openstack-murano-engine'), 'Murano-engine Pacemaker service is not started!'
end
def test_murano_haproxy_backend_online
assert TestCommon::HAProxy.backend_up?('murano-api'), 'Murano HAProxy backend is not up!'
end
def test_murano_rabbitmq_haproxy_backend_online
assert TestCommon::HAProxy.backend_up?('murano_rabbitmq'), 'Murano_rabbitmq HAProxy backend is not up!'
end
def test_murano_api_url_accessible
ip = TestCommon::Settings.management_vip
port = 8082
url = "http://#{ip}:#{port}"
assert TestCommon::Network.url_accessible?(url), "Murano-api url '#{url}' is not accessible!"
end
def test_murano_has_core_library
murano_package_list = TestCommon::Cmd.openstack_cli 'murano package-list'
assert murano_package_list.is_a?(Array), 'Could not get a correct murano package-list!'
core_library = murano_package_list.find { |line| line['FQN'] == 'io.murano' and line['Name'] == 'Core library' }
assert core_library, 'Core library with io.murano not found in murano package-list!'
end
end

View File

@ -1,17 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class MuranoPreTest < Test::Unit::TestCase
def test_amqp_accessible
assert TestCommon::AMQP.connection?, 'Cannot connect to AMQP server!'
end
def test_haproxy_murano_backend_present
assert TestCommon::HAProxy.backend_present?('murano-api'), 'No murano haproxy backend!'
end
def test_horizon_haproxy_backend_online
assert TestCommon::HAProxy.backend_up?('horizon'), 'Horizon HAProxy backend is not up!'
end
end

View File

@ -1,17 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class SaharaPostTest < Test::Unit::TestCase
def test_sahara_api_is_running
assert TestCommon::Process.running?('sahara-api'), 'Sahara-api is not running!'
end
def test_sahara_engine_is_running
assert TestCommon::Process.running?('sahara-engine'), 'Sahara-engine is not running!'
end
def test_sahara_haproxy_backend_online
assert TestCommon::HAProxy.backend_up?('sahara'), 'Sahara HAProxy backend is not up!'
end
end

View File

@ -1,21 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class SaharaPreTest < Test::Unit::TestCase
def test_amqp_accessible
assert TestCommon::AMQP.connection?, 'Cannot connect to AMQP server!'
end
def test_haproxy_sahara_backend_present
assert TestCommon::HAProxy.backend_present?('sahara'), 'No sahara haproxy backend!'
end
def test_horizon_haproxy_backend_online
assert TestCommon::HAProxy.backend_up?('horizon'), 'Horizon HAProxy backend is not up!'
end
def test_keystone_backend_online
assert TestCommon::HAProxy.backend_up?('keystone-1'), 'Haproxy keystone-1 backend is down!'
assert TestCommon::HAProxy.backend_up?('keystone-2'), 'Haproxy keystone-2 backend is down!'
end
end

View File

@ -1,13 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class SwiftRebalancePostTest < Test::Unit::TestCase
def test_that_cron_job_is_configured
if TestCommon::Settings.lookup('role') == 'primary-controller'
assert TestCommon::Cron.cronjob_exists?('swift', 'swift-rings-rebalance.sh'),
'No cronjob for swift-rings-rebalance.sh!'
else
assert TestCommon::Cron.cronjob_exists?('swift', 'swift-rings-sync.sh'),
'No cronjob for swift-rings-sync.sh!'
end
end
end

View File

@ -1,25 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
PROCESSES = %w(
swift-proxy-server
swift-account-server
swift-container-server
swift-object-server
)
class SwiftPostTest < Test::Unit::TestCase
def self.create_tests
PROCESSES.each do |process|
method_name = "test_process_#{process}_running"
define_method method_name do
assert TestCommon::Process.running?(process), "Process '#{process}' is not running!"
end
end
end
def test_swift_backend_online
assert TestCommon::HAProxy.backend_up?('swift'), 'Haproxy swift backend is down!'
end
end
SwiftPostTest.create_tests

View File

@ -1,8 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class SwiftPreTest < Test::Unit::TestCase
def test_keystone_backend_online
assert TestCommon::HAProxy.backend_up?('keystone-1'), 'Haproxy keystone-1 backend is down!'
assert TestCommon::HAProxy.backend_up?('keystone-2'), 'Haproxy keystone-2 backend is down!'
end
end

View File

@ -1,10 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class ApachePostTest < Test::Unit::TestCase
def test_apache_80_on_public
ip = TestCommon::Settings.public_address
assert TestCommon::Network.connection?(ip, 80), 'Cannot connect to apache on the public address!'
end
end

View File

@ -1,8 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class ApiProxyPostTest < Test::Unit::TestCase
def test_api_proxy_online
assert TestCommon::Network.connection?('localhost', 8888), 'Cannot connect to API proxy!'
end
end

View File

@ -1,24 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class CephComputePostTest < Test::Unit::TestCase
def config
'/etc/nova/nova.conf'
end
def ephemeral_enabled?
TestCommon::Settings.lookup('storage', {}).fetch 'ephemeral_ceph', false
end
def test_nova_ceph_ephemeral_configured
return unless ephemeral_enabled?
assert TestCommon::Config.value?(config, 'libvirt/images_type', 'rbd'), 'No libvirt/images_type in nova.conf!'
assert TestCommon::Config.value?(config, 'libvirt/inject_key', false), 'No libvirt/inject_key in nova.conf!'
assert TestCommon::Config.value?(config, 'libvirt/inject_partition', -2), 'No libvirt/inject_partition in nova.conf!'
assert TestCommon::Config.value?(config, 'libvirt/images_rbd_pool', 'compute'), 'No libvirt/images_rbd_pool in nova.conf!'
end
def test_nova_ceph_compute_configured
assert TestCommon::Config.value?(config, 'libvirt/rbd_user', 'compute'), 'No libvirt/rbd_user in nova.conf!'
assert TestCommon::Config.has_line?(config, /^rbd_secret_uuid=[\w\-]*$/), 'No rbd_secret_uuid in nova.conf!'
end
end

View File

@ -1,11 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class RadosgwPostTest < Test::Unit::TestCase
def test_radosgw_process_running
assert TestCommon::Process.running?('radosgw'), 'Radosgw process is not running!'
end
def test_radosgw_backend_online
assert TestCommon::Network.connection?('localhost', 6780), 'Can not connect to radoswg port 6780 on this host!'
end
end

View File

@ -1,7 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class RadosgwPreTest < Test::Unit::TestCase
def test_keystone_backend_online
assert TestCommon::HAProxy.backend_up?('keystone-1'), 'Haproxy keystone backend is down!'
end
end

View File

@ -1,16 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class ClusterHaproxyPostTest < Test::Unit::TestCase
def test_haproxy_config_present
assert File.file?('/etc/haproxy/haproxy.cfg'), 'No haproxy config file!'
end
def test_haproxy_is_running
assert TestCommon::Process.running?('/usr/sbin/haproxy'), 'Haproxy is not running!'
end
def test_haproxy_stats_accessible
url = TestCommon::HAProxy.stats_url
assert TestCommon::Network.url_accessible?(url), "Cannot connect to the HAProxy stats url '#{url}'!"
end
end

View File

@ -1,29 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
PROCESSES = %w(
crmd
lrmd
pengine
attrd
stonithd
cib
pacemakerd
corosync
)
class ClusterPostTest < Test::Unit::TestCase
def self.create_tests
PROCESSES.each do |process|
method_name = "test_process_#{process}_running"
define_method method_name do
assert TestCommon::Process.running?(process), "Process '#{process}' is not running!"
end
end
end
def test_pacemaker_is_online
assert TestCommon::Pacemaker.online?, 'Could not query Pacemaker CIB!'
end
end
ClusterPostTest.create_tests

View File

@ -1,14 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class HealthPostTest < Test::Unit::TestCase
def ubuntu?
TestCommon::Facts.operatingsystem == 'Ubuntu'
end
def test_sysinfo_resource_started
return unless ubuntu?
fqdn = TestCommon::Settings.fqdn
assert TestCommon::Pacemaker.primitive_present?("sysinfo_#{fqdn}"), 'sysinfo is not created!'
end
end

View File

@ -1,81 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
BACKEND = 'mysqld'
PROCESS = 'mysqld_safe'
PRIMITIVE = 'p_mysql'
class DatabaseInstallPostTest < Test::Unit::TestCase
def test_mysqld_safe_is_running
assert TestCommon::Process.running?(PROCESS), "Process '#{PROCESS}' is not running!"
end
def test_mysql_primitive_running
assert TestCommon::Pacemaker.primitive_started?(PRIMITIVE), "Primitive '#{PRIMITIVE}' is not started!"
end
def test_mysqld_haproxy_backend_up
assert TestCommon::HAProxy.backend_up?(BACKEND), "HAProxy backend '#{BACKEND}' is not up!"
end
def test_mysql_connection_without_auth
TestCommon::MySQL.no_auth
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL without auth!'
end
def test_mysql_connection_with_auth
TestCommon::MySQL.pass = TestCommon::Settings.mysql['root_password']
TestCommon::MySQL.user = 'root'
TestCommon::MySQL.host = 'localhost'
TestCommon::MySQL.port = 3306
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL with auth!'
end
def test_mysql_connection_keystone
TestCommon::MySQL.pass = TestCommon::Settings.keystone['db_password']
TestCommon::MySQL.user = 'keystone'
TestCommon::MySQL.host = TestCommon::Settings.management_vip
TestCommon::MySQL.port = 3306
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL with Keystone auth!'
end
def test_mysql_connection_glance
TestCommon::MySQL.pass = TestCommon::Settings.glance['db_password']
TestCommon::MySQL.user = 'glance'
TestCommon::MySQL.host = TestCommon::Settings.management_vip
TestCommon::MySQL.port = 3306
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL with Glance auth!'
end
def test_mysql_connection_nova
TestCommon::MySQL.pass = TestCommon::Settings.nova['db_password']
TestCommon::MySQL.user = 'nova'
TestCommon::MySQL.host = TestCommon::Settings.management_vip
TestCommon::MySQL.port = 3306
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL with Nova auth!'
end
def test_mysql_connection_cinder
TestCommon::MySQL.pass = TestCommon::Settings.cinder['db_password']
TestCommon::MySQL.user = 'cinder'
TestCommon::MySQL.host = TestCommon::Settings.management_vip
TestCommon::MySQL.port = 3306
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL with Cinder auth!'
end
def test_mysql_connection_neutron
return unless TestCommon::Settings.use_neutron
TestCommon::MySQL.pass = TestCommon::Settings.cinder['db_password']
TestCommon::MySQL.user = 'cinder'
TestCommon::MySQL.host = TestCommon::Settings.management_vip
TestCommon::MySQL.port = 3306
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL with Cinder auth!'
end
def test_mysql_status_check_ok
check_port = 49000
url = "http://#{TestCommon::Settings.fqdn}:#{check_port}"
assert TestCommon::Network.url_accessible?(url), 'Cannot connect to the MySQL Checker URL!'
end
end

View File

@ -1,20 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
BACKEND = 'mysqld'
class DatabasePreTest < Test::Unit::TestCase
def test_haproxy_stats_accessible
url = TestCommon::HAProxy.stats_url
assert TestCommon::Network.url_accessible?(url), "Cannot connect to the HAProxy stats url '#{url}'!"
end
def test_mysqld_haproxy_backend_present
assert TestCommon::HAProxy.backend_present?(BACKEND), "There is no '#{BACKEND}' HAProxy backend!"
end
def test_pacemaker_installed
assert TestCommon::Pacemaker.online?, 'Pacemaker is not running!'
end
end

View File

@ -1,75 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
COMMON_RULES = [
'accept all icmp requests',
'accept all to lo interface',
'ssh',
'iscsi',
'ntp-server',
'notrack gre',
'accept gre',
'vxlan_udp_port',
]
CONTROLLER_RULES = [
'remote rabbitmq',
'remote puppet',
'local rabbitmq admin',
'reject non-local rabbitmq admin',
'allow connections from haproxy namespace',
'http',
'mysql',
'keystone',
'swift',
'glance',
'nova',
'nova internal - no ssl',
'rabbitmq',
'memcache tcp',
'memcache udp',
'rsync',
'neutron',
'dns-server udp',
'dns-server tcp',
'dhcp-server',
'corosync-input',
'corosync-output',
'pcsd-server',
'openvswitch db',
'ceilometer',
'murano-rabbitmq',
'heat-api',
'heat-api-cfn',
'heat-api-cloudwatch',
]
COMPUTE_RULES = [
'libvirt',
'libvirt-migration',
]
def role
TestCommon::Settings.role.to_s
end
class FirewallPostTest < Test::Unit::TestCase
def self.create_tests(rules)
rules.each do |rule|
method_name = "test_iptables_have_rule_#{rule.gsub ' ', '_'}"
define_method method_name do
assert TestCommon::Network.iptables_rules.include?(rule), "Iptables don't have the '#{rule}' rule!'"
end
end
end
def self.run_tests
create_tests COMMON_RULES
if %w(controller primary-controller).include? role
create_tests CONTROLLER_RULES
elsif role == "compute"
create_tests COMPUTE_RULES
end
end
end
FirewallPostTest.run_tests

View File

@ -1,7 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class FirewallPreTest < Test::Unit::TestCase
def test_iptables_installed
assert TestCommon::Process.command_present?('iptables'), 'Iptables is not installed!'
end
end

View File

@ -1,16 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class HostsPostTest < Test::Unit::TestCase
def test_hosts_file_has_all_nodes
nodes_array = TestCommon::Settings.nodes
raise 'No nodes data!' unless nodes_array and nodes_array.is_a? Array
hosts_file = File.read '/etc/hosts'
nodes_array.each do |node|
host_regexp1 = Regexp.new "#{node['internal_address']}\\s+#{node['fqdn']}\\s+#{node['name']}"
host_regexp2 = Regexp.new "#{node['internal_address']}\\s+#{node['name']}\\s+#{node['fqdn']}"
assert (hosts_file =~ host_regexp1 or hosts_file =~ host_regexp2), "Host #{node['name']} was not found in hosts file!"
end
end
end

View File

@ -1,22 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class HostsPreTest < Test::Unit::TestCase
def test_hiera_has_nodes_data
nodes_array = TestCommon::Settings.nodes
assert nodes_array.is_a?(Array), 'Nodes data not found!'
assert nodes_array.any?
end
def test_nodes_are_correct
nodes_array = TestCommon::Settings.nodes
nodes_array.each do |node|
error = "Node #{node.inspect} is not correct!"
assert node['internal_address'], error
assert node['fqdn'], error
assert node['name'], error
end
end
end

View File

@ -1,18 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class MemcachedPostTest < Test::Unit::TestCase
def test_memcached_is_running
assert TestCommon::Process.running?('memcached'), 'Memcached is not running!'
end
def get_node
metadata = TestCommon::Settings.network_metadata
node_name = TestCommon::Settings.node_name
return metadata['nodes'][node_name]
end
def test_memcached_listen
ip = get_node['network_roles']['mgmt/memcache']
assert TestCommon::Network.connection?(ip, 11211), 'Cannot connect to memcached on the internal address!'
end
end

View File

@ -1,67 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class NetconfigPostTest < Test::Unit::TestCase
def node
TestCommon::Settings.nodes.each do |node|
next unless node['fqdn'] == TestCommon::Settings.fqdn
return node
end
end
def test_management_ip_present
ip = node['internal_address']
assert TestCommon::Network.ips.include?(ip), 'Management address is not set!'
end
def test_public_ip_present
if %w(controller primary-controller).include? TestCommon::Settings.role
ip = node['public_address']
assert TestCommon::Network.ips.include?(ip), 'Public address is not set!'
end
end
def test_storage_ip_present
ip = node['storage_address']
assert TestCommon::Network.ips.include?(ip), 'Storage address is not set!'
end
def test_can_ping_the_default_router_on_controller
return unless %w(controller primary-controller).include? TestCommon::Settings.role
ip = TestCommon::Network.default_router
assert TestCommon::Network.ping?(ip), "Cannot ping the default router '#{ip}'!"
end
def test_can_ping_the_master_node
ip = TestCommon::Settings.master_ip
assert TestCommon::Network.ping?(ip), "Cannot ping the master node '#{ip}'!"
end
def processor_count
File.read('/proc/cpuinfo').split("\n").count { |line| line.start_with? 'processor' }
end
def hex_mask
return @hex_mask if @hex_mask
@hex_mask = ((2 ** processor_count) -1 ).to_s(16)
end
def rps_cpus
Dir.glob('/sys/class/net/eth*/queues/rx-*/rps_cpus')
end
def test_rps_cpus_set
rps_cpus.each do |node|
assert File.read(node).chomp.end_with?(hex_mask), "Sysfs node: '#{node}' is not '#{hex_mask}'!"
end
end
def test_rps_cpus_config
assert File.exists?('/etc/sysfs.d/rps_cpus.conf'), 'RPS_CPUS sysfs config is missing!'
rps_cpus.each do |line|
line.gsub! %r(/sys/), ''
line = "#{line} = #{hex_mask}"
assert TestCommon::Config.has_line?('/etc/sysfs.d/rps_cpus.conf', line), "Line '#{line}' is missing in the rps_cpus.conf!"
end
end
end

View File

@ -1,12 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class NetconfigPreTest < Test::Unit::TestCase
def test_nodes_present_in_hiera
nodes = TestCommon::Settings.nodes
assert nodes, 'Could not get the nodes data!'
assert nodes.is_a?(Array), 'Incorrect nodes data!'
assert nodes.any?, 'Empty nodes data!'
end
end

View File

@ -1,27 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class NTPServerPostTest < Test::Unit::TestCase
def has_external_ntp?
TestCommon::Settings.lookup 'external_ntp'
end
def test_ntp_config_present
assert File.file?('/etc/ntp.conf'), 'No NTP config file!'
end
def test_ntp_is_running
assert TestCommon::Process.running?('/usr/sbin/ntpd'), 'NTP is not running!'
end
def test_ntp_monitor_inaccessible_via_public
out = `ntpq -p #{TestCommon::Settings.public_address}`
assert out == '', "NTP peers advertised on public address"
end
def test_ntp_monitor_inaccessible_via_internal
out = `ntpq -p #{TestCommon::Settings.internal_address}`
assert out == '', "NTP peers advertised on internal address"
end
end

View File

@ -1,11 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
aodh
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,11 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
ceilometer
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,11 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
cinder-api
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,12 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
glance-api
glance-registry
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,13 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
heat-api
heat-api-cfn
heat-api-cloudwatch
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,11 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
horizon
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,12 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
ironic
ironic-baremetal
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,12 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
keystone-1
keystone-2
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,12 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
murano
murano_rabbitmq
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,11 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
mysqld
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,11 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
neutron
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,12 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
nova-api
nova-metadata-api
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,11 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
radosgw
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,11 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
sahara
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,12 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
stats
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,11 +0,0 @@
require File.join File.dirname(__FILE__), 'haproxy_post_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
swift
)
$expected_backends = backends
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,39 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
def expected_backends
return $expected_backends if $expected_backends
backends = %w(
Stats
horizon
keystone-1
keystone-2
nova-api
nova-metadata-api
cinder-api
glance-api
neutron
glance-registry
mysqld
swift
heat-api
heat-api-cfn
heat-api-cloudwatch
nova-novncproxy
)
backends += %w(sahara) if TestCommon::Settings.sahara['enabled']
backends += %w(murano murano_rabbitmq) if TestCommon::Settings.murano['enabled']
$expected_backends = backends
end
class OpenstackHaproxyPostTest < Test::Unit::TestCase
def self.create_tests
expected_backends.each do |backend|
method_name = "test_backend_#{backend}_present"
define_method method_name do
assert TestCommon::HAProxy.backend_present?(backend), "There is no '#{backend}' HAProxy backend!"
end
end
end
end
OpenstackHaproxyPostTest.create_tests

View File

@ -1,9 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class OpenstackHaproxyPreTest < Test::Unit::TestCase
def test_haproxy_is_running
assert TestCommon::Process.running?('haproxy'), 'Haproxy is not running!'
end
end

View File

@ -1,16 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
RABBITMQ_USER="rabbitmq"
class RabbitMQPostTest < Test::Unit::TestCase
def test_rabbitmq_is_running
assert TestCommon::Process.running?('/usr/sbin/rabbitmq-server'), 'RabbitMQ is not running!'
end
def test_rabbitmq_running_as_rabbitmq_user
cmd = "ps haxo user,cmd | egrep -v su | egrep \"rabbitmq|beam|epmd\" | egrep -v ^#{RABBITMQ_USER}"
assert TestCommon::Process.run_successful?(cmd), "'#{cmd}' returns processes not running as #{RABBITMQ_USER}'"
end
end

View File

@ -1,91 +0,0 @@
# Copyright 2015 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.
require 'find'
require 'yaml'
# this file can run all the tests fro the modular tasks found
# in this folder and then display the report
def test_dir
File.dirname(__FILE__)
end
def each_task_file
Find.find(test_dir) do |path|
yield path if path.end_with? 'tasks.yaml'
end
end
def tasks
data = []
each_task_file do |file|
begin
task = YAML.load_file file
data = data + task if task.is_a? Array
rescue => e
puts "Error in task file '#{file}': #{e.message}"
next
end
end
data
end
def each_test
tasks.each do |task|
next unless task.is_a? Hash
id = task['id']
next unless id
test_pre = task.fetch('test_pre', {}).fetch('cmd', nil)
test_post = task.fetch('test_post', {}).fetch('cmd', nil)
yield id, :pre, test_pre if test_pre
yield id, :post, test_post if test_post
end
end
def print_results(results)
results.each do |result|
id = result[:id].to_s.ljust 30
type = result[:type].to_s.ljust 4
success = (result[:success] ? 'OK' : 'FAIL').ljust 4
cmd = result[:cmd]
puts "#{id} #{type} #{success} '#{cmd}'"
end
end
def run_tests
results = []
each_test do |id, type, cmd|
puts '=' * 79
puts "Run: '#{cmd}'"
system cmd
success = $?.exitstatus == 0
result = {
:id => id,
:cmd => cmd,
:type => type,
:success => success,
}
results << result
end
puts '=' * 79
print_results results
end
############################################
run_tests
#TODO port the old tasklib for this tests format

View File

@ -1,15 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class SslKeysSavingPostTest < Test::Unit::TestCase
def public_ssl
ssl_hash = TestCommon::Settings.lookup 'public_ssl'
ssl_hash['horizon'] or ssl_hash['services']
end
def test_ssl_keys_availability
assert File.file?('/var/lib/astute/haproxy/public_haproxy.pem'), 'No public keypair saved!' unless not public_ssl
assert !File.file?('/var/lib/astute/haproxy/public_haproxy.pem'), 'Keypair exist but should not!' unless public_ssl
end
end

View File

@ -1,9 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class SslKeysSavingPreTest < Test::Unit::TestCase
def test_ssl_data
assert TestCommon::Settings.lookup('use_ssl'), 'No SSL hash found in Hiera!'
end
end

View File

@ -1,759 +0,0 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
require 'timeout'
require 'facter'
require 'socket'
module TestCommon
module Cmd
# Run a shell command and return stdout and return code as an array
# @param command [String] the command to run
# @return [Array<String,Numeric>] Stdout and return code
def self.run(command)
out = `#{command}`
code = $?.exitstatus
[out, code]
end
# set the OpenStack CLI auth data
def self.openstack_auth
ENV['LC_ALL'] = 'C'
ENV['OS_NO_CACHE'] = 'true'
ENV['OS_TENANT_NAME'] = TestCommon::Settings.access['tenant']
ENV['OS_USERNAME'] = TestCommon::Settings.access['user']
ENV['OS_PASSWORD'] = TestCommon::Settings.access['password']
ENV['OS_AUTH_URL'] = "http://#{TestCommon::Settings.management_vip}:5000/v2.0"
ENV['OS_AUTH_STRATEGY'] = 'keystone'
ENV['OS_REGION_NAME'] = 'RegionOne'
ENV['OS_ENDPOINT_TYPE'] = 'internalURL'
end
# run the openstack cli command with auth
# and parse the results into a structure
# @return [Array<Hash>]
def self.openstack_cli(command)
openstack_auth
out, code = run command
return [nil, code] unless code == 0
headers = nil
data = []
out.split("\n").each do |line|
next unless line.start_with? '|'
columns = line.split('|')
next unless columns.length > 2
columns = columns[1..-2].map do |column|
column.chomp.strip
end
unless headers
headers = columns
next
end
record = {}
field_number = 0
columns.each do |column|
header = headers[field_number]
next unless header
record[header] = column
field_number += 1
end
data << record if record.any?
end
data
end
end
module Settings
# get a Hiera class instance
# @return [Hiera]
def self.hiera
return @hiera if @hiera
@hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
# lookup a value using the Hiera class
# @param key [String,Symbol] a value to look for
# @return [String,Array,Hash,nil] found value or nil if not found
def self.lookup(key, default=nil)
key = key.to_s
key = 'rabbit_hash' if key == 'rabbit'
@keys = {} unless @keys
return @keys[key] if @keys[key]
@keys[key] = hiera.lookup key, default, {}
end
# access lookup values as methods
def self.method_missing(key)
lookup key
end
# access lookup methods as indices
def self.[](key)
lookup key
end
# reset mnemoization
def self.reset
@hiera = nil
@keys = nil
end
end
module HAProxy
# get the URL of HAProxy stats page
# @return [String] the stats url
def self.stats_url
ip = Settings.management_vip
ip = Settings.controller_node_address unless ip
raise 'Could not get internal address!' unless ip
port = 10000
"http://#{ip}:#{port}/;csv"
end
# read the CSV from the Stats URL
# @return [String] csv data
def self.csv
return @csv if @csv
begin
url = open(stats_url)
csv = url.read
rescue
nil
end
return nil unless csv and not csv.empty?
@csv = csv
end
# parse the csv data to the backends and their statuses
# 'backend_name' => 'UP/DOWN'
# @return [Hash<String => String>] the backends structure
def self.backends
return @backends if @backends
raise 'Could not get CSV from HAProxy stats!' unless csv
backends = {}
csv.split("\n").each do |line|
next if line.start_with? '#'
next unless line.include? 'BACKEND'
fields = line.split(',')
backend = fields[0]
status = fields[17]
backends[backend] = status
end
@backends = backends
end
# check if the backend is present
# @param backend [String] the backend name
# @return [true,false]
def self.backend_present?(backend)
backends.keys.include? backend
end
# check if the backend is online
# @param backend [String] the backend name
# @return [true,false]
def self.backend_up?(backend)
backends[backend] == 'UP'
end
# reset mnemoization
def self.reset
@csv = nil
@backends = nil
end
end
module Process
# try to run the command and return true if the run was successful
# @param cmd [String] the command to run
# @return [true,false]
def self.run_successful?(cmd)
out = TestCommon::Cmd.run cmd
out.last == 0
end
# try to run find if the command executable is installed
# @param cmd [String] the command to run
# @return [true,false]
def self.command_present?(command)
run_successful? "which '#{command}' 1>/dev/null 2>/dev/null"
end
# use the 'ps' to get the list of all running processes
# @return [Array<String>] the list of running commands
def self.list
return @process_list if @process_list
@process_list = []
ps = TestCommon::Cmd.run 'ps haxo cmd'
ps.first.split("\n").each do |cmd|
@process_list << cmd
end
@process_list
end
# check if there is a running command which
# command line contains this string
# @param process [String] look for this string in the list
# @return [true,false]
def self.running?(process)
not list.find { |cmd| cmd.include? process }.nil?
end
# use the 'ps' tool to build the process tree
# using pids and ppids of the processes
# and the pid as the hash key
# @return [Hash<Numeric => Hash>]
def self.tree
return @process_tree if @process_tree
@process_tree = {}
ps = TestCommon::Cmd.run 'ps haxo pid,ppid,cmd'
ps.first.split("\n").each do |p|
f = p.split
pid = f.shift.to_i
ppid = f.shift.to_i
cmd = f.join ' '
# create entry for this pid if not present
@process_tree[pid] = {
:children => []
} unless @process_tree.key? pid
# fill this entry
@process_tree[pid][:ppid] = ppid
@process_tree[pid][:pid] = pid
@process_tree[pid][:cmd] = cmd
unless ppid == 0
# create entry for parent process if not present
@process_tree[ppid] = {
:children => [],
:cmd => '',
} unless @process_tree.key? ppid
# fill parent's children
@process_tree[ppid][:children] << pid
end
end
@process_tree
end
# reset mnemoization
def self.reset
@process_tree = nil
@process_list = nil
end
end
module MySQL
@pass = nil
@user = nil
@host = nil
@port = nil
@db = nil
@options = '--raw --skip-column-names --batch'
# turn off the MySQL auth and use the saved credentials if any
def self.no_auth
@pass = nil
@user = nil
@host = nil
@port = nil
@db = nil
end
def self.pass=(pass)
@pass = pass
end
def self.pass
@pass
end
def self.user=(user)
@user = user
end
def self.user
@user
end
def self.host=(host)
@host = host
end
def self.host
@host
end
def self.port=(port)
@port = port
end
def self.port
@port
end
def self.db
@db
end
def self.db=(db)
@db = db
end
def self.options=(options)
@options = options
end
def self.options
@options
end
# execute the mysql query using the 'mysql' command
# return the array of the output and the exit code
# @param query [String] the query to run
# @return [Array<String, Numeric>] command output
def self.query(query)
query = query.gsub %q('), %q(")
command = %Q(mysql #{options} --execute='#{query}')
command += %Q( --host='#{host}') if host
command += %Q( --user='#{user}') if user
command += %Q( --password='#{pass}') if pass
command += %Q( --port='#{port}') if port
command += %Q( --database='#{db}') if db
TestCommon::Cmd.run command
end
# check if mysql can connect ot the server
# @return [true,false]
def self.connection?
result = query 'show databases'
result.last == 0
end
# get the list of databases on the server
# @return [Array<String>] the list of database names
def self.databases
return @databases if @databases
out, code = query 'show databases'
return unless code == 0
@databases = []
out.split("\n").each do |db|
@databases << db
end
@databases
end
# check is the database is present on the server
# @param database [String] the database name
# @return [true,false]
def self.database_exists?(database)
return unless databases
databases.include?(database)
end
# reset mnemoization
def self.reset
@databases = nil
no_auth
end
end
module Pacemaker
# check if pacemaker is online
# @return [true,false]
def self.online?
begin
out = Timeout::timeout(5) do
TestCommon::Cmd.run 'cibadmin -Q'
end
rescue
return false
end
out.last == 0
end
# get the list of pacemaker primitives
# @return [Array<String>] the list of primitive names
def self.primitives
begin
out = Timeout::timeout(5) do
TestCommon::Cmd.run 'crm_resource -l'
end
rescue
return
end
return unless out.last == 0
primitives = []
out.first.split("\n").each do |line|
primitives << line.split(':').first
end
primitives
end
# remove prefix from primitive name
# @param primitive [String] primitive name
# @return [String] primitive name without prefix
def self.clean_primitive_name(primitive)
primitive = primitive.gsub /^clone_/, ''
primitive = primitive.gsub /^master_/, ''
primitive
end
# check if the primitive is present in paceamaker
# @param primitive [String] primitive name
# @return [true,false]
def self.primitive_present?(primitive)
primitive = clean_primitive_name primitive
primitives.include? primitive
end
# check if the pacemaker primitive is started
# at least on a single cluster node
# @param primitive [String] primitive name
# @return [true,false]
def self.primitive_started?(primitive)
primitive = clean_primitive_name primitive
begin
out = TestCommon::Cmd.run "crm_resource -r #{primitive} -W 2>&1"
rescue
return
end
return true if out.first.include? 'is running on'
return false if out.first.include? 'is NOT running'
nil
end
# reset mnemoization
def self.reset
nil
end
end
module Facts
# use the Puppet's Facter to lookup a value
# @param fact [String,Symbol] the fact's name
def self.value(fact)
@facts = {} unless @facts
fact = fact.to_s
return @facts[fact] if @facts[fact]
@facts[fact] = Facter.value fact
@facts[fact]
end
# access using indices
def self.[](fact)
value fact
end
# access using method names
def self.method_missing(fact)
value fact
end
# reset mnemoization
def self.reset
@facts = nil
end
end
module Package
# obtain the list of rpm packages
# using the 'rpm' tool
# @returns [String] packages
def self.get_rpm_packages
out = TestCommon::Cmd.run "rpm -qa --queryformat '%{NAME}|%{VERSION}-%{RELEASE}\n'"
out.first
end
# obtain the list of deb packages
# using the 'dpkg-query' tool
# @returns [String] packages
def self.get_deb_packages
out = TestCommon::Cmd.run "dpkg-query --show -f='${Package}|${Version}|${Status}\n'"
out.first
end
# parse the received rpm packages list
# to get the structure of package names and versions
# 'package_name' => 'package_version'
# @returns [Hash<String => String>] packages
def self.parse_rpm_packages
packages = {}
get_rpm_packages.split("\n").each do |package|
fields = package.split('|')
name = fields[0]
version = fields[1]
if name
packages.store name, version
end
end
packages
end
# parse the received deb packages list
# to get the structure of package names and versions
# 'package_name' => 'package_version'
# @returns [Hash<String => String>] packages
def self.parse_deb_packages
packages = {}
get_deb_packages.split("\n").each do |package|
fields = package.split('|')
name = fields[0]
version = fields[1]
if fields[2] == 'install ok installed'
installed = true
else
installed = false
end
if installed and name
packages.store name, version
end
end
packages
end
# get the installed packages either on Debian or on RedHat system
# 'package_name' => 'package_version'
# @returns [Hash<String => String>] packages
def self.installed_packages
return @installed_packages if @installed_packages
if Facts.osfamily == 'RedHat'
@installed_packages = parse_rpm_packages
elsif Facts.osfamily == 'Debian'
@installed_packages = parse_deb_packages
else
raise "Unknown osfamily: #{Facts.osfamily}"
end
end
# reset mnemoization
def self.reset
@installed_packages = nil
end
# check if this package is installed
# @param package [String] package name
# @return [true,false]
def self.is_installed?(package)
installed_packages.key? package
end
end
module Network
# check if this url is accessible and gives success HTTP status
# @param url [String] the url to check
# @return [true,false]
def self.url_accessible?(url)
out = TestCommon::Cmd.run "curl --fail '#{url}' 1>/dev/null 2>/dev/null"
out.last == 0
end
# check is TCP connection can be open to this socket
# @param host [String] hostname of IP address
# @param port [String,Numeric] the port number to connect to
# @return [true,false]
def self.connection?(host, port)
begin
Timeout::timeout(5) do
sock = TCPSocket.open(host, port)
sock.close if sock
end
rescue
return false
end
true
end
# check id TCP connection is closed to this socket
# inversion on connection?
# @param host [String] hostname of IP address
# @param port [String,Numeric] the port number to connect to
# @return [true,false]
def self.no_connection?(host, port)
not connection?(host, port)
end
# get the list of names from the named iptables rules
# most likely created by Puppet
# @return [Array<String>] the list of rule names
def self.iptables_rules
return @iptables_rules if @iptables_rules
output, code = TestCommon::Cmd.run 'iptables-save'
return unless code == 0
comments = []
output.split("\n").each do |line|
line =~ %r(--comment\s+"(.*?)")
next unless $1
comment = $1.chomp.strip.gsub /^\d+\s+/, ''
comment.gsub! /\sfrom\s\d+\.\d+\.\d+\.\d+\/\d+/, ''
comments << comment
end
@iptables_rules = comments
end
# get the list of ip addresses found on this system's interfaces
# @return [Array<String>] the list of addresses
def self.ips
return @ips if @ips
ip_out, code = TestCommon::Cmd.run 'ip -4 -o a'
return unless code == 0
ips = []
ip_out.split("\n").each do |line|
if line =~ /\s+inet\s+([\d\.]*)/
ips << $1
end
end
@ips = ips
end
# get this systems default router
# @return [String] the default router ip
def self.default_router
return @default_router if @default_router
routes, code = TestCommon::Cmd.run 'ip route'
return unless code == 0
routes.split("\n").each do |line|
if line =~ /^default via ([\d\.]*)/
return @default_router = $1
end
end
nil
end
# try to ping this host and return success
# @param host [String] the hostname or the ip address to ping
# @return [true,false]
def self.ping?(host)
begin
out = Timeout::timeout(5) do
TestCommon::Cmd.run "ping -q -c 1 -W 3 '#{host}'"
end
rescue
return false
end
out.last == 0
end
# reset mnemoization
def self.reset
@iptables_rules = nil
@ips = nil
@default_router = nil
end
end
module AMQP
# use python's kombu library to check is connection
# to AMQP server is possible with this credentials
# python's library is used because it's installed everywhere
# and ruby's library is not
# @param [String] user
# @param [String] password
# @param [String] host
# @param [String,Numeric] port
# @param [String] vhost
# @param [String] protocol
# @return [true,false]
def self.connection?(
user=Settings.rabbit['user'],
password=Settings.rabbit['password'],
host='localhost',
port='5673',
vhost='/',
protocol='amqp')
url = "#{protocol}://#{user}:#{password}@#{host}:#{port}/#{vhost}"
python = <<-eof
import sys
import kombu
connected = False
try:
connection = kombu.Connection("#{url}")
connection.connect()
connected = connection.connected
connection.close()
connection.release()
except Exception as e:
sys.stdout.write("AMQP error: %s\\n" % e)
if connected:
sys.exit(0)
else:
sys.exit(1)
eof
system "python -c '#{python}'"
$?.exitstatus == 0
end
end
module Config
# parse the ini-style config file
# 'section/key' => 'value'
# @param [String] file path to the file
# @return [Hash<String => String>]
def self.ini_file(file)
content = File.read file
data = {}
return data unless content
section = 'default'
content.split("\n").each do |line|
line = line.strip
next if line.start_with? '#'
next if line == ''
if line =~ /\[(\S+)\]/
section = $1.downcase
elsif line =~ /(\S+)\s*=\s*(.*)/
data["#{section}/#{$1.downcase}"] = $2
end
end
data
end
# check if this ini-style config file hash a value
# @param [String] file path to the file
# @param [String] key section/key of the param
# @param [String] value the value of the param
# @return [true,false]
def self.value?(file, key, value)
key = key.downcase
key = 'default/' + key unless key.include? '/'
data = ini_file file
return !data.key?(key) if value.nil?
value = value.to_s
value.capitalize! if %w(true false).include? value
data[key] == value
end
# check if this file contains either a string or a regexp
# @param file [String] path to the file
# @param line [String, Regexp] look for this string or regexp
# @return [true,false]
def self.has_line?(file, line)
content = File.read file
if line.is_a? String
content.include? line
elsif line.is_a? Regexp
not (content =~ line).nil?
else
raise 'Line should be a string or a regexp!'
end
end
end
module Cron
# check if cronjob exists, ignores comments
# @param user [String] usernam to check cron for
# @param cronjob [String, Regexp] pattern look for in cron
# @return [true,false]
def self.cronjob_exists?(user, cronjob)
cmd = "crontab -u #{user} -l"
out = TestCommon::Cmd.run cmd
false unless out.last == 0
out.first[/^\s*[^#]*#{cronjob}/].nil? == false
end
end
end

View File

@ -1,26 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
TOOLS = %w(
acpid
screen
tmux
man
htop
tcpdump
strace
atop
puppet-pull
)
class ToolsPostTest < Test::Unit::TestCase
def self.create_tests
TOOLS.each do |tool|
method_name = "test_tool_#{tool}_present"
define_method method_name do
assert TestCommon::Process.command_present?(tool), "There is no '#{tool}' installed!"
end
end
end
end
ToolsPostTest.create_tests

View File

@ -1,14 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class PublicVipPingPostTest < Test::Unit::TestCase
def ubuntu?
TestCommon::Facts.operatingsystem == 'Ubuntu'
end
def test_contrack_resource_started
return unless ubuntu?
assert TestCommon::Pacemaker.primitive_present?('p_conntrackd'), 'p_conntrackd is not created!'
end
end

View File

@ -1,9 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class ContrackdPreTest < Test::Unit::TestCase
def test_pacemaker_is_online
assert TestCommon::Pacemaker.online?, 'Could not query Pacemaker CIB!'
end
end

View File

@ -1,20 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class PublicVipPingPostTest < Test::Unit::TestCase
def has_public?
TestCommon::Settings.lookup 'public_vip'
end
def test_ping_resource_started
return unless has_public?
assert TestCommon::Pacemaker.primitive_started?('ping_vip__public'), 'ping_vip__public is not started!'
end
def test_paceamaker_public_vips
return unless has_public?
assert TestCommon::Pacemaker.primitive_started?('vip__public'), 'vip__public Pacemaker service is not started!'
assert TestCommon::Pacemaker.primitive_started?('vip__vrouter_pub'), 'vip__vrouter_pub Pacemaker service is not started!'
end
end

View File

@ -1,13 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class PublicVipPingPreTest < Test::Unit::TestCase
def test_pacemaker_is_online
assert TestCommon::Pacemaker.online?, 'Could not query Pacemaker CIB!'
end
def test_hiera_data
assert TestCommon::Settings.lookup('network_scheme'), 'No network_scheme in Hiera!'
end
end

View File

@ -1,52 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class VirtualIPsPostTest < Test::Unit::TestCase
def has_public?
TestCommon::Settings.lookup 'public_vip'
end
def test_can_ping_the_default_router
ip = TestCommon::Network.default_router
assert TestCommon::Network.ping?(ip), "Cannot ping the default router '#{ip}'!"
end
def test_public_vip_ping
return unless has_public?
ip = TestCommon::Settings.public_vip
assert TestCommon::Network.ping?(ip), "Could not ping the public vip '#{ip}'!"
end
def test_public_vrouter_vip_ping
return unless has_public?
ip = TestCommon::Settings.public_vrouter_vip
assert TestCommon::Network.ping?(ip), "Could not ping the public vrouter vip '#{ip}'!"
end
def test_management_vip_ping
ip = TestCommon::Settings.management_vip
assert TestCommon::Network.ping?(ip), "Could not ping the management vip '#{ip}'!"
end
def test_management_vrouter_vip_ping
ip = TestCommon::Settings.management_vrouter_vip
assert TestCommon::Network.ping?(ip), "Could not ping the management vrouter vip '#{ip}'!"
end
def test_vip_ocf_present
file = '/usr/lib/ocf/resource.d/fuel/ns_IPaddr2'
assert File.exist?(file), 'VIP OCF file is missing!'
end
def test_paceamaker_management_vips
assert TestCommon::Pacemaker.primitive_started?('vip__management'), 'vip__management Pacemaker service is not started!'
assert TestCommon::Pacemaker.primitive_started?('vip__management_vrouter'), 'vip__management_vrouter Pacemaker service is not started!'
end
def test_paceamaker_public_vips
return unless has_public?
assert TestCommon::Pacemaker.primitive_started?('vip__public'), 'vip__public Pacemaker service is not started!'
assert TestCommon::Pacemaker.primitive_started?('vip__vrouter_pub'), 'vip__vrouter_pub Pacemaker service is not started!'
end
end

View File

@ -1,18 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class VirtualIpsPrePreTest < Test::Unit::TestCase
def test_pacemaker_is_online
assert TestCommon::Pacemaker.online?, 'Could not query Pacemaker CIB!'
end
def test_hiera_data
assert TestCommon::Settings.lookup('management_vip'), 'No management_vip in Hiera!'
assert TestCommon::Settings.lookup('management_vrouter_vip'), 'No management_vrouter_vip in Hiera!'
if TestCommon::Settings.lookup 'public_int'
assert TestCommon::Settings.lookup('public_vip'), 'No public_vip in Hiera!'
assert TestCommon::Settings.lookup('public_vrouter_vip'), 'No public_vrouter_vip in Hiera!'
end
end
end

View File

@ -1,9 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class CinderVmwarePostTest < Test::Unit::TestCase
def test_process
assert TestCommon::Process.running?('/etc/cinder/cinder.d/vmware'), 'Process cinder-volume --config /etc/cinder/cinder.d/vmware-N.conf is not running!'
end
end

View File

@ -1,12 +0,0 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
class CinderVmwarePreTest < Test::Unit::TestCase
def test_roles_present
roles = TestCommon::Settings.roles
assert roles, 'Could not get the roles data!'
assert roles.is_a?(Array), 'Incorrect roles data!'
assert roles.find_index('cinder-vmware'), 'Wrong role for this node!'
end
end