Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • digit-c4/netbox-plugins
  • abramda/netbox-plugins-for-git-lab-pilot
2 results
Show changes
Commits on Source (25)
......@@ -196,3 +196,8 @@ override.tf.json
terraform.rc
docker-compose.override.yml
#Robot Framework reports
log.html
output.xml
report.html
......@@ -40,11 +40,16 @@ build-job: # This job runs in the build stage, which runs first.
script:
- ansible-playbook ansible/build.yml
up-test-env-job:
stage: test
script:
- chmod 600 $ANSIBLE_PRIVATE_KEY_FILE
- env ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_PRIVATE_KEY_FILE="$ANSIBLE_PRIVATE_KEY_FILE" ansible-playbook -i "$TESTING_HOSTS" -u debian ansible/deploy_on_test.yml
run-test-job:
stage: test
before_script:
- chmod 600 $ANSIBLE_PRIVATE_KEY_FILE
- env ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_PRIVATE_KEY_FILE="$ANSIBLE_PRIVATE_KEY_FILE" ansible-playbook -i "$TESTING_HOSTS" -u debian ansible/deploy_on_test.yml
- python3 -m venv "$CI_PROJECT_DIR/plugins/venv"
- source "$CI_PROJECT_DIR/plugins/venv/bin/activate"
- pip install -r "$CI_PROJECT_DIR/plugins/netbox-rps-plugin/tests/requirements.e2e.txt"
......@@ -55,13 +60,57 @@ run-test-job:
- env HOST="$CI_COMMIT_SHORT_SHA.$HOSTNAME" PORT="$PORT" API_KEY="$API_KEY" pytest -s --junit-xml=tests-report-netbox-cert-plugin.xml "$CI_PROJECT_DIR/plugins/netbox-cert-plugin/tests/"
- env HOST="$CI_COMMIT_SHORT_SHA.$HOSTNAME" PORT="$PORT" API_KEY="$API_KEY" pytest -s --junit-xml=tests-report-netbox-dist-plugin.xml "$CI_PROJECT_DIR/tests/e2e/"
after_script:
- env ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_PRIVATE_KEY_FILE="$ANSIBLE_PRIVATE_KEY_FILE" ansible-playbook -i "$TESTING_HOSTS" -u debian ansible/halt_test.yml
- deactivate
- rm -rf "$CI_PROJECT_DIR/plugins/venv"
artifacts:
when: always
reports:
junit: tests-report-netbox-*-plugin.xml
dependencies:
- up-test-env-job
needs:
- up-test-env-job
run-robot-test-job:
stage: test
before_script:
- python3 -m venv "$CI_PROJECT_DIR/plugins/venv"
- source "$CI_PROJECT_DIR/plugins/venv/bin/activate"
- docker build -t robotframework ./tests/docker/
script:
- docker run --rm -v $CI_PROJECT_DIR:/project --network "host" robotframework:latest bash -c "robot -v HOST:"$CI_COMMIT_SHORT_SHA.$HOSTNAME" -v PORT:$PORT -v API_TOKEN:"$API_KEY" --outputdir /project/reports /project/tests/robot/; chmod -R 777 /project/reports"
after_script:
- docker image prune -a -f
- deactivate
- rm -rf "$CI_PROJECT_DIR/plugins/venv"
artifacts:
paths:
- reports/*
dependencies:
- up-test-env-job
- run-test-job
needs:
- up-test-env-job
- run-test-job
.down-test-env-job: &down-test-env-job
stage: test
before_script:
- chmod 600 $ANSIBLE_PRIVATE_KEY_FILE
script:
- echo "Test Env Down"
after_script:
- env ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_PRIVATE_KEY_FILE="$ANSIBLE_PRIVATE_KEY_FILE" ansible-playbook -i "$TESTING_HOSTS" -u debian ansible/halt_test.yml
dependencies:
- run-test-job
- run-robot-test-job
needs:
- run-test-job
- run-robot-test-job
down-test-env-job_always:
when: always
<<: *down-test-env-job
deliver-latest-job:
stage: deliver
......
FROM netboxcommunity/netbox:v3.6.9-2.7.0
USER root
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
python3-dev \
python3-venv \
&& \
rm -rf /var/lib/apt/lists/*
RUN mkdir /opt/netbox/plugins
COPY requirements.txt /opt/netbox/plugins
COPY netbox_configuration/plugins.py /etc/netbox/config/plugins.py
COPY netbox_configuration/extra.py /etc/netbox/config/extra.py
COPY netbox_configuration/entrypoint.sh /usr/bin/netbox_plugin_entrypoint.sh
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN pip install -r /opt/netbox/plugins/requirements.txt
RUN rm -rf /opt/netbox/plugins
CMD ["/usr/bin/netbox_plugin_entrypoint.sh"]
#!/bin/bash
########################################################
# Select how to start Netbox Docker.
# set env variable `ACTIVATE_WORKER_AND_HOUSEKEEPING` if needed to:
# - 1
# - 0 (legacy)
########################################################
migrate_func () {
########################################################################################
# Piece of code borrowed from netbox official `/opt/netbox/docker-entrypoint.sh` script.
########################################################################################
# Load correct Python3 env
source /opt/netbox/venv/bin/activate
# Check if update is needed
if ! ./manage.py migrate --check >/dev/null 2>&1; then
echo "⚙️ Applying database migrations"
./manage.py migrate --no-input
echo "⚙️ Running trace_paths"
./manage.py trace_paths --no-input
echo "⚙️ Removing stale content types"
./manage.py remove_stale_contenttypes --no-input
echo "⚙️ Removing expired user sessions"
./manage.py clearsessions
echo "⚙️ Building search index (lazy)"
./manage.py reindex --lazy
fi
}
if [[ "${ACTIVATE_WORKER_AND_HOUSEKEEPING}" == 1 ]] ; then
echo "var ACTIVATE_WORKER_AND_HOUSEKEEPING=1"
echo "Netbox-worker and Netbox-housekeeping will not need extra containers to run."
# run function.
migrate_func && \
# Start netbox with `netbox-worker` and `netbox-housekeeping` running on same container
supervisord --configuration /etc/supervisor/conf.d/supervisord.conf
else
echo "var ACTIVATE_WORKER_AND_HOUSEKEEPING=0"
echo "Netbox-worker and Netbox-housekeeping might need separate containers to run."
## Launch regular netbox entrypoint
/opt/netbox/docker-entrypoint.sh /opt/netbox/launch-netbox.sh
fi
netbox-plugin-dns == 0.19.*
netbox-plugin-prometheus-sd
netbox-docker-plugin
netbox-docker-plugin == 1.*
--extra-index-url https://code.europa.eu/api/v4/projects/713/packages/pypi/simple
--extra-index-url https://code.europa.eu/api/v4/projects/662/packages/pypi/simple
netbox-cert-plugin == 0.1.*
netbox-cert-plugin == 0.2.*
--extra-index-url https://code.europa.eu/api/v4/projects/623/packages/pypi/simple
netbox-rps-plugin == 0.15.*
supervisor == 4.2.5
###################################################################
# How to redirect stdout from child processes to supervisord
# http://veithen.io/2015/01/08/supervisord-redirecting-stdout.html
###################################################################
[supervisord]
nodaemon=true
logfile=/tmp/supervisord.log
logfile_maxbytes=1MB
[program:netbox-worker]
command=/opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py rqworker
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=901
[program:netbox-housekeeping]
command=/opt/netbox/housekeeping.sh
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=902
[program:netbox-default-entrypoint]
command=/opt/netbox/docker-entrypoint.sh /opt/netbox/launch-netbox.sh
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=900
FROM python:3
RUN pip install robotframework robotframework-requests
*** Test Cases ***
TC01 Pass Test
Pass Execution A Passing Test
\ No newline at end of file
*** Settings ***
Library RequestsLibrary
*** Variables ***
${HOST} localhost
${PORT} 8080
${BASE_URL} http://${HOST}:${PORT}
${USER_API} admin
${PASSWORD_API} thisisagoodpassword
${API_TOKEN} only4testingpurpose
${TOKEN} Token ${API_TOKEN}
${CONTENT_TYPE} application/json
@{PLUGINS} rps netbox-dns cert prometheus-sd docker
*** Test Cases ***
TC02 Check installed plugins
${auth}= Evaluate ("${USER_API}", "${PASSWORD_API}")
&{HEADERS} Create Dictionary Authorization=${TOKEN} Content-Type=${CONTENT_TYPE}
Create Session robot_test_session ${BASE_URL} headers=${HEADERS}
Log to console ${\n}
FOR ${item} IN @{PLUGINS}
${response}= GET On session robot_test_session /api/plugins/${item}/ auth=${auth} headers=${HEADERS} expected_status=200
Check plugins response status "${response.ok}" "${item}"
END
Log to console ${\n}
TC02.1 Check Nonexistent Plugin
${auth}= Evaluate ("${USER_API}", "${PASSWORD_API}")
&{HEADERS} Create Dictionary Authorization=${TOKEN} Content-Type=${CONTENT_TYPE}
${response}= GET On session robot_test_session /api/plugins/nonexistent_plugin headers=${HEADERS} expected_status=404
Check plugins response status "${response.ok}" "nonexistent"
*** Keywords ***
Check plugins response status "${response.ok}" "${item}"
IF "${response.ok}" == "True"
Log to console ${\n}Plugin ${item} Installed
Log ${\n}Plugin ${item} Installed
ELSE
Log to console ${\n}Plugin ${item} Not Installed
Log ${\n}Plugin ${item} Not Installed
END
\ No newline at end of file
*** Settings ***
Library RequestsLibrary
*** Variables ***
${HOST} localhost
${PORT} 8080
${BASE_URL} http://${HOST}:${PORT}
${USER_API} admin
${PASSWORD_API} thisisagoodpassword
${API_TOKEN} only4testingpurpose
${TOKEN} Token ${API_TOKEN}
${CONTENT_TYPE} application/json
${page} metrics
*** Test Cases ***
TC03 Check Metrics Page
${auth}= Evaluate ("${USER_API}", "${PASSWORD_API}")
&{HEADERS} Create Dictionary Authorization=${TOKEN} Content-Type=${CONTENT_TYPE}
Create Session robot_test_session ${BASE_URL} headers=${HEADERS}
${response}= GET On session robot_test_session /${page} headers=${HEADERS} auth=${auth} expected_status=200
Log to console ${\n}
Check metrics response status "${response.ok}" "${page}"
Log to console ${\n}
TC03.1 Check Nonexistent Page
${auth}= Evaluate ("${USER_API}", "${PASSWORD_API}")
&{HEADERS} Create Dictionary Authorization=${TOKEN} Content-Type=${CONTENT_TYPE}
${response}= GET On session robot_test_session /api/plugins/nonexistent_plugin auth=${auth} headers=${HEADERS} expected_status=404
Log to console ${\n}
Check metrics response status "${response.ok}" "nonexistent"
Log to console ${\n}
*** Keywords ***
Check metrics response status "${response.ok}" "${page}"
IF "${response.ok}" == "True"
Log to console ${\n}${page} Ready
Log ${\n}${page} Ready
ELSE
Log to console ${\n}${page} Not Ready
Log ${\n}${page} Not Ready
END
\ No newline at end of file