Replace serverspec with nose in systemvm test.sh

Also remove the serverspec-specific files.
This commit is contained in:
Leo Simons 2014-08-06 13:47:13 +02:00 committed by wilderrodrigues
parent 2188d8d633
commit e405e94797
11 changed files with 36 additions and 144 deletions

View File

@ -5,7 +5,7 @@ see ../../tools/vagrant/systemvm.
Then, install dependencies Then, install dependencies
pip install nose paramiko python-vagrant envassert cuisine pip install nose paramiko python-vagrant envassert cuisine fabric
Running tests Running tests
============= =============

View File

@ -15,11 +15,13 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
from __future__ import with_statement
from vagrant import Vagrant from vagrant import Vagrant
from unittest import TestCase from unittest import TestCase
from paramiko.config import SSHConfig from paramiko.config import SSHConfig
from paramiko.client import SSHClient, AutoAddPolicy from paramiko.client import SSHClient, AutoAddPolicy
from fabric.api import env from fabric.api import env
from fabric.api import run, hide
from envassert import file, detect from envassert import file, detect
from StringIO import StringIO from StringIO import StringIO
@ -147,3 +149,9 @@ class SystemVMTestCase(TestCase):
# this could break down when executing multiple test cases in parallel in the same python process # this could break down when executing multiple test cases in parallel in the same python process
# def tearDown(self): # def tearDown(self):
# env.host_string = self._env_host_string_orig # env.host_string = self._env_host_string_orig
def has_line(location, line):
with hide("everything"):
text = run('cat "%s"' % location)
return text.find(line) >= 0

View File

@ -21,9 +21,9 @@ from nose.plugins.attrib import attr
from envassert import file, package, user from envassert import file, package, user
from cuisine import file_write from cuisine import file_write
try: try:
from . import SystemVMTestCase from . import SystemVMTestCase, has_line
except (ImportError, ValueError): except (ImportError, ValueError):
from systemvm import SystemVMTestCase from systemvm import SystemVMTestCase, has_line
class HelloSystemVMTestCase(SystemVMTestCase): class HelloSystemVMTestCase(SystemVMTestCase):
@ -47,5 +47,5 @@ class HelloSystemVMTestCase(SystemVMTestCase):
@attr(tags=["systemvm"], required_hardware="true") @attr(tags=["systemvm"], required_hardware="true")
def test_hello_systemvm_cuisine(self): def test_hello_systemvm_cuisine(self):
"""Test we can run cuisine on the systemvm""" """Test we can run cuisine on the systemvm"""
file_write('/tmp/run_cuisine', 'success!\n') file_write('/tmp/run_cuisine', '\n\nsuccess!\n')
assert file.has_line('/tmp/run_cuisine', 'success!') assert has_line('/tmp/run_cuisine', 'success!')

View File

@ -1,3 +0,0 @@
--format documentation
--format RspecJunitFormatter
--out rspec.xml

View File

@ -17,8 +17,4 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'rake'
gem 'rspec', '~> 2.99'
gem 'serverspec', '~> 1.11.0'
gem 'rspec_junit_formatter'
gem 'vagrant-wrapper' gem 'vagrant-wrapper'

View File

