Add boilerplate config for Zuul and unit tests

Adds the required configuration to run Zuul on
reviews, including flake8, pylint, bandit and
unit tests.

Tested by running tox locally.

Partial-Bug: 1927003
Signed-off-by: Isac Souza <IsacSacchi.Souza@windriver.com>
Change-Id: I7906dbadc00693736dedc2f5ea88ed24f74345f7
This commit is contained in:
Isac Souza 2021-05-06 16:59:30 -03:00
parent 633d0a9a76
commit 87dcbb336b
11 changed files with 129 additions and 23 deletions

View File

@ -3,13 +3,95 @@
check: check:
jobs: jobs:
- openstack-tox-linters - openstack-tox-linters
- k8sapp-nginx-ingress-controller-tox-py27
- k8sapp-nginx-ingress-controller-tox-py36
- k8sapp-nginx-ingress-controller-tox-flake8
- k8sapp-nginx-ingress-controller-tox-pylint
- k8sapp-nginx-ingress-controller-tox-bandit
gate: gate:
jobs: jobs:
- openstack-tox-linters - openstack-tox-linters
- k8sapp-nginx-ingress-controller-tox-py27
- k8sapp-nginx-ingress-controller-tox-py36
- k8sapp-nginx-ingress-controller-tox-flake8
- k8sapp-nginx-ingress-controller-tox-pylint
- k8sapp-nginx-ingress-controller-tox-bandit
post: post:
jobs: jobs:
- stx-nginx-ingress-controller-armada-app-upload-git-mirror - stx-nginx-ingress-controller-armada-app-upload-git-mirror
- job:
name: k8sapp-nginx-ingress-controller-tox-py27
parent: tox
description: |
Run py27 test for k8sapp-nginx-ingress-controller
nodeset: ubuntu-xenial
required-projects:
- starlingx/config
- starlingx/fault
- starlingx/update
- starlingx/utilities
files:
- python-k8sapp-nginx-ingress-controller/*
vars:
tox_envlist: py27
tox_extra_args: -c python-k8sapp-nginx-ingress-controller/k8sapp_nginx_ingress_controller/tox.ini
- job:
name: k8sapp-nginx-ingress-controller-tox-py36
parent: tox
description: |
Run py36 test for k8sapp-nginx-ingress-controller
nodeset: ubuntu-bionic
required-projects:
- starlingx/config
- starlingx/fault
- starlingx/update
- starlingx/utilities
files:
- python-k8sapp-nginx-ingress-controller/*
vars:
tox_envlist: py36
tox_extra_args: -c python-k8sapp-nginx-ingress-controller/k8sapp_nginx_ingress_controller/tox.ini
- job:
name: k8sapp-nginx-ingress-controller-tox-flake8
parent: tox
description: |
Run flake8 test for k8sapp-nginx-ingress-controller
files:
- python-k8sapp-nginx-ingress-controller/*
vars:
tox_envlist: flake8
tox_extra_args: -c python-k8sapp-nginx-ingress-controller/k8sapp_nginx_ingress_controller/tox.ini
- job:
name: k8sapp-nginx-ingress-controller-tox-pylint
parent: tox
description: |
Run pylint test for k8sapp-nginx-ingress-controller
required-projects:
- starlingx/config
- starlingx/fault
- starlingx/update
- starlingx/utilities
files:
- python-k8sapp-nginx-ingress-controller/*
vars:
tox_envlist: pylint
tox_extra_args: -c python-k8sapp-nginx-ingress-controller/k8sapp_nginx_ingress_controller/tox.ini
- job:
name: k8sapp-nginx-ingress-controller-tox-bandit
parent: tox
description: |
Run bandit test for k8sapp-nginx-ingress-controller
files:
- python-k8sapp-nginx-ingress-controller/*
vars:
tox_envlist: bandit
tox_extra_args: -c python-k8sapp-nginx-ingress-controller/k8sapp_nginx_ingress_controller/tox.ini
- job: - job:
name: stx-nginx-ingress-controller-armada-app-upload-git-mirror name: stx-nginx-ingress-controller-armada-app-upload-git-mirror
parent: upload-git-mirror parent: upload-git-mirror

View File

@ -0,0 +1,4 @@
[DEFAULT]
test_path=./k8sapp_nginx_ingress_controller/tests
top_dir=./k8sapp_nginx_ingress_controller
#parallel_class=True

View File

@ -1,5 +0,0 @@
#
# Copyright (c) 2021 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#

View File

@ -1,5 +0,0 @@
#
# Copyright (c) 2021 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#

View File

@ -6,7 +6,7 @@
# All Rights Reserved. # All Rights Reserved.
# #
""" System inventory App lifecycle operator.""" """System inventory App lifecycle operator."""
from k8sapp_nginx_ingress_controller.common import constants as app_constants from k8sapp_nginx_ingress_controller.common import constants as app_constants
from oslo_log import log as logging from oslo_log import log as logging
@ -18,7 +18,7 @@ LOG = logging.getLogger(__name__)
class NginxIngressControllerAppLifecycleOperator(base.AppLifecycleOperator): class NginxIngressControllerAppLifecycleOperator(base.AppLifecycleOperator):
def app_lifecycle_actions(self, context, conductor_obj, app_op, app, hook_info): def app_lifecycle_actions(self, context, conductor_obj, app_op, app, hook_info):
""" Perform lifecycle actions for an operation """Perform lifecycle actions for an operation
:param context: request context :param context: request context
:param conductor_obj: conductor object :param conductor_obj: conductor object
@ -34,7 +34,8 @@ class NginxIngressControllerAppLifecycleOperator(base.AppLifecycleOperator):
return self.pre_etcd_backup(app_op) return self.pre_etcd_backup(app_op)
# Use the default behaviour for other hooks # Use the default behaviour for other hooks
super(NginxIngressControllerAppLifecycleOperator, self).app_lifecycle_actions(context, conductor_obj, app_op, app, hook_info) super(NginxIngressControllerAppLifecycleOperator, self).app_lifecycle_actions(
context, conductor_obj, app_op, app, hook_info)
def pre_etcd_backup(self, app_op): def pre_etcd_backup(self, app_op):
"""Pre Etcd backup actions """Pre Etcd backup actions
@ -46,7 +47,9 @@ class NginxIngressControllerAppLifecycleOperator(base.AppLifecycleOperator):
label_selector = "app.kubernetes.io/name={}," \ label_selector = "app.kubernetes.io/name={}," \
"app.kubernetes.io/component={}"\ "app.kubernetes.io/component={}"\
.format(app_constants.HELM_CHART_INGRESS_NGINX, "admission-webhook") .format(app_constants.HELM_CHART_INGRESS_NGINX, "admission-webhook")
# pylint: disable=protected-access
webhooks = app_op._kube.kube_get_validating_webhook_configurations_by_selector(label_selector, "") webhooks = app_op._kube.kube_get_validating_webhook_configurations_by_selector(label_selector, "")
if webhooks: if webhooks:
admission_webhook = webhooks[0].metadata.name admission_webhook = webhooks[0].metadata.name
# pylint: disable=protected-access
app_op._kube.kube_delete_validating_webhook_configuration(admission_webhook) app_op._kube.kube_delete_validating_webhook_configuration(admission_webhook)

View File

@ -0,0 +1,19 @@
#
# Copyright (c) 2021 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from sysinv.tests.db import base
class NginxICTestCase(base.DbTestCase):
def setUp(self):
super(NginxICTestCase, self).setUp()
def tearDown(self):
super(NginxICTestCase, self).tearDown()
def test_plugins(self):
# placeholder for future unit tests
pass

View File

@ -1,2 +1,2 @@
pbr>=2.0.0 pbr>=2.0.0
PyYAML==3.10 PyYAML==3.13

View File

@ -1,8 +1,6 @@
# The order of packages is significant, because pip processes them in the order # The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration # of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later. # process, which may cause wedges in the gate later.
flake8<3.8.0
pycodestyle<2.6.0 # MIT License
hacking>=1.1.0,<=2.0.0 # Apache-2.0 hacking>=1.1.0,<=2.0.0 # Apache-2.0
coverage>=3.6 coverage>=3.6
discover discover
@ -12,14 +10,12 @@ passlib>=1.7.0
psycopg2-binary psycopg2-binary
python-subunit>=0.0.18 python-subunit>=0.0.18
requests-mock>=0.6.0 # Apache-2.0 requests-mock>=0.6.0 # Apache-2.0
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 sphinx
oslosphinx<2.6.0,>=2.5.0 # Apache-2.0 oslosphinx
oslotest>=3.2.0 # Apache-2.0 oslotest>=3.2.0 # Apache-2.0
stestr>=1.0.0 # Apache-2.0 stestr>=1.0.0 # Apache-2.0
testrepository>=0.0.18 testrepository>=0.0.18
testtools!=1.2.0,>=0.9.36 testtools!=1.2.0,>=0.9.36
tempest-lib<0.5.0,>=0.4.0
ipaddr
pytest pytest
pyudev pyudev
migrate migrate

View File

@ -1,8 +1,9 @@
[tox] [tox]
envlist = flake8,py27,py36,pylint,bandit envlist = flake8,py27,py36,pylint,bandit
minversion = 1.6 minversion = 1.6
# skipsdist = True # disable source dist generation because Zuul fails on setting up
#,pip-missing-reqs # pbr randomly in the sdist step.
skipsdist = True
# tox does not work if the path to the workdir is too long, so move it to /tmp # tox does not work if the path to the workdir is too long, so move it to /tmp
toxworkdir = /tmp/{env:USER}_k8sapp_nginx_ingress_controllertox toxworkdir = /tmp/{env:USER}_k8sapp_nginx_ingress_controllertox
@ -36,7 +37,6 @@ setenv = VIRTUAL_ENV={envdir}
LANG=en_US.UTF-8 LANG=en_US.UTF-8
LANGUAGE=en_US:en LANGUAGE=en_US:en
LC_ALL=C LC_ALL=C
EVENTS_YAML=./k8sapp_nginx_ingress_controller/tests/events_for_testing.yaml
SYSINV_TEST_ENV=True SYSINV_TEST_ENV=True
TOX_WORK_DIR={toxworkdir} TOX_WORK_DIR={toxworkdir}
PYLINTHOME={toxworkdir} PYLINTHOME={toxworkdir}

12
tox.ini
View File

@ -33,3 +33,15 @@ commands =
[testenv:linters] [testenv:linters]
commands = commands =
{[testenv:bashate]commands} {[testenv:bashate]commands}
[testenv:flake8]
basepython = python3
description = Dummy environment to allow flake8 to be run in subdir tox
[testenv:pylint]
basepython = python3
description = Dummy environment to allow pylint to be run in subdir tox
[testenv:bandit]
basepython = python3
description = Dummy environment to allow bandit to be run in subdir tox