Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Sanity test issues #701

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions ansible_collections/juniper/device/docs/ansible2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,19 @@
import datetime
import os
import re
import sys
from distutils.version import LooseVersion

import warnings
import yaml
from jinja2 import Environment, FileSystemLoader
from six import print_

try:
from collections import MutableMapping, MutableSequence, MutableSet
except ImportError:
# Python-3.8 or later
from collections.abc import MutableMapping, MutableSet, MutableSequence
from collections.abc import MutableMapping, MutableSet, MutableSequence

from ansible.module_utils._text import to_bytes
from ansible.module_utils.six import iteritems, string_types
from ansible.parsing.plugin_docs import read_docstring
from ansible.parsing.yaml.loader import AnsibleLoader
from ansible.plugins.loader import fragment_loader
from ansible.errors import AnsibleError

try:
from html import escape as html_escape
Expand Down Expand Up @@ -327,7 +322,7 @@ def process_module(fname, template, outputname, aliases=None):
# Error out if there's no description
if "description" not in doc["options"][k]:
raise AnsibleError(
"Missing required description for option %s in %s " % (k, module)
"Missing required description for option %s in %s " % (k, module_name)
)

# Error out if required isn't a boolean (people have been putting
Expand All @@ -337,7 +332,7 @@ def process_module(fname, template, outputname, aliases=None):
if not isinstance(required_value, bool):
raise AnsibleError(
"Invalid required value '%s' for option '%s' in '%s' (must be truthy)"
% (required_value, k, module)
% (required_value, k, module_name)
)

# Strip old version_added information for options
Expand All @@ -360,7 +355,7 @@ def process_module(fname, template, outputname, aliases=None):
if "description" not in doc["connection_options"][k]:
raise AnsibleError(
"Missing required description for connection_option %s in %s "
% (k, module)
% (k, module_name)
)

# Error out if required isn't a boolean (people have been putting
Expand All @@ -370,7 +365,7 @@ def process_module(fname, template, outputname, aliases=None):
if not isinstance(required_value, bool):
raise AnsibleError(
"Invalid required value '%s' for connection_option '%s' in '%s' (must be truthy)"
% (required_value, k, module)
% (required_value, k, module_name)
)

# Strip old version_added information for options
Expand All @@ -395,7 +390,7 @@ def process_module(fname, template, outputname, aliases=None):
if "description" not in doc["logging_options"][k]:
raise AnsibleError(
"Missing required description for logging_option %s in %s "
% (k, module)
% (k, module_name)
)

# Error out if required isn't a boolean (people have been putting
Expand All @@ -405,7 +400,7 @@ def process_module(fname, template, outputname, aliases=None):
if not isinstance(required_value, bool):
raise AnsibleError(
"Invalid required value '%s' for logging_option '%s' in '%s' (must be truthy)"
% (required_value, k, module)
% (required_value, k, module_name)
)

# Strip old version_added information for options
Expand Down Expand Up @@ -452,7 +447,7 @@ def process_module(fname, template, outputname, aliases=None):
doc["author"] = [doc["author"]]

# here is where we build the table of contents...
text = template.render(doc)
template.render(doc)
# write_data(text, outputname, module_name, OUTPUTDIR)


Expand Down
8 changes: 4 additions & 4 deletions ansible_collections/juniper/device/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ def setup(app):

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# 'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
Expand Down Expand Up @@ -283,7 +283,7 @@ def setup(app):
"Junos Ansible Collection Modules Documentation",
"Juniper Networks, Inc.",
"JunosAnsibleCollectionModules",
"Ansible Modules for " "Junos",
"Ansible Modules for Junos",
"Miscellaneous",
),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

#
Expand Down Expand Up @@ -31,7 +32,6 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

import os

from ansible.plugins.action.normal import ActionModule as ActionNormal

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

#
Expand Down Expand Up @@ -31,8 +32,6 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

import os

from ansible.plugins.action.normal import ActionModule as ActionNormal

from ansible_collections.juniper.device.plugins.action.extract_data import ExtractData
Expand Down
19 changes: 8 additions & 11 deletions ansible_collections/juniper/device/plugins/callback/jsnapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@

__metaclass__ = type

import collections
import json
import os
import pprint
import time

from ansible.module_utils.six import iteritems
from ansible import constants as C
from ansible.plugins.callback import CallbackBase
from six import iteritems


class CallbackModule(CallbackBase):
Expand All @@ -58,8 +55,8 @@ class CallbackModule(CallbackBase):
# callback needs to be enabled with config-file to use jsnapy callback during execution
CALLBACK_NEEDS_WHITELIST = True

## useful links regarding Callback
## https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/__init__.py
# useful links regarding Callback
# https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/__init__.py

