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

Cobbler: Replace SSH with XML-RPC API calls #261

Merged
merged 7 commits into from
Aug 28, 2024
Merged
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
46 changes: 11 additions & 35 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,26 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-devel.txt', '**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Dependencies
- name: Allow writing from inside the container
run: |
sudo apt-get install python3-setuptools libldap2-dev libsasl2-dev jq
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-devel.txt
- name: Create required directories
chmod g+w,o+w .
- name: Build images
run: |
sudo mkdir -p /var/log/orthos2
sudo mkdir -p /var/lib/orthos2/database
- name: Create required files
docker compose build
- name: Start Compose Stack
run: |
sudo touch /var/log/orthos2/default.log
sudo touch /var/lib/orthos2/database/db.sqlite3
- name: Adjust permissions for files
docker compose up -d
- name: Wait for Cobbler to run
run: |
CURRENT_USER=$(whoami)
CURRENT_GROUP=$(id -gn)
sudo chown -R $CURRENT_USER:$CURRENT_GROUP /var/lib/orthos2
sudo chown -R $CURRENT_USER:$CURRENT_GROUP /var/log/orthos2
- name: Migrate database
env:
ORTHOS_USER: runner
run: |
python3 manage.py migrate
sleep 60
- name: Run Tests
env:
ORTHOS_USER: runner
run: |
coverage run --source='.' manage.py test orthos2
coverage report
docker compose exec -it orthos2 bash -c 'coverage run --source="." manage.py test orthos2'
docker compose exec -it orthos2 bash -c 'coverage report'
- name: Check coverage goal
run: |
# Coverage goal is atm 25% or greater
coverage json
docker compose exec -it orthos2 bash -c 'coverage json'
coverage_percent=$(jq -r ".totals.percent_covered_display" < coverage.json)
[ "$coverage_percent" -gt "25" ]
integration:
Expand Down
27 changes: 14 additions & 13 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@ services:
orthos2:
build:
context: .
dockerfile: docker/develop.dockerfile
hostname: orthos2.test.de
dockerfile: docker/develop-tw.dockerfile
hostname: orthos2.orthos2.test
cap_add:
- NET_RAW
volumes:
- ./:/code
ports:
- 8000:8000
- "8000:8000"
cobbler:
image: registry.opensuse.org/systemsmanagement/cobbler/github-ci/containers/cobbler-test-github:release33
hostname: cobbler.test.de
hostname: cobbler.orthos2.test
command: >
bash -c "zypper --gpg-auto-import-keys ref
&& zypper in -y cobbler
&& zypper in -y cobbler lynx w3m
&& /usr/bin/ssh-keygen -A
&& /usr/sbin/sshd
&& cobblerd -F"
#ports:
# - 22:22
# - 80:80
# - 443:443
&& cobblerd
&& apachectl -D FOREGROUND"
ports:
# - "22:22"
- "80:80"
- "443:443"
serial_console:
image: registry.opensuse.org/opensuse/tumbleweed:latest
hostname: sconsole.test.de
hostname: sconsole.orthos2.test
# https://github.com/openSUSE/cscreen
command: >
bash -c "zypper in -y cscreen openssh-server
Expand All @@ -34,9 +35,9 @@ services:
#ports:
# - 22:22
machine_bmc:
hostname: bmc.test.de
hostname: bmc.orthos2.test
build:
context: docker
dockerfile: bmc.dockerfile
ports:
- 9001:9001
- "9001:9001"
56 changes: 56 additions & 0 deletions docker/develop-leap156.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM registry.opensuse.org/opensuse/leap:15.6

# Install system dependencies
RUN zypper in -y \
shadow \
python3 \
python3-devel \
python3-pip \
python3-setuptools \
gcc \
openldap2-devel \
cyrus-sasl-devel \
jq \
sudo

# Install requirements via zypper
RUN zypper in -y \
python311-Django \
python311-django-extensions \
python311-paramiko \
python311-djangorestframework \
python311-validators \
python311-netaddr \
python311-pytz \
python311-django-auth-ldap

# Test dependencies
RUN zypper in -y \
python311-flake8 \
python311-coverage \
python311-isort \
python311-pytest \
python311-django-webtest \
python311-pexpect \
iputils

# Create required user
RUN groupadd -r orthos
RUN useradd -r -g orthos -d /var/lib/orthos2 -s /bin/bash -c "orthos account" orthos

# Create required directories
RUN mkdir -p /var/log/orthos2
RUN mkdir -p /var/lib/orthos2/database
RUN touch /var/log/orthos2/default.log
RUN chmod o+w /var/log/orthos2/default.log
RUN chown -R orthos:orthos /var/log/orthos2
RUN chown -R orthos:orthos /var/lib/orthos2

# Setup container for work
WORKDIR /code
VOLUME /code
EXPOSE 8000
USER orthos

# Set entrypoint for development
CMD ["/code/docker/devel-server.sh"]
File renamed without changes.
2 changes: 1 addition & 1 deletion orthos2/api/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _list(self, request, machine):
if not machine.has_setup_capability():
return InfoMessage("Machine has no setup capability.").as_json

grouped_records = machine.fqdn_domain.get_setup_records(
grouped_records = machine.fqdn_domain.get_setup_records_grouped(
machine.architecture.name,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Generated by Django 4.2.14 on 2024-08-04 10:05
from django.apps.registry import Apps
from django.db import migrations, models
from django.db.backends.base.schema import BaseDatabaseSchemaEditor


def delete_setup_list_commands(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
"""
Drop the row "setup.list.command". It is not required anymore due to the switch to the Cobbler XML-RPC API.
"""
model = apps.get_model("data", "ServerConfig")
list_command = model.objects.filter(key="setup.list.command")
if list_command.exists():
list_command.delete()


class Migration(migrations.Migration):

dependencies = [
("data", "0040_alter_bmc_fence_name_remove_domain_cobbler_server_and_more"),
]

operations = [
migrations.AddField(
model_name="domain",
name="cobbler_server_password",
field=models.CharField(
default="cobbler",
help_text="The password to login to Cobbler via XML-RPC.",
max_length=255,
verbose_name="Cobbler server password",
),
),
migrations.AddField(
model_name="domain",
name="cobbler_server_username",
field=models.CharField(
default="cobbler",
help_text="The username to login to Cobbler via XML-RPC.",
max_length=255,
verbose_name="Cobbler server username",
),
),
migrations.AlterField(
model_name="bmc",
name="fence_name",
field=models.CharField(
choices=[("redfish", "redfish"), ("ipmilanplus", "ipmilanplus")],
max_length=255,
verbose_name="Fence agent",
),
),
migrations.AlterField(
model_name="remotepowerdevice",
name="fence_name",
field=models.CharField(
choices=[("apc", "apc")], max_length=255, verbose_name="Fence Agent"
),
),
migrations.RunPython(delete_setup_list_commands),
]
Loading
Loading