# Chef InSpec test for recipe irrigate-ceph::default

# The Chef InSpec reference, with examples and extensive documentation, can be
# found at https://docs.chef.io/inspec/resources/
#
packages = %w(
  apt-transport-https
  cephadm
  ceph-common
  cloud-guest-utils
  curl
  docker-ce
  gnupg
  jq
  lvm2
  neovim
  python3
  python3-dev
)

packages.each do |package_name|
  describe package(package_name) do
    it { should be_installed }
  end
end

# cephadm will use podman over docker if it's installed, we prefer docker for consistency with the rest of our toolchain
describe package('podman') do
  it { should_not be_installed }
end

describe user('ceph') do
  it { should exist }
  its('home') { should eq '/home/ceph' }
  its('shell') { should eq '/bin/bash' }
end

describe file('/etc/sudoers.d/ceph') do
  its('content') { should match(/ceph ALL=\(ALL\) NOPASSWD:ALL/) }
end

describe file('/home/ceph/.ssh/authorized_keys') do
  its('content') { should match(/ssh-ed25519 \S+ ceph/) }
end

describe file('/usr/local/bin/ceph-dashboard-monitor.sh') do
  it { should exist }
  it { should be_file }
  its('mode') { should cmp '0755' }
end

describe cron do
  it { should have_entry '*/5 * * * * timeout -k 120 60 /usr/local/bin/ceph-dashboard-monitor.sh >/dev/null 2>&1' }
end

describe json('/etc/docker/daemon.json') do
  its('log-driver') { should eq 'json-file' }
  its(%w(log-opts max-size)) { should eq '10m' }
  its(%w(log-opts max-file)) { should eq '24' }
end
