Skip to content

Commit e1ad843

Browse files
committed
Merge branch 'ran-3.2.3-8.3-mypy' into 3.2.3-8.3
2 parents 65021ac + 59ed5e3 commit e1ad843

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1547
-850
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ name: Test SM
33
on: [push, pull_request]
44

55
jobs:
6+
static-analysis:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
- name: Set up Python 3
12+
uses: actions/setup-python@v4
13+
with:
14+
python-version: '3.x'
15+
16+
- name: Install dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install -r dev_requirements_static_analysis.txt
20+
21+
- name: mypy
22+
run: |
23+
mypy .
24+
625
build:
726
runs-on: ubuntu-20.04
827

.mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mypy]
2+
enable_error_code = explicit-override
3+

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ precheck: build
127127
echo "Precheck succeeded with no outstanding issues found."
128128

129129
.PHONY: install
130-
install: precheck
130+
install: build
131131
mkdir -p $(SM_STAGING)
132132
$(call mkdir_clean,$(SM_STAGING))
133133
mkdir -p $(SM_STAGING)$(SM_DEST)
@@ -231,6 +231,7 @@ install: precheck
231231
install -m 755 scripts/set-iscsi-initiator $(SM_STAGING)$(LIBEXEC)
232232
$(MAKE) -C dcopy install DESTDIR=$(SM_STAGING)
233233
$(MAKE) -C linstor install DESTDIR=$(SM_STAGING)
234+
$(MAKE) -C sm_typing install DESTDIR=$(SM_STAGING)
234235
ln -sf $(SM_DEST)blktap2.py $(SM_STAGING)$(BIN_DEST)/blktap2
235236
ln -sf $(SM_DEST)lcache.py $(SM_STAGING)$(BIN_DEST)tapdisk-cache-stats
236237
ln -sf /dev/null $(SM_STAGING)$(UDEV_RULES_DIR)/69-dm-lvm-metad.rules
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bitarray
2+
mypy
3+
python-linstor

drivers/BaseISCSI.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
# ISCSISR: ISCSI software initiator SR driver
1919
#
2020

21+
from sm_typing import override
22+
2123
import SR
24+
import VDI
2225
import util
2326
import time
2427
import LUNperVDI
@@ -100,11 +103,12 @@ def address(self):
100103
self._initPaths()
101104
return self._address
102105

103-
def handles(type):
106+
@override
107+
@staticmethod
108+
def handles(type) -> bool:
104109
return False
105-
handles = staticmethod(handles)
106110

107-
def _synchroniseAddrList(self, addrlist):
111+
def _synchroniseAddrList(self, addrlist) -> None:
108112
if not self.multihomed:
109113
return
110114
change = False
@@ -133,7 +137,8 @@ def _synchroniseAddrList(self, addrlist):
133137
except:
134138
pass
135139

136-
def load(self, sr_uuid):
140+
@override
141+
def load(self, sr_uuid) -> None:
137142
if self.force_tapdisk:
138143
self.sr_vditype = 'aio'
139144
else:
@@ -175,23 +180,23 @@ def load(self, sr_uuid):
175180
and ('chappassword' in self.dconf or 'chappassword_secret' in self.dconf):
176181
self.chapuser = self.dconf['chapuser'].encode('utf-8')
177182
if 'chappassword_secret' in self.dconf:
178-
self.chappassword = util.get_secret(self.session, self.dconf['chappassword_secret'])
183+
chappassword = util.get_secret(self.session, self.dconf['chappassword_secret'])
179184
else:
180-
self.chappassword = self.dconf['chappassword']
185+
chappassword = self.dconf['chappassword']
181186

182-
self.chappassword = self.chappassword.encode('utf-8')
187+
self.chappassword = chappassword.encode('utf-8')
183188

184189
self.incoming_chapuser = ""
185190
self.incoming_chappassword = ""
186191
if 'incoming_chapuser' in self.dconf \
187192
and ('incoming_chappassword' in self.dconf or 'incoming_chappassword_secret' in self.dconf):
188193
self.incoming_chapuser = self.dconf['incoming_chapuser'].encode('utf-8')
189194
if 'incoming_chappassword_secret' in self.dconf:
190-
self.incoming_chappassword = util.get_secret(self.session, self.dconf['incoming_chappassword_secret'])
195+
incoming_chappassword = util.get_secret(self.session, self.dconf['incoming_chappassword_secret'])
191196
else:
192-
self.incoming_chappassword = self.dconf['incoming_chappassword']
197+
incoming_chappassword = self.dconf['incoming_chappassword']
193198

194-
self.incoming_chappassword = self.incoming_chappassword.encode('utf-8')
199+
self.incoming_chappassword = incoming_chappassword.encode('utf-8')
195200

