Skip to content

Commit

Permalink
test: add invalid shared tests
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Townsend <[email protected]>
  • Loading branch information
brooksmtownsend committed Sep 25, 2024
1 parent cbb8c30 commit 4c9883e
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 33 deletions.
73 changes: 41 additions & 32 deletions crates/wadm/src/scaler/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,22 @@ fn provider_scalers<S, P, L>(

let mut scaler_specified = false;
scalers.extend(traits.unwrap_or(&EMPTY_TRAIT_VEC).iter().filter_map(|trt| {
// TODO: properties.image to check for shared?
match (trt.trait_type.as_str(), &trt.properties) {
(SPREADSCALER_TRAIT, TraitProperty::SpreadScaler(p)) => {
match (trt.trait_type.as_str(), &trt.properties, &properties.image) {
// Shared application components already have their own spread/daemon scalers, you
// cannot modify them from another manifest
(SPREADSCALER_TRAIT, TraitProperty::SpreadScaler(_), None) => {
warn!(
"Unsupported SpreadScaler trait specified for a shared provider {component_name}"
);
None
}
(DAEMONSCALER_TRAIT, TraitProperty::SpreadScaler(_), None) => {
warn!(
"Unsupported DaemonScaler trait specified for a shared provider {component_name}"
);
None
}
(SPREADSCALER_TRAIT, TraitProperty::SpreadScaler(p), Some(image)) => {
scaler_specified = true;
let (config_scalers, mut config_names) =
config_to_scalers(snapshot_data, application_name, &properties.config);
Expand All @@ -358,31 +371,29 @@ fn provider_scalers<S, P, L>(
);
config_names.append(&mut secret_names.clone());

properties.image.as_ref().map(|image| {
Box::new(BackoffWrapper::new(
ProviderSpreadScaler::new(
snapshot_data.clone(),
ProviderSpreadConfig {
lattice_id: lattice_id.to_owned(),
provider_id: provider_id.to_owned(),
provider_reference: image.to_owned(),
spread_config: p.to_owned(),
model_name: application_name.to_owned(),
provider_config: config_names,
},
component_name,
),
notifier.clone(),
config_scalers,
secret_scalers,
notifier_subject,
application_name,
// Providers are a bit longer because it can take a bit to download
Some(Duration::from_secs(60)),
)) as BoxedScaler
})
Some(Box::new(BackoffWrapper::new(
ProviderSpreadScaler::new(
snapshot_data.clone(),
ProviderSpreadConfig {
lattice_id: lattice_id.to_owned(),
provider_id: provider_id.to_owned(),
provider_reference: image.to_owned(),
spread_config: p.to_owned(),
model_name: application_name.to_owned(),
provider_config: config_names,
},
component_name,
),
notifier.clone(),
config_scalers,
secret_scalers,
notifier_subject,
application_name,
// Providers are a bit longer because it can take a bit to download
Some(Duration::from_secs(60)),
)) as BoxedScaler)
}
(DAEMONSCALER_TRAIT, TraitProperty::SpreadScaler(p)) => {
(DAEMONSCALER_TRAIT, TraitProperty::SpreadScaler(p), Some(image)) => {
scaler_specified = true;
let (config_scalers, mut config_names) =
config_to_scalers(snapshot_data, application_name, &properties.config);
Expand All @@ -393,8 +404,7 @@ fn provider_scalers<S, P, L>(
policies,
);
config_names.append(&mut secret_names.clone());
properties.image.as_ref().map(|image| {
Box::new(BackoffWrapper::new(
Some(Box::new(BackoffWrapper::new(
ProviderDaemonScaler::new(
snapshot_data.clone(),
ProviderSpreadConfig {
Expand All @@ -414,11 +424,10 @@ fn provider_scalers<S, P, L>(
application_name,
// Providers are a bit longer because it can take a bit to download
Some(Duration::from_secs(60)),
)) as BoxedScaler
})
)) as BoxedScaler)
}
// Find the target component of the link and create a scaler for it.
(LINK_TRAIT, TraitProperty::Link(p)) => {
(LINK_TRAIT, TraitProperty::Link(p), _) => {
components
.iter()
.find_map(|component| match &component.properties {
Expand Down
67 changes: 66 additions & 1 deletion tests/e2e_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ use crate::{
helpers::{HELLO_IMAGE_REF, HTTP_SERVER_IMAGE_REF},
};

const MANIFESTS_PATH: &str = "tests/fixtures/manifests";
const MANIFESTS_PATH: &str = "tests/fixtures/manifests/shared";
const DOCKER_COMPOSE_FILE: &str = "tests/docker-compose-e2e-shared.yaml";

const SHARED_COMPONENTS_LATTICE: &str = "shared_components";
const SHARED_PROVIDERS_LATTICE: &str = "shared_providers";
const INVALID_TEST_LATTICE: &str = "shared_invalid";

#[cfg(feature = "_e2e_tests")]
#[tokio::test(flavor = "multi_thread")]
Expand All @@ -42,6 +43,8 @@ async fn run_shared_component_tests() {
.add_ctl_client(SHARED_PROVIDERS_LATTICE, None)
.await;
client_info.add_wadm_client(SHARED_PROVIDERS_LATTICE).await;
client_info.add_ctl_client(INVALID_TEST_LATTICE, None).await;
client_info.add_wadm_client(INVALID_TEST_LATTICE).await;
client_info.launch_wadm().await;

// Wait for the first event on the lattice prefix before we start deploying and checking
Expand Down Expand Up @@ -107,6 +110,7 @@ async fn run_shared_component_tests() {
let tests = [
test_shared_providers(&client_info).boxed(),
test_shared_components(&client_info).boxed(),
test_invalid_shared(&client_info).boxed(),
];
futures::future::join_all(tests).await;
}
Expand Down Expand Up @@ -249,6 +253,16 @@ async fn test_shared_providers(client_info: &ClientInfo) {
.await
.unwrap();

// TODO(#381): Additional validation tests coming in a follow-up PR
// // You can't undeploy an application that is depended on
// assert!(client.undeploy_manifest("shared-http").await.is_err());
// assert!(client.delete_manifest("shared-http", None).await.is_err());

// // Once dependent application is undeployed, you can undeploy and delete
// assert!(client.undeploy_manifest("shared-http-dev").await.is_ok());
// assert!(client.undeploy_manifest("shared-http").await.is_ok());
// assert!(client.delete_manifest("shared-http", None).await.is_ok());

Ok(())
})
.await;
Expand Down Expand Up @@ -410,3 +424,54 @@ async fn test_shared_components(client_info: &ClientInfo) {
})
.await;
}

async fn test_invalid_shared(client_info: &ClientInfo) {
let client = client_info.wadm_client(INVALID_TEST_LATTICE);

// Including `image` and `application` is not supported
assert!(client
.put_manifest(client_info.load_raw_manifest("both_properties.yaml").await)
.await
.is_err());
// Must include `image` or `application`
assert!(client
.put_manifest(client_info.load_raw_manifest("no_properties.yaml").await)
.await
.is_err());

// If the app or component is mismatched, should warn at put time
// and fail to deploy
let (name, _version) = client
.put_manifest(client_info.load_raw_manifest("no_matching_app.yaml").await)
.await
.expect("Shouldn't have errored when creating manifest");
assert!(client.deploy_manifest(&name, None).await.is_err());
let (name, _version) = client
.put_manifest(
client_info
.load_raw_manifest("no_matching_component.yaml")
.await,
)
.await
.expect("Shouldn't have errored when creating manifest");
assert!(client.deploy_manifest(&name, None).await.is_err());

// Deploy manifest, but not shared, and another app that depends on it, which should fail
let (name, _version) = client
.put_manifest(client_info.load_raw_manifest("notshared_http.yaml").await)
.await
.expect("Shouldn't have errored when creating manifest");
client
.deploy_manifest(&name, None)
.await
.expect("Shouldn't have errored when deploying manifest");
let (name, _version) = client
.put_manifest(
client_info
.load_raw_manifest("notshared_http_dev.yaml")
.await,
)
.await
.expect("Shouldn't have errored when creating manifest");
assert!(client.deploy_manifest(&name, None).await.is_err());
}
15 changes: 15 additions & 0 deletions tests/fixtures/manifests/shared/both_properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: both-props
annotations:
description: 'Contains a component with image and application'
spec:
components:
- name: httpserver
type: capability
properties:
image: pull-from-me
application:
name: wheee
component: httpserver
35 changes: 35 additions & 0 deletions tests/fixtures/manifests/shared/no_matching_app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: some-nonexistant-app
annotations:
description: 'Manifest that refers to a nonexistant app'
spec:
components:
- name: hello
type: component
properties:
image: ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0
traits:
- type: spreadscaler
properties:
instances: 12
- name: httpserver
type: capability
properties:
application:
name: some-nonexistant-app
component: httpserver
traits:
- type: link
properties:
namespace: wasi
package: http
interfaces: [incoming-handler]
target:
name: hello
source:
config:
- name: httpaddr
properties:
address: 0.0.0.0:8080
35 changes: 35 additions & 0 deletions tests/fixtures/manifests/shared/no_matching_component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: no-matching-component
annotations:
description: 'Manifest that refers to a nonexistant component'
spec:
components:
- name: hello
type: component
properties:
image: ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0
traits:
- type: spreadscaler
properties:
instances: 12
- name: httpserver
type: capability
properties:
application:
name: shared-http
component: some-nonexistant-component
traits:
- type: link
properties:
namespace: wasi
package: http
interfaces: [incoming-handler]
target:
name: hello
source:
config:
- name: httpaddr
properties:
address: 0.0.0.0:8080
15 changes: 15 additions & 0 deletions tests/fixtures/manifests/shared/no_properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: no-props
annotations:
description: 'Contains a component with neither image and application'
spec:
components:
- name: httpserver
type: capability
properties:
config:
- name: log
properties:
level: info
16 changes: 16 additions & 0 deletions tests/fixtures/manifests/shared/notshared_http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: not-shared-http
annotations:
description: 'My Precious! O my Precious! We needs it. Must have the precious. They stole it from us'
spec:
components:
- name: httpserver
type: capability
properties:
image: ghcr.io/wasmcloud/http-server:0.23.0
traits:
- type: spreadscaler
properties:
instances: 1
35 changes: 35 additions & 0 deletions tests/fixtures/manifests/shared/notshared_http_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: not-shared-http-dev
annotations:
description: 'A Hello World app that tries to use a not shared component'
spec:
components:
- name: hello
type: component
properties:
image: ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0
traits:
- type: spreadscaler
properties:
instances: 12
- name: httpserver
type: capability
properties:
application:
name: not-shared-http
component: httpserver
traits:
- type: link
properties:
namespace: wasi
package: http
interfaces: [incoming-handler]
target:
name: hello
source:
config:
- name: httpaddr
properties:
address: 0.0.0.0:8080
File renamed without changes.

0 comments on commit 4c9883e

Please sign in to comment.