Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zombienet-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
zombienet-sdk
Commits
6eb6cb20
Unverified
Commit
6eb6cb20
authored
9 months ago
by
Javier Viola
Committed by
GitHub
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: add environment helper (#230)
parent
69cb0eac
Branches
Branches containing commit
No related merge requests found
Pipeline
#480611
failed with stage
in 11 minutes and 16 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
crates/sdk/src/environment.rs
+51
-0
51 additions, 0 deletions
crates/sdk/src/environment.rs
crates/sdk/src/lib.rs
+2
-1
2 additions, 1 deletion
crates/sdk/src/lib.rs
crates/sdk/tests/smoke.rs
+3
-23
3 additions, 23 deletions
crates/sdk/tests/smoke.rs
with
56 additions
and
24 deletions
crates/sdk/src/environment.rs
0 → 100644
+
51
−
0
View file @
6eb6cb20
//! Helpers functions to get configuration (e.g. Provider and images) from the env vars
use
std
::{
env
,
future
::
Future
,
pin
::
Pin
};
use
crate
::{
LocalFileSystem
,
Network
,
NetworkConfig
,
NetworkConfigExt
,
OrchestratorError
};
const
DEFAULT_POLKADOT_IMAGE
:
&
str
=
"docker.io/parity/polkadot:latest"
;
const
DEFAULT_CUMULUS_IMAGE
:
&
str
=
"docker.io/parity/polkadot-parachain:latest"
;
#[derive(Debug,
Default)]
pub
struct
Images
{
pub
polkadot
:
String
,
pub
cumulus
:
String
,
}
pub
enum
Provider
{
Native
,
K8s
,
Docker
,
}
// Use `docker` as default provider
impl
From
<
String
>
for
Provider
{
fn
from
(
value
:
String
)
->
Self
{
match
value
.to_ascii_lowercase
()
.as_ref
()
{
"native"
=>
Provider
::
Native
,
"k8s"
=>
Provider
::
K8s
,
_
=>
Provider
::
Docker
,
// default provider
}
}
}
pub
fn
get_images_from_env
()
->
Images
{
let
polkadot
=
env
::
var
(
"POLKADOT_IMAGE"
)
.unwrap_or
(
DEFAULT_POLKADOT_IMAGE
.into
());
let
cumulus
=
env
::
var
(
"CUMULUS_IMAGE"
)
.unwrap_or
(
DEFAULT_CUMULUS_IMAGE
.into
());
Images
{
polkadot
,
cumulus
}
}
pub
fn
get_provider_from_env
()
->
Provider
{
env
::
var
(
"ZOMBIE_PROVIDER"
)
.unwrap_or_default
()
.into
()
}
pub
type
SpawnResult
=
Result
<
Network
<
LocalFileSystem
>
,
OrchestratorError
>
;
pub
fn
get_spawn_fn
()
->
fn
(
NetworkConfig
)
->
Pin
<
Box
<
dyn
Future
<
Output
=
SpawnResult
>
+
Send
>>
{
let
provider
=
get_provider_from_env
();
match
provider
{
Provider
::
Native
=>
NetworkConfigExt
::
spawn_native
,
Provider
::
K8s
=>
NetworkConfigExt
::
spawn_k8s
,
Provider
::
Docker
=>
NetworkConfigExt
::
spawn_docker
,
}
}
This diff is collapsed.
Click to expand it.
crates/sdk/src/lib.rs
+
2
−
1
View file @
6eb6cb20
...
...
@@ -10,7 +10,8 @@ pub use orchestrator::{
use
provider
::{
DockerProvider
,
KubernetesProvider
,
NativeProvider
};
pub
use
support
::
fs
::
local
::
LocalFileSystem
;
pub
const
PROVIDERS
:
[
&
str
;
2
]
=
[
"k8s"
,
"native"
];
pub
mod
environment
;
pub
const
PROVIDERS
:
[
&
str
;
3
]
=
[
"k8s"
,
"native"
,
"docker"
];
#[async_trait]
pub
trait
NetworkConfigExt
{
...
...
This diff is collapsed.
Click to expand it.
crates/sdk/tests/smoke.rs
+
3
−
23
View file @
6eb6cb20
use
std
::
{
env
,
pin
::
Pin
,
time
::
Instant
}
;
use
std
::
time
::
Instant
;
use
configuration
::{
NetworkConfig
,
NetworkConfigBuilder
};
use
futures
::
{
stream
::
StreamExt
,
Future
}
;
use
futures
::
stream
::
StreamExt
;
use
orchestrator
::{
AddCollatorOptions
,
AddNodeOptions
};
use
serde_json
::
json
;
use
support
::
fs
::
local
::
LocalFileSystem
;
use
zombienet_sdk
::{
Network
,
NetworkConfigExt
,
OrchestratorError
,
PROVIDERS
};
use
zombienet_sdk
::
environment
::
get_spawn_fn
;
fn
small_network
()
->
NetworkConfig
{
NetworkConfigBuilder
::
new
()
...
...
@@ -27,25 +26,6 @@ fn small_network() -> NetworkConfig {
.unwrap
()
}
type
SpawnResult
=
Result
<
Network
<
LocalFileSystem
>
,
OrchestratorError
>
;
fn
get_spawn_fn
()
->
fn
(
NetworkConfig
)
->
Pin
<
Box
<
dyn
Future
<
Output
=
SpawnResult
>
+
Send
>>
{
const
PROVIDER_KEY
:
&
str
=
"ZOMBIE_PROVIDER"
;
let
provider
=
env
::
var
(
PROVIDER_KEY
)
.unwrap_or
(
String
::
from
(
"k8s"
));
assert!
(
PROVIDERS
.contains
(
&
provider
.as_str
()),
"
\n
❌ Invalid provider, available options {}
\n
"
,
PROVIDERS
.join
(
", "
)
);
// TODO: revisit this
if
provider
==
"k8s"
{
zombienet_sdk
::
NetworkConfig
::
spawn_k8s
}
else
{
zombienet_sdk
::
NetworkConfig
::
spawn_native
}
}
#[tokio::test(flavor
=
"multi_thread"
)]
async
fn
ci_k8s_basic_functionalities_should_works
()
{
tracing_subscriber
::
fmt
::
init
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment