summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-08-13 10:22:57 -0700
committerGitHub <noreply@github.com>2018-08-13 10:22:57 -0700
commit606267f92d21cefaf5e1e7e93db06cd645eaab58 (patch)
tree5a68dd15ca58c80d930d5afb6d884013abd81d7a
parent1d874bf5ef81f884b60284597753cec8de492066 (diff)
parentc51c36c94f039f9da8338dd02a587c458a5f92e5 (diff)
downloadchef-606267f92d21cefaf5e1e7e93db06cd645eaab58.tar.gz
Merge pull request #7529 from chef/lcg/rspec-testing
Run rspec tests within a kitchen container on CentOS 7
-rw-r--r--.travis.yml20
-rw-r--r--kitchen-tests/Berksfile1
-rw-r--r--kitchen-tests/cookbooks/rspec/metadata.rb8
-rw-r--r--kitchen-tests/cookbooks/rspec/recipes/default.rb13
-rw-r--r--kitchen-tests/cookbooks/rspec/templates/run-chef-rspec11
-rw-r--r--kitchen-tests/kitchen.travis.yml7
-rw-r--r--lib/chef/provider/mount/mount.rb4
-rw-r--r--spec/functional/resource/mount_spec.rb2
-rw-r--r--spec/functional/resource/yum_package_spec.rb6
-rw-r--r--spec/unit/provider/mount/mount_spec.rb1
-rw-r--r--spec/unit/provider/package/rubygems_spec.rb19
11 files changed, 85 insertions, 7 deletions
diff --git a/.travis.yml b/.travis.yml
index cade7e5fca..d6c6cd0f04 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,7 +13,6 @@ before_install:
- gem install bundler -v $(grep :bundler omnibus_overrides.rb | cut -d'"' -f2)
- bundle --version
- rm -f .bundle/config
- - gem uninstall rspec -v 3.8.0
before_script:
# force all .rspec tests into progress display to reduce line count
@@ -322,6 +321,25 @@ matrix:
- cat /tmp/out.txt
- sudo cat /var/log/squid3/cache.log
- sudo cat /var/log/squid3/access.log
+ # Use test-kitchen to launch a centos docker container to run the full rspec tests against. This catches
+ # errors in travis, before PRs are merged, hopefully before they become errors in jenkins.
+ - rvm: 2.4.4
+ services: docker
+ sudo: required
+ gemfile: kitchen-tests/Gemfile
+ before_install:
+ - gem update --system $(grep rubygems omnibus_overrides.rb | cut -d'"' -f2)
+ - gem install bundler -v $(grep :bundler omnibus_overrides.rb | cut -d'"' -f2)
+ before_script:
+ - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
+ - cd kitchen-tests
+ script:
+ - bundle exec kitchen test rspec-centos-7
+ after_failure:
+ - cat .kitchen/logs/kitchen.log
+ env:
+ - RSPEC_CENTOS=7
+ - KITCHEN_YAML=kitchen.travis.yml
notifications:
on_change: true
diff --git a/kitchen-tests/Berksfile b/kitchen-tests/Berksfile
index 50e09ebf3b..d699452ebe 100644
--- a/kitchen-tests/Berksfile
+++ b/kitchen-tests/Berksfile
@@ -1,3 +1,4 @@
source "https://supermarket.chef.io"
cookbook "end_to_end", path: "cookbooks/end_to_end"
+cookbook "rspec", path: "cookbooks/rspec"
diff --git a/kitchen-tests/cookbooks/rspec/metadata.rb b/kitchen-tests/cookbooks/rspec/metadata.rb
new file mode 100644
index 0000000000..56fb816ce4
--- /dev/null
+++ b/kitchen-tests/cookbooks/rspec/metadata.rb
@@ -0,0 +1,8 @@
+name "rspec"
+license "Apache-2.0"
+description "Utility cookbook for rspec testing"
+version "1.0.0"
+
+chef_version ">= 14"
+issues_url "https://github.com/chef/chef/issues"
+source_url "https://github.com/chef/chef"
diff --git a/kitchen-tests/cookbooks/rspec/recipes/default.rb b/kitchen-tests/cookbooks/rspec/recipes/default.rb
new file mode 100644
index 0000000000..4dc1c10d99
--- /dev/null
+++ b/kitchen-tests/cookbooks/rspec/recipes/default.rb
@@ -0,0 +1,13 @@
+# we're using chef-client now as a glorified way to push a file to the remote host
+# if we had a way to turn off chef-client converge and push arbitrary files to the
+# remote this complexity could be removed.
+template "/usr/local/bin/run-chef-rspec" do
+ source "run-chef-rspec"
+ mode 0755
+end
+
+# do NOT even think of trying to add an execute resource here to launch rspec.
+# chefception is proven to be a bad idea, and the rspec tests that really launch
+# chef-client will likely break due to the outer chef-client run. i also do not
+# want to debug rspec's output being filtered through chef-client's logger -- fuck
+# all of that noise.
diff --git a/kitchen-tests/cookbooks/rspec/templates/run-chef-rspec b/kitchen-tests/cookbooks/rspec/templates/run-chef-rspec
new file mode 100644
index 0000000000..54c4297479
--- /dev/null
+++ b/kitchen-tests/cookbooks/rspec/templates/run-chef-rspec
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# remove ip6 entries for docker
+egrep -v "ip6" /etc/hosts > /etc/hosts.new
+cp /etc/hosts.new /etc/hosts
+
+export PATH=/opt/chef/embedded/bin:$PATH
+cd /opt/chef/embedded/apps/chef
+
+/opt/chef/embedded/bin/bundle install
+/opt/chef/embedded/bin/bundle exec /opt/chef/embedded/bin/rspec --format progress
diff --git a/kitchen-tests/kitchen.travis.yml b/kitchen-tests/kitchen.travis.yml
index 3736fb2fab..aa15da8795 100644
--- a/kitchen-tests/kitchen.travis.yml
+++ b/kitchen-tests/kitchen.travis.yml
@@ -69,6 +69,7 @@ platforms:
image: dokken/centos-7
pid_one_command: /usr/lib/systemd/systemd
intermediate_instructions:
+ - RUN yum -y install e2fsprogs
- RUN sed -i -e "s/Defaults.*requiretty.*/Defaults !requiretty/g" /etc/sudoers
- name: fedora-latest
@@ -108,3 +109,9 @@ suites:
- name: end-to-end
run_list:
- recipe[end_to_end::default]
+ - name: rspec
+ run_list:
+ - recipe[rspec]
+ lifecycle:
+ post_converge:
+ - remote: /usr/local/bin/run-chef-rspec
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb
index 55be15d8c5..7852c8dfdf 100644
--- a/lib/chef/provider/mount/mount.rb
+++ b/lib/chef/provider/mount/mount.rb
@@ -53,6 +53,10 @@ class Chef
def enabled?
# Check to see if there is a entry in /etc/fstab. Last entry for a volume wins.
enabled = false
+ unless ::File.exist?("/etc/fstab")
+ logger.debug "/etc/fstab not found, treating mount as not-enabled"
+ return
+ end
::File.foreach("/etc/fstab") do |line|
case line
when /^[#\s]/
diff --git a/spec/functional/resource/mount_spec.rb b/spec/functional/resource/mount_spec.rb
index f4e528c755..f6c7f91bcd 100644
--- a/spec/functional/resource/mount_spec.rb
+++ b/spec/functional/resource/mount_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
-# Copyright:: Copyright 2013-2016, Chef Software Inc.
+# Copyright:: Copyright 2013-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb
index 17e4669255..3735e67cf2 100644
--- a/spec/functional/resource/yum_package_spec.rb
+++ b/spec/functional/resource/yum_package_spec.rb
@@ -443,11 +443,13 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do
expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
end
- it "downgrade on a local file raises an error" do
+ it "downgrade on a local file is ignored" do
preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
yum_package.version "1.2-1"
yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
- expect { yum_package.run_action(:install) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
end
it "downgrade on a local file with allow_downgrade true works" do
diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb
index 2af3c93fc9..2353d992d0 100644
--- a/spec/unit/provider/mount/mount_spec.rb
+++ b/spec/unit/provider/mount/mount_spec.rb
@@ -43,6 +43,7 @@ describe Chef::Provider::Mount::Mount do
describe "when discovering the current fs state" do
before do
allow(@provider).to receive(:shell_out_compacted!).and_return(OpenStruct.new(stdout: ""))
+ allow(::File).to receive(:exist?).with("/etc/fstab").and_return(true)
allow(::File).to receive(:foreach).with("/etc/fstab")
end
diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb
index 6b33ab97f9..2e9888fb78 100644
--- a/spec/unit/provider/package/rubygems_spec.rb
+++ b/spec/unit/provider/package/rubygems_spec.rb
@@ -27,6 +27,19 @@ module GemspecBackcompatCreator
end
end
+# this is a global variable we construct of the highest rspec-core version which is installed, using APIs which
+# will break out of the bundle -- and done this way so that we can mock all these internal Gem APIs later...
+class RspecVersionString
+ def self.rspec_version_string
+ @rspec_version_string ||= begin
+ stubs = Gem::Specification.send(:installed_stubs, Gem::Specification.dirs, "rspec-core-*.gemspec")
+ stubs.select! { |stub| stub.name == "rspec-core" && Gem::Dependency.new("rspec-core", ">= 0").requirement.satisfied_by?(stub.version) }
+ stubs.max_by(&:version).version.to_s
+ end
+ end
+end
+RspecVersionString.rspec_version_string
+
require "spec_helper"
require "ostruct"
@@ -57,7 +70,7 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do
end
it "determines the installed versions of gems from the source index (part2: the unmockening)" do
- expected = ["rspec-core", Gem::Version.new(RSpec::Core::Version::STRING)]
+ expected = ["rspec-core", Gem::Version.new( RspecVersionString.rspec_version_string )]
actual = @gem_env.installed_versions(Gem::Dependency.new("rspec-core", nil)).map { |spec| [spec.name, spec.version] }
expect(actual).to include(expected)
end
@@ -247,7 +260,7 @@ describe Chef::Provider::Package::Rubygems::AlternateGemEnvironment do
end
skip("cant find your gem executable") if path_to_gem.empty?
gem_env = Chef::Provider::Package::Rubygems::AlternateGemEnvironment.new(path_to_gem)
- expected = ["rspec-core", Gem::Version.new(RSpec::Core::Version::STRING)]
+ expected = ["rspec-core", Gem::Version.new( RspecVersionString.rspec_version_string )]
actual = gem_env.installed_versions(Gem::Dependency.new("rspec-core", nil)).map { |s| [s.name, s.version] }
expect(actual).to include(expected)
end
@@ -400,7 +413,7 @@ describe Chef::Provider::Package::Rubygems do
end
describe "when new_resource version is an rspec version" do
- let(:current_version) { RSpec::Core::Version::STRING }
+ let(:current_version) { RspecVersionString.rspec_version_string }
let(:target_version) { current_version }
it "triggers a gem configuration load so a later one will not stomp its config values" do