Refactor pre/post modular tests

* Use common library for tests

Related blueprint: fuel-library-modularization
Fuel-CI: disable

Change-Id: I8769748ae79d5a1597eb0f320e0a0ed9581d5a0b
This commit is contained in:
Dmitry Ilyin
2015-03-18 18:39:40 +03:00
parent a636c680e3
commit 4296519bf6
46 changed files with 1297 additions and 1532 deletions

View File

@@ -0,0 +1,2 @@
--color
-f doc

View File

@@ -1,23 +1,8 @@
require 'test/unit'
require 'socket'
def test_connection(host, port)
begin
s = TCPSocket.open(host, port)
s.close
rescue
return false
end
true
end
def api_proxy_online?
test_connection('localhost', '8888')
end
require File.join File.dirname(__FILE__), '../test_common.rb'
class ApiProxyPostTest < Test::Unit::TestCase
def test_api_proxy_online
assert api_proxy_online?, 'Can not connect to API proxy!'
assert TestCommon::Network.connection?('localhost', 8888), 'Cannot connect to API proxy!'
end
end

View File

@@ -1,71 +1,11 @@
require 'test/unit'
require 'socket'
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
def test_connection(host, port)
begin
s = TCPSocket.open(host, port)
s.close
rescue
return false
end
true
end
def radosgw_backend_online?
test_connection('localhost', '6780')
end
PROCESSES = %w(
radosgw
)
require File.join File.dirname(__FILE__), '../test_common.rb'
class RadosgwPostTest < Test::Unit::TestCase
def self.create_tests
PROCESSES.each do |process|
method_name = "test_iprocess_#{process}_running"
define_method method_name do
assert process_tree.find { |pid, proc| proc[:cmd].include? process }, "Process '#{process}' is not running!"
end
end
def test_radosgw_process_running
assert TestCommon::Process.running?('radosgw'), 'Radosgw process is not running!'
end
def test_radosgw_backend_online
assert radosgw_backend_online?, 'Can not connect to radoswg on this host!'
assert TestCommon::Network.connection?('localhost', 6780), 'Can not connect to radoswg port 6780 on this host!'
end
end
RadosgwPostTest.create_tests

View File

@@ -1,63 +1,7 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
require 'socket'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def management_vip
return $management_vip if $management_vip
$management_vip = hiera.lookup 'management_vip', nil, {}
end
def hostname
return $hostname if $hostname
$hostname = Socket.gethostname.split('.').first
end
def controller_node_address
return $controller_node_address if $controller_node_address
$controller_node_address = hiera.lookup 'controller_node_address', nil, {}
end
def haproxy_stats_url
ip = management_vip
ip = controller_node_address unless ip
raise 'Could not get internal address!' unless ip
port = 10000
"http://#{ip}:#{port}/;csv"
end
def csv
return $csv if $csv
begin
url = open(haproxy_stats_url)
csv = url.read
rescue
nil
end
return nil unless csv and not csv.empty?
$csv = csv
end
def keystone_backends_online?
raise 'Could not get CSV from HAProxy stats!' unless csv
status = false
csv.split("\n").each do |line|
next unless line.start_with? 'keystone-1'
next unless line.include? 'BACKEND'
puts "DEBUG: #{line}"
fields = line.split(',')
status ||= fields[17].eql? 'UP'
end
status
end
require File.join File.dirname(__FILE__), '../test_common.rb'
class RadosgwPreTest < Test::Unit::TestCase
def test_keystone_backends_are_online
assert keystone_backends_online?, 'Haproxy keystone backend is down!'
def test_keystone_backend_online
assert TestCommon::HAProxy.backend_up?('keystone-1'), 'Haproxy keystone backend is down!'
end
end

View File

@@ -1,67 +1,4 @@
require 'hiera'
require 'test/unit'
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def management_vip
return $management_vip if $management_vip
$management_vip = hiera.lookup 'management_vip', nil, {}
end
def controller_node_address
return $controller_node_address if $controller_node_address
$controller_node_address = hiera.lookup 'controller_node_address', nil, {}
end
def haproxy_stats_url
ip = management_vip
ip = controller_node_address unless ip
raise 'Could not get internal address!' unless ip
port = 10000
"http://#{ip}:#{port}/;csv"
end
def url_accessible?(url)
`curl --fail '#{url}' 1>/dev/null 2>/dev/null`
$?.exitstatus == 0
end
require File.join File.dirname(__FILE__), '../test_common.rb'
class ClusterHaproxyPostTest < Test::Unit::TestCase
def test_haproxy_config_present
@@ -69,10 +6,11 @@ class ClusterHaproxyPostTest < Test::Unit::TestCase
end
def test_haproxy_is_running
assert process_tree.find { |pid, proc| proc[:cmd].include? '/usr/sbin/haproxy' }, 'Haproxy is not running!'
assert TestCommon::Process.running?('/usr/sbin/haproxy'), 'Haproxy is not running!'
end
def test_haproxy_stats_accessible
assert url_accessible?(haproxy_stats_url), "Cannot connect to the HAProxy stats url '#{haproxy_stats_url}'!"
url = TestCommon::HAProxy.stats_url
assert TestCommon::Network.url_accessible?(url), "Cannot connect to the HAProxy stats url '#{url}'!"
end
end

View File