@ -18,13 +18,13 @@ under the License.
=========================================================== ===========================================================
Allows spinning up the systemvm appliance from ../../appliance inside Allows spinning up the systemvm appliance from ../../appliance inside
vagrant, and then running tests against it with serverspec. vagrant, and then running tests against it with nose.
To use, install vagrant, rvm, ruby, and bundler. Then run ./test.sh. To use, install vagrant, rvm, ruby, bundler, python and pip.
Then run ./test.sh.
To write tests, create files underneath ../../../test/systemvm
named test_xxx.py. These tests are standard python unit tests with
some logic to SSH into the SystemVM. See
../../../test/systemvm/README.md for more info.
To write tests, create files underneath spec/ whose names end in
_spec.rb. These tests are [RSpec](http://rspec.info/) tests that use
[Serverspec](http://serverspec.org/) matchers. Basically, they log
in using SSH and then inspect files and processes. See the list of
[Serverspec matchers](http://serverspec.org/resource_types.html)
for inspiration.

View File

@ -1,25 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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 'rake'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/*/*_spec.rb'
end
task :default => :spec

View File

@ -22,7 +22,7 @@ include RbConfig
VAGRANTFILE_API_VERSION = '2' VAGRANTFILE_API_VERSION = '2'
if ENV['VPC_IP'] unless ENV['VPC_IP']
puts 'You did not specify the VPC IP by settings the VPC_IP environment variable' puts 'You did not specify the VPC IP by settings the VPC_IP environment variable'
puts 'Using the default VPC_IP=192.168.56.30' puts 'Using the default VPC_IP=192.168.56.30'
end end

View File

@ -1,69 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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 'serverspec'
require 'pathname'
require 'net/ssh'
require 'pp'
include SpecInfra::Helper::Ssh
include SpecInfra::Helper::DetectOS
#RSpec.configure do |c|
# c.before :all do
# c.path = '/sbin:/usr/sbin'
# end
#end
RSpec.configure do |c|
if ENV['ASK_SUDO_PASSWORD']
require 'highline/import'
c.sudo_password = ask('Enter sudo password: ') { |q| q.echo = false }
else
c.sudo_password = ENV['SUDO_PASSWORD']
end
c.before :all do
block = self.class.metadata[:example_group_block]
if RUBY_VERSION.start_with?('1.8')
file = block.to_s.match(/.*@(.*):[0-9]+>/)[1]
else
file = block.source_location.first
end
host = File.basename(Pathname.new(file).dirname)
if c.host != host
c.ssh.close if c.ssh
c.host = host
options = Net::SSH::Config.for(c.host)
user = options[:user] || Etc.getlogin
config = `vagrant ssh-config default`
if config != ''
config.each_line do |line|
if match = /HostName (.*)/.match(line)
host = match[1]
elsif match = /User (.*)/.match(line)
user = match[1]
elsif match = /IdentityFile (.*)/.match(line)
options[:keys] = [match[1].gsub(/"/,'')]
elsif match = /Port (.*)/.match(line)
options[:port] = match[1]
end
end
end
c.ssh = Net::SSH.start(host, user, options)
end
end
end

View File

@ -1,23 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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 'spec_helper'
describe file('/etc/cloudstack-release') do
it { should be_file }
its(:content) { should match /Cloudstack Release [0-9]+(\.[0-9]+)+/ }
end

View File

@ -18,7 +18,7 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
# build script which wraps around test-kitchen to test the systemvm # build script which wraps around nose to test the systemvm
function usage() { function usage() {
cat <<END cat <<END
@ -150,9 +150,15 @@ function setup_ruby() {
bundle check || bundle install ${bundle_args} bundle check || bundle install ${bundle_args}
} }
function setup_python() {
which pip || sudo easy_install pip
pip install nose paramiko python-vagrant envassert cuisine fabric
}
function prepare() { function prepare() {
log INFO "preparing for build" log INFO "preparing for build"
setup_ruby setup_ruby
setup_python
rm -f systemvm.iso rm -f systemvm.iso
} }
@ -174,10 +180,11 @@ function vagrant_provision() {
log INFO "vagrant up complete" log INFO "vagrant up complete"
} }
function serverspec() { function nose() {
log INFO "invoking serverspec" log INFO "invoking nose"
bundle exec rake spec cd ../../../test/systemvm
log INFO "serverspec complete" mkdir -p target/test-reports
nosetests --with-xunit --xunit-file=target/test-reports/xunit.xml
} }
function vagrant_destroy() { function vagrant_destroy() {
@ -185,6 +192,7 @@ function vagrant_destroy() {
vagrant destroy -f vagrant destroy -f
log INFO "vagrant destroy complete" log INFO "vagrant destroy complete"
} }
### ###
### Main invocation ### Main invocation
### ###
@ -196,7 +204,7 @@ function main() {
add_on_exit vagrant_destroy add_on_exit vagrant_destroy
vagrant_up vagrant_up
vagrant_provision vagrant_provision
serverspec nose
add_on_exit log INFO "BUILD SUCCESSFUL" add_on_exit log INFO "BUILD SUCCESSFUL"
} }