Skip to content

Commit

Permalink
Merge pull request #374 from napalm-automation/code-refresh
Browse files Browse the repository at this point in the history
Code refresh: drop Python 3.6 (and earlier support) and ZMQ 2
  • Loading branch information
mirceaulinic authored Nov 8, 2022
2 parents 1aaebb6 + 06f812e commit 5178563
Show file tree
Hide file tree
Showing 56 changed files with 1,922 additions and 1,928 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ jobs:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7]
python-version: [3.7, 3.8, 3.9, 3.10.8]

steps:
- uses: actions/checkout@v2
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/docker_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on:
push:
tags:
- '.*'
workflow_run:
workflows: ["Test code"]
branches: [master, develop]
types:
- completed

name: Docker Build
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check Out Repo
uses: actions/checkout@v2

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Extract tag name
id: extract_tag_name
shell: bash
run: echo "##[set-output name=tag;]$(echo ${GITHUB_REF##*/})"

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
push: true
tags: napalmautomation/napalm-logs:${{ steps.extract_tag_name.outputs.tag }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
15 changes: 8 additions & 7 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
pip install setuptools wheel
- name: Build
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Publish
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM python:3.6-alpine
FROM python:3.9-slim-buster

COPY docker/config.txt /etc/napalm/logs
COPY ./ /var/cache/napalm-logs/

# Install napalm-logs and pre-requisites
RUN apk add --no-cache \
libffi \
libffi-dev \
python3-dev \
build-base \
&& pip --no-cache-dir install cffi pyzmq==19.0.2 /var/cache/napalm-logs/ \
&& rm -rf /var/cache/napalm-logs/

CMD napalm-logs --config-file /etc/napalm/logs
RUN apt-get update \
&& apt-get install -y dumb-init python3-dev python3-cffi libffi-dev \
&& pip --no-cache-dir install -U pip \
&& pip --no-cache-dir install /var/cache/napalm-logs/ \
&& rm -rf /var/cache/napalm-logs/

ENTRYPOINT ["/usr/bin/dumb-init", "--"]

CMD ["napalm-logs", "--config-file", "/etc/napalm/logs"]
152 changes: 76 additions & 76 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
# Import third party libs
import jinja2

sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.abspath('_themes'))
sys.path.insert(0, os.path.abspath("../"))
sys.path.insert(0, os.path.abspath("_themes"))

import napalm_logs # noqa
from napalm_logs.base import NapalmLogs # noqa
Expand All @@ -42,30 +42,30 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
"sphinx.ext.githubpages",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'napalm-logs'
copyright = u'2017-2019, Mircea Ulinic'
author = u'Mircea Ulinic'
project = "napalm-logs"
copyright = "2017-2019, Mircea Ulinic"
author = "Mircea Ulinic"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -86,10 +86,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'flask_theme_support.FlaskyStyle'
pygments_style = "flask_theme_support.FlaskyStyle"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -99,38 +99,38 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'show_powered_by': False,
'github_user': 'napalm-automation',
'github_repo': 'napalm-logs',
'github_banner': True,
'show_related': False,
"show_powered_by": False,
"github_user": "napalm-automation",
"github_repo": "napalm-logs",
"github_banner": True,
"show_related": False,
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'about.html',
'navigation.html',
'links.html',
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
'donate.html',
"**": [
"about.html",
"navigation.html",
"links.html",
"relations.html", # needs 'show_related': True theme option to display
"searchbox.html",
"donate.html",
]
}

Expand All @@ -146,7 +146,7 @@
# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'napalm-logsdoc'
htmlhelp_basename = "napalm-logsdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -172,10 +172,10 @@
latex_documents = [
(
master_doc,
'napalm-logs.tex',
u'napalm-logs Documentation',
u'Mircea Ulinic',
'manual',
"napalm-logs.tex",
"napalm-logs Documentation",
"Mircea Ulinic",
"manual",
),
]

