Coverage for drivers/sr_health_check.py : 95%
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 check_xapi_is_enabled(session, hostref):
28 host = session.xenapi.host.get_record(hostref)
29 return host['enabled']
32def main():
33 """
34 For all locally plugged SRs check that they are healthy
35 """
36 with util.ApiSession("SM-sr-health-check") as session:
37 localhost = util.get_localhost_ref(session)
38 if not check_xapi_is_enabled(session, localhost):
39 # Xapi not enabled, skip and let the next timer trigger this
40 return
42 sm_types = [x['type'] for x in session.xenapi.SM.get_all_records_where(
43 'field "required_api_version" = "1.0"').values()]
44 for sm_type in sm_types:
45 srs = session.xenapi.SR.get_all_records_where(
46 f'field "type" = "{sm_type}"')
47 for sr in srs:
48 pbds = session.xenapi.PBD.get_all_records_where(
49 f'field "SR" = "{sr}" and field "host" = "{localhost}"')
50 if not pbds:
51 continue
53 pbd_ref, pbd = pbds.popitem()
54 if not pbd['currently_attached']:
55 continue
57 sr_uuid = srs[sr]['uuid']
58 sr_obj = SR.SR.from_uuid(session, sr_uuid)
59 sr_obj.check_sr(sr_uuid)
62if __name__ == "__main__": 62 ↛ 63line 62 didn't jump to line 63, because the condition on line 62 was never true
63 main()