Skip to content

Commit 9867da5

Browse files
Fix repository listing and selection (#71)
* inifile: add functions to list sections This way, we can easily discover all repos in the machine * repos: refactor it so we can enable/disable repos... from outside, from an interface or answerfile Also add some tests to see if we parsed the data correctly * repos: add view to select repos * repos: fix security issue * repos: allow the user to set repos on interactive install * repos: fix temporary directory name generation * Disable bogus sonarcloud notification It complains about a pseudo-RNG in a function that is rarely used, and used only for testing, almost never in production * Solve Sonarcloud duplicated code warning * repos: use the correct version enum > @viniciusferrao: There's a class that defines version: > ```cpp > enum class Platform { el8, el9 }; > ``` * Implement corrections suggested by @viniciusferrao * Correct issues on RepoManager class * Fix broken lines. Signed-off-by: Vinícius Ferrão <[email protected]> --------- Signed-off-by: Vinícius Ferrão <[email protected]> Co-authored-by: Vinícius Ferrão <[email protected]>
1 parent dc1e4f1 commit 9867da5

25 files changed

+884
-275
lines changed

include/cloysterhpc/cloyster.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
#include <string>
1313

1414
namespace cloyster {
15-
bool showVersion = false;
16-
bool runAsRoot = false;
17-
bool dryRun = false;
18-
bool enableTUI = false;
19-
bool enableCLI = false;
20-
bool runAsDaemon = false;
21-
std::string logLevelInput
22-
= fmt::format("{}", magic_enum::enum_name(Log::Level::Info));
23-
std::string answerfile;
24-
std::string customRepofilePath;
15+
extern bool showVersion;
16+
extern bool runAsRoot;
17+
extern bool dryRun;
18+
extern bool enableTUI;
19+
extern bool enableCLI;
20+
extern bool runAsDaemon;
21+
22+
extern std::string logLevelInput;
23+
extern std::string answerfile;
24+
extern std::string customRepofilePath;
2525
}
2626

2727
#endif // CLOYSTERHPC_CLOYSTER_H_

include/cloysterhpc/cluster.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <cloysterhpc/ofed.h>
2121
#include <cloysterhpc/queuesystem/pbs.h>
2222
#include <cloysterhpc/queuesystem/slurm.h>
23+
#include <cloysterhpc/repos.h>
2324
#include <cloysterhpc/services/locale.h>
2425
#include <cloysterhpc/services/timezone.h>
2526

@@ -55,6 +56,7 @@ class Cluster {
5556
std::optional<std::unique_ptr<QueueSystem>> m_queueSystem {};
5657
std::optional<Postfix> m_mailSystem {};
5758
std::vector<Node> m_nodes;
59+
std::unique_ptr<BaseRunner> m_runner;
5860

5961
bool m_firewall { false };
6062
SELinuxMode m_selinux { SELinuxMode::Disabled };
@@ -67,7 +69,11 @@ class Cluster {
6769
bool m_updateSystem { false };
6870
DiskImage m_diskImage;
6971

72+
std::optional<RepoManager> m_repos = std::nullopt;
73+
7074
public:
75+
Cluster();
76+
7177
[[nodiscard]] Headnode& getHeadnode();
7278
[[nodiscard]] const Headnode& getHeadnode() const;
7379

@@ -91,6 +97,9 @@ class Cluster {
9197
std::list<std::unique_ptr<Network>>& getNetworks();
9298
Network& getNetwork(Network::Profile profile);
9399

100+
void initRepoManager();
101+
RepoManager& getRepoManager();
102+
94103
/**
95104
* @brief Add a new network to the cluster.
96105
*
@@ -234,9 +243,9 @@ class Cluster {
234243
#endif
235244

236245
/* TODO: Refactor all those leftovers from legacy C version */
237-
std::size_t nodeQuantity;
246+
std::size_t nodeQuantity = 0;
238247
std::string nodePrefix;
239-
std::size_t nodePadding;
248+
std::size_t nodePadding = 0;
240249
address nodeStartIP;
241250
std::string nodeRootPassword;
242251
};

include/cloysterhpc/const.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ constexpr const char* installPath = INSTALL_PATH;
3030

3131
} // namespace cloyster
3232

33+
#define OK 0
34+
3335
using cloyster::installPath;
3436
using cloyster::productName;
3537
using cloyster::productUrl;

include/cloysterhpc/inifile.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <SimpleIni.h>
1010
#include <filesystem>
11+
#include <vector>
1112

1213
/**
1314
* @class inifile
@@ -56,6 +57,20 @@ class inifile {
5657
std::string getValue(const std::string& section, const std::string& key,
5758
const bool optional = true, const bool canBeNull = true);
5859

60+
/**
61+
* @brief List all the sections in a file
62+
*
63+
* @return The names of the sections found
64+
*/
65+
std::vector<std::string> listAllSections() const;
66+
67+
/**
68+
* @brief List all the entries of a section
69+
*
70+
* @return The names of the entries found
71+
*/
72+
std::vector<std::string> listAllEntries(const std::string& section) const;
73+
5974
/**
6075
* @brief Sets a value in the INI file.
6176
*
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2024 Vinícius Ferrão <[email protected]>
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
#pragma once
6+
7+
#include <cloysterhpc/presenter/Presenter.h>
8+
9+
class PresenterRepository : public Presenter {
10+
private:
11+
struct Messages {
12+
static constexpr const auto title = "Repository Selection";
13+
14+
struct General {
15+
static constexpr const auto question
16+
= "Enable/disable the repositories you want to install. Use "
17+
"SPACE for selecting/deselecting";
18+
static constexpr const auto help
19+
= Presenter::Messages::Placeholder::help;
20+
};
21+
};
22+
23+
public:
24+
PresenterRepository(
25+
std::unique_ptr<Cluster>& model, std::unique_ptr<Newt>& view);
26+
};

include/cloysterhpc/repos.h

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,30 @@
66
#ifndef CLOYSTERHPC_REPOS_H_
77
#define CLOYSTERHPC_REPOS_H_
88

9-
#include "inifile.h"
9+
#include <cloysterhpc/inifile.h>
1010
#include <cloysterhpc/os.h>
11+
#include <cloysterhpc/runner.h>
12+
13+
#include <filesystem>
14+
#include <ranges>
1115
#include <string>
1216

1317
namespace cloyster {
1418
extern std::string customRepofilePath;
1519
};
1620

17-
struct repofile {
21+
struct repository {
1822
std::string id;
1923
bool enabled = true;
2024
std::string name;
2125
std::string baseurl;
2226
std::string metalink;
2327
bool gpgcheck = true;
2428
std::string gpgkey;
25-
std::string gpgkeyContent;
26-
27-
repofile(const std::string& id, const std::string& name,
28-
const std::string& baseurl, const std::string& metalink,
29-
const std::string& gpgkey, const std::string& gpgkeyContent)
30-
: id(id)
31-
, name(name)
32-
, baseurl(baseurl)
33-
, metalink(metalink)
34-
, gpgkey(gpgkey)
35-
, gpgkeyContent(gpgkeyContent)
36-
{
37-
}
29+
std::filesystem::path source;
3830
};
3931

40-
class Repos {
32+
class RepoManager {
4133
public:
4234
enum class AdditionalType {
4335
beegfs,
@@ -51,35 +43,43 @@ class Repos {
5143
RPMFusionUpdates
5244
};
5345

46+
RepoManager(BaseRunner& runner, const OS& osinfo)
47+
: m_runner(runner)
48+
, m_os(osinfo)
49+
{
50+
}
51+
52+
void loadFiles(const std::filesystem::path& basedir = "/etc/yum.repos.d");
53+
void loadCustom(inifile& file, const std::filesystem::path& path);
54+
55+
void enable(const std::string& id);
56+
void enableMultiple(std::vector<std::string> ids);
57+
void disable(const std::string& id);
58+
59+
void commitStatus();
60+
61+
const std::vector<repository>& listRepos() const;
62+
63+
std::vector<std::string> getxCATOSImageRepos() const;
64+
5465
private:
55-
void configureEL() const;
56-
void configureEL8() const;
57-
void configureEL9() const;
58-
void configureXCAT() const;
59-
void configureAdditionalRepos(
60-
const std::vector<AdditionalType>& additional) const;
61-
void createGPGKeyFile(
62-
const std::string& filename, const std::string& key) const;
63-
void createGPGKeyFile(
64-
const std::filesystem::path& path, const std::string& key) const;
65-
void createGPGKeyFile(const repofile& repo) const;
66-
void createCloysterRepo() const;
66+
std::vector<repository> m_repos;
67+
BaseRunner& m_runner;
6768
OS m_os;
6869

69-
inifile CLOYSTER_REPO_EL8 {
70-
#include "cloysterhpc/repos/el8/cloyster.repo"
71-
};
72-
inifile CLOYSTER_REPO_EL9 = {
73-
#include "cloysterhpc/repos/el9/cloyster.repo"
74-
};
70+
void createFileFor(std::filesystem::path path);
7571

76-
public:
77-
explicit Repos(const OS& osinfo);
78-
void createConfigurationFile(const repofile& repo) const;
79-
static void enable(const std::string& id);
80-
static void disable(const std::string& id);
81-
void configureRepositories() const;
82-
[[nodiscard]] std::vector<std::string> getxCATOSImageRepos() const;
72+
std::vector<repository> buildCloysterTree(
73+
const std::filesystem::path& basedir);
74+
75+
void loadSingleFile(std::filesystem::path source);
76+
void saveRepositories();
77+
78+
void configureXCAT();
79+
void configureEL();
80+
void setEnableState(const std::string& id, bool value);
81+
82+
void mergeWithCurrentList(std::vector<repository>&& repo);
8383
};
8484

85-
#endif // CLOYSTERHPC_REPOS_H_
85+
#endif // CLOYSTERHPC_REPOS_H_

0 commit comments

Comments
 (0)