| 1 |
# Copyright (C) 2013 Cloudwatt <[email protected]> |
| 2 |
# Copyright (C) 2013, 2014 iWeb Technologies Inc. |
| 3 |
# Copyright (C) 2014 Nine Internet Solutions AG |
| 4 |
# |
| 5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
# you may not use this file except in compliance with the License. |
| 7 |
# You may obtain a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
# See the License for the specific language governing permissions and |
| 15 |
# limitations under the License. |
| 16 |
# |
| 17 |
# Author: Loic Dachary <[email protected]> |
| 18 |
# Author: David Moreau Simard <[email protected]> |
| 19 |
# Author: David Gurtner <[email protected]> |
| 20 |
# |
| 21 |
require 'spec_helper' |
| 22 |
|
| 23 |
describe 'ceph::mon' do |
| 24 |
shared_examples 'ceph::mon on Ubuntu 14.04' do |
| 25 |
before do |
| 26 |
facts.merge!( :osfamily => 'Debian', |
| 27 |
:operatingsystem => 'Ubuntu', |
| 28 |
:operatingsystemrelease => '14.04', |
| 29 |
:service_provider => 'upstart' ) |
| 30 |
end |
| 31 |
|
| 32 |
context 'with default params' do |
| 33 |
let :title do |
| 34 |
'A' |
| 35 |
end |
| 36 |
|
| 37 |
it { should raise raise_error(Puppet::Error, /authentication_type cephx requires either key or keyring to be set but both are undef/) } |
| 38 |
end |
| 39 |
|
| 40 |
context 'with key' do |
| 41 |
let :title do |
| 42 |
'A' |
| 43 |
end |
| 44 |
|
| 45 |
let :params do |
| 46 |
{ |
| 47 |
:key => 'AQATGHJTUCBqIBAA7M2yafV1xctn1pgr3GcKPg==', |
| 48 |
} |
| 49 |
end |
| 50 |
|
| 51 |
it { should contain_service('ceph-mon-A').with('ensure' => 'running') } |
| 52 |
|
| 53 |
it { should contain_exec('create-keyring-A').with( |
| 54 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 55 |
set -ex |
| 56 |
cat > /tmp/ceph-mon-keyring-A << EOF |
| 57 |
[mon.] |
| 58 |
key = AQATGHJTUCBqIBAA7M2yafV1xctn1pgr3GcKPg== |
| 59 |
caps mon = "allow *" |
| 60 |
EOF |
| 61 |
|
| 62 |
chmod 0444 /tmp/ceph-mon-keyring-A |
| 63 |
', |
| 64 |
:unless => '/bin/true # comment to satisfy puppet syntax requirements |
| 65 |
set -ex |
| 66 |
mon_data=$(ceph-mon --cluster ceph --id A --show-config-value mon_data) || exit 1 |
| 67 |
# if ceph-mon fails then the mon is probably not configured yet |
| 68 |
test -e $mon_data/done |
| 69 |
') } |
| 70 |
|
| 71 |
it { should contain_exec('ceph-mon-ceph.client.admin.keyring-A').with( |
| 72 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 73 |
set -ex |
| 74 |
touch /etc/ceph/ceph.client.admin.keyring' |
| 75 |
) } |
| 76 |
|
| 77 |
it { should contain_exec('ceph-mon-mkfs-A').with( |
| 78 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 79 |
set -ex |
| 80 |
mon_data=\$(ceph-mon --cluster ceph --id A --show-config-value mon_data) |
| 81 |
if [ ! -d \$mon_data ] ; then |
| 82 |
mkdir -p \$mon_data |
| 83 |
if getent passwd ceph >/dev/null 2>&1; then |
| 84 |
chown -h ceph:ceph \$mon_data |
| 85 |
if ceph-mon --cluster ceph \ |
| 86 |
--setuser ceph --setgroup ceph \ |
| 87 |
--mkfs \ |
| 88 |
--id A \ |
| 89 |
--keyring /tmp/ceph-mon-keyring-A ; then |
| 90 |
touch \$mon_data/done \$mon_data/upstart \$mon_data/keyring |
| 91 |
chown -h ceph:ceph \$mon_data/done \$mon_data/upstart \$mon_data/keyring |
| 92 |
else |
| 93 |
rm -fr \$mon_data |
| 94 |
fi |
| 95 |
else |
| 96 |
if ceph-mon --cluster ceph \ |
| 97 |
--mkfs \ |
| 98 |
--id A \ |
| 99 |
--keyring /tmp/ceph-mon-keyring-A ; then |
| 100 |
touch \$mon_data/done \$mon_data/upstart \$mon_data/keyring |
| 101 |
else |
| 102 |
rm -fr \$mon_data |
| 103 |
fi |
| 104 |
fi |
| 105 |
fi |
| 106 |
", |
| 107 |
:logoutput => true )} |
| 108 |
|
| 109 |
it { should contain_exec('rm-keyring-A').with('command' => '/bin/rm /tmp/ceph-mon-keyring-A') } |
| 110 |
end |
| 111 |
|
| 112 |
context 'with keyring' do |
| 113 |
let :title do |
| 114 |
'A' |
| 115 |
end |
| 116 |
|
| 117 |
let :params do |
| 118 |
{ |
| 119 |
:keyring => '/etc/ceph/ceph.mon.keyring', |
| 120 |
} |
| 121 |
end |
| 122 |
|
| 123 |
it { should contain_service('ceph-mon-A').with('ensure' => 'running') } |
| 124 |
|
| 125 |
it { should contain_exec('ceph-mon-ceph.client.admin.keyring-A').with( |
| 126 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 127 |
set -ex |
| 128 |
touch /etc/ceph/ceph.client.admin.keyring' |
| 129 |
)} |
| 130 |
|
| 131 |
it { should contain_exec('ceph-mon-mkfs-A').with( |
| 132 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 133 |
set -ex |
| 134 |
mon_data=\$(ceph-mon --cluster ceph --id A --show-config-value mon_data) |
| 135 |
if [ ! -d \$mon_data ] ; then |
| 136 |
mkdir -p \$mon_data |
| 137 |
if getent passwd ceph >/dev/null 2>&1; then |
| 138 |
chown -h ceph:ceph \$mon_data |
| 139 |
if ceph-mon --cluster ceph \ |
| 140 |
--setuser ceph --setgroup ceph \ |
| 141 |
--mkfs \ |
| 142 |
--id A \ |
| 143 |
--keyring /etc/ceph/ceph.mon.keyring ; then |
| 144 |
touch \$mon_data/done \$mon_data/upstart \$mon_data/keyring |
| 145 |
chown -h ceph:ceph \$mon_data/done \$mon_data/upstart \$mon_data/keyring |
| 146 |
else |
| 147 |
rm -fr \$mon_data |
| 148 |
fi |
| 149 |
else |
| 150 |
if ceph-mon --cluster ceph \ |
| 151 |
--mkfs \ |
| 152 |
--id A \ |
| 153 |
--keyring /etc/ceph/ceph.mon.keyring ; then |
| 154 |
touch \$mon_data/done \$mon_data/upstart \$mon_data/keyring |
| 155 |
else |
| 156 |
rm -fr \$mon_data |
| 157 |
fi |
| 158 |
fi |
| 159 |
fi |
| 160 |
", |
| 161 |
:logoutput => true )} |
| 162 |
end |
| 163 |
|
| 164 |
context 'with custom params' do |
| 165 |
let :title do |
| 166 |
'A' |
| 167 |
end |
| 168 |
|
| 169 |
let :params do |
| 170 |
{ |
| 171 |
:public_addr => '127.0.0.1', |
| 172 |
:authentication_type => 'none', |
| 173 |
:cluster => 'testcluster', |
| 174 |
} |
| 175 |
end |
| 176 |
|
| 177 |
it { should contain_service('ceph-mon-A').with('ensure' => 'running') } |
| 178 |
it { should contain_ceph_config('mon.A/public_addr').with_value("127.0.0.1") } |
| 179 |
|
| 180 |
it { should contain_exec('ceph-mon-testcluster.client.admin.keyring-A').with( |
| 181 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 182 |
set -ex |
| 183 |
touch /etc/ceph/testcluster.client.admin.keyring' |
| 184 |
)} |
| 185 |
|
| 186 |
it { should contain_exec('ceph-mon-mkfs-A').with( |
| 187 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 188 |
set -ex |
| 189 |
mon_data=\$(ceph-mon --cluster testcluster --id A --show-config-value mon_data) |
| 190 |
if [ ! -d \$mon_data ] ; then |
| 191 |
mkdir -p \$mon_data |
| 192 |
if getent passwd ceph >/dev/null 2>&1; then |
| 193 |
chown -h ceph:ceph \$mon_data |
| 194 |
if ceph-mon --cluster testcluster \ |
| 195 |
--setuser ceph --setgroup ceph \ |
| 196 |
--mkfs \ |
| 197 |
--id A \ |
| 198 |
--keyring /dev/null ; then |
| 199 |
touch \$mon_data/done \$mon_data/upstart \$mon_data/keyring |
| 200 |
chown -h ceph:ceph \$mon_data/done \$mon_data/upstart \$mon_data/keyring |
| 201 |
else |
| 202 |
rm -fr \$mon_data |
| 203 |
fi |
| 204 |
else |
| 205 |
if ceph-mon --cluster testcluster \ |
| 206 |
--mkfs \ |
| 207 |
--id A \ |
| 208 |
--keyring /dev/null ; then |
| 209 |
touch \$mon_data/done \$mon_data/upstart \$mon_data/keyring |
| 210 |
else |
| 211 |
rm -fr \$mon_data |
| 212 |
fi |
| 213 |
fi |
| 214 |
fi |
| 215 |
", |
| 216 |
:logoutput => true )} |
| 217 |
end |
| 218 |
|
| 219 |
context 'with ensure absent' do |
| 220 |
let :title do |
| 221 |
'A' |
| 222 |
end |
| 223 |
|
| 224 |
let :params do |
| 225 |
{ |
| 226 |
:ensure => 'absent', |
| 227 |
:public_addr => '127.0.0.1', |
| 228 |
:authentication_type => 'none', |
| 229 |
:cluster => 'testcluster', |
| 230 |
} |
| 231 |
end |
| 232 |
|
| 233 |
it { should contain_service('ceph-mon-A').with('ensure' => 'stopped') } |
| 234 |
|
| 235 |
it { should contain_exec('remove-mon-A').with( |
| 236 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 237 |
set -ex |
| 238 |
mon_data=\$(ceph-mon --cluster testcluster --id A --show-config-value mon_data) |
| 239 |
rm -fr \$mon_data |
| 240 |
", |
| 241 |
:unless => "/bin/true # comment to satisfy puppet syntax requirements |
| 242 |
set -ex |
| 243 |
which ceph-mon || exit 0 # if ceph-mon is not available we already uninstalled ceph and there is nothing to do |
| 244 |
mon_data=\$(ceph-mon --cluster testcluster --id A --show-config-value mon_data) |
| 245 |
test ! -d \$mon_data |
| 246 |
", |
| 247 |
:logoutput => true )} |
| 248 |
end |
| 249 |
end |
| 250 |
|
| 251 |
shared_examples 'ceph::mon on Ubuntu 16.04' do |
| 252 |
before do |
| 253 |
facts.merge!( :osfamily => 'Debian', |
| 254 |
:operatingsystem => 'Ubuntu', |
| 255 |
:operatingsystemrelease => '16.04', |
| 256 |
:service_provider => 'systemd' ) |
| 257 |
end |
| 258 |
|
| 259 |
context 'with default params' do |
| 260 |
let :title do |
| 261 |
'A' |
| 262 |
end |
| 263 |
|
| 264 |
it { should raise_error(Puppet::Error, /authentication_type cephx requires either key or keyring to be set but both are undef/) } |
| 265 |
end |
| 266 |
|
| 267 |
context 'with key' do |
| 268 |
let :title do |
| 269 |
'A' |
| 270 |
end |
| 271 |
|
| 272 |
let :params do |
| 273 |
{ |
| 274 |
:key => 'AQATGHJTUCBqIBAA7M2yafV1xctn1pgr3GcKPg==', |
| 275 |
} |
| 276 |
end |
| 277 |
|
| 278 |
it { should contain_service('ceph-mon-A').with('ensure' => 'running') } |
| 279 |
|
| 280 |
it { should contain_exec('create-keyring-A').with( |
| 281 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 282 |
set -ex |
| 283 |
cat > /tmp/ceph-mon-keyring-A << EOF |
| 284 |
[mon.] |
| 285 |
key = AQATGHJTUCBqIBAA7M2yafV1xctn1pgr3GcKPg== |
| 286 |
caps mon = "allow *" |
| 287 |
EOF |
| 288 |
|
| 289 |
chmod 0444 /tmp/ceph-mon-keyring-A |
| 290 |
', |
| 291 |
:unless => '/bin/true # comment to satisfy puppet syntax requirements |
| 292 |
set -ex |
| 293 |
mon_data=$(ceph-mon --cluster ceph --id A --show-config-value mon_data) || exit 1 |
| 294 |
# if ceph-mon fails then the mon is probably not configured yet |
| 295 |
test -e $mon_data/done |
| 296 |
')} |
| 297 |
|
| 298 |
it { should contain_exec('ceph-mon-ceph.client.admin.keyring-A').with( |
| 299 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 300 |
set -ex |
| 301 |
touch /etc/ceph/ceph.client.admin.keyring' |
| 302 |
)} |
| 303 |
|
| 304 |
it { should contain_exec('ceph-mon-mkfs-A').with( |
| 305 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 306 |
set -ex |
| 307 |
mon_data=\$(ceph-mon --cluster ceph --id A --show-config-value mon_data) |
| 308 |
if [ ! -d \$mon_data ] ; then |
| 309 |
mkdir -p \$mon_data |
| 310 |
if getent passwd ceph >/dev/null 2>&1; then |
| 311 |
chown -h ceph:ceph \$mon_data |
| 312 |
if ceph-mon --cluster ceph \ |
| 313 |
--setuser ceph --setgroup ceph \ |
| 314 |
--mkfs \ |
| 315 |
--id A \ |
| 316 |
--keyring /tmp/ceph-mon-keyring-A ; then |
| 317 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 318 |
chown -h ceph:ceph \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 319 |
else |
| 320 |
rm -fr \$mon_data |
| 321 |
fi |
| 322 |
else |
| 323 |
if ceph-mon --cluster ceph \ |
| 324 |
--mkfs \ |
| 325 |
--id A \ |
| 326 |
--keyring /tmp/ceph-mon-keyring-A ; then |
| 327 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 328 |
else |
| 329 |
rm -fr \$mon_data |
| 330 |
fi |
| 331 |
fi |
| 332 |
fi |
| 333 |
", |
| 334 |
:logoutput => true )} |
| 335 |
|
| 336 |
it { should contain_exec('rm-keyring-A').with('command' => '/bin/rm /tmp/ceph-mon-keyring-A') } |
| 337 |
end |
| 338 |
|
| 339 |
context 'with keyring' do |
| 340 |
let :title do |
| 341 |
'A' |
| 342 |
end |
| 343 |
|
| 344 |
let :params do |
| 345 |
{ |
| 346 |
:keyring => '/etc/ceph/ceph.mon.keyring', |
| 347 |
} |
| 348 |
end |
| 349 |
|
| 350 |
it { should contain_service('ceph-mon-A').with('ensure' => 'running') } |
| 351 |
|
| 352 |
it { should contain_exec('ceph-mon-ceph.client.admin.keyring-A').with( |
| 353 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 354 |
set -ex |
| 355 |
touch /etc/ceph/ceph.client.admin.keyring' |
| 356 |
)} |
| 357 |
|
| 358 |
it { should contain_exec('ceph-mon-mkfs-A').with( |
| 359 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 360 |
set -ex |
| 361 |
mon_data=\$(ceph-mon --cluster ceph --id A --show-config-value mon_data) |
| 362 |
if [ ! -d \$mon_data ] ; then |
| 363 |
mkdir -p \$mon_data |
| 364 |
if getent passwd ceph >/dev/null 2>&1; then |
| 365 |
chown -h ceph:ceph \$mon_data |
| 366 |
if ceph-mon --cluster ceph \ |
| 367 |
--setuser ceph --setgroup ceph \ |
| 368 |
--mkfs \ |
| 369 |
--id A \ |
| 370 |
--keyring /etc/ceph/ceph.mon.keyring ; then |
| 371 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 372 |
chown -h ceph:ceph \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 373 |
else |
| 374 |
rm -fr \$mon_data |
| 375 |
fi |
| 376 |
else |
| 377 |
if ceph-mon --cluster ceph \ |
| 378 |
--mkfs \ |
| 379 |
--id A \ |
| 380 |
--keyring /etc/ceph/ceph.mon.keyring ; then |
| 381 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 382 |
else |
| 383 |
rm -fr \$mon_data |
| 384 |
fi |
| 385 |
fi |
| 386 |
fi |
| 387 |
", |
| 388 |
:logoutput => true )} |
| 389 |
end |
| 390 |
|
| 391 |
context 'with custom params' do |
| 392 |
let :title do |
| 393 |
'A' |
| 394 |
end |
| 395 |
|
| 396 |
let :params do |
| 397 |
{ |
| 398 |
:public_addr => '127.0.0.1', |
| 399 |
:authentication_type => 'none', |
| 400 |
:cluster => 'testcluster', |
| 401 |
} |
| 402 |
end |
| 403 |
|
| 404 |
it { should contain_service('ceph-mon-A').with('ensure' => 'running') } |
| 405 |
it { should contain_ceph_config('mon.A/public_addr').with_value("127.0.0.1") } |
| 406 |
|
| 407 |
it { should contain_exec('ceph-mon-testcluster.client.admin.keyring-A').with( |
| 408 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 409 |
set -ex |
| 410 |
touch /etc/ceph/testcluster.client.admin.keyring' |
| 411 |
)} |
| 412 |
|
| 413 |
it { should contain_exec('ceph-mon-mkfs-A').with( |
| 414 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 415 |
set -ex |
| 416 |
mon_data=\$(ceph-mon --cluster testcluster --id A --show-config-value mon_data) |
| 417 |
if [ ! -d \$mon_data ] ; then |
| 418 |
mkdir -p \$mon_data |
| 419 |
if getent passwd ceph >/dev/null 2>&1; then |
| 420 |
chown -h ceph:ceph \$mon_data |
| 421 |
if ceph-mon --cluster testcluster \ |
| 422 |
--setuser ceph --setgroup ceph \ |
| 423 |
--mkfs \ |
| 424 |
--id A \ |
| 425 |
--keyring /dev/null ; then |
| 426 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 427 |
chown -h ceph:ceph \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 428 |
else |
| 429 |
rm -fr \$mon_data |
| 430 |
fi |
| 431 |
else |
| 432 |
if ceph-mon --cluster testcluster \ |
| 433 |
--mkfs \ |
| 434 |
--id A \ |
| 435 |
--keyring /dev/null ; then |
| 436 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 437 |
else |
| 438 |
rm -fr \$mon_data |
| 439 |
fi |
| 440 |
fi |
| 441 |
fi |
| 442 |
", |
| 443 |
:logoutput => true )} |
| 444 |
end |
| 445 |
|
| 446 |
context 'with ensure absent' do |
| 447 |
let :title do |
| 448 |
'A' |
| 449 |
end |
| 450 |
|
| 451 |
let :params do |
| 452 |
{ |
| 453 |
:ensure => 'absent', |
| 454 |
:public_addr => '127.0.0.1', |
| 455 |
:authentication_type => 'none', |
| 456 |
:cluster => 'testcluster', |
| 457 |
} |
| 458 |
end |
| 459 |
|
| 460 |
it { should contain_service('ceph-mon-A').with('ensure' => 'stopped') } |
| 461 |
|
| 462 |
it { should contain_exec('remove-mon-A').with( |
| 463 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 464 |
set -ex |
| 465 |
mon_data=\$(ceph-mon --cluster testcluster --id A --show-config-value mon_data) |
| 466 |
rm -fr \$mon_data |
| 467 |
", |
| 468 |
:unless => "/bin/true # comment to satisfy puppet syntax requirements |
| 469 |
set -ex |
| 470 |
which ceph-mon || exit 0 # if ceph-mon is not available we already uninstalled ceph and there is nothing to do |
| 471 |
mon_data=\$(ceph-mon --cluster testcluster --id A --show-config-value mon_data) |
| 472 |
test ! -d \$mon_data |
| 473 |
", |
| 474 |
:logoutput => true )} |
| 475 |
end |
| 476 |
end |
| 477 |
|
| 478 |
shared_examples 'ceph::mon on RHEL7' do |
| 479 |
before do |
| 480 |
facts.merge!( :osfamily => 'RedHat', |
| 481 |
:operatingsystem => 'RHEL7', |
| 482 |
:service_provider => 'systemd' ) |
| 483 |
end |
| 484 |
|
| 485 |
context 'with default params' do |
| 486 |
let :title do |
| 487 |
'A' |
| 488 |
end |
| 489 |
|
| 490 |
it { should raise_error(Puppet::Error, /authentication_type cephx requires either key or keyring to be set but both are undef/) } |
| 491 |
end |
| 492 |
|
| 493 |
context 'with key' do |
| 494 |
let :title do |
| 495 |
'A' |
| 496 |
end |
| 497 |
|
| 498 |
let :params do |
| 499 |
{ |
| 500 |
:key => 'AQATGHJTUCBqIBAA7M2yafV1xctn1pgr3GcKPg==', |
| 501 |
} |
| 502 |
end |
| 503 |
|
| 504 |
it { should contain_service('ceph-mon-A').with('ensure' => 'running') } |
| 505 |
|
| 506 |
it { should contain_exec('create-keyring-A').with( |
| 507 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 508 |
set -ex |
| 509 |
cat > /tmp/ceph-mon-keyring-A << EOF |
| 510 |
[mon.] |
| 511 |
key = AQATGHJTUCBqIBAA7M2yafV1xctn1pgr3GcKPg== |
| 512 |
caps mon = "allow *" |
| 513 |
EOF |
| 514 |
|
| 515 |
chmod 0444 /tmp/ceph-mon-keyring-A |
| 516 |
', |
| 517 |
:unless => '/bin/true # comment to satisfy puppet syntax requirements |
| 518 |
set -ex |
| 519 |
mon_data=$(ceph-mon --cluster ceph --id A --show-config-value mon_data) || exit 1 |
| 520 |
# if ceph-mon fails then the mon is probably not configured yet |
| 521 |
test -e $mon_data/done |
| 522 |
')} |
| 523 |
|
| 524 |
it { should contain_exec('ceph-mon-ceph.client.admin.keyring-A').with( |
| 525 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 526 |
set -ex |
| 527 |
touch /etc/ceph/ceph.client.admin.keyring', |
| 528 |
:unless => '/bin/true # comment to satisfy puppet syntax requirements |
| 529 |
set -ex |
| 530 |
test -e /etc/ceph/ceph.client.admin.keyring' |
| 531 |
)} |
| 532 |
|
| 533 |
it { should contain_exec('ceph-mon-mkfs-A').with( |
| 534 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 535 |
set -ex |
| 536 |
mon_data=\$(ceph-mon --cluster ceph --id A --show-config-value mon_data) |
| 537 |
if [ ! -d \$mon_data ] ; then |
| 538 |
mkdir -p \$mon_data |
| 539 |
if getent passwd ceph >/dev/null 2>&1; then |
| 540 |
chown -h ceph:ceph \$mon_data |
| 541 |
if ceph-mon --cluster ceph \ |
| 542 |
--setuser ceph --setgroup ceph \ |
| 543 |
--mkfs \ |
| 544 |
--id A \ |
| 545 |
--keyring /tmp/ceph-mon-keyring-A ; then |
| 546 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 547 |
chown -h ceph:ceph \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 548 |
else |
| 549 |
rm -fr \$mon_data |
| 550 |
fi |
| 551 |
else |
| 552 |
if ceph-mon --cluster ceph \ |
| 553 |
--mkfs \ |
| 554 |
--id A \ |
| 555 |
--keyring /tmp/ceph-mon-keyring-A ; then |
| 556 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 557 |
else |
| 558 |
rm -fr \$mon_data |
| 559 |
fi |
| 560 |
fi |
| 561 |
fi |
| 562 |
", |
| 563 |
:logoutput => true )} |
| 564 |
|
| 565 |
it { should contain_exec('rm-keyring-A').with( |
| 566 |
:command => '/bin/rm /tmp/ceph-mon-keyring-A', |
| 567 |
:unless => '/bin/true # comment to satisfy puppet syntax requirements |
| 568 |
set -ex |
| 569 |
test ! -e /tmp/ceph-mon-keyring-A |
| 570 |
')} |
| 571 |
end |
| 572 |
|
| 573 |
context 'with keyring' do |
| 574 |
let :title do |
| 575 |
'A' |
| 576 |
end |
| 577 |
|
| 578 |
let :params do |
| 579 |
{ |
| 580 |
:keyring => '/etc/ceph/ceph.mon.keyring', |
| 581 |
} |
| 582 |
end |
| 583 |
|
| 584 |
it { should contain_service('ceph-mon-A').with('ensure' => 'running') } |
| 585 |
|
| 586 |
it { should contain_exec('ceph-mon-ceph.client.admin.keyring-A').with( |
| 587 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 588 |
set -ex |
| 589 |
touch /etc/ceph/ceph.client.admin.keyring' |
| 590 |
)} |
| 591 |
|
| 592 |
it { should contain_exec('ceph-mon-mkfs-A').with( |
| 593 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 594 |
set -ex |
| 595 |
mon_data=\$(ceph-mon --cluster ceph --id A --show-config-value mon_data) |
| 596 |
if [ ! -d \$mon_data ] ; then |
| 597 |
mkdir -p \$mon_data |
| 598 |
if getent passwd ceph >/dev/null 2>&1; then |
| 599 |
chown -h ceph:ceph \$mon_data |
| 600 |
if ceph-mon --cluster ceph \ |
| 601 |
--setuser ceph --setgroup ceph \ |
| 602 |
--mkfs \ |
| 603 |
--id A \ |
| 604 |
--keyring /etc/ceph/ceph.mon.keyring ; then |
| 605 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 606 |
chown -h ceph:ceph \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 607 |
else |
| 608 |
rm -fr \$mon_data |
| 609 |
fi |
| 610 |
else |
| 611 |
if ceph-mon --cluster ceph \ |
| 612 |
--mkfs \ |
| 613 |
--id A \ |
| 614 |
--keyring /etc/ceph/ceph.mon.keyring ; then |
| 615 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 616 |
else |
| 617 |
rm -fr \$mon_data |
| 618 |
fi |
| 619 |
fi |
| 620 |
fi |
| 621 |
", |
| 622 |
:logoutput => true )} |
| 623 |
end |
| 624 |
|
| 625 |
context 'with custom params' do |
| 626 |
let :title do |
| 627 |
'A' |
| 628 |
end |
| 629 |
|
| 630 |
let :params do |
| 631 |
{ |
| 632 |
:public_addr => '127.0.0.1', |
| 633 |
:authentication_type => 'none', |
| 634 |
:cluster => 'testcluster', |
| 635 |
} |
| 636 |
end |
| 637 |
|
| 638 |
it { should contain_service('ceph-mon-A').with('ensure' => 'running') } |
| 639 |
it { should contain_ceph_config('mon.A/public_addr').with_value("127.0.0.1") } |
| 640 |
|
| 641 |
it { should contain_exec('ceph-mon-testcluster.client.admin.keyring-A').with( |
| 642 |
:command => '/bin/true # comment to satisfy puppet syntax requirements |
| 643 |
set -ex |
| 644 |
touch /etc/ceph/testcluster.client.admin.keyring' |
| 645 |
)} |
| 646 |
|
| 647 |
it { should contain_exec('ceph-mon-mkfs-A').with( |
| 648 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 649 |
set -ex |
| 650 |
mon_data=\$(ceph-mon --cluster testcluster --id A --show-config-value mon_data) |
| 651 |
if [ ! -d \$mon_data ] ; then |
| 652 |
mkdir -p \$mon_data |
| 653 |
if getent passwd ceph >/dev/null 2>&1; then |
| 654 |
chown -h ceph:ceph \$mon_data |
| 655 |
if ceph-mon --cluster testcluster \ |
| 656 |
--setuser ceph --setgroup ceph \ |
| 657 |
--mkfs \ |
| 658 |
--id A \ |
| 659 |
--keyring /dev/null ; then |
| 660 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 661 |
chown -h ceph:ceph \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 662 |
else |
| 663 |
rm -fr \$mon_data |
| 664 |
fi |
| 665 |
else |
| 666 |
if ceph-mon --cluster testcluster \ |
| 667 |
--mkfs \ |
| 668 |
--id A \ |
| 669 |
--keyring /dev/null ; then |
| 670 |
touch \$mon_data/done \$mon_data/systemd \$mon_data/keyring |
| 671 |
else |
| 672 |
rm -fr \$mon_data |
| 673 |
fi |
| 674 |
fi |
| 675 |
fi |
| 676 |
", |
| 677 |
:logoutput => true )} |
| 678 |
end |
| 679 |
|
| 680 |
context 'with ensure absent' do |
| 681 |
let :title do |
| 682 |
'A' |
| 683 |
end |
| 684 |
|
| 685 |
let :params do |
| 686 |
{ |
| 687 |
:ensure => 'absent', |
| 688 |
:public_addr => '127.0.0.1', |
| 689 |
:authentication_type => 'none', |
| 690 |
:cluster => 'testcluster', |
| 691 |
} |
| 692 |
end |
| 693 |
|
| 694 |
it { should contain_service('ceph-mon-A').with('ensure' => 'stopped') } |
| 695 |
|
| 696 |
it { should contain_exec('remove-mon-A').with( |
| 697 |
:command => "/bin/true # comment to satisfy puppet syntax requirements |
| 698 |
set -ex |
| 699 |
mon_data=\$(ceph-mon --cluster testcluster --id A --show-config-value mon_data) |
| 700 |
rm -fr \$mon_data |
| 701 |
", |
| 702 |
:unless => "/bin/true # comment to satisfy puppet syntax requirements |
| 703 |
set -ex |
| 704 |
which ceph-mon || exit 0 # if ceph-mon is not available we already uninstalled ceph and there is nothing to do |
| 705 |
mon_data=\$(ceph-mon --cluster testcluster --id A --show-config-value mon_data) |
| 706 |
test ! -d \$mon_data |
| 707 |
", |
| 708 |
:logoutput => true )} |
| 709 |
end |
| 710 |
|
| 711 |
context 'with ensure set with bad value' do |
| 712 |
let :title do |
| 713 |
'A' |
| 714 |
end |
| 715 |
|
| 716 |
let :params do |
| 717 |
{ |
| 718 |
:ensure => 'badvalue', |
| 719 |
} |
| 720 |
end |
| 721 |
|
| 722 |
it { should raise_error(Puppet::Error, /Ensure on MON must be either present or absent/) } |
| 723 |
end |
| 724 |
end |
| 725 |
|
| 726 |
on_supported_os({ |
| 727 |
:supported_os => OSDefaults.get_supported_os |
| 728 |
}).each do |os,facts| |
| 729 |
context "on #{os}" do |
| 730 |
let (:facts) do |
| 731 |
facts.merge!(OSDefaults.get_facts()) |
| 732 |
end |
| 733 |
|
| 734 |
# if facts[:operatingsystem] == 'Ubuntu' |
| 735 |
# it_behaves_like 'ceph::mon on Ubuntu 14.04' |
| 736 |
# it_behaves_like 'ceph::mon on Ubuntu 16.04' |
| 737 |
# elsif facts[:operatingsystem] == 'CentOS' |
| 738 |
# it_behaves_like 'ceph::mon on RHEL7' |
| 739 |
# end |
| 740 |
end |
| 741 |
end |
| 742 |
end |