Skip to content

Commit

Permalink
Fix test path (#128)
Browse files Browse the repository at this point in the history
* Switch test to use temporary directory

* Fix path usage

* Update version

* Drop test path

* Update version to main+1
  • Loading branch information
jiria authored Nov 16, 2020
1 parent 28a237c commit 3c5f721
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ serde_derive = "1.0.104"
akri-shared = { path = "../shared" }
sxd-document = "0.3.0"
sxd-xpath = "0.4.0"
tempfile = "3.1.0"
tokio = { version = "0.2", features = ["full"] }
tokio-core = "0.1"
tonic = "0.1"
Expand Down
18 changes: 16 additions & 2 deletions agent/src/util/config_action.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::super::protocols;
use super::{
constants::{DISCOVERY_DELAY_SECS, SHARED_INSTANCE_OFFLINE_GRACE_PERIOD_SECS},
constants::{
DEVICE_PLUGIN_PATH, DISCOVERY_DELAY_SECS, SHARED_INSTANCE_OFFLINE_GRACE_PERIOD_SECS,
},
device_plugin_service,
device_plugin_service::{
get_device_instance_name, ConnectivityStatus, InstanceInfo, InstanceMap,
Expand Down Expand Up @@ -184,6 +186,7 @@ async fn handle_config_add(
&kube_interface,
stop_discovery_receiver,
finished_discovery_sender,
DEVICE_PLUGIN_PATH,
)
.await
.unwrap();
Expand Down Expand Up @@ -322,6 +325,7 @@ impl PeriodicDiscovery {
kube_interface: &impl KubeInterface,
mut stop_discovery_receiver: mpsc::Receiver<()>,
finished_discovery_sender: broadcast::Sender<()>,
device_plugin_path: &str,
) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
trace!(
"do_periodic_discovery - start for config {}",
Expand Down Expand Up @@ -373,6 +377,7 @@ impl PeriodicDiscovery {
shared,
instance_properties,
instance_map,
device_plugin_path,
)
.await
{
Expand Down Expand Up @@ -495,6 +500,7 @@ mod config_action_tests {
use akri_shared::k8s::test_kube::MockKubeImpl;
use protocols::debug_echo::{DEBUG_ECHO_AVAILABILITY_CHECK_PATH, OFFLINE};
use std::{env, fs};
use tempfile::Builder;
use tokio::sync::broadcast;

async fn build_instance_map(
Expand Down Expand Up @@ -767,8 +773,16 @@ mod config_action_tests {
config_protocol: protocol,
instance_map: instance_map_clone,
};
let device_plugin_temp_dir =
Builder::new().prefix("device-plugins-").tempdir().unwrap();
let device_plugin_temp_dir_path = device_plugin_temp_dir.path().to_str().unwrap();
periodic_dicovery
.do_periodic_discovery(&mock, watch_periph_rx, finished_watching_tx)
.do_periodic_discovery(
&mock,
watch_periph_rx,
finished_watching_tx,
device_plugin_temp_dir_path,
)
.await
.unwrap();
});
Expand Down
6 changes: 1 addition & 5 deletions agent/src/util/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ pub const UNHEALTHY: &str = "Unhealthy";
pub const K8S_DEVICE_PLUGIN_VERSION: &str = "v1beta1";

/// DevicePluginPath is the folder the kubelet expects to find Device-Plugin sockets. Only privileged pods have access to this path.
#[cfg(not(test))]
pub const DEVICE_PLUGIN_PATH: &str = "/var/lib/kubelet/device-plugins/";
/// Path for testing `DevicePluginService`
#[cfg(test)]
pub const DEVICE_PLUGIN_PATH: &str = "/tmp/device-plugins/";
pub const DEVICE_PLUGIN_PATH: &str = "/var/lib/kubelet/device-plugins";

/// Path of the Kubelet registry socket
pub const KUBELET_SOCKET: &str = "/var/lib/kubelet/device-plugins/kubelet.sock";
Expand Down
29 changes: 16 additions & 13 deletions agent/src/util/device_plugin_service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::constants::{
DEVICE_PLUGIN_PATH, HEALTHY, K8S_DEVICE_PLUGIN_VERSION, KUBELET_SOCKET,
LIST_AND_WATCH_SLEEP_SECS, UNHEALTHY,
HEALTHY, K8S_DEVICE_PLUGIN_VERSION, KUBELET_SOCKET, LIST_AND_WATCH_SLEEP_SECS, UNHEALTHY,
};
use super::v1beta1;
use super::v1beta1::{
Expand Down Expand Up @@ -751,16 +750,17 @@ pub async fn build_device_plugin(
shared: bool,
instance_properties: HashMap<String, String>,
instance_map: InstanceMap,
device_plugin_path: &str,
) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
info!("build_device_plugin - entered for device {}", instance_name);
let capability_id: String = format!("{}/{}", AKRI_PREFIX, instance_name);
let unique_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
let device_endpoint: String = format!("{}-{}.sock", instance_name, unique_time.as_secs());
let socket_path: String = format!(
"{}{}",
DEVICE_PLUGIN_PATH.to_string(),
device_endpoint.clone()
);
let socket_path: String = Path::new(device_plugin_path)
.join(device_endpoint.clone())
.to_str()
.unwrap()
.to_string();
// Channel capacity set to 6 because 3 possible senders (allocate, update_connectivity_status, and handle_config_delete)
// and and receiver only periodically checks channel
let (list_and_watch_message_sender, _) = broadcast::channel(6);
Expand Down Expand Up @@ -900,7 +900,7 @@ async fn register(
pre_start_required: false,
};

// lttp://... is a fake uri that is unused (in service_fn) but neccessary for uds connection
// lttp://... is a fake uri that is unused (in service_fn) but necessary for uds connection
let channel = Endpoint::try_from("lttp://[::]:50051")?
.connect_with_connector(service_fn(|_: Uri| UnixStream::connect(KUBELET_SOCKET)))
.await?;
Expand Down Expand Up @@ -1002,6 +1002,7 @@ mod device_plugin_service_tests {
fs,
io::{Error, ErrorKind},
};
use tempfile::Builder;

enum NodeName {
ThisNode,
Expand Down Expand Up @@ -1346,11 +1347,13 @@ mod device_plugin_service_tests {
let _ = env_logger::builder().is_test(true).try_init();
let (device_plugin_service, device_plugin_service_receivers) =
create_device_plugin_service(ConnectivityStatus::Online, false);
let socket_path: String = format!(
"{}{}",
DEVICE_PLUGIN_PATH.to_string(),
device_plugin_service.endpoint.clone()
);
let device_plugin_temp_dir = Builder::new().prefix("device-plugins-").tempdir().unwrap();
let socket_path: String = device_plugin_temp_dir
.path()
.join(device_plugin_service.endpoint.clone())
.to_str()
.unwrap()
.to_string();
let list_and_watch_message_sender =
device_plugin_service.list_and_watch_message_sender.clone();
let instance_name = device_plugin_service.instance_name.clone();
Expand Down

0 comments on commit 3c5f721

Please sign in to comment.