Coverage for drivers/on_slave.py : 97%

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
2#
3# Copyright (C) Citrix Systems 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
17#
18# A plugin for synchronizing slaves when something changes on the Master
20import sys
21sys.path.append("/opt/xensource/sm/")
22import util
23import lock
24from lvmcache import LVMCache
25import scsiutil
28def multi(session, args):
29 """Perform several actions in one call (to save on round trips)"""
30 util.SMlog("on-slave.multi: %s" % args)
31 vgName = args["vgName"]
32 lvmCache = LVMCache(vgName)
33 i = 1
34 while True:
35 action = args.get("action%d" % i)
36 if not action:
37 break
38 util.SMlog("on-slave.action %d: %s" % (i, action))
39 if action == "activate":
40 try:
41 lvmCache.activate(args["ns%d" % i], args["uuid%d" % i],
42 args["lvName%d" % i], False)
43 except util.CommandException:
44 util.SMlog("on-slave.activate failed")
45 raise
46 elif action == "deactivate":
47 try:
48 lvmCache.deactivate(args["ns%d" % i], args["uuid%d" % i],
49 args["lvName%d" % i], False)
50 except util.SMException:
51 util.SMlog("on-slave.deactivate failed")
52 raise
53 elif action == "deactivateNoRefcount":
54 try:
55 lvmCache.deactivateNoRefcount(args["lvName%d" % i])
56 except util.SMException:
57 util.SMlog("on-slave.deactivateNoRefcount failed")
58 raise
59 elif action == "refresh":
60 try:
61 lvmCache.activateNoRefcount(args["lvName%d" % i], True)
62 except util.CommandException:
63 util.SMlog("on-slave.refresh failed")
64 raise
65 elif action == "cleanupLockAndRefcount":
66 from refcounter import RefCounter
67 lock.Lock.cleanup(args["uuid%d" % i], args["ns%d" % i])
68 RefCounter.reset(args["uuid%d" % i], args["ns%d" % i])
69 else:
70 raise util.SMException("unrecognized action: %s" % action)
71 i += 1
72 return str(True)
75def _is_open(session, args):
76 """Check if VDI <args["vdiUuid"]> is open by a tapdisk on this host"""
77 import SRCommand
78 import SR
79 import CephFSSR
80 import EXTSR
81 import GlusterFSSR
82 import LVHDSR
83 import MooseFSSR
84 import NFSSR
85 import XFSSR
86 import ZFSSR
87 import blktap2
89 util.SMlog("on-slave.is_open: %s" % args)
90 vdiUuid = args["vdiUuid"]
91 srRef = args["srRef"]
92 srRec = session.xenapi.SR.get_record(srRef)
93 srType = srRec["type"]
95 # FIXME: ugly hacks to create a VDI object without a real SRCommand to
96 # avoid having to refactor the core files
97 if srType.startswith("lvm"):
98 srType = "lvhd"
99 cmd = SRCommand.SRCommand(None)
100 cmd.driver_info = {"capabilities": None}
101 cmd.dconf = {
102 "server": None,
103 "device": "/HACK",
104 # Hack for custom XCP-ng drivers.
105 "masterhost": None, # MooseFS
106 "rootpath": None, # MooseFS
107 "serverpath": None, # CephFS
108 "location": "/HACK" # ZFS
109 }
110 cmd.params = {"command": None}
112 driver = SR.driver(srType)
113 sr = driver(cmd, srRec["uuid"])
114 vdi = sr.vdi(vdiUuid)
115 tapdisk = blktap2.Tapdisk.find_by_path(vdi.path)
116 util.SMlog("Tapdisk for %s: %s" % (vdi.path, tapdisk))
117 if tapdisk:
118 return "True"
119 return "False"
122def is_open(session, args):
123 try:
124 return _is_open(session, args)
125 except:
126 util.logException("is_open")
127 raise
130def refresh_lun_size_by_SCSIid(session, args):
131 """Refresh the size of LUNs backing the SCSIid on the local node."""
132 util.SMlog("on-slave.refresh_lun_size_by_SCSIid(,%s)" % args)
133 if scsiutil.refresh_lun_size_by_SCSIid(args['SCSIid']):
134 util.SMlog("on-slave.refresh_lun_size_by_SCSIid with %s succeeded"
135 % args)
136 return "True"
137 else:
138 util.SMlog("on-slave.refresh_lun_size_by_SCSIid with %s failed" % args)
139 return "False"
142if __name__ == "__main__": 142 ↛ 143line 142 didn't jump to line 143, because the condition on line 142 was never true
143 import XenAPIPlugin
144 XenAPIPlugin.dispatch({
145 "multi": multi,
146 "is_open": is_open,
147 "refresh_lun_size_by_SCSIid": refresh_lun_size_by_SCSIid})