Add murano package-list port test

Change-Id: I528183984bea4e70f279fa480d82d02f866a0826
This commit is contained in:
Dmitry Ilyin 2015-05-07 20:40:38 +03:00
parent 156fb11bbf
commit b333086aac
5 changed files with 146 additions and 57 deletions

View File

@ -23,11 +23,7 @@ class GlancePostTest < Test::Unit::TestCase
end
def test_keystone_endpoint_list_run
ENV['OS_TENANT_NAME']="services"
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"
TestCommon::Cmd.openstack_auth
cmd = 'glance image-list'
assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!"
end

View File

@ -20,13 +20,7 @@ class KeystonePostTest < Test::Unit::TestCase
end
def test_keystone_endpoint_list_run
# Keystone doen't have a user, so we'd have to use the admin token, or use
# 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"
TestCommon::Cmd.openstack_auth
cmd = 'keystone endpoint-list'
assert TestCommon::Process.run_successful?(cmd), "Could not run '#{cmd}'!"
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!"
end
def test_murano_has_core_library
murano_package_list = TestCommon::Cmd.openstack_cli 'murano package-list'
assert murano_package_list.is_a?(Array), 'Could not get a correct murano package-list!'
core_library = murano_package_list.find { |line| line['FQN'] == 'io.murano' and line['Name'] == 'Core library' }
assert core_library, 'Core library with io.murano not found in murano package-list!'
end
end

View File

@ -2,6 +2,49 @@ require 'spec_helper'
require File.join File.dirname(__FILE__), '../test_common.rb'
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
before :each do
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
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])
allow(TestCommon::Cmd).to receive(:run).with('ps haxo cmd').and_return([short_ps, 0])
allow(TestCommon::Cmd).to receive(:run).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])
allow(TestCommon::Cmd).to receive(:run).with('/bin/true').and_return(['', 0])
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/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])
allow(TestCommon::Cmd).to receive(:run).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])
allow(TestCommon::Cmd).to receive(:run).with(cmd).and_return(['', 1])
expect(subject.command_present? 'my_command').to eq false
end
@ -237,7 +280,7 @@ nova
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])
expect(TestCommon::Cmd).to receive(:run).with(cmd).and_return(['',0])
subject.query 'show databases'
end
@ -248,7 +291,7 @@ nova
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])
expect(TestCommon::Cmd).to receive(:run).with(cmd).and_return(['',0])
subject.query 'show databases'
end
@ -288,29 +331,29 @@ p_mysql:0
end
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
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
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])
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))
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])
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? '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])
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
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
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
end
end
@ -449,9 +492,9 @@ default via 172.16.0.1 dev br-ex
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])
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
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
end
@ -463,27 +506,27 @@ default via 172.16.0.1 dev br-ex
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])
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)
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
end
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)
end
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'
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])
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
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
end
end

View File

@ -6,13 +6,62 @@ 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]
module Cmd
# Run a shell command and return stdout and return code as an array
# @param command [String] the command to run
# @return [Array<String,Numeric>] Stdout and return code
def self.run(command)
out = `#{command}`
code = $?.exitstatus
[out, code]
end
# set the OpenStack CLI auth data
def self.openstack_auth
ENV['LC_ALL'] = 'C'
ENV['OS_NO_CACHE'] = 'true'
ENV['OS_TENANT_NAME'] = TestCommon::Settings.access['tenant']
ENV['OS_USERNAME'] = TestCommon::Settings.access['user']
ENV['OS_PASSWORD'] = TestCommon::Settings.access['password']
ENV['OS_AUTH_URL'] = "http://#{TestCommon::Settings.management_vip}:5000/v2.0"
ENV['OS_AUTH_STRATEGY'] = 'keystone'
ENV['OS_REGION_NAME'] = 'RegionOne'
ENV['OS_ENDPOINT_TYPE'] = 'internalURL'
end
# run the openstack cli command with auth
# and parse the results into a structure
# @return [Array<Hash>]
def self.openstack_cli(command)
openstack_auth
out, code = run command
return [nil, code] unless code == 0
headers = nil
data = []
out.split("\n").each do |line|
next unless line.start_with? '|'
columns = line.split('|')
next unless columns.length > 2
columns = columns[1..-2].map do |column|
column.chomp.strip
end
unless headers
headers = columns
next
end
record = {}
field_number = 0
columns.each do |column|
header = headers[field_number]
next unless header
record[header] = column
field_number += 1
end
data << record if record.any?
end
data
end
end
module Settings
@ -121,7 +170,7 @@ module TestCommon
# @param cmd [String] the command to run
# @return [true,false]
def self.run_successful?(cmd)
out = TestCommon.run_command cmd
out = TestCommon::Cmd.run cmd
out.last == 0
end
@ -137,7 +186,7 @@ module TestCommon
def self.list
return @process_list if @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|
@process_list << cmd
end
@ -159,7 +208,7 @@ module TestCommon
def self.tree
return @process_tree if @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|
f = p.split
pid = f.shift.to_i
@ -274,7 +323,7 @@ module TestCommon
command += %Q( --password='#{pass}') if pass
command += %Q( --port='#{port}') if port
command += %Q( --database='#{db}') if db
TestCommon.run_command command
TestCommon::Cmd.run command
end
# check if mysql can connect ot the server
@ -319,7 +368,7 @@ module TestCommon
def self.online?
begin
out = Timeout::timeout(5) do
TestCommon.run_command 'cibadmin -Q'
TestCommon::Cmd.run 'cibadmin -Q'
end
rescue
return false
@ -332,7 +381,7 @@ module TestCommon
def self.primitives
begin
out = Timeout::timeout(5) do
TestCommon.run_command 'crm_resource -l'
TestCommon::Cmd.run 'crm_resource -l'
end
rescue
return
@ -369,7 +418,7 @@ module TestCommon
def self.primitive_started?(primitive)
primitive = clean_primitive_name primitive
begin
out = TestCommon.run_command "crm_resource -r #{primitive} -W 2>&1"
out = TestCommon::Cmd.run "crm_resource -r #{primitive} -W 2>&1"
rescue
return
end
@ -416,7 +465,7 @@ module TestCommon
# using the 'rpm' tool
# @returns [String] 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
end
@ -424,7 +473,7 @@ module TestCommon
# using the 'dpkg-query' tool
# @returns [String] 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
end
@ -499,7 +548,7 @@ module TestCommon
# @param url [String] the url to check
# @return [true,false]
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
end
@ -533,7 +582,7 @@ module TestCommon
# @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'
output, code = TestCommon::Cmd.run 'iptables-save'
return unless code == 0
comments = []
output.split("\n").each do |line|
@ -549,7 +598,7 @@ module TestCommon
# @return [Array<String>] the list of addresses
def self.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
ips = []
ip_out.split("\n").each do |line|
@ -564,7 +613,7 @@ module TestCommon
# @return [String] the default router ip
def self.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
routes.split("\n").each do |line|
if line =~ /^default via ([\d\.]*)/
@ -580,7 +629,7 @@ module TestCommon
def self.ping?(host)
begin
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
rescue
return false
@ -699,7 +748,7 @@ else:
# @return [true,false]
def self.cronjob_exists?(user, cronjob)
cmd = "crontab -u #{user} -l"
out = TestCommon.run_command cmd
out = TestCommon::Cmd.run cmd
false unless out.last == 0
out.first[/^\s*[^#]*#{cronjob}/].nil? == false
end