Coverage for drivers/sr_health_check.py : 88%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/python3
3# Copyright (C) Cloud Software Group, Inc.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published
7# by the Free Software Foundation; version 2.1 only.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18"""
19Health check for SR, to be triggered periodically by a systemd timer. What is checked is
20SR implementation type dependent.
21"""
23import SR
24import util
25import xs_errors
27def main():
28 """
29 For all locally plugged SRs check that they are healthy
30 """
31 try:
32 session = util.get_localAPI_session()
33 except xs_errors.SROSError:
34 util.SMlog("Unable to open local XAPI session", priority=util.LOG_ERR)
35 return
37 try:
38 localhost = util.get_localhost_ref(session)
40 sm_types = [x['type'] for x in session.xenapi.SM.get_all_records_where(
41 'field "required_api_version" = "1.0"').values()]
42 for sm_type in sm_types:
43 srs = session.xenapi.SR.get_all_records_where(
44 f'field "type" = "{sm_type}"')
45 for sr in srs:
46 pbds = session.xenapi.PBD.get_all_records_where(
47 f'field "SR" = "{sr}" and field "host" = "{localhost}"')
48 if not pbds:
49 continue
51 pbd_ref, pbd = pbds.popitem()
52 if not pbd['currently_attached']:
53 continue
55 sr_uuid = srs[sr]['uuid']
56 sr_obj = SR.SR.from_uuid(session, sr_uuid)
57 sr_obj.check_sr(sr_uuid)
58 finally:
59 session.xenapi.session.logout()
62if __name__ == "__main__": 62 ↛ 63line 62 didn't jump to line 63, because the condition on line 62 was never true
63 main()