@@ -1,44 +1,4 @@
require 'hiera'
require 'test/unit'
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
def pacemaker_online?
`timeout 5 cibadmin -Q`
$?.exitstatus == 0
end
require File.join File.dirname(__FILE__), '../test_common.rb'
PROCESSES = %w(
crmd
@@ -54,15 +14,15 @@ corosync
class ClusterPostTest < Test::Unit::TestCase
def self.create_tests
PROCESSES.each do |process|
method_name = "test_iprocess_#{process}_running"
method_name = "test_process_#{process}_running"
define_method method_name do
assert process_tree.find { |pid, proc| proc[:cmd].include? process }, "Process '#{process}' is not running!"
assert TestCommon::Process.running?(process), "Process '#{process}' is not running!"
end
end
end
def test_pacemaker_is_online
assert pacemaker_online?, 'Could not query Pacemaker CIB!'
assert TestCommon::Pacemaker.online?, 'Could not query Pacemaker CIB!'
end
end

View File

@@ -1,110 +1,81 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
include TestCommon
BACKEND = 'mysqld'
PROCESS = 'mysqld_safe'
PRIMITIVE = 'p_mysql'
if Facts.osfamily == 'RedHat'
PACKAGES = %w(
MySQL-server-wsrep
MySQL-client-wsrep
MySQL-shared
mysql-libs
)
elsif Facts.osfamily == 'Debian'
PACKAGES = %w(
mysql-wsrep-common-5.6
mysql-server-wsrep-core-5.6
mysql-server-wsrep-5.6
mysql-common
mysql-client-core-5.6
mysql-client-5.6
libmysqlclient18
)
else
PACKAGES = []
end
class DatabaseInstallPostTest < Test::Unit::TestCase
def test_packages_are_installed
return unless PACKAGES
PACKAGES.each do |package|
assert Package.is_installed?(package), "Package '#{package}' is not installed!"
end
end
def test_mysqld_safe_is_running
assert PS.running?(PROCESS), "Process '#{PROCESS}' is not running!"
assert TestCommon::Process.running?(PROCESS), "Process '#{PROCESS}' is not running!"
end
def test_mysql_primitive_running
assert Pacemaker.primitive_started?(PRIMITIVE), "Primitive '#{PRIMITIVE}' is not started!"
assert TestCommon::Pacemaker.primitive_started?(PRIMITIVE), "Primitive '#{PRIMITIVE}' is not started!"
end
def test_mysqld_haproxy_backend_up
assert HAProxy.backend_up?(BACKEND), "HAProxy backend '#{BACKEND}' is not up!"
assert TestCommon::HAProxy.backend_up?(BACKEND), "HAProxy backend '#{BACKEND}' is not up!"
end
def test_mysql_connection_without_auth
MySQL.no_auth
assert MySQL.connection?, 'Cannot connect to MySQL without auth!'
TestCommon::MySQL.no_auth
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL without auth!'
end
def test_mysql_connection_with_auth
MySQL.pass = Settings.mysql['root_password']
MySQL.user = 'root'
MySQL.host = 'localhost'
MySQL.port = 3306
assert MySQL.connection?, 'Cannot connect to MySQL 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
MySQL.pass = Settings.keystone['db_password']
MySQL.user = 'keystone'
MySQL.host = Settings.management_vip
MySQL.port = 3306
assert MySQL.connection?, 'Cannot connect to MySQL with Keystone auth!'
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
MySQL.pass = Settings.glance['db_password']
MySQL.user = 'glance'
MySQL.host = Settings.management_vip
MySQL.port = 3306
assert MySQL.connection?, 'Cannot connect to MySQL with Glance auth!'
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
MySQL.pass = Settings.nova['db_password']
MySQL.user = 'nova'
MySQL.host = Settings.management_vip
MySQL.port = 3306
assert MySQL.connection?, 'Cannot connect to MySQL with Nova auth!'
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
MySQL.pass = Settings.cinder['db_password']
MySQL.user = 'cinder'
MySQL.host = Settings.management_vip
MySQL.port = 3306
assert MySQL.connection?, 'Cannot connect to MySQL with Cinder auth!'
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 Settings.use_neutron
MySQL.pass = Settings.cinder['db_password']
MySQL.user = 'cinder'
MySQL.host = Settings.management_vip
MySQL.port = 3306
assert MySQL.connection?, 'Cannot connect to MySQL with Cinder auth!'
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://#{Settings.internal_address}:#{check_port}"
assert Net.url_accessible?(url), 'Cannot connect to the MySQL Checker URL!'
url = "http://#{TestCommon::Settings.internal_address}:#{check_port}"
assert TestCommon::Network.url_accessible?(url), 'Cannot connect to the MySQL Checker URL!'
end
end

View File

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

View File

@@ -1,20 +1,4 @@
require 'hiera'
require 'test/unit'
def iptables
return $iptables if $iptables
output = `iptables-save`
code = $?.exitstatus
return unless code == 0
comments = []
output.split("\n").each do |line|
line =~ /--comment\s+"(.*?)"/
next unless $1
comment = $1.chomp.strip.gsub /^\d+\s+/, ''
comments << comment
end
$iptables = comments
end
require File.join File.dirname(__FILE__), '../test_common.rb'
RULES = [
'accept all to lo interface',
@@ -55,7 +39,7 @@ class FirewallPostTest < Test::Unit::TestCase
RULES.each do |rule|
method_name = "test_iptables_have_rule_#{rule.gsub ' ', '_'}"
define_method method_name do
assert iptables.include?(rule), "Iptables don't have the '#{rule}' rule!'"
assert TestCommon::Network.iptables_rules.include?(rule), "Iptables don't have the '#{rule}' rule!'"
end
end
end

View File

@@ -1,14 +0,0 @@
import subprocess
import unittest
class FirewallPreTest(unittest.TestCase):
def test_iptables_installed(self):
hiera = subprocess.Popen(['which', 'iptables'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
hiera.communicate()
self.assertEqual(hiera.returncode, 0, 'Iptables not installed!')
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,7 @@
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

@@ -8,6 +8,6 @@
puppet_modules: /etc/puppet/modules
timeout: 3600
test_pre:
cmd: python /etc/puppet/modules/osnailyfacter/modular/firewall/firewall_pre.py
cmd: ruby /etc/puppet/modules/osnailyfacter/modular/firewall/firewall_pre.rb
test_post:
cmd: ruby /etc/puppet/modules/osnailyfacter/modular/firewall/firewall_post.rb

View File

@@ -1,31 +1,30 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
include TestCommon
PORT = 9292
class GlancePostTest < Test::Unit::TestCase
def test_glance_api_is_running
assert PS.running?('/usr/bin/glance-api'), 'Glance API is not running!'
assert TestCommon::Process.running?('/usr/bin/glance-api'), 'Glance API is not running!'
end
def test_glance_gistry_is_running
assert PS.running?('/usr/bin/glance-registry'), 'Glance Registry is not running!'
assert TestCommon::Process.running?('/usr/bin/glance-registry'), 'Glance Registry is not running!'
end
def test_glance_public_url_accessible
url = "http://#{Settings.public_vip}:#{PORT}"
assert Net.url_accessible?(url), "Public Glance URL '#{url}' is not accessible!"
url = "http://#{TestCommon::Settings.public_vip}:#{PORT}"
assert TestCommon::Network.url_accessible?(url), "Public Glance URL '#{url}' is not accessible!"
end
def test_glance_admin_url_accessible
url = "http://#{Settings.management_vip}:#{PORT}"
assert Net.url_accessible?(url), "Management Glance URL '#{url}' is not accessible!"
url = "http://#{TestCommon::Settings.management_vip}:#{PORT}"
assert TestCommon::Network.url_accessible?(url), "Management Glance URL '#{url}' is not accessible!"
end
def test_keystone_endpoint_list_run
cmd = 'source /root/openrc && glance image-list'
assert PS.run_successful?(cmd), "Could not run '#{cmd}'!"
assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!"
end
end

View File

@@ -1,28 +1,24 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
include TestCommon
BACKEND = 'glance-api'
class GlancePreTest < Test::Unit::TestCase
def test_haproxy_glance_backend_present
assert HAProxy.backend_present?(BACKEND), "There is no '#{BACKEND}' HAProxy backend!"
assert TestCommon::HAProxy.backend_present?(BACKEND), "There is no '#{BACKEND}' HAProxy backend!"
end
def test_mysql_accessible_for_glance
MySQL.pass = Settings.glance['db_password']
MySQL.user = 'glance'
MySQL.host = Settings.management_vip
MySQL.port = 3306
MySQL.db = 'glance'
assert MySQL.connection?, 'Cannot connect to MySQL with Glance auth!'
TestCommon::MySQL.pass = TestCommon::Settings.glance['db_password']
TestCommon::MySQL.user = 'glance'
TestCommon::MySQL.host = TestCommon::Settings.management_vip
TestCommon::MySQL.port = 3306
TestCommon::MySQL.db = 'glance'
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL with Glance auth!'
end
def test_amqp_accessible
user = Settings.rabbit['user']
password = Settings.rabbit['password']
host = Settings.management_vip
assert AMQP.connection?(user, password, host), 'Cannot connect to AMQP server!'
assert TestCommon::AMQP.connection?, 'Cannot connect to AMQP server!'
end
end

View File

@@ -1,43 +1,71 @@
require 'test/unit'
require File.join File.dirname(__FILE__), '../test_common.rb'
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.split("\n").each do |p|
f = p.split
pid = f.shift.to_i
ppid = f.shift.to_i
cmd = f.join ' '
PROCESSES = %w(
heat-api
heat-api-cfn
heat-api-cloudwatch
heat-engine
)
# create entry for this pid if not present
$process_tree[pid] = {
:children => []
} unless $process_tree.key? pid
BACKENDS = %w(
heat-api
heat-api-cfn
heat-api-cloudwatch
)
# fill this entry
$process_tree[pid][:ppid] = ppid
$process_tree[pid][:pid] = pid
$process_tree[pid][:cmd] = cmd
HOSTS = {
'public' => TestCommon::Settings.public_vip,
'management' => TestCommon::Settings.management_vip,
}
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
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 = "http://#{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', ''), 'trusts_delegated_roles is not 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
def test_heat_is_running
assert process_tree.find { |pid, proc| proc[:cmd].include? 'heat' }, 'Heat is not running!'
end
end
HeatPostTest.create_tests

View File

@@ -1,11 +1,17 @@
require 'test/unit'
require File.join File.dirname(__FILE__), '../test_common.rb'
class HeatPostTest < Test::Unit::TestCase
def test_rabbitmq_available
#TODO
def test_mysql_connection_without_auth
TestCommon::MySQL.no_auth
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL without auth!'
end
def test_mysql_available
#TODO
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,64 +1,8 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
require 'socket'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def management_vip
return $management_vip if $management_vip
$management_vip = hiera.lookup 'management_vip', nil, {}
end
def hostname
return $hostname if $hostname
$hostname = Socket.gethostname.split('.').first
end
def controller_node_address
return $controller_node_address if $controller_node_address
$controller_node_address = hiera.lookup 'controller_node_address', nil, {}
end
def haproxy_stats_url
ip = management_vip
ip = controller_node_address unless ip
raise 'Could not get internal address!' unless ip
port = 10000
"http://#{ip}:#{port}/;csv"
end
def csv
return $csv if $csv
begin
url = open(haproxy_stats_url)
csv = url.read
rescue
nil
end
return nil unless csv and not csv.empty?
$csv = csv
end
def horizon_backend_online?
raise 'Could not get CSV from HAProxy stats!' unless csv
status = 'DOWN'
csv.split("\n").each do |line|
next unless line.start_with? 'horizon'
next unless line.include? hostname
puts "DEBUG: #{line}"
fields = line.split(',')
status = fields[17]
end
status == 'UP'
end
require File.join File.dirname(__FILE__), '../test_common.rb'
class HorizonPostTest < Test::Unit::TestCase
def test_horizon_backend_online
assert horizon_backend_online?, 'Haproxy horizon backend is down on this node!'
assert TestCommon::HAProxy.backend_up?('horizon'), 'Haproxy horizon backend is not online!'
end
end

View File

@@ -1,104 +1,12 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
require 'socket'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def management_vip
return $management_vip if $management_vip
$management_vip = hiera.lookup 'management_vip', nil, {}
end
def hostname
return $hostname if $hostname
$hostname = Socket.gethostname.split('.').first
end
def controller_node_address
return $controller_node_address if $controller_node_address
$controller_node_address = hiera.lookup 'controller_node_address', nil, {}
end
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
def haproxy_stats_url
ip = management_vip
ip = controller_node_address unless ip
raise 'Could not get internal address!' unless ip
port = 10000
"http://#{ip}:#{port}/;csv"
end
def csv
return $csv if $csv
begin
url = open(haproxy_stats_url)
csv = url.read
rescue
nil
end
return nil unless csv and not csv.empty?
$csv = csv
end
def is_memcached_accessible?
# TODO: write test to check connectivity to memcached port on localhost
true
end
PROCESSES = %w(
memcached
)
require File.join File.dirname(__FILE__), '../test_common.rb'
class HorizonPreTest < Test::Unit::TestCase
def self.create_tests
PROCESSES.each do |process|
method_name = "test_iprocess_#{process}_running"
define_method method_name do
assert process_tree.find { |pid, proc| proc[:cmd].include? process }, "Process '#{process}' is not running!"
end
end
def test_memcached_is_running
assert TestCommon::Process.running?('memcached'), 'Memcached is not running!'
end
def test_memcached_is_accessible
assert is_memcached_accessible?, 'Memcached is not accessible!'
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
HorizonPreTest.create_tests

View File

@@ -1,11 +1,9 @@
require 'hiera'
require 'test/unit'
require File.join File.dirname(__FILE__), '../test_common.rb'
class HostsPostTest < Test::Unit::TestCase
def test_hosts_file_has_all_nodes
hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
nodes_array = hiera.lookup 'nodes', nil, {}
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|

View File

@@ -1,18 +1,15 @@
require 'hiera'
require 'test/unit'
require File.join File.dirname(__FILE__), '../test_common.rb'
class HostsPreTest < Test::Unit::TestCase
def test_hiera_has_nodes_data
hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
nodes_array = hiera.lookup 'nodes', nil, {}
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
hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
nodes_array = hiera.lookup 'nodes', nil, {}
nodes_array = TestCommon::Settings.nodes
nodes_array.each do |node|
error = "Node #{node.inspect} is not correct!"

View File

@@ -1,44 +1,27 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
include TestCommon
PUBLIC_PORT = 5000
ADMIN_PORT = 35357
if Facts.osfamily == 'RedHat'
PACKAGES = %w(
openstack-keystone
python-keystoneclient
python-keystonemiddleware
python-keystone
)
end
class KeystonePostTest < Test::Unit::TestCase
def test_packages_are_installed
return unless PACKAGES
PACKAGES.each do |package|
assert Package.is_installed?(package), "Package '#{package}' is not installed!"
end
end
def test_keystone_is_running
assert PS.running?('/usr/bin/keystone-all'), 'Keystone is not running!'
assert TestCommon::Process.running?('/usr/bin/keystone-all'), 'Keystone is not running!'
end
def test_keystone_public_url_accessible
url = "http://#{Settings.public_vip}:#{PUBLIC_PORT}"
assert Net.url_accessible?(url), "Public Keystone URL '#{url}' is not accessible!"
url = "http://#{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://#{Settings.management_vip}:#{ADMIN_PORT}"
assert Net.url_accessible?(url), "Admin Keystone URL '#{url}' is not 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
cmd = 'source /root/openrc && keystone endpoint-list'
assert PS.run_successful?(cmd), "Could not run '#{cmd}'!"
assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!"
end
def test_openrc_file_present

View File

@@ -1,5 +1,4 @@
require File.join File.dirname(__FILE__), '../test_common.rb'
include TestCommon
PUBLIC_BACKEND = 'keystone-1'
ADMIN_BACKEND = 'keystone-2'
@@ -7,27 +6,24 @@ ADMIN_BACKEND = 'keystone-2'
class KeystonePreTest < Test::Unit::TestCase
def test_haproxy_public_backend_present
assert HAProxy.backend_present?(PUBLIC_BACKEND), "There is no '#{PUBLIC_BACKEND}' HAProxy backend!"
assert TestCommon::HAProxy.backend_present?(PUBLIC_BACKEND), "There is no '#{PUBLIC_BACKEND}' HAProxy backend!"
end
def test_haproxy_admin_backend_present
assert HAProxy.backend_present?(ADMIN_BACKEND), "There is no '#{ADMIN_BACKEND}' HAProxy backend!"
assert TestCommon::HAProxy.backend_present?(ADMIN_BACKEND), "There is no '#{ADMIN_BACKEND}' HAProxy backend!"
end
def test_mysql_accessible_for_keystone
MySQL.pass = Settings.keystone['db_password']
MySQL.user = 'keystone'
MySQL.host = Settings.management_vip
MySQL.port = 3306
MySQL.db = 'keystone'
assert MySQL.connection?, 'Cannot connect to MySQL with Keystone auth!'
TestCommon::MySQL.pass = TestCommon::Settings.keystone['db_password']
TestCommon::MySQL.user = 'keystone'
TestCommon::MySQL.host = TestCommon::Settings.management_vip
TestCommon::MySQL.port = 3306
TestCommon::MySQL.db = 'keystone'
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL with Keystone auth!'
end
def test_amqp_accessible
user = Settings.rabbit['user']
password = Settings.rabbit['password']
host = Settings.management_vip
assert AMQP.connection?(user, password, host), 'Cannot connect to AMQP server!'
assert TestCommon::AMQP.connection?, 'Cannot connect to AMQP server!'
end
end

View File

@@ -1,102 +1,17 @@
require 'hiera'
require 'test/unit'
require 'socket'
require 'timeout'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def internal_address
return $internal_address if $internal_address
$internal_address = hiera.lookup 'internal_address', nil, {}
end
def public_address
return $public_address if $public_address
$public_address = hiera.lookup 'public_address', nil, {}
end
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
def test_connection(host, port)
begin
Timeout::timeout( 3 ) do
s = TCPSocket.open(host, port)
s.close
end
rescue
raise Errno::ECONNREFUSED
end
true
end
def memcached_backend_online?
test_connection(internal_address, '11211')
end
def memcached_backend_listen_public?
test_connection(public_address, '11211')
end
PROCESSES = %w(
memcached
)
require File.join File.dirname(__FILE__), '../test_common.rb'
class MemcachedPostTest < Test::Unit::TestCase
def self.create_tests
PROCESSES.each do |process|
method_name = "test_iprocess_#{process}_running"
define_method method_name do
assert process_tree.find { |pid, proc| proc[:cmd].include? process }, "Process '#{process}' is not running!"
end
end
def test_memcached_is_running
assert TestCommon::Process.running?('memcached'), 'Memcached is not running!'
end
def test_memcached_backend_online
assert_nothing_raised do
assert memcached_backend_online?, 'Can not connect to memcached on this host!'
end
def test_memcached_on_internal
ip = TestCommon::Settings.internal_address
assert TestCommon::Network.connection?(ip, 11211), 'Cannot connect to memcached on the internal address!'
end
def test_memcached_backend_dont_listen_public
assert_raise Errno::ECONNREFUSED do
memcached_backend_listen_public?
end
def test_memcached_no_public
ip = TestCommon::Settings.public_address
assert TestCommon::Network.no_connection?(ip, 11211), 'Memcached should not be accessible from the public network!'
end
end
MemcachedPostTest.create_tests

View File

@@ -1,43 +1,28 @@
require 'test/unit'
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
require File.join File.dirname(__FILE__), '../test_common.rb'
class MuranoPostTest < Test::Unit::TestCase
def test_murano_is_running
assert process_tree.find { |pid, proc| proc[:cmd].include? 'murano' }, 'Murano is not 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'), '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
end

View File

@@ -1,15 +1,22 @@
require 'test/unit'
require File.join File.dirname(__FILE__), '../test_common.rb'
class MuranoPreTest < Test::Unit::TestCase
def test_rabbitmq_available
#TODO
def test_mysql_connection_without_auth
TestCommon::MySQL.no_auth
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL without auth!'
end
def test_mysql_available
#TODO
def test_amqp_accessible
assert TestCommon::AMQP.connection?, 'Cannot connect to AMQP server!'
end
def test_heat_available
#TODO
def test_haproxy_murano_backend_present
assert TestCommon::HAProxy.backend_present?('murano'), '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,88 +1,33 @@
require 'hiera'
require 'test/unit'
def ips
return $ips if $ips
ip_out = `ip addr`
return unless $?.exitstatus == 0
ips = []
ip_out.split("\n").each do |line|
if line =~ /\s+inet\s+([\d\.]*)/
ips << $1
end
end
$ips = ips
end
def router
return $router if $router
routes = `ip route`
return unless $?.exitstatus == 0
routes.split("\n").each do |line|
if line =~ /^default via ([\d\.]*)/
return $router = $1
end
end
nil
end
def ping(host)
`ping -q -c 1 -W 3 '#{host}'`
$?.exitstatus == 0
end
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def fqdn
return $fqdn if $fqdn
$fqdn = hiera.lookup 'fqdn', nil, {}
end
def nodes
return $nodes if $nodes
$nodes = hiera.lookup 'nodes', [], {}
end
def role
return $role if $role
$role = hiera.lookup 'role', nil, {}
end
def master_ip
return $master_ip if $master_ip
$master_ip = hiera.lookup 'master_ip', nil, {}
end
require File.join File.dirname(__FILE__), '../test_common.rb'
class NetconfigPostTest < Test::Unit::TestCase
def test_management_ip_present
ip = nodes.find { |node| node['fqdn'] == fqdn }['internal_address']
assert ips.include?(ip), 'Management address is not set!'
ip = TestCommon::Settings.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? role
ip = nodes.find { |node| node['fqdn'] == fqdn }['public_address']
assert ips.include?(ip), 'Public address is not set!'
if %w(controller primary-controller).include? TestCommon::Settings.role
ip = TestCommon::Settings.public_address
assert TestCommon::Network.ips.include?(ip), 'Public address is not set!'
end
end
def test_storage_ip_present
ip = nodes.find { |node| node['fqdn'] == fqdn }['storage_address']
assert ips.include?(ip), 'Storage address is not set!'
end
def test_can_ping_the_master_node
assert ping(master_ip), 'Cannot ping the master node!'
ip = TestCommon::Settings.storage_address
assert TestCommon::Network.ips.include?(ip), 'Storage address is not set!'
end
def test_can_ping_the_default_router_on_controller
if %w(controller primary-controller).include? role
assert ping(router), 'Cannot ping the default router!'
end
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
end

View File

@@ -1,19 +1,9 @@
require 'hiera'
require 'test/unit'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def nodes
return $nodes if $nodes
$nodes = hiera.lookup 'nodes', nil, {}
end
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!'

View File

@@ -1,66 +1,4 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def management_vip
return $management_vip if $management_vip
$management_vip = hiera.lookup 'management_vip', nil, {}
end
def controller_node_address
return $controller_node_address if $controller_node_address
$controller_node_address = hiera.lookup 'controller_node_address', nil, {}
end
def sahara_enabled?
return $sahara_enabled if $sahara_enabled
sahara = hiera.lookup 'sahara', {}, {}
$sahara_enabled = sahara.fetch 'enabled', false
end
def murano_enabled?
return $murano_enabled if $murano_enabled
murano = hiera.lookup 'murano', {}, {}
$murano_enabled = murano.fetch 'enabled', false
end
def haproxy_stats_url
ip = management_vip
ip = controller_node_address unless ip
raise 'Could not get internal address!' unless ip
port = 10000
"http://#{ip}:#{port}/;csv"
end
def csv
return $csv if $csv
begin
url = open(haproxy_stats_url)
csv = url.read
rescue
nil
end
return nil unless csv and not csv.empty?
$csv = csv
end
def haproxy_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'
backend = line.split(',').first
backends << backend
end
$backends = backends
end
require File.join File.dirname(__FILE__), '../test_common.rb'
def expected_backends
return $expected_backends if $expected_backends
@@ -83,8 +21,8 @@ def expected_backends
heat-api-cloudwatch
nova-novncproxy
)
backends += %w(sahara) if sahara_enabled?
backends += %w(murano murano_rabbitmq) if murano_enabled?
backends += %w(sahara) if TestCommon::Settings.sahara['enabled']
backends += %w(murano murano_rabbitmq) if TestCommon::Settings.murano['enabled']
$expected_backends = backends
end
@@ -93,7 +31,7 @@ class OpenstackHaproxyPostTest < Test::Unit::TestCase
expected_backends.each do |backend|
method_name = "test_backend_#{backend}_present"
define_method method_name do
assert haproxy_backends.include?(backend), "There is no '#{backend}' HAProxy backend!"
assert TestCommon::HAProxy.backend_present?(backend), "There is no '#{backend}' HAProxy backend!"
end
end
end

View File

@@ -1,43 +1,9 @@
require 'test/unit'
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
require File.join File.dirname(__FILE__), '../test_common.rb'
class OpenstackHaproxyPreTest < Test::Unit::TestCase
def test_haproxy_is_running
assert process_tree.find { |pid, proc| proc[:cmd].include? '/usr/sbin/haproxy' }, 'Haproxy is not running!'
assert TestCommon::Process.running?('haproxy'), 'Haproxy is not running!'
end
end

View File

@@ -1,62 +1,3 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
require 'socket'
require File.join File.dirname(__FILE__), '../test_common.rb'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
#TODO: test for neutron or nova-network processes depending
# on network provider.
PROCESSES = %w(
init
)
class OpenstackNetworkComputePostTest < Test::Unit::TestCase
def self.create_tests
PROCESSES.each do |process|
method_name = "test_iprocess_#{process}_running"
define_method method_name do
assert process_tree.find { |pid, proc| proc[:cmd].include? process }, "Process '#{process}' is not running!"
end
end
end
end
OpenstackNetworkComputePostTest.create_tests
#TODO: test for neutron or nova-network processes depending on network provider

View File

@@ -1,63 +1,8 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
require 'socket'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def management_vip
return $management_vip if $management_vip
$management_vip = hiera.lookup 'management_vip', nil, {}
end
def hostname
return $hostname if $hostname
$hostname = Socket.gethostname.split('.').first
end
def controller_node_address
return $controller_node_address if $controller_node_address
$controller_node_address = hiera.lookup 'controller_node_address', nil, {}
end
def haproxy_stats_url
ip = management_vip
ip = controller_node_address unless ip
raise 'Could not get internal address!' unless ip
port = 10000
"http://#{ip}:#{port}/;csv"
end
def csv
return $csv if $csv
begin
url = open(haproxy_stats_url)
csv = url.read
rescue
nil
end
return nil unless csv and not csv.empty?
$csv = csv
end
def keystone_backends_online?
raise 'Could not get CSV from HAProxy stats!' unless csv
status = false
csv.split("\n").each do |line|
next unless line.start_with? 'keystone'
next unless line.include? 'BACKEND'
puts "DEBUG: #{line}"
fields = line.split(',')
status ||= fields[17].eql? 'UP'
end
status
end
require File.join File.dirname(__FILE__), '../test_common.rb'
class OpenStackNetworkComputePreTest < Test::Unit::TestCase
def test_keystone_backends_are_online
assert keystone_backends_online?, 'Haproxy keystone backend is down!'
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,62 +1,3 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
require 'socket'
require File.join File.dirname(__FILE__), '../test_common.rb'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
#TODO: test for neutron or nova-network processes depending
# on network provider.
PROCESSES = %w(
init
)
class OpenstackNetworkControllerPostTest < Test::Unit::TestCase
def self.create_tests
PROCESSES.each do |process|
method_name = "test_iprocess_#{process}_running"
define_method method_name do
assert process_tree.find { |pid, proc| proc[:cmd].include? process }, "Process '#{process}' is not running!"
end
end
end
end
OpenstackNetworkControllerPostTest.create_tests
#TODO: test for neutron or nova-network processes depending on network provider

View File

@@ -1,63 +1,8 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
require 'socket'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def management_vip
return $management_vip if $management_vip
$management_vip = hiera.lookup 'management_vip', nil, {}
end
def hostname
return $hostname if $hostname
$hostname = Socket.gethostname.split('.').first
end
def controller_node_address
return $controller_node_address if $controller_node_address
$controller_node_address = hiera.lookup 'controller_node_address', nil, {}
end
def haproxy_stats_url
ip = management_vip
ip = controller_node_address unless ip
raise 'Could not get internal address!' unless ip
port = 10000
"http://#{ip}:#{port}/;csv"
end
def csv
return $csv if $csv
begin
url = open(haproxy_stats_url)
csv = url.read
rescue
nil
end
return nil unless csv and not csv.empty?
$csv = csv
end
def keystone_backends_online?
raise 'Could not get CSV from HAProxy stats!' unless csv
status = false
csv.split("\n").each do |line|
next unless line.start_with? 'keystone'
next unless line.include? 'BACKEND'
puts "DEBUG: #{line}"
fields = line.split(',')
status ||= fields[17].eql? 'UP'
end
status
end
require File.join File.dirname(__FILE__), '../test_common.rb'
class OpenStackNetworkControllerPreTest < Test::Unit::TestCase
def test_keystone_backends_are_online
assert keystone_backends_online?, 'Haproxy keystone backend is down!'
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

@@ -0,0 +1,91 @@
# 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,43 +1,13 @@
require 'test/unit'
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
require File.join File.dirname(__FILE__), '../test_common.rb'
class SaharaPostTest < Test::Unit::TestCase
def test_sahara_is_running
assert process_tree.find { |pid, proc| proc[:cmd].include? 'sahara' }, 'Sahara is not running!'
assert TestCommon::Process.running?('sahara-all'), 'Sahara-all 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,11 +1,22 @@
require 'test/unit'
require File.join File.dirname(__FILE__), '../test_common.rb'
class SaharaPreTest < Test::Unit::TestCase
def test_rabbitmq_available
#TODO
def test_mysql_connection_without_auth
TestCommon::MySQL.no_auth
assert TestCommon::MySQL.connection?, 'Cannot connect to MySQL without auth!'
end
def test_mysql_available
#TODO
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 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

@@ -0,0 +1,5 @@
RSpec.configure do |config|
config.mock_with :rspec do |c|
c.syntax = :expect
end
end

View File

@@ -0,0 +1,535 @@
require 'spec_helper'
require File.join File.dirname(__FILE__), '../test_common.rb'
describe TestCommon do
context TestCommon::Settings do
before :each do
allow(subject.hiera).to receive(:lookup).with('id', nil, {}).and_return('1')
end
it 'can get the hiera object' do
expect(subject.hiera).to be_a Hiera
end
it 'can lookup a settings value' do
expect(subject.lookup 'id').to eq('1')
end
it 'can lookup by index or method' do
expect(subject.id).to eq('1')
expect(subject['id']).to eq('1')
end
end
context TestCommon::HAProxy do
let :csv do
<<-eof
# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime,
Stats,FRONTEND,,,0,2,8000,479,3959708,1147775737,0,0,0,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,6,,,,0,11394,0,0,0,0,,0,8,11394,,,0,0,0,0,,,,,,,,
Stats,BACKEND,0,0,0,0,800,0,3959708,1147775737,0,0,,0,0,0,0,UP,0,0,0,,0,347258,0,,1,2,0,,0,,1,0,,0,,,,0,0,0,0,0,0,,,,,0,0,0,0,0,0,319035,,,0,0,0,2585,
horizon,FRONTEND,,,0,0,8000,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,3,0,,,,0,0,0,0,,,,0,0,0,0,0,0,,0,0,0,,,0,0,0,0,,,,,,,,
horizon,node-7,0,0,0,0,,0,0,0,,0,,0,0,0,0,DOWN,1,1,0,3,1,10,10,,1,3,1,,0,,2,0,,0,L4CON,,0,0,0,0,0,0,0,0,,,,0,0,,,,,-1,Connection refused,,0,0,0,0,
horizon,BACKEND,0,0,0,0,800,0,0,0,0,0,,0,0,0,0,DOWN,0,0,0,,1,10,10,,1,3,0,,0,,1,0,,0,,,,0,0,0,0,0,0,,,,,0,0,0,0,0,0,-1,,,0,0,0,0,
keystone-1,FRONTEND,,,0,1,8000,25,4200,22925,0,0,0,,,,,OPEN,,,,,,,,,1,4,0,,,,0,0,0,1,,,,0,0,25,0,0,0,,0,1,25,,,0,0,0,0,,,,,,,,
keystone-1,node-7,0,0,0,1,,25,4200,22925,,0,,0,0,0,0,UP,1,1,0,0,0,347258,0,,1,4,1,,25,,2,0,,1,L7OK,300,2,0,0,25,0,0,0,0,,,,0,0,,,,,332047,Multiple Choices,,0,0,1,1,
keystone-1,BACKEND,0,0,0,1,800,25,4200,22925,0,0,,0,0,0,0,UP,1,1,0,,0,347258,0,,1,4,0,,25,,1,0,,1,,,,0,0,25,0,0,0,,,,,0,0,0,0,0,0,332047,,,0,0,1,1,
keystone-2,FRONTEND,,,0,2,8000,135,31659,695738,0,0,0,,,,,OPEN,,,,,,,,,1,5,0,,,,0,0,0,4,,,,0,105,30,0,0,0,,0,4,135,,,0,0,0,0,,,,,,,,
keystone-2,node-7,0,0,0,1,,135,31659,695738,,0,,0,0,0,0,UP,1,1,0,0,0,347258,0,,1,5,1,,135,,2,0,,4,L7OK,300,3,0,105,30,0,0,0,0,,,,0,0,,,,,331832,Multiple Choices,,0,1,16,17,
keystone-2,BACKEND,0,0,0,1,800,135,31659,695738,0,0,,0,0,0,0,UP,1,1,0,,0,347258,0,,1,5,0,,135,,1,0,,4,,,,0,105,30,0,0,0,,,,,0,0,0,0,0,0,331832,,,0,1,16,17,
eof
end
let :backends do
{"Stats"=>"UP", "horizon"=>"DOWN", "keystone-1"=>"UP", "keystone-2"=>"UP"}
end
before :each do
allow(TestCommon::Settings.hiera).to receive(:lookup).with('management_vip', nil, {}).and_return('127.0.0.1')
allow(TestCommon::Settings.hiera).to receive(:lookup).with('controller_node_address', nil, {}).and_return('127.0.0.1')
allow(subject).to receive(:csv).and_return(csv)
end
it 'can get the HAProxy stats url' do
expect(subject.stats_url).to eq('http://127.0.0.1:10000/;csv')
end
it 'can parse stats csv' do
expect(subject.backends).to eq(backends)
end
it 'can chack if a backend exists' do
expect(subject.backend_present? 'horizon').to eq true
expect(subject.backend_present? 'MISSING').to eq false
end
it 'can chack if a backend is up' do
expect(subject.backend_up? 'horizon').to eq false
expect(subject.backend_up? 'keystone-1').to eq true
expect(subject.backend_up? 'MISSING').to eq false
end
end
context TestCommon::Process do
let(:full_ps) do
<<-eos
1 0 /bin/init
100 1 /usr/bin/python nova-api.py
101 100 /usr/bin/python nova-api.py
102 100 /usr/bin/python nova-api.py
103 100 /usr/bin/python nova-api.py
104 1 /usr/bin/python cinder-volume.py
105 104 /usr/sbin/tgtd
106 1 /usr/bin/python neutron.py
107 106 /usr/sbin/dnsmasq
108 1 /usr/sbin/apache2
109 1 /usr/bin/python keystone.py
eos
end
let(:short_ps) do
<<-eos
/bin/init
/usr/bin/python nova-api.py
/usr/bin/python nova-api.py
/usr/bin/python nova-api.py
/usr/bin/python nova-api.py
/usr/bin/python cinder-volume.py
/usr/sbin/tgtd
/usr/bin/python neutron.py
/usr/sbin/dnsmasq
/usr/sbin/apache2
/usr/bin/python keystone.py
eos
end
let(:pstree) do
{
1 => {
:children => [100, 104, 106, 108, 109],
:ppid => 0,
:pid => 1,
:cmd => "/bin/init"
},
104 => {
:children => [105],
:ppid => 1,
:cmd => "/usr/bin/python cinder-volume.py",
:pid => 104
},
105 => {
:children => [],
:ppid => 104,
:cmd => "/usr/sbin/tgtd",
:pid => 105
},
100 => {
:children => [101, 102, 103],
:ppid => 1,
:cmd => "/usr/bin/python nova-api.py",
:pid => 100
},
106 => {
:children => [107],
:ppid => 1,
:cmd => "/usr/bin/python neutron.py",
:pid => 106
},
101 => {
:children => [],
:ppid => 100,
:cmd => "/usr/bin/python nova-api.py",
:pid => 101
},
107 => {
:children => [],
:ppid => 106,
:cmd => "/usr/sbin/dnsmasq",
:pid => 107
},
102 => {
:children => [],
:ppid => 100,
:cmd => "/usr/bin/python nova-api.py",
:pid => 102
},
108 => {
:children => [],
:ppid => 1,
:cmd => "/usr/sbin/apache2",
:pid => 108
},
103 => {
:children => [],
:ppid => 100,
:cmd => "/usr/bin/python nova-api.py",
:pid => 103
},
109 => {
:children => [],
:ppid => 1,
:cmd => "/usr/bin/python keystone.py",
:pid => 109
}
}
end
let(:pslist) do
[
"/bin/init",
"/usr/bin/python nova-api.py",
"/usr/bin/python nova-api.py",
"/usr/bin/python nova-api.py",
"/usr/bin/python nova-api.py",
"/usr/bin/python cinder-volume.py",
"/usr/sbin/tgtd",
"/usr/bin/python neutron.py",
"/usr/sbin/dnsmasq",
"/usr/sbin/apache2",
"/usr/bin/python keystone.py"
]
end
before :each do
allow(TestCommon).to receive(:run_command).with('ps haxo cmd').and_return([short_ps, 0])
allow(TestCommon).to receive(:run_command).with('ps haxo pid,ppid,cmd').and_return([full_ps, 0])
end
it 'can check if command runs successfully' do
allow(TestCommon).to receive(:run_command).with('/bin/true').and_return(['', 0])
allow(TestCommon).to receive(:run_command).with('/bin/false').and_return(['', 1])
expect(subject.run_successful? '/bin/true').to eq true
expect(subject.run_successful? '/bin/false').to eq false
end
it 'can check if a command can be found' do
cmd = "which 'my_command' 1>/dev/null 2>/dev/null"
allow(TestCommon).to receive(:run_command).with(cmd).and_return(['', 0])
expect(subject.command_present? 'my_command').to eq true
allow(TestCommon).to receive(:run_command).with(cmd).and_return(['', 1])
expect(subject.command_present? 'my_command').to eq false
end
it 'can parse the process tree' do
expect(subject.tree).to eq(pstree)
end
it 'can get the process list' do
expect(subject.list).to eq(pslist)
end
it 'can find if a process is running' do
expect(subject.running? 'apache2').to eq true
expect(subject.running? 'nginx').to eq false
end
end
context TestCommon::MySQL do
let :databases do
<<-eof
mysql
test
nova
eof
end
it 'can form mysql queries without auth' do
subject.no_auth
cmd = %q(mysql --raw --skip-column-names --batch --execute='show databases')
expect(TestCommon).to receive(:run_command).with(cmd).and_return(['',0])
subject.query 'show databases'
end
it 'can form mysql queries with auth' do
subject.user = 'user'
subject.pass = 'pass'
subject.db = 'mydb'
subject.port = '123'
subject.host = 'myhost'
cmd = %q(mysql --raw --skip-column-names --batch --execute='show databases' --host='myhost' --user='user' --password='pass' --port='123' --database='mydb')
expect(TestCommon).to receive(:run_command).with(cmd).and_return(['',0])
subject.query 'show databases'
end
it 'can check is there is connection' do
allow(subject).to receive(:query).and_return(['',0])
expect(subject.connection?).to eq true
allow(subject).to receive(:query).and_return(['',1])
expect(subject.connection?).to eq false
end
it 'can get the list of databases' do
allow(subject).to receive(:query).and_return([databases,0])
expect(subject.databases).to eq(%w(mysql test nova))
subject.reset
allow(subject).to receive(:query).and_return([databases,1])
expect(subject.databases).to eq nil
end
it 'can determine if database exists' do
allow(subject).to receive(:query).and_return([databases,0])
expect(subject.database_exists? 'test').to eq true
expect(subject.database_exists? 'MISSING').to eq false
subject.reset
allow(subject).to receive(:query).and_return([databases,1])
expect(subject.database_exists? 'test').to eq nil
end
end
context TestCommon::Pacemaker do
let :crm_resource_l do
<<-eof
p_haproxy:0
p_dns:0
p_ntp:0
p_mysql:0
eof
end
it 'can check if pacemaker is online' do
allow(TestCommon).to receive(:run_command).with('cibadmin -Q').and_return(['',0])
expect(subject.online?).to eq true
allow(TestCommon).to receive(:run_command).with('cibadmin -Q').and_return(['',1])
expect(subject.online?).to eq false
end
it 'can get the list of the primitives' do
allow(TestCommon).to receive(:run_command).with('crm_resource -l').and_return([crm_resource_l,0])
expect(subject.primitives).to eq(%w(p_haproxy p_dns p_ntp p_mysql))
end
it 'can check if a primitive is present' do
allow(TestCommon).to receive(:run_command).with('crm_resource -l').and_return([crm_resource_l,0])
expect(subject.primitive_present? 'p_dns').to eq true
expect(subject.primitive_present? 'MISSING').to eq false
end
it 'can check if primitive is started' do
allow(TestCommon).to receive(:run_command).with('crm_resource -r p_haproxy -W 2>&1').and_return(['resource p_haproxy is running on: node-1',0])
expect(subject.primitive_started? 'clone_p_haproxy').to eq true
allow(TestCommon).to receive(:run_command).with('crm_resource -r p_haproxy -W 2>&1').and_return(['resource p_haproxy is NOT running',0])
expect(subject.primitive_started? 'clone_p_haproxy').to eq false
allow(TestCommon).to receive(:run_command).with('crm_resource -r MISSING -W 2>&1').and_return(['',1])
expect(subject.primitive_started? 'MISSING').to eq nil
end
end
context TestCommon::Facts do
before :each do
allow(Facter).to receive(:value).with('kernel').and_return('Linux')
end
it 'can get a facter value' do
expect(subject.value 'kernel').to eq 'Linux'
end
it 'can get a facter value by index or method' do
expect(subject['kernel']).to eq 'Linux'
expect(subject.kernel).to eq 'Linux'
end
end
context TestCommon::Package do
let(:deb_packages) do
<<-eos
mc|3:4.8.11-1|deinstall ok config-files
ipcalc|0.41-4|install ok installed
iproute|3.12.0-2|install ok installed
iptables|1.4.21-1ubuntu1|install ok installed
ntpdate|4.2.6.p5+dfsg-3ubuntu2|install ok installed
mc|3:4.8.11-1|install ok installed
eos
end
let(:deb_packages_list) do
{
"iptables"=>"1.4.21-1ubuntu1",
"iproute"=>"3.12.0-2",
"ipcalc"=>"0.41-4",
"ntpdate" =>"4.2.6.p5+dfsg-3ubuntu2",
"mc" => "3:4.8.11-1",
}
end
let(:rpm_packages) do
<<-eos
iproute|2.6.32-130.el6.netns.2.mira1
util-linux-ng|2.17.2-12.14.el6_5
udev|147-2.51.el6
device-mapper|1.02.79-8.el6
openssh|5.3p1-94.el6
ntpdate|4.2.6p5-1.el6
mc|1:4.7.0.2-3.el6
eos
end
let(:rpm_packages_list) do
{
"util-linux-ng"=>"2.17.2-12.14.el6_5",
"iproute"=>"2.6.32-130.el6.netns.2.mira1",
"openssh"=>"5.3p1-94.el6",
"udev"=>"147-2.51.el6",
"device-mapper"=>"1.02.79-8.el6",
"ntpdate"=>"4.2.6p5-1.el6",
"mc"=>"1:4.7.0.2-3.el6",
}
end
context 'on a Debian system' do
before :each do
TestCommon::Package.reset
TestCommon::Facts.reset
allow(Facter).to receive(:value).with('osfamily').and_return('Debian')
allow(TestCommon::Package).to receive(:get_deb_packages).and_return(deb_packages)
end
it 'can get a list of packages' do
expect(subject.installed_packages).to eq(deb_packages_list)
end
it 'it can check if a package is installed' do
expect(subject.is_installed? 'mc').to eq true
expect(subject.is_installed? 'nginx').to eq false
end
end
context 'on a RedHat system' do
before :each do
TestCommon::Package.reset
TestCommon::Facts.reset
allow(Facter).to receive(:value).with('osfamily').and_return('RedHat')
allow(TestCommon::Package).to receive(:get_rpm_packages).and_return(rpm_packages)
end
it 'can get a list of packages' do
expect(subject.installed_packages).to eq(rpm_packages_list)
end
it 'it can check if a package is installed' do
expect(subject.is_installed? 'mc').to eq true
expect(subject.is_installed? 'nginx').to eq false
end
end
end
describe TestCommon::Network do
let :iptables_save do
<<-eof
-A INPUT -p tcp -m multiport --ports 8777 -m comment --comment "121 ceilometer" -j ACCEPT
-A INPUT -p tcp -m multiport --dports 8386 -m comment --comment "201 sahara-all" -j ACCEPT
-A INPUT -p tcp -m multiport --dports 8004 -m comment --comment "204 heat-api" -j ACCEPT
eof
end
let :ip_a do
<<-eof
7: br-mgmt: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 0e:41:54:77:e4:f3 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.6/24 scope global br-mgmt
inet6 fe80::f82b:c5ff:fe8c:6cf1/64 scope link
valid_lft forever preferred_lft forever
8: br-storage: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 52:54:00:00:01:04 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.2/24 scope global br-storage
inet6 fe80::182b:e1ff:fe17:8876/64 scope link
valid_lft forever preferred_lft forever
eof
end
let :ip_r do
<<-eof
192.168.0.0/24 dev br-mgmt proto kernel scope link src 192.168.0.6
169.254.0.0/16 dev eth2 scope link metric 1004
default via 172.16.0.1 dev br-ex
eof
end
it 'can check is the url is accessible' do
allow(TestCommon).to receive(:run_command).with("curl --fail 'http://localhost' 1>/dev/null 2>/dev/null").and_return(['',0])
expect(subject.url_accessible? 'http://localhost').to eq true
allow(TestCommon).to receive(:run_command).with("curl --fail 'http://localhost' 1>/dev/null 2>/dev/null").and_return(['',1])
expect(subject.url_accessible? 'http://localhost').to eq false
end
it 'can check if tcp connection to a socket is possible' do
allow(TCPSocket).to receive(:open).with('localhost', 123).and_return(nil)
expect(subject.connection? 'localhost', 123).to eq true
allow(TCPSocket).to receive(:open).with('localhost', 123).and_raise 'error'
expect(subject.connection? 'localhost', 123).to eq false
end
it 'can get a list of the commented iptables rules' do
allow(TestCommon).to receive(:run_command).with('iptables-save').and_return([iptables_save,0])
expect(subject.iptables_rules).to eq %w(ceilometer sahara-all heat-api)
subject.reset
allow(TestCommon).to receive(:run_command).with('iptables-save').and_return([iptables_save,1])
expect(subject.iptables_rules).to eq nil
end
it 'can get a list of IP addresses' do
allow(TestCommon).to receive(:run_command).with('ip addr').and_return([ip_a,0])
expect(subject.ips).to eq %w(192.168.0.6 192.168.1.2)
end
it 'can get a default router' do
allow(TestCommon).to receive(:run_command).with('ip route').and_return([ip_r,0])
expect(subject.default_router).to eq '172.16.0.1'
end
it 'can check if a host is pingable' do
allow(TestCommon).to receive(:run_command).with("ping -q -c 1 -W 3 '127.0.0.1'").and_return(['',0])
expect(subject.ping? '127.0.0.1').to eq true
allow(TestCommon).to receive(:run_command).with("ping -q -c 1 -W 3 '127.0.0.1'").and_return(['',1])
expect(subject.ping? '127.0.0.1').to eq false
end
end
describe TestCommon::Config do
let :ini do
<<-eof
#data
a=1
[sec1]
b=2
[default]
c=3
#d=4
#e=5
eof
end
let :ini_data do
{"default/a"=>"1", "sec1/b"=>"2", "default/c"=>"3"}
end
before :each do
allow(File).to receive(:read).with('myfile').and_return(ini)
end
it 'can parse an ini file' do
expect(subject.ini_file 'myfile').to eq(ini_data)
end
it 'can check if a value is present in an ini config' do
expect(subject.value? 'myfile', 'default/a', '1').to eq true
expect(subject.value? 'myfile', 'DEFAULT/a', '1').to eq true
expect(subject.value? 'myfile', 'sec1/b', '2').to eq true
expect(subject.value? 'myfile', 'sec1/b', 2).to eq true
expect(subject.value? 'myfile', 'default/d', '4').to eq false
expect(subject.value? 'myfile', 'sec1/missing', '?').to eq false
end
it 'can check if a string is present in a file' do
expect(subject.has_line? 'myfile', 'a=1').to eq true
expect(subject.has_line? 'myfile', 'hello').to eq false
expect(subject.has_line? 'myfile', /^#e=5$/).to eq true
expect(subject.has_line? 'myfile', /a=\d+/).to eq true
expect(subject.has_line? 'myfile', /^xyz/).to eq false
end
end
end

View File

@@ -1,94 +1,4 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
require 'socket'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def management_vip
return $management_vip if $management_vip
$management_vip = hiera.lookup 'management_vip', nil, {}
end
def hostname
return $hostname if $hostname
$hostname = Socket.gethostname.split('.').first
end
def controller_node_address
return $controller_node_address if $controller_node_address
$controller_node_address = hiera.lookup 'controller_node_address', nil, {}
end
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
def haproxy_stats_url
ip = management_vip
ip = controller_node_address unless ip
raise 'Could not get internal address!' unless ip
port = 10000
"http://#{ip}:#{port}/;csv"
end
def csv
return $csv if $csv
begin
url = open(haproxy_stats_url)
csv = url.read
rescue
nil
end
return nil unless csv and not csv.empty?
$csv = csv
end
def swift_backend_online?
raise 'Could not get CSV from HAProxy stats!' unless csv
status = 'DOWN'
csv.split("\n").each do |line|
next unless line.start_with? 'swift'
next unless line.include? hostname
puts "DEBUG: #{line}"
fields = line.split(',')
status = fields[17]
end
status == 'UP'
end
require File.join File.dirname(__FILE__), '../test_common.rb'
PROCESSES = %w(
swift-proxy-server
@@ -100,15 +10,15 @@ swift-object-server
class SwiftPostTest < Test::Unit::TestCase
def self.create_tests
PROCESSES.each do |process|
method_name = "test_iprocess_#{process}_running"
method_name = "test_process_#{process}_running"
define_method method_name do
assert process_tree.find { |pid, proc| proc[:cmd].include? process }, "Process '#{process}' is not running!"
assert TestCommon::Process.running?(process), "Process '#{process}' is not running!"
end
end
end
def test_swift_backend_online
assert swift_backend_online?, 'Haproxy swift backend is down!'
assert TestCommon::HAProxy.backend_up?('swift'), 'Haproxy swift backend is down!'
end
end

View File

@@ -1,63 +1,8 @@
require 'hiera'
require 'test/unit'
require 'open-uri'
require 'socket'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def management_vip
return $management_vip if $management_vip
$management_vip = hiera.lookup 'management_vip', nil, {}
end
def hostname
return $hostname if $hostname
$hostname = Socket.gethostname.split('.').first
end
def controller_node_address
return $controller_node_address if $controller_node_address
$controller_node_address = hiera.lookup 'controller_node_address', nil, {}
end
def haproxy_stats_url
ip = management_vip
ip = controller_node_address unless ip
raise 'Could not get internal address!' unless ip
port = 10000
"http://#{ip}:#{port}/;csv"
end
def csv
return $csv if $csv
begin
url = open(haproxy_stats_url)
csv = url.read
rescue
nil
end
return nil unless csv and not csv.empty?
$csv = csv
end
def keystone_backends_online?
raise 'Could not get CSV from HAProxy stats!' unless csv
status = false
csv.split("\n").each do |line|
next unless line.start_with? 'keystone'
next unless line.include? 'BACKEND'
puts "DEBUG: #{line}"
fields = line.split(',')
status ||= fields[17].eql? 'UP'
end
status
end
require File.join File.dirname(__FILE__), '../test_common.rb'
class SwiftPreTest < Test::Unit::TestCase
def test_keystone_backends_are_online
assert keystone_backends_online?, 'Haproxy keystone backend is down!'
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

@@ -3,15 +3,29 @@ require 'test/unit'
require 'open-uri'
require 'timeout'
require 'facter'
require 'socket'
module TestCommon
# 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(command)
out = `#{command}`
code = $?.exitstatus
[out, code]
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)
key = key.to_s
key = 'rabbit_hash' if key == 'rabbit'
@@ -20,16 +34,26 @@ module TestCommon
@keys[key] = hiera.lookup key, nil, {}
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
@@ -38,6 +62,8 @@ module TestCommon
"http://#{ip}:#{port}/;csv"
end
# read the CSV from the Stats URL
# @return [String] csv data
def self.csv
return @csv if @csv
begin
@@ -50,6 +76,9 @@ module TestCommon
@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
@@ -65,45 +94,73 @@ module TestCommon
@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 PS
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)
`#{cmd}`
$?.exitstatus == 0
out = TestCommon.run_command 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 = `ps haxo cmd`
ps.split("\n").each do |cmd|
ps = TestCommon.run_command '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)
list.find { |cmd| cmd.include? 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 = `ps haxo pid,ppid,cmd`
ps.split("\n").each do |p|
ps = TestCommon.run_command '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
@@ -133,6 +190,11 @@ module TestCommon
@process_tree
end
# reset mnemoization
def self.reset
@process_tree = nil
@process_list = nil
end
end
module MySQL
@@ -143,6 +205,7 @@ module TestCommon
@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
@@ -199,6 +262,10 @@ module TestCommon
@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}')
@@ -207,85 +274,164 @@ module TestCommon
command += %Q( --password='#{pass}') if pass
command += %Q( --port='#{port}') if port
command += %Q( --database='#{db}') if db
out = `#{command}`
code = $?.exitstatus
return out, code
TestCommon.run_command 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|
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?
Timeout::timeout(5) { `cibadmin -Q` } rescue return false
$?.exitstatus == 0
begin
out = Timeout::timeout(5) do
TestCommon.run_command '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
list = Timeout::timeout(5) { `crm_resource -l` } rescue return
begin
out = Timeout::timeout(5) do
TestCommon.run_command 'crm_resource -l'
end
rescue
return
end
return unless out.last == 0
primitives = []
list.split("\n").each do |line|
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
out = Timeout::timeout(5) { `crm_resource -r #{primitive} -W 2>&1` } rescue return
return true if out.include? 'is running on'
return false if out.include? 'is NOT running'
begin
out = TestCommon.run_command "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
def self.osfamily
return @osfamily if @osfamily
@osfamily = Facter.value 'osfamily'
# 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
`rpm -qa --queryformat '%{NAME}|%{VERSION}-%{RELEASE}\n'`
out = TestCommon.run_command "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
`dpkg-query --show -f='${Package}|${Version}|${Status}\n'`
out = TestCommon.run_command "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|
@@ -299,6 +445,10 @@ module TestCommon
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|
@@ -317,6 +467,9 @@ module TestCommon
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'
@@ -328,25 +481,140 @@ module TestCommon
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 Net
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)
`curl --fail '#{url}' 1>/dev/null 2>/dev/null`
$?.exitstatus == 0
out = TestCommon.run_command "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.run_command '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+/, ''
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.run_command 'ip addr'
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.run_command '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)
`ping -q -c 1 -W 3 '#{host}'`
$?.exitstatus == 0
begin
out = Timeout::timeout(5) do
TestCommon.run_command "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
def self.connection?(user, password, host='localhost', port='5672', vhost='/', protocol='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
@@ -371,9 +639,56 @@ else:
end
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? '/'
value = value.to_s
data = ini_file file
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
if __FILE__ == $1
require 'pry'
TestCommon.pry
end

View File

@@ -1,9 +1,4 @@
require 'test/unit'
def tool_present(tool)
`which '#{tool}' 1>/dev/null 2>/dev/null`
$?.exitstatus == 0
end
require File.join File.dirname(__FILE__), '../test_common.rb'
TOOLS = %w(
screen
@@ -22,7 +17,7 @@ class ToolsPostTest < Test::Unit::TestCase
TOOLS.each do |tool|
method_name = "test_tool_#{tool}_present"
define_method method_name do
assert tool_present(tool), "There is no '#{tool}' installed!"
assert TestCommon::Process.command_present?(tool), "There is no '#{tool}' installed!"
end
end
end

View File

@@ -1,43 +1,20 @@
require 'hiera'
require 'test/unit'
def ping(host)
`ping -q -c 1 -W 3 '#{host}'`
$?.exitstatus == 0
end
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def public_vip
return $public_vip if $public_vip
$public_vip = hiera.lookup 'public_vip', nil, {}
end
def management_vip
return $management_vip if $management_vip
$management_vip = hiera.lookup 'management_vip', nil, {}
end
def deployment_mode
return $deployment_mode if $deployment_mode
$deployment_mode = hiera.lookup 'deployment_mode', nil, {}
end
def is_ha?
%w(ha ha_compact).include? deployment_mode
end
require File.join File.dirname(__FILE__), '../test_common.rb'
class VirtualIPsPostTest < Test::Unit::TestCase
def test_public_vip_ping
assert ping(public_vip), "Could not ping the public vip '#{public_vip}'!" if is_ha?
ip = TestCommon::Settings.public_vip
assert TestCommon::Network.ping?(ip), "Could not ping the public vip '#{ip}'!"
end
def test_management_vip_ping
assert ping(management_vip), "Could not ping the management vip '#{management_vip}'!" if is_ha?
ip = TestCommon::Settings.management_vip
assert TestCommon::Network.ping?(ip), "Could not ping the management vip '#{ip}'!"
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
end

View File

@@ -1,43 +1,9 @@
require 'test/unit'
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
require File.join File.dirname(__FILE__), '../test_common.rb'
class CinderVmwarePostTest < Test::Unit::TestCase
def test_process
assert process_tree.find { |pid, proc| proc[:cmd].include? "/etc/cinder/cinder.d/vmware"}, "Process cinder-volume --config /etc/cinder/cinder.d/vmware-N.conf is not running!"
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,23 +1,12 @@
require 'hiera'
require 'test/unit'
def hiera
return $hiera if $hiera
$hiera = Hiera.new(:config => '/etc/puppet/hiera.yaml')
end
def roles
return $roles if $roles
$roles = hiera.lookup 'roles', nil, {}
end
require File.join File.dirname(__FILE__), '../test_common.rb'
class CinderVmwarePreTest < Test::Unit::TestCase
def test_roles
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!'
assert roles.find_index('cinder-vmware'), 'Wrong role for this node!'
end
end

View File

@@ -1,43 +1,9 @@
require 'test/unit'
def process_tree
return $process_tree if $process_tree
$process_tree = {}
ps = `ps haxo pid,ppid,cmd`
ps.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
require File.join File.dirname(__FILE__), '../test_common.rb'
class ZabbixPostTest < Test::Unit::TestCase
def test_zabbix_is_running
assert process_tree.find { |pid, proc| proc[:cmd].include? 'zabbix_server' }, 'Zabbix server is not running!'
assert TestCommon::Process.running?('zabbix_server'), 'Zabbix server is not running!'
end
end