|
| 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 | + |
0 commit comments