[PATCH 3/3] storage: Add tests for the Linstor storage backend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Rene Peinthor <rene.peinthor@xxxxxxxxxx>
---
 tests/linstorjsondata/broken.json             |   1 +
 tests/linstorjsondata/resource-group.json     |   1 +
 .../linstorjsondata/resource-list-test2.json  | 332 ++++++++++++++++
 .../storage-pools-ssdpool.json                |  72 ++++
 tests/linstorjsondata/storage-pools.json      | 192 +++++++++
 tests/linstorjsondata/volume-def-list.json    | 158 ++++++++
 .../volume-definition-test2.json              |   1 +
 tests/meson.build                             |   6 +
 tests/storagebackendlinstortest.c             | 372 ++++++++++++++++++
 tests/storagepoolxml2xmlin/pool-linstor.xml   |   8 +
 tests/storagevolxml2xmlin/vol-linstor.xml     |  10 +
 11 files changed, 1153 insertions(+)
 create mode 100644 tests/linstorjsondata/broken.json
 create mode 100644 tests/linstorjsondata/resource-group.json
 create mode 100644 tests/linstorjsondata/resource-list-test2.json
 create mode 100644 tests/linstorjsondata/storage-pools-ssdpool.json
 create mode 100644 tests/linstorjsondata/storage-pools.json
 create mode 100644 tests/linstorjsondata/volume-def-list.json
 create mode 100644 tests/linstorjsondata/volume-definition-test2.json
 create mode 100644 tests/storagebackendlinstortest.c
 create mode 100644 tests/storagepoolxml2xmlin/pool-linstor.xml
 create mode 100644 tests/storagevolxml2xmlin/vol-linstor.xml

