Skip to content

Commit

Permalink
Merge pull request #1315 from alaaeddineelamri/dev/alaaeddineelamri/m…
Browse files Browse the repository at this point in the history
…aster/s5321-fix-show-directors

dird: fix director resource not showing when using `show director` or the `--xc director` cli option
  • Loading branch information
joergsteffens committed Nov 30, 2022
2 parents ae50ae6 + bb3ce33 commit 3a8de24
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 122 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Expand Up @@ -30,7 +30,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- tests: simplify test coverage analysis [PR #1010]
- webui: analytics module: show stored data per jobname in treemap [PR #1082]
- webui: add pool column to volume lists [PR #1120]
- webui: introduce themes [#1281]
- webui: introduce themes [PR #1281]
- dird: console: add `jobtype` parameter to `(l)list jobs` [PR #1149]
- contrib: add support for building and packaging [PR #768]:
- bareos-contrib-director-python-plugins
Expand Down Expand Up @@ -109,11 +109,11 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- testfind: remove unnecessary libraries and fix systemtest [PR #1250]
- stored: systemtests: docs: checkpoints improvements [PR #1277]
- winbareos.nsi: fix working directory in configure.sed [PR #1288]
- core: BareosDb::FindLastJobStartTimeForJobAndClient: take into account Running job [PR #1265] [Issue #1466]
- core: BareosDb::FindLastJobStartTimeForJobAndClient: take into account Running job [Issue #1466] [PR #1265]
- backup.cc: fail backup when `Write Bootstrap` to pipe fails [PR #1296]
- webui: fix pool link in job details formatter [Issue #1489] [PR #1303]
- webui: patch zf2 to eliminate a php warning caused by zend-stdlib [PR #1305]
- dird: fix director resource not showing when using `show director` or the `--xc director` cli option [PR #1315]

### Changed
- contrib: rename Python modules to satisfy PEP8 [PR #768]
Expand Down Expand Up @@ -364,9 +364,9 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
[PR #1277]: https://github.com/bareos/bareos/pull/1277
[PR #1278]: https://github.com/bareos/bareos/pull/1278
[PR #1279]: https://github.com/bareos/bareos/pull/1279
[PR #1281]: https://github.com/bareos/bareos/pull/1281
[PR #1282]: https://github.com/bareos/bareos/pull/1282
[PR #1283]: https://github.com/bareos/bareos/pull/1283
[PR #1281]: https://github.com/bareos/bareos/pull/1281
[PR #1284]: https://github.com/bareos/bareos/pull/1284
[PR #1285]: https://github.com/bareos/bareos/pull/1285
[PR #1288]: https://github.com/bareos/bareos/pull/1288
Expand All @@ -379,6 +379,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
[PR #1306]: https://github.com/bareos/bareos/pull/1306
[PR #1307]: https://github.com/bareos/bareos/pull/1307
[PR #1313]: https://github.com/bareos/bareos/pull/1313
[PR #1315]: https://github.com/bareos/bareos/pull/1315
[PR #1317]: https://github.com/bareos/bareos/pull/1317
[PR #1318]: https://github.com/bareos/bareos/pull/1318
[PR #1314]: https://github.com/bareos/bareos/pull/1314
Expand Down
56 changes: 0 additions & 56 deletions core/src/dird/show_cmd_available_resources.h

This file was deleted.

98 changes: 45 additions & 53 deletions core/src/dird/ua_output.cc
Expand Up @@ -40,7 +40,6 @@
#include "dird/ua_db.h"
#include "dird/ua_output.h"
#include "dird/ua_select.h"
#include "dird/show_cmd_available_resources.h"
#include "lib/edit.h"
#include "lib/parse_conf.h"
#include "dird/jcr_util.h"
Expand Down Expand Up @@ -212,29 +211,36 @@ static void ShowAll(UaContext* ua, bool hide_sensitive_data, bool verbose)
*/
bool show_cmd(UaContext* ua, const char*)
{
int i, j, type, len;
int recurse;
char* res_name;
BareosResource* res = NULL;
bool verbose = false;
bool hide_sensitive_data;

Dmsg1(20, "show: %s\n", ua->UA_sock->msg);

/*
* When the console has no access to the configure cmd then any show cmd
* will suppress all sensitive information like for instance passwords.
*/
hide_sensitive_data = !ua->AclAccessOk(Command_ACL, "configure", false);

if (FindArg(ua, NT_("verbose")) > 0) { verbose = true; }
bool hide_sensitive_data = !ua->AclAccessOk(Command_ACL, "configure", false);

bool show_verbose = false;
if (FindArg(ua, NT_("verbose")) > 0) { show_verbose = true; }

if (FindArg(ua, "help") > 0) {
ua->InfoMsg(_("Keywords for the show command are:\n"));
for (const auto& command : show_cmd_available_resources) {
ua->InfoMsg("%s\n", command.first.c_str());
}
return true;
}

LockRes(my_config);

// Without parameter, show all ressources.
if (ua->argc == 1) { ShowAll(ua, hide_sensitive_data, verbose); }
if (ua->argc == 1 || FindArg(ua, "all") > 0) {
ShowAll(ua, hide_sensitive_data, show_verbose);
UnlockRes(my_config);
return true;
}

for (i = 1; i < ua->argc; i++) {
for (int i = 1; i < ua->argc; i++) {
// skip verbose keyword, already handled earlier.
if (Bstrcasecmp(ua->argk[i], NT_("verbose"))) { continue; }

Expand All @@ -254,67 +260,53 @@ bool show_cmd(UaContext* ua, const char*)
ShowDisabledSchedules(ua);
}
ua->send->ObjectEnd("disabled");
goto bail_out;
UnlockRes(my_config);
return true;
}

type = 0;
res_name = ua->argk[i];
int type = -1;
int recurse = 0;
char* res_name = ua->argk[i];
int len = strlen(res_name);
BareosResource* res = nullptr;
if (!ua->argv[i]) { /* was a name given? */
// No name, dump all resources of specified type
recurse = 1;
len = strlen(res_name);
for (j = 0; show_cmd_available_resources[j].res_name; j++) {
if (bstrncasecmp(res_name, _(show_cmd_available_resources[j].res_name),
len)) {
type = show_cmd_available_resources[j].type;
if (type > 0) {
res = my_config->config_resources_container_
->configuration_resources_[type];
} else {
res = NULL;
}
for (const auto& command : show_cmd_available_resources) {
if (bstrncasecmp(res_name, command.first.c_str(), len)) {
type = command.second;
res = my_config->config_resources_container_
->configuration_resources_[type];
break;
}
}
} else {
// Dump a single resource with specified name
recurse = 0;
len = strlen(res_name);
for (j = 0; show_cmd_available_resources[j].res_name; j++) {
if (bstrncasecmp(res_name, _(show_cmd_available_resources[j].res_name),
len)) {
type = show_cmd_available_resources[j].type;
for (const auto& command : show_cmd_available_resources) {
if (bstrncasecmp(res_name, command.first.c_str(), len)) {
type = command.second;
res = (BareosResource*)ua->GetResWithName(type, ua->argv[i], true);
if (!res) { type = -3; }
if (!res) {
ua->ErrorMsg(_("%s resource %s not found.\n"), res_name,
ua->argv[i]);
UnlockRes(my_config);
return true;
}
break;
}
}
}

switch (type) {
case -1: /* all */
ShowAll(ua, hide_sensitive_data, verbose);
break;
case -2:
ua->InfoMsg(_("Keywords for the show command are:\n"));
for (j = 0; show_cmd_available_resources[j].res_name; j++) {
ua->InfoMsg("%s\n", _(show_cmd_available_resources[j].res_name));
}
goto bail_out;
case -3:
ua->ErrorMsg(_("%s resource %s not found.\n"), res_name, ua->argv[i]);
goto bail_out;
case 0:
ua->ErrorMsg(_("Resource %s not found\n"), res_name);
goto bail_out;
default:
my_config->DumpResourceCb_(recurse ? type : -type, res, bsendmsg, ua,
hide_sensitive_data, verbose);
break;
if (type >= 0) {
my_config->DumpResourceCb_(recurse ? type : -type, res, bsendmsg, ua,
hide_sensitive_data, show_verbose);

} else {
ua->ErrorMsg(_("Resource %s not found\n"), res_name);
}
}

bail_out:
UnlockRes(my_config);
return true;
}
Expand Down
13 changes: 12 additions & 1 deletion core/src/dird/ua_output.h
@@ -1,7 +1,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2018-2020 Bareos GmbH & Co. KG
Copyright (C) 2018-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand All @@ -23,9 +23,20 @@
#define BAREOS_DIRD_UA_OUTPUT_H_

#include "lib/output_formatter.h"
#include "dird/dird_conf.h"

#include <unordered_map>

namespace directordaemon {

static std::unordered_map<std::string, int> show_cmd_available_resources = {
{"directors", R_DIRECTOR}, {"clients", R_CLIENT}, {"jobdefs", R_JOBDEFS},
{"jobs", R_JOB}, {"storages", R_STORAGE}, {"catalogs", R_CATALOG},
{"schedules", R_SCHEDULE}, {"filesets", R_FILESET}, {"pools", R_POOL},
{"messages", R_MSGS}, {"counters", R_COUNTER}, {"profiles", R_PROFILE},
{"consoles", R_CONSOLE}, {"users", R_USER}};


class RunResource;

bool bsendmsg(void* ua_ctx, const char* fmt, ...);
Expand Down
4 changes: 2 additions & 2 deletions core/src/lib/parse_conf.cc
Expand Up @@ -304,7 +304,7 @@ int ConfigurationParser::GetResourceCode(const char* resource_type_name)
}
}

return 0;
return -1;
}

ResourceTable* ConfigurationParser::GetResourceTable(
Expand Down Expand Up @@ -563,7 +563,7 @@ bool ConfigurationParser::DumpResources(bool sendit(void* sock,
result = true;
} else {
int res_type = GetResourceCode(res_type_name.c_str());
if (res_type > 0) {
if (res_type >= 0) {
BareosResource* res = nullptr;
if (res_name.empty()) {
// No name, dump all resources of specified type
Expand Down
Expand Up @@ -30,7 +30,6 @@
#include "dird/dird_globals.h"
#include "dird/dird_conf.h"
#include "dird/ua_output.h"
#include "dird/show_cmd_available_resources.h"

#include <set>

Expand All @@ -53,10 +52,8 @@ TEST(available_resources_equals_config_resources, check_contents)

std::set<uint32_t> set_of_show_cmd_resources;

for (int i = 0; show_cmd_available_resources[i].res_name; i++) {
if (show_cmd_available_resources[i].type >= 0) {
set_of_show_cmd_resources.insert(show_cmd_available_resources[i].type);
}
for (const auto& command : show_cmd_available_resources) {
set_of_show_cmd_resources.insert(command.second);
}

EXPECT_EQ(set_of_config_resources, set_of_show_cmd_resources)
Expand Down
@@ -0,0 +1,3 @@
Counter {
name = "random-counter"
}
@@ -0,0 +1,4 @@
Schedule {
Name = "TestCycle"
Run = Full at 14:00
}
@@ -0,0 +1,3 @@
User {
name = "random-user"
}
2 changes: 1 addition & 1 deletion systemtests/tests/python-bareos/test_list_command.py
Expand Up @@ -238,7 +238,7 @@ def test_list_jobs(self):
self.assertTrue(result["jobs"])
for job in result["jobs"]:
self.assertTrue(job["jobstatus"], "T")

# running a job a canceling
director.call("run job=backup-bareos-fd yes")
director.call("cancel job=backup-bareos-fd yes")
Expand Down
38 changes: 37 additions & 1 deletion systemtests/tests/python-bareos/test_show.py
@@ -1,7 +1,7 @@
#
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2021 Bareos GmbH & Co. KG
# Copyright (C) 2019-2022 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -74,3 +74,39 @@ def test_fileset(self):
fileset_show_description = result["filesets"][fileset]["description"]

self.assertIn(fileset_show_description, fileset_content_list)

def test_show_resources(self):
"""
show resources in bconsole
"""

username = self.get_operator_username()
password = self.get_operator_password(username)

director = bareos.bsock.DirectorConsoleJson(
address=self.director_address,
port=self.director_port,
name=username,
password=password,
**self.director_extra_options
)
list_of_resources = {
"directors",
"clients",
"jobs",
"jobdefs",
"storages",
"schedules",
"catalogs",
"filesets",
"pools",
"messages",
"profiles",
"consoles",
"counters",
"users",
}
for resource in list_of_resources:
call = director.call("show {}".format(resource))
result = call[resource]
self.assertTrue(len(result) > 0)

0 comments on commit 3a8de24

Please sign in to comment.