cls_user: add generate_test_instances() implementation

to all the encoded/decoded stuff

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
This commit is contained in:
Yehuda Sadeh 2014-01-24 15:01:01 -08:00
parent e5dc8d6583
commit 9a55fa1cac
6 changed files with 254 additions and 1 deletions

View File

@ -100,7 +100,11 @@ DENCODER_DEPS += libcls_rgw_client.la
libcls_rbd_client_la_SOURCES = cls/rbd/cls_rbd_client.cc
noinst_LTLIBRARIES += libcls_rbd_client.la
libcls_user_client_a_SOURCES = cls/user/cls_user_client.cc cls/user/cls_user_types.cc
libcls_user_client_a_SOURCES = cls/user/cls_user_client.cc \
cls/user/cls_user_types.cc \
cls/user/cls_user_ops.cc
DENCODER_DEPS += libcls_user_client.a
noinst_LIBRARIES += libcls_user_client.a
noinst_HEADERS += \

View File

@ -0,0 +1,115 @@
// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "cls/user/cls_user_types.h"
#include "cls/user/cls_user_ops.h"
#include "common/Formatter.h"
#include "common/ceph_json.h"
void cls_user_set_buckets_op::dump(Formatter *f) const
{
encode_json("entries", entries, f);
encode_json("add", add, f);
encode_json("time", time, f);
}
void cls_user_set_buckets_op::generate_test_instances(list<cls_user_set_buckets_op*>& ls)
{
ls.push_back(new cls_user_set_buckets_op);
cls_user_set_buckets_op *op = new cls_user_set_buckets_op;
for (int i = 0; i < 3; i++) {
cls_user_bucket_entry e;
cls_user_gen_test_bucket_entry(&e, i);
op->entries.push_back(e);
}
op->add = true;
op->time = utime_t(1, 0);
ls.push_back(op);
}
void cls_user_remove_bucket_op::dump(Formatter *f) const
{
encode_json("bucket", bucket, f);
}
void cls_user_remove_bucket_op::generate_test_instances(list<cls_user_remove_bucket_op*>& ls)
{
ls.push_back(new cls_user_remove_bucket_op);
cls_user_remove_bucket_op *op = new cls_user_remove_bucket_op;
cls_user_gen_test_bucket(&op->bucket, 0);
ls.push_back(op);
}
void cls_user_list_buckets_op::dump(Formatter *f) const
{
encode_json("marker", marker, f);
encode_json("max_entries", max_entries, f);
}
void cls_user_list_buckets_op::generate_test_instances(list<cls_user_list_buckets_op*>& ls)
{
ls.push_back(new cls_user_list_buckets_op);
cls_user_list_buckets_op *op = new cls_user_list_buckets_op;
op->marker = "marker";
op->max_entries = 1000;
ls.push_back(op);
}
void cls_user_list_buckets_ret::dump(Formatter *f) const
{
encode_json("entries", entries, f);
encode_json("marker", marker, f);
encode_json("truncated", truncated, f);
}
void cls_user_list_buckets_ret::generate_test_instances(list<cls_user_list_buckets_ret*>& ls)
{
ls.push_back(new cls_user_list_buckets_ret);
cls_user_list_buckets_ret *ret = new cls_user_list_buckets_ret;
for (int i = 0; i < 3; i++) {
cls_user_bucket_entry e;
cls_user_gen_test_bucket_entry(&e, i);
ret->entries.push_back(e);
}
ret->marker = "123";
ret->truncated = true;
ls.push_back(ret);
}
void cls_user_get_header_op::dump(Formatter *f) const
{
// empty!
}
void cls_user_get_header_op::generate_test_instances(list<cls_user_get_header_op*>& ls)
{
ls.push_back(new cls_user_get_header_op);
}
void cls_user_get_header_ret::dump(Formatter *f) const
{
encode_json("header", header, f);
}
void cls_user_get_header_ret::generate_test_instances(list<cls_user_get_header_ret*>& ls)
{
ls.push_back(new cls_user_get_header_ret);
cls_user_get_header_ret *ret = new cls_user_get_header_ret;
cls_user_gen_test_header(&ret->header);
ls.push_back(ret);
}
void cls_user_complete_stats_sync_op::dump(Formatter *f) const
{
encode_json("time", time, f);
}
void cls_user_complete_stats_sync_op::generate_test_instances(list<cls_user_complete_stats_sync_op*>& ls)
{
ls.push_back(new cls_user_complete_stats_sync_op);
cls_user_complete_stats_sync_op *op = new cls_user_complete_stats_sync_op;
op->time = utime_t(12345, 0);
ls.push_back(op);
}

View File