196201
self.port = DEFAULT_PORT
197202
if 'port' in self.dconf and self.dconf['port']:
@@ -276,7 +281,7 @@ def _initPaths(self):
276281
self._address = self.tgtidx
277282
self._synchroniseAddrList(addrlist)
278283

279-
def _init_adapters(self):
284+
def _init_adapters(self) -> None:
280285
# Generate a list of active adapters
281286
ids = scsiutil._genHostList(ISCSI_PROCNAME)
282287
util.SMlog(ids)
@@ -293,7 +298,8 @@ def _init_adapters(self):
293298
pass
294299
self._devs = scsiutil.cacheSCSIidentifiers()
295300

296-
def attach(self, sr_uuid):
301+
@override
302+
def attach(self, sr_uuid) -> None:
297303
self._mpathHandle()
298304

299305
multiTargets = False
@@ -391,10 +397,9 @@ def attach(self, sr_uuid):
391397
util._incr_iscsiSR_refcount(self.targetIQN, sr_uuid)
392398
IQNs = []
393399
if "multiSession" in self.dconf:
394-
IQNs = ""
395400
for iqn in self.dconf['multiSession'].split("|"):
396401
if len(iqn):
397-
IQNs += iqn.split(',')[2]
402+
IQNs.append(iqn.split(',')[2])
398403
else:
399404
IQNs.append(self.targetIQN)
400405

@@ -429,7 +434,11 @@ def attach(self, sr_uuid):
429434
realdev = os.path.realpath(os.path.join(dev_path, dev))
430435
util.set_scheduler(os.path.basename(realdev))
431436

432-
def detach(self, sr_uuid, delete=False):
437+
@override
438+
def detach(self, sr_uuid) -> None:
439+
self.detach_and_delete(sr_uuid, delete=False)
440+
441+
def detach_and_delete(self, sr_uuid, delete=True) -> None:
433442
keys = []
434443
pbdref = None
435444
try:
@@ -470,7 +479,8 @@ def detach(self, sr_uuid, delete=False):
470479

471480
self.attached = False
472481

473-
def create(self, sr_uuid, size):
482+
@override
483+
def create(self, sr_uuid, size) -> None:
474484
# Check whether an SR already exists
475485
SRs = self.session.xenapi.SR.get_all_records()
476486
for sr in SRs:
@@ -499,11 +509,13 @@ def create(self, sr_uuid, size):
499509
self.session.xenapi.SR.set_sm_config(self.sr_ref, self.sm_config)
500510
return
501511

502-
def delete(self, sr_uuid):
512+
@override
513+
def delete(self, sr_uuid) -> None:
503514
self.detach(sr_uuid)
504515
return
505516

506-
def probe(self):
517+
@override
518+
def probe(self) -> str:
507519
SRs = self.session.xenapi.SR.get_all_records()
508520
Recs = {}
509521
for sr in SRs:
@@ -513,8 +525,9 @@ def probe(self):
513525
sm_config['targetIQN'] == self.targetIQN:
514526
Recs[record["uuid"]] = sm_config
515527
return self.srlist_toxml(Recs)
516-
517-
def scan(self, sr_uuid):
528+
529+
@override
530+
def scan(self, sr_uuid) -> None:
518531
if not self.passthrough:
519532
if not self.attached:
520533
raise xs_errors.XenError('SRUnavailable')
@@ -526,9 +539,10 @@ def scan(self, sr_uuid):
526539
if vdi.managed:
527540
self.physical_utilisation += vdi.size
528541
self.virtual_allocation = self.physical_utilisation
529-
return super(BaseISCSISR, self).scan(sr_uuid)
542+
super(BaseISCSISR, self).scan(sr_uuid)
530543

531-
def vdi(self, uuid):
544+
@override
545+
def vdi(self, uuid) -> VDI.VDI:
532546
return LUNperVDI.RAWVDI(self, uuid)
533547

534548
def _scan_IQNs(self):

drivers/CephFSSR.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#
1919
# CEPHFSSR: Based on FileSR, mounts ceph fs share
2020

21+
from sm_typing import override
22+
2123
import errno
2224
import os
2325
import socket
@@ -33,6 +35,7 @@
3335
import SRCommand
3436
import FileSR
3537
# end of careful
38+
import VDI
3639
import cleanup
3740
import util
3841
import vhdutil
@@ -83,13 +86,14 @@ class CephFSSR(FileSR.FileSR):
8386

8487
DRIVER_TYPE = 'cephfs'
8588

86-
def handles(sr_type):
89+
@override
90+
@staticmethod
91+
def handles(sr_type) -> bool:
8792
# fudge, because the parent class (FileSR) checks for smb to alter its behavior
8893
return sr_type == CephFSSR.DRIVER_TYPE or sr_type == 'smb'
8994

