Skip to content

Commit 1d8189b

Browse files
authored
Merge pull request #582 from diconico07/improve-udev-handler-tests
udev: Improve testability and tests
2 parents 54923fb + cffeba6 commit 1d8189b

File tree

20 files changed

+148
-51
lines changed

20 files changed

+148
-51
lines changed

.github/workflows/run-test-cases.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ jobs:
192192
run: |
193193
sudo apt-get update -y
194194
sudo apt-get install -y apt-transport-https ca-certificates curl
195-
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
195+
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://dl.k8s.io/apt/doc/apt-key.gpg
196196
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
197197
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
198198
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list

Cargo.lock

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "agent"
3-
version = "0.10.5"
3+
version = "0.10.6"
44
authors = ["Kate Goldenring <kate.goldenring@microsoft.com>", "<bfjelds@microsoft.com>"]
55
edition = "2018"
66
rust-version = "1.68.1"

controller/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "controller"
3-
version = "0.10.5"
3+
version = "0.10.6"
44
authors = ["<bfjelds@microsoft.com>", "<kagold@microsoft.com>"]
55
edition = "2018"
66
rust-version = "1.68.1"

deployment/helm/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.10.5
18+
version: 0.10.6
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
23-
appVersion: 0.10.5
23+
appVersion: 0.10.6

discovery-handler-modules/debug-echo-discovery-handler/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "debug-echo-discovery-handler"
3-
version = "0.10.5"
3+
version = "0.10.6"
44
authors = ["Kate Goldenring <kate.goldenring@microsoft.com>"]
55
edition = "2018"
66
rust-version = "1.68.1"

discovery-handler-modules/onvif-discovery-handler/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "onvif-discovery-handler"
3-
version = "0.10.5"
3+
version = "0.10.6"
44
authors = ["Kate Goldenring <kate.goldenring@microsoft.com>"]
55
edition = "2018"
66
rust-version = "1.68.1"

discovery-handler-modules/opcua-discovery-handler/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "opcua-discovery-handler"
3-
version = "0.10.5"
3+
version = "0.10.6"
44
authors = ["Kate Goldenring <kate.goldenring@microsoft.com>"]
55
edition = "2018"
66
rust-version = "1.68.1"

discovery-handler-modules/udev-discovery-handler/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "udev-discovery-handler"
3-
version = "0.10.5"
3+
version = "0.10.6"
44
authors = ["Kate Goldenring <kate.goldenring@microsoft.com>"]
55
edition = "2018"
66
rust-version = "1.68.1"

discovery-handlers/debug-echo/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "akri-debug-echo"
3-
version = "0.10.5"
3+
version = "0.10.6"
44
authors = ["Kate Goldenring <kate.goldenring@microsoft.com>"]
55
edition = "2018"
66
rust-version = "1.68.1"

discovery-handlers/onvif/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "akri-onvif"
3-
version = "0.10.5"
3+
version = "0.10.6"
44
authors = ["Kate Goldenring <kate.goldenring@microsoft.com>"]
55
edition = "2018"
66
rust-version = "1.68.1"

discovery-handlers/opcua/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "akri-opcua"
3-
version = "0.10.5"
3+
version = "0.10.6"
44
authors = ["Kate Goldenring <kate.goldenring@microsoft.com>"]
55
edition = "2018"
66
rust-version = "1.68.1"

discovery-handlers/udev/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "akri-udev"
3-
version = "0.10.5"
3+
version = "0.10.6"
44
authors = ["Kate Goldenring <kate.goldenring@microsoft.com>"]
55
edition = "2018"
66
rust-version = "1.68.1"

discovery-handlers/udev/src/discovery_handler.rs

+5-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{
2-
discovery_impl::{do_parse_and_find, get_device_relatives, DeviceProperties},
2+
discovery_impl::{do_parse_and_find, insert_device_with_relatives, DeviceProperties},
33
wrappers::udev_enumerator,
44
};
55
use akri_discovery_utils::discovery::{
@@ -12,7 +12,7 @@ use akri_discovery_utils::discovery::{
1212
};
1313
use async_trait::async_trait;
1414
use log::{error, info, trace};
15-
use std::collections::HashMap;
15+
use std::collections::{HashMap, HashSet};
1616
use std::time::Duration;
1717
use tokio::sync::mpsc;
1818
use tokio::time::sleep;
@@ -71,28 +71,15 @@ impl DiscoveryHandler for DiscoveryHandlerImpl {
7171
}
7272
break;
7373
}
74-
let mut devpaths: HashMap<String, Vec<DeviceProperties>> = HashMap::new();
74+
let mut devpaths: HashMap<String, HashSet<DeviceProperties>> = HashMap::new();
7575
udev_rules.iter().for_each(|rule| {
7676
let enumerator = udev_enumerator::create_enumerator();
7777
let paths = do_parse_and_find(enumerator, rule).unwrap();
7878
for path in paths.into_iter() {
7979
if !discovery_handler_config.group_recursive {
80-
devpaths.insert(path.0.clone(), vec![path]);
80+
devpaths.insert(path.0.clone(), HashSet::from([path]));
8181
} else {
82-
match get_device_relatives(&path.0, devpaths.keys()) {
83-
(Some(parent), _) => devpaths.get_mut(&parent).unwrap().push(path),
84-
(None, children) => {
85-
let id = path.0.clone();
86-
let mut children_devices: Vec<DeviceProperties> = children
87-
.into_iter()
88-
.flat_map(|child| {
89-
devpaths.remove(&child).unwrap().into_iter()
90-
})
91-
.collect();
92-
children_devices.push(path);
93-
let _ = devpaths.insert(id, children_devices);
94-
}
95-
}
82+
insert_device_with_relatives(&mut devpaths, path);
9683
}
9784
}
9885
});

0 commit comments

Comments
 (0)