From e0d15aae41cdec0ee67115f792eb94c9a5c8ccab Mon Sep 17 00:00:00 2001
From: Klaus Aehlig <aehlig@google.com>
Date: Tue, 9 Apr 2013 11:24:09 +0200
Subject: [PATCH] Add shelltests verifying hail applies disk ipolicy per disk

We test on two minimal examples, a positive and a negative one, where
the possibility to allocate a node depends on whether the disk policy
is checked on a per-disk level or on the total amount of disk space
requested.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 Makefile.am                                   |  2 +
 .../htools/hail-alloc-invalid-twodisks.json   | 86 +++++++++++++++++++
 test/data/htools/hail-alloc-twodisks.json     | 86 +++++++++++++++++++
 test/hs/shelltests/htools-hail.test           |  9 ++
 4 files changed, 183 insertions(+)
 create mode 100644 test/data/htools/hail-alloc-invalid-twodisks.json
 create mode 100644 test/data/htools/hail-alloc-twodisks.json

diff --git a/Makefile.am b/Makefile.am
index 0059a7b2b..868d73768 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -959,6 +959,8 @@ TEST_FILES = \
 	test/data/htools/common-suffix.data \
 	test/data/htools/empty-cluster.data \
 	test/data/htools/hail-alloc-drbd.json \
+	test/data/htools/hail-alloc-invalid-twodisks.json \
+	test/data/htools/hail-alloc-twodisks.json \
 	test/data/htools/hail-change-group.json \
 	test/data/htools/hail-invalid-reloc.json \
 	test/data/htools/hail-node-evac.json \
diff --git a/test/data/htools/hail-alloc-invalid-twodisks.json b/test/data/htools/hail-alloc-invalid-twodisks.json
new file mode 100644
index 000000000..355825666
--- /dev/null
+++ b/test/data/htools/hail-alloc-invalid-twodisks.json
@@ -0,0 +1,86 @@
+{
+  "cluster_tags": [],
+  "instances": {},
+  "ipolicy": {
+    "max": {
+      "disk-size": 2048
+    },
+    "min": {
+      "disk-size": 1024
+    }
+  },
+  "nodegroups": {
+    "uuid-group-1": {
+      "alloc_policy": "preferred",
+      "ipolicy": {
+        "disk-templates": [
+          "file"
+        ],
+        "max": {
+          "cpu-count": 2,
+          "disk-count": 8,
+          "disk-size": 2048,
+          "memory-size": 12800,
+          "nic-count": 8,
+          "spindle-use": 8
+        },
+        "min": {
+          "cpu-count": 1,
+          "disk-count": 1,
+          "disk-size": 1024,
+          "memory-size": 128,
+          "nic-count": 1,
+          "spindle-use": 1
+        },
+        "spindle-ratio": 32.0,
+        "std": {
+          "cpu-count": 1,
+          "disk-count": 1,
+          "disk-size": 1024,
+          "memory-size": 128,
+          "nic-count": 1,
+          "spindle-use": 1
+        },
+        "vcpu-ratio": 4.0
+      },
+      "name": "default",
+      "tags": []
+    }
+  },
+  "nodes": {
+    "node1": {
+      "drained": false,
+      "free_disk": 1377280,
+      "free_memory": 31389,
+      "group": "uuid-group-1",
+      "ndparams": {
+        "spindle_count": 1
+      },
+      "offline": false,
+      "reserved_memory": 1017,
+      "total_cpus": 4,
+      "total_disk": 1377280,
+      "total_memory": 32763
+    }
+  },
+  "request": {
+    "disk_space_total": 1536,
+    "disk_template": "file",
+    "disks": [
+      {
+        "size": 768
+      },
+      {
+        "size": 768
+      }
+    ],
+    "memory": 1024,
+    "name": "instance1",
+    "required_nodes": 1,
+    "spindle_use": 2,
+    "tags": [],
+    "type": "allocate",
+    "vcpus": 1
+  },
+  "version": 2
+}
diff --git a/test/data/htools/hail-alloc-twodisks.json b/test/data/htools/hail-alloc-twodisks.json
new file mode 100644
index 000000000..abf722141
--- /dev/null
+++ b/test/data/htools/hail-alloc-twodisks.json
@@ -0,0 +1,86 @@
+{
+  "cluster_tags": [],
+  "instances": {},
+  "ipolicy": {
+    "max": {
+      "disk-size": 2048
+    },
+    "min": {
+      "disk-size": 1024
+    }
+  },
+  "nodegroups": {
+    "uuid-group-1": {
+      "alloc_policy": "preferred",
+      "ipolicy": {
+        "disk-templates": [
+          "file"
+        ],
+        "max": {
+          "cpu-count": 2,
+          "disk-count": 8,
+          "disk-size": 2048,
+          "memory-size": 12800,
+          "nic-count": 8,
+          "spindle-use": 8
+        },
+        "min": {
+          "cpu-count": 1,
+          "disk-count": 1,
+          "disk-size": 1024,
+          "memory-size": 128,
+          "nic-count": 1,
+          "spindle-use": 1
+        },
+        "spindle-ratio": 32.0,
+        "std": {
+          "cpu-count": 1,
+          "disk-count": 1,
+          "disk-size": 1024,
+          "memory-size": 128,
+          "nic-count": 1,
+          "spindle-use": 1
+        },
+        "vcpu-ratio": 4.0
+      },
+      "name": "default",
+      "tags": []
+    }
+  },
+  "nodes": {
+    "node1": {
+      "drained": false,
+      "free_disk": 1377280,
+      "free_memory": 31389,
+      "group": "uuid-group-1",
+      "ndparams": {
+        "spindle_count": 1
+      },
+      "offline": false,
+      "reserved_memory": 1017,
+      "total_cpus": 4,
+      "total_disk": 1377280,
+      "total_memory": 32763
+    }
+  },
+  "request": {
+    "disk_space_total": 3072,
+    "disk_template": "file",
+    "disks": [
+      {
+        "size": 1536
+      },
+      {
+        "size": 1536
+      }
+    ],
+    "memory": 1024,
+    "name": "instance1",
+    "required_nodes": 1,
+    "spindle_use": 2,
+    "tags": [],
+    "type": "allocate",
+    "vcpus": 1
+  },
+  "version": 2
+}
diff --git a/test/hs/shelltests/htools-hail.test b/test/hs/shelltests/htools-hail.test
index 55dd3ca20..4da03d89a 100644
--- a/test/hs/shelltests/htools-hail.test
+++ b/test/hs/shelltests/htools-hail.test
@@ -38,6 +38,15 @@ echo '{"request": 0}' | ./test/hs/hail -
 >>> /"success":true,"info":"Request successful: 0 instances failed to move and 1 were moved successfully"/
 >>>= 0
 
+# check that hail correctly applies the disk policy on a per-disk basis
+./test/hs/hail $TESTDATA_DIR/hail-alloc-twodisks.json
+>>> /"success":true,.*,"result":\["node1"\]/
+>>>= 0
+
+./test/hs/hail $TESTDATA_DIR/hail-alloc-invalid-twodisks.json
+>>> /"success":false,.*FailDisk: 1/
+>>>= 0
+
 # check that hail can use the simu backend
 ./test/hs/hail --simu p,8,8T,16g,16 $TESTDATA_DIR/hail-alloc-drbd.json
 >>> /"success":true,/
-- 
GitLab