diff --git a/tests/linstorjsondata/broken.json b/tests/linstorjsondata/broken.json
new file mode 100644
index 0000000000..bce5bde3c6
--- /dev/null
+++ b/tests/linstorjsondata/broken.json
@@ -0,0 +1 @@
+[[{"name":"DfltRscGrp","select_filter":{"place_count":2},id":"a52e934a-9fd9-44cb-9db1-716dcd13aae3"},{"name":"libvirtgrp","select_filter":{"place_count":2,"storage_pool":"thinpool","storage_pool_list":["thinpool"]},"uuid":"7ec0bdee-9176-470e-8f7d-532032434160"}]]
diff --git a/tests/linstorjsondata/resource-group.json b/tests/linstorjsondata/resource-group.json
new file mode 100644
index 0000000000..3a2f959ad7
--- /dev/null
+++ b/tests/linstorjsondata/resource-group.json
@@ -0,0 +1 @@
+[[{"name":"DfltRscGrp","select_filter":{"place_count":2},"uuid":"a52e934a-9fd9-44cb-9db1-716dcd13aae3"},{"name":"libvirtgrp","select_filter":{"place_count":2,"storage_pool":"thinpool","storage_pool_list":["thinpool"]},"uuid":"7ec0bdee-9176-470e-8f7d-532032434160"}]]
diff --git a/tests/linstorjsondata/resource-list-test2.json b/tests/linstorjsondata/resource-list-test2.json
new file mode 100644
index 0000000000..86e7f04d82
--- /dev/null
+++ b/tests/linstorjsondata/resource-list-test2.json
@@ -0,0 +1,332 @@
+[
+  [
+    {
+      "name": "test2",
+      "node_name": "linstor1",
+      "props": {
+        "StorPoolName": "thinpool"
+      },
+      "layer_object": {
+        "children": [
+          {
+            "type": "STORAGE",
+            "storage": {
+              "storage_volumes": [
+                {
+                  "volume_number": 0,
+                  "device_path": "/dev/scratch/test2_00000",
+                  "allocated_size_kib": 106496,
+                  "usable_size_kib": 106496,
+                  "disk_state": "[]"
+                }
+              ]
+            }
+          }
+        ],
+        "type": "DRBD",
+        "drbd": {
+          "drbd_resource_definition": {
+            "peer_slots": 7,
+            "al_stripes": 1,
+            "al_stripe_size_kib": 32,
+            "port": 7001,
+            "transport_type": "IP",
+            "secret": "2vD4CZEbaEAO3XIZ/ICv",
+            "down": false
+          },
+          "node_id": 0,
+          "peer_slots": 7,
+          "al_stripes": 1,
+          "al_size": 32,
+          "drbd_volumes": [
+            {
+              "drbd_volume_definition": {
+                "volume_number": 0,
+                "minor_number": 1001
+              },
+              "device_path": "/dev/drbd1001",
+              "backing_device": "/dev/scratch/test2_00000",
+              "allocated_size_kib": 102460,
+              "usable_size_kib": 102400
+            }
+          ],
+          "connections": {
+            "linstor2": {
+              "connected": true,
+              "message": "Connected"
+            },
+            "linstor3": {
+              "connected": true,
+              "message": "Connected"
+            }
+          },
+          "promotion_score": 10102,
+          "may_promote": true
+        }
+      },
+      "state": {
+        "in_use": false
+      },
+      "uuid": "a567d642-02ab-4dd3-8183-a726b20aa9d9",
+      "create_timestamp": 1606836534107,
+      "volumes": [
+        {
+          "volume_number": 0,
+          "storage_pool_name": "thinpool",
+          "provider_kind": "LVM_THIN",
+          "device_path": "/dev/drbd1001",
+          "allocated_size_kib": 63,
+          "state": {
+            "disk_state": "UpToDate"
+          },
+          "layer_data_list": [
+            {
+              "type": "DRBD",
+              "data": {
+                "drbd_volume_definition": {
+                  "volume_number": 0,
+                  "minor_number": 1001
+                },
+                "device_path": "/dev/drbd1001",
+                "backing_device": "/dev/scratch/test2_00000",
+                "allocated_size_kib": 102460,
+                "usable_size_kib": 102400
+              }
+            },
+            {
+              "type": "STORAGE",
+              "data": {
+                "volume_number": 0,
+                "device_path": "/dev/scratch/test2_00000",
+                "allocated_size_kib": 106496,
+                "usable_size_kib": 106496,
+                "disk_state": "[]"
+              }
+            }
+          ],
+          "uuid": "2e4b6876-c6a0-4df9-8283-5633fce67dee"
+        }
+      ]
+    },
+    {
+      "name": "test2",
+      "node_name": "linstor2",
+      "props": {
+        "StorPoolName": "DfltDisklessStorPool"
+      },
+      "flags": [
+        "DISKLESS",
+        "DRBD_DISKLESS",
+        "TIE_BREAKER"
+      ],
+      "layer_object": {
+        "children": [
+          {
+            "type": "STORAGE",
+            "storage": {
+              "storage_volumes": [
+                {
+                  "volume_number": 0,
+                  "allocated_size_kib": 0,
+                  "usable_size_kib": 102400
+                }
+              ]
+            }
+          }
+        ],
+        "type": "DRBD",
+        "drbd": {
+          "drbd_resource_definition": {
+            "peer_slots": 7,
+            "al_stripes": 1,
+            "al_stripe_size_kib": 32,
+            "port": 7001,
+            "transport_type": "IP",
+            "secret": "2vD4CZEbaEAO3XIZ/ICv",
+            "down": false
+          },
+          "node_id": 2,
+          "peer_slots": 7,
+          "al_stripes": 1,
+          "al_size": 32,
+          "flags": [
+            "DISKLESS",
+            "INITIALIZED"
+          ],
+          "drbd_volumes": [
+            {
+              "drbd_volume_definition": {
+                "volume_number": 0,
+                "minor_number": 1001
+              },
+              "device_path": "/dev/drbd1001",
+              "allocated_size_kib": -1,
+              "usable_size_kib": 102400
+            }
+          ],
+          "connections": {
+            "linstor1": {
+              "connected": true,
+              "message": "Connected"
+            },
+            "linstor3": {
+              "connected": true,
+              "message": "Connected"
+            }
+          },
+          "promotion_score": 2,
+          "may_promote": false
+        }
+      },
+      "state": {
+        "in_use": false
+      },
+      "uuid": "57696dfa-4e9e-4a95-93bb-787e8a34fe42",
+      "create_timestamp": 1606836534944,
+      "volumes": [
+        {
+          "volume_number": 0,
+          "storage_pool_name": "DfltDisklessStorPool",
+          "provider_kind": "DISKLESS",
+          "device_path": "/dev/drbd1001",
+          "allocated_size_kib": 0,
+          "state": {
+            "disk_state": "Diskless"
+          },
+          "layer_data_list": [
+            {
+              "type": "DRBD",
+              "data": {
+                "drbd_volume_definition": {
+                  "volume_number": 0,
+                  "minor_number": 1001
+                },
+                "device_path": "/dev/drbd1001",
+                "allocated_size_kib": -1,
+                "usable_size_kib": 102400
+              }
+            },
+            {
+              "type": "STORAGE",
+              "data": {
+                "volume_number": 0,
+                "allocated_size_kib": 0,
+                "usable_size_kib": 102400
+              }
+            }
+          ],
+          "uuid": "eb058821-f1f9-4d4e-8f89-c33839b71a6b"
+        }
+      ]
+    },
+    {
+      "name": "test2",
+      "node_name": "linstor3",
+      "props": {
+        "AutoSelectedStorPoolName": "thinpool",
+        "StorPoolName": "thinpool"
+      },
+      "layer_object": {
+        "children": [
+          {
+            "type": "STORAGE",
+            "storage": {
+              "storage_volumes": [
+                {
+                  "volume_number": 0,
+                  "device_path": "/dev/scratch/test2_00000",
+                  "allocated_size_kib": 106496,
+                  "usable_size_kib": 106496,
+                  "disk_state": "[]"
+                }
+              ]
+            }
+          }
+        ],
+        "type": "DRBD",
+        "drbd": {
+          "drbd_resource_definition": {
+            "peer_slots": 7,
+            "al_stripes": 1,
+            "al_stripe_size_kib": 32,
+            "port": 7001,
+            "transport_type": "IP",
+            "secret": "2vD4CZEbaEAO3XIZ/ICv",
+            "down": false
+          },
+          "node_id": 1,
+          "peer_slots": 7,
+          "al_stripes": 1,
+          "al_size": 32,
+          "drbd_volumes": [
+            {
+              "drbd_volume_definition": {
+                "volume_number": 0,
+                "minor_number": 1001
+              },
+              "device_path": "/dev/drbd1001",
+              "backing_device": "/dev/scratch/test2_00000",
+              "allocated_size_kib": 102460,
+              "usable_size_kib": 102400
+            }
+          ],
+          "connections": {
+            "linstor2": {
+              "connected": true,
+              "message": "Connected"
+            },
+            "linstor1": {
+              "connected": true,
+              "message": "Connected"
+            }
+          },
+          "promotion_score": 10102,
+          "may_promote": true
+        }
+      },
+      "state": {
+        "in_use": false
+      },
+      "uuid": "f2b1885d-c6e9-4878-9e0a-32d9939e7e73",
+      "create_timestamp": 1606836535621,
+      "volumes": [
+        {
+          "volume_number": 0,
+          "storage_pool_name": "thinpool",
+          "provider_kind": "LVM_THIN",
+          "device_path": "/dev/drbd1001",
+          "allocated_size_kib": 63,
+          "state": {
+            "disk_state": "UpToDate"
+          },
+          "layer_data_list": [
+            {
+              "type": "DRBD",
+              "data": {
+                "drbd_volume_definition": {
+                  "volume_number": 0,
+                  "minor_number": 1001
+                },
+                "device_path": "/dev/drbd1001",
+                "backing_device": "/dev/scratch/test2_00000",
+                "allocated_size_kib": 102460,
+                "usable_size_kib": 102400
+              }
+            },
+            {
+              "type": "STORAGE",
+              "data": {
+                "volume_number": 0,
+                "device_path": "/dev/scratch/test2_00000",
+                "allocated_size_kib": 106496,
+                "usable_size_kib": 106496,
+                "disk_state": "[]"
+              }
+            }
+          ],
+          "uuid": "c1911c4e-8650-4743-bbc1-5000b133f7a5"
+        }
+      ]
+    }
+  ]
+]
diff --git a/tests/linstorjsondata/storage-pools-ssdpool.json b/tests/linstorjsondata/storage-pools-ssdpool.json
new file mode 100644
index 0000000000..4f83fcb96f
--- /dev/null
+++ b/tests/linstorjsondata/storage-pools-ssdpool.json
@@ -0,0 +1,72 @@
+[
+  [
+    {
+      "storage_pool_name": "ssdpool",
+      "node_name": "kitfox",
+      "provider_kind": "LVM_THIN",
+      "props": {
+        "StorDriver/StorPoolName": "ssdpool/ssdthin"
+      },
+      "static_traits": {
+        "Provisioning": "Thin",
+        "SupportsSnapshots": "true"
+      },
+      "free_capacity": 2520332505,
+      "total_capacity": 3006480384,
+      "free_space_mgr_name": "kitfox:ssdpool",
+      "uuid": "0ec1c14b-684f-432d-83c4-06c093fd5008",
+      "supports_snapshots": true
+    },
+    {
+      "storage_pool_name": "ssdpool",
+      "node_name": "redfox",
+      "provider_kind": "LVM_THIN",
+      "props": {
+        "StorDriver/StorPoolName": "ssdpool/ssdthin"
+      },
+      "static_traits": {
+        "Provisioning": "Thin",
+        "SupportsSnapshots": "true"
+      },
+      "free_capacity": 2263879729,
+      "total_capacity": 3006480384,
+      "free_space_mgr_name": "redfox:ssdpool",
+      "uuid": "ce5cadae-0138-4ce7-8294-9c2dd648ff2c",
+      "supports_snapshots": true
+    },
+    {
+      "storage_pool_name": "ssdpool",
+      "node_name": "silverfox",
+      "provider_kind": "LVM_THIN",
+      "props": {
+        "StorDriver/StorPoolName": "ssdpool/ssdthin"
+      },
+      "static_traits": {
+        "Provisioning": "Thin",
+        "SupportsSnapshots": "true"
+      },
+      "free_capacity": 2541678516,
+      "total_capacity": 3006480384,
+      "free_space_mgr_name": "silverfox:ssdpool",
+      "uuid": "1042ae20-ec3d-494a-8188-0032df0775a2",
+      "supports_snapshots": true
+    },
+    {
+      "storage_pool_name": "ssdpool",
+      "node_name": "swiftfox",
+      "provider_kind": "LVM_THIN",
+      "props": {
+        "StorDriver/StorPoolName": "ssdpool/ssdthin"
+      },
+      "static_traits": {
+        "Provisioning": "Thin",
+        "SupportsSnapshots": "true"
+      },
+      "free_capacity": 2682983094,
+      "total_capacity": 3006480384,
+      "free_space_mgr_name": "swiftfox:ssdpool",
+      "uuid": "38c8220f-b0c1-4977-8b3f-0376bc5f9ee2",
+      "supports_snapshots": true
+    }
+  ]
+]
diff --git a/tests/linstorjsondata/storage-pools.json b/tests/linstorjsondata/storage-pools.json
new file mode 100644
index 0000000000..446ae05ba9
--- /dev/null
+++ b/tests/linstorjsondata/storage-pools.json
@@ -0,0 +1,192 @@
+[
+  [
+    {
+      "storage_pool_name": "DfltDisklessStorPool",
+      "node_name": "kitfox",
+      "provider_kind": "DISKLESS",
+      "static_traits": {
+        "SupportsSnapshots": "false"
+      },
+      "free_capacity": 9223372036854775807,
+      "total_capacity": 9223372036854775807,
+      "free_space_mgr_name": "kitfox:DfltDisklessStorPool",
+      "uuid": "d43400aa-cec3-4517-9eac-e188821dd537",
+      "supports_snapshots": false
+    },
+    {
+      "storage_pool_name": "DfltDisklessStorPool",
+      "node_name": "redfox",
+      "provider_kind": "DISKLESS",
+      "static_traits": {
+        "SupportsSnapshots": "false"
+      },
+      "free_capacity": 9223372036854775807,
+      "total_capacity": 9223372036854775807,
+      "free_space_mgr_name": "redfox:DfltDisklessStorPool",
+      "uuid": "227873ed-422b-4200-a01b-13050218d67b",
+      "supports_snapshots": false
+    },
+    {
+      "storage_pool_name": "DfltDisklessStorPool",
+      "node_name": "silverfox",
+      "provider_kind": "DISKLESS",
+      "static_traits": {
+        "SupportsSnapshots": "false"
+      },
+      "free_capacity": 9223372036854775807,
+      "total_capacity": 9223372036854775807,
+      "free_space_mgr_name": "silverfox:DfltDisklessStorPool",
+      "uuid": "62540ab6-8eea-4283-8e96-338ece66bf68",
+      "supports_snapshots": false
+    },
+    {
+      "storage_pool_name": "DfltDisklessStorPool",
+      "node_name": "swiftfox",
+      "provider_kind": "DISKLESS",
+      "static_traits": {
+        "SupportsSnapshots": "false"
+      },
+      "free_capacity": 9223372036854775807,
+      "total_capacity": 9223372036854775807,
+      "free_space_mgr_name": "swiftfox:DfltDisklessStorPool",
+      "uuid": "0299ef6d-4a72-49c6-bcb1-681875b9da51",
+      "supports_snapshots": false
+    },
+    {
+      "storage_pool_name": "hddpool",
+      "node_name": "kitfox",
+      "provider_kind": "LVM",
+      "props": {
+        "StorDriver/StorPoolName": "hddpool"
+      },
+      "static_traits": {
+        "Provisioning": "Fat",
+        "SupportsSnapshots": "false"
+      },
+      "free_capacity": 46365757440,
+      "total_capacity": 46884159488,
+      "free_space_mgr_name": "kitfox:hddpool",
+      "uuid": "896402d9-a128-45b2-9a22-73a75ff02cf8",
+      "supports_snapshots": false
+    },
+    {
+      "storage_pool_name": "hddpool",
+      "node_name": "redfox",
+      "provider_kind": "LVM",
+      "props": {
+        "StorDriver/StorPoolName": "hddpool"
+      },
+      "static_traits": {
+        "Provisioning": "Fat",
+        "SupportsSnapshots": "false"
+      },
+      "free_capacity": 44282089472,
+      "total_capacity": 46884159488,
+      "free_space_mgr_name": "redfox:hddpool",
+      "uuid": "8b1ba3b9-a202-4d79-bc1e-bd0c4b44d700",
+      "supports_snapshots": false
+    },
+    {
+      "storage_pool_name": "hddpool",
+      "node_name": "silverfox",
+      "provider_kind": "LVM",
+      "props": {
+        "StorDriver/StorPoolName": "hddpool"
+      },
+      "static_traits": {
+        "Provisioning": "Fat",
+        "SupportsSnapshots": "false"
+      },
+      "free_capacity": 46346166272,
+      "total_capacity": 46884159488,
+      "free_space_mgr_name": "silverfox:hddpool",
+      "uuid": "0425df26-da1f-4980-af55-1117b7671b28",
+      "supports_snapshots": false
+    },
+    {
+      "storage_pool_name": "hddpool",
+      "node_name": "swiftfox",
+      "provider_kind": "LVM",
+      "props": {
+        "StorDriver/StorPoolName": "hddpool"
+      },
+      "static_traits": {
+        "Provisioning": "Fat",
+        "SupportsSnapshots": "false"
+      },
+      "free_capacity": 44498202624,
+      "total_capacity": 46884159488,
+      "free_space_mgr_name": "swiftfox:hddpool",
+      "uuid": "5be30898-c8fa-4bea-a54e-99062d43ab30",
+      "supports_snapshots": false
+    },
+    {
+      "storage_pool_name": "ssdpool",
+      "node_name": "kitfox",
+      "provider_kind": "LVM_THIN",
+      "props": {
+        "StorDriver/StorPoolName": "ssdpool/ssdthin"
+      },
+      "static_traits": {
+        "Provisioning": "Thin",
+        "SupportsSnapshots": "true"
+      },
+      "free_capacity": 2520332505,
+      "total_capacity": 3006480384,
+      "free_space_mgr_name": "kitfox:ssdpool",
+      "uuid": "0ec1c14b-684f-432d-83c4-06c093fd5008",
+      "supports_snapshots": true
+    },
+    {
+      "storage_pool_name": "ssdpool",
+      "node_name": "redfox",
+      "provider_kind": "LVM_THIN",
+      "props": {
+        "StorDriver/StorPoolName": "ssdpool/ssdthin"
+      },
+      "static_traits": {
+        "Provisioning": "Thin",
+        "SupportsSnapshots": "true"
+      },
+      "free_capacity": 2263879729,
+      "total_capacity": 3006480384,
+      "free_space_mgr_name": "redfox:ssdpool",
+      "uuid": "ce5cadae-0138-4ce7-8294-9c2dd648ff2c",
+      "supports_snapshots": true
+    },
+    {
+      "storage_pool_name": "ssdpool",
+      "node_name": "silverfox",
+      "provider_kind": "LVM_THIN",
+      "props": {
+        "StorDriver/StorPoolName": "ssdpool/ssdthin"
+      },
+      "static_traits": {
+        "Provisioning": "Thin",
+        "SupportsSnapshots": "true"
+      },
+      "free_capacity": 2541678516,
+      "total_capacity": 3006480384,
+      "free_space_mgr_name": "silverfox:ssdpool",
+      "uuid": "1042ae20-ec3d-494a-8188-0032df0775a2",
+      "supports_snapshots": true
+    },
+    {
+      "storage_pool_name": "ssdpool",
+      "node_name": "swiftfox",
+      "provider_kind": "LVM_THIN",
+      "props": {
+        "StorDriver/StorPoolName": "ssdpool/ssdthin"
+      },
+      "static_traits": {
+        "Provisioning": "Thin",
+        "SupportsSnapshots": "true"
+      },
+      "free_capacity": 2682983094,
+      "total_capacity": 3006480384,
+      "free_space_mgr_name": "swiftfox:ssdpool",
+      "uuid": "38c8220f-b0c1-4977-8b3f-0376bc5f9ee2",
+      "supports_snapshots": true
+    }
+  ]
+]
diff --git a/tests/linstorjsondata/volume-def-list.json b/tests/linstorjsondata/volume-def-list.json
new file mode 100644
index 0000000000..130d258395
--- /dev/null
+++ b/tests/linstorjsondata/volume-def-list.json
@@ -0,0 +1,158 @@
+[
+  [
+    {
+      "name": "test",
+      "props": {
+        "DrbdPrimarySetOn": "LINSTOR2",
+        "DrbdOptions/Handlers/quorum-lost": "/usr/bin/false",
+        "DrbdOptions/Resource/on-no-quorum": "io-error",
+        "DrbdOptions/Resource/quorum": "majority"
+      },
+      "layer_data": [
+        {
+          "type": "DRBD",
+          "data": {
+            "peer_slots": 7,
+            "al_stripes": 1,
+            "al_stripe_size_kib": 32,
+            "port": 7000,
+            "transport_type": "IP",
+            "secret": "nho9cGTqxHSpsL3PVRlh",
+            "down": false
+          }
+        },
+        {
+          "type": "STORAGE"
+        }
+      ],
+      "uuid": "8a6f32cd-05c7-4ab0-b1e4-28ae7bd9716c",
+      "resource_group_name": "DfltRscGrp",
+      "volume_definitions": [
+        {
+          "volume_number": 0,
+          "size_kib": 102400,
+          "props": {
+            "DrbdCurrentGi": "8D2C5D7B9EFDE716",
+            "DrbdOptions/Disk/discard-zeroes-if-aligned": "yes",
+            "DrbdOptions/Disk/rs-discard-granularity": "65536"
+          },
+          "layer_data": [
+            {
+              "type": "DRBD",
+              "data": {
+                "volume_number": 0,
+                "minor_number": 1000
+              }
+            },
+            {
+              "type": "STORAGE"
+            }
+          ],
+          "uuid": "d5711c63-4aa8-4d01-97a6-982129fb757a"
+        }
+      ]
+    },
+    {
+      "name": "test2",
+      "props": {
+        "DrbdPrimarySetOn": "LINSTOR1",
+        "DrbdOptions/Resource/on-no-quorum": "io-error",
+        "DrbdOptions/Resource/quorum": "majority"
+      },
+      "layer_data": [
+        {
+          "type": "DRBD",
+          "data": {
+            "peer_slots": 7,
+            "al_stripes": 1,
+            "al_stripe_size_kib": 32,
+            "port": 7001,
+            "transport_type": "IP",
+            "secret": "2vD4CZEbaEAO3XIZ/ICv",
+            "down": false
+          }
+        },
+        {
+          "type": "STORAGE"
+        }
+      ],
+      "uuid": "1b0b86a3-eba1-4453-b8ac-b8389f1ef732",
+      "resource_group_name": "libvirtgrp",
+      "volume_definitions": [
+        {
+          "volume_number": 0,
+          "size_kib": 102400,
+          "props": {
+            "DrbdCurrentGi": "65E85E9CE441095A",
+            "DrbdOptions/Disk/discard-zeroes-if-aligned": "yes",
+            "DrbdOptions/Disk/rs-discard-granularity": "65536"
+          },
+          "layer_data": [
+            {
+              "type": "DRBD",
+              "data": {
+                "volume_number": 0,
+                "minor_number": 1001
+              }
+            },
+            {
+              "type": "STORAGE"
+            }
+          ],
+          "uuid": "3d859e23-db34-4b29-a1d9-7237dca34b48"
+        }
+      ]
+    },
+    {
+      "name": "test3",
+      "props": {
+        "DrbdPrimarySetOn": "LINSTOR2",
+        "DrbdOptions/Resource/on-no-quorum": "io-error",
+        "DrbdOptions/Resource/quorum": "majority"
+      },
+      "layer_data": [
+        {
+          "type": "DRBD",
+          "data": {
+            "peer_slots": 7,
+            "al_stripes": 1,
+            "al_stripe_size_kib": 32,
+            "port": 7002,
+            "transport_type": "IP",
+            "secret": "YfrSh5eLhZStJ0JHFaVx",
+            "down": false
+          }
+        },
+        {
+          "type": "STORAGE"
+        }
+      ],
+      "uuid": "1d14069d-2a17-4865-be9f-73be985c029e",
+      "resource_group_name": "libvirtgrp",
+      "volume_definitions": [
+        {
+          "volume_number": 0,
+          "size_kib": 102400,
+          "props": {
+            "DrbdCurrentGi": "57D5597EEFCA7CCE",
+            "DrbdOptions/Disk/discard-zeroes-if-aligned": "yes",
+            "DrbdOptions/Disk/rs-discard-granularity": "65536"
+          },
+          "layer_data": [
+            {
+              "type": "DRBD",
+              "data": {
+                "volume_number": 0,
+                "minor_number": 1002
+              }
+            },
+            {
+              "type": "STORAGE"
+            }
+          ],
+          "uuid": "f57e6b5f-e516-4a7d-ba3a-24af5cad0428"
+        }
+      ]
+    }
+  ]
+]
diff --git a/tests/linstorjsondata/volume-definition-test2.json b/tests/linstorjsondata/volume-definition-test2.json
new file mode 100644
index 0000000000..cf9b8d3655
--- /dev/null
+++ b/tests/linstorjsondata/volume-definition-test2.json
@@ -0,0 +1 @@
+[[{"name":"test2","props":{"DrbdPrimarySetOn":"LINSTOR1","DrbdOptions/Resource/on-no-quorum":"io-error","DrbdOptions/Resource/quorum":"majority"},"layer_data":[{"type":"DRBD","data":{"peer_slots":7,"al_stripes":1,"al_stripe_size_kib":32,"port":7001,"transport_type":"IP","secret":"N5JDi3hRpTqPnIz/uioJ","down":false}},{"type":"STORAGE"}],"uuid":"fe7f23be-7f1f-4d31-b335-bcde071d5b99","resource_group_name":"DfltRscGrp","volume_definitions":[{"volume_number":0,"size_kib":102400,"props":{"DrbdCurrentGi":"7A18B00623CC057A","DrbdOptions/Disk/discard-zeroes-if-aligned":"yes","DrbdOptions/Disk/rs-discard-granularity":"65536"},"layer_data":[{"type":"DRBD","data":{"volume_number":0,"minor_number":1001}},{"type":"STORAGE"}],"uuid":"984e57bd-adec-464f-b9a3-ce0a10ae2711"}]}]]
diff --git a/tests/meson.build b/tests/meson.build
index 0de0783839..64c889aee5 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -519,6 +519,12 @@ if conf.has('WITH_STORAGE_SHEEPDOG')
   ]
 endif
 
+if conf.has('WITH_STORAGE_LINSTOR')
+  tests += [
+    { 'name': 'storagebackendlinstortest', 'link_with': [ storage_driver_impl_lib, storage_backend_linstor_priv_lib ] },
+  ]
+endif
+
 if conf.has('WITH_VBOX')
   tests += [
     { 'name': 'vboxsnapshotxmltest', 'link_with': [ vbox_driver_impl ] },
diff --git a/tests/storagebackendlinstortest.c b/tests/storagebackendlinstortest.c
new file mode 100644
index 0000000000..4cd7664304
--- /dev/null
+++ b/tests/storagebackendlinstortest.c
@@ -0,0 +1,372 @@
+/*
+ * storagebackendlinstortest.c: test for linstor storage backend
+ *
+ * Copyright (C) 2020-2021 LINBIT HA-Solutions GmbH
+ * implemented by Rene Peinthor
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <config.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+#include "internal.h"
+#include "testutils.h"
+#define LIBVIRT_STORAGE_BACKEND_LINSTOR_PRIV_H_ALLOW
+#include "storage/storage_backend_linstor_priv.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+struct testStoragePoolListParserData {
+    const char *input_json;
+    const char *poolxml;
+    const char *node_name;
+    int expected_return;
+    uint64_t expected_capacity;
+    uint64_t expected_allocation;
+};
+
+struct testVolumeDefinitionListParserData {
+    const char *input_json;
+    const char *poolxml;
+    const char *volxml;
+    int expected_return;
+    uint64_t expected_capacity;
+};
+
+struct testResourceListParserData {
+    const char *rsclist_json;
+    const char *voldeflist_json;
+    const char *poolxml;
+    const char *noden_name;
+    const char *rsc_filter_json;
+    int expected_return;
+    size_t expected_volume_count;
+};
+
+struct testResourceGroupListParserData {
+    const char *input_json;
+    const char *poolxml;
+    const char *rsc_grp;
+    int expected_return;
+    const char *expected_storpools;
+};
+
+struct testResourceDeployedData {
+    const char *input_json;
+    const char *rscname;
+    const char *nodename;
+    int expected_return;
+};
+
+
+static int
+test_resourcegroup_list_parser(const void *opaque)
+{
+    const struct testResourceGroupListParserData *data = opaque;
+    g_autofree char *poolxml = NULL;
+    g_autoptr(virStoragePoolDef) pool = NULL;
+    g_autofree char *inputJson = NULL;
+    g_autofree char *indata = NULL;
+    virJSONValuePtr storagePoolList = NULL;
+
+    inputJson = g_strdup_printf("%s/linstorjsondata/%s",
+                              abs_srcdir, data->input_json);
+
+    poolxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s",
+                              abs_srcdir, data->poolxml);
+
+    if (!(pool = virStoragePoolDefParseFile(poolxml))) {
+        return -1;
+    }
+
+    if (virTestLoadFile(inputJson, &indata) < 0)
+        return -1;
+
+    if (virStorageBackendLinstorParseResourceGroupList(data->rsc_grp,
+                                                       indata,
+                                                       &storagePoolList) != 0) {
+        virJSONValueFree(storagePoolList);
+        return -1;
+    }
+
+    if (storagePoolList == NULL) {
+        return -1;
+    }
+
+    if (g_strcmp0(virJSONValueToString(storagePoolList, false),
+                  data->expected_storpools) != 0) {
+            virJSONValueFree(storagePoolList);
+            return -1;
+    }
+
+    virJSONValueFree(storagePoolList);
+    return 0;
+}
+
+
+static int
+run_test_resourcegroup_list_parser(void)
+{
+    int ret = 0;
+
+    struct testResourceGroupListParserData rscGrpTest[] = {
+        { "resource-group.json", "pool-linstor.xml", "libvirtgrp", 0, "[\"thinpool\"]" },
+        { NULL, NULL, NULL, 0, NULL }
+    };
+
+    /* volumedefinition list parse */
+    struct testResourceGroupListParserData *test = rscGrpTest;
+    {
+        while (test->input_json != NULL) {
+            if (virTestRun(
+                        "resourcegroup_list_parser",
+                        test_resourcegroup_list_parser, test) < 0)
+                ret = -1;
+            ++test;
+        }
+    }
+    return ret;
+}
+
+
+static int
+test_storagepool_list_parser(const void *opaque)
+{
+    const struct testStoragePoolListParserData *data = opaque;
+    g_autofree char *poolxml = NULL;
+    g_autoptr(virStoragePoolDef) pool = NULL;
+    g_autofree char *inputJson = NULL;
+    g_autofree char *indata = NULL;
+
+    inputJson = g_strdup_printf("%s/linstorjsondata/%s",
+                              abs_srcdir, data->input_json);
+
+    poolxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s",
+                              abs_srcdir, data->poolxml);
+
+    if (!(pool = virStoragePoolDefParseFile(poolxml)))
+        return -1;
+
+    if (virTestLoadFile(inputJson, &indata) < 0)
+        return -1;
+
+    if (virStorageBackendLinstorParseStoragePoolList(pool, data->node_name, indata) !=
+        data->expected_return)
+        return -1;
+
+    if (data->expected_return)
+        return 0;
+
+    if (pool->capacity == data->expected_capacity &&
+        pool->allocation == data->expected_allocation)
+        return 0;
+
+    return -1;
+}
+
+
+static int
+run_test_storagepool_list_parser(void)
+{
+    int ret = 0;
+
+    struct testStoragePoolListParserData storPoolTest[] = {
+        { "storage-pools-ssdpool.json", "pool-linstor.xml", "redfox", 0, 3078635913216, 760423070720 },
+        { "storage-pools.json", "pool-linstor.xml", "silverfox", 0, 51088015228928, 1026862166016 },
+        { NULL, NULL, NULL, 0, 0, 0 }
+    };
+    /* volumedefinition list parse */
+    struct testStoragePoolListParserData *test = storPoolTest;
+    {
+        while (test->input_json != NULL) {
+            if (virTestRun(
+                        "test_storagepool_list_parser",
+                        test_storagepool_list_parser, test) < 0)
+                ret = -1;
+            ++test;
+        }
+    }
+    return ret;
+}
+
+
+static int
+test_volumedefinition_list_parser(const void *opaque)
+{
+    const struct testVolumeDefinitionListParserData *data = opaque;
+    g_autoptr(virStoragePoolDef) pool = NULL;
+    g_autoptr(virStorageVolDef) vol = NULL;
+    g_autofree char *poolxml = NULL;
+    g_autofree char *volxml = NULL;
+    g_autofree char *inputJson = NULL;
+    g_autofree char *indata = NULL;
+
+    inputJson = g_strdup_printf("%s/linstorjsondata/%s",
+                              abs_srcdir, data->input_json);
+
+    poolxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s",
+                              abs_srcdir, data->poolxml);
+
+    volxml = g_strdup_printf("%s/storagevolxml2xmlin/%s",
+                             abs_srcdir, data->volxml);
+
+    if (!(pool = virStoragePoolDefParseFile(poolxml)))
+        return -1;
+
+    if (!(vol = virStorageVolDefParseFile(pool, volxml, 0)))
+        return -1;
+
+    if (virTestLoadFile(inputJson, &indata) < 0)
+        return -1;
+
+    if (virStorageBackendLinstorParseVolumeDefinition(vol, indata) !=
+        data->expected_return)
+        return -1;
+
+    if (data->expected_return)
+        return 0;
+
+    if (vol->target.capacity == data->expected_capacity)
+        return 0;
+
+    return -1;
+}
+
+
+static int
+run_test_volumedefinition_list_parser(void)
+{
+    int ret = 0;
+
+    struct testVolumeDefinitionListParserData volumeDefTest[] = {
+        { "volume-definition-test2.json", "pool-linstor.xml", "vol-linstor.xml", 0, 104857600 },
+        { NULL, NULL, NULL, 0, 0 }
+    };
+    /* volumedefinition list parse */
+    struct testVolumeDefinitionListParserData *test = volumeDefTest;
+    {
+        while (test->input_json != NULL) {
+            if (virTestRun(
+                        "volumedefinition_list_parser",
+                        test_volumedefinition_list_parser, test) < 0)
+                ret = -1;
+            ++test;
+        }
+    }
+    return ret;
+}
+
+
+static int
+testResourceListParser(const void *opaque)
+{
+    int ret = -1;
+    const struct testResourceListParserData *data = opaque;
+    virStoragePoolObjPtr pool = NULL;
+    virStoragePoolDefPtr poolDef = NULL;
+    g_autofree char *poolxml = NULL;
+    g_autofree char *rscListJsonFile = NULL;
+    g_autofree char *volDefListJsonFile = NULL;
+    g_autofree char *rscListData = NULL;
+    g_autofree char *volDefListData = NULL;
+    virJSONValuePtr rscFilterArr = NULL;
+
+    rscListJsonFile = g_strdup_printf("%s/linstorjsondata/%s",
+                              abs_srcdir, data->rsclist_json);
+
+    volDefListJsonFile = g_strdup_printf("%s/linstorjsondata/%s",
+                              abs_srcdir, data->voldeflist_json);
+
+    poolxml = g_strdup_printf("%s/storagepoolxml2xmlin/%s",
+                              abs_srcdir, data->poolxml);
+
+    rscFilterArr = virJSONValueFromString(data->rsc_filter_json);
+
+    if (!(poolDef = virStoragePoolDefParseFile(poolxml)))
+        goto cleanup;
+
+    if (!(pool = virStoragePoolObjNew()))
+        goto cleanup;
+
+    virStoragePoolObjSetDef(pool, poolDef);
+
+    if (virTestLoadFile(rscListJsonFile, &rscListData) < 0)
+        goto cleanup;
+
+    if (virTestLoadFile(volDefListJsonFile, &volDefListData) < 0)
+        goto cleanup;
+
+    if (virStorageBackendLinstorParseResourceList(pool,
+                                                  data->noden_name,
+                                                  rscFilterArr,
+                                                  rscListData,
+                                                  volDefListData) != data->expected_return)
+        goto cleanup;
+
+    if (data->expected_return) {
+        ret = 0;
+        goto cleanup;
+    }
+
+    if (data->expected_volume_count == virStoragePoolObjGetVolumesCount(pool))
+        ret = 0;
+
+ cleanup:
+    virStoragePoolObjEndAPI(&pool);
+    return ret;
+}
+
+static int
+runTestResourceListParser(void)
+{
+    int ret = 0;
+    struct testResourceListParserData rscListParseData[] = {
+        { "resource-list-test2.json", "volume-def-list.json", "pool-linstor.xml", "linstor1", "[\"test2\"]", 0, 1 },
+        { NULL, NULL, NULL, NULL, NULL, 0, 0}
+    };
+
+    struct testResourceListParserData *test = rscListParseData;
+    {
+        while (test->rsclist_json != NULL) {
+            if (virTestRun(
+                        "virStorageBackendLinstorParseResourceList",
+                        testResourceListParser, test) < 0)
+                ret = -1;
+            ++test;
+        }
+    }
+
+    return ret;
+}
+
+
+static int
+mymain(void)
+{
+    int ret = 0;
+
+    ret = run_test_resourcegroup_list_parser() ? -1 : ret;
+    ret = run_test_storagepool_list_parser() ? -1 : ret;
+    ret = run_test_volumedefinition_list_parser() ? -1 : ret;
+    ret = runTestResourceListParser() ? -1 : ret;
+
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIR_TEST_MAIN(mymain)
diff --git a/tests/storagepoolxml2xmlin/pool-linstor.xml b/tests/storagepoolxml2xmlin/pool-linstor.xml
new file mode 100644
index 0000000000..36f2781e21
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-linstor.xml
@@ -0,0 +1,8 @@
+<pool type="linstor">
+  <source>
+    <name>DfltRscGrp</name>
+    <host name="linstor1"/>
+  </source>
+  <uuid>65fcba04-5b13-bd93-cff3-52ce48e11ad7</uuid>
+  <name>linstor</name>
+</pool>
diff --git a/tests/storagevolxml2xmlin/vol-linstor.xml b/tests/storagevolxml2xmlin/vol-linstor.xml
new file mode 100644
index 0000000000..7369f4f673
--- /dev/null
+++ b/tests/storagevolxml2xmlin/vol-linstor.xml
@@ -0,0 +1,10 @@
+<volume type='network'>
+  <name>test2</name>
+  <source>
+  </source>
+  <capacity unit='bytes'>1024</capacity>
+  <allocation unit='bytes'>0</allocation>
+  <target>
+	  <path>/dev/drbd1000</path>
+  </target>
+</volume>
-- 
2.30.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux