-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add method to provision more empty canisters and refactor (#415)
* add method to provision more empty canisters and refactor * fix test
- Loading branch information
1 parent
d5432bc
commit b234455
Showing
13 changed files
with
227 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...latform_orchestrator/src/api/canister_management/provision_empty_canisters_in_a_subnet.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use candid::Principal; | ||
use ic_cdk_macros::update; | ||
|
||
use crate::{ | ||
guard::is_caller::is_caller_global_admin_or_controller, | ||
utils::registered_subnet_orchestrator::RegisteredSubnetOrchestrator, | ||
}; | ||
|
||
#[update(guard = "is_caller_global_admin_or_controller")] | ||
async fn provision_empty_canisters_in_a_subnet( | ||
subnet_orchestrator_canister_id: Principal, | ||
number_of_canisters: u64, | ||
) -> Result<(), String> { | ||
let registered_subnet_orchestrator = | ||
RegisteredSubnetOrchestrator::new(subnet_orchestrator_canister_id)?; | ||
registered_subnet_orchestrator | ||
.provision_empty_canisters(number_of_canisters) | ||
.await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/canister/user_index/src/api/canister_management/provision_empty_canisters.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use ic_cdk_macros::update; | ||
use shared_utils::common::utils::permissions::is_caller_controller; | ||
|
||
use crate::util::canister_management::provision_number_of_empty_canisters; | ||
|
||
#[update(guard = "is_caller_controller")] | ||
async fn provision_empty_canisters(number_of_canisters: u64) { | ||
ic_cdk::spawn(provision_number_of_empty_canisters( | ||
number_of_canisters, | ||
|| false, | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
pub mod get_user_index_canister_cycle_balance; | ||
pub mod reclaim_cycles_from_individual_canisters; | ||
pub mod return_cycles_to_platform_orchestrator_canister; | ||
pub mod return_cycles_to_platform_orchestrator_canister; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...tegration_tests/tests/platform_orchestrator/provision_empty_canisters_in_a_subnet_test.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
use candid::{encode_args, encode_one, Principal}; | ||
use pocket_ic::WasmResult; | ||
use shared_utils::{ | ||
common::types::known_principal::KnownPrincipalType, | ||
constant::TEST_BACKUP_INDIVIDUAL_USER_CANISTER_BATCH_SIZE, | ||
}; | ||
use test_utils::setup::{ | ||
env::pocket_ic_env::get_new_pocket_ic_env, test_constants::get_mock_user_charlie_principal_id, | ||
}; | ||
|
||
#[test] | ||
fn provision_empty_canisters_in_a_subnet_test() { | ||
let (pocket_ic, known_principal) = get_new_pocket_ic_env(); | ||
let platform_canister_id = known_principal | ||
.get(&KnownPrincipalType::CanisterIdPlatformOrchestrator) | ||
.cloned() | ||
.unwrap(); | ||
|
||
let super_admin = known_principal | ||
.get(&KnownPrincipalType::UserIdGlobalSuperAdmin) | ||
.cloned() | ||
.unwrap(); | ||
|
||
let application_subnets = pocket_ic.topology().get_app_subnets(); | ||
|
||
let charlie_global_admin = get_mock_user_charlie_principal_id(); | ||
|
||
pocket_ic | ||
.update_call( | ||
platform_canister_id, | ||
super_admin, | ||
"add_principal_as_global_admin", | ||
candid::encode_one(charlie_global_admin).unwrap(), | ||
) | ||
.unwrap(); | ||
|
||
let subnet_orchestrator_canister_id: Principal = pocket_ic | ||
.update_call( | ||
platform_canister_id, | ||
charlie_global_admin, | ||
"provision_subnet_orchestrator_canister", | ||
candid::encode_one(application_subnets[0]).unwrap(), | ||
) | ||
.map(|res| { | ||
let canister_id_result: Result<Principal, String> = match res { | ||
WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), | ||
_ => panic!("Canister call failed"), | ||
}; | ||
canister_id_result.unwrap() | ||
}) | ||
.unwrap(); | ||
|
||
for i in 0..110 { | ||
pocket_ic.tick(); | ||
} | ||
|
||
let empty_canisters_cnt = pocket_ic | ||
.query_call( | ||
subnet_orchestrator_canister_id, | ||
super_admin, | ||
"get_subnet_backup_capacity", | ||
encode_one(()).unwrap(), | ||
) | ||
.map(|reply_payload| { | ||
let subnet_capacity: u64 = match reply_payload { | ||
WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), | ||
_ => panic!("\n🛑 get_subnet_backup_capacity failed\n"), | ||
}; | ||
subnet_capacity | ||
}) | ||
.unwrap(); | ||
|
||
assert_eq!( | ||
empty_canisters_cnt, | ||
TEST_BACKUP_INDIVIDUAL_USER_CANISTER_BATCH_SIZE | ||
); | ||
|
||
pocket_ic | ||
.update_call( | ||
platform_canister_id, | ||
charlie_global_admin, | ||
"provision_empty_canisters_in_a_subnet", | ||
encode_args((subnet_orchestrator_canister_id, 100_u64)).unwrap(), | ||
) | ||
.map(|reply_payload| { | ||
let res: Result<(), String> = match reply_payload { | ||
WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), | ||
_ => panic!("\n🛑 provision_empty_canisters_in_a_subnet failed\n"), | ||
}; | ||
res | ||
}) | ||
.unwrap() | ||
.unwrap(); | ||
|
||
for _ in 0..110 { | ||
pocket_ic.tick(); | ||
} | ||
|
||
let empty_canisters_cnt = pocket_ic | ||
.query_call( | ||
subnet_orchestrator_canister_id, | ||
super_admin, | ||
"get_subnet_backup_capacity", | ||
encode_one(()).unwrap(), | ||
) | ||
.map(|reply_payload| { | ||
let subnet_capacity: u64 = match reply_payload { | ||
WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), | ||
_ => panic!("\n🛑 get_subnet_backup_capacity failed\n"), | ||
}; | ||
subnet_capacity | ||
}) | ||
.unwrap(); | ||
|
||
assert_eq!( | ||
empty_canisters_cnt, | ||
TEST_BACKUP_INDIVIDUAL_USER_CANISTER_BATCH_SIZE + 100 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters