Merge "Add murano package-list port test"

This commit is contained in:
Jenkins 2015-05-18 10:21:08 +00:00 committed by Gerrit Code Review
commit aece146fb4
5 changed files with 146 additions and 57 deletions

View File

@ -23,11 +23,7 @@ class GlancePostTest < Test::Unit::TestCase
end end
def test_keystone_endpoint_list_run def test_keystone_endpoint_list_run
ENV['OS_TENANT_NAME']="services" TestCommon::Cmd.openstack_auth
ENV['OS_USERNAME']="glance"
ENV['OS_PASSWORD']="#{TestCommon::Settings.glance['user_password']}"
ENV['OS_AUTH_URL']="http://#{TestCommon::Settings.management_vip}:5000/v2.0"
ENV['OS_ENDPOINT_TYPE'] = "internalURL"
cmd = 'glance image-list' cmd = 'glance image-list'
assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!" assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!"
end end

View File

@ -20,13 +20,7 @@ class KeystonePostTest < Test::Unit::TestCase
end end
def test_keystone_endpoint_list_run def test_keystone_endpoint_list_run
# Keystone doen't have a user, so we'd have to use the admin token, or use TestCommon::Cmd.openstack_auth
# another user like nova.
ENV['OS_TENANT_NAME']="services"
ENV['OS_USERNAME']="nova"
ENV['OS_PASSWORD']="#{TestCommon::Settings.nova['user_password']}"
ENV['OS_AUTH_URL']="http://#{TestCommon::Settings.management_vip}:#{PUBLIC_PORT}/v2.0"
ENV['OS_ENDPOINT_TYPE'] = "internalURL"
cmd = 'keystone endpoint-list' cmd = 'keystone endpoint-list'
assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!" assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!"
end end

View File

@ -25,4 +25,11 @@ class MuranoPostTest < Test::Unit::TestCase
assert TestCommon::Network.url_accessible?(url), "Murano-api url '#{url}' is not accessible!" assert TestCommon::Network.url_accessible?(url), "Murano-api url '#{url}' is not accessible!"
end 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 end

View File

@ -2,6 +2,49 @@ require 'spec_helper'
require File.join File.dirname(__FILE__), '../test_common.rb' require File.join File.dirname(__FILE__), '../test_common.rb'
describe TestCommon do describe TestCommon do
context TestCommon::Cmd do
let(:cli_data) do
<<-eos
+----------------------------------+----------+----------------+----------------------------------+
| id | name | type | description |
+----------------------------------+----------+----------------+----------------------------------+
| 5374e5389d364da28c984bc429c3e33a | cinder | volume | Cinder Service |
| af3d223f30da4fe09cec7b857a204ba4 | cinderv2 | volumev2 | Cinder Service v2 |
| 0640b5feb76948ee93a33ab4354bb2b8 | glance | image | Openstack Image Service |
| 7923acaf138247269fb3ef12236c5c6a | heat | orchestration | Openstack Orchestration Service |
| 27be38b78d57489eb54a6b41a630b443 | heat-cfn | cloudformation | Openstack Cloudformation Service |
| b2ea93c019704ed4bbc0c4da8fff425b | keystone | identity | OpenStack Identity Service |
| f8daa037416549b0a7bbdff67b0501b3 | neutron | network | Neutron Networking Service |
| d20f6c9b482642c8b3c92ea5c115f100 | nova | compute | Openstack Compute Service |
| d8882e01181740e1b96b34dbf9b4dd77 | nova_ec2 | ec2 | EC2 Service |
| c9291f7d537141ffb6a560dd42e7d159 | swift | object-store | Openstack Object-Store Service |
| b622a097b88e460ebea284bf04f65be5 | swift_s3 | s3 | Openstack S3 Service |
+----------------------------------+----------+----------------+----------------------------------+
eos
end
let(:cli_data_parsed) do
[
{"id"=>"5374e5389d364da28c984bc429c3e33a", "name"=>"cinder", "type"=>"volume"},
{"id"=>"af3d223f30da4fe09cec7b857a204ba4", "name"=>"cinderv2", "type"=>"volumev2"},
{"id"=>"0640b5feb76948ee93a33ab4354bb2b8", "name"=>"glance", "type"=>"image"},
{"id"=>"7923acaf138247269fb3ef12236c5c6a", "name"=>"heat", "type"=>"orchestration"},
{"id"=>"27be38b78d57489eb54a6b41a630b443", "name"=>"heat-cfn", "type"=>"cloudformation"},
{"id"=>"b2ea93c019704ed4bbc0c4da8fff425b", "name"=>"keystone", "type"=>"identity"},
{"id"=>"f8daa037416549b0a7bbdff67b0501b3", "name"=>"neutron", "type"=>"network"},
{"id"=>"d20f6c9b482642c8b3c92ea5c115f100", "name"=>"nova", "type"=>"compute"},
{"id"=>"d8882e01181740e1b96b34dbf9b4dd77", "name"=>"nova_ec2", "type"=>"ec2"},
{"id"=>"c9291f7d537141ffb6a560dd42e7d159", "name"=>"swift", "type"=>"object-store"},
{"id"=>"b622a097b88e460ebea284bf04f65be5", "name"=>"swift_s3", "type"=>"s3"},
]
end
it 'can run the OpenStack cli command and parse the results' do
expect(TestCommon::Cmd).to receive(:run).with('keystone service-list').and_return([cli_data, 0])
allow(TestCommon::Cmd).to receive(:openstack_auth)
expect(TestCommon::Cmd.openstack_cli 'keystone service-list').to eq cli_data_parsed
end
end
context TestCommon::Settings do context TestCommon::Settings do
before :each do before :each do
allow(subject.hiera).to receive(:lookup).with('id', nil, {}).and_return('1') allow(subject.hiera).to receive(:lookup).with('id', nil, {}).and_return('1')
@ -192,22 +235,22 @@ keystone-2,BACKEND,0,0,0,1,800,135,31659,695738,0,0,,0,0,0,0,UP,1,1,0,,0,347258,
end end
before :each do before :each do
allow(TestCommon).to receive(:run_command).with('ps haxo cmd').and_return([short_ps, 0]) allow(TestCommon::Cmd).to receive(:run).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]) allow(TestCommon::Cmd).to receive(:run).with('ps haxo pid,ppid,cmd').and_return([full_ps, 0])
end end
it 'can check if command runs successfully' do it 'can check if command runs successfully' do
allow(TestCommon).to receive(:run_command).with('/bin/true').and_return(['', 0]) allow(TestCommon::Cmd).to receive(:run).with('/bin/true').and_return(['', 0])
allow(TestCommon).to receive(:run_command).with('/bin/false').and_return(['', 1]) allow(TestCommon::Cmd).to receive(:run).with('/bin/false').and_return(['', 1])
expect(subject.run_successful? '/bin/true').to eq true expect(subject.run_successful? '/bin/true').to eq true
expect(subject.run_successful? '/bin/false').to eq false expect(subject.run_successful? '/bin/false').to eq false
end end
it 'can check if a command can be found' do it 'can check if a command can be found' do
cmd = "which 'my_command' 1>/dev/null 2>/dev/null" cmd = "which 'my_command' 1>/dev/null 2>/dev/null"
allow(TestCommon).to receive(:run_command).with(cmd).and_return(['', 0]) allow(TestCommon::Cmd).to receive(:run).with(cmd).and_return(['', 0])
expect(subject.command_present? 'my_command').to eq true expect(subject.command_present? 'my_command').to eq true
allow(TestCommon).to receive(:run_command).with(cmd).and_return(['', 1]) allow(TestCommon::Cmd).to receive(:run).with(cmd).and_return(['', 1])
expect(subject.command_present? 'my_command').to eq false expect(subject.command_present? 'my_command').to eq false
end end
@ -237,7 +280,7 @@ nova
it 'can form mysql queries without auth' do it 'can form mysql queries without auth' do
subject.no_auth subject.no_auth
cmd = %q(mysql --raw --skip-column-names --batch --execute='show databases') cmd = %q(mysql --raw --skip-column-names --batch --execute='show databases')
expect(TestCommon).to receive(:run_command).with(cmd).and_return(['',0]) expect(TestCommon::Cmd).to receive(:run).with(cmd).and_return(['',0])
subject.query 'show databases' subject.query 'show databases'
end end
@ -248,7 +291,7 @@ nova
subject.port = '123' subject.port = '123'
subject.host = 'myhost' subject.host = 'myhost'
cmd = %q(mysql --raw --skip-column-names --batch --execute='show databases' --host='myhost' --user='user' --password='pass' --port='123' --database='mydb') 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]) expect(TestCommon::Cmd).to receive(:run).with(cmd).and_return(['',0])
subject.query 'show databases' subject.query 'show databases'
end end
@ -288,29 +331,29 @@ p_mysql:0
end end
it 'can check if pacemaker is online' do it 'can check if pacemaker is online' do
allow(TestCommon).to receive(:run_command).with('cibadmin -Q').and_return(['',0]) allow(TestCommon::Cmd).to receive(:run).with('cibadmin -Q').and_return(['',0])
expect(subject.online?).to eq true expect(subject.online?).to eq true
allow(TestCommon).to receive(:run_command).with('cibadmin -Q').and_return(['',1]) allow(TestCommon::Cmd).to receive(:run).with('cibadmin -Q').and_return(['',1])
expect(subject.online?).to eq false expect(subject.online?).to eq false
end end
it 'can get the list of the primitives' do 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]) allow(TestCommon::Cmd).to receive(:run).with('crm_resource -l').and_return([crm_resource_l,0])
expect(subject.primitives).to eq(%w(p_haproxy p_dns p_ntp p_mysql)) expect(subject.primitives).to eq(%w(p_haproxy p_dns p_ntp p_mysql))
end end
it 'can check if a primitive is present' do 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]) allow(TestCommon::Cmd).to receive(:run).with('crm_resource -l').and_return([crm_resource_l,0])
expect(subject.primitive_present? 'p_dns').to eq true expect(subject.primitive_present? 'p_dns').to eq true
expect(subject.primitive_present? 'MISSING').to eq false expect(subject.primitive_present? 'MISSING').to eq false
end end
it 'can check if primitive is started' do 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]) allow(TestCommon::Cmd).to receive(:run).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 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]) allow(TestCommon::Cmd).to receive(:run).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 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]) allow(TestCommon::Cmd).to receive(:run).with('crm_resource -r MISSING -W 2>&1').and_return(['',1])
expect(subject.primitive_started? 'MISSING').to eq nil expect(subject.primitive_started? 'MISSING').to eq nil
end end
end end
@ -449,9 +492,9 @@ default via 172.16.0.1 dev br-ex
end end
it 'can check is the url is accessible' do 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]) allow(TestCommon::Cmd).to receive(:run).with("curl --fail 'http://localhost' 1>/dev/null 2>/dev/null").and_return(['',0])
expect(subject.url_accessible? 'http://localhost').to eq true 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]) allow(TestCommon::Cmd).to receive(:run).with("curl --fail 'http://localhost' 1>/dev/null 2>/dev/null").and_return(['',1])
expect(subject.url_accessible? 'http://localhost').to eq false expect(subject.url_accessible? 'http://localhost').to eq false
end end
@ -463,27 +506,27 @@ default via 172.16.0.1 dev br-ex
end end
it 'can get a list of the commented iptables rules' do 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]) allow(TestCommon::Cmd).to receive(:run).with('iptables-save').and_return([iptables_save,0])
expect(subject.iptables_rules).to eq %w(ceilometer sahara-all heat-api) expect(subject.iptables_rules).to eq %w(ceilometer sahara-all heat-api)
subject.reset subject.reset
allow(TestCommon).to receive(:run_command).with('iptables-save').and_return([iptables_save,1]) allow(TestCommon::Cmd).to receive(:run).with('iptables-save').and_return([iptables_save,1])
expect(subject.iptables_rules).to eq nil expect(subject.iptables_rules).to eq nil
end end
it 'can get a list of IP addresses' do it 'can get a list of IP addresses' do
allow(TestCommon).to receive(:run_command).with('ip addr').and_return([ip_a,0]) allow(TestCommon::Cmd).to receive(:run).with('ip addr').and_return([ip_a,0])
expect(subject.ips).to eq %w(192.168.0.6 192.168.1.2) expect(subject.ips).to eq %w(192.168.0.6 192.168.1.2)
end end
it 'can get a default router' do it 'can get a default router' do
allow(TestCommon).to receive(:run_command).with('ip route').and_return([ip_r,0]) allow(TestCommon::Cmd).to receive(:run).with('ip route').and_return([ip_r,0])
expect(subject.default_router).to eq '172.16.0.1' expect(subject.default_router).to eq '172.16.0.1'
end end
it 'can check if a host is pingable' do 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]) allow(TestCommon::Cmd).to receive(:run).with("ping -q -c 1 -W 3 '127.0.0.1'").and_return(['',0])
expect(subject.ping? '127.0.0.1').to eq true 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]) allow(TestCommon::Cmd).to receive(:run).with("ping -q -c 1 -W 3 '127.0.0.1'").and_return(['',1])
expect(subject.ping? '127.0.0.1').to eq false expect(subject.ping? '127.0.0.1').to eq false
end end
end end