def __init__(self):
self._pp = pprint.PrettyPrinter(indent=4)
Expand All @@ -72,28 +69,28 @@ def v2_runner_on_ok(self, result):
Collect test results for all tests executed if action is snapcheck or check
"""

## Extract module name
# Extract module name
module_args = {}
if "invocation" in result._result:
if "module_args" in result._result["invocation"]:
module_args = result._result["invocation"]["module_args"]

## Check if dic return has all valid information
# Check if dic return has all valid information
if "action" not in module_args:
return None

if module_args["action"] == "snapcheck" or module_args["action"] == "check":

## Check if dict entry already exist for this host
# Check if dict entry already exist for this host
host = result._host.name
if not host in self._results.keys():
if host not in self._results.keys():
self._results[host] = []

self._results[host].append(result)

def v2_playbook_on_stats(self, stats):

## Go over all results for all hosts
# Go over all results for all hosts
for host, results in iteritems(self._results):
has_printed_banner = False
for result in results:
Expand Down
28 changes: 11 additions & 17 deletions ansible_collections/juniper/device/plugins/connection/pyez.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@

from __future__ import absolute_import, division, print_function

import xmltodict
try:
import xmltodict

HAS_XMLTODICT = True
except ImportError:
HAS_XMLTODICT = False

__metaclass__ = type

Expand Down Expand Up @@ -207,10 +212,9 @@
"""
import json
import logging
import pickle

from ansible.errors import AnsibleConnectionFailure, AnsibleError
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.errors import AnsibleError
from ansible.module_utils._text import to_bytes
from ansible.plugins.connection import NetworkConnectionBase, ensure_connect

# Non-standard library imports and checks
Expand Down Expand Up @@ -266,7 +270,7 @@
HAS_PYEZ_EXCEPTIONS = False

try:
from jnpr.jsnapy import SnapAdmin, __version__
from jnpr.jsnapy import __version__

HAS_JSNAPY_VERSION = __version__
except ImportError:
Expand Down Expand Up @@ -296,19 +300,9 @@
except ImportError:
HAS_YAML_VERSION = None

try:
# Python 2
basestring
except NameError:
# Python 3
basestring = str

# import q
logging.getLogger("ncclient").setLevel(logging.INFO)

from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
to_list,
)

# Supported configuration modes
CONFIG_MODE_CHOICES = ["exclusive", "private", "dynamic", "batch", "ephemeral"]
Expand Down Expand Up @@ -895,13 +889,13 @@ def reboot_api(self, all_re, vmhost, member_id=None):
msg += " Reboot successfully initiated. " "Reboot message: %s" % got
else:
raise AnsibleError(
" Did not find expected response " "from reboot RPC. "
" Did not find expected response from reboot RPC. "
)
except self.pyez_exception.RpcTimeoutError as ex:
try:
self.close(raise_exceptions=True)
# This means the device wasn't already disconnected.
raise AnsibleError(" Reboot failed. It may not have been " "initiated.")
raise AnsibleError(" Reboot failed. It may not have been initiated.")
except (
self.pyez_exception.RpcError,
self.pyez_exception.RpcTimeoutError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
from __future__ import absolute_import, division, print_function

import os
from distutils.version import LooseVersion
__metaclass__ = type

try:
from looseversion import LooseVersion

HAS_LOOSE_VERSION = True
except ImportError:
HAS_LOOSE_VERSION = False
# Non-standard library imports and checks
try:
from jnpr.junos.version import VERSION
Expand All @@ -51,11 +57,11 @@
HAS_PYEZ_OP_TABLE = False

try:
import ncclient.operations.errors as ncclient_exception
import ncclient

HAS_NCCLIENT_EXCEPTIONS = True
HAS_NCCLIENT_VERSION = ncclient.__version__
except ImportError:
HAS_NCCLIENT_EXCEPTIONS = False
HAS_NCCLIENT_VERSION = None

try:
import jnpr.jsnapy
Expand Down Expand Up @@ -88,13 +94,6 @@
except ImportError:
HAS_YAML_VERSION = None

try:
# Python 2
basestring
except NameError:
# Python 3
basestring = str

# Constants
# Minimum PyEZ version required by shared code.
MIN_PYEZ_VERSION = "2.5.2"
Expand Down Expand Up @@ -196,8 +195,8 @@ def check_pyez(minimum=None):
- PyEZ not installed (unable to import).
- PyEZ version < minimum.
"""
if HAS_NCCLIENT_EXCEPTIONS is False:
return "ncclient.operations.errors module could not " "be imported."
if HAS_NCCLIENT_VERSION is None:
return "ncclient module could not " "be imported."
return _check_library(
"junos-eznc",
HAS_PYEZ_VERSION,
Expand Down
Loading