mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
Replace serverspec with nose in systemvm test.sh
Also remove the serverspec-specific files.
This commit is contained in:
parent
2188d8d633
commit
e405e94797
@ -5,7 +5,7 @@ see ../../tools/vagrant/systemvm.
|
||||
|
||||
Then, install dependencies
|
||||
|
||||
pip install nose paramiko python-vagrant envassert cuisine
|
||||
pip install nose paramiko python-vagrant envassert cuisine fabric
|
||||
|
||||
Running tests
|
||||
=============
|
||||
|
||||
@ -15,11 +15,13 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from __future__ import with_statement
|
||||
from vagrant import Vagrant
|
||||
from unittest import TestCase
|
||||
from paramiko.config import SSHConfig
|
||||
from paramiko.client import SSHClient, AutoAddPolicy
|
||||
from fabric.api import env
|
||||
from fabric.api import run, hide
|
||||
from envassert import file, detect
|
||||
|
||||
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
|
||||
# def tearDown(self):
|
||||
# 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
|
||||
|
||||
@ -21,9 +21,9 @@ from nose.plugins.attrib import attr
|
||||
from envassert import file, package, user
|
||||
from cuisine import file_write
|
||||
try:
|
||||
from . import SystemVMTestCase
|
||||
from . import SystemVMTestCase, has_line
|
||||
except (ImportError, ValueError):
|
||||
from systemvm import SystemVMTestCase
|
||||
from systemvm import SystemVMTestCase, has_line
|
||||
|
||||
|
||||
class HelloSystemVMTestCase(SystemVMTestCase):
|
||||
@ -47,5 +47,5 @@ class HelloSystemVMTestCase(SystemVMTestCase):
|
||||
@attr(tags=["systemvm"], required_hardware="true")
|
||||
def test_hello_systemvm_cuisine(self):
|
||||
"""Test we can run cuisine on the systemvm"""
|
||||
file_write('/tmp/run_cuisine', 'success!\n')
|
||||
assert file.has_line('/tmp/run_cuisine', 'success!')
|
||||
file_write('/tmp/run_cuisine', '\n\nsuccess!\n')
|
||||
assert has_line('/tmp/run_cuisine', 'success!')
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
--format documentation
|
||||
--format RspecJunitFormatter
|
||||
--out rspec.xml
|
||||
@ -17,8 +17,4 @@
|
||||
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'rake'
|
||||
gem 'rspec', '~> 2.99'
|
||||
gem 'serverspec', '~> 1.11.0'
|
||||
gem 'rspec_junit_formatter'
|
||||
gem 'vagrant-wrapper'
|
||||
|
||||
@ -18,13 +18,13 @@ under the License.
|
||||
===========================================================
|
||||
|
||||
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.
|
||||
|
||||
@ -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
|
||||
2
tools/vagrant/systemvm/Vagrantfile
vendored
2
tools/vagrant/systemvm/Vagrantfile
vendored
@ -22,7 +22,7 @@ include RbConfig
|
||||
|
||||
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 'Using the default VPC_IP=192.168.56.30'
|
||||
end
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
@ -18,7 +18,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# 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() {
|
||||
cat <<END
|
||||
@ -150,9 +150,15 @@ function setup_ruby() {
|
||||
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() {
|
||||
log INFO "preparing for build"
|
||||
setup_ruby
|
||||
setup_python
|
||||
rm -f systemvm.iso
|
||||
}
|
||||
|
||||
@ -174,10 +180,11 @@ function vagrant_provision() {
|
||||
log INFO "vagrant up complete"
|
||||
}
|
||||
|
||||
function serverspec() {
|
||||
log INFO "invoking serverspec"
|
||||
bundle exec rake spec
|
||||
log INFO "serverspec complete"
|
||||
function nose() {
|
||||
log INFO "invoking nose"
|
||||
cd ../../../test/systemvm
|
||||
mkdir -p target/test-reports
|
||||
nosetests --with-xunit --xunit-file=target/test-reports/xunit.xml
|
||||
}
|
||||
|
||||
function vagrant_destroy() {
|
||||
@ -185,6 +192,7 @@ function vagrant_destroy() {
|
||||
vagrant destroy -f
|
||||
log INFO "vagrant destroy complete"
|
||||
}
|
||||
|
||||
###
|
||||
### Main invocation
|
||||
###
|
||||
@ -196,7 +204,7 @@ function main() {
|
||||
add_on_exit vagrant_destroy
|
||||
vagrant_up
|
||||
vagrant_provision
|
||||
serverspec
|
||||
nose
|
||||
add_on_exit log INFO "BUILD SUCCESSFUL"
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user