Skip to content

Commit

Permalink
fix gtest:setdevice.scan_command_line
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz authored and alaaeddineelamri committed Aug 4, 2022
1 parent 8ea2322 commit 88d47f8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 45 deletions.
53 changes: 14 additions & 39 deletions core/src/lib/parse_conf.cc
Expand Up @@ -207,10 +207,6 @@ bool ConfigurationParser::ParseConfig()
bool success = ParseConfigFile(config_path.c_str(), nullptr, scan_error_,
scan_warning_);
if (success && ParseConfigReadyCb_) { ParseConfigReadyCb_(*this); }
/* if (success) { */
/* res_head_container_previous_ = std::move(res_head_container_); */
/* res_head_container_.reset(new ResHeadContainer(this)); */
/* } */
return success;
}

Expand Down Expand Up @@ -518,54 +514,33 @@ bool ConfigurationParser::FindConfigPath(PoolMem& full_path)
return found;
}


// remove our shared pointer to previous configuration so that it will be freed
// when last job owning is done
// when last job also owning finishes
void ConfigurationParser::ReleasePreviousResourceTable()
{
Dmsg1(10, "ConfigurationParser::ReleasePreviousResourceTable: %p\n",
res_head_container_previous_->res_head_);
res_head_container_previous_ = nullptr;
}

#if 0
void ConfigurationParser::RestorePreviousConfig()
{
// res_head_container_ = std::move(res_head_container_previous_);
res_head_container_backup_->res_head_);
res_head_container_backup_ = nullptr;
}

#endif

#if 0
void ConfigurationParser::ClearResourceTables()
// swap the previously saved res_head_previous_ with res_head_
// and release the res_head_previous_
void ConfigurationParser::RestoreResourceTable()
{
/* int num = r_num_; */
/* for (int i = 0; i < num; i++) { */
/* res_head_container_->res_head_[i] = nullptr; */
/* res_head_[i] = nullptr; */
/* } */
}
#endif

// restore the previously saved res_head_backup_ to res_head_
bool ConfigurationParser::RestoreResourceTable()
{
std::swap(res_head_container_, res_head_container_previous_);
std::swap(res_head_container_, res_head_container_backup_);
Dmsg1(10, "ConfigurationParser::RestoreResourceTable: %p -> %p\n",
res_head_container_previous_->res_head_,
res_head_container_->res_head_);
res_head_container_backup_->res_head_, res_head_container_->res_head_);
Dmsg1(10, "ConfigurationParser::RestoreResourceTable: release %p\n",
res_head_container_previous_->res_head_);
res_head_container_previous_ = nullptr;
return true;
res_head_container_backup_->res_head_);
res_head_container_backup_ = nullptr;
}

// copy the current resource table to res_head_backup_
// and create a new res_head_container_
bool ConfigurationParser::BackupResourceTable()
// and create a new empty res_head_container_
void ConfigurationParser::BackupResourceTable()
{
std::swap(res_head_container_, res_head_container_previous_);
std::swap(res_head_container_, res_head_container_backup_);
res_head_container_.reset(new ResHeadContainer(this));
return true;
}

bool ConfigurationParser::RemoveResource(int rcode, const char* name)
Expand Down
7 changes: 3 additions & 4 deletions core/src/lib/parse_conf.h
Expand Up @@ -220,7 +220,7 @@ class ConfigurationParser {
ResourceTable*
resource_definitions_; /* Pointer to table of permitted resources */
std::shared_ptr<ResHeadContainer> res_head_container_;
std::shared_ptr<ResHeadContainer> res_head_container_previous_;
std::shared_ptr<ResHeadContainer> res_head_container_backup_;
mutable brwlock_t res_lock_; /* Resource lock */

SaveResourceCb_t SaveResourceCb_;
Expand Down Expand Up @@ -257,9 +257,8 @@ class ConfigurationParser {
void FreeResources();

void ReleasePreviousResourceTable();
void RestorePreviousConfig();
bool BackupResourceTable();
bool RestoreResourceTable();
void BackupResourceTable();
void RestoreResourceTable();

void InitResource(int rcode,
ResourceItem items[],
Expand Down
10 changes: 10 additions & 0 deletions core/src/tests/setdevice.cc
Expand Up @@ -34,6 +34,11 @@
#include "include/job_types.h"
#include "lib/output_formatter.h"

#include "lib/parse_conf.h"
#include "dird/dird_globals.h"
#include "dird/dird_conf.h"


#include <array>

namespace directordaemon {
Expand All @@ -60,6 +65,11 @@ static bool sprintit(void* ctx, const char* fmt, ...)

TEST(setdevice, scan_command_line)
{
OSDependentInit();
std::string path_to_config_file = std::string(
RELATIVE_PROJECT_SOURCE_DIR "/configs/bareos-configparser-tests");
my_config = InitDirConfig(path_to_config_file.c_str(), M_ERROR_TERM);

std::unique_ptr<JobControlRecord, decltype(&Test_FreeJcr)> jcr(
NewDirectorJcr(), &Test_FreeJcr);

Expand Down
4 changes: 2 additions & 2 deletions core/src/tests/test_config_parser_dir.cc
Expand Up @@ -41,13 +41,13 @@ TEST(ConfigParser_Dir, bareos_configparser_tests)
my_config->ParseConfig();
my_config->DumpResources(PrintMessage, NULL);

ASSERT_EQ(true, my_config->BackupResourceTable());
my_config->BackupResourceTable();

my_config->ParseConfig();
me = (DirectorResource*)my_config->GetNextRes(R_DIRECTOR, nullptr);
my_config->own_resource_ = me;
ASSERT_NE(nullptr, me);
ASSERT_EQ(true, my_config->RestoreResourceTable());
my_config->RestoreResourceTable();
ASSERT_NE(nullptr, me);
my_config->ParseConfig();
me = (DirectorResource*)my_config->GetNextRes(R_DIRECTOR, nullptr);
Expand Down

0 comments on commit 88d47f8

Please sign in to comment.