blob: 16bf224ce222548ad3dd4d5fe031cb7abb40cdcd [file] [log] [blame]
Michael Walshe11a1362017-10-19 15:35:26 -05001#!/usr/bin/env python
2
3r"""
4This file contains functions which are useful for processing BMC dumps.
5"""
6
7import gen_print as gp
8import bmc_ssh_utils as bsu
9import var_funcs as vf
10from robot.libraries.BuiltIn import BuiltIn
11import sys
12import os
13import imp
14base_path = os.path.dirname(os.path.dirname(
15 imp.find_module("gen_robot_print")[1])) + os.sep
16sys.path.append(base_path + "data/")
17import variables as var
18
19
20def get_dump_dict(quiet=None):
21
22 r"""
23 Get dump information and return as an ordered dictionary where the keys
24 are the dump IDs and the values are the full path names of the dumps.
25
26 Example robot program call:
27
28 ${dump_dict}= Get Dump Dict
29 Rpvars 1 dump_dict
30
31 Example output:
32
33 dump_dict:
34 [1]: /var/lib/phosphor-debug-collector/dumps/1/obmcdump_1_1508255216.tar.xz
35 [2]: /var/lib/phosphor-debug-collector/dumps/2/obmcdump_2_1508255245.tar.xz
36 [3]: /var/lib/phosphor-debug-collector/dumps/3/obmcdump_3_1508255267.tar.xz
37 [4]: /var/lib/phosphor-debug-collector/dumps/4/obmcdump_4_1508255283.tar.xz
38
39 Description of argument(s):
40 quiet If quiet is set to 1, this function will
41 NOT write status messages to stdout.
42 """
43
44 quiet = int(gp.get_var_value(quiet, 1))
45 cmd_buf = "dump_dir_path=" + var.DUMP_DIR_PATH + " ; " \
46 + "for dump_id in $(ls ${dump_dir_path} | sort -n) ; " \
47 + "do echo -n $dump_id: ; ls ${dump_dir_path}${dump_id}/* ; done"
48 output, stderr, rc = bsu.bmc_execute_command(cmd_buf, quiet=quiet)
49
50 return vf.key_value_outbuf_to_dict(output)
51
52
53def valid_dump(dump_id,
54 dump_dict=None,
55 quiet=None):
56
57 r"""
58 Verify that dump_id is a valid. If it is not valid, issue robot failure
59 message.
60
61 A dump is valid if the indicated dump_id refers to an existing dump with a
62 valid associated dump file.
63
64 Description of argument(s):
65 dump_id A dump ID (e.g. "1", "2", etc.)
66 dump_dict A dump dictionary such as the one returned
67 by get_dump_dict. If this value is None,
68 this function will call get_dump_dict on
69 the caller's behalf.
70 quiet If quiet is set to 1, this function will
71 NOT write status messages to stdout.
72 """
73
74 if dump_dict is None:
75 dump_dict = get_dump_dict(quiet=quiet)
76
77 if dump_id not in dump_dict:
78 message = "The specified dump ID was not found among the existing" \
79 + " dumps:\n"
80 message += gp.sprint_var(dump_id)
81 message += gp.sprint_var(dump_dict)
82 BuiltIn().fail(gp.sprint_error(message))
83
84 if not dump_dict[dump_id].endswith("tar.xz"):
85 message = "There is no \"tar.xz\" file associated with the given" \
86 + " dump_id:\n"
87 message += gp.sprint_var(dump_id)
88 dump_file_path = dump_dict[dump_id]
89 message += gp.sprint_var(dump_file_path)
90 BuiltIn().fail(gp.sprint_error(message))