cf37acfc1cdfcb16b0d510355d8e5fc8f317bfc6
[sdnvpn.git] / sdnvpn / lib / gather_logs.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2017 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # performes:
11 # - Gather
12 #   - odl logs
13 #   - ovs logs
14 #   - neutron logs
15 #   - odl datastore state
16 #   - ovs state (openflow and dp)
17 #   - optional - memory dump from odl
18
19 import os
20 import inspect
21
22 import sdnvpn.lib.utils as test_utils
23 import functest.utils.functest_utils as ft_utils
24 from functest.utils import config
25
26 LIB_PATH = os.path.dirname(
27     os.path.abspath(inspect.getfile(inspect.currentframe())))
28
29
30 def gather_logs(name):
31     openstack_nodes = test_utils.get_nodes()
32
33     ft_utils.execute_command_raise('rm -rf /tmp/sdnvpn-logs/;'
34                                    'mkdir -p /tmp/sdnvpn-logs/')
35     for node in openstack_nodes:
36         node.put_file('%s/../sh_utils/fetch-log-script.sh'
37                       % LIB_PATH,
38                       '/tmp/fetch-log-script.sh')
39         node.run_cmd('sudo bash /tmp/fetch-log-script.sh')
40         node.get_file('/tmp/log_output.tar.gz',
41                       '/tmp/log_output-%s.tar.gz'
42                       % node.get_dict()['name'])
43         ft_utils.execute_command_raise('mkdir -p /tmp/sdnvpn-logs/')
44         ft_utils.execute_command_raise(
45             'cd /tmp/sdnvpn-logs/; '
46             'tar -xzvf /tmp/log_output-%s.tar.gz --strip-components=1'
47             % node.get_dict()['name'])
48
49     ft_utils.execute_command_raise(
50         'cd %s;tar czvf sdnvpn-logs-%s.tar.gz /tmp/sdnvpn-logs/' % (
51             getattr(config.CONF, 'dir_results'), name))
52
53
54 if __name__ == '__main__':
55     gather_logs('test')