Skip to content

Commit 32ed2d6

Browse files
authored
Merge pull request #115 from Synicix/pod_model_hash
Update pod hashing to remove non-replication concerns from hash
2 parents 49a79b0 + 8365fda commit 32ed2d6

File tree

16 files changed

+264
-218
lines changed

16 files changed

+264
-218
lines changed

.github/workflows/tests.yaml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install code coverage
2323
uses: taiki-e/install-action@cargo-llvm-cov
2424
- name: Run syntax and style tests
25-
run: cargo clippy --no-default-features --features=test --all-targets -- -D warnings
25+
run: cargo clippy --all-targets -- -D warnings
2626
- name: Run format test
2727
run: cargo fmt --check
2828
- name: Run integration tests w/ coverage report
@@ -57,15 +57,11 @@ jobs:
5757
uv pip install eclipse-zenoh -p ~/.local/share/base
5858
. ~/.local/share/base/bin/activate
5959
maturin develop --uv
60-
- name: Run smoke test
60+
- name: Run Python tests
6161
env:
6262
RUST_BACKTRACE: full
6363
run: |
6464
. ~/.local/share/base/bin/activate
65-
python tests/extra/python/smoke_test.py -- tests/.tmp
66-
- name: Run agent test
67-
env:
68-
RUST_BACKTRACE: full
69-
run: |
70-
. ~/.local/share/base/bin/activate
71-
python tests/extra/python/agent_test.py -- tests/.tmp
65+
for py_file in tests/extra/python/*.py; do
66+
python "$py_file" -- tests/.tmp
67+
done

notebook.ipynb

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/core/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl fmt::Debug for OrcaError {
121121
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
122122
match &self.kind {
123123
Kind::AgentCommunicationFailure { backtrace, .. }
124+
| Kind::EmptyDir { backtrace, .. }
124125
| Kind::FailedToStartPod { backtrace, .. }
125126
| Kind::FailedToExtractRunInfo { backtrace, .. }
126127
| Kind::IncompletePacket { backtrace, .. }

src/core/model/mod.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,33 @@ use std::{
88
hash::BuildHasher,
99
result,
1010
};
11-
/// Converts a model instance into a consistent yaml.
12-
///
13-
/// # Errors
14-
///
15-
/// Will return `Err` if there is an issue converting an `instance` into YAML (w/o annotation).
16-
pub fn to_yaml<T: Serialize>(instance: &T) -> Result<String> {
17-
let mapping: IndexMap<String, Value> = serde_yaml::from_str(&serde_yaml::to_string(instance)?)?; // cast to map
18-
let mut yaml = serde_yaml::to_string(
19-
&mapping
20-
.iter()
21-
.filter_map(|(k, v)| match &**k {
22-
"annotation" | "hash" => None,
23-
"pod" | "pod_job" => Some((k, v["hash"].clone())),
24-
_ => Some((k, v.clone())),
25-
})
26-
.collect::<IndexMap<_, _>>(),
27-
)?; // skip fields and convert refs to hash pointers
28-
yaml.insert_str(
29-
0,
30-
&format!("class: {}\n", get_type_name::<T>().to_snake_case()),
31-
); // replace class at top
32-
Ok(yaml)
11+
12+
/// Trait to handle serialization to yaml for `OrcaPod` models
13+
pub trait ToYaml: Serialize + Sized {
14+
/// Serializes the instance to a YAML string.
15+
/// # Errors
16+
/// Will return `Err` if it fail to serialize instance to string
17+
fn to_yaml(&self) -> Result<String> {
18+
let mapping: IndexMap<String, Value> = serde_yaml::from_str(&serde_yaml::to_string(self)?)?; // cast to map
19+
let mut yaml = serde_yaml::to_string(
20+
&mapping
21+
.iter()
22+
.filter_map(|(k, v)| Self::process_field(k, v))
23+
.collect::<IndexMap<_, _>>(),
24+
)?; // skip fields and convert refs to hash pointers
25+
yaml.insert_str(
26+
0,
27+
&format!("class: {}\n", get_type_name::<Self>().to_snake_case()),
28+
); // replace class at top
29+
Ok(yaml)
30+
}
31+
32+
/// Filter out which field to serialize and which to omit
33+
///
34+
/// # Returns
35+
/// (`field_name`, `field_value`): to be pass to `to_yaml` for serialization
36+
/// None: to skip
37+
fn process_field(field_name: &str, field_value: &Value) -> Option<(String, Value)>;
3338
}
3439

3540
pub(crate) fn serialize_hashmap<S, K: Ord + Serialize, V: Serialize, BH: BuildHasher>(

src/core/pipeline_runner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,8 @@ impl PodProcessor {
653653
)
654654
.into(),
655655
},
656-
pod.recommended_cpus,
657-
pod.recommended_memory,
656+
pod.recommend_specs.cpus,
657+
pod.recommend_specs.memory,
658658
None,
659659
&pipeline_run.namespace_lookup,
660660
)?;

src/core/store/filestore.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
core::{
3-
model::to_yaml,
3+
model::ToYaml,
44
store::MODEL_NAMESPACE,
55
util::{get_type_name, parse_debug_name},
66
},
@@ -111,7 +111,7 @@ impl LocalFileStore {
111111
Ok(model_info.hash)
112112
}
113113

114-
fn save_file(file: impl AsRef<Path>, content: impl AsRef<[u8]>) -> Result<()> {
114+
pub(crate) fn save_file(file: impl AsRef<Path>, content: impl AsRef<[u8]>) -> Result<()> {
115115
if let Some(parent) = file.as_ref().parent() {
116116
fs::create_dir_all(parent)?;
117117
}
@@ -123,7 +123,7 @@ impl LocalFileStore {
123123
/// # Errors
124124
///
125125
/// Will return `Err` if there is an issue storing the model.
126-
pub(crate) fn save_model<T: Serialize + fmt::Debug>(
126+
pub(crate) fn save_model<T: Serialize + fmt::Debug + ToYaml>(
127127
&self,
128128
model: &T,
129129
hash: &str,
@@ -174,7 +174,7 @@ impl LocalFileStore {
174174
.yellow(),
175175
);
176176
} else {
177-
Self::save_file(spec_file, to_yaml(model)?)?;
177+
Self::save_file(spec_file, model.to_yaml()?)?;
178178
}
179179
Ok(())
180180
}

src/uniffi/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ pub(crate) enum Kind {
3131
source: Box<dyn Error + Send + Sync>,
3232
backtrace: Option<Backtrace>,
3333
},
34+
#[snafu(display("Empty directory: {dir:?}, where they should be files"))]
35+
EmptyDir {
36+
dir: PathBuf,
37+
backtrace: Option<Backtrace>,
38+
},
3439
#[snafu(display(
3540
"Failed to extract run info from the container image file: {container_name}."
3641
))]

0 commit comments

Comments
 (0)