From 1925451f6741379c1ac9ab5d3ce8b2e787513143 Mon Sep 17 00:00:00 2001 From: John Dewey Date: Thu, 9 May 2013 16:06:19 -0700 Subject: [PATCH] Gave better examples of how to test templates I wanted to work off what abe did to give examples to others on ways to add attributes and test conditionals. --- Gemfile.lock | 1 - spec/api_spec.rb | 72 +++++++++++++++++++++++++++++++++++--- spec/scheduler_spec.rb | 8 ++++- spec/spec_helper.rb | 11 ------ spec/volume-redhat_spec.rb | 8 +++++ spec/volume_spec.rb | 18 +++++++--- 6 files changed, 95 insertions(+), 23 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f07e520..3e8d9ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -160,7 +160,6 @@ PLATFORMS DEPENDENCIES berkshelf (~> 1.4.0) - celluloid (= 0.13.0) chef (~> 10.18.2) chefspec (~> 1.0.0) foodcritic (~> 2.1.0) diff --git a/spec/api_spec.rb b/spec/api_spec.rb index 2edb67e..4c703ea 100644 --- a/spec/api_spec.rb +++ b/spec/api_spec.rb @@ -7,12 +7,18 @@ describe "cinder::api" do @chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS @node = @chef_run.node @node.set["cinder"]["syslog"]["use"] = true - @node.set["cinder"]["volume"]["volume_driver"] = "cinder.volume.driver.RBDDriver" @chef_run.converge "cinder::api" end expect_runs_openstack_common_logging_recipe + it "doesn't run logging recipe" do + chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + chef_run.converge "cinder::api" + + expect(chef_run).not_to include_recipe "openstack-common::logging" + end + it "installs cinder api packages" do expect(@chef_run).to upgrade_package "cinder-common" expect(@chef_run).to upgrade_package "cinder-api" @@ -43,6 +49,53 @@ describe "cinder::api" do expect_creates_cinder_conf "service[cinder-api]" + describe "cinder.conf" do + before do + @file = "/etc/cinder/cinder.conf" + end + + it "runs logging recipe if node attributes say to" do + expect(@chef_run).to create_file_with_content @file, + "log_config = /etc/openstack/logging.conf" + end + + it "doesn't run logging recipe" do + chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + chef_run.converge "cinder::api" + + expect(chef_run).not_to create_file_with_content @file, + "log_config = /etc/openstack/logging.conf" + end + + it "has rbd driver settings" do + chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + node = chef_run.node + node.set["cinder"]["volume"] = { + "volume_driver" => "cinder.volume.driver.RBDDriver" + } + chef_run.converge "cinder::api" + + expect(chef_run).to create_file_with_content @file, + /^rbd_/ + expect(chef_run).not_to create_file_with_content @file, + /^netapp_/ + end + + it "has netapp driver settings" do + chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + node = chef_run.node + node.set["cinder"]["volume"] = { + "volume_driver" => "cinder.volume.netapp.NetAppISCSIDriver" + } + chef_run.converge "cinder::api" + + expect(chef_run).to create_file_with_content @file, + /^netapp_/ + expect(chef_run).not_to create_file_with_content @file, + /^rbd_/ + end + end + it "runs db migrations" do cmd = "cinder-manage db sync" expect(@chef_run).to execute_command cmd @@ -61,10 +114,19 @@ describe "cinder::api" do expect(sprintf("%o", @file.mode)).to eq "644" end - it "template contents" do - expect(@chef_run).to create_file_with_content "/etc/cinder/api-paste.ini", "autogenerated" - expect(@chef_run).to create_file_with_content "/etc/cinder/api-paste.ini", "service" - expect(@chef_run).not_to create_file_with_content "/etc/cinder/api-paste.ini", "signing_dir" + it "has signing_dir with auth_strategy is pki" do + chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + node = chef_run.node + node.set["openstack"]["auth"]["strategy"] = "pki" + chef_run.converge "cinder::api" + + expect(chef_run).to create_file_with_content @file.name, + "signing_dir = /var/cache/cinder/api" + end + + it "does not have signing_dir when auth strategy is not pki" do + expect(@chef_run).not_to create_file_with_content @file.name, + "signing_dir = /var/cache/cinder/api" end it "notifies nova-api-ec2 restart" do diff --git a/spec/scheduler_spec.rb b/spec/scheduler_spec.rb index a2d5a84..cd9f500 100644 --- a/spec/scheduler_spec.rb +++ b/spec/scheduler_spec.rb @@ -7,12 +7,18 @@ describe "cinder::scheduler" do @chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS @node = @chef_run.node @node.set["cinder"]["syslog"]["use"] = true - @node.set["cinder"]["volume"]["volume_driver"] = "cinder.volume.driver.RBDDriver" @chef_run.converge "cinder::scheduler" end expect_runs_openstack_common_logging_recipe + it "doesn't run logging recipe" do + chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + chef_run.converge "cinder::api" + + expect(chef_run).not_to include_recipe "openstack-common::logging" + end + it "installs cinder api packages" do expect(@chef_run).to upgrade_package "cinder-scheduler" expect(@chef_run).to upgrade_package "python-mysqldb" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 76ab546..2823379 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -45,17 +45,6 @@ def expect_creates_cinder_conf service, action=:restart expect(sprintf("%o", @file.mode)).to eq "644" end - it "template contents" do - expect(@chef_run).to create_file_with_content "/etc/cinder/cinder.conf", "autogenerated" - expect(@chef_run).to create_file_with_content "/etc/cinder/cinder.conf", "logging.conf" - expect(@chef_run).to create_file_with_content "/etc/cinder/cinder.conf", "lock_path=/var/lock/cinder" - expect(@chef_run).to create_file_with_content "/etc/cinder/cinder.conf", "rbd_pool=rbd" - expect(@chef_run).to create_file_with_content "/etc/cinder/cinder.conf", "iscsi_helper=tgtadm" - expect(@chef_run).to create_file_with_content "/etc/cinder/cinder.conf", "RBDDriver" - expect(@chef_run).not_to create_file_with_content "/etc/cinder/cinder.conf", "NetAppISCSIDriver" - - end - it "notifies nova-api-ec2 restart" do expect(@file).to notify service, action end diff --git a/spec/volume-redhat_spec.rb b/spec/volume-redhat_spec.rb index 4e12f19..c2a4936 100644 --- a/spec/volume-redhat_spec.rb +++ b/spec/volume-redhat_spec.rb @@ -30,6 +30,14 @@ describe "cinder::volume" do expect(@chef_run).to set_service_to_start_on_boot "tgtd" end + it "has redhat include" do + file = "/etc/tgt/targets.conf" + expect(@chef_run).to create_file_with_content file, + "include /var/lib/cinder/volumes/*" + expect(@chef_run).not_to create_file_with_content file, + "include /etc/tgt/conf.d/*.conf" + end + it "has different tgt" do expect(@chef_run).to create_file_with_content "/etc/tgt/targets.conf", "/var/lib/cinder/volumes" end diff --git a/spec/volume_spec.rb b/spec/volume_spec.rb index 3029b39..7b27f94 100644 --- a/spec/volume_spec.rb +++ b/spec/volume_spec.rb @@ -7,12 +7,18 @@ describe "cinder::volume" do @chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS @node = @chef_run.node @node.set["cinder"]["syslog"]["use"] = true - @node.set["cinder"]["volume"]["volume_driver"] = "cinder.volume.driver.RBDDriver" @chef_run.converge "cinder::volume" end expect_runs_openstack_common_logging_recipe + it "doesn't run logging recipe" do + chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + chef_run.converge "cinder::api" + + expect(chef_run).not_to include_recipe "openstack-common::logging" + end + it "installs cinder volume packages" do expect(@chef_run).to upgrade_package "cinder-volume" expect(@chef_run).to upgrade_package "python-mysqldb" @@ -45,13 +51,15 @@ describe "cinder::volume" do expect(sprintf("%o", @file.mode)).to eq "600" end - it "notifies nova-api-ec2 restart" do + it "notifies iscsi restart" do expect(@file).to notify "service[iscsitarget]", :restart end - it "template contents" do - expect(@chef_run).to create_file_with_content "/etc/tgt/targets.conf", "autogenerated" - expect(@chef_run).to create_file_with_content "/etc/tgt/targets.conf", "/etc/tgt/conf.d" + it "has ubuntu include" do + expect(@chef_run).to create_file_with_content @file.name, + "include /etc/tgt/conf.d/*.conf" + expect(@chef_run).not_to create_file_with_content @file.name, + "include /var/lib/cinder/volumes/*" end end