Requires: lvm2
Requires: python%{python3_pkgversion}
Requires: openssh-server
+Requires: which
%if 0%{?weak_deps}
Recommends: podman >= 2.0.2
%endif
from ceph_volume import terminal
from ceph_volume.util import as_bytes
+import locale
+
+if locale.getpreferredencoding().upper() != 'UTF-8':
+ locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
+
import logging
logger = logging.getLogger(__name__)
if terminal_logging:
getattr(terminal, descriptor)(message)
if logfile_logging:
- logger.info(line.encode('ascii', 'ignore').decode('ascii'))
+ logger.info(line)
def log_descriptors(reads, process, terminal_logging):
# https://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container/
FROM centos:8 as centos-systemd
ENV container docker
+ENV CEPHADM_PATH=/usr/local/sbin/cephadm
#RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
#rm -f /lib/systemd/system/multi-user.target.wants/*;\
#rm -f /etc/systemd/system/*.wants/*;\
#rm -f /lib/systemd/system/basic.target.wants/*;\
#rm -f /lib/systemd/system/anaconda.target.wants/*;
RUN dnf -y install chrony firewalld lvm2 \
- openssh-server openssh-clients python3 yum-utils && dnf clean all
+ openssh-server openssh-clients python3 \
+ yum-utils sudo which && dnf clean all
+
RUN systemctl enable chronyd firewalld sshd
RUN dnf -y install docker-ce && \
dnf clean all && systemctl enable docker
+# ssh utilities
+RUN dnf install epel-release -y && dnf makecache && dnf install sshpass -y
EXPOSE 8443
-
-RUN dnf install sudo which -y
+EXPOSE 22
FROM centos-systemd-docker
WORKDIR /root
echo "options:"
echo " --hosts n: number of hosts to add"
echo " --osds n: number of osds to add"
- echo " --update-image: create/update ceph image"
+ echo " --update-ceph-image: create/update ceph image"
+ echo " --update-box-image: create/update cephadm box image"
+ echo " --skip-create-loop: skip creating loopback device"
+ echo " -l | --list-hosts: list available cephad-box hosts/seed"
+ echo " -h | --help: this help :)"
}
function docker-ips() {
while [ $# -ge 1 ]; do
case $1 in
- --help)
+ -h | --help)
print_usage
exit
;;
- --list-hosts) # TODO remove when ceph-ci updated
+ -l | --list-hosts) # TODO remove when ceph-ci updated
docker-ips | grep box
exit
;;
- --update-image) # TODO remove when ceph-ci updated
+ --update-box-image)
+ docker build -t cephadm-box -f Dockerfile .
+ ;;
+ --update-ceph-image) # TODO remove when ceph-ci updated
source ./get_ceph_image.sh
;;
--hosts)
exit
fi
-if [[ SKIP_LOOP -eq 0 ]]
+if [[ $OSDS -eq 0 ]]
+then
+ SKIP_LOOP=1
+fi
+
+if [[ $SKIP_LOOP -eq 0 ]]
then
source setup_loop.sh
+ create_loops $OSDS
fi
-create_loops $OSDS
# loops should be created before starting docker-compose or else docker could
# not find lvs
docker-compose up --scale hosts=$HOSTS -d
sleep 3
-# setup ssh in hosts
-docker-compose exec hosts /cephadm/box/setup_ssh.sh
+IPS=$(docker-ips | grep "box_hosts" | awk '{ print $1 }')
+echo "IPS: "
+echo $IPS
+
+sudo sysctl net.ipv4.conf.all.forwarding=1
+sudo iptables -P FORWARD ACCEPT
+
+for ((i=1;i<=$HOSTS;i++))
+do
+ docker-compose exec --index=$i hosts /cephadm/box/setup_ssh.sh run-sshd
+done
+
docker-compose exec -e NUM_OSDS=${OSDS} seed /cephadm/box/start
+
+docker-compose exec -e HOST_IPS="${IPS}" seed /cephadm/box/setup_ssh.sh copy-cluster-ssh-key
# update image with deps
docker build -t $IMAGE docker/ceph
# store to later load within docker
-rm docker/ceph/image/quay.ceph.image.tar
+mkdir -p docker/ceph/image
+rm -f docker/ceph/image/quay.ceph.image.tar
docker save quay.ceph.io/ceph-ci/ceph:master -o docker/ceph/image/quay.ceph.image.tar
#!/bin/bash
function clean_vg() {
- # sudo lvm lvremove -y "/dev/vg1/lv${i}"
- sudo lvm vgremove -y vg1
+ sudo lvm vgremove -f -y vg1
sudo rm loop-images/*
}
#!/usr/bin/env bash
-# SSH
-if [[ ! -f "/root/.ssh/id_rsa" ]]; then
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ""
-fi
+set -e
-cat ~/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
-if [[ ! -f "/root/.ssh/known_hosts" ]]; then
- ssh-keygen -A
-fi
-dnf install -y openssh-server
-/usr/sbin/sshd
+function run-sshd() {
+ echo "Creating sshd server on $(hostname):$(hostname -i)"
+ # SSH
+ if [[ ! -f "/root/.ssh/id_rsa" ]]; then
+ mkdir -p ~/.ssh
+ chmod 700 ~/.ssh
+ ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ""
+ fi
-# no password
-echo "root:" | chpasswd
-echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
+ cat ~/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
+ if [[ ! -f "/root/.ssh/known_hosts" ]]; then
+ ssh-keygen -A
+ fi
+
+ # change password
+ echo "root:root" | chpasswd
+ echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
+ echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
+
+ /usr/sbin/sshd
+ echo "sshd finished"
+}
+
+function copy-cluster-ssh-key() {
+ echo "Adding cluster ssh key to all hosts: ${HOST_IPS}"
+ HOST_IPS=$(echo $HOST_IPS)
+ for ip in $(echo $HOST_IPS)
+ do
+ if [[ ! $ip == $(hostname -i) ]]
+ then
+ echo $ip
+ # copy cluster key
+ sshpass -p "root" ssh-copy-id -f -o StrictHostKeyChecking=no -i /etc/ceph/ceph.pub "root@${ip}"
+ fi
+ done
+ echo "Finished adding keys, you can now add existing hosts containers to the cluster!"
+}
+
+case $1 in
+ run-sshd)
+ run-sshd
+ ;;
+ copy-cluster-ssh-key)
+ copy-cluster-ssh-key
+ ;;
+esac
#!/usr/bin/env bash
set -euxo pipefail
-CEPHADM_PATH=/usr/local/sbin/cephadm
-
-dnf install which sudo -y
# link so we can debug cephadm
ln -s -f /cephadm/cephadm $CEPHADM_PATH
def validate_osd_data_dir(data_dir):
+ # type: (str) -> None
required_files = ['keyring', 'block', 'type', 'config']
current_files = os.listdir(data_dir)
error_msg = ''
def configure_osd_data_dir(ctx, fsid, daemon_id, uid, gid):
+ # type: (CephadmContext, str, Union[int, str], int, int) -> None
daemon_type = 'osd'
data_dir = get_data_dir(fsid, ctx.data_dir, daemon_type, daemon_id)
@default_image
@infer_fsid
def command_deploy(ctx):
- assert ctx.fsid
# type: (CephadmContext) -> None
+ assert ctx.fsid
daemon_type, daemon_id = ctx.name.split('.', 1)
lock = FileLock(ctx, ctx.fsid)
# Ceph-volume uses the bootstrap-osd key in order to do its operations.
# This function retrieves the keyring so it can be provided.
- def get_bootstrap_osd_keyring() -> str:
+ def get_bootstrap_osd_keyring() -> Optional[str]:
if not ctx.keyring and os.path.exists(SHELL_DEFAULT_KEYRING):
ctx.keyring = SHELL_DEFAULT_KEYRING
(config, keyring) = get_config_and_keyring(ctx)
# If ceph-volume creates osd data directories which won't be persisted
# so we use a tmp dir for that.
# FIXME: probably we can use /var/lib/ceph/{fsid}?
- tmp_osd_dir = tempfile.TemporaryDirectory()
- # match /var/lib/ceph/osd/ dir permissions
- os.chown(tmp_osd_dir.name, uid, gid)
- os.chmod(tmp_osd_dir.name, 0o755)
- # store newly created osds here
- mounts[tmp_osd_dir.name] = '/var/lib/ceph/osd/:z'
+ with tempfile.TemporaryDirectory() as tmp_osd_dir:
+ # match /var/lib/ceph/osd/ dir permissions
+ os.chown(tmp_osd_dir, uid, gid)
+ os.chmod(tmp_osd_dir, 0o755)
+ # store newly created osds here
+ mounts[tmp_osd_dir] = '/var/lib/ceph/osd/:z'
- c = CephContainer(
- ctx,
- image=ctx.image,
- entrypoint='/usr/sbin/ceph-volume',
- envs=ctx.env,
- args=ctx.command,
- privileged=True,
- volume_mounts=mounts,
- )
+ c = CephContainer(
+ ctx,
+ image=ctx.image,
+ entrypoint='/usr/sbin/ceph-volume',
+ envs=ctx.env,
+ args=ctx.command,
+ privileged=True,
+ volume_mounts=mounts,
+ )
- out, err, code = call_throws(ctx, c.run_cmd())
- if not code:
- print(out)
- else:
- print(err)
- # If osds were created move osd's data directories
- for osd_folder_name in os.listdir(tmp_osd_dir.name):
- if 'ceph-' in osd_folder_name[:5]:
- osd_id = osd_folder_name[5:]
- osd_data_dir = os.path.join(tmp_osd_dir.name, osd_folder_name)
- copy_tree(ctx, [osd_data_dir], f'/var/lib/ceph/{ctx.fsid}/osd.{osd_id}', uid=uid, gid=gid)
+ out, err, code = call_throws(ctx, c.run_cmd())
+ if not code:
+ print(out)
+ else:
+ print(err)
+ # If osds were created move osd's data directories
+ for osd_folder_name in os.listdir(tmp_osd_dir):
+ if 'ceph-' in osd_folder_name[:5]:
+ osd_id = osd_folder_name[5:]
+ osd_data_dir = os.path.join(tmp_osd_dir, osd_folder_name)
+ copy_tree(ctx, [osd_data_dir], f'/var/lib/ceph/{ctx.fsid}/osd.{osd_id}', uid=uid, gid=gid)
##################################