Skip to content

Commit

Permalink
Merge pull request #69 from napalm-automation/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
dbarrosop authored Jul 6, 2017
2 parents 57fdb9e + 1cbcbd0 commit b810bdf
Show file tree
Hide file tree
Showing 57 changed files with 512 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ env

tags
*.swp

.compiled
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: python
python:
- 2.7

env:
- ANSIBLE_VERSION=2.2
- ANSIBLE_VERSION=2.3

install:
- pip install napalm-base
- pip install "ansible>=$ANSIBLE_VERSION.0,<$ANSIBLE_VERSION.99"

script:
- cd tests
# Test configuration dry-run
- ansible-playbook -i napalm_install_config/hosts -l "*.dry_run.*" napalm_install_config/config.yaml -C
# Test configuration commit
- ansible-playbook -i napalm_install_config/hosts -l "*.commit.*" napalm_install_config/config.yaml
# Test configuration errrors
- ansible-playbook -i napalm_install_config/hosts -l "*.error*" napalm_install_config/config_error.yaml
# Test get_facts
- ansible-playbook -i napalm_get_facts/hosts napalm_get_facts/get_facts_ok.yaml -l multiple_facts.ok
- ansible-playbook -i napalm_get_facts/hosts napalm_get_facts/get_facts_not_implemented.yaml -l multiple_facts.not_implemented -e "ignore_notimplemented=true"
- ansible-playbook -i napalm_get_facts/hosts napalm_get_facts/get_facts_not_implemented.yaml -l multiple_facts.not_implemented -e "ignore_notimplemented=false"
- ansible-playbook -i napalm_get_facts/hosts napalm_get_facts/get_facts_error.yaml -l multiple_facts.error
6 changes: 3 additions & 3 deletions library/napalm_get_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
description:
- OS of the device
required: False
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'nxos', 'panos', 'vyos']
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'mock', 'nxos', 'panos', 'vyos']
provider:
description:
- Dictionary which acts as a collection of arguments used to define the characteristics
Expand Down Expand Up @@ -152,7 +152,7 @@


def main():
os_choices = ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'nxos', 'panos', 'vyos', 'ros']
os_choices = ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'mock', 'nxos', 'panos', 'vyos', 'ros']
module = AnsibleModule(
argument_spec=dict(
hostname=dict(type='str', required=False, aliases=['host']),
Expand Down Expand Up @@ -188,7 +188,7 @@ def main():
password = module.params['password']
timeout = module.params['timeout']
filter_list = module.params['filter']
args = module.params.get('args', {})
args = module.params['args'] or {}
ignore_notimplemented = module.params['ignore_notimplemented']
implementation_errors = []

Expand Down
4 changes: 2 additions & 2 deletions library/napalm_install_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
description:
- OS of the device
required: False
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'nxos', 'panos', 'vyos']
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'mock', 'nxos', 'panos', 'vyos']
timeout:
description:
- Time in seconds to wait for the device to respond
Expand Down Expand Up @@ -174,7 +174,7 @@ def save_to_file(content, filename):
f.close()

def main():
os_choices = ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'nxos', 'panos', 'vyos', 'ros']
os_choices = ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'mock', 'nxos', 'panos', 'vyos', 'ros']
module = AnsibleModule(
argument_spec=dict(
hostname=dict(type='str', required=False, aliases=['host']),
Expand Down
6 changes: 3 additions & 3 deletions library/napalm_parse_yang.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
description:
- OS of the device
required: False
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'nxos',
'panos', 'vyos']
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'mock',
'nxos', 'panos', 'vyos']
provider:
description:
- Dictionary which acts as a collection of arguments used to define
Expand Down Expand Up @@ -246,7 +246,7 @@ def parse_from_device(module, os_choices):

