mirror of
https://github.com/krkn-chaos/krkn.git
synced 2026-02-14 18:10:00 +00:00
Added python linters and enabled travis CI to run linters
This commit adds python linters as it improves the code quality. Travis CI is enabled to run linters on each PR to make sure it follows the best practices and doesn't break the tool.
This commit is contained in:
committed by
Naga Ravi Chaitanya Elluri
parent
c11ba92bb3
commit
f5ae7818fd
50
.gitignore
vendored
Normal file
50
.gitignore
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
# Temporary and binary files
|
||||
*~
|
||||
*.py[cod]
|
||||
*.so
|
||||
*.cfg
|
||||
!.isort.cfg
|
||||
!setup.cfg
|
||||
*.orig
|
||||
*.log
|
||||
*.pot
|
||||
__pycache__/*
|
||||
.cache/*
|
||||
.*.swp
|
||||
*/.ipynb_checkpoints/*
|
||||
.DS_Store
|
||||
|
||||
# Project files
|
||||
.ropeproject
|
||||
.project
|
||||
.pydevproject
|
||||
.settings
|
||||
.idea
|
||||
tags
|
||||
|
||||
# Package files
|
||||
*.egg
|
||||
*.eggs/
|
||||
.installed.cfg
|
||||
*.egg-info
|
||||
|
||||
# Unittest and coverage
|
||||
htmlcov/*
|
||||
.coverage
|
||||
.tox
|
||||
junit.xml
|
||||
coverage.xml
|
||||
.pytest_cache/
|
||||
|
||||
# Build and docs folder/files
|
||||
build/*
|
||||
dist/*
|
||||
sdist/*
|
||||
docs/api/*
|
||||
docs/_rst/*
|
||||
docs/_build/*
|
||||
cover/*
|
||||
MANIFEST
|
||||
|
||||
# Per-project virtualenvs
|
||||
.venv*/
|
||||
15
.travis.yml
Normal file
15
.travis.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
dist: xenial
|
||||
|
||||
langauge: python
|
||||
|
||||
python: "3.6"
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update
|
||||
|
||||
install:
|
||||
- sudo apt install python3-pip
|
||||
- sudo pip3 install -r test-requirements.txt
|
||||
- sudo pip3 install tox
|
||||
|
||||
script: tox .
|
||||
@@ -2,6 +2,7 @@ from kubernetes import client, config
|
||||
from kubernetes.client.rest import ApiException
|
||||
import logging
|
||||
|
||||
|
||||
# Load kubeconfig and initialize kubernetes python client
|
||||
def initialize_clients(kubeconfig_path):
|
||||
global cli
|
||||
|
||||
@@ -43,25 +43,32 @@ def main(cfg):
|
||||
# Inject chaos scenarios specified in the config
|
||||
try:
|
||||
for scenario in scenarios:
|
||||
logging.info("Injecting scenario: %s" %(scenario))
|
||||
runcommand.invoke("powerfulseal autonomous --use-pod-delete-instead-of-ssh-kill --policy-file %s --kubeconfig %s --no-cloud --inventory-kubernetes --headless" % (scenario,kubeconfig_path))
|
||||
logging.info("Scenario: %s has been successfully injected!" %(scenario))
|
||||
logging.info("Waiting for the specified duration: %s" %(wait_duration))
|
||||
time.sleep(wait_duration)
|
||||
logging.info("Injecting scenario: %s" % (scenario))
|
||||
runcommand.invoke("powerfulseal autonomous --use-pod-delete-instead-of-ssh-kill "
|
||||
"--policy-file %s --kubeconfig %s --no-cloud "
|
||||
"--inventory-kubernetes --headless" % (scenario, kubeconfig_path))
|
||||
logging.info("Scenario: %s has been successfully injected!" % (scenario))
|
||||
logging.info("Waiting for the specified duration: %s" % (wait_duration))
|
||||
time.sleep(wait_duration)
|
||||
if cerberus_enabled:
|
||||
cerberus_url = config["cerberus"]["cerberus_url"]
|
||||
if not cerberus_url:
|
||||
logging.error("url where Cerberus publishes True/False signal is not provided.")
|
||||
logging.error("url where Cerberus publishes True/False signal "
|
||||
"is not provided.")
|
||||
sys.exit(1)
|
||||
cerberus_status = requests.get(cerberus_url).content
|
||||
cerberus_status = True if cerberus_status == b'True' else False
|
||||
if not cerberus_status:
|
||||
logging.error("Received a no-go signal from Cerberus, looks like the cluster is unhealthy. Please check the Cerberus report for more details. Test failed.")
|
||||
logging.error("Received a no-go signal from Cerberus, looks like the "
|
||||
"cluster is unhealthy. Please check the Cerberus report "
|
||||
"for more details. Test failed.")
|
||||
sys.exit(1)
|
||||
else:
|
||||
logging.info("Received a go signal from Ceberus, the cluster is healthy. Test passed.")
|
||||
logging.info("Received a go signal from Ceberus, the cluster is healthy. "
|
||||
"Test passed.")
|
||||
except Exception as e:
|
||||
logging.error("Failed to run scenario: %s. Encountered the following exception: %s" %(scenario, e))
|
||||
logging.error("Failed to run scenario: %s. Encountered the following exception: %s"
|
||||
% (scenario, e))
|
||||
else:
|
||||
logging.error("Cannot find a config at %s, please check" % (cfg))
|
||||
sys.exit(1)
|
||||
|
||||
46
setup.cfg
Normal file
46
setup.cfg
Normal file
@@ -0,0 +1,46 @@
|
||||
[metadata]
|
||||
name = kraken
|
||||
description = Chaos and resiliency testing tool
|
||||
author = chaitanyaenr
|
||||
author-email = nelluri@redhat.com
|
||||
license = mit
|
||||
long-description = file: README.md
|
||||
long-description-content-type = text/markdown; charset=UTF-8
|
||||
classifiers =
|
||||
Development Status :: 4 - Beta
|
||||
Programming Language :: Python
|
||||
|
||||
[options]
|
||||
zip_safe = False
|
||||
packages = find:
|
||||
include_package_data = True
|
||||
package_dir =
|
||||
=kraken
|
||||
# Add here dependencies of your project (semicolon/line-separated), e.g.
|
||||
install_requires = PyYAML
|
||||
# tests_require = pytest; pytest-cov
|
||||
# Require a specific Python version, e.g. Python 2.7 or >= 3.4
|
||||
# python_requires = >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*
|
||||
|
||||
[options.packages.find]
|
||||
where = src
|
||||
|
||||
[options.extras_require]
|
||||
# Add here additional requirements for extra features, to install with:
|
||||
# `pip install touchstone[PDF]` like:
|
||||
# PDF = ReportLab; RXP
|
||||
|
||||
[aliases]
|
||||
dists = bdist_wheel
|
||||
|
||||
[bdist_wheel]
|
||||
# Use this option if your package is pure-python
|
||||
universal = 1
|
||||
|
||||
[flake8]
|
||||
# Some sane defaults for the code style checker flake8
|
||||
exclude =
|
||||
.tox
|
||||
build
|
||||
dist
|
||||
.eggsse
|
||||
15
setup.py
Normal file
15
setup.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
|
||||
from pkg_resources import VersionConflict, require
|
||||
from setuptools import setup
|
||||
|
||||
try:
|
||||
require('setuptools>=38.3')
|
||||
except VersionConflict:
|
||||
print("Error: version of setuptools is too old (<38.3)!")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup()
|
||||
2
test-requirements.txt
Normal file
2
test-requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
setuptools
|
||||
flake8
|
||||
24
tox.ini
Normal file
24
tox.ini
Normal file
@@ -0,0 +1,24 @@
|
||||
[tox]
|
||||
envlist = pep8
|
||||
|
||||
[testenv]
|
||||
usedevelop = True
|
||||
setenv =
|
||||
VIRTUAL_ENV={envdir}
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
commands = python setup.py develop
|
||||
|
||||
[testenv:pep8]
|
||||
basepython = python
|
||||
commands = flake8 {posargs}
|
||||
|
||||
[testenv:venv]
|
||||
commands = {posargs}
|
||||
|
||||
[flake8]
|
||||
# E123, E125 skipped as they are invalid PEP-8.
|
||||
show-source = True
|
||||
max-line-length = 100
|
||||
ignore = E123,E125
|
||||
builtins = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
|
||||
Reference in New Issue
Block a user