diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..45fff23 --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Senthil Kumar Ganesan diff --git a/CONTRIBUTING b/CONTRIBUTING new file mode 100644 index 0000000..6ccfd34 --- /dev/null +++ b/CONTRIBUTING @@ -0,0 +1 @@ +Please, read http://napalm.readthedocs.io/en/latest/contributing/index.html diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..89182bd --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include requirements.txt +include napalm_dellos10/templates/*.j2 +include napalm_dellos10/utils/textfsm_templates/*.tpl diff --git a/napalm_dellos10/__init__.py b/napalm_dellos10/__init__.py new file mode 100644 index 0000000..1bf7a24 --- /dev/null +++ b/napalm_dellos10/__init__.py @@ -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 diff --git a/napalm_dellos10/dellos10.py b/napalm_dellos10/dellos10.py new file mode 100644 index 0000000..6090e68 --- /dev/null +++ b/napalm_dellos10/dellos10.py @@ -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 diff --git a/napalm_dellos10/templates/.placeholder b/napalm_dellos10/templates/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/napalm_dellos10/utils/__init__.py b/napalm_dellos10/utils/__init__.py new file mode 100644 index 0000000..678164a --- /dev/null +++ b/napalm_dellos10/utils/__init__.py @@ -0,0 +1 @@ +"""napalm.utils package.""" diff --git a/napalm_dellos10/utils/textfsm_templates/.placeholder b/napalm_dellos10/utils/textfsm_templates/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..31014be --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,8 @@ +future >= 0.13.1, <1 +pytest +pytest-cov +pytest-json +pytest-pythonpath +pylama +flake8-import-order +-r requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d140051 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +napalm_base diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..3472be0 --- /dev/null +++ b/setup.cfg @@ -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/* diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c03f184 --- /dev/null +++ b/setup.py @@ -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 ' + +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="skg.dev.net@gmail.com", + 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, +) diff --git a/test/unit/TestDellos10Driver.py b/test/unit/TestDellos10Driver.py new file mode 100644 index 0000000..addbe2f --- /dev/null +++ b/test/unit/TestDellos10Driver.py @@ -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() diff --git a/test/unit/conftest.py b/test/unit/conftest.py new file mode 100644 index 0000000..b501130 --- /dev/null +++ b/test/unit/conftest.py @@ -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 diff --git a/test/unit/dellos10/initial.conf b/test/unit/dellos10/initial.conf new file mode 100644 index 0000000..859698e --- /dev/null +++ b/test/unit/dellos10/initial.conf @@ -0,0 +1 @@ +Initial configuration diff --git a/test/unit/dellos10/merge_good.conf b/test/unit/dellos10/merge_good.conf new file mode 100644 index 0000000..89ef127 --- /dev/null +++ b/test/unit/dellos10/merge_good.conf @@ -0,0 +1 @@ +Some changes that will be merged while testing diff --git a/test/unit/dellos10/merge_good.diff b/test/unit/dellos10/merge_good.diff new file mode 100644 index 0000000..2b6918c --- /dev/null +++ b/test/unit/dellos10/merge_good.diff @@ -0,0 +1 @@ +The diff when merging `merged_good.conf` diff --git a/test/unit/dellos10/merge_typo.conf b/test/unit/dellos10/merge_typo.conf new file mode 100644 index 0000000..da7e876 --- /dev/null +++ b/test/unit/dellos10/merge_typo.conf @@ -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 diff --git a/test/unit/dellos10/mock_data/.placeholder b/test/unit/dellos10/mock_data/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/test/unit/dellos10/new_good.conf b/test/unit/dellos10/new_good.conf new file mode 100644 index 0000000..e142fa9 --- /dev/null +++ b/test/unit/dellos10/new_good.conf @@ -0,0 +1 @@ +A full new configuration. It will be used to test the replace operation diff --git a/test/unit/dellos10/new_good.diff b/test/unit/dellos10/new_good.diff new file mode 100644 index 0000000..a313d37 --- /dev/null +++ b/test/unit/dellos10/new_good.diff @@ -0,0 +1 @@ +A diff between `initial.conf` and `new_good.conf` diff --git a/test/unit/dellos10/new_typo.conf b/test/unit/dellos10/new_typo.conf new file mode 100644 index 0000000..b97f25f --- /dev/null +++ b/test/unit/dellos10/new_typo.conf @@ -0,0 +1,2 @@ +A full new configuration. However, it should contain a typo or something that triggers an error +during commit/load phase. diff --git a/test/unit/test_getters.py b/test/unit/test_getters.py new file mode 100644 index 0000000..6509001 --- /dev/null +++ b/test/unit/test_getters.py @@ -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.""" diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..7d786bf --- /dev/null +++ b/tox.ini @@ -0,0 +1,9 @@ +[tox] +envlist = py27,py34,py35 + +[testenv] +deps = + -rrequirements-dev.txt + +commands= + py.test