Merge pull request #38009 from ideepika/wip-48058-cephadm

qa/tasks/cephadm: update_info_yam() only if ctx.archive is valid

Reviewed-by: Kefu Chai <kchai@redhat.com>
Reviewed-by: Sebastian Wagner <sebastian.wagner@suse.com>
This commit is contained in:
Sebastian Wagner 2020-12-10 15:13:42 +01:00 committed by GitHub
commit 56db4fbed8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 67 deletions

View File

@ -74,8 +74,11 @@ def generate_caps(type_):
yield capability
def update_archive_setting(archive_dir, key, value):
with open(os.path.join(archive_dir, 'info.yaml'), 'r+') as info_file:
def update_archive_setting(ctx, key, value):
"""
Add logs directory to job's info log file
"""
with open(os.path.join(ctx.archive, 'info.yaml'), 'r+') as info_file:
info_yaml = yaml.safe_load(info_file)
info_file.seek(0)
if 'archive' in info_yaml:
@ -91,9 +94,8 @@ def ceph_crash(ctx, config):
Gather crash dumps from /var/lib/ceph/crash
"""
if ctx.archive is not None:
# Add crash directory to job's archive
update_archive_setting(ctx.archive, 'crash', '/var/lib/ceph/crash')
# Add crash directory to job's archive
update_archive_setting(ctx, 'crash', '/var/lib/ceph/crash')
try:
yield
@ -165,8 +167,7 @@ def ceph_log(ctx, config):
)
# Add logs directory to job's info log file
if ctx.archive is not None:
update_archive_setting(ctx.archive, 'log', '/var/log/ceph')
update_archive_setting(ctx, 'log', '/var/log/ceph')
class Rotater(object):
stop_event = gevent.event.Event()

View File

@ -66,6 +66,19 @@ def build_initial_config(ctx, config):
return conf
def update_archive_setting(ctx, key, value):
"""
Add logs directory to job's info log file
"""
with open(os.path.join(ctx.archive, 'info.yaml'), 'r+') as info_file:
info_yaml = yaml.safe_load(info_file)
info_file.seek(0)
if 'archive' in info_yaml:
info_yaml['archive'][key] = value
else:
info_yaml['archive'] = {key: value}
yaml.safe_dump(info_yaml, info_file, default_flow_style=False)
@contextlib.contextmanager
def normalize_hostnames(ctx):
"""
@ -73,11 +86,7 @@ def normalize_hostnames(ctx):
remote.shortname and socket.gethostname() in cephadm.
"""
log.info('Normalizing hostnames...')
ctx.cluster.run(args=[
'sudo',
'hostname',
run.Raw('$(hostname -s)'),
])
ctx.cluster.sh('sudo hostname $(hostname -s)')
try:
yield
@ -159,15 +168,8 @@ def ceph_log(ctx, config):
cluster_name = config['cluster']
fsid = ctx.ceph[cluster_name].fsid
# Add logs directory to job's info log file
with open(os.path.join(ctx.archive, 'info.yaml'), 'r+') as info_file:
info_yaml = yaml.safe_load(info_file)
info_file.seek(0)
if 'archive' not in info_yaml:
info_yaml['archive'] = {'log': '/var/log/ceph'}
else:
info_yaml['archive']['log'] = '/var/log/ceph'
yaml.safe_dump(info_yaml, info_file, default_flow_style=False)
update_archive_setting(ctx, 'log', '/var/log/ceph')
try:
yield
@ -228,28 +230,10 @@ def ceph_log(ctx, config):
not (ctx.config.get('archive-on-error') and ctx.summary['success']):
# and logs
log.info('Compressing logs...')
run.wait(
ctx.cluster.run(
args=[
'sudo',
'find',
'/var/log/ceph', # all logs, not just for the cluster
'/var/log/rbd-target-api', # ceph-iscsi
'-name',
'*.log',
'-print0',
run.Raw('|'),
'sudo',
'xargs',
'-0',
'--no-run-if-empty',
'--',
'gzip',
'--',
],
wait=False,
),
)
ctx.cluster.sh(
'sudo find /var/log/ceph -name *.log -print0 | '
'sudo xargs -0 --no-run-if-empty -- gzip --',
wait=False)
log.info('Archiving logs...')
path = os.path.join(ctx.archive, 'remote')
@ -277,15 +261,7 @@ def ceph_crash(ctx, config):
cluster_name = config['cluster']
fsid = ctx.ceph[cluster_name].fsid
# Add logs directory to job's info log file
with open(os.path.join(ctx.archive, 'info.yaml'), 'r+') as info_file:
info_yaml = yaml.safe_load(info_file)
info_file.seek(0)
if 'archive' not in info_yaml:
info_yaml['archive'] = {'crash': '/var/lib/ceph/%s/crash' % fsid}
else:
info_yaml['archive']['crash'] = '/var/lib/ceph/%s/crash' % fsid
yaml.safe_dump(info_yaml, info_file, default_flow_style=False)
update_archive_setting(ctx, 'crash', '/var/lib/ceph/crash')
try:
yield
@ -330,12 +306,8 @@ def ceph_bootstrap(ctx, config, registry):
first_mon_role = ctx.ceph[cluster_name].first_mon_role
mons = ctx.ceph[cluster_name].mons
ctx.cluster.run(args=[
'sudo', 'mkdir', '-p', '/etc/ceph',
]);
ctx.cluster.run(args=[
'sudo', 'chmod', '777', '/etc/ceph',
]);
ctx.cluster.sh('sudo mkdir -p /etc/ceph')
ctx.cluster.sh('sudo chmod 777 /etc/ceph')
if registry:
add_mirror_to_cluster(ctx, registry)
try:
@ -423,15 +395,11 @@ def ceph_bootstrap(ctx, config, registry):
f'{testdir}/{cluster_name}.pub').decode('ascii').strip()
log.info('Installing pub ssh key for root users...')
ctx.cluster.run(args=[
'sudo', 'install', '-d', '-m', '0700', '/root/.ssh',
run.Raw('&&'),
'echo', ssh_pub_key,
run.Raw('|'),
'sudo', 'tee', '-a', '/root/.ssh/authorized_keys',
run.Raw('&&'),
'sudo', 'chmod', '0600', '/root/.ssh/authorized_keys',
])
ctx.cluster.sh(
'sudo install -d -m 0700 /root/.ssh &&'
f'echo {ssh_pub_key} |'
'sudo tee -a /root/.ssh/authorized_keys &&'
'sudo chmod 0600 /root/.ssh/authorized_keys')
# set options
_shell(ctx, cluster_name, bootstrap_remote,