This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project iwhd.git.
The branch, dyn-providers-gc has been updated
via 9a01fd31a76f228cafdbf3b119b959751cb39801 (commit)
via 8fb2017e8a820be824f4486cd04e915bee19ce62 (commit)
via 4212f02a207caf13ac3c2903a67a449ac314bcf2 (commit)
via 06254fb7e9346b5bd47eaa3e8b6cab003a264d95 (commit)
from 5bd9b0f67ffbd4af4ef7681db8948de7c1ae97c5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/iwhd.git/commit/9a01fd31a76f228cafdbf3b119b959751cb39801
commit 9a01fd31a76f228cafdbf3b119b959751cb39801
Author: Jim Meyering <meyering(a)redhat.com>
Date: Tue Jan 18 15:13:29 2011 +0100
tests: also check JSON provider lists
* t/init.cfg (emit_provider): Add parameter, is-last, so that
we know whether to print the final comma for JSON output.
* t/basic: Update emit_trivial_provider_list use.
* t/provider: Check both XML and JSON formats.
diff --git a/t/basic b/t/basic
index 7180bbd..6a650c1 100644
--- a/t/basic
+++ b/t/basic
@@ -122,7 +122,7 @@ p_name=primary
# Verify that default provider's information is as expected.
curl
http://localhost:$port/_providers > p || fail=1
-emit_trivial_provider_list xml "$p_name" fs '' 0 '' ''
> p.exp || fail=1
+emit_trivial_provider_list xml "$p_name" fs '' 0 '' ''
is-last > p.exp || fail=1
compare p.exp p || fail=1
for i in xml json; do
diff --git a/t/init.cfg b/t/init.cfg
index 4777954..af9356e 100644
--- a/t/init.cfg
+++ b/t/init.cfg
@@ -65,7 +65,7 @@ emit_provider()
shift 1
case $xml_or_json in xml|json);;
*) echo "invalid xml_or_json $xml_or_json" 1>&2; exit 1;; esac
- case $# in 6);; *) echo "emit_provider: wrong # args" 1>&2; exit 1;;
esac
+ case $# in 7);; *) echo "emit_provider: wrong # args" 1>&2; exit 1;;
esac
if test $xml_or_json = xml; then
printf @@ -76,8 +76,10 @@ emit_provider()
tt<username>%s</username>
tt<password>%s</password>
t</provider>
-' "$@"
+' "$1" "$2" "$3" "$4" "$5"
"$6"
else
+ comma=,
+ test "$7" = is-last && comma=
printf 't{
tt"name": "%s",
@@ -86,8 +88,8 @@ emit_provider()
tt"port": %s,
tt"username": "%s",
tt"password": "%s"
-t}
-' "$@"
+t}%s
+' "$1" "$2" "$3" "$4" "$5"
"$6" $comma
fi
}
diff --git a/t/provider b/t/provider
index 4f7ce25..82b8e5f 100644
--- a/t/provider
+++ b/t/provider
@@ -47,20 +47,25 @@ for i in $(seq $n); do
sleep 99d; }
done
-# List providers.
-curl
http://localhost:$port/_providers > p-list || fail=1
+for z in xml json; do
+ curl_H() { curl -H "Accept: */$z" "$@"; }
+
+ # List providers.
+ curl_H
http://localhost:$port/_providers > p-list-$z || fail=1
+
+ # Ensure that each was added:
+ {
+ emit_provider_list_prefix $z
+ for i in $(seq $n); do
+ i=$(expr 1000 + $i)
+ emit_provider $z p-$i s3 localhost 80 u p not-last || fail=1
+ done
+ emit_provider $z primary fs '' 0 '' '' is-last || fail=1
+ emit_provider_list_suffix $z
+ } > p-exp-$z
+ compare p-list-$z p-exp-$z || fail=1
-# Ensure that each was added:
-{
- emit_provider_list_prefix xml
- for i in $(seq $n); do
- i=$(expr 1000 + $i)
- emit_provider xml p-$i s3 localhost 80 u p || fail=1
- done
- emit_provider xml primary fs '' 0 '' '' || fail=1
- emit_provider_list_suffix xml
-} > p-exp
-compare p-list p-exp || fail=1
+done
# ===================================
for i in $(seq $n); do
http://repo.or.cz/w/iwhd.git/commit/8fb2017e8a820be824f4486cd04e915bee19ce62
commit 8fb2017e8a820be824f4486cd04e915bee19ce62
Author: Jim Meyering <meyering(a)redhat.com>
Date: Tue Jan 18 19:16:16 2011 +0100
list providers: avoid syntax error in JSON output
Without this change, we would print "[,n" at the beginning
of the list of JSON-formatted providers.
* template.c (tmpl_prov_entry): Don't emit the leading ","
on the first entry.
* template.h: Adjust prototype.
* rest.c: Update sole caller.
Spotted by Jeff Darcy.
diff --git a/rest.c b/rest.c
index 486547a..3f9daa0 100644
--- a/rest.c
+++ b/rest.c
@@ -1535,7 +1535,7 @@ prov_fmt (provider_t *prov, void *ms_v)
size_t n_remaining = ms->buf_n_alloc - ms->buf_n_used;
int len = tmpl_prov_entry (ms->buf + ms->buf_n_used,
n_remaining,
- ms->gen_ctx->format->prov_entry,
+ ms->gen_ctx,
prov->name, prov->type,
prov->host, prov->port,
prov->username, prov->password);
diff --git a/template.c b/template.c
index 593bd45..bb0a42a 100644
--- a/template.c
+++ b/template.c
@@ -267,7 +267,7 @@ tmpl_prov_header (tmpl_ctx_t *ctx)
int
tmpl_prov_entry (char *buf, size_t buf_len,
- const char *fmt,
+ tmpl_ctx_t *ctx,
const char *name, const char *type,
const char *host, int port,
const char *user, const char *pass)
@@ -278,8 +278,13 @@ tmpl_prov_entry (char *buf, size_t buf_len,
if (!user) user = "";
if (!pass) pass = "";
+ const char *fmt = ctx->format->prov_entry;
+ if (ctx->index == 0)
+ fmt += ctx->format->z_offset;
int size = snprintf(buf, buf_len, fmt,
name, type, host, port, user, pass);
+ if (0 < size && size < buf_len)
+ ctx->index++;
return size;
}
diff --git a/template.h b/template.h
index e2bb300..b45eb95 100644
--- a/template.h
+++ b/template.h
@@ -53,7 +53,7 @@ size_t tmpl_root_footer (tmpl_ctx_t *ctx);
size_t tmpl_prov_header (tmpl_ctx_t *ctx);
int tmpl_prov_entry (char *buf, size_t buf_len,
- const char *fmt,
+ tmpl_ctx_t *ctx,
const char *name, const char *type,
const char *host, int port,
const char *user, const char *pass);
http://repo.or.cz/w/iwhd.git/commit/4212f02a207caf13ac3c2903a67a449ac314bcf2
commit 4212f02a207caf13ac3c2903a67a449ac314bcf2
Author: Jim Meyering <meyering(a)redhat.com>
Date: Tue Jan 18 13:05:20 2011 +0100
sort provider list on "name"
* rest.c: Sort provider list output on name:
(struct plist): Define.
(prov_get, prov_name_compare): New functions.
(prov_list_generator): Rather than emitting provider XML/JSON
in arbitrary (hash-traversal) order, first gather an array of
provider_t* pointers, sort them, and *then* emit listing.
* t/init.cfg (emit_provider_list_prefix): New helper.
(emit_provider_list_suffix): Likewise.
(emit_trivial_provider_list): Renamed from emit_provider.
(emit_provider): Emit output for a single provider.
I.e., do not emit prefix and suffix.
* t/basic: s/emit_provider/emit_trivial_provider_list/
* t/provider: Compare full output with expected output,
rather than just grepping for a summary.
This is feasible, now that the provider list is sorted.
diff --git a/rest.c b/rest.c
index 290dfd1..486547a 100644
--- a/rest.c
+++ b/rest.c
@@ -1553,6 +1553,38 @@ prov_fmt (provider_t *prov, void *ms_v)
}
}
+// Aux structure solely to accumulate and sort providers on name.
+struct plist_t
+{
+ provider_t **buf;
+ size_t n_used;
+ size_t n_allocated;
+};
+
+// Accumulate a list of provider pointers.
+static int
+prov_get (provider_t *prov, void *plist_v)
+{
+ struct plist_t *p = plist_v;
+ if (p->n_used == p->n_allocated) {
+ void *v = a2nrealloc (p->buf, &p->n_allocated, sizeof *(p->buf));
+ if (v == NULL)
+ return 0; // tell caller we've failed
+ p->buf = v;
+ }
+ p->buf[p->n_used++] = prov;
+ return 1;
+}
+
+// Compare two providers based on their names.
+static int
+prov_name_compare (const void *av, const void *bv)
+{
+ const provider_t *const *a = av;
+ const provider_t *const *b = bv;
+ return strcmp ((*a)->name, (*b)->name);
+}
+
static ssize_t
prov_list_generator (void *ctx, uint64_t pos, char *buf, size_t max)
{
@@ -1581,12 +1613,24 @@ prov_list_generator (void *ctx, uint64_t pos, char *buf, size_t
max)
if (ms->gen_ctx == TMPL_CTX_DONE) {
return -1;
}
-
if (ms->buf == NULL) {
- // generate/alloc all provider-related output into memory
- if (prov_do_for_each (prov_fmt, ms) < 0)
+ struct plist_t plist = {NULL, 0, 0};
+
+ // Create list of provider_t pointers.
+ if (prov_do_for_each (prov_get, &plist) < 0)
return -1;
+ // Sort that list on provider names.
+ qsort (plist.buf, plist.n_used, sizeof *(plist.buf),
+ prov_name_compare);
+
+ // Emit all provider-related output into memory.
+ size_t i;
+ for (i = 0; i < plist.n_used; i++) {
+ if (prov_fmt (plist.buf[i], ms) == 0)
+ return -1; // failed
+ }
+
// Abuse the ms->buf_n_alloc member to indicate current offset.
# define buf_offset buf_n_alloc
ms->buf_offset = 0;
diff --git a/t/basic b/t/basic
index 09e25fa..7180bbd 100644
--- a/t/basic
+++ b/t/basic
@@ -122,7 +122,7 @@ p_name=primary
# Verify that default provider's information is as expected.
curl
http://localhost:$port/_providers > p || fail=1
-emit_provider xml "$p_name" fs '' 0 '' '' > p.exp ||
fail=1
+emit_trivial_provider_list xml "$p_name" fs '' 0 '' ''
> p.exp || fail=1
compare p.exp p || fail=1
for i in xml json; do
diff --git a/t/init.cfg b/t/init.cfg
index fd0a838..4777954 100644
--- a/t/init.cfg
+++ b/t/init.cfg
@@ -39,6 +39,26 @@ wait_for()
done
}
+emit_provider_list_prefix()
+{
+ test $1 = xml && p='<providers>' || p='['
+ printf '%sn' "$p"
+}
+
+emit_provider_list_suffix()
+{
+ test $1 = xml && p='</providers>' || p=']'
+ printf '%sn' "$p"
+}
+
+emit_trivial_provider_list()
+{
+ local xml_or_json=$1
+ emit_provider_list_prefix $xml_or_json
+ emit_provider "$@"
+ emit_provider_list_suffix $xml_or_json
+}
+
emit_provider()
{
local xml_or_json=$1
@@ -49,20 +69,17 @@ emit_provider()
if test $xml_or_json = xml; then
printf -'<providers>
-t<provider name="%s">
+'t<provider name="%s">
tt<type>%s</type>
tt<host>%s</host>
tt<port>%s</port>
tt<username>%s</username>
tt<password>%s</password>
t</provider>
-</providers>
' "$@"
else
printf -'[
-t{
+'t{
tt"name": "%s",
tt"type": "%s",
tt"host": "%s",
@@ -70,7 +87,6 @@ emit_provider()
tt"username": "%s",
tt"password": "%s"
t}
-]
' "$@"
fi
}
diff --git a/t/provider b/t/provider
index da372b2..4f7ce25 100644
--- a/t/provider
+++ b/t/provider
@@ -30,11 +30,15 @@ wait_for .1 50 "curl -s
http://localhost:$port" || { echo
iwhd failed to listen; Exit 1; }
fail=0
+
+# Use at least n=300 here, since some processes typically kick in
+# around n=280.
n=400
# ===================================
for i in $(seq $n); do
# Add provider
- p=http://localhost:$port/_providers/p-$i
+ lexico_sortable_i=$(expr 1000 + $i)
+ p=http://localhost:$port/_providers/p-$lexico_sortable_i
curl -d type=s3 -dhost=localhost -dport=80 -dkey=u -dsecret=p $p || fail=1
curl
http://localhost:$port/_providers > p-list || fail=1
# Ensure that there is the correct number of p-DDD entries.
@@ -47,9 +51,16 @@ done
curl
http://localhost:$port/_providers > p-list || fail=1
# Ensure that each was added:
-for i in $(seq $n); do
- grep 'name="'p-$i'"' p-list || fail=1
-done
+{
+ emit_provider_list_prefix xml
+ for i in $(seq $n); do
+ i=$(expr 1000 + $i)
+ emit_provider xml p-$i s3 localhost 80 u p || fail=1
+ done
+ emit_provider xml primary fs '' 0 '' '' || fail=1
+ emit_provider_list_suffix xml
+} > p-exp
+compare p-list p-exp || fail=1
# ===================================
for i in $(seq $n); do
http://repo.or.cz/w/iwhd.git/commit/06254fb7e9346b5bd47eaa3e8b6cab003a264d95
commit 06254fb7e9346b5bd47eaa3e8b6cab003a264d95
Author: Jim Meyering <meyering(a)redhat.com>
Date: Tue Jan 18 10:28:55 2011 +0100
tests: prepare for improved provider checks in t/provider
* t/basic (emit_provider, emit_bucket_list): Move helper functions...
* t/init.cfg: ...to here.
diff --git a/t/basic b/t/basic
index 21d97a7..09e25fa 100644
--- a/t/basic
+++ b/t/basic
@@ -56,80 +56,6 @@ cat <<EOF > root.json || framework_failure_
}
EOF
-emit_provider()
-{
- local xml_or_json=$1
- shift 1
- case $xml_or_json in xml|json);;
- *) echo "invalid xml_or_json $xml_or_json" 1>&2; exit 1;; esac
- case $# in 6);; *) echo "emit_provider: wrong # args" 1>&2; exit 1;;
esac
-
- if test $xml_or_json = xml; then
- printf -'<providers>
-t<provider name="%s">
-tt<type>%s</type>
-tt<host>%s</host>
-tt<port>%s</port>
-tt<username>%s</username>
-tt<password>%s</password>
-t</provider>
-</providers>
-' "$@"
- else
- printf -'[
-t{
-tt"name": "%s",
-tt"type": "%s",
-tt"host": "%s",
-tt"port": %s,
-tt"username": "%s",
-tt"password": "%s"
-t}
-]
-' "$@"
- fi
-}
-
-emit_bucket_list()
-{
- local xml_or_json=$1
- case $xml_or_json in xml|json);;
- *) echo "invalid xml_or_json $xml_or_json" 1>&2; exit 1;; esac
- shift
-
- local i b k
- if test $xml_or_json = xml; then
- printf '<objects>n'
- for i in "$@"; do
- b=$(echo "$i"|sed 's/:.*//')
- k=$(echo "$i"|sed 's/.*://')
- printf -'t<object>
-tt<bucket>%s</bucket>
-tt<key>%s</key>
-t</object>
-' $b $k
- done
- printf '</objects>n'
- else
- printf '[n'
- for i in "$@"; do
- b=$(echo "$i"|sed 's/:.*//')
- k=$(echo "$i"|sed 's/.*://')
- printf -'t{
-tt"bucket": "%s",
-tt"key": "%s"
-t}
-' $b $k
- done
- printf ']n'
- fi
-
-}
-
printf '[{"path": "FS", "type": "fs",
"name": "primary"}]n' > iwhd.cfg || fail=1
@@ -194,7 +120,7 @@ grep ' 403$' role.err || fail=1
p_name=primary
-# Verify that default providers information is as expected.
+# Verify that default provider's information is as expected.
curl
http://localhost:$port/_providers > p || fail=1
emit_provider xml "$p_name" fs '' 0 '' '' > p.exp ||
fail=1
compare p.exp p || fail=1
diff --git a/t/init.cfg b/t/init.cfg
index 0b92496..fd0a838 100644
--- a/t/init.cfg
+++ b/t/init.cfg
@@ -38,3 +38,76 @@ wait_for()
&& { warn_ "EXPIRED: $i x ${sleep_seconds}s: '$cmd'";
return 1; }
done
}
+
+emit_provider()
+{
+ local xml_or_json=$1
+ shift 1
+ case $xml_or_json in xml|json);;
+ *) echo "invalid xml_or_json $xml_or_json" 1>&2; exit 1;; esac
+ case $# in 6);; *) echo "emit_provider: wrong # args" 1>&2; exit 1;;
esac
+
+ if test $xml_or_json = xml; then
+ printf +'<providers>
+t<provider name="%s">
+tt<type>%s</type>
+tt<host>%s</host>
+tt<port>%s</port>
+tt<username>%s</username>
+tt<password>%s</password>
+t</provider>
+</providers>
+' "$@"
+ else
+ printf +'[
+t{
+tt"name": "%s",
+tt"type": "%s",
+tt"host": "%s",
+tt"port": %s,
+tt"username": "%s",
+tt"password": "%s"
+t}
+]
+' "$@"
+ fi
+}
+
+emit_bucket_list()
+{
+ local xml_or_json=$1
+ case $xml_or_json in xml|json);;
+ *) echo "invalid xml_or_json $xml_or_json" 1>&2; exit 1;; esac
+ shift
+
+ local i b k
+ if test $xml_or_json = xml; then
+ printf '<objects>n'
+ for i in "$@"; do
+ b=$(echo "$i"|sed 's/:.*//')
+ k=$(echo "$i"|sed 's/.*://')
+ printf +'t<object>
+tt<bucket>%s</bucket>
+tt<key>%s</key>
+t</object>
+' $b $k
+ done
+ printf '</objects>n'
+ else
+ printf '[n'
+ for i in "$@"; do
+ b=$(echo "$i"|sed 's/:.*//')
+ k=$(echo "$i"|sed 's/.*://')
+ printf +'t{
+tt"bucket": "%s",
+tt"key": "%s"
+t}
+' $b $k
+ done
+ printf ']n'
+ fi
+}
-----------------------------------------------------------------------
Summary of changes:
rest.c | 52 +++++++++++++++++++++++++++++++--
t/basic | 78 +--------------------------------------------------
t/init.cfg | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
t/provider | 28 ++++++++++++++----
template.c | 7 ++++-
template.h | 2 +-
6 files changed, 170 insertions(+), 88 deletions(-)
repo.or.cz automatic notification. Contact project admin jim(a)meyering.net
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
iwhd.git ("image warehouse daemon")