Expand All @@ -184,7 +184,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, 'napalm-logs', u'napalm-logs Documentation', [author], 1)]
man_pages = [(master_doc, "napalm-logs", "napalm-logs Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -195,15 +195,15 @@
texinfo_documents = [
(
master_doc,
'napalm-logs',
u'napalm-logs Documentation',
"napalm-logs",
"napalm-logs Documentation",
author,
'napalm-logs',
"napalm-logs",
(
'napalm-logs is a Python library that listens to syslog messages from network devices and returns strucuted data'
'following the OpenConfig or IETF YANG models'
"napalm-logs is a Python library that listens to syslog messages from network devices and returns strucuted data"
"following the OpenConfig or IETF YANG models"
),
'Miscellaneous',
"Miscellaneous",
),
]

Expand All @@ -225,7 +225,7 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]


def gen_messages_rst():
Expand All @@ -250,71 +250,71 @@ def gen_messages_rst():
nl_ = NapalmLogs(publisher=[])
defined_errors = {}
for os_name, os_cfg in nl_.config_dict.items():
for message in os_cfg['messages']:
error_name = message['error']
for message in os_cfg["messages"]:
error_name = message["error"]
if error_name not in defined_errors:
defined_errors[error_name] = {'doc': '', 'os': [], 'model': ''}
if not defined_errors[error_name]['doc'] or len(
defined_errors[error_name]['doc']
) < len(message['__doc__']):
defined_errors[error_name]['doc'] = message['__doc__']
if not defined_errors[error_name]['model']:
defined_errors[error_name]['model'] = message['model']
defined_errors[error_name]['os'].append(os_name)
defined_errors[error_name] = {"doc": "", "os": [], "model": ""}
if not defined_errors[error_name]["doc"] or len(
defined_errors[error_name]["doc"]
) < len(message["__doc__"]):
defined_errors[error_name]["doc"] = message["__doc__"]
if not defined_errors[error_name]["model"]:
defined_errors[error_name]["model"] = message["model"]
defined_errors[error_name]["os"].append(os_name)
# The collect the mock data from the tests:
cwd = os.path.dirname(__file__)
test_root_path = os.path.join(cwd, '..', 'tests', 'config')
env = jinja2.Environment(loader=jinja2.FileSystemLoader('.'))
test_root_path = os.path.join(cwd, "..", "tests", "config")
env = jinja2.Environment(loader=jinja2.FileSystemLoader("."))
for error_name, error_details in defined_errors.items():
os_name = error_details['os'][0] # Picking up the first OS in the list.
os_name = error_details["os"][0] # Picking up the first OS in the list.
error_path = os.path.join(test_root_path, os_name, error_name)
test_cases = [
name
for name in os.listdir(error_path)
if os.path.isdir(os.path.join(error_path, name))
]
test_case_name = (
'default' if 'default' in test_cases else test_cases[0]
"default" if "default" in test_cases else test_cases[0]
) # Picking up a test case.
test_case_path = os.path.join(error_path, test_case_name)
raw_message_filepath = os.path.join(test_case_path, 'syslog.msg')
log.debug('Looking for %s', raw_message_filepath)
raw_message_filepath = os.path.join(test_case_path, "syslog.msg")
log.debug("Looking for %s", raw_message_filepath)
assert os.path.isfile(raw_message_filepath)
with open(raw_message_filepath, 'r') as raw_message_fh:
with open(raw_message_filepath, "r") as raw_message_fh:
raw_message = raw_message_fh.read()
log.debug('Read raw message:')
log.debug("Read raw message:")
log.debug(raw_message)
yang_message_filepath = os.path.join(test_case_path, 'yang.json')
log.debug('Looking for %s', yang_message_filepath)
yang_message_filepath = os.path.join(test_case_path, "yang.json")
log.debug("Looking for %s", yang_message_filepath)
assert os.path.isfile(yang_message_filepath)
with open(yang_message_filepath, 'r') as yang_message_fh:
with open(yang_message_filepath, "r") as yang_message_fh:
yang_message = yang_message_fh.read()
log.debug('Read YANG text:')
log.debug("Read YANG text:")
log.debug(yang_message)
struct_yang_message = json.loads(yang_message)
indented_yang_message = json.dumps(
struct_yang_message, indent=4, sort_keys=True
)
log.debug('Struct YANG message:')
log.debug("Struct YANG message:")
log.debug(struct_yang_message)
msg_template = env.get_template('message_template.jinja')
msg_template = env.get_template("message_template.jinja")
rendered_template = msg_template.render(
error_name=error_name,
error_doc=error_details['doc'],
error_yang=error_details['model'],
error_os_list=list(set(error_details['os'])),
error_doc=error_details["doc"],
error_yang=error_details["model"],
error_os_list=list(set(error_details["os"])),
error_txt_example=raw_message.strip(),
error_json_example=indented_yang_message.replace('\n}', '\n }'),
error_json_example=indented_yang_message.replace("\n}", "\n }"),
)
message_rst_path = 'messages/{error_name}.rst'.format(error_name=error_name)
with open(message_rst_path, 'w') as rst_fh:
message_rst_path = "messages/{error_name}.rst".format(error_name=error_name)
with open(message_rst_path, "w") as rst_fh:
rst_fh.write(rendered_template)
index_tpl_file = env.get_template('messages_index_template.jinja')
index_tpl_file = env.get_template("messages_index_template.jinja")
messages_list = list(defined_errors.keys())
messages_list.extend(['RAW', 'UNKNOWN'])
messages_list.extend(["RAW", "UNKNOWN"])
messages_list.sort()
rendered_template = index_tpl_file.render(error_list=messages_list)
with open('messages/index.rst', 'w') as index_fh:
with open("messages/index.rst", "w") as index_fh:
index_fh.write(rendered_template)


Expand Down
Loading

0 comments on commit 5178563

Please sign in to comment.