diff --git a/Cargo.lock b/Cargo.lock index 47867dc2..4f01519f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2626,6 +2626,7 @@ dependencies = [ "env_logger", "qovery-engine", "rand 0.7.3", + "reqwest 0.10.8", "serde", "serde_derive", "serde_json", diff --git a/src/transaction.rs b/src/transaction.rs index 75e5fe04..10c85ad3 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -497,6 +497,37 @@ impl<'a> Transaction<'a> { let applications = apps_result.ok().unwrap(); applications_by_environment.insert(target_environment, applications); + + // build ad well the failover environment, retention could remove the application image + match environment_action { + EnvironmentAction::EnvironmentWithFailover(_, fe) => { + let apps_result = match self._build_applications(fe, option) { + Ok(applications) => { + match self._push_applications(applications, option) { + Ok(results) => { + let applications = results + .into_iter() + .map(|(app, _)| app) + .collect::>(); + + Ok(applications) + } + Err(err) => Err(err), + } + } + Err(err) => Err(err), + }; + if apps_result.is_err() { + // should never be triggered because core always should ask for working failover environment + let commit_error = apps_result.err().unwrap(); + error!( + "An error occurred on failover application {:?}", + commit_error + ); + } + } + _ => {} + }; } Step::DeployEnvironment(kubernetes, environment_action) => { // deploy complete environment diff --git a/test_utilities/Cargo.toml b/test_utilities/Cargo.toml index c534ce93..92211dbc 100644 --- a/test_utilities/Cargo.toml +++ b/test_utilities/Cargo.toml @@ -16,7 +16,7 @@ serde = "1.0" serde_json = "1.0.57" serde_derive = "1.0" curl = "0.4.34" - +reqwest = { version = "0.10.8", features = ["blocking"] } # Digital Ocean Deps digitalocean = "0.1.1" \ No newline at end of file diff --git a/test_utilities/src/utilities.rs b/test_utilities/src/utilities.rs index dfa6f8b1..e6c68a28 100644 --- a/test_utilities/src/utilities.rs +++ b/test_utilities/src/utilities.rs @@ -1,13 +1,15 @@ -use curl::easy::Easy; use curl::Error; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; use crate::aws::{aws_access_key_id, aws_default_region, aws_secret_access_key, KUBE_CLUSTER_ID}; +use curl::easy::Easy; +use digitalocean::error::Error::ReqwestError; use qovery_engine::build_platform::local_docker::LocalDocker; use qovery_engine::cloud_provider::aws::common; use qovery_engine::cmd; use qovery_engine::models::{Context, Environment}; +use reqwest::StatusCode; pub fn build_platform_local_docker(context: &Context) -> LocalDocker { LocalDocker::new(context.clone(), "oxqlm3r99vwcmvuj", "qovery-local-docker") @@ -103,3 +105,31 @@ pub fn is_pod_restarted(environment_check: Environment, podToCheck: &str) -> (bo Err(e) => return (false, "".to_string()), } } + +// curl it and compare the body result, invalid certs are accepted +pub fn curl_it_and_compare(path: &str, should_return_str: &str) -> Result { + use reqwest::blocking::Client; + let client = Client::builder() + .danger_accept_invalid_certs(true) + .build() + .unwrap(); + + let res = client.get(path).send(); + + match res { + Ok(output) => match output.status() { + StatusCode::OK | StatusCode::PERMANENT_REDIRECT => { + let returned = output.text().unwrap(); + match should_return_str.eq(returned.as_str()) { + true => Ok(true), + false => Ok(false), + } + } + _ => Ok(false), + }, + Err(e) => { + println!("While curl {}: {:?}", path, e); + Err(e) + } + } +} diff --git a/tests/aws/aws_databases.rs b/tests/aws/aws_databases.rs index a2ea5a24..06a23738 100644 --- a/tests/aws/aws_databases.rs +++ b/tests/aws/aws_databases.rs @@ -5,6 +5,7 @@ use rusoto_core::region::Region::Custom; use self::test_utilities::cloudflare::dns_provider_cloudflare; use self::test_utilities::utilities::generate_id; +use crate::aws::aws_environment::{delete_environment, deploy_environment}; use qovery_engine::cloud_provider::aws::common; use qovery_engine::cloud_provider::service::Router; use qovery_engine::cmd; @@ -16,7 +17,6 @@ use qovery_engine::models::{ use qovery_engine::transaction::{DeploymentOption, TransactionResult}; use test_utilities::aws::{aws_access_key_id, aws_default_region, aws_secret_access_key, context}; use test_utilities::utilities::{init, is_pod_restarted}; -use crate::aws::aws_environment::{deploy_environment, delete_environment}; // to check overload between several databases and apps #[test] @@ -58,7 +58,6 @@ fn deploy_an_environment_with_3_databases_and_3_apps() { ** **/ - #[test] #[ignore] fn deploy_a_working_development_environment_with_all_options_and_psql() { @@ -98,7 +97,6 @@ fn deploy_a_working_development_environment_with_all_options_and_psql() { }; } - #[test] fn deploy_a_working_environment_with_postgresql() { init(); @@ -195,7 +193,8 @@ fn deploy_a_working_environment_and_redeploy_with_postgresql() { let mut environment = test_utilities::aws::working_minimal_environment(&context); - let database_host = "postgresql-".to_string() + generate_id().as_str() + ".oom.sh"; // External access check + let database_host = + "postgresql-".to_string() + generate_id().as_str() + ".CHANGE-ME/DEFAULT_TEST_DOMAIN"; // External access check let database_port = 5432; let database_db_name = "my-postgres".to_string(); let database_username = "superuser".to_string(); @@ -487,7 +486,6 @@ fn test_mongodb_configuration(context: Context, mut environment: Environment, ve ** **/ - /// test mongodb v3.6 with development environment #[test] fn deploy_a_working_environment_with_mongodb_v3_6() { @@ -533,14 +531,12 @@ fn deploy_a_working_environment_with_production_mongodb_v3_6() { test_mongodb_configuration(context, environment, "3.6"); } - /** ** ** MySQL PART ** **/ - #[test] #[ignore] fn deploy_a_working_environment_with_mysql() { diff --git a/tests/aws/aws_environment.rs b/tests/aws/aws_environment.rs index 9856220e..35b55dc3 100644 --- a/tests/aws/aws_environment.rs +++ b/tests/aws/aws_environment.rs @@ -15,7 +15,7 @@ use qovery_engine::models::{ }; use qovery_engine::transaction::{DeploymentOption, TransactionResult}; use test_utilities::aws::{aws_access_key_id, aws_default_region, aws_secret_access_key, context}; -use test_utilities::utilities::{init, is_pod_restarted}; +use test_utilities::utilities::{curl_it_and_compare, init, is_pod_restarted}; // insert how many actions you will use in tests // args are function you want to use and how many context you want to have @@ -662,58 +662,60 @@ fn deploy_a_non_working_environment_with_a_working_failover_on_aws_eks() { }; } - #[test] #[ignore] fn deploy_2_non_working_environments_with_2_working_failovers_on_aws_eks() { init(); // context for non working environment let context_failover_1 = context(); - let context_failover_2 = context.clone_not_same_execution_id(); + let context_failover_2 = context_failover_1.clone_not_same_execution_id(); - let context_first_fail_deployement_1 = context.clone_not_same_execution_id(); - let context_second_fail_deployement_2 = context.clone_not_same_execution_id(); + let context_first_fail_deployement_1 = context_failover_1.clone_not_same_execution_id(); + let context_second_fail_deployement_2 = context_failover_1.clone_not_same_execution_id(); let mut failover_environment_1 = test_utilities::aws::echo_app_environment(&context_failover_1); - let mut fail_app_1 = test_utilities::aws::non_working_environment(&context_first_fail_deployement_1); - let mut failover_environment_1 = test_utilities::aws::echo_app_environment(&context_failover_2); - let mut fail_app_2 = test_utilities::aws::non_working_environment(&context_second_fail_deployement_2); + let mut fail_app_1 = + test_utilities::aws::non_working_environment(&context_first_fail_deployement_1); + let mut failover_environment_2 = test_utilities::aws::echo_app_environment(&context_failover_2); + let mut fail_app_2 = + test_utilities::aws::non_working_environment(&context_second_fail_deployement_2); - failover_environment.applications = failover_environment + failover_environment_2.applications = failover_environment_2 .applications .into_iter() - .map(|mut app |{ - app.environment_variables = vec![ - EnvironmentVariable { - key: "ECHO_TEXT".to_string(), - value: "Lilou".to_string(), - }, - ], + .map(|mut app| { + app.environment_variables = vec![EnvironmentVariable { + key: "ECHO_TEXT".to_string(), + value: "Lilou".to_string(), + }]; app }) - .collect::>(); + .collect::>(); // context for deletion - let context_deletion = context.clone_not_same_execution_id(); + let context_deletion = context_failover_1.clone_not_same_execution_id(); let mut delete_env = test_utilities::aws::echo_app_environment(&context_deletion); delete_env.action = Action::Delete; let ea_delete = EnvironmentAction::Environment(delete_env); + let envToCheck = failover_environment_1.clone(); + // first deployement let ea1 = EnvironmentAction::EnvironmentWithFailover(fail_app_1, failover_environment_1); let ea2 = EnvironmentAction::EnvironmentWithFailover(fail_app_2, failover_environment_2); - match deploy_environment(&context_failover_1, &ea1) { TransactionResult::Ok => assert!(false), - TransactionResult::Rollback(_) => assert!(true), - TransactionResult::UnrecoverableError(_, _) => assert!(false), - }; - match deploy_environment(&context_failover_2, &ea2) { - TransactionResult::Ok => assert!(false), - TransactionResult::Rollback(_) => assert!(true), + TransactionResult::Rollback(_) => assert!(false), TransactionResult::UnrecoverableError(_, _) => assert!(true), }; + + match deploy_environment(&context_failover_2, &ea2) { + TransactionResult::Ok => assert!(false), + TransactionResult::Rollback(_) => assert!(false), + TransactionResult::UnrecoverableError(_, _) => assert!(true), + }; + match delete_environment(&context_deletion, &ea_delete) { TransactionResult::Ok => assert!(true), TransactionResult::Rollback(_) => assert!(false), @@ -721,8 +723,6 @@ fn deploy_2_non_working_environments_with_2_working_failovers_on_aws_eks() { }; } - - #[test] #[ignore] fn deploy_a_non_working_environment_with_a_non_working_failover_on_aws_eks() {