Skip to content

Commit 5178563

Browse files
authored
Merge pull request #374 from napalm-automation/code-refresh
Code refresh: drop Python 3.6 (and earlier support) and ZMQ 2
2 parents 1aaebb6 + 06f812e commit 5178563

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1922
-1928
lines changed

.github/workflows/code.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ jobs:
1414

1515
runs-on: ubuntu-latest
1616
strategy:
17+
max-parallel: 4
1718
matrix:
18-
python-version: [3.6, 3.7]
19+
python-version: [3.7, 3.8, 3.9, 3.10.8]
1920

2021
steps:
2122
- uses: actions/checkout@v2
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
on:
2+
push:
3+
tags:
4+
- '.*'
5+
workflow_run:
6+
workflows: ["Test code"]
7+
branches: [master, develop]
8+
types:
9+
- completed
10+
11+
name: Docker Build
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Check Out Repo
18+
uses: actions/checkout@v2
19+
20+
- name: Login to Docker Hub
21+
uses: docker/login-action@v1
22+
with:
23+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
24+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
25+
26+
- name: Set up Docker Buildx
27+
id: buildx
28+
uses: docker/setup-buildx-action@v1
29+
30+
- name: Extract tag name
31+
id: extract_tag_name
32+
shell: bash
33+
run: echo "##[set-output name=tag;]$(echo ${GITHUB_REF##*/})"
34+
35+
- name: Build and push
36+
id: docker_build
37+
uses: docker/build-push-action@v2
38+
with:
39+
context: ./
40+
file: ./Dockerfile
41+
push: true
42+
tags: napalmautomation/napalm-logs:${{ steps.extract_tag_name.outputs.tag }}
43+
44+
- name: Image digest
45+
run: echo ${{ steps.docker_build.outputs.digest }}

