[sheepdog] [PATCH v2 2/2] tests/func: add 081 to test http service

Liu Yuan namei.unix at gmail.com
Wed Dec 18 13:46:55 CET 2013


Current master can pass it, wow!

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/cluster/local.c          |   11 +++--
 tests/functional/081           |   96 ++++++++++++++++++++++++++++++++++++++++
 tests/functional/081.out       |   69 +++++++++++++++++++++++++++++
 tests/functional/common.config |    1 +
 tests/functional/group         |    1 +
 5 files changed, 175 insertions(+), 3 deletions(-)
 create mode 100755 tests/functional/081
 create mode 100644 tests/functional/081.out

diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index c9c0ede..5c27908 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -582,9 +582,14 @@ static void local_lock(uint64_t lock_id)
 
 	sd_write_lock(&lock);
 	snprintf(path, sizeof(path), "%s%016"PRIx64, lockdir, lock_id);
-	fd = open(path, O_RDONLY | O_CREAT, sd_def_fmode);
-	if (fd < 0)
-		panic("failed to open %s, %m", path);
+	fd = open(path, O_RDONLY | O_CREAT | O_EXCL, sd_def_fmode);
+	if (fd < 0) {
+		if (unlikely(errno != EEXIST))
+			panic("failed to open %s, %m", path);
+		fd = open(path, O_RDONLY, sd_def_fmode);
+		if (fd < 0)
+			panic("failed to open %s, %m", path);
+	}
 
 	if (xflock(fd, LOCK_EX) < 0)
 		panic("lock file failed %s, %m", path);
diff --git a/tests/functional/081 b/tests/functional/081
new file mode 100755
index 0000000..307fb8e
--- /dev/null
+++ b/tests/functional/081
@@ -0,0 +1,96 @@
+#!/bin/bash
+
+# Test http service with a single server
+
+. ./common
+
+pgrep 'nginx' > /dev/null || _notrun "Require nginx but it's not running"
+
+_start_sheep 0 "-r swift"
+for i in `seq 1 5`; do
+	_start_sheep $i
+done
+
+_wait_for_sheep 6
+
+_cluster_format -c 4:2
+
+curl -s -X POST http://localhost/v1/sd
+curl -s -X PUT http://localhost/v1/sd/sheep
+curl -s -X PUT http://localhost/v1/sd/dog
+
+for i in 4 19 97 137; do
+    _random | dd iflag=fullblock of=$STORE/data$i bs=1M count=$i &> /dev/null
+    dd if=$STORE/data$i 2> /dev/null | md5sum > $STORE/data$i.1
+done
+sheep_files=`find $SOURCE/sheep -name '*.c'`
+dog_files=`find $SOURCE/dog -name '*.c'`
+
+# upload the objects
+for file in $sheep_files; do
+	f=`basename $file`
+	cat $file | md5sum > $STORE/$f.1
+	cat $file | curl -s -T "-" -X PUT http://localhost/v1/sd/sheep/$f &
+done
+
+for file in $dog_files; do
+	f=`basename $file`
+	cat $file | md5sum > $STORE/$f.1
+	cat $file | curl -s -T "-" -X PUT http://localhost/v1/sd/dog/$f &
+done
+
+for i in 4 19 97 137; do
+	curl -s -T $STORE/data$i -X PUT http://localhost/v1/sd/sheep/data$i &
+done
+wait
+
+# list the container and objects
+curl -s -X GET http://localhost/v1/sd
+curl -s -X GET http://localhost/v1/sd/sheep | sort
+curl -s -X GET http://localhost/v1/sd/dog | sort
+
+# download the objects
+for file in $sheep_files; do
+	f=`basename $file`
+	curl -s -X GET http://localhost/v1/sd/sheep/$f | md5sum > $STORE/$f.2 &
+done
+for file in $dog_files; do
+	f=`basename $file`
+	curl -s -X GET http://localhost/v1/sd/dog/$f | md5sum > $STORE/$f.2 &
+done
+for i in 4 19 97 137; do
+	curl -s -X GET http://localhost/v1/sd/sheep/data$i | md5sum > $STORE/data$i.2 &
+done
+wait
+
+# check the objects
+for file in $sheep_files $dog_files; do
+	f=`basename $file`
+	diff -u $STORE/$f.1 $STORE/$f.2
+done
+for i in 4 19 97 137; do
+	diff -u $STORE/data$i.1 $STORE/data$i.2
+done
+
+_vdi_list
+
+#delete the objects
+for file in $sheep_files; do
+	f=`basename $file`
+	curl -s -X DELETE http://localhost/v1/sd/sheep/$f &
+done
+wait
+curl -s -X GET http://localhost/v1/sd/sheep
+
+_vdi_list
+
+for i in 4 19 97 137; do
+	curl -s -X DELETE http://localhost/v1/sd/sheep/data$i &
+done
+
+curl -s -X DELETE http://localhost/v1/sd/dog
+
+curl -s -X GET http://localhost/v1/sd
+curl -s -X GET http://localhost/v1/sd/sheep
+
+_vdi_list
diff --git a/tests/functional/081.out b/tests/functional/081.out
new file mode 100644
index 0000000..919bc26
--- /dev/null
+++ b/tests/functional/081.out
@@ -0,0 +1,69 @@
+QA output created by 081
+using backend plain store
+sheep
+dog
+checker.c
+config.c
+corosync.c
+data137
+data19
+data4
+data97
+gateway.c
+graph.c
+group.c
+http.c
+journal.c
+kv.c
+local.c
+md.c
+migrate.c
+oalloc.c
+object_cache.c
+object_list_cache.c
+ops.c
+plain_store.c
+recovery.c
+request.c
+s3.c
+sheep.c
+shepherd.c
+store.c
+swift.c
+trace.c
+vdi.c
+zookeeper.c
+cluster.c
+common.c
+dog.c
+farm.c
+node.c
+object_tree.c
+sha1_file.c
+slice.c
+snap.c
+trace.c
+treeview.c
+trunk.c
+vdi.c
+  Name        Id    Size    Used  Shared    Creation time   VDI id  Copies  Tag
+  sd/dog       0   16 PB   52 MB  0.0 MB DATE   5a5cbf     6              
+  sd           0   16 PB  8.0 MB  0.0 MB DATE   7927f2     6              
+  sd/sheep     0   16 PB  124 MB  0.0 MB DATE   8ad11e     6              
+  sd/dog/allocator     0   16 PB  4.0 MB  0.0 MB DATE   936d95     6              
+  sd/sheep/allocator     0   16 PB  268 MB  0.0 MB DATE   fd57fc     6              
+data4
+data19
+data97
+data137
+  Name        Id    Size    Used  Shared    Creation time   VDI id  Copies  Tag
+  sd/dog       0   16 PB   52 MB  0.0 MB DATE   5a5cbf     6              
+  sd           0   16 PB  8.0 MB  0.0 MB DATE   7927f2     6              
+  sd/sheep     0   16 PB   16 MB  0.0 MB DATE   8ad11e     6              
+  sd/dog/allocator     0   16 PB  4.0 MB  0.0 MB DATE   936d95     6              
+  sd/sheep/allocator     0   16 PB  268 MB  0.0 MB DATE   fd57fc     6              
+sheep
+  Name        Id    Size    Used  Shared    Creation time   VDI id  Copies  Tag
+  sd           0   16 PB  4.0 MB  0.0 MB DATE   7927f2     6              
+  sd/sheep     0   16 PB  0.0 MB  0.0 MB DATE   8ad11e     6              
+  sd/sheep/allocator     0   16 PB  4.0 MB  0.0 MB DATE   fd57fc     6              
diff --git a/tests/functional/common.config b/tests/functional/common.config
index 482bdd9..dc07748 100644
--- a/tests/functional/common.config
+++ b/tests/functional/common.config
@@ -86,6 +86,7 @@ export EC=${EC:-false}
 export QEMU_IO=${QEMU_IO_PROG:-qemu-io}
 export QEMU_IMG=${QEMU_IMG_PROG:-qemu-img}
 export SHEEPFS=${SHEEPFS:-../../sheepfs/sheepfs}
+export SOURCE=${SOURCE:-../..}
 
 # make sure this script returns success
 /bin/true
diff --git a/tests/functional/group b/tests/functional/group
index e999b6f..1a3ce8c 100644
--- a/tests/functional/group
+++ b/tests/functional/group
@@ -95,3 +95,4 @@
 078 auto quick vdi md
 079 auto quick vdi md
 080 auto quick vdi md
+081 auto quick vdi md
-- 
1.7.9.5




More information about the sheepdog mailing list