@ -29,6 +29,9 @@ struct cls_user_set_buckets_op {
::decode(time, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_set_buckets_op*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_set_buckets_op)
@ -48,6 +51,9 @@ struct cls_user_remove_bucket_op {
::decode(bucket, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_remove_bucket_op*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_remove_bucket_op)
@ -71,6 +77,9 @@ struct cls_user_list_buckets_op {
::decode(max_entries, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_list_buckets_op*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_list_buckets_op)
@ -96,6 +105,9 @@ struct cls_user_list_buckets_ret {
::decode(truncated, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_list_buckets_ret*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_list_buckets_ret)
@ -112,6 +124,9 @@ struct cls_user_get_header_op {
DECODE_START(1, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_get_header_op*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_get_header_op)
@ -131,6 +146,9 @@ struct cls_user_get_header_ret {
::decode(header, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_get_header_ret*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_get_header_ret)
@ -150,6 +168,9 @@ struct cls_user_complete_stats_sync_op {
::decode(time, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_complete_stats_sync_op*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_complete_stats_sync_op)

View File

@ -5,6 +5,69 @@
#include "common/Formatter.h"
#include "common/ceph_json.h"
void cls_user_gen_test_bucket(cls_user_bucket *bucket, int i)
{
char buf[16];
snprintf(buf, sizeof(buf), ".%d", i);
bucket->name = string("buck") + buf;
bucket->data_pool = string(".data.pool") + buf;
bucket->index_pool = string(".index.pool") + buf;
bucket->marker = string("mark") + buf;
bucket->bucket_id = string("bucket.id") + buf;
}
void cls_user_bucket::dump(Formatter *f) const
{
encode_json("name", name, f);
encode_json("data_pool", data_pool,f);
encode_json("index_pool", index_pool,f);
encode_json("marker", marker,f);
encode_json("bucket_id", bucket_id,f);
}
void cls_user_bucket::generate_test_instances(list<cls_user_bucket*>& ls)
{
ls.push_back(new cls_user_bucket);
cls_user_bucket *b = new cls_user_bucket;
cls_user_gen_test_bucket(b, 0);
ls.push_back(b);
}
void cls_user_bucket_entry::dump(Formatter *f) const
{
encode_json("bucket", bucket, f);
encode_json("size", size, f);
encode_json("size_rounded", size_rounded, f);
encode_json("creation_time", creation_time, f);
encode_json("count", count, f);
encode_json("user_stats_sync", user_stats_sync, f);
}
void cls_user_gen_test_bucket_entry(cls_user_bucket_entry *entry, int i)
{
cls_user_gen_test_bucket(&entry->bucket, i);
entry->size = i + 1;
entry->size_rounded = i + 2;
entry->creation_time = i + 3;
entry->count = i + 4;
entry->user_stats_sync = true;
}
void cls_user_bucket_entry::generate_test_instances(list<cls_user_bucket_entry*>& ls)
{
ls.push_back(new cls_user_bucket_entry);
cls_user_bucket_entry *entry = new cls_user_bucket_entry;
cls_user_gen_test_bucket_entry(entry, 0);
ls.push_back(entry);
}
void cls_user_gen_test_stats(cls_user_stats *s)
{
s->total_entries = 1;
s->total_bytes = 2;
s->total_bytes_rounded = 3;
}
void cls_user_stats::dump(Formatter *f) const
{
@ -13,9 +76,32 @@ void cls_user_stats::dump(Formatter *f) const
f->dump_int("total_bytes_rounded", total_bytes_rounded);
}
void cls_user_stats::generate_test_instances(list<cls_user_stats*>& ls)
{
ls.push_back(new cls_user_stats);
cls_user_stats *s = new cls_user_stats;
cls_user_gen_test_stats(s);
ls.push_back(s);
}
void cls_user_gen_test_header(cls_user_header *h)
{
cls_user_gen_test_stats(&h->stats);
h->last_stats_sync = utime_t(1, 0);
h->last_stats_update = utime_t(2, 0);
}
void cls_user_header::dump(Formatter *f) const
{
encode_json("stats", stats, f);
encode_json("last_stats_sync", last_stats_sync, f);
encode_json("last_stats_update", last_stats_update, f);
}
void cls_user_header::generate_test_instances(list<cls_user_header*>& ls)
{
ls.push_back(new cls_user_header);
cls_user_header *h = new cls_user_header;
cls_user_gen_test_header(h);
ls.push_back(h);
}

View File

@ -54,6 +54,9 @@ struct cls_user_bucket {
bool operator<(const cls_user_bucket& b) const {
return name.compare(b.name) < 0;
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_bucket*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_bucket)
@ -106,6 +109,8 @@ struct cls_user_bucket_entry {
::decode(user_stats_sync, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_bucket_entry*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_bucket_entry)
@ -130,6 +135,7 @@ struct cls_user_stats {
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_stats*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_stats)
@ -157,9 +163,15 @@ struct cls_user_header {
}
void dump(Formatter *f) const;
static void generate_test_instances(list<cls_user_header*>& ls);
};
WRITE_CLASS_ENCODER(cls_user_header)
void cls_user_gen_test_bucket(cls_user_bucket *bucket, int i);
void cls_user_gen_test_bucket_entry(cls_user_bucket_entry *entry, int i);
void cls_user_gen_test_stats(cls_user_stats *stats);
void cls_user_gen_test_header(cls_user_header *h);
#endif

View File

@ -239,6 +239,21 @@ TYPE(cls_rgw_bi_log_list_ret)
#include "cls/rgw/cls_rgw_client.h"
TYPE(rgw_bi_log_entry)
#include "cls/user/cls_user_types.h"
TYPE(cls_user_bucket)
TYPE(cls_user_bucket_entry)
TYPE(cls_user_stats)
TYPE(cls_user_header)
#include "cls/user/cls_user_ops.h"
TYPE(cls_user_set_buckets_op)
TYPE(cls_user_remove_bucket_op)
TYPE(cls_user_list_buckets_op)
TYPE(cls_user_list_buckets_ret)
TYPE(cls_user_get_header_op)
TYPE(cls_user_get_header_ret)
TYPE(cls_user_complete_stats_sync_op)
#include "rgw/rgw_common.h"
TYPE(RGWAccessKey);
TYPE(RGWSubUser);