GithubHelp home page GithubHelp logo

sivel / ansible-testing Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 11.0 130 KB

Python module to help test or validate Ansible, specifically ansible modules

License: GNU General Public License v3.0

Python 100.00%

ansible-testing's People

Contributors

abadger avatar alikins avatar bhcopeland avatar gundalow avatar mattclay avatar nitzmahone avatar sivel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ansible-testing's Issues

Detect new arguments

Detect new arguments for modules, and validate that they have the correct version_added.

Error when description contains a colon

In the documentation section of my module, I have this part:

  type:
    description:
      - the type of certificate to generate: RSA or ECDSA. If type is ecdsa, you must specify a curve to use.
    required: false
    default: "rsa"
    choices: [ "rsa", "ecdsa" ]

This throws an error:

 ERROR: DOCUMENTATION.options.type.description.0: invalid list value

Removing the colon got rid of the error.

Network modules don't require ansible.module_utils.basic

New Network modules, such as ansible/ansible-modules-core#4065 don't require ansible.module_utils.basic

Instead they get access to this module via a OS specific Network module, such as:

from ansible.module_utils.eos import *
or
from ansible.module_utils.ios import *```

To unblock the development work by @privateip, we have made this a warning see #31

A full fix is still required which is to only skip the test for ansible.module_utils.basic for networking modules. This could be done by looking to see if the file is under ./network/

YAML Parsing error line numbers

I'm not sure there is anything we can do here, but the line number you get from a YAML parsing error is the line number within the YAML document, not the module.

Maybe there is a way we can offset that line number somehow? This may require not displaying the traceback, but using the data in the traceback to construct our own error.

version_added improvements

We detect version added and compare to current devel. However it is too dumb. It will assume that all modules must have a version_added for the next release, not just new modules. We'll have to find out how to make that determination better.

Add pep8 like codes

It could be useful to assign pep8 like codes to errors/warnings/etc.

This could also give us the ability to filter out certain codes as well.

boto2 = bad

It was discussed that any new module referencing boto2 should be treated as a fail

Agreed in the New Modules meeting on 6th April 2016

Need to decide what to do if any existing modules are still using boto2

Check for json import

import json is not required nor recommended. ansible.module_utils.basic already provides json, and does so by also attempting to import simplejson.

version_addes logic fix for new args

Currently if new args are added, they need to have a version_added indicating the upcoming version, however of the module also targets that new version we shouldn't error.

[Bug] - Exception thrown against ansible-modules-extras

Getting the following stack track:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-validate-modules", line 9, in <module>
    load_entry_point('ansible-testing==0.0.1b', 'console_scripts', 'ansible-validate-modules')()
  File "/Library/Python/2.7/site-packages/ansible_testing/modules.py", line 513, in main
    mv.validate()
  File "/Library/Python/2.7/site-packages/ansible_testing/modules.py", line 398, in validate
    self._check_version_added(doc)
  File "/Library/Python/2.7/site-packages/ansible_testing/modules.py", line 341, in _check_version_added
    'number: %s' % version_added)
UnboundLocalError: local variable 'version_added' referenced before assignment

Don't match imports on globals check from basic.py

As of now we are adding a warning if things like json or re are imported in the module and in basic.py. Due to changes coming to the modules, the duplicate import is probably ok. We should ignore imports when scanning basic.py.

Analysis of argument_spec

Right now we cannot effectively analyze the argument_spec as we need to run the code to do so.

See if we can somehow mock AnsibleModule to allow us to run the module and inspect argument_spec

This can also help us better detect when new arguments are added. As of now, if we are updating documentation to add missing arguments, it will complain that we need to set version_added to the next release, which isn't correct.

module_utils import checking is kinda broken

There is some bad logic in there somewhere. I haven't looked at it in depth. However I am currently running with uncommited code that looks like the following:

diff --git a/ansible_testing/modules.py b/ansible_testing/modules.py
index f0acaa3..10d135d 100644
--- a/ansible_testing/modules.py
+++ b/ansible_testing/modules.py
@@ -100,6 +100,7 @@ class ModuleValidator(Validator):
         'ansible.module_utils.facts',
         'ansible.module_utils.splitter',
         'ansible.module_utils.known_hosts',
+        'ansible.module_utils.rax',
     ))
     BOTTOM_IMPORTS_BLACKLIST = frozenset((
         'command.py',
@@ -203,11 +204,11 @@ class ModuleValidator(Validator):
                     if child.module in self.BOTTOM_IMPORTS:
                         if (child.lineno < main - 10 and
                                 not self._is_bottom_import_blacklisted()):
-                            self.errors.append('%s import not near main()' %
-                                               child.module)
-                    else:
-                        self.warnings.append('%s import not near main()' %
-                                             child.module)
+                            self.errors.append('%s import not near call to '
+                                               'main()' % child.module)
+                    #else:
+                    #    self.warnings.append('%s import not near main()' %
+                    #                         child.module)

                     linenos.append(child.lineno)

I haven't really taken the time to validate those changes from above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.