summaryrefslogtreecommitdiffstats
path: root/sdnvpn/lib/gather_logs.py
blob: 9afa0778fe5f9c63e61f909aa6ce067b4131ec19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright (c) 2017 All rights reserved
# This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# performes:
# - Gather
#   - odl logs
#   - ovs logs
#   - neutron logs
#   - odl datastore state
#   - ovs state (openflow and dp)
#   - optional - memory dump from odl

import os
import inspect

import sdnvpn.lib.utils as test_utils
import functest.utils.functest_utils as ft_utils
from functest.utils.constants import CONST

LIB_PATH = os.path.dirname(
    os.path.abspath(inspect.getfile(inspect.currentframe())))


def gather_logs(name):
    openstack_nodes = test_utils.get_nodes()

    ft_utils.execute_command_raise('rm -rf /tmp/sdnvpn-logs/;'
                                   'mkdir -p /tmp/sdnvpn-logs/')
    for node in openstack_nodes:
        node.put_file('%s/../sh_utils/fetch-log-script.sh'
                      % LIB_PATH,
                      '/tmp/fetch-log-script.sh')
        node.run_cmd('sudo bash /tmp/fetch-log-script.sh')
        node.get_file('/tmp/log_output.tar.gz',
                      '/tmp/log_output-%s.tar.gz'
                      % node.get_dict()['name'])
        ft_utils.execute_command_raise('mkdir -p /tmp/sdnvpn-logs/')
        ft_utils.execute_command_raise(
            'cd /tmp/sdnvpn-logs/; '
            'tar -xzvf /tmp/log_output-%s.tar.gz --strip-components=1'
            % node.get_dict()['name'])

    ft_utils.execute_command_raise('cd %s;tar czvf sdnvpn-logs-%s.tar.gz'
                                   ' sdnvpn-logs/'
                                   % (CONST.__getattribute__('dir_results'),
                                      name))


if __name__ == '__main__':
    gather_logs('test')