def main():
os_choices = ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios',
'nxos', 'panos', 'vyos']
'mock', 'nxos', 'panos', 'vyos']
module = AnsibleModule(
argument_spec=dict(
hostname=dict(type='str', required=False, aliases=['host']),
Expand Down
6 changes: 3 additions & 3 deletions library/napalm_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
description:
- OS of the device.
required: False
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'nxos',
'panos', 'vyos']
choices: ['eos', 'junos', 'iosxr', 'fortios', 'ibm', 'ios', 'mock',
'nxos', 'panos', 'vyos']
provider:
description:
- Dictionary which acts as a collection of arguments used to define
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_root_object(models):

def main():
os_choices = ['eos', 'junos', 'iosxr', 'fortios', 'ibm',
'ios', 'nxos', 'panos', 'vyos']
'ios', 'mock', 'nxos', 'panos', 'vyos']
module = AnsibleModule(
argument_spec=dict(
models=dict(type="list", required=False),
Expand Down
4 changes: 4 additions & 0 deletions tests/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[defaults]
library = ../library/

retry_files_enabled = False
32 changes: 32 additions & 0 deletions tests/napalm_get_facts/get_facts_error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: Get facts
hosts: all
connection: local # code is run locally
gather_facts: no # don't gather facts
tasks:
- block:
- name: get facts from device
napalm_get_facts: # NAPALM plugin
hostname: "{{ host }}" # start of connection parameters
username: "{{ user }}"
dev_os: "{{ os }}"
password: "{{ password }}"
optional_args:
path: "{{ playbook_dir }}/mocked/{{ inventory_hostname }}"
profile: "{{ profile }}"
filter: ['facts', 'route_to', 'interfaces'] # which NAPALM getters to use
args:
route_to:
protocol: static
destination: 8.8.8.8
register: napalm_facts # store information here
- assert:
that:
- napalm_facts.ansible_facts.facts.hostname == "localhost"
- napalm_facts.ansible_facts.interfaces.Ethernet1.mac_address == "08:00:27:C6:00:F0"
rescue:
- debug:
var: ansible_failed_result.msg
- assert:
that:
- "{{ ansible_failed_result.msg == \"[interfaces] cannot retrieve device data: u'Key blah is not present'\" }}"
34 changes: 34 additions & 0 deletions tests/napalm_get_facts/get_facts_not_implemented.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Get facts
hosts: all
connection: local # code is run locally
gather_facts: no # don't gather facts
tasks:
- block:
- name: get facts from device
napalm_get_facts: # NAPALM plugin
hostname: "{{ host }}" # start of connection parameters
username: "{{ user }}"
dev_os: "{{ os }}"
password: "{{ password }}"
optional_args:
path: "{{ playbook_dir }}/mocked/{{ inventory_hostname }}"
profile: "{{ profile }}"
filter: ['facts', 'route_to', 'interfaces'] # which NAPALM getters to use
args:
route_to:
protocol: static
destination: 8.8.8.8
ignore_notimplemented: "{{ ignore_notimplemented }}"
register: napalm_facts # store information here
- assert:
that:
- napalm_facts.ansible_facts.facts.hostname == "localhost"
- napalm_facts.ansible_facts.interfaces.Ethernet1.mac_address == "08:00:27:C6:00:F0"
rescue:
- fail:
msg: Whe shouldn't be here
when: ignore_notimplemented
- assert:
that:
- ansible_failed_result.msg == "The filter route_to is not supported in napalm-mock [get_route_to()]"
26 changes: 26 additions & 0 deletions tests/napalm_get_facts/get_facts_ok.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Get facts
hosts: all
connection: local # code is run locally
gather_facts: no # don't gather facts
tasks:
- name: get facts from device
napalm_get_facts: # NAPALM plugin
hostname: "{{ host }}" # start of connection parameters
username: "{{ user }}"
dev_os: "{{ os }}"
password: "{{ password }}"
optional_args:
path: "{{ playbook_dir }}/mocked/{{ inventory_hostname }}"
profile: "{{ profile }}"
filter: ['facts', 'route_to', 'interfaces'] # which NAPALM getters to use
args:
route_to:
protocol: static
destination: 8.8.8.8
register: napalm_facts # store information here
- assert:
that:
- napalm_facts.ansible_facts.facts.hostname == "localhost"
- "{{ '1.0.4.0/24' in napalm_facts.ansible_facts.route_to }}"
- napalm_facts.ansible_facts.interfaces.Ethernet1.mac_address == "08:00:27:C6:00:F0"
7 changes: 7 additions & 0 deletions tests/napalm_get_facts/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[all]
multiple_facts.ok os=mock host=127.0.0.1 user=vagrant password=vagrant profile=[eos]
multiple_facts.not_implemented os=mock host=127.0.0.1 user=vagrant password=vagrant profile=[eos]
multiple_facts.error os=mock host=127.0.0.1 user=vagrant password=vagrant profile=[eos]

[all:vars]
ansible_python_interpreter="/usr/bin/env python"
16 changes: 16 additions & 0 deletions tests/napalm_get_facts/mocked/multiple_facts.error/get_facts.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"fqdn": "localhost",
"hostname": "localhost",
"interface_list": [
"Ethernet1",
"Ethernet2",
"Ethernet3",
"Ethernet4",
"Management1"
],
"model": "vEOS",
"os_version": "4.15.5M-3054042.4155M",
"serial_number": "",
"uptime": "...",
"vendor": "Arista"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"exception": "KeyError",
"args": [
"Key blah is not present"
],
"kwargs": {}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"1.0.4.0/24": [{"next_hop": "192.168.0.1", "preference": 200, "protocol": "eBGP", "selected_next_hop": true, "current_active": true, "routing_table": "TEST", "protocol_attributes": {"remote_as": 43515, "as_path": "1299 15169 43515", "local_preference": 50, "remote_address": "192.168.0.1", "preference2": 0, "metric": 0, "communities": ["1299:1234", "1299:5678", "1299:91011", "1299:12134"], "local_as": 13335}, "outgoing_interface": "Port-Channel2", "last_active": true, "inactive_reason": "", "age": 0}, {"next_hop": "192.168.0.1", "preference": 200, "protocol": "eBGP", "selected_next_hop": true, "current_active": true, "routing_table": "default", "protocol_attributes": {"remote_as": 43515, "as_path": "1299 15169 43515", "local_preference": 50, "remote_address": "192.168.0.1", "preference2": 0, "metric": 0, "communities": ["1299:1234", "1299:5678", "1299:91011", "1299:12134"], "local_as": 13335}, "outgoing_interface": "Port-Channel2", "last_active": true, "inactive_reason": "", "age": 0}]}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"fqdn": "localhost",
"hostname": "localhost",
"interface_list": [
"Ethernet1",
"Ethernet2",
"Ethernet3",
"Ethernet4",
"Management1"
],
"model": "vEOS",
"os_version": "4.15.5M-3054042.4155M",
"serial_number": "",
"uptime": "...",
"vendor": "Arista"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"Ethernet2": {
"is_enabled": true,
"description": "",
"last_flapped": 1466586841.4151127,
"is_up": true,
"mac_address": "08:00:27:10:C4:8F",
"speed": 0
},
"Management1": {
"is_enabled": true,
"description": "",
"last_flapped": 1466586841.4284112,
"is_up": true,
"mac_address": "08:00:27:20:B9:04",
"speed": 1000
},
"Ethernet1": {
"is_enabled": true,
"description": "",
"last_flapped": 1466586841.4148579,
"is_up": true,
"mac_address": "08:00:27:C6:00:F0",
"speed": 0
},
"Ethernet4": {
"is_enabled": true,
"description": "",
"last_flapped": 1466586841.415464,
"is_up": true,
"mac_address": "08:00:27:E0:12:D2",
"speed": 0
},
"Ethernet3": {
"is_enabled": true,
"description": "",
"last_flapped": 1466586841.4152465,
"is_up": true,
"mac_address": "08:00:27:1F:60:43",
"speed": 0
}
}
16 changes: 16 additions & 0 deletions tests/napalm_get_facts/mocked/multiple_facts.ok/get_facts.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"fqdn": "localhost",
"hostname": "localhost",
"interface_list": [
"Ethernet1",
"Ethernet2",
"Ethernet3",
"Ethernet4",
"Management1"
],
"model": "vEOS",
"os_version": "4.15.5M-3054042.4155M",
"serial_number": "",
"uptime": "...",
"vendor": "Arista"
}
42 changes: 42 additions & 0 deletions tests/napalm_get_facts/mocked/multiple_facts.ok/get_interfaces.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"Ethernet2": {
"is_enabled": true,
"description": "",
"last_flapped": 1466586841.4151127,
"is_up": true,
"mac_address": "08:00:27:10:C4:8F",
"speed": 0
},
"Management1": {
"is_enabled": true,
"description": "",
"last_flapped": 1466586841.4284112,
"is_up": true,
"mac_address": "08:00:27:20:B9:04",
"speed": 1000
},
"Ethernet1": {
"is_enabled": true,
"description": "",
"last_flapped": 1466586841.4148579,
"is_up": true,
"mac_address": "08:00:27:C6:00:F0",
"speed": 0
},
"Ethernet4": {
"is_enabled": true,
"description": "",
"last_flapped": 1466586841.415464,
"is_up": true,
"mac_address": "08:00:27:E0:12:D2",
"speed": 0
},
"Ethernet3": {
"is_enabled": true,
"description": "",
"last_flapped": 1466586841.4152465,
"is_up": true,
"mac_address": "08:00:27:1F:60:43",
"speed": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"1.0.4.0/24": [{"next_hop": "192.168.0.1", "preference": 200, "protocol": "eBGP", "selected_next_hop": true, "current_active": true, "routing_table": "TEST", "protocol_attributes": {"remote_as": 43515, "as_path": "1299 15169 43515", "local_preference": 50, "remote_address": "192.168.0.1", "preference2": 0, "metric": 0, "communities": ["1299:1234", "1299:5678", "1299:91011", "1299:12134"], "local_as": 13335}, "outgoing_interface": "Port-Channel2", "last_active": true, "inactive_reason": "", "age": 0}, {"next_hop": "192.168.0.1", "preference": 200, "protocol": "eBGP", "selected_next_hop": true, "current_active": true, "routing_table": "default", "protocol_attributes": {"remote_as": 43515, "as_path": "1299 15169 43515", "local_preference": 50, "remote_address": "192.168.0.1", "preference2": 0, "metric": 0, "communities": ["1299:1234", "1299:5678", "1299:91011", "1299:12134"], "local_as": 13335}, "outgoing_interface": "Port-Channel2", "last_active": true, "inactive_reason": "", "age": 0}]}

Loading

0 comments on commit b810bdf

Please sign in to comment.