90-
handles = staticmethod(handles)
91-
92-
def load(self, sr_uuid):
95+
@override
96+
def load(self, sr_uuid) -> None:
9397
if not self._is_ceph_available():
9498
raise xs_errors.XenError(
9599
'SRUnavailable',
@@ -180,7 +184,8 @@ def unmount(self, mountpoint, rmmountpoint):
180184
except OSError as inst:
181185
raise CephFSException("rmdir failed with error '%s'" % inst.strerror)
182186

183-
def attach(self, sr_uuid):
187+
@override
188+
def attach(self, sr_uuid) -> None:
184189
if not self.checkmount():
185190
try:
186191
self.mount()
@@ -189,18 +194,19 @@ def attach(self, sr_uuid):
189194
raise xs_errors.SROSError(12, exc.errstr)
190195
self.attached = True
191196

192-
def probe(self):
197+
@override
198+
def probe(self) -> str:
193199
try:
194200
self.mount(PROBE_MOUNTPOINT)
195201
sr_list = filter(util.match_uuid, util.listdir(PROBE_MOUNTPOINT))
196202
self.unmount(PROBE_MOUNTPOINT, True)
197203
except (util.CommandException, xs_errors.XenError):
198204
raise
199205
# Create a dictionary from the SR uuids to feed SRtoXML()
200-
sr_dict = {sr_uuid: {} for sr_uuid in sr_list}
201-
return util.SRtoXML(sr_dict)
206+
return util.SRtoXML({sr_uuid: {} for sr_uuid in sr_list})
202207

203-
def detach(self, sr_uuid):
208+
@override
209+
def detach(self, sr_uuid) -> None:
204210
if not self.checkmount():
205211
return
206212
util.SMlog("Aborting GC/coalesce")
@@ -211,7 +217,8 @@ def detach(self, sr_uuid):
211217
os.unlink(self.path)
212218
self.attached = False
213219

214-
def create(self, sr_uuid, size):
220+
@override
221+
def create(self, sr_uuid, size) -> None:
215222
if self.checkmount():
216223
raise xs_errors.SROSError(113, 'CephFS mount point already attached')
217224

@@ -245,7 +252,8 @@ def create(self, sr_uuid, size):
245252
os.strerror(inst.code)))
246253
self.detach(sr_uuid)
247254

248-
def delete(self, sr_uuid):
255+
@override
256+
def delete(self, sr_uuid) -> None:
249257
# try to remove/delete non VDI contents first
250258
super(CephFSSR, self).delete(sr_uuid)
251259
try:
@@ -260,24 +268,26 @@ def delete(self, sr_uuid):
260268
if inst.code != errno.ENOENT:
261269
raise xs_errors.SROSError(114, "Failed to remove CephFS mount point")
262270

263-
def vdi(self, uuid, loadLocked=False):
271+
@override
272+
def vdi(self, uuid, loadLocked=False) -> VDI.VDI:
264273
return CephFSFileVDI(self, uuid)
265274

266275
@staticmethod
267276
def _is_ceph_available():
268-
import distutils.spawn
269-
return distutils.spawn.find_executable('ceph')
277+
return util.find_executable('ceph')
270278

271279
class CephFSFileVDI(FileSR.FileVDI):
272-
def attach(self, sr_uuid, vdi_uuid):
280+
@override
281+
def attach(self, sr_uuid, vdi_uuid) -> str:
273282
if not hasattr(self, 'xenstore_data'):
274283
self.xenstore_data = {}
275284

276285
self.xenstore_data['storage-type'] = CephFSSR.DRIVER_TYPE
277286

278287
return super(CephFSFileVDI, self).attach(sr_uuid, vdi_uuid)
279288

280-
def generate_config(self, sr_uuid, vdi_uuid):
289+
@override
290+
def generate_config(self, sr_uuid, vdi_uuid) -> str:
281291
util.SMlog("SMBFileVDI.generate_config")
282292
if not util.pathexists(self.path):
283293
raise xs_errors.XenError('VDIUnavailable')
@@ -291,15 +301,16 @@ def generate_config(self, sr_uuid, vdi_uuid):
291301
config = xmlrpc.client.dumps(tuple([resp]), "vdi_attach_from_config")
292302
return xmlrpc.client.dumps((config,), "", True)
293303

294-
def attach_from_config(self, sr_uuid, vdi_uuid):
304+
@override
305+
def attach_from_config(self, sr_uuid, vdi_uuid) -> str:
295306
try:
296307
if not util.pathexists(self.sr.path):
297-
self.sr.attach(sr_uuid)
308+
return self.sr.attach(sr_uuid)
298309
except:
299310
util.logException("SMBFileVDI.attach_from_config")
300311
raise xs_errors.XenError('SRUnavailable',
301312
opterr='Unable to attach from config')
302-
313+
return ''
303314

304315
if __name__ == '__main__':
305316
SRCommand.run(CephFSSR, DRIVER_INFO)

0 commit comments

Comments
 (0)