From: Matan Breizman Date: Tue, 29 Jun 2021 13:05:29 +0000 (+0000) Subject: rgw: add package version support to lua scripting X-Git-Tag: v17.1.0~1368^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ba3013e212af463ca9e8e81e053f3b9ee5345fad;p=ceph.git rgw: add package version support to lua scripting This patch allows users to set the package version when adding packages to rgw's luarocks package manager. Signed-off-by: Matan Breizman --- diff --git a/doc/radosgw/lua-scripting.rst b/doc/radosgw/lua-scripting.rst index 0f385c46fefa..326eaf6a7a95 100644 --- a/doc/radosgw/lua-scripting.rst +++ b/doc/radosgw/lua-scripting.rst @@ -57,6 +57,20 @@ To add a package to the allowlist: # radosgw-admin script-package add --package={package name} [--allow-compilation] +To add a specific version of a package to the allowlist: + +:: + + # radosgw-admin script-package add --package='{package name} {package version}' [--allow-compilation] + + +* When adding a diffrent version of a package which already exists in the list, the newly + added version will override the existing one. + +* When adding a package without a version specified, the latest version of the package + will be added. + + To remove a package from the allowlist: :: @@ -64,6 +78,17 @@ To remove a package from the allowlist: # radosgw-admin script-package rm --package={package name} +To remove a specific version of a package from the allowlist: + +:: + + # radosgw-admin script-package rm --package='{package name} {package version}' + + +* When removing a package without a version specified, any existing versions of the + package will be removed. + + To print the list of packages in the allowlist: :: diff --git a/src/rgw/rgw_lua.cc b/src/rgw/rgw_lua.cc index 7d5ba3635eda..946a6ff81418 100644 --- a/src/rgw/rgw_lua.cc +++ b/src/rgw/rgw_lua.cc @@ -118,6 +118,13 @@ int add_package(const DoutPrefixProvider *dpp, rgw::sal::Store* store, optional_ return -EINVAL; } + //replace previous versions of the package + const std::string package_name_no_version = package_name.substr(0, package_name.find(" ")); + ret = remove_package(dpp, store, y, package_name_no_version); + if (ret < 0) { + return ret; + } + // add package to list const bufferlist empty_bl; std::map new_package{{package_name, empty_bl}}; @@ -134,14 +141,34 @@ int add_package(const DoutPrefixProvider *dpp, rgw::sal::Store* store, optional_ int remove_package(const DoutPrefixProvider *dpp, rgw::sal::Store* store, optional_yield y, const std::string& package_name) { librados::ObjectWriteOperation op; - op.omap_rm_keys(std::set({package_name})); - const auto ret = rgw_rados_operate(dpp, *(static_cast(store)->getRados()->get_lc_pool_ctx()), - PACKAGE_LIST_OBJECT_NAME, &op, y); - - if (ret < 0) { + size_t pos = package_name.find(" "); + if (pos != string::npos) { + // remove specfic version of the the package + op.omap_rm_keys(std::set({package_name})); + auto ret = rgw_rados_operate(dpp, *(static_cast(store)->getRados()->get_lc_pool_ctx()), + PACKAGE_LIST_OBJECT_NAME, &op, y); + if (ret < 0) { + return ret; + } + return 0; + } + // otherwise, remove any existing versions of the package + packages_t packages; + auto ret = list_packages(dpp, store, y, packages); + if (ret < 0 && ret != -ENOENT) { return ret; } - + for(const auto& package : packages) { + const std::string package_no_version = package.substr(0, package.find(" ")); + if (package_no_version.compare(package_name) == 0) { + op.omap_rm_keys(std::set({package})); + ret = rgw_rados_operate(dpp, *(static_cast(store)->getRados()->get_lc_pool_ctx()), + PACKAGE_LIST_OBJECT_NAME, &op, y); + if (ret < 0) { + return ret; + } + } + } return 0; } @@ -197,13 +224,11 @@ int install_packages(const DoutPrefixProvider *dpp, rgw::sal::Store* store, opti // the lua rocks install dir will be created by luarocks the first time it is called for (const auto& package : packages) { bp::ipstream is; - bp::child c(p, "install", "--lua-version", CEPH_LUA_VERSION, "--tree", luarocks_path, "--deps-mode", "one", package, - bp::std_in.close(), - (bp::std_err & bp::std_out) > is); + const auto cmd = p.string() + " install --lua-version " + CEPH_LUA_VERSION + " --tree " + luarocks_path + " --deps-mode one " + package; + bp::child c(cmd, bp::std_in.close(), (bp::std_err & bp::std_out) > is); // once package reload is supported, code should yield when reading output - std::string line = "CMD: luarocks install --lua-version " + std::string(CEPH_LUA_VERSION) + std::string(" --tree ") + - luarocks_path + " --deps-mode one " + package; + std::string line = std::string("CMD: ") + cmd; do { if (!line.empty()) {