Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cctl module and extend e2e test to use it #46

Merged
merged 6 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@
cargoArtifacts = self'.packages.kairos-deps;
});

cctld = pkgs.runCommand "cctld-wrapped"
{
buildInputs = [ pkgs.makeWrapper ];
meta.mainProgram = "cctld";
}
''
mkdir -p $out/bin
makeWrapper ${self'.packages.kairos}/bin/cctld $out/bin/cctld \
--set PATH ${pkgs.lib.makeBinPath [inputs'.csprpkgs.packages.cctl ]}
'';

default = self'.packages.kairos;

kairos-docs = craneLib.cargoDoc (kairosNodeAttrs // {
Expand Down
8 changes: 8 additions & 0 deletions kairos-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ version.workspace = true
edition.workspace = true
license.workspace = true

[[bin]]
name = "cctld"
path = "bin/cctld.rs"
version.workspace = true
test = false
bench = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]

Expand All @@ -13,6 +20,7 @@ anyhow = "1"
backoff = { version = "0.4", features = ["tokio", "futures"]}
casper-client = "2"
nom = "7"
sd-notify = "0.4"
tokio = { version = "1", features = [ "full", "tracing", "macros" ] }
tempfile = "3"
tracing = "0.1"
Expand Down
14 changes: 14 additions & 0 deletions kairos-test-utils/bin/cctld.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use kairos_test_utils::cctl;
use sd_notify::NotifyState;
use tokio::signal;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let _network = cctl::CCTLNetwork::run()
.await
.expect("An error occured while starting the CCTL network");

let _ = sd_notify::notify(true, &[NotifyState::Ready]);
signal::ctrl_c().await?;
Ok(())
}
10 changes: 9 additions & 1 deletion nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ in
./tests/end-to-end.nix
{
inherit mkKairosHostConfig;
inherit (self.packages."x86_64-linux") kairos;
inherit (self.packages.${pkgs.system}) kairos;
cctlModule = self.nixosModules.cctl;
inherit (inputs.csprpkgs.packages.${pkgs.system}) casper-client-rs;
};
};
nixosModules = {
Expand All @@ -40,6 +42,12 @@ in
imports = [ ./modules/kairos.nix ];
services.kairos.package = self.packages.${pkgs.system}.kairos;
};
cctl =
{ pkgs, lib, ... }:
{
imports = [ ./modules/cctl.nix ];
services.cctl.package = self.packages.${pkgs.system}.cctld;
};
};
};
}
69 changes: 69 additions & 0 deletions nixos/modules/cctl.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{ lib, pkgs, config, ... }:
let
inherit (lib)
types
mkOption
mkIf
mkMerge
mkEnableOption
mdDoc
;
cfg = config.services.cctl;
in
{
options.services.cctl = {

enable = mkEnableOption (mdDoc "cctl");

package = mkOption {
type = types.package;
};

port = mkOption {
type = types.port;
default = 11101;
example = 60000;
description = mdDoc ''
Port to listen on.
TODO make port configurable in cctl

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just do it now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because CCTL does not offer a way to do that yet. Mark is aware of it and working on it.

'';
};

logLevel = mkOption {
type = types.enum [
"error"
"warn"
"info"
"debug"
"trace"
];
marijanp marked this conversation as resolved.
Show resolved Hide resolved
default = "info";
description = ''
The log-level that should be used.
'';
};
};

config = mkIf cfg.enable {

systemd.services.cctl =
{
description = "cctl";
documentation = [ "" ];
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
requires = [ "network-online.target" ];
environment = {
RUST_LOG = cfg.logLevel;
};
serviceConfig = mkMerge [
{
ExecStart = ''${lib.getExe cfg.package}'';
Type = "notify";
Restart = "always";
DynamicUser = true;
}
];
};
};
}
9 changes: 9 additions & 0 deletions nixos/tests/end-to-end.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
, mkKairosHostConfig
, kairos
, testResources ? ../../kairos-cli/tests/fixtures
, cctlModule
, casper-client-rs
}:
nixosTest {
name = "kairos e2e test";
Expand All @@ -10,13 +12,16 @@ nixosTest {
server = { config, pkgs, lib, ... }: {
imports = [
(mkKairosHostConfig "kairos")
cctlModule
];

# modify acme for nixos-test environment
security.acme = {
preliminarySelfsigned = true;
defaults.server = "https://example.com"; # don't spam the acme production server
};
services.cctl.enable = true;
environment.systemPackages = [ casper-client-rs ];
};

client = { config, pkgs, nodes, ... }: {
Expand All @@ -29,12 +34,16 @@ nixosTest {

start_all()

kairos.wait_for_unit("cctl.service")

kairos.wait_for_unit("kairos.service")
kairos.wait_for_unit("nginx.service")
kairos.wait_for_open_port(80)

client.wait_for_unit ("multi-user.target")

kairos.succeed("casper-client get-node-status --node-address http://localhost:11101")

deposit_request = { "public_key": "publickey", "amount": 10 }
# REST API
client.succeed("curl -X POST http://kairos/api/v1/deposit -H 'Content-Type: application/json' -d '{}'".format(json.dumps(deposit_request)))
Expand Down
Loading