Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add makefile for o2ims #870

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions operators/o2ims-operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ RUN addgroup --gid 65535 o2ims && \
# Set working directory
WORKDIR /usr/o2ims

# Copy requirements first and install dependencies
Copy link
Contributor

@vjayaramrh vjayaramrh Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious as to reason for making these changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Makefile setup for building docker images runs from the root of the repo with a context of ../../
https://github.com/nephio-project/nephio/blob/main/default-docker.mk
Without this change, it's broken.
We should also have some way of executing the tests in each repo through Make, etc.

COPY --chown=o2ims:o2ims /operators/o2ims-operator/requirements.txt requirements.txt
RUN python -m venv /home/o2ims/venv && \
/home/o2ims/venv/bin/pip install --no-cache-dir -r requirements.txt

# Copy application files
COPY --chown=o2ims:o2ims controllers/ src/
COPY --chown=o2ims:o2ims requirements.txt requirements.txt
COPY --chown=o2ims:o2ims /operators/o2ims-operator/controllers/ src/

# Switch to non-root user
USER o2ims

# Create a virtual environment and install dependencies
RUN python -m venv /home/o2ims/venv && \
/home/o2ims/venv/bin/pip install --no-cache-dir -r requirements.txt

# Set environment variables
ENV PATH="/home/o2ims/venv/bin:${PATH}" \
VIRTUAL_ENV="/home/o2ims/venv"
Expand Down
10 changes: 10 additions & 0 deletions operators/o2ims-operator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
IMAGE_TAG ?= latest
REGISTRY ?= docker.io/nephio
IMAGE_NAME ?= o2ims-operator
IMG ?= $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)

# This includes the following targets:
# docker-build, docker-push
include ../../default-docker.mk


37 changes: 19 additions & 18 deletions operators/o2ims-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This operator implements O-RAN O2 IMS for K8s based cloud management.

### Development Requirements:

- Python3.11
- >= Python3.11
- requirements.txt installed in development environment

### Nephio Management Cluster Requirements:
Expand Down Expand Up @@ -73,13 +73,14 @@ nohup kubectl proxy --port 8080 &>/dev/null &
Build a Docker image:

```bash
docker build -t o2ims-operator:latest -f Dockerfile .
cd operators/o2ims-operator/
make docker-build
```

Push this image in your cluster, here we are using a `kind` cluster so we will push using the below command:

```bash
kind load docker-image o2ims-operator:latest -n o2ims-mgmt
kind load docker-image nephio/o2ims-operator:latest -n o2ims-mgmt
```

`NOTE`: `o2ims-mgmt` is the name of the kind cluster. It is good to mention cluster name if you have multiple clusters.
Expand Down Expand Up @@ -176,34 +177,34 @@ status:

Unit tests are contained in the `tests` directory, and are intended to test pieces of the O2IMS Operator in the `controllers` directory. Currently unit tests are not comprehensive, but provide expected coverage of core utility components.

Prior to running the tests, install the requirements:
Prior to running the tests, install tox in your environment:
```bash
pip3 install -r ./tests/unit_test_requirements.txt
pip install tox
```

To run all tests in `test_utils.py` with abridged output:
To run all tests in `test_utils.py` targeting a specific python version:
```bash
pytest ./tests/test_utils.py
tox -e py312
```

Output:
```bash
==================================================================== test session starts ====================================================================
platform linux -- Python 3.13.0, pytest-8.3.4, pluggy-1.5.0
rootdir: /home/dkosteck/Documents/nephio/operators/o2ims-operator
collected 61 items
py312: commands[0]> pytest --maxfail=1 --disable-warnings -q -v
=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.12.3, pytest-8.3.4, pluggy-1.5.0
cachedir: .tox/py312/.pytest_cache
rootdir: /home/fiachra/git/nordix_github/nephio/operators/o2ims-operator
plugins: cov-6.0.0
collected 39 items

tests/test_utils.py ............................................................. [100%]
tests/test_utils.py ....................................... [100%]

==================================================================== 61 passed in 0.14s =====================================================================
=========================================================================================== 39 passed in 0.12s ============================================================================================
py312: OK (0.27=setup[0.02]+cmd[0.25] seconds)
congratulations :) (0.30 seconds)

```

To run with verbose output (showing individual test results):
```bash
pytest -v ./tests/test_utils.py
```

## Known issues

### Porch Endpoints and Stuck Deployments
Expand Down
6 changes: 3 additions & 3 deletions operators/o2ims-operator/tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tox]
envlist = py311, lint
envlist = py311, py312, lint

[testenv:py311]
[testenv:py311,py312]
deps =
-r requirements.txt
-r tests/unit_test_requirements.txt
pytest-cov
commands =
pytest --maxfail=1 --disable-warnings -q
pytest --maxfail=1 --disable-warnings -q -v

# Lint environment for running code style checks
[testenv:lint]
Expand Down