View File

@ -6,13 +6,62 @@ require 'facter'
require 'socket' require 'socket'
module TestCommon module TestCommon
# Run a shell command and return stdout and return code as an array module Cmd
# @param command [String] the command to run # Run a shell command and return stdout and return code as an array
# @return [Array<String,Numeric>] Stdout and return code # @param command [String] the command to run
def self.run_command(command) # @return [Array<String,Numeric>] Stdout and return code
out = `#{command}` def self.run(command)
code = $?.exitstatus out = `#{command}`
[out, code] 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 end
module Settings module Settings
@ -121,7 +170,7 @@ module TestCommon
# @param cmd [String] the command to run # @param cmd [String] the command to run
# @return [true,false] # @return [true,false]
def self.run_successful?(cmd) def self.run_successful?(cmd)
out = TestCommon.run_command cmd out = TestCommon::Cmd.run cmd
out.last == 0 out.last == 0
end end
@ -137,7 +186,7 @@ module TestCommon
def self.list def self.list
return @process_list if @process_list return @process_list if @process_list
@process_list = [] @process_list = []
ps = TestCommon.run_command 'ps haxo cmd' ps = TestCommon::Cmd.run 'ps haxo cmd'
ps.first.split("\n").each do |cmd| ps.first.split("\n").each do |cmd|
@process_list << cmd @process_list << cmd
end end
@ -159,7 +208,7 @@ module TestCommon
def self.tree def self.tree
return @process_tree if @process_tree return @process_tree if @process_tree
@process_tree = {} @process_tree = {}
ps = TestCommon.run_command 'ps haxo pid,ppid,cmd' ps = TestCommon::Cmd.run 'ps haxo pid,ppid,cmd'
ps.first.split("\n").each do |p| ps.first.split("\n").each do |p|
f = p.split f = p.split
pid = f.shift.to_i pid = f.shift.to_i
@ -274,7 +323,7 @@ module TestCommon
command += %Q( --password='#{pass}') if pass command += %Q( --password='#{pass}') if pass
command += %Q( --port='#{port}') if port command += %Q( --port='#{port}') if port
command += %Q( --database='#{db}') if db command += %Q( --database='#{db}') if db
TestCommon.run_command command TestCommon::Cmd.run command
end end
# check if mysql can connect ot the server # check if mysql can connect ot the server
@ -319,7 +368,7 @@ module TestCommon
def self.online? def self.online?
begin begin
out = Timeout::timeout(5) do out = Timeout::timeout(5) do
TestCommon.run_command 'cibadmin -Q' TestCommon::Cmd.run 'cibadmin -Q'
end end
rescue rescue
return false return false
@ -332,7 +381,7 @@ module TestCommon
def self.primitives def self.primitives
begin begin
out = Timeout::timeout(5) do out = Timeout::timeout(5) do
TestCommon.run_command 'crm_resource -l' TestCommon::Cmd.run 'crm_resource -l'
end end
rescue rescue
return return
@ -369,7 +418,7 @@ module TestCommon
def self.primitive_started?(primitive) def self.primitive_started?(primitive)
primitive = clean_primitive_name primitive primitive = clean_primitive_name primitive
begin begin
out = TestCommon.run_command "crm_resource -r #{primitive} -W 2>&1" out = TestCommon::Cmd.run "crm_resource -r #{primitive} -W 2>&1"
rescue rescue
return return
end end
@ -416,7 +465,7 @@ module TestCommon
# using the 'rpm' tool # using the 'rpm' tool
# @returns [String] packages # @returns [String] packages
def self.get_rpm_packages def self.get_rpm_packages
out = TestCommon.run_command "rpm -qa --queryformat '%{NAME}|%{VERSION}-%{RELEASE}\n'" out = TestCommon::Cmd.run "rpm -qa --queryformat '%{NAME}|%{VERSION}-%{RELEASE}\n'"
out.first out.first
end end
@ -424,7 +473,7 @@ module TestCommon
# using the 'dpkg-query' tool # using the 'dpkg-query' tool
# @returns [String] packages # @returns [String] packages
def self.get_deb_packages def self.get_deb_packages
out = TestCommon.run_command "dpkg-query --show -f='${Package}|${Version}|${Status}\n'" out = TestCommon::Cmd.run "dpkg-query --show -f='${Package}|${Version}|${Status}\n'"
out.first out.first
end end
@ -499,7 +548,7 @@ module TestCommon
# @param url [String] the url to check # @param url [String] the url to check
# @return [true,false] # @return [true,false]
def self.url_accessible?(url) def self.url_accessible?(url)
out = TestCommon.run_command "curl --fail '#{url}' 1>/dev/null 2>/dev/null" out = TestCommon::Cmd.run "curl --fail '#{url}' 1>/dev/null 2>/dev/null"
out.last == 0 out.last == 0
end end
@ -533,7 +582,7 @@ module TestCommon
# @return [Array<String>] the list of rule names # @return [Array<String>] the list of rule names
def self.iptables_rules def self.iptables_rules
return @iptables_rules if @iptables_rules return @iptables_rules if @iptables_rules
output, code = TestCommon.run_command 'iptables-save' output, code = TestCommon::Cmd.run 'iptables-save'
return unless code == 0 return unless code == 0
comments = [] comments = []
output.split("\n").each do |line| output.split("\n").each do |line|
@ -549,7 +598,7 @@ module TestCommon
# @return [Array<String>] the list of addresses # @return [Array<String>] the list of addresses
def self.ips def self.ips
return @ips if @ips return @ips if @ips
ip_out, code = TestCommon.run_command 'ip addr' ip_out, code = TestCommon::Cmd.run 'ip addr'
return unless code == 0 return unless code == 0
ips = [] ips = []
ip_out.split("\n").each do |line| ip_out.split("\n").each do |line|
@ -564,7 +613,7 @@ module TestCommon
# @return [String] the default router ip # @return [String] the default router ip
def self.default_router def self.default_router
return @default_router if @default_router return @default_router if @default_router
routes, code = TestCommon.run_command 'ip route' routes, code = TestCommon::Cmd.run 'ip route'
return unless code == 0 return unless code == 0
routes.split("\n").each do |line| routes.split("\n").each do |line|
if line =~ /^default via ([\d\.]*)/ if line =~ /^default via ([\d\.]*)/
@ -580,7 +629,7 @@ module TestCommon
def self.ping?(host) def self.ping?(host)
begin begin
out = Timeout::timeout(5) do out = Timeout::timeout(5) do
TestCommon.run_command "ping -q -c 1 -W 3 '#{host}'" TestCommon::Cmd.run "ping -q -c 1 -W 3 '#{host}'"
end end
rescue rescue
return false return false
@ -699,7 +748,7 @@ else:
# @return [true,false] # @return [true,false]
def self.cronjob_exists?(user, cronjob) def self.cronjob_exists?(user, cronjob)
cmd = "crontab -u #{user} -l" cmd = "crontab -u #{user} -l"
out = TestCommon.run_command cmd out = TestCommon::Cmd.run cmd
false unless out.last == 0 false unless out.last == 0
out.first[/^\s*[^#]*#{cronjob}/].nil? == false out.first[/^\s*[^#]*#{cronjob}/].nil? == false
end end