Skip to content

Commit 8164f6e

Browse files
shan.wuMatheMatrix
authored andcommitted
<bug>[sblk]: add ping check for sblk vg lock
add ping check for sblk vg lock http://jira.zstack.io/browse/SUG-411 Resolves/Related: SUG-411 Change-Id: 3c246404f4944e4db991250bf103b464
1 parent 88c9e6c commit 8164f6e

File tree

9 files changed

+160
-6
lines changed

9 files changed

+160
-6
lines changed

kvmagent/kvmagent/plugins/shared_block_plugin.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from zstacklib.utils import linux
1818
from zstacklib.utils import lock
1919
from zstacklib.utils import lvm
20+
from zstacklib.utils import list_ops
2021
from zstacklib.utils import bash
2122
from zstacklib.utils import qemu_img, qcow2
2223
from zstacklib.utils import traceable_shell
@@ -353,6 +354,7 @@ class SharedBlockPlugin(kvmagent.KvmAgent):
353354
CONVERT_VOLUME_FORMAT_PATH = "/sharedblock/volume/convertformat"
354355
SHRINK_SNAPSHOT_PATH = "/sharedblock/snapshot/shrink"
355356
GET_QCOW2_HASH_VALUE_PATH = "/sharedblock/getqcow2hash"
357+
CHECK_LOCK_PATH = "/sharedblock/lock/check"
356358

357359
vgs_in_progress = set()
358360
vg_size = {}
@@ -401,6 +403,7 @@ def start(self):
401403
http_server.register_async_uri(self.GET_DOWNLOAD_BITS_FROM_KVM_HOST_PROGRESS_PATH, self.get_download_bits_from_kvmhost_progress)
402404
http_server.register_async_uri(self.SHRINK_SNAPSHOT_PATH, self.shrink_snapshot)
403405
http_server.register_async_uri(self.GET_QCOW2_HASH_VALUE_PATH, self.get_qcow2_hashvalue)
406+
http_server.register_async_uri(self.CHECK_LOCK_PATH, self.check_lock)
404407

405408
self.imagestore_client = ImageStoreClient()
406409

@@ -502,7 +505,7 @@ def ping(self, req):
502505
cmd = jsonobject.loads(req[http.REQUEST_BODY])
503506
rsp = AgentRsp()
504507
size_cache = self.vg_size.get(cmd.vgUuid)
505-
if size_cache != None and linux.get_current_timestamp() - size_cache['currentTimestamp'] < 60:
508+
if size_cache is not None and linux.get_current_timestamp() - size_cache['currentTimestamp'] < 60:
506509
rsp.totalCapacity = size_cache['totalCapacity']
507510
rsp.availableCapacity = size_cache['availableCapacity']
508511
elif cmd.vgUuid not in self.vgs_in_progress:
@@ -1644,4 +1647,45 @@ def get_qcow2_hashvalue(self, req):
16441647

16451648
with lvm.RecursiveOperateLv(abs_path, shared=True):
16461649
rsp.hashValue = secret.get_image_hash(abs_path)
1650+
return jsonobject.dumps(rsp)
1651+
1652+
@kvmagent.replyerror
1653+
def check_lock(self, req):
1654+
cmd = jsonobject.loads(req[http.REQUEST_BODY])
1655+
rsp = AgentRsp()
1656+
if cmd.vgUuids is None or len(cmd.vgUuids) == 0:
1657+
return jsonobject.dumps(rsp)
1658+
1659+
rsp.failedVgs = {}
1660+
1661+
def vgck(vg_group):
1662+
if len(vg_group) == 0:
1663+
return
1664+
1665+
vgUuid = vg_group.pop(0)
1666+
r, o, e = lvm.vgck(vgUuid, 10)
1667+
1668+
if o is not None and o != "":
1669+
for es in o.strip().splitlines():
1670+
if "lock start in progress" in es:
1671+
break
1672+
elif "held by other host" in es:
1673+
break
1674+
elif "Reading VG %s without a lock" % vgUuid in es:
1675+
rsp.failedVgs.update({vgUuid : o})
1676+
break
1677+
vgck(vg_group)
1678+
1679+
# up to three worker threads executing vgck
1680+
threads_maxnum = 3
1681+
vg_groups = list_ops.list_split(cmd.vgUuids, threads_maxnum)
1682+
1683+
threads = []
1684+
for vg_group in vg_groups:
1685+
if len(vg_group) != 0:
1686+
threads.append(thread.ThreadFacade.run_in_thread(vgck, (vg_group,)))
1687+
1688+
for t in threads:
1689+
t.join()
1690+
16471691
return jsonobject.dumps(rsp)

kvmagent/kvmagent/test/shareblock_testsuite/test_shareblock_data_volume_with_iothreadpin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212

1313
storage_device_utils.init_storagedevice_plugin()
14-
init_kvmagent()
1514
vm_utils.init_vm_plugin()
1615

1716

kvmagent/kvmagent/test/shareblock_testsuite/test_shareblock_data_volume_with_multi_queues.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212

1313
storage_device_utils.init_storagedevice_plugin()
14-
init_kvmagent()
1514
vm_utils.init_vm_plugin()
1615

1716

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# coding=utf-8
2+
from kvmagent.test.shareblock_testsuite.shared_block_plugin_teststub import SharedBlockPluginTestStub
3+
from kvmagent.test.utils import sharedblock_utils,pytest_utils,storage_device_utils
4+
from zstacklib.utils import bash, lvm, jsonobject
5+
from unittest import TestCase
6+
from zstacklib.test.utils import misc,env
7+
8+
9+
storage_device_utils.init_storagedevice_plugin()
10+
11+
PKG_NAME = __name__
12+
13+
# must create iSCSI stroage before run test
14+
__ENV_SETUP__ = {
15+
'self': {
16+
'xml':'http://smb.zstack.io/mirror/ztest/xml/threeDiskVm.xml',
17+
'init':['bash ./createTwoLunsIscsiStorage.sh']
18+
}
19+
}
20+
21+
hostUuid = "8b12f74e6a834c5fa90304b8ea54b1dd"
22+
hostId = 24
23+
vgUuid = "36b02490bb944233b0b01990a450ba83"
24+
vg2Uuid = "ee09b7986bbc4a1f85f439b168c3aee7"
25+
26+
## describe: case will manage by ztest
27+
class TestSharedBlockPlugin(TestCase, SharedBlockPluginTestStub):
28+
@classmethod
29+
def setUpClass(cls):
30+
pass
31+
@pytest_utils.ztest_decorater
32+
def test_sharedblock_check_lock(self):
33+
self_vm = env.get_vm_metadata('self')
34+
rsp = storage_device_utils.iscsi_login(
35+
self_vm.ip,"3260"
36+
)
37+
self.assertEqual(rsp.success, True, rsp.error)
38+
39+
# test connect shareblock
40+
r, o = bash.bash_ro("ls /dev/disk/by-id | grep scsi|awk -F '-' '{print $2}'")
41+
blockUuids = o.strip().splitlines()
42+
43+
rsp = self.connect(blockUuids[0 : 1], blockUuids, vgUuid, hostUuid, hostId, forceWipe=True)
44+
self.assertEqual(True, rsp.success, rsp.error)
45+
o = bash.bash_o("vgs")
46+
self.assertEqual(True, rsp.success, o)
47+
48+
rsp = self.connect(blockUuids[1 : 2], blockUuids, vg2Uuid, hostUuid, hostId, forceWipe=True)
49+
self.assertEqual(True, rsp.success, rsp.error)
50+
51+
# normal
52+
rsp = sharedblock_utils.sharedblock_check_lock(
53+
vgUuids=[vgUuid, vg2Uuid],
54+
)
55+
self.assertEqual(True, rsp.success, rsp.error)
56+
self.assertEqual(0, len(rsp.failedVgs), rsp.failedVgs.__dict__)
57+
58+
# vg without a lock
59+
lvm.drop_vg_lock(vgUuid)
60+
61+
rsp = sharedblock_utils.sharedblock_check_lock(
62+
vgUuids=[vgUuid, vg2Uuid],
63+
)
64+
self.assertEqual(True, rsp.success, rsp.error)
65+
self.assertEqual(1, len(rsp.failedVgs), rsp.failedVgs.__dict__)
66+
self.assertEqual(rsp.failedVgs.hasattr(vgUuid), True, rsp.failedVgs.__dict__)
67+
68+
rsp = self.connect(blockUuids[0 : 1], blockUuids, vgUuid, hostUuid, hostId, forceWipe=False)
69+
self.assertEqual(True, rsp.success, rsp.error)
70+
71+
# If there is no lv, restarting lvmlockd may not restore vg lock(lvm 2.03.11)
72+
bash.bash_errorout("lvcreate --size 10M %s" % vgUuid)
73+
bash.bash_errorout("lvcreate --size 10M %s" % vg2Uuid)
74+
75+
# kill lvmlockd
76+
lvm.stop_lvmlockd()
77+
rsp = sharedblock_utils.sharedblock_check_lock(
78+
vgUuids=[vgUuid, vg2Uuid],
79+
)
80+
self.assertEqual(True, rsp.success, rsp.error)
81+
self.assertEqual(rsp.failedVgs.hasattr(vgUuid), True, str(rsp.failedVgs))
82+
self.assertEqual(rsp.failedVgs.hasattr(vg2Uuid), True, str(rsp.failedVgs))
83+
84+
rsp = self.connect(blockUuids[0 : 1], blockUuids, vgUuid, hostUuid, hostId, forceWipe=False)
85+
self.assertEqual(True, rsp.success, rsp.error)
86+
rsp = self.connect(blockUuids[1 : 2], blockUuids, vg2Uuid, hostUuid, hostId, forceWipe=False)
87+
self.assertEqual(True, rsp.success, rsp.error)
88+
bash.bash_errorout("lvcreate --size 10M %s" % vgUuid)
89+
bash.bash_errorout("lvcreate --size 10M %s" % vg2Uuid)
90+
91+

kvmagent/kvmagent/test/shareblock_testsuite/test_virtio_scsi_shareblock_data_volume_with_iothreadpin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212

1313
storage_device_utils.init_storagedevice_plugin()
14-
init_kvmagent()
1514
vm_utils.init_vm_plugin()
1615

1716

kvmagent/kvmagent/test/utils/pytest_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os
22
import coverage
33
from zstacklib.test.utils import env
4+
from zstacklib.utils import debug
45

56
Out_flag = True
67

7-
8+
debug.install_runtime_tracedumper()
89
class PytestExtension(object):
910

1011
cov = None

kvmagent/kvmagent/test/utils/sharedblock_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,9 @@ def shareblock_get_qcow2_hashvalue(installPath=None):
314314
return get_sharedblock_plugin().get_qcow2_hashvalue(misc.make_a_request({
315315
"installPath": installPath
316316
}))
317+
318+
@misc.return_jsonobject()
319+
def sharedblock_check_lock(vgUuids=[]):
320+
return get_sharedblock_plugin().check_lock(misc.make_a_request({
321+
"vgUuids": vgUuids
322+
}))

zstacklib/zstacklib/utils/list_ops.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,15 @@ def list_and(list1, list2):
2929
new_list.append(item)
3030

3131
return new_list
32+
33+
def list_split(list, n):
34+
if len(list) == 0:
35+
return list
36+
37+
if n <= 0:
38+
raise Exception("num must be positive")
39+
40+
result = [[] for _ in range(min(n, len(list)))]
41+
for i, v in enumerate(list):
42+
result[i % n].append(v)
43+
return result

zstacklib/zstacklib/utils/lvm.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1814,9 +1814,12 @@ def check_pv_status(vgUuid, timeout):
18141814

18151815
return True, ""
18161816

1817+
@bash.in_bash
1818+
def vgck(vgUuid, timeout):
1819+
return bash.bash_roe('timeout -s SIGKILL %s vgck %s 2>&1' % (timeout, vgUuid))
18171820

18181821
def lvm_vgck(vgUuid, timeout):
1819-
health, o, e = bash.bash_roe('timeout -s SIGKILL %s vgck %s 2>&1' % (360 if timeout < 360 else timeout, vgUuid))
1822+
health, o, e = vgck(vgUuid, 360 if timeout < 360 else timeout)
18201823
check_stuck_vglk()
18211824

18221825
if health != 0:

0 commit comments

Comments
 (0)