From bcbf3b10677e506942ec017eca329f98b4744d50 Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Tue, 7 Dec 2021 10:53:30 -0500 Subject: [PATCH] rgw:adminops: slightly generalize /info Adds a get_name() method to rgw::sal::Store, by which each store returns its unique name in lowercase. Signed-off-by: Matt Benjamin --- qa/tasks/radosgw_admin_rest.py | 12 ++++++++---- src/rgw/rgw_rest_info.cc | 11 ++++++++++- src/rgw/rgw_sal.h | 2 ++ src/rgw/rgw_sal_dbstore.h | 5 +++++ src/rgw/rgw_sal_rados.h | 4 ++++ 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/qa/tasks/radosgw_admin_rest.py b/qa/tasks/radosgw_admin_rest.py index c0657d53bae..77fb3a65e62 100644 --- a/qa/tasks/radosgw_admin_rest.py +++ b/qa/tasks/radosgw_admin_rest.py @@ -32,7 +32,7 @@ def rgwadmin_rest(connection, cmd, params=None, headers=None, raw=False): put_cmds = ['create', 'link', 'add'] post_cmds = ['unlink', 'modify'] delete_cmds = ['trim', 'rm', 'process'] - get_cmds = ['check', 'info', 'show', 'list'] + get_cmds = ['check', 'info', 'show', 'list', ''] bucket_sub_resources = ['object', 'policy', 'index'] user_sub_resources = ['subuser', 'key', 'caps'] @@ -722,11 +722,15 @@ def task(ctx, config): (ret, out) = rgwadmin_rest(admin_conn, ['user', 'info'], {'uid' : user1}) assert ret == 404 - # TESTCASE 'info' 'info' 'show' 'display info' 'succeeds' + # TESTCASE 'info' 'display info' 'succeeds' (ret, out) = rgwadmin_rest(admin_conn, ['info', '']) assert ret == 200 info = out['info'] - # currently, cluster_id is the only element in the info section - fsid = info['cluster_id'] + backends = info['storage_backends'] + name = backends[0]['name'] + fsid = backends[0]['cluster_id'] + # name is always "rados" at time of writing, but zipper would allow + # other backends, at some point + assert len(name) > 0 # fsid is a uuid, but I'm not going to try to parse it assert len(fsid) > 0 diff --git a/src/rgw/rgw_rest_info.cc b/src/rgw/rgw_rest_info.cc index c69f46243b7..4276819a394 100644 --- a/src/rgw/rgw_rest_info.cc +++ b/src/rgw/rgw_rest_info.cc @@ -24,12 +24,21 @@ void RGWOp_Info_Get::execute(optional_yield y) { Formatter *formatter = flusher.get_formatter(); flusher.start(0); - // extensible array of general info sections + /* extensible array of general info sections, currently only + * storage backend is defined: + * {"info":{"storage_backends":[{"name":"rados","cluster_id":"75d1938b-2949-4933-8386-fb2d1449ff03"}]}} + */ formatter->open_object_section("dummy"); formatter->open_object_section("info"); + formatter->open_array_section("storage_backends"); + // for now, just return the backend that is accessible + formatter->open_object_section("dummy"); + formatter->dump_string("name", store->get_name()); formatter->dump_string("cluster_id", store->get_cluster_id(this, y)); formatter->close_section(); formatter->close_section(); + formatter->close_section(); + formatter->close_section(); flusher.flush(); } /* RGWOp_Info_Get::execute */ diff --git a/src/rgw/rgw_sal.h b/src/rgw/rgw_sal.h index 9e47bb59271..5bb3aff8e4c 100644 --- a/src/rgw/rgw_sal.h +++ b/src/rgw/rgw_sal.h @@ -244,6 +244,8 @@ class Store { Store() {} virtual ~Store() = default; + /** Name of this store provider (e.g., RADOS") */ + virtual const char* get_name() const = 0; /** Get cluster unique identifier */ virtual std::string get_cluster_id(const DoutPrefixProvider* dpp, optional_yield y) = 0; /** Get a User from a rgw_user. Does not query store for user info, so quick */ diff --git a/src/rgw/rgw_sal_dbstore.h b/src/rgw/rgw_sal_dbstore.h index 93f6696afdd..20788e1b653 100644 --- a/src/rgw/rgw_sal_dbstore.h +++ b/src/rgw/rgw_sal_dbstore.h @@ -506,6 +506,11 @@ protected: } int initialize(CephContext *cct, const DoutPrefixProvider *dpp); + + virtual const char* get_name() const override { + return "dbstore"; + } + virtual std::unique_ptr get_user(const rgw_user& u) override; virtual int get_user_by_access_key(const DoutPrefixProvider *dpp, const std::string& key, optional_yield y, std::unique_ptr* user) override; virtual int get_user_by_email(const DoutPrefixProvider *dpp, const std::string& email, optional_yield y, std::unique_ptr* user) override; diff --git a/src/rgw/rgw_sal_rados.h b/src/rgw/rgw_sal_rados.h index c07315ddb33..2b4dfb5169c 100644 --- a/src/rgw/rgw_sal_rados.h +++ b/src/rgw/rgw_sal_rados.h @@ -373,6 +373,10 @@ class RadosStore : public Store { delete rados; } + virtual const char* get_name() const override { + return "rados"; + } + virtual std::unique_ptr get_user(const rgw_user& u) override; virtual std::string get_cluster_id(const DoutPrefixProvider* dpp, optional_yield y) override; virtual int get_user_by_access_key(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y, std::unique_ptr* user) override; -- 2.39.5