Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doveadm rmb unit tests #174 #176

Merged
merged 16 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librmb/rados-mail-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ RadosMailObject::RadosMailObject() {
this->object_size = -1;
this->active_op = false;
this->save_date_rados = -1;
this->valid = true;
}
RadosMailObject::~RadosMailObject() {}

Expand Down Expand Up @@ -60,8 +61,11 @@ std::string RadosMailObject::to_string(const string &padding) {
}
}
ostringstream ss;

ss << endl;
if (!valid) {
ss << padding << "<<< MAIL OBJECT IS NOT VALID <<<<" << endl;
}

ss << padding << "MAIL: ";
if (!uid.empty()) {
ss << static_cast<char>(RBOX_METADATA_MAIL_UID) << "(uid)=" << uid << endl;
Expand Down
3 changes: 3 additions & 0 deletions src/librmb/rados-mail-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ string get_metadata(const string& key) {
return value;
}

bool is_valid() { return valid; }
void set_valid(bool valid_) { valid = valid_; }
bool has_active_op() { return active_op; }
string to_string(const string& padding);
void add_metadata(const RadosMetadata& metadata) { attrset[metadata.key] = metadata.bl; }
Expand Down Expand Up @@ -92,6 +94,7 @@ const string get_extended_metadata(string& key) {

map<string, ceph::bufferlist> attrset;
map<string, ceph::bufferlist> extended_attrset;
bool valid;

public:
static const char X_ATTR_VERSION_VALUE[];
Expand Down
2 changes: 1 addition & 1 deletion src/librmb/rados-storage-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ int RadosStorageImpl::copy(std::string &src_oid, const char *src_ns, std::string
ret = aio_operate(&dest_io_ctx, dest_oid, completion, &write_op);
if (ret >= 0) {
ret = completion->wait_for_complete();
// cppcheck-suppress redundantAssignment
// cppcheck-suppress redundantAssignment
ret = completion->get_return_value();
}
completion->release();
Expand Down
12 changes: 6 additions & 6 deletions src/librmb/tools/rmb/rados-mail-box.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class RadosMailBox {

void add_mail(RadosMailObject *mail) {
total_mails++;
if (!mail->is_valid()) {
mails.push_back(mail);
return;
}
if (parser == nullptr) {
mails.push_back(mail);
return;
Expand All @@ -44,18 +48,14 @@ class RadosMailBox {
}
for (std::map<std::string, Predicate *>::iterator it = parser->get_predicates().begin();
it != parser->get_predicates().end(); ++it) {
// std::cout << " looking for: " << it->first << std::endl;
if (mail->get_metadata()->find(it->first) != mail->get_metadata()->end()) {
/* std::cout << "comparing: " << it->second
<< " with : " << mail->get_xvalue(it->first).substr(0, mail->get_xvalue(it->first).length() - 1)
<< " org: " << mail->get_xvalue(it->first) << std::endl;*/
// std::cout << " found : " << it->first << std::endl;

std::string key = it->first;
if (it->second->eval(mail->get_metadata(key))) {
mails.push_back(mail);
}
return;
} else if (it->first.compare("-") == 0) {
mails.push_back(mail);
}
}
}
Expand Down
62 changes: 24 additions & 38 deletions src/librmb/tools/rmb/rmb-commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ int RmbCommands::delete_mail(bool confirmed) {
"may lead to corrupt mailbox\n"
<< " add --yes-i-really-really-mean-it to confirm the delete " << std::endl;
} else {
std::cout << " deleting mail : " << storage->get_pool_name() << " ns: " << storage->get_namespace() << std::endl;
ret = storage->delete_mail((*opts)["to_delete"]);
if (ret < 0) {
std::cout << "unable to delete e-mail object with oid: " << (*opts)["to_delete"] << std::endl;
Expand All @@ -156,7 +157,7 @@ int RmbCommands::rename_user(librmb::RadosCephConfig *cfg, bool confirmed, const
std::cout << "Error: To be able to rename a user, the configuration option generate_namespace needs to be active"
<< std::endl;
print_debug("end: rename_user");
return 0;
return -1;
}
if (!confirmed) {
std::cout << "WARNING: renaming a user may lead to data loss! Do you really really want to do this? \n add "
Expand Down Expand Up @@ -184,21 +185,21 @@ int RmbCommands::rename_user(librmb::RadosCephConfig *cfg, bool confirmed, const
std::cout << "Error there does not exist a configuration file for " << src_ << std::endl;
print_debug("end: rename_user");
return -1;
}
exist = storage->stat_mail(dest_, &size, &save_time);
if (exist >= 0) {
std::cout << "Error: there already exists a configuration file: " << dest_ << std::endl;
print_debug("end: rename_user");
return -1;
}
int ret = storage->copy(src_, cfg->get_user_ns().c_str(), dest_, cfg->get_user_ns().c_str(), list);
if (ret == 0) {
ret = storage->delete_mail(src_);
if (ret != 0) {
std::cout << "Error removing errorcode: " << ret << " oid: " << src_ << std::endl;
}
exist = storage->stat_mail(dest_, &size, &save_time);
if (exist >= 0) {
std::cout << "Error: there already exists a configuration file: " << dest_ << std::endl;
print_debug("end: rename_user");
return -1;
}
int ret = storage->copy(src_, cfg->get_user_ns().c_str(), dest_, cfg->get_user_ns().c_str(), list);
if (ret == 0) {
ret = storage->delete_mail(src_);
if (ret != 0) {
std::cout << "Error removing errorcode: " << ret << " oid: " << src_ << std::endl;
}
} else {
std::cout << "Error renaming copy failed: return code: " << ret << " oid: " << src_ << std::endl;
} else {
std::cout << "Error renaming copy failed: return code: " << ret << " oid: " << src_ << std::endl;
}
print_debug("end: rename_user");
return ret;
Expand Down Expand Up @@ -327,33 +328,21 @@ static void aio_cb(rados_completion_t cb, void *arg) {
if (stat->completion->get_return_value() == 0 && stat->object_size > 0) {
stat->mail->set_mail_size(stat->object_size);
stat->mail->set_rados_save_date(stat->save_date_rados);
bool valid = true;
if (stat->load_metadata) {
if (stat->ms->load_metadata(stat->mail) < 0) {
std::cout << " loading metadata of object '" << stat->mail->get_oid() << "' faild " << std::endl;
delete stat->mail;
valid = false;
stat->mail->set_valid(false);
}

if (stat->mail->get_metadata()->empty()) {
std::cout << " pool object " << stat->mail->get_oid() << " is not a mail object" << std::endl;
delete stat->mail;
valid = false;
stat->mail->set_valid(false);
}

if (!librmb::RadosUtils::validate_metadata(stat->mail->get_metadata())) {
std::cout << "object : " << stat->mail->get_oid() << " metadata is not valid " << std::endl;
delete stat->mail;
valid = false;
stat->mail->set_valid(false);
}
}
if (valid) {
stat->mail_objects->push_back(stat->mail);
}
} else {
std::cout << " object '" << stat->mail->get_oid() << "' is not a valid mail object, size = 0" << std::endl;
delete stat->mail;
stat->mail->set_valid(false);
}
stat->mail_objects->push_back(stat->mail);
delete stat;
}
int RmbCommands::load_objects(librmb::RadosStorageMetadataModule *ms,
Expand Down Expand Up @@ -420,7 +409,6 @@ int RmbCommands::load_objects(librmb::RadosStorageMetadataModule *ms,
int RmbCommands::print_mail(std::map<std::string, librmb::RadosMailBox *> *mailbox, std::string &output_dir,
bool download) {
print_debug("entry:: print_mail");

for (std::map<std::string, librmb::RadosMailBox *>::iterator it = mailbox->begin(); it != mailbox->end(); ++it) {
if (it->second->get_mail_count() == 0) {
continue;
Expand All @@ -429,7 +417,6 @@ int RmbCommands::print_mail(std::map<std::string, librmb::RadosMailBox *> *mailb
if (!download) {
continue;
}

librmb::MailboxTools tools(it->second, output_dir);
if (tools.init_mailbox_dir() < 0) {
std::cout << " error initializing output dir : " << output_dir << std::endl;
Expand All @@ -446,9 +433,7 @@ int RmbCommands::print_mail(std::map<std::string, librmb::RadosMailBox *> *mailb
}
}
}

print_debug("end: print_mail");

return 0;
}

Expand Down Expand Up @@ -514,8 +499,9 @@ RadosStorageMetadataModule *RmbCommands::init_metadata_storage_module(librmb::Ra
} else {
ms = new librmb::RadosMetadataStorageDefault(&storage->get_io_ctx());
}

*uid = (*opts)["namespace"] + cfg.get_user_suffix();
if (!(*opts)["namespace"].empty()) {
*uid = (*opts)["namespace"] + cfg.get_user_suffix();
}
std::string ns;
if (mgr.lookup_key(*uid, &ns)) {
storage->set_namespace(ns);
Expand Down
Loading