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