require 'spec_helper'

files = { "cinder.conf"=> 640, "api-paste.ini"=> 640, "policy.json"=> 644, "rootwrap.conf"=> 640 }  
files.each do |file, mode|
  describe file("/etc/cinder/#{file}") do
    it { should be_mode mode }
    it { should be_owned_by 'cinder' } 
    it { should be_grouped_into'cinder' } 
  end
end 

files = {"cinder-api.log"=> 'cinder', "cinder-volume.log"=> 'cinder', "cinder-scheduler.log"=> 'cinder', "cinder-manage.log"=> 'root'}
files.each do |file, owner|
  file_exists = file("/var/log/cinder/#(file)").exists?
  describe file("/var/log/cinder/#{file}"), :if => file_exists do
    it { should be_mode 644 }
    it { should be_owned_by owner }
    it { should be_grouped_into 'adm' }
  end
end

describe file('/etc/logrotate.d/cinder') do
  it { should exist }
  file_contents = [ '# Generated by Ansible.',
         '# Local modifications will be overwritten.',
         '',
         '/var/log/cinder/*.log',
         '{',
         '  daily',
         '  missingok',
         '  rotate 7',
         '  compress',
         '}']
  file_contents.each do |file_line|
    it { should contain file_line }
  end
end

describe file('/etc/cinder/cinder.conf') do
  it { should contain 'log_dir = /var/log/cinder' }
  it { should contain 'debug = {{ cinder.logging.debug }}' }
end 

