Skip to content

Commit

Permalink
fix: only add device id to broker env vars suffix
Browse files Browse the repository at this point in the history
Signed-off-by: Kate Goldenring <[email protected]>
  • Loading branch information
kate-goldenring committed Oct 23, 2024
1 parent 66ce8ac commit bfb80ee
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
10 changes: 5 additions & 5 deletions agent/src/plugin_manager/device_plugin_instance_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,27 +405,27 @@ impl InternalDevicePlugin for InstanceDevicePlugin {
tonic::Status::unknown("Unable to claim slot")
})?;
}
container_responses.push(cdi_device_to_car(&self.instance_name, &self.device));
container_responses.push(cdi_device_to_car(&self.device));
}
Ok(tonic::Response::new(AllocateResponse {
container_responses,
}))
}
}

fn cdi_device_to_car(instance_name: &str, device: &cdi::Device) -> ContainerAllocateResponse {
fn cdi_device_to_car(device: &cdi::Device) -> ContainerAllocateResponse {
ContainerAllocateResponse {
envs: device
.container_edits
.env
.iter()
.map(|e| match e.split_once('=') {
Some((k, v)) => (
format!("{}_{}", k, instance_name.to_uppercase()),
format!("{}_{}", k, device.name.to_uppercase()),
v.to_string(),
),
None => (
format!("{}_{}", e, instance_name.to_uppercase()),
format!("{}_{}", e, device.name.to_uppercase()),
"".to_string(),
),
})
Expand Down Expand Up @@ -672,7 +672,7 @@ impl InternalDevicePlugin for ConfigurationDevicePlugin {
.get(&dev)
.ok_or(tonic::Status::unknown("Invalid slot"))?
.clone();
container_responses.push(cdi_device_to_car(&dp.instance_name, &dp.device));
container_responses.push(cdi_device_to_car(&dp.device));
dp.claim_slot(
None,
DeviceUsage::Configuration {
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Running E2E Tests Locally

Reference the [Akri developer guide](https://docs.akri.sh/development/test-cases-workflow#run-the-tests-locally) for details on running locally.

## Displaying Output
By default, pytest captures output. If you always want to disable output capturing when running pytest through poetry, you can set the `PYTEST_ADDOPTS` environment variable:

```sh
PYTEST_ADDOPTS="-s" poetry run pytest -v | tee output.log
```

## Running a Specific Test
A specific test can be executed by specifying its file and name like so:
```
poetry run pytest test_core.py::test_device_offline -vvv
```
4 changes: 2 additions & 2 deletions test/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def install_akri(request, pytestconfig, akri_version):
helm_install_command.extend(
[
"--set",
"agent.allowDebugEcho=true,debugEcho.configuration.shared=false",
"agent.allowDebugEcho=true",
]
)
if pytestconfig.getoption("--use-local"):
Expand All @@ -90,7 +90,7 @@ def install_akri(request, pytestconfig, akri_version):
)
helm_install_command.extend(
[
"--debug",
# "--debug",
"--atomic",
]
)
Expand Down
30 changes: 24 additions & 6 deletions test/e2e/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def test_all_scheduled(akri_version, basic_config):
assert_svc_present(basic_config, True, 2)
assert_svc_present(basic_config, False, 1)


def test_device_offline(akri_version, basic_config):
# Check we are in sane setup
assert_akri_instances_present(akri_version, basic_config, 2)
Expand All @@ -61,15 +60,35 @@ def test_device_offline(akri_version, basic_config):
assert_svc_present(basic_config, False, 1)

v1_core = kubernetes.client.CoreV1Api()
pods = v1_core.list_namespaced_pod(
broker_pods = v1_core.list_namespaced_pod(
"default",
label_selector=f"app.kubernetes.io/name=akri-debug-echo-discovery",
label_selector="akri.sh/configuration=akri-debug-echo-foo",
field_selector="status.phase=Running",
).items
base_command = ["/bin/sh", "-c"]
for pod in broker_pods:
envs = kubernetes.stream.stream(
v1_core.connect_get_namespaced_pod_exec,
pod.metadata.name,
"default",
command="printenv",
stdout=True,
stdin=False,
stderr=False,
tty=False,
)
# TODO: Check env var suffix is as expected
if "DEBUG_ECHO_DESCRIPTION" not in envs:
raise AssertionError(f"DEBUG_ECHO_DESCRIPTION env var not found in broker")

dh_pods = v1_core.list_namespaced_pod(
"default",
label_selector=f"app.kubernetes.io/name=akri-debug-echo-discovery",
field_selector="status.phase=Running",
).items
command = "echo {} > /tmp/debug-echo-availability.txt"
# Unplug the devices
for pod in pods:
for pod in dh_pods:
kubernetes.stream.stream(
v1_core.connect_get_namespaced_pod_exec,
pod.metadata.name,
Expand All @@ -85,7 +104,7 @@ def test_device_offline(akri_version, basic_config):
assert_svc_present(basic_config, True, 0)
assert_svc_present(basic_config, False, 0)
# Plug them back
for pod in pods:
for pod in dh_pods:
kubernetes.stream.stream(
v1_core.connect_get_namespaced_pod_exec,
pod.metadata.name,
Expand All @@ -101,7 +120,6 @@ def test_device_offline(akri_version, basic_config):
assert_svc_present(basic_config, True, 2)
assert_svc_present(basic_config, False, 1)


def test_cleanup(akri_version, faker):
with open(Path(__file__).parent / "yaml/debugEchoConfiguration.yaml") as f:
body = yaml.safe_load(f)
Expand Down

0 comments on commit bfb80ee

Please sign in to comment.