Skip to content

Commit 8ba1f51

Browse files
author
mabuaisha
authored
RD-2283 Fix cfy logs download for 3 nodes cluster (#1308)
1 parent 0d2b023 commit 8ba1f51

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

cloudify_cli/commands/logs.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,23 @@ def get_host_date(conn):
4141
return conn.run('date +%Y%m%dT%H%M%S', hide=True).stdout.strip()
4242

4343

44-
def _archive_logs(conn, node_type, logger):
44+
def _archive_logs(conn, node_type, logger, node_ip):
4545
"""Creates an archive of all logs found under /var/log/cloudify plus
4646
journalctl.
4747
"""
4848
archive_filename = 'cloudify-{node_type}-logs_{date}_{ip}.tar.gz'.format(
4949
node_type=node_type,
5050
date=get_host_date(conn),
51-
ip=env.profile.manager_ip
51+
ip=node_ip
5252
)
5353
archive_path = '/tmp/{}'.format(archive_filename)
5454
journalctl_destination_path = '/var/log/cloudify/journalctl.log'
5555
conn.sudo(
5656
'bash -c "journalctl > /tmp/jctl && mv /tmp/jctl {0}"'
5757
.format(journalctl_destination_path),
5858
)
59-
logger.info('Creating logs archive in manager: {0}'.format(archive_path))
59+
logger.info('Creating logs archive in {0}: {1}'.format(node_type,
60+
archive_path))
6061
conn.sudo(
6162
'tar -czf {0} -C /var/log cloudify '
6263
'--warning=no-file-changed'.format(archive_path),
@@ -67,8 +68,9 @@ def _archive_logs(conn, node_type, logger):
6768
return archive_path
6869

6970

70-
def _download_archive(conn, host_type, output_path, logger, output_json):
71-
archive_path_on_host = _archive_logs(conn, host_type, logger)
71+
def _download_archive(conn, host_type, output_path,
72+
logger, output_json, node_ip):
73+
archive_path_on_host = _archive_logs(conn, host_type, logger, node_ip)
7274
filename = posixpath.basename(archive_path_on_host)
7375
output_path = os.path.join(output_path, filename)
7476
logger.info('Downloading archive to: {0}'.format(output_path))
@@ -93,6 +95,9 @@ def download(output_path, all_nodes, logger):
9395

9496
if not output_path:
9597
output_path = os.getcwd()
98+
99+
if not (env.profile.ssh_user and env.profile.ssh_key):
100+
raise CloudifyCliError('Make sure both `ssh_user` & `ssh_key` are set')
96101
if all_nodes:
97102
if not env.profile.cluster:
98103
raise CloudifyCliError(
@@ -109,7 +114,8 @@ def download(output_path, all_nodes, logger):
109114
node.get('host_type'),
110115
output_path,
111116
logger,
112-
output_json)
117+
output_json,
118+
node['host_ip'])
113119
except CloudifyCliError as e:
114120
logger.info('Skipping node {0}: {1}'
115121
.format(node['hostname'], e))
@@ -120,7 +126,8 @@ def download(output_path, all_nodes, logger):
120126
CloudifyNodeType.MANAGER,
121127
output_path,
122128
logger,
123-
output_json)
129+
output_json,
130+
env.profile.manager_ip)
124131

125132
if get_global_json_output():
126133
output(json.dumps(output_json, cls=CloudifyJSONEncoder))
@@ -174,7 +181,7 @@ def backup(logger):
174181
"""
175182
with env.ssh_connection() as conn:
176183
archive_path_on_manager = _archive_logs(
177-
conn, CloudifyNodeType.MANAGER, logger)
184+
conn, CloudifyNodeType.MANAGER, logger, env.profile.manager_ip)
178185
logger.info('Backing up manager logs to /var/log/{0}'.format(
179186
os.path.basename(archive_path_on_manager)))
180187
conn.sudo('mv {0} {1}'.format(archive_path_on_manager, '/var/log/'))

0 commit comments

Comments
 (0)