Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Test repository selection #43

Merged
merged 4 commits into from
Jul 22, 2021
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
550 changes: 539 additions & 11 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ name = "agent-integration-tests"
version = "0.1.0"

[dependencies]
anyhow = "1.0"
flate2 = "1.0"
futures = "0.3"
http = "0.2"
integration-test-commons = { git = "https://github.com/stackabletech/integration-test-commons.git", tag = "0.3.0" }
k8s-openapi = { version = "0.12", default-features = false, features = ["v1_21"] }
nix = "0.22"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.9"
tar = "0.4"
tokio = { version = "1.8", features = ["macros", "rt-multi-thread"] }
uuid = { version = "0.8", features = ["v4"] }
warp = "0.3"
4 changes: 3 additions & 1 deletion tests/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl<'a> ExitService<'a> {

let pod = TemporaryResource::new(
&client,
&with_unique_name(&format!(
&with_unique_name(&formatdoc!(
"
apiVersion: v1
kind: Pod
Expand All @@ -27,6 +27,8 @@ impl<'a> ExitService<'a> {
- name: EXIT_CODE
value: {exit_code}
restartPolicy: Never
nodeSelector:
kubernetes.io/arch: stackable-linux
tolerations:
- key: kubernetes.io/arch
operator: Equal
Expand Down
7 changes: 5 additions & 2 deletions tests/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ impl<'a> EchoService<'a> {

let pod = TemporaryResource::new(
&client,
&with_unique_name(&formatdoc! {r#"
&with_unique_name(&formatdoc!(
r#"
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -35,13 +36,15 @@ impl<'a> EchoService<'a> {
env:
- name: LOG_OUTPUT
value: "{log_output}"
nodeSelector:
kubernetes.io/arch: stackable-linux
tolerations:
- key: kubernetes.io/arch
operator: Equal
value: stackable-linux
"#,
log_output = log_output.join(NEWLINE)
}),
)),
);

client.verify_pod_condition(&pod, "Ready");
Expand Down
131 changes: 131 additions & 0 deletions tests/repository.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
mod util;

use std::fmt::Debug;

use anyhow::{anyhow, Result};
use integration_test_commons::test::prelude::*;
use uuid::Uuid;

use crate::util::{
repository::{StackableRepository, StackableRepositoryInstance},
services::noop_service,
};

#[tokio::test]
async fn invalid_or_unreachable_repositories_should_be_ignored() -> Result<()> {
let client = KubeClient::new().await?;

let mut result = Ok(());

// Set up repositories and pod

// The agent processes the repositories by their name in
// alphabetical order.

let repository0_result = client
.create::<Repository>(indoc!(
"
apiVersion: stable.stackable.de/v1
kind: Repository
metadata:
name: 0-no-repository-url
namespace: default
spec:
repo_type: StackableRepo
properties: {}
"
))
.await;
combine(&mut result, &repository0_result);

let repository1_result = client
.create::<Repository>(indoc!(
"
apiVersion: stable.stackable.de/v1
kind: Repository
metadata:
name: 1-unreachable
namespace: default
spec:
repo_type: StackableRepo
properties:
url: https://unreachable
"
))
.await;
combine(&mut result, &repository1_result);

let empty_repository = StackableRepository {
name: String::from("2-empty-repository"),
packages: Vec::new(),
};
let repository2_result = StackableRepositoryInstance::new(&empty_repository, &client).await;
combine(&mut result, &repository2_result);

let mut service = noop_service();
// Add a UUID to the service name to circumvent the package cache
service.name.push_str(&format!("-{}", Uuid::new_v4()));

let repository_with_service = StackableRepository {
name: String::from("3-repository-with-service"),
packages: vec![service.clone()],
};
let repository3_result =
StackableRepositoryInstance::new(&repository_with_service, &client).await;
combine(&mut result, &repository3_result);

let pod_result = client
.create::<Pod>(&service.pod_spec("agent-service-integration-test-repository"))
.await;
combine(&mut result, &pod_result);

// Verify that the pod was downloaded, started, and is ready

if let Ok(pod) = &pod_result {
let pod_ready = client.verify_pod_condition(&pod, "Ready").await;
combine(&mut result, &pod_ready);
}

// Tear down pod and repositories

if let Ok(pod) = pod_result {
let deletion_result = client.delete(pod).await;
combine(&mut result, &deletion_result);
}
if let Ok(repository3) = repository3_result {
let close_result = repository3.close(&client).await;
combine(&mut result, &close_result);
}
if let Ok(repository2) = repository2_result {
let close_result = repository2.close(&client).await;
combine(&mut result, &close_result);
}
if let Ok(repository1) = repository1_result {
let close_result = client.delete(repository1).await;
combine(&mut result, &close_result);
}
if let Ok(repository0) = repository0_result {
let close_result = client.delete(repository0).await;
combine(&mut result, &close_result);
}

// Return test result

result
}

/// Applies the AND operation to the given results
///
/// If `result` contains already an error then `other_result` is
/// ignored else if `other_result` contains an error then it is applied
/// on `result`.
fn combine<T, E>(result: &mut Result<()>, other_result: &Result<T, E>)
where
E: Debug,
{
if result.is_ok() {
if let Err(error) = other_result {
*result = Err(anyhow!("{:?}", error))
}
}
}
59 changes: 37 additions & 22 deletions tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ fn service_should_be_started_successfully() {

let pod = TemporaryResource::new(
&client,
&with_unique_name(indoc! {"
&with_unique_name(indoc!(
"
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -21,11 +22,14 @@ fn service_should_be_started_successfully() {
image: noop-service:1.0.0
command:
- noop-service-1.0.0/start.sh
nodeSelector:
kubernetes.io/arch: stackable-linux
tolerations:
- key: kubernetes.io/arch
operator: Equal
value: stackable-linux
"}),
"
)),
);

client.verify_pod_condition(&pod, "Ready");
Expand All @@ -39,7 +43,8 @@ fn host_ip_and_node_ip_should_be_set() {

let pod = TemporaryResource::new(
&client,
&with_unique_name(indoc! {"
&with_unique_name(indoc!(
"
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -50,11 +55,14 @@ fn host_ip_and_node_ip_should_be_set() {
image: noop-service:1.0.0
command:
- noop-service-1.0.0/start.sh
nodeSelector:
kubernetes.io/arch: stackable-linux
tolerations:
- key: kubernetes.io/arch
operator: Equal
value: stackable-linux
"}),
"
)),
);

let are_host_ip_and_node_ip_set = |pod: &Pod| {
Expand Down Expand Up @@ -85,7 +93,8 @@ fn restart_after_ungraceful_shutdown_should_succeed() {

setup_repository(&client);

let pod_spec = with_unique_name(&formatdoc! {"
let pod_spec = with_unique_name(&formatdoc!(
"
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -96,12 +105,16 @@ fn restart_after_ungraceful_shutdown_should_succeed() {
image: nostop-service:1.0.1
command:
- nostop-service-1.0.1/start.sh
nodeSelector:
kubernetes.io/arch: stackable-linux
tolerations:
- key: kubernetes.io/arch
operator: Equal
value: stackable-linux
terminationGracePeriodSeconds: {termination_grace_period_seconds}
", termination_grace_period_seconds = termination_grace_period.as_secs()});
",
termination_grace_period_seconds = termination_grace_period.as_secs()
));

for _ in 1..=2 {
let pod = TemporaryResource::new(&client, &pod_spec);
Expand Down Expand Up @@ -148,23 +161,25 @@ async fn starting_and_stopping_100_pods_simultaneously_should_succeed() {
node_name = node_name
);

let pod_spec = format!(
let pod_spec = formatdoc!(
"
apiVersion: v1
kind: Pod
metadata:
name: agent-service-integration-test-race-condition
spec:
containers:
- name: noop-service
image: noop-service:1.0.0
command:
- noop-service-1.0.0/start.sh
tolerations:
- key: kubernetes.io/arch
operator: Equal
value: stackable-linux
nodeName: {node_name}
apiVersion: v1
kind: Pod
metadata:
name: agent-service-integration-test-race-condition
spec:
containers:
- name: noop-service
image: noop-service:1.0.0
command:
- noop-service-1.0.0/start.sh
nodeSelector:
kubernetes.io/arch: stackable-linux
tolerations:
- key: kubernetes.io/arch
operator: Equal
value: stackable-linux
nodeName: {node_name}
",
node_name = node_name
);
Expand Down
3 changes: 3 additions & 0 deletions tests/util/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod repository;
pub mod services;
pub mod test_package;
Loading