Skip to content

Commit

Permalink
Initial skeleton from napalm cookiecutter
Browse files Browse the repository at this point in the history
  • Loading branch information
skg-net committed Feb 12, 2018
1 parent 5a90123 commit 9853801
Show file tree
Hide file tree
Showing 24 changed files with 254 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Senthil Kumar Ganesan <[email protected]>
1 change: 1 addition & 0 deletions CONTRIBUTING
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please, read http://napalm.readthedocs.io/en/latest/contributing/index.html
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include requirements.txt
include napalm_dellos10/templates/*.j2
include napalm_dellos10/utils/textfsm_templates/*.tpl
16 changes: 16 additions & 0 deletions napalm_dellos10/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2016 Dravetech AB. All rights reserved.
#
# The contents of this file are licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

"""napalm-dellos10 package."""
from dellos10 import Dellos10Driver
51 changes: 51 additions & 0 deletions napalm_dellos10/dellos10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2016 Dravetech AB. All rights reserved.
#
# The contents of this file are licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

"""
Napalm driver for Dellos10.
Read https://napalm.readthedocs.io for more information.
"""

from napalm_base.base import NetworkDriver
from napalm_base.exceptions import (
ConnectionException,
SessionLockedException,
MergeConfigException,
ReplaceConfigException,
CommandErrorException,
)


class Dellos10Driver(NetworkDriver):
"""Napalm driver for Dellos10."""

def __init__(self, hostname, username, password, timeout=60, optional_args=None):
"""Constructor."""
self.device = None
self.hostname = hostname
self.username = username
self.password = password
self.timeout = timeout

if optional_args is None:
optional_args = {}

def open(self):
"""Implementation of NAPALM method open."""
pass

def close(self):
"""Implementation of NAPALM method close."""
pass
Empty file.
1 change: 1 addition & 0 deletions napalm_dellos10/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""napalm.utils package."""
Empty file.
8 changes: 8 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
future >= 0.13.1, <1
pytest
pytest-cov
pytest-json
pytest-pythonpath
pylama
flake8-import-order
-r requirements.txt
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
napalm_base
15 changes: 15 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[pylama]
linters = mccabe,pep257,pep8,pyflakes,import_order
ignore = D203

[pylama:pep8]
max_line_length = 100

[pytest]
addopts = --cov=napalm_dellos10 --cov-report term-missing -vs --pylama
json_report = report.json
jsonapi = true

[coverage:run]
include =
napalm_skeleton/*
31 changes: 31 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""setup.py file."""

import uuid

from setuptools import setup, find_packages
from pip.req import parse_requirements

__author__ = 'Senthil Kumar Ganesan <[email protected]>'

install_reqs = parse_requirements('requirements.txt', session=uuid.uuid1())
reqs = [str(ir.req) for ir in install_reqs]

setup(
name="napalm-dellos10",
version="0.1.0",
packages=find_packages(),
author="Senthil Kumar Ganesan",
author_email="[email protected]",
description="NAPALM driver for Dell EMC Networking OS10 Operating System.",
classifiers=[
'Topic :: Utilities',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS',
],
url="https://github.com/skg-net/napalm-dellos10",
include_package_data=True,
install_requires=reqs,
)
40 changes: 40 additions & 0 deletions test/unit/TestDellos10Driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2016 Dravetech AB. All rights reserved.
#
# The contents of this file are licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

"""Tests."""

import unittest

from napalm_dellos10 import dellos10
from napalm_base.test.base import TestConfigNetworkDriver


class TestConfigDellos10Driver(unittest.TestCase, TestConfigNetworkDriver):
"""Group of tests that test Configuration related methods."""

@classmethod
def setUpClass(cls):
"""Run before starting the tests."""
hostname = '127.0.0.1'
username = 'vagrant'
password = 'vagrant'
cls.vendor = 'dellos10'

optional_args = {'port': 12443, }
cls.device = dellos10.Dellos10Driver(hostname, username, password, timeout=60,
optional_args=optional_args)
cls.device.open()

cls.device.load_replace_candidate(filename='%s/initial.conf' % cls.vendor)
cls.device.commit_config()
57 changes: 57 additions & 0 deletions test/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Test fixtures."""
from builtins import super

import pytest
from napalm_base.test import conftest as parent_conftest

from napalm_base.test.double import BaseTestDouble

from napalm_dellos10 import dellos10


@pytest.fixture(scope='class')
def set_device_parameters(request):
"""Set up the class."""
def fin():
request.cls.device.close()
request.addfinalizer(fin)

request.cls.driver = dellos10.Dellos10Driver
request.cls.patched_driver = PatchedDellos10Driver
request.cls.vendor = 'dellos10'
parent_conftest.set_device_parameters(request)


def pytest_generate_tests(metafunc):
"""Generate test cases dynamically."""
parent_conftest.pytest_generate_tests(metafunc, __file__)


class PatchedDellos10Driver(dellos10.Dellos10Driver):
"""Patched Dellos10 Driver."""

def __init__(self, hostname, username, password, timeout=60, optional_args=None):
"""Patched Dellos10 Driver constructor."""
super().__init__(hostname, username, password, timeout, optional_args)

self.patched_attrs = ['device']
self.device = FakeDellos10Device()


class FakeDellos10Device(BaseTestDouble):
"""Dellos10 device test double."""

def run_commands(self, command_list, encoding='json'):
"""Fake run_commands."""
result = list()

for command in command_list:
filename = '{}.{}'.format(self.sanitize_text(command), encoding)
full_path = self.find_file(filename)

if encoding == 'json':
result.append(self.read_json_file(full_path))
else:
result.append({'output': self.read_txt_file(full_path)})

return result
1 change: 1 addition & 0 deletions test/unit/dellos10/initial.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Initial configuration
1 change: 1 addition & 0 deletions test/unit/dellos10/merge_good.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some changes that will be merged while testing
1 change: 1 addition & 0 deletions test/unit/dellos10/merge_good.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The diff when merging `merged_good.conf`
2 changes: 2 additions & 0 deletions test/unit/dellos10/merge_typo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Some changes that will be merge while testing. Should contain a typo or something that triggers
an error during the load/commmit phase
Empty file.
1 change: 1 addition & 0 deletions test/unit/dellos10/new_good.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A full new configuration. It will be used to test the replace operation
1 change: 1 addition & 0 deletions test/unit/dellos10/new_good.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A diff between `initial.conf` and `new_good.conf`
2 changes: 2 additions & 0 deletions test/unit/dellos10/new_typo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A full new configuration. However, it should contain a typo or something that triggers an error
during commit/load phase.
11 changes: 11 additions & 0 deletions test/unit/test_getters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Tests for getters."""

from napalm_base.test.getters import BaseTestGetters


import pytest


@pytest.mark.usefixtures("set_device_parameters")
class TestGetter(BaseTestGetters):
"""Test get_* methods."""
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tox]
envlist = py27,py34,py35

[testenv]
deps =
-rrequirements-dev.txt

commands=
py.test

0 comments on commit 9853801

Please sign in to comment.