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

Fixes #23904: rudder-packages does not build the right Rust project #5256

Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 8 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,12 @@ pipeline {
}
}
steps {

script {
running.add("Tests - policies")
updateSlack(errors, running, slackResponse, version, changeUrl)
}
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('policies') {
dir('policies/rudderc') {
dir('target/repos') {
dir('ncf') {
git url: 'https://github.com/normation/ncf.git'
Expand All @@ -416,8 +415,11 @@ pipeline {
}
}
sh script: 'make agent-windows', label: 'install local Windows agent'
sh script: 'make check', label: 'language tests'
sh script: 'make docs', label: 'language docs'
sh script: 'make check', label: 'rudderc tests'
sh script: 'make docs', label: 'rudderc docs'
}
dir('policies') {
sh script: 'make check', label: 'policies test'
}
}
}
Expand Down Expand Up @@ -693,7 +695,7 @@ pipeline {
updateSlack(errors, running, slackResponse, version, changeUrl)
}
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('policies') {
dir('policies/rudderc') {
dir('target/repos') {
dir('ncf') {
git url: 'https://github.com/normation/ncf.git'
Expand All @@ -709,7 +711,7 @@ pipeline {
}
sh script: 'RUDDERC_VERSION="${RUDDER_VERSION}-${GIT_COMMIT}" make static', label: 'public binary'
withCredentials([sshUserPrivateKey(credentialsId: 'f15029d3-ef1d-4642-be7d-362bf7141e63', keyFileVariable: 'KEY_FILE', passphraseVariable: '', usernameVariable: 'KEY_USER')]) {
sh script: 'rsync -avz -e "ssh -o StrictHostKeyChecking=no -i${KEY_FILE} -p${SSH_PORT}" target/release/rudderc packager@${HOST_REPO}:/var/www/repos/tools/rudderc/${RUDDER_VERSION}/rudderc-linux-x86_64', label: 'publish rudderc'
sh script: 'rsync -avz -e "ssh -o StrictHostKeyChecking=no -i${KEY_FILE} -p${SSH_PORT}" ../../target/release/rudderc packager@${HOST_REPO}:/var/www/repos/tools/rudderc/${RUDDER_VERSION}/rudderc-linux-x86_64', label: 'publish rudderc'
}
}
}
Expand Down
46 changes: 2 additions & 44 deletions policies/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,5 @@

include ../rust.makefile

DOC_EXAMPLES := $(wildcard rudderc/docs/examples/*/technique.yml)
DOC_EXAMPLES_CF := $(DOC_EXAMPLES:.yml=.cf)

install: build
mkdir -p $(DESTDIR)/opt/rudder/bin
# Install executable
install -m 755 target/release/rudderc $(DESTDIR)/opt/rudder/bin/rudderc

test-docs: $(DOC_EXAMPLES_CF)

test: libs
cargo test --locked --package rudderc
# Parse lib
cargo run --quiet --bin rudderc -- --quiet lib -f json --stdout -l target/repos/ncf/tree/30_generic_methods/ -l target/repos/dsc/plugin/src/ncf/30_generic_methods/ >/dev/null

static: libs version
cargo auditable build --release --locked --features embedded-lib

%.cf: %.yml libs
cd $(shell dirname $@) && cargo run --quiet --bin rudderc -- --quiet build -l ../../../../target/repos/ncf/tree/30_generic_methods/

docs: libs
cargo run --quiet --bin rudderc -- lib -l target/repos/ncf/tree/30_generic_methods/ -l target/repos/dsc/plugin/src/ncf/30_generic_methods/

libs:
mkdir -p target/repos
[ -d target/repos/ncf ] || git clone git@github.com:Normation/ncf.git target/repos/ncf
cd target/repos/ncf && git checkout master && git pull origin master
[ -d target/repos/dsc ] || git clone git@github.com:Normation/rudder-agent-windows.git target/repos/dsc || mkdir -p target/repos/dsc/plugin/ncf/30_generic_methods/
cd target/repos/dsc && git checkout master && git pull origin master || true

agent-windows: libs
curl -sS --output target/rudder-agent.msi https://publisher.normation.com/misc/windows/8.0.3/rudder-agent-8.0.3.2000000000.msi
msiextract target/rudder-agent.msi -C target/agent-windows/
# Sadly, we need to add .cf files to the agent to have everything in one place for now
mkdir -p target/agent-windows/Rudder/share/initial-policy/ncf/cf/
cp target/repos/ncf/tree/30_generic_methods/*.cf target/agent-windows/Rudder/share/initial-policy/ncf/cf/
cp target/repos/dsc/plugin/src/ncf/30_generic_methods/*.cf target/agent-windows/Rudder/share/initial-policy/ncf/cf/
# Simulate a real agent to get correct reporting
echo "1d58a791-7278-4a2c-a10d-048c7b4be2a6" > target/agent-windows/Rudder/etc/uuid.hive

check: lint test test-docs

.PHONY: docs libs clean
check:
cd rudderc && make check
49 changes: 49 additions & 0 deletions policies/rudderc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2020 Normation SAS

include ../../rust.makefile

DOC_EXAMPLES := $(wildcard rudderc/docs/examples/*/technique.yml)
DOC_EXAMPLES_CF := $(DOC_EXAMPLES:.yml=.cf)

install: build
mkdir -p $(DESTDIR)/opt/rudder/bin
# Install executable
install -m 755 target/release/rudderc $(DESTDIR)/opt/rudder/bin/rudderc

test-docs: $(DOC_EXAMPLES_CF)

test: libs
cargo test --locked --package rudderc
# Parse lib
cargo run --quiet --bin rudderc -- --quiet lib -f json --stdout -l target/repos/ncf/tree/30_generic_methods/ -l target/repos/dsc/plugin/src/ncf/30_generic_methods/ >/dev/null

static: libs version
cargo auditable build --release --locked --features embedded-lib

%.cf: %.yml libs
cd $(shell dirname $@) && cargo run --quiet --bin rudderc -- --quiet build -l ../../../../target/repos/ncf/tree/30_generic_methods/

docs: libs
cargo run --quiet --bin rudderc -- lib -l target/repos/ncf/tree/30_generic_methods/ -l target/repos/dsc/plugin/src/ncf/30_generic_methods/

libs:
mkdir -p target/repos
[ -d target/repos/ncf ] || git clone git@github.com:Normation/ncf.git target/repos/ncf
cd target/repos/ncf && git checkout master && git pull origin master
[ -d target/repos/dsc ] || git clone git@github.com:Normation/rudder-agent-windows.git target/repos/dsc || mkdir -p target/repos/dsc/plugin/ncf/30_generic_methods/
cd target/repos/dsc && git checkout master && git pull origin master || true

agent-windows: libs
curl -sS --output target/rudder-agent.msi https://publisher.normation.com/misc/windows/8.0.3/rudder-agent-8.0.3.2000000000.msi
msiextract target/rudder-agent.msi -C target/agent-windows/
# Sadly, we need to add .cf files to the agent to have everything in one place for now
mkdir -p target/agent-windows/Rudder/share/initial-policy/ncf/cf/
cp target/repos/ncf/tree/30_generic_methods/*.cf target/agent-windows/Rudder/share/initial-policy/ncf/cf/
cp target/repos/dsc/plugin/src/ncf/30_generic_methods/*.cf target/agent-windows/Rudder/share/initial-policy/ncf/cf/
# Simulate a real agent to get correct reporting
echo "1d58a791-7278-4a2c-a10d-048c7b4be2a6" > target/agent-windows/Rudder/etc/uuid.hive

check: lint test test-docs

.PHONY: docs libs clean
4 changes: 2 additions & 2 deletions policies/rudderc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ fn main() {
// Done in `Jenkinsfile`
let libs = [
// Unix
PathBuf::from("../target/repos/ncf/tree"),
PathBuf::from("target/repos/ncf/tree"),
// Windows
PathBuf::from("../target/repos/dsc/plugin/src/ncf"),
PathBuf::from("target/repos/dsc/plugin/src/ncf"),
];
let methods = read(&libs).unwrap();
fs::write(METHODS_FILE, serde_json::to_string(methods).unwrap()).unwrap();
Expand Down
14 changes: 11 additions & 3 deletions policies/rudderc/src/backends/windows/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
ir::Technique,
test::TestCase,
};
use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use askama::Template;
use rudder_commons::{
logs::ok_output,
Expand Down Expand Up @@ -96,6 +96,16 @@ pub fn win_agent(
.arg(format!("&'{}'", test_path.display()))
.output()?;

debug!("stdout: {}", String::from_utf8_lossy(&output.stdout));
debug!("stderr: {}", String::from_utf8_lossy(&output.stderr));
if !output.status.success() {
bail!(
"Test {} failed with {}",
case_id,
String::from_utf8_lossy(&output.stderr)
);
}

// Take latest file from reports_dir
// FIXME: find something more reliable
let mut paths: Vec<_> = fs::read_dir(reports_dir)?.map(|r| r.unwrap()).collect();
Expand All @@ -114,7 +124,5 @@ pub fn win_agent(

let run_log = Report::parse(&clean_reports.join("\n"))?;
debug!("reports: {}", reports);
debug!("stdout: {}", String::from_utf8_lossy(&output.stdout));
debug!("stderr: {}", String::from_utf8_lossy(&output.stderr));
Ok(run_log)
}
10 changes: 8 additions & 2 deletions policies/rudderc/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use test_generator::test_resources;

const UNIX_TEST_LIB: &str = "tests/lib/common";
// We need a real windows agent
const WINDOWS_TEST_LIB: &str = "../target/agent-windows/Rudder";
const WINDOWS_TEST_LIB: &str = "target/agent-windows/Rudder";
const TEST_METHODS: &str = "tests/lib/common/30_generic_methods";

/// Compile and tests all files in `cases/test`. This tests the testing feature itself.
Expand Down Expand Up @@ -69,9 +69,15 @@ fn test_windows(filename: &str) {
&technique_dir.join("target"),
&technique_dir.join("tests"),
&[cwd.join(WINDOWS_TEST_LIB)],
"../target/agent-windows/Rudder".to_string(),
Path::new("target/agent-windows/Rudder")
.canonicalize()
.unwrap()
.to_str()
.unwrap()
.to_string(),
None,
false,
);
dbg!(&res);
res.unwrap();
}