.github/workflows/pythonpublish.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ jobs:
1313
- name: Set up Python
1414
uses: actions/setup-python@v1
1515
with:
16-
python-version: '3.x'
16+
python-version: '3.9'
1717
- name: Install dependencies
1818
run: |
1919
python -m pip install --upgrade pip
20-
pip install setuptools wheel twine
21-
- name: Build and publish
22-
env:
23-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
24-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
20+
pip install setuptools wheel
21+
- name: Build
2522
run: |
2623
python setup.py sdist bdist_wheel
27-
twine upload dist/*
24+
- name: Publish
25+
uses: pypa/gh-action-pypi-publish@master
26+
with:
27+
user: __token__
28+
password: ${{ secrets.PYPI_TOKEN }}

Dockerfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
FROM python:3.6-alpine
1+
FROM python:3.9-slim-buster
22

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

66
# Install napalm-logs and pre-requisites
7-
RUN apk add --no-cache \
8-
libffi \
9-
libffi-dev \
10-
python3-dev \
11-
build-base \
12-
&& pip --no-cache-dir install cffi pyzmq==19.0.2 /var/cache/napalm-logs/ \
13-
&& rm -rf /var/cache/napalm-logs/
14-
15-
CMD napalm-logs --config-file /etc/napalm/logs
7+
RUN apt-get update \
8+
&& apt-get install -y dumb-init python3-dev python3-cffi libffi-dev \
9+
&& pip --no-cache-dir install -U pip \
10+
&& pip --no-cache-dir install /var/cache/napalm-logs/ \
11+
&& rm -rf /var/cache/napalm-logs/
12+
13+
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
14+
15+
CMD ["napalm-logs", "--config-file", "/etc/napalm/logs"]

docs/conf.py

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
# Import third party libs
2525
import jinja2
2626

27-
sys.path.insert(0, os.path.abspath('../'))
28-
sys.path.insert(0, os.path.abspath('_themes'))
27+
sys.path.insert(0, os.path.abspath("../"))
28+
sys.path.insert(0, os.path.abspath("_themes"))
2929

3030
import napalm_logs # noqa
3131
from napalm_logs.base import NapalmLogs # noqa
@@ -42,30 +42,30 @@
4242
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4343
# ones.
4444
extensions = [
45-
'sphinx.ext.autodoc',
46-
'sphinx.ext.doctest',
47-
'sphinx.ext.intersphinx',
48-
'sphinx.ext.coverage',
49-
'sphinx.ext.viewcode',
50-
'sphinx.ext.githubpages',
45+
"sphinx.ext.autodoc",
46+
"sphinx.ext.doctest",
47+
"sphinx.ext.intersphinx",
48+
"sphinx.ext.coverage",
49+
"sphinx.ext.viewcode",
50+
"sphinx.ext.githubpages",
5151
]
5252

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

5656
# The suffix(es) of source filenames.
5757
# You can specify multiple suffix as a list of string:
5858
#
5959
# source_suffix = ['.rst', '.md']
60-
source_suffix = '.rst'
60+
source_suffix = ".rst"
6161

6262
# The master toctree document.
63-
master_doc = 'index'
63+
master_doc = "index"
6464

6565
# General information about the project.
66-
project = u'napalm-logs'
67-
copyright = u'2017-2019, Mircea Ulinic'
68-
author = u'Mircea Ulinic'
66+
project = "napalm-logs"
67+
copyright = "2017-2019, Mircea Ulinic"
68+
author = "Mircea Ulinic"
6969

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

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

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

104104
# Theme options are theme-specific and customize the look and feel of a theme
105105
# further. For a list of options available for each theme, see the
106106
# documentation.
107107
#
108108
html_theme_options = {
109-
'show_powered_by': False,
110-
'github_user': 'napalm-automation',
111-
'github_repo': 'napalm-logs',
112-
'github_banner': True,
113-
'show_related': False,
109+
"show_powered_by": False,
110+
"github_user": "napalm-automation",
111+
"github_repo": "napalm-logs",
112+
"github_banner": True,
113+
"show_related": False,
114114
}
115115

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

121121
# Custom sidebar templates, must be a dictionary that maps document names
122122
# to template names.
123123
#
124124
# This is required for the alabaster theme
125125
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
126126
html_sidebars = {
127-
'**': [
128-
'about.html',
129-
'navigation.html',
130-
'links.html',
131-
'relations.html', # needs 'show_related': True theme option to display
132-
'searchbox.html',
133-
'donate.html',
127+
"**": [
128+
"about.html",
129+
"navigation.html",
130+
"links.html",
131+
"relations.html", # needs 'show_related': True theme option to display
132+
"searchbox.html",
133+
"donate.html",
134134
]
135135
}
136136

@@ -146,7 +146,7 @@
146146
# -- Options for HTMLHelp output ------------------------------------------
147147

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

151151

152152
# -- Options for LaTeX output ---------------------------------------------
@@ -172,10 +172,10 @@
172172
latex_documents = [
173173
(
174174
master_doc,
175-
'napalm-logs.tex',
176-
u'napalm-logs Documentation',
177-
u'Mircea Ulinic',
178-
'manual',
175+
"napalm-logs.tex",
176+
"napalm-logs Documentation",
177+
"Mircea Ulinic",
178+
"manual",
179179
),
180180
]
181181

@@ -184,7 +184,7 @@
184184

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

189189

190190
# -- Options for Texinfo output -------------------------------------------
@@ -195,15 +195,15 @@
195195
texinfo_documents = [
196196
(
197197
master_doc,
198-
'napalm-logs',
199-
u'napalm-logs Documentation',
198+
"napalm-logs",
199+
"napalm-logs Documentation",
200200
author,
201-
'napalm-logs',
201+
"napalm-logs",
202202
(
203-
'napalm-logs is a Python library that listens to syslog messages from network devices and returns strucuted data'
204-
'following the OpenConfig or IETF YANG models'
203+
"napalm-logs is a Python library that listens to syslog messages from network devices and returns strucuted data"
204+
"following the OpenConfig or IETF YANG models"
205205
),
206-
'Miscellaneous',
206+
"Miscellaneous",
207207
),
208208
]
209209

@@ -225,7 +225,7 @@
225225
# epub_uid = ''
226226

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

230230

231231
def gen_messages_rst():
@@ -250,71 +250,71 @@ def gen_messages_rst():
250250
nl_ = NapalmLogs(publisher=[])
251251
defined_errors = {}
252252
for os_name, os_cfg in nl_.config_dict.items():
253-
for message in os_cfg['messages']:
254-
error_name = message['error']
253+
for message in os_cfg["messages"]:
254+
error_name = message["error"]
255255
if error_name not in defined_errors:
256-
defined_errors[error_name] = {'doc': '', 'os': [], 'model': ''}
257-
if not defined_errors[error_name]['doc'] or len(
258-
defined_errors[error_name]['doc']
259-
) < len(message['__doc__']):
260-
defined_errors[error_name]['doc'] = message['__doc__']
261-
if not defined_errors[error_name]['model']:
262-
defined_errors[error_name]['model'] = message['model']
263-
defined_errors[error_name]['os'].append(os_name)
256+
defined_errors[error_name] = {"doc": "", "os": [], "model": ""}
257+
if not defined_errors[error_name]["doc"] or len(
258+
defined_errors[error_name]["doc"]
259+
) < len(message["__doc__"]):
260+
defined_errors[error_name]["doc"] = message["__doc__"]
261+
if not defined_errors[error_name]["model"]:
262+
defined_errors[error_name]["model"] = message["model"]
263+
defined_errors[error_name]["os"].append(os_name)
264264
# The collect the mock data from the tests:
265265
cwd = os.path.dirname(__file__)
266-
test_root_path = os.path.join(cwd, '..', 'tests', 'config')
267-
env = jinja2.Environment(loader=jinja2.FileSystemLoader('.'))
266+
test_root_path = os.path.join(cwd, "..", "tests", "config")
267+
env = jinja2.Environment(loader=jinja2.FileSystemLoader("."))
268268
for error_name, error_details in defined_errors.items():
269-
os_name = error_details['os'][0] # Picking up the first OS in the list.
269+
os_name = error_details["os"][0] # Picking up the first OS in the list.
270270
error_path = os.path.join(test_root_path, os_name, error_name)
271271
test_cases = [
272272
name
273273
for name in os.listdir(error_path)
274274
if os.path.isdir(os.path.join(error_path, name))
275275
]
276276
test_case_name = (
277-
'default' if 'default' in test_cases else test_cases[0]
277+
"default" if "default" in test_cases else test_cases[0]
278278
) # Picking up a test case.
279279
test_case_path = os.path.join(error_path, test_case_name)
280-
raw_message_filepath = os.path.join(test_case_path, 'syslog.msg')
281-
log.debug('Looking for %s', raw_message_filepath)
280+
raw_message_filepath = os.path.join(test_case_path, "syslog.msg")
281+
log.debug("Looking for %s", raw_message_filepath)
282282
assert os.path.isfile(raw_message_filepath)
283-
with open(raw_message_filepath, 'r') as raw_message_fh:
283+
with open(raw_message_filepath, "r") as raw_message_fh:
284284
raw_message = raw_message_fh.read()
285-
log.debug('Read raw message:')
285+
log.debug("Read raw message:")
286286
log.debug(raw_message)
287-
yang_message_filepath = os.path.join(test_case_path, 'yang.json')
288-
log.debug('Looking for %s', yang_message_filepath)
287+
yang_message_filepath = os.path.join(test_case_path, "yang.json")
288+
log.debug("Looking for %s", yang_message_filepath)
289289
assert os.path.isfile(yang_message_filepath)
290-
with open(yang_message_filepath, 'r') as yang_message_fh:
290+
with open(yang_message_filepath, "r") as yang_message_fh:
291291
yang_message = yang_message_fh.read()
292-
log.debug('Read YANG text:')
292+
log.debug("Read YANG text:")
293293
log.debug(yang_message)
294294
struct_yang_message = json.loads(yang_message)
295295
indented_yang_message = json.dumps(
296296
struct_yang_message, indent=4, sort_keys=True
297297
)
298-
log.debug('Struct YANG message:')
298+
log.debug("Struct YANG message:")
299299
log.debug(struct_yang_message)
300-
msg_template = env.get_template('message_template.jinja')
300+
msg_template = env.get_template("message_template.jinja")
301301
rendered_template = msg_template.render(
302302
error_name=error_name,
303-
error_doc=error_details['doc'],
304-
error_yang=error_details['model'],
305-
error_os_list=list(set(error_details['os'])),
303+
error_doc=error_details["doc"],
304+
error_yang=error_details["model"],
305+
error_os_list=list(set(error_details["os"])),
306306
error_txt_example=raw_message.strip(),
307-
error_json_example=indented_yang_message.replace('\n}', '\n }'),
307+
error_json_example=indented_yang_message.replace("\n}", "\n }"),
308308
)
309-
message_rst_path = 'messages/{error_name}.rst'.format(error_name=error_name)
310-
with open(message_rst_path, 'w') as rst_fh:
309+
message_rst_path = "messages/{error_name}.rst".format(error_name=error_name)
310+
with open(message_rst_path, "w") as rst_fh:
311311
rst_fh.write(rendered_template)
312-
index_tpl_file = env.get_template('messages_index_template.jinja')
312+
index_tpl_file = env.get_template("messages_index_template.jinja")
313313
messages_list = list(defined_errors.keys())
314-
messages_list.extend(['RAW', 'UNKNOWN'])
314+
messages_list.extend(["RAW", "UNKNOWN"])
315315
messages_list.sort()
316316
rendered_template = index_tpl_file.render(error_list=messages_list)
317-
with open('messages/index.rst', 'w') as index_fh:
317+
with open("messages/index.rst", "w") as index_fh:
318318
index_fh.write(rendered_template)
319319

320320

0 commit comments

Comments
 (0)