Merge PR #31168 into master

* refs/pull/31168/head:
	ceph-daemon: try py2 import before py3
	qa/suites/rados/singleton-nomsgr/ceph-daemon: make sure python3 is installed
	qa/standalone/test_ceph_damon.sh: test with python2 and python3
	mgr/ssh: python, not python3
	ceph-daemon: python, not python3
	ceph-daemon: os.makedirs
	ceph-daemon: configparser is ConfigParser on py2
	ceph-daemon: avoid py3-isms

Reviewed-by: Sebastian Wagner <swagner@suse.com>
Reviewed-by: Alfredo Deza <adeza@redhat.com>
This commit is contained in:
Sage Weil 2019-10-28 14:59:43 -05:00
commit d927374bb4
4 changed files with 48 additions and 23 deletions

View File

@ -1,12 +1,32 @@
#!/bin/bash -ex
# respawn ourselves with a modified path with both python2 and python3
PYTHONS="python3 python2" # which pythons we test
if [ -z "$PYTHON_KLUDGE" ]; then
TMPBINDIR=`mktemp -d $TMPDIR`
trap "rm -rf $TMPBINDIR" TERM HUP INT
for p in $PYTHONS; do
ln -s `which $p` $TMPBINDIR/python
echo "=== re-running with $p ==="
PYTHON_KLUDGE=1 PATH=$TMPBINDIR:$PATH $0
rm $TMPBINDIR/python
done
rm -rf $TMPBINDIR
echo "PASS with all of: $PYTHONS"
exit 0
fi
echo "path is $PATH"
ls -al `which python`
[ -z "$SUDO" ] && SUDO=sudo
[ -x ../src/ceph-daemon ] && CEPH_DAEMON=../src/ceph-daemon
[ -x ./ceph-daemon ] && CEPH_DAEMON=.ceph-daemon
which ceph-daemon && CEPH_DAEMON=$(which ceph-daemon)
FSID='00000000-0000-0000-0000-0000deadbeef'
IMAGE='ceph/daemon-base:latest-master'
IMAGE='ceph/daemon-base:latest-master-devel'
# clean up previous run(s)?
$SUDO $CEPH_DAEMON rm-cluster --fsid $FSID --force

View File

@ -2,6 +2,9 @@ roles:
- [mon.a, mgr.x, osd.0, client.0]
tasks:
- install:
- exec:
mon.a:
- yum install -y python3 || apt install -y python3
- workunit:
basedir: qa/standalone
clients:

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python
DEFAULT_IMAGE='ceph/daemon-base'
DATA_DIR='/var/lib/ceph'
@ -31,8 +31,15 @@ You can invoke ceph-daemon in two ways:
"""
import argparse
import configparser
try:
from ConfigParser import ConfigParser # py2
except ImportError:
from configparser import ConfigParser # py3
import fcntl
try:
from StringIO import StringIO # py2
except:
from io import StringIO # py3
import json
import logging
import os
@ -45,14 +52,6 @@ import time
import uuid
from distutils.spawn import find_executable
try:
from StringIO import StringIO
except ImportError:
pass
try:
from io import StringIO
except ImportError:
pass
podman_path = None
@ -165,7 +164,10 @@ def is_fsid(s):
return True
def makedirs(dir, uid, gid, mode):
os.makedirs(dir, exist_ok=True, mode=mode)
if not os.path.exists(dir):
os.makedirs(dir, mode=mode)
else:
os.chmod(dir, mode)
os.chown(dir, uid, gid)
os.chmod(dir, mode) # the above is masked by umask...
@ -201,7 +203,7 @@ def make_log_dir(fsid, uid=None, gid=None):
def find_program(filename):
name = find_executable(filename)
if name is None:
raise ValueError(f'{filename} not found')
raise ValueError('%s not found' % filename)
return name
def get_unit_name(fsid, daemon_type, daemon_id):
@ -237,7 +239,7 @@ def check_unit(unit_name):
def get_legacy_config_fsid(cluster):
try:
config = configparser.ConfigParser()
config = ConfigParser()
config.read('/etc/ceph/%s.conf' % cluster)
if 'global' in config and 'fsid' in config['global']:
return config['global']['fsid']
@ -677,11 +679,11 @@ class CephContainer:
def run_cmd(self):
vols = sum(
[['-v', f'{host_dir}:{container_dir}']
[['-v', '%s:%s' % (host_dir, container_dir)]
for host_dir, container_dir in self.volume_mounts.items()], [])
envs = [
'-e', f'CONTAINER_IMAGE={self.image}',
'-e', f'NODE_NAME={get_hostname()}',
'-e', 'CONTAINER_IMAGE=%s' % self.image,
'-e', 'NODE_NAME=%s' % get_hostname(),
]
cname = ['--name', self.cname] if self.cname else []
return [
@ -696,11 +698,11 @@ class CephContainer:
def shell_cmd(self, cmd):
vols = sum(
[['-v', f'{host_dir}:{container_dir}']
[['-v', '%s:%s' % (host_dir, container_dir)]
for host_dir, container_dir in self.volume_mounts.items()], [])
envs = [
'-e', f'CONTAINER_IMAGE={self.image}',
'-e', f'NODE_NAME={get_hostname()}',
'-e', 'CONTAINER_IMAGE=%s' % self.image,
'-e', 'NODE_NAME=%s' % get_hostname(),
]
cmd_args = []
if cmd:
@ -735,7 +737,7 @@ class CephContainer:
def command_version():
out = CephContainer(args.image, 'ceph', ['--version']).run()
print(out, end='')
print(out.strip())
return 0
##################################
@ -748,7 +750,7 @@ def command_bootstrap():
logging.info('Cluster fsid: %s' % fsid)
# config
cp = configparser.ConfigParser()
cp = ConfigParser()
if args.config:
cp.read(args.config)
if args.mon_ip:

View File

@ -460,7 +460,7 @@ class SSHOrchestrator(MgrModule, orchestrator.Orchestrator):
out, err, code = remoto.process.check(
conn,
['/usr/bin/python3', '-u'],
['/usr/bin/python', '-u'],
stdin=script.encode('utf-8'))
self.log.debug('exit code %s out %s err %s' % (code, out, err))
return out, code