-
Notifications
You must be signed in to change notification settings - Fork 80
<bug>[sblk]: fix vg being re created #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
|
||
|
||
storage_device_utils.init_storagedevice_plugin() | ||
init_kvmagent() | ||
vm_utils.init_vm_plugin() | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
|
||
|
||
storage_device_utils.init_storagedevice_plugin() | ||
init_kvmagent() | ||
vm_utils.init_vm_plugin() | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,91 @@ | ||||||
# coding=utf-8 | ||||||
from kvmagent.test.shareblock_testsuite.shared_block_plugin_teststub import SharedBlockPluginTestStub | ||||||
from kvmagent.test.utils import sharedblock_utils,pytest_utils,storage_device_utils | ||||||
from zstacklib.utils import bash, lvm, jsonobject | ||||||
from unittest import TestCase | ||||||
from zstacklib.test.utils import misc,env | ||||||
|
||||||
|
||||||
storage_device_utils.init_storagedevice_plugin() | ||||||
|
||||||
PKG_NAME = __name__ | ||||||
|
||||||
# must create iSCSI stroage before run test | ||||||
__ENV_SETUP__ = { | ||||||
'self': { | ||||||
'xml':'http://smb.zstack.io/mirror/ztest/xml/threeDiskVm.xml', | ||||||
'init':['bash ./createTwoLunsIscsiStorage.sh'] | ||||||
} | ||||||
} | ||||||
|
||||||
hostUuid = "8b12f74e6a834c5fa90304b8ea54b1dd" | ||||||
hostId = 24 | ||||||
vgUuid = "36b02490bb944233b0b01990a450ba83" | ||||||
vg2Uuid = "ee09b7986bbc4a1f85f439b168c3aee7" | ||||||
|
||||||
Comment on lines
+21
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在测试用例中使用硬编码的UUID和主机ID可能不是最佳实践,因为在不同的环境或资源下运行测试时可能会导致问题。建议使用动态生成或配置文件中的值来替换这些硬编码值。 |
||||||
## describe: case will manage by ztest | ||||||
class TestSharedBlockPlugin(TestCase, SharedBlockPluginTestStub): | ||||||
@classmethod | ||||||
def setUpClass(cls): | ||||||
pass | ||||||
@pytest_utils.ztest_decorater | ||||||
def test_sharedblock_check_lock(self): | ||||||
self_vm = env.get_vm_metadata('self') | ||||||
rsp = storage_device_utils.iscsi_login( | ||||||
self_vm.ip,"3260" | ||||||
) | ||||||
self.assertEqual(rsp.success, True, rsp.error) | ||||||
|
||||||
# test connect shareblock | ||||||
r, o = bash.bash_ro("ls /dev/disk/by-id | grep scsi|awk -F '-' '{print $2}'") | ||||||
blockUuids = o.strip().splitlines() | ||||||
|
||||||
rsp = self.connect(blockUuids[0 : 1], blockUuids, vgUuid, hostUuid, hostId, forceWipe=True) | ||||||
self.assertEqual(True, rsp.success, rsp.error) | ||||||
o = bash.bash_o("vgs") | ||||||
self.assertEqual(True, rsp.success, o) | ||||||
|
||||||
rsp = self.connect(blockUuids[1 : 2], blockUuids, vg2Uuid, hostUuid, hostId, forceWipe=True) | ||||||
self.assertEqual(True, rsp.success, rsp.error) | ||||||
|
||||||
# normal | ||||||
rsp = sharedblock_utils.sharedblock_check_lock( | ||||||
vgUuids=[vgUuid, vg2Uuid], | ||||||
) | ||||||
self.assertEqual(True, rsp.success, rsp.error) | ||||||
self.assertEqual(0, len(rsp.failedVgs), rsp.failedVgs.__dict__) | ||||||
|
||||||
# vg without a lock | ||||||
lvm.drop_vg_lock(vgUuid) | ||||||
|
||||||
rsp = sharedblock_utils.sharedblock_check_lock( | ||||||
vgUuids=[vgUuid, vg2Uuid], | ||||||
) | ||||||
self.assertEqual(True, rsp.success, rsp.error) | ||||||
self.assertEqual(1, len(rsp.failedVgs), rsp.failedVgs.__dict__) | ||||||
self.assertEqual(rsp.failedVgs.hasattr(vgUuid), True, rsp.failedVgs.__dict__) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
- self.assertEqual(rsp.failedVgs.hasattr(vgUuid), True, rsp.failedVgs.__dict__)
+ self.assertIn(vgUuid, rsp.failedVgs, str(rsp.failedVgs)) Committable suggestion
Suggested change
|
||||||
|
||||||
rsp = self.connect(blockUuids[0 : 1], blockUuids, vgUuid, hostUuid, hostId, forceWipe=False) | ||||||
self.assertEqual(True, rsp.success, rsp.error) | ||||||
|
||||||
# If there is no lv, restarting lvmlockd may not restore vg lock(lvm 2.03.11) | ||||||
bash.bash_errorout("lvcreate --size 10M %s" % vgUuid) | ||||||
bash.bash_errorout("lvcreate --size 10M %s" % vg2Uuid) | ||||||
|
||||||
# kill lvmlockd | ||||||
lvm.stop_lvmlockd() | ||||||
rsp = sharedblock_utils.sharedblock_check_lock( | ||||||
vgUuids=[vgUuid, vg2Uuid], | ||||||
) | ||||||
self.assertEqual(True, rsp.success, rsp.error) | ||||||
self.assertEqual(rsp.failedVgs.hasattr(vgUuid), True, str(rsp.failedVgs)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上,这里的 - self.assertEqual(rsp.failedVgs.hasattr(vgUuid), True, str(rsp.failedVgs))
+ self.assertIn(vgUuid, rsp.failedVgs, str(rsp.failedVgs)) Committable suggestion
Suggested change
|
||||||
self.assertEqual(rsp.failedVgs.hasattr(vg2Uuid), True, str(rsp.failedVgs)) | ||||||
|
||||||
rsp = self.connect(blockUuids[0 : 1], blockUuids, vgUuid, hostUuid, hostId, forceWipe=False) | ||||||
self.assertEqual(True, rsp.success, rsp.error) | ||||||
rsp = self.connect(blockUuids[1 : 2], blockUuids, vg2Uuid, hostUuid, hostId, forceWipe=False) | ||||||
self.assertEqual(True, rsp.success, rsp.error) | ||||||
bash.bash_errorout("lvcreate --size 10M %s" % vgUuid) | ||||||
bash.bash_errorout("lvcreate --size 10M %s" % vg2Uuid) | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
|
||
|
||
storage_device_utils.init_storagedevice_plugin() | ||
init_kvmagent() | ||
vm_utils.init_vm_plugin() | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import os | ||
import coverage | ||
from zstacklib.test.utils import env | ||
from zstacklib.utils import debug | ||
|
||
Out_flag = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 全局变量 |
||
|
||
|
||
debug.install_runtime_tracedumper() | ||
class PytestExtension(object): | ||
|
||
cov = None | ||
Comment on lines
1
to
11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
在
函数名 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,15 +20,16 @@ def sharedblock_ping(vgUuid): | |
})) | ||
|
||
@misc.return_jsonobject() | ||
def shareblock_connect(sharedBlockUuids=None, allSharedBlockUuids=None, vgUuid=None,hostId=None,hostUuid=None, forceWipe=True): | ||
def shareblock_connect(sharedBlockUuids=None, allSharedBlockUuids=None, vgUuid=None,hostId=None,hostUuid=None, forceWipe=True, isFirst=True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在 |
||
return get_sharedblock_plugin().connect(misc.make_a_request({ | ||
"sharedBlockUuids":sharedBlockUuids, # [], ls /dev/disk/by-id -l|grep scsi | ||
"allSharedBlockUuids":allSharedBlockUuids, | ||
"vgUuid": vgUuid ,# random uuid | ||
"hostId":hostId, | ||
"hostUuid": hostUuid, | ||
"forceWipe": forceWipe, | ||
"primaryStorageUuid":vgUuid | ||
"primaryStorageUuid":vgUuid, | ||
"isFirst":isFirst | ||
})) | ||
|
||
@misc.return_jsonobject() | ||
|
@@ -313,3 +314,9 @@ def shareblock_get_qcow2_hashvalue(installPath=None): | |
return get_sharedblock_plugin().get_qcow2_hashvalue(misc.make_a_request({ | ||
"installPath": installPath | ||
})) | ||
|
||
@misc.return_jsonobject() | ||
def sharedblock_check_lock(vgUuids=[]): | ||
return get_sharedblock_plugin().check_lock(misc.make_a_request({ | ||
"vgUuids": vgUuids | ||
})) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,3 +29,15 @@ def list_and(list1, list2): | |||||||||||||||||||||||||||||||||||||||||||||
new_list.append(item) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
return new_list | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
def list_split(list, n): | ||||||||||||||||||||||||||||||||||||||||||||||
if len(list) == 0: | ||||||||||||||||||||||||||||||||||||||||||||||
return list | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if n <= 0: | ||||||||||||||||||||||||||||||||||||||||||||||
raise Exception("num must be positive") | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
result = [[] for _ in range(min(n, len(list)))] | ||||||||||||||||||||||||||||||||||||||||||||||
for i, v in enumerate(list): | ||||||||||||||||||||||||||||||||||||||||||||||
result[i % n].append(v) | ||||||||||||||||||||||||||||||||||||||||||||||
return result | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+33
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using - def list_split(list, n):
+ def list_split(input_list, n):
- if len(list) == 0:
+ if len(input_list) == 0:
- return list
+ return [[]]
- raise Exception("num must be positive")
+ raise Exception("n must be positive")
- result = [[] for _ in range(min(n, len(list)))]
+ result = [[] for _ in range(min(n, len(input_list)))]
- for i, v in enumerate(list):
+ for i, v in enumerate(input_list): Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1814,9 +1814,12 @@ def check_pv_status(vgUuid, timeout): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return True, "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@bash.in_bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def vgck(vgUuid, timeout): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return bash.bash_roe('timeout -s SIGKILL %s vgck %s 2>&1' % (timeout, vgUuid)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1818
to
+1819
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - return bash.bash_roe('timeout -s SIGKILL %s vgck %s 2>&1' % (timeout, vgUuid))
+ # Ensure that the timeout command is available or handle its absence
+ if not shell.command_exists('timeout'):
+ raise Exception('The "timeout" command is not available on this system.')
+ return bash.bash_roe('timeout -s SIGKILL %s vgck %s 2>&1' % (timeout, vgUuid)) Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def lvm_vgck(vgUuid, timeout): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
health, o, e = bash.bash_roe('timeout -s SIGKILL %s vgck %s 2>&1' % (360 if timeout < 360 else timeout, vgUuid)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
health, o, e = vgck(vgUuid, 360 if timeout < 360 else timeout) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
check_stuck_vglk() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if health != 0: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
1814
to
1825
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - health, o, e = vgck(vgUuid, 360 if timeout < 360 else timeout)
+ # Consider replacing the hardcoded value with a configurable parameter or constant
+ health, o, e = vgck(vgUuid, timeout) Committable suggestion
Suggested change
Comment on lines
1821
to
1825
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - check_stuck_vglk()
+ # Handle the result of check_stuck_vglk
+ try:
+ check_stuck_vglk()
+ except Exception as e:
+ logger.error('An error occurred while checking for stuck vglk: %s' % str(e))
+ return False, 'An error occurred while checking for stuck vglk' Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在
create_vg_if_not_found
方法中,当is_first_create_vg
为False
时,抛出异常以防止数据丢失,这与PR目标一致。但是,在add_disk
方法中调用create_vg_if_not_found
时,没有传递is_first_create_vg
参数,这可能会导致在不应该创建vg时创建vg,从而可能导致数据丢失。建议在add_disk
方法中添加对is_first_create_vg
参数的处理。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我在 create_vg_if_not_found 的 is_first_create_vg 参数设置为默认 false,是不是这样就比较安全,就不需要在 add_disk 里加了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MatheMatrix 您的建议将
is_first_create_vg
参数的默认值设置为False
是一个安全的做法,这样可以确保在默认情况下不会无意中重新创建卷组,从而避免数据丢失。如果您的代码逻辑中确实需要在某些情况下创建新的卷组,您可以显式地将该参数设置为True
。这样,就不需要在add_disk
方法中添加额外的处理了。🐰