From e405e9479751d6bf767232746a963f7cd94f0214 Mon Sep 17 00:00:00 2001 From: Leo Simons Date: Wed, 6 Aug 2014 13:47:13 +0200 Subject: [PATCH] Replace serverspec with nose in systemvm test.sh Also remove the serverspec-specific files. --- test/systemvm/README.md | 2 +- test/systemvm/__init__.py | 8 +++ test/systemvm/test_hello_systemvm.py | 8 +-- tools/vagrant/systemvm/.rspec | 3 - tools/vagrant/systemvm/Gemfile | 4 -- tools/vagrant/systemvm/README.md | 16 ++--- tools/vagrant/systemvm/Rakefile | 25 ------- tools/vagrant/systemvm/Vagrantfile | 2 +- tools/vagrant/systemvm/spec/spec_helper.rb | 69 ------------------- .../spec/test_cloudstack_metadata_spec.rb | 23 ------- tools/vagrant/systemvm/test.sh | 20 ++++-- 11 files changed, 36 insertions(+), 144 deletions(-) delete mode 100644 tools/vagrant/systemvm/.rspec delete mode 100644 tools/vagrant/systemvm/Rakefile delete mode 100644 tools/vagrant/systemvm/spec/spec_helper.rb delete mode 100644 tools/vagrant/systemvm/spec/test_cloudstack_metadata_spec.rb diff --git a/test/systemvm/README.md b/test/systemvm/README.md index 7473fb8863f..b23eab65663 100644 --- a/test/systemvm/README.md +++ b/test/systemvm/README.md @@ -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 ============= diff --git a/test/systemvm/__init__.py b/test/systemvm/__init__.py index 3c4dd4b956d..fa79acfda24 100644 --- a/test/systemvm/__init__.py +++ b/test/systemvm/__init__.py @@ -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 diff --git a/test/systemvm/test_hello_systemvm.py b/test/systemvm/test_hello_systemvm.py index ce33c3be960..ee231b27608 100644 --- a/test/systemvm/test_hello_systemvm.py +++ b/test/systemvm/test_hello_systemvm.py @@ -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!') diff --git a/tools/vagrant/systemvm/.rspec b/tools/vagrant/systemvm/.rspec deleted file mode 100644 index ba8e4a3a093..00000000000 --- a/tools/vagrant/systemvm/.rspec +++ /dev/null @@ -1,3 +0,0 @@ ---format documentation ---format RspecJunitFormatter ---out rspec.xml diff --git a/tools/vagrant/systemvm/Gemfile b/tools/vagrant/systemvm/Gemfile index 32e7896753d..cd0fea4b1b6 100644 --- a/tools/vagrant/systemvm/Gemfile +++ b/tools/vagrant/systemvm/Gemfile @@ -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' diff --git a/tools/vagrant/systemvm/README.md b/tools/vagrant/systemvm/README.md index 9f2536db78a..8569d57f636 100644 --- a/tools/vagrant/systemvm/README.md +++ b/tools/vagrant/systemvm/README.md @@ -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. diff --git a/tools/vagrant/systemvm/Rakefile b/tools/vagrant/systemvm/Rakefile deleted file mode 100644 index 042a1e7d977..00000000000 --- a/tools/vagrant/systemvm/Rakefile +++ /dev/null @@ -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 diff --git a/tools/vagrant/systemvm/Vagrantfile b/tools/vagrant/systemvm/Vagrantfile index 56f3e0b3aa5..c5aa7aac4d9 100644 --- a/tools/vagrant/systemvm/Vagrantfile +++ b/tools/vagrant/systemvm/Vagrantfile @@ -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 diff --git a/tools/vagrant/systemvm/spec/spec_helper.rb b/tools/vagrant/systemvm/spec/spec_helper.rb deleted file mode 100644 index a4839bb5bdf..00000000000 --- a/tools/vagrant/systemvm/spec/spec_helper.rb +++ /dev/null @@ -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 diff --git a/tools/vagrant/systemvm/spec/test_cloudstack_metadata_spec.rb b/tools/vagrant/systemvm/spec/test_cloudstack_metadata_spec.rb deleted file mode 100644 index cd239af4ecf..00000000000 --- a/tools/vagrant/systemvm/spec/test_cloudstack_metadata_spec.rb +++ /dev/null @@ -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 diff --git a/tools/vagrant/systemvm/test.sh b/tools/vagrant/systemvm/test.sh index f44ba7fae3d..4db5bea3e7c 100755 --- a/tools/vagrant/systemvm/test.sh +++ b/tools/vagrant/systemvm/test.sh @@ -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 <