diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
commit | a453ac31f3428614cceb99027f8efbdb9258a40b (patch) | |
tree | f61f87408f32a8511cbd91799f9cececb53e0374 /collections-debian-merged/ansible_collections/community/routeros | |
parent | Initial commit. (diff) | |
download | ansible-a453ac31f3428614cceb99027f8efbdb9258a40b.tar.xz ansible-a453ac31f3428614cceb99027f8efbdb9258a40b.zip |
Adding upstream version 2.10.7+merged+base+2.10.8+dfsg.upstream/2.10.7+merged+base+2.10.8+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collections-debian-merged/ansible_collections/community/routeros')
51 files changed, 4634 insertions, 0 deletions
diff --git a/collections-debian-merged/ansible_collections/community/routeros/.github/workflows/ansible-test.yml b/collections-debian-merged/ansible_collections/community/routeros/.github/workflows/ansible-test.yml new file mode 100644 index 00000000..619ce594 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/.github/workflows/ansible-test.yml @@ -0,0 +1,170 @@ +name: CI +on: + # Run CI against all pushes (direct commits, also merged PRs), Pull Requests + push: + pull_request: + # Run CI once per day (at 06:00 UTC) + schedule: + - cron: '0 6 * * *' + +jobs: + +### +# Sanity tests (REQUIRED) +# +# https://docs.ansible.com/ansible/latest/dev_guide/testing_sanity.html + + sanity: + name: Sanity (Ⓐ${{ matrix.ansible }}) + strategy: + matrix: + ansible: + # It's important that Sanity is tested against all stable-X.Y branches + # Testing against `devel` may fail as new tests are added. + - stable-2.9 + - stable-2.10 + - devel + runs-on: ubuntu-latest + steps: + + # ansible-test requires the collection to be in a directory in the form + # .../ansible_collections/community/routeros/ + + - name: Check out code + uses: actions/checkout@v2 + with: + path: ansible_collections/community/routeros + + - name: Set up Python + uses: actions/setup-python@v2 + with: + # it is just required to run that once as "ansible-test sanity" in the docker image + # will run on all python versions it supports. + python-version: 3.8 + + # Install the head of the given branch (devel, stable-2.10) + - name: Install ansible-base (${{ matrix.ansible }}) + run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check + + - name: Install collection dependencies + run: ansible-galaxy collection install ansible.netcommon -p . + + # run ansible-test sanity inside of Docker. + # The docker container has all the pinned dependencies that are required + # and all python versions ansible supports. + - name: Run sanity tests + run: ansible-test sanity --docker -v --color + working-directory: ./ansible_collections/community/routeros + +### +# Unit tests (OPTIONAL) +# +# https://docs.ansible.com/ansible/latest/dev_guide/testing_units.html + + units: + runs-on: ubuntu-latest + name: Units (Ⓐ${{ matrix.ansible }}) + strategy: + # As soon as the first unit test fails, cancel the others to free up the CI queue + fail-fast: true + matrix: + ansible: + - stable-2.9 + - stable-2.10 + - devel + + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + path: ansible_collections/community/routeros + + - name: Set up Python ${{ matrix.ansible }} + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install ansible-base (${{ matrix.ansible }}) + run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check + + - name: Install collection dependencies + run: ansible-galaxy collection install ansible.netcommon -p . + + # Run the unit tests + - name: Run unit tests for all Python versions + run: ansible-test units -v --color --docker --coverage + working-directory: ./ansible_collections/community/routeros + + # ansible-test support producing code coverage date + - name: Generate coverage report + run: ansible-test coverage xml -v --requirements --group-by command --group-by version + working-directory: ./ansible_collections/community/routeros + + # See the reports at https://codecov.io/gh/ansible_collections/ansible-collections/community.routeros + - uses: codecov/codecov-action@v1 + with: + fail_ci_if_error: false + +### +# Integration tests (RECOMMENDED) +# +# https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html + + +# If the application you are testing is available as a docker container and you want to test +# multiple versions see the following for an example: +# https://github.com/ansible-collections/community.zabbix/tree/master/.github/workflows + +# integration: +# runs-on: ubuntu-latest +# name: I (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}}) +# strategy: +# fail-fast: false +# matrix: +# ansible: +# - stable-2.9 +# - stable-2.10 +# - devel +# python: +# - 2.6 +# - 2.7 +# - 3.5 +# - 3.6 +# - 3.7 +# - 3.8 +# - 3.9 +# exclude: +# - ansible: stable-2.9 +# python: 3.9 +# +# steps: +# - name: Check out code +# uses: actions/checkout@v2 +# with: +# path: ansible_collections/community/routeros +# +# - name: Set up Python ${{ matrix.ansible }} +# uses: actions/setup-python@v2 +# with: +# python-version: 3.8 +# +# - name: Install ansible-base (${{ matrix.ansible }}) +# run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check +# +# - name: Install collection dependencies +# run: ansible-galaxy collection install ansible.netcommon -p . +# +# # Run the integration tests +# - name: Run integration test +# run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --docker --coverage +# working-directory: ./ansible_collections/community/routeros +# +# # ansible-test support producing code coverage date +# - name: Generate coverage report +# run: ansible-test coverage xml -v --requirements --group-by command --group-by version +# working-directory: ./ansible_collections/community/routeros +# +# # See the reports at https://codecov.io/gh/ansible_collections/ansible-collections/community.routeros +# - uses: codecov/codecov-action@v1 +# with: +# fail_ci_if_error: false diff --git a/collections-debian-merged/ansible_collections/community/routeros/CHANGELOG.rst b/collections-debian-merged/ansible_collections/community/routeros/CHANGELOG.rst new file mode 100644 index 00000000..a7df9bdc --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/CHANGELOG.rst @@ -0,0 +1,75 @@ +================================ +Community RouterOS Release Notes +================================ + +.. contents:: Topics + + +v1.1.0 +====== + +Release Summary +--------------- + +This release allow dashes in usernames for SSH-based modules. + +Minor Changes +------------- + +- command - added support for a dash (``-``) in username (https://github.com/ansible-collections/community.routeros/pull/18). +- facts - added support for a dash (``-``) in username (https://github.com/ansible-collections/community.routeros/pull/18). + +v1.0.1 +====== + +Release Summary +--------------- + +Maintenance release with a bugfix for ``api``. + +Bugfixes +-------- + +- api - remove ``id to .id`` as default requirement which conflicts with RouterOS ``id`` configuration parameter (https://github.com/ansible-collections/community.routeros/pull/15). + +v1.0.0 +====== + +Release Summary +--------------- + +This is the first production (non-prerelease) release of ``community.routeros``. + + +Bugfixes +-------- + +- routeros terminal plugin - allow slashes in hostnames for terminal detection. Without this, slashes in hostnames will result in connection timeouts (https://github.com/ansible-collections/community.network/pull/138). + +v0.1.1 +====== + +Release Summary +--------------- + +Small improvements and bugfixes over the initial release. + +Bugfixes +-------- + +- api - fix crash when the ``ssl`` parameter is used (https://github.com/ansible-collections/community.routeros/pull/3). + +v0.1.0 +====== + +Release Summary +--------------- + +The ``community.routeros`` continues the work on the Ansible RouterOS modules from their state in ``community.network`` 1.2.0. The changes listed here are thus relative to the modules ``community.network.routeros_*``. + + +Minor Changes +------------- + +- facts - now also collecting data about BGP and OSPF (https://github.com/ansible-collections/community.network/pull/101). +- facts - set configuration export on to verbose, for full configuration export (https://github.com/ansible-collections/community.network/pull/104). diff --git a/collections-debian-merged/ansible_collections/community/routeros/COPYING b/collections-debian-merged/ansible_collections/community/routeros/COPYING new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<https://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<https://www.gnu.org/licenses/why-not-lgpl.html>. diff --git a/collections-debian-merged/ansible_collections/community/routeros/FILES.json b/collections-debian-merged/ansible_collections/community/routeros/FILES.json new file mode 100644 index 00000000..e474944f --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/FILES.json @@ -0,0 +1,481 @@ +{ + "files": [ + { + "name": ".", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "plugins", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "plugins/cliconf", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "plugins/cliconf/routeros.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "05c45d4d6a86230b48d06d17d03b62442c4792b441924352a4165710f573ef71", + "format": 1 + }, + { + "name": "plugins/terminal", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "plugins/terminal/routeros.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "829c3cd43efe71963130e9b6376f555c8c41097cd187e05d7da9eae0d4cee459", + "format": 1 + }, + { + "name": "plugins/module_utils", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "plugins/module_utils/routeros.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "1666cf579d0f77b2fdf9bb3c3c07bd4d63efccc2042d1a9dcde51db7ba2d3db0", + "format": 1 + }, + { + "name": "plugins/module_utils/__init__.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "format": 1 + }, + { + "name": "plugins/modules", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "plugins/modules/command.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "d07b03d90bd17a4a75cc922ecb0f9420a1d6e1f038639cc1a921b4bfc7afefb2", + "format": 1 + }, + { + "name": "plugins/modules/api.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "7a023729b6b5aec25f8f6929f2563300a21338961a5ba3ada0b8252bde6c5163", + "format": 1 + }, + { + "name": "plugins/modules/facts.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "d5b1937ec577a48494eebc185f397055a1e6b450934a56274ba7d98dba43319f", + "format": 1 + }, + { + "name": "README.md", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "d701feedc2590505a33cc3a9af2798aae1a500f6c91247ccef318a1acaae9932", + "format": 1 + }, + { + "name": "CHANGELOG.rst", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "24a430f5a2223d9bec77aee98268dc832bcf4866641f866dfc740bb124ee4351", + "format": 1 + }, + { + "name": "COPYING", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986", + "format": 1 + }, + { + "name": "codecov.yml", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "dd643d0b67099068b2ca9801498ea4d9aa6d989b466c943887d4ebf5c972c60c", + "format": 1 + }, + { + "name": "tests", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "tests/sanity", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "tests/sanity/ignore-2.9.txt", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "96570f1f1a03da7628187bc10d708b68974f1c38a45957696b33ab5517b6a4b9", + "format": 1 + }, + { + "name": "tests/sanity/ignore-2.10.txt", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "80054b83ba6beaa8a846024911249f4c888aa272c24ecad09d851720a6e85fae", + "format": 1 + }, + { + "name": "tests/sanity/ignore-2.11.txt", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "80054b83ba6beaa8a846024911249f4c888aa272c24ecad09d851720a6e85fae", + "format": 1 + }, + { + "name": "tests/unit", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "tests/unit/plugins", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "tests/unit/plugins/modules", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/test_facts.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "1b8ba5453361f76054b371663a70ce29c7163968caff494ac80d859359429cc4", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/routeros_module.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "07446c0ed5047a0d09060026c64b0c015b7fa350f41f636acb281743c649d8e7", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/__init__.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/test_api.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "7b26d7e6885ded0ebaa766a89aba8f3737ed1aaf3ad7eee0d31c7ba4f04375b2", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/utils.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "42ca4a4e74ac6d8c6a356d23c35163f7766d2c235f4eaf22a1a4b951a48c781f", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/system_package_print", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "f8110c29ce0c00b77de46340820369a7f2b55095e760e62a0f5b0367427faee8", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/system_resource_print", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "4552a30ac27b98cdb531164e6e945d66ce3bff0ddd196aa6dc9ae488bee324d7", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/__init__.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/ipv6_address_print_detail_without-paging_no-ipv6", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "11a84f884f00b8aaab8bf53f65468f002af838c2a08e08bee1ca548fe3a1f6f3", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/ipv6_address_print_detail_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "41eeef5f976ce4d413c4e3b42a88c877704a7316b1b0db0dee41b4f392d959a8", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/routing_bgp_peer_print_detail_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "dc57eef1e65d31f99813f6d791941d191c61ad7855dd5911daca563793d230eb", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/routing_bgp_vpnv4-route_print_detail_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "8803159ba6080f60a29513e1dd15472044ec419eb430f59f44df165d77a002db", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/ip_address_print_detail_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "e6a4983f12ede3b9995ffcfb59d711b89b38745c9084de0c863175f5f2532b0f", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/routing_ospf_neighbor_print_detail_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "532f9999b20ca5b30c339e515d6938a27fa3ce7597358692a0326793257cd312", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/interface_print_detail_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "eef2936c689ad9f1f5fb6e21a4acb14ab3d8f70162b8ad7494adaf66ac587f7e", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/ip_neighbor_print_detail_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "0f6558742320457a85313a978aa58834d2e0a915e3a4c86ade9e587fe65c9459", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/system_identity_print_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "67979768c0d45173cab664b8cf291701244f8a90c510c246164ed6e36abd62a0", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/system_routerboard_print_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "bee309db19bcdd458729b1f27825242a85ecb79f614d0b3ee7afc15f09240abe", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/export_verbose", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "f62326680b3affcfad5718fe4db6b6aae213b53eb99c48c49fd7e6ca0d2d7bfd", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/routing_bgp_instance_print_detail_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "cf5c61d0c54d4583e46ff6e198c94ba28cca895d782d3b3e217b0c29bc86597a", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/ip_route_print_detail_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "9b92f4b196df00c1aa7fb006b3e3e637912a3c07feae82855a6a75ca4cc9dc83", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/routing_ospf_instance_print_detail_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "513e2c73df0909f6e0d3436b1f814a2f0627517a216daf1434f215a6a0bfcbf0", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/fixtures/facts/system_resource_print_without-paging", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "0446e354c094bea8ba33c4bdee11a9c0fc9e09aee11a0e6d92ef58fd59ee7d0e", + "format": 1 + }, + { + "name": "tests/unit/plugins/modules/test_command.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "22b87aa79e1e5f04e6e1eecd3670676965b4bf63d72f44f08769856b0bd08455", + "format": 1 + }, + { + "name": "tests/unit/requirements.txt", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "bc75a59f7a58a82ac1d38c38907b745fbfd8f68f5b63b0ff314600986911418f", + "format": 1 + }, + { + "name": "tests/unit/compat", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "tests/unit/compat/builtins.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "0ca4cac919e166b25e601e11acb01f6957dddd574ff0a62569cb994a5ecb63e1", + "format": 1 + }, + { + "name": "tests/unit/compat/__init__.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "format": 1 + }, + { + "name": "tests/unit/compat/unittest.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "5401a046e5ce71fa19b6d905abd0f9bdf816c0c635f7bdda6730b3ef06e67096", + "format": 1 + }, + { + "name": "tests/unit/compat/mock.py", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "0af958450cf6de3fbafe94b1111eae8ba5a8dbe1d785ffbb9df81f26e4946d99", + "format": 1 + }, + { + "name": "tests/requirements.yml", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "0910d26a3f5e6984e697e713c648c393d998205d83dbbbdda1373674b50ac084", + "format": 1 + }, + { + "name": "changelogs", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "changelogs/fragments", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "changelogs/fragments/.keep", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "format": 1 + }, + { + "name": "changelogs/changelog.yaml", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "415fa69d8b10b80d61efe622da2a4882219ab62080d515dcf17b417198bd7d31", + "format": 1 + }, + { + "name": "changelogs/config.yaml", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "83e636096f80be7539aa8bce7065db2ff83c4ed8dc61d63562d2956e2e453c7a", + "format": 1 + }, + { + "name": "meta", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": "meta/runtime.yml", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "df18179bb2f5447a56ac92261a911649b96821c0b2c08eea62d5cc6b0195203f", + "format": 1 + }, + { + "name": ".github", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": ".github/workflows", + "ftype": "dir", + "chksum_type": null, + "chksum_sha256": null, + "format": 1 + }, + { + "name": ".github/workflows/ansible-test.yml", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "2889b9dd356b9f7874b3bc623f0c07054389025bd3d45938420bc5ea9018b679", + "format": 1 + } + ], + "format": 1 +}
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/community/routeros/MANIFEST.json b/collections-debian-merged/ansible_collections/community/routeros/MANIFEST.json new file mode 100644 index 00000000..58951d88 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/MANIFEST.json @@ -0,0 +1,35 @@ +{ + "collection_info": { + "namespace": "community", + "name": "routeros", + "version": "1.1.0", + "authors": [ + "Egor Zaitsev (github.com/heuels)", + "Nikolay Dachev (github.com/NikolayDachev)" + ], + "readme": "README.md", + "tags": [ + "network", + "mikrotik", + "routeros" + ], + "description": "Modules for MikroTik RouterOS", + "license": [], + "license_file": "COPYING", + "dependencies": { + "ansible.netcommon": ">=1.0.0" + }, + "repository": "https://github.com/ansible-collections/community.routeros", + "documentation": "https://ansible.fontein.de/collections/community/routeros/", + "homepage": "https://github.com/ansible-collections/community.routeros", + "issues": "https://github.com/ansible-collections/community.routeros/issues" + }, + "file_manifest_file": { + "name": "FILES.json", + "ftype": "file", + "chksum_type": "sha256", + "chksum_sha256": "1c899d2fb0a2a238a065cbcd1880d16281b2f785d95c48933d8c1eecc965c2d1", + "format": 1 + }, + "format": 1 +}
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/community/routeros/README.md b/collections-debian-merged/ansible_collections/community/routeros/README.md new file mode 100644 index 00000000..17faa10c --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/README.md @@ -0,0 +1,140 @@ +# Community RouterOS Collection +[![CI](https://github.com/ansible-collections/community.routeros/workflows/CI/badge.svg?event=push)](https://github.com/ansible-collections/community.routeros/actions) [![Codecov](https://img.shields.io/codecov/c/github/ansible-collections/community.routeros)](https://codecov.io/gh/ansible-collections/community.routeros) + +Provides modules for [Ansible](https://www.ansible.com/community) to manage [MikroTik RouterOS](http://www.mikrotik-routeros.net/routeros.aspx) instances. + +You can find [documentation for the modules and plugins in this collection here](https://ansible.fontein.de/collections/community/routeros/). + +## Tested with Ansible + +Tested with both the current Ansible 2.9 and 2.10 releases and the current development version of Ansible. Ansible versions before 2.9.10 are not supported. + +## External requirements + +The exact requirements for every module are listed in the module documentation. + +### Supported connections + +The collection supports the `network_cli` connection. + +## Included content + +- `community.routeros.api` +- `community.routeros.command` +- `community.routeros.facts` + +You can find [documentation for the modules and plugins in this collection here](https://ansible.fontein.de/collections/community/routeros/). + +## Using this collection + +See [Ansible Using collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for general detail on using collections. + +There are two approaches for using this collection. The `command` and `facts` modules use the `network_cli` connection and connect with SSH. The `api` module connects with the HTTP/HTTPS API. + +### Prerequisites + +The terminal-based modules in this collection (`community.routeros.command` and `community.routeros.facts`) do not support arbitrary symbols in router's identity. If you are having trouble connecting to your device, please make sure that your MikroTik's identity contains only alphanumeric characters and dashes. Also, the `community.routeros.command` module does not support nesting commands and expects every command to start with a forward slash (`/`). Running the following command will produce an error. + +```yaml +- community.routeros.command: + commands: + - /ip + - print +``` + +### Connecting with `network_cli` + +Example inventory `hosts` file: + +```.ini +[routers] +router ansible_host=192.168.1.1 + +[routers:vars] +ansible_connection=ansible.netcommon.network_cli +ansible_network_os=community.routeros.routeros +ansible_user=admin +ansible_ssh_pass=test1234 +``` + +Example playbook: + +```.yaml +--- +- name: RouterOS test with network_cli connection + hosts: routers + gather_facts: false + tasks: + + # Run a command and print its output + - community.routeros.command: + commands: + - /system resource print + register: system_resource_print + - debug: + var: system_resource_print.stdout_lines + + # Retrieve facts + - community.routeros.facts: + - debug: + msg: "First IP address: {{ ansible_net_all_ipv4_addresses[0] }}" +``` + +### Connecting with HTTP/HTTPS API + +Example playbook: + +```.yaml +--- +- name: RouterOS test with API + hosts: localhost + gather_facts: no + vars: + hostname: 192.168.1.1 + username: admin + password: test1234 + tasks: + - name: Get "ip address print" + community.routeros.api: + hostname: "{{ hostname }}" + password: "{{ password }}" + username: "{{ username }}" + path: "ip address" + ssl: true + register: print_path +``` + +## Contributing to this collection + +We're following the general Ansible contributor guidelines; see [Ansible Community Guide](https://docs.ansible.com/ansible/latest/community/index.html). + +If you want to clone this repositority (or a fork of it) to improve it, you can proceed as follows: +1. Create a directory `ansible_collections/community`; +2. In there, checkout this repository (or a fork) as `routeros`; +3. Add the directory containing `ansible_collections` to your [ANSIBLE_COLLECTIONS_PATH](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths). + +See [Ansible's dev guide](https://docs.ansible.com/ansible/devel/dev_guide/developing_collections.html#contributing-to-collections) for more information. + +## Release notes + +See the [changelog](https://github.com/ansible-collections/community.routeros/blob/main/CHANGELOG.rst). + +## Roadmap + +We plan to regularly release minor and patch versions, whenever new features are added or bugs fixed. Our collection follows [semantic versioning](https://semver.org/), so breaking changes will only happen in major releases. + +## More information + +- [Ansible Collection overview](https://github.com/ansible-collections/overview) +- [Ansible User guide](https://docs.ansible.com/ansible/latest/user_guide/index.html) +- [Ansible Developer guide](https://docs.ansible.com/ansible/latest/dev_guide/index.html) +- [Ansible Collections Checklist](https://github.com/ansible-collections/overview/blob/master/collection_requirements.rst) +- [Ansible Community code of conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html) +- [The Bullhorn (the Ansible Contributor newsletter)](https://us19.campaign-archive.com/home/?u=56d874e027110e35dea0e03c1&id=d6635f5420) +- [Changes impacting Contributors](https://github.com/ansible-collections/overview/issues/45) + +## Licensing + +GNU General Public License v3.0 or later. + +See [COPYING](https://www.gnu.org/licenses/gpl-3.0.txt) to see the full text. diff --git a/collections-debian-merged/ansible_collections/community/routeros/changelogs/changelog.yaml b/collections-debian-merged/ansible_collections/community/routeros/changelogs/changelog.yaml new file mode 100644 index 00000000..cf1c51af --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/changelogs/changelog.yaml @@ -0,0 +1,59 @@ +ancestor: null +releases: + 0.1.0: + changes: + minor_changes: + - facts - now also collecting data about BGP and OSPF (https://github.com/ansible-collections/community.network/pull/101). + - facts - set configuration export on to verbose, for full configuration export + (https://github.com/ansible-collections/community.network/pull/104). + release_summary: 'The ``community.routeros`` continues the work on the Ansible + RouterOS modules from their state in ``community.network`` 1.2.0. The changes + listed here are thus relative to the modules ``community.network.routeros_*``. + + ' + fragments: + - 0.1.0.yml + - 101_update_facts.yml + - 104_facts_export_verbose.yml + release_date: '2020-10-26' + 0.1.1: + changes: + bugfixes: + - api - fix crash when the ``ssl`` parameter is used (https://github.com/ansible-collections/community.routeros/pull/3). + release_summary: Small improvements and bugfixes over the initial release. + fragments: + - 0.1.1.yml + - 3-api-ssl.yml + release_date: '2020-10-31' + 1.0.0: + changes: + bugfixes: + - routeros terminal plugin - allow slashes in hostnames for terminal detection. + Without this, slashes in hostnames will result in connection timeouts (https://github.com/ansible-collections/community.network/pull/138). + release_summary: 'This is the first production (non-prerelease) release of ``community.routeros``. + + ' + fragments: + - 1.0.0.yml + - community.network-138-routeros-allow-slash.yml + release_date: '2020-11-17' + 1.0.1: + changes: + bugfixes: + - api - remove ``id to .id`` as default requirement which conflicts with RouterOS + ``id`` configuration parameter (https://github.com/ansible-collections/community.routeros/pull/15). + release_summary: Maintenance release with a bugfix for ``api``. + fragments: + - 1.0.1.yml + - 13-remove-id-restriction-for-api.yaml + release_date: '2020-12-11' + 1.1.0: + changes: + minor_changes: + - command - added support for a dash (``-``) in username (https://github.com/ansible-collections/community.routeros/pull/18). + - facts - added support for a dash (``-``) in username (https://github.com/ansible-collections/community.routeros/pull/18). + release_summary: This release allow dashes in usernames for SSH-based modules. + fragments: + - 1.1.0.yml + - 18-support-dashes-in-username.yml + release_date: '2021-01-04' diff --git a/collections-debian-merged/ansible_collections/community/routeros/changelogs/config.yaml b/collections-debian-merged/ansible_collections/community/routeros/changelogs/config.yaml new file mode 100644 index 00000000..8f014edb --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/changelogs/config.yaml @@ -0,0 +1,29 @@ +changelog_filename_template: ../CHANGELOG.rst +changelog_filename_version_depth: 0 +changes_file: changelog.yaml +changes_format: combined +keep_fragments: false +mention_ancestor: true +flatmap: true +new_plugins_after_name: removed_features +notesdir: fragments +prelude_section_name: release_summary +prelude_section_title: Release Summary +sections: +- - major_changes + - Major Changes +- - minor_changes + - Minor Changes +- - breaking_changes + - Breaking Changes / Porting Guide +- - deprecated_features + - Deprecated Features +- - removed_features + - Removed Features (previously deprecated) +- - security_fixes + - Security Fixes +- - bugfixes + - Bugfixes +- - known_issues + - Known Issues +title: Community RouterOS diff --git a/collections-debian-merged/ansible_collections/community/routeros/changelogs/fragments/.keep b/collections-debian-merged/ansible_collections/community/routeros/changelogs/fragments/.keep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/changelogs/fragments/.keep diff --git a/collections-debian-merged/ansible_collections/community/routeros/codecov.yml b/collections-debian-merged/ansible_collections/community/routeros/codecov.yml new file mode 100644 index 00000000..724e0634 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/codecov.yml @@ -0,0 +1,2 @@ +fixes: + - "ansible_collections/community/routeros/::" diff --git a/collections-debian-merged/ansible_collections/community/routeros/meta/runtime.yml b/collections-debian-merged/ansible_collections/community/routeros/meta/runtime.yml new file mode 100644 index 00000000..2ee3c9fa --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/meta/runtime.yml @@ -0,0 +1,2 @@ +--- +requires_ansible: '>=2.9.10' diff --git a/collections-debian-merged/ansible_collections/community/routeros/plugins/cliconf/routeros.py b/collections-debian-merged/ansible_collections/community/routeros/plugins/cliconf/routeros.py new file mode 100644 index 00000000..2e4adf7c --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/plugins/cliconf/routeros.py @@ -0,0 +1,79 @@ +# +# (c) 2017 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. +# +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION = ''' +--- +author: "Egor Zaitsev (@heuels)" +name: routeros +short_description: Use routeros cliconf to run command on MikroTik RouterOS platform +description: + - This routeros plugin provides low level abstraction apis for + sending and receiving CLI commands from MikroTik RouterOS network devices. +''' + +import re +import json + +from itertools import chain + +from ansible.module_utils._text import to_bytes, to_text +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list +from ansible.plugins.cliconf import CliconfBase, enable_mode + + +class Cliconf(CliconfBase): + + def get_device_info(self): + device_info = {} + device_info['network_os'] = 'RouterOS' + + resource = self.get('/system resource print') + data = to_text(resource, errors='surrogate_or_strict').strip() + match = re.search(r'version: (\S+)', data) + if match: + device_info['network_os_version'] = match.group(1) + + routerboard = self.get('/system routerboard print') + data = to_text(routerboard, errors='surrogate_or_strict').strip() + match = re.search(r'model: (.+)$', data, re.M) + if match: + device_info['network_os_model'] = match.group(1) + + identity = self.get('/system identity print') + data = to_text(identity, errors='surrogate_or_strict').strip() + match = re.search(r'name: (.+)$', data, re.M) + if match: + device_info['network_os_hostname'] = match.group(1) + + return device_info + + def get_config(self, source='running', format='text', flags=None): + return + + def edit_config(self, command): + return + + def get(self, command, prompt=None, answer=None, sendonly=False, newline=True, check_all=False): + return self.send_command(command=command, prompt=prompt, answer=answer, sendonly=sendonly, newline=newline, check_all=check_all) + + def get_capabilities(self): + result = super(Cliconf, self).get_capabilities() + return json.dumps(result) diff --git a/collections-debian-merged/ansible_collections/community/routeros/plugins/module_utils/__init__.py b/collections-debian-merged/ansible_collections/community/routeros/plugins/module_utils/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/plugins/module_utils/__init__.py diff --git a/collections-debian-merged/ansible_collections/community/routeros/plugins/module_utils/routeros.py b/collections-debian-merged/ansible_collections/community/routeros/plugins/module_utils/routeros.py new file mode 100644 index 00000000..20a8400b --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/plugins/module_utils/routeros.py @@ -0,0 +1,163 @@ +# This code is part of Ansible, but is an independent component. +# This particular file snippet, and this file snippet only, is BSD licensed. +# Modules you write using this snippet, which is embedded dynamically by Ansible +# still belong to the author of the module, and may assign their own license +# to the complete work. +# +# (c) 2016 Red Hat Inc. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (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 +__metaclass__ = type + +import json +from ansible.module_utils._text import to_native +from ansible.module_utils.basic import env_fallback +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list, ComplexList +from ansible.module_utils.connection import Connection, ConnectionError + +_DEVICE_CONFIGS = {} + +routeros_provider_spec = { + 'host': dict(), + 'port': dict(type='int'), + 'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])), + 'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True), + 'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'), + 'timeout': dict(type='int') +} +routeros_argument_spec = {} + + +def get_provider_argspec(): + return routeros_provider_spec + + +def get_connection(module): + if hasattr(module, '_routeros_connection'): + return module._routeros_connection + + capabilities = get_capabilities(module) + network_api = capabilities.get('network_api') + if network_api == 'cliconf': + module._routeros_connection = Connection(module._socket_path) + else: + module.fail_json(msg='Invalid connection type %s' % network_api) + + return module._routeros_connection + + +def get_capabilities(module): + if hasattr(module, '_routeros_capabilities'): + return module._routeros_capabilities + + try: + capabilities = Connection(module._socket_path).get_capabilities() + module._routeros_capabilities = json.loads(capabilities) + return module._routeros_capabilities + except ConnectionError as exc: + module.fail_json(msg=to_native(exc, errors='surrogate_then_replace')) + + +def get_defaults_flag(module): + connection = get_connection(module) + + try: + out = connection.get('/system default-configuration print') + except ConnectionError as exc: + module.fail_json(msg=to_native(exc, errors='surrogate_then_replace')) + + out = to_native(out, errors='surrogate_then_replace') + + commands = set() + for line in out.splitlines(): + if line.strip(): + commands.add(line.strip().split()[0]) + + if 'all' in commands: + return ['all'] + else: + return ['full'] + + +def get_config(module, flags=None): + flag_str = ' '.join(to_list(flags)) + + try: + return _DEVICE_CONFIGS[flag_str] + except KeyError: + connection = get_connection(module) + + try: + out = connection.get_config(flags=flags) + except ConnectionError as exc: + module.fail_json(msg=to_native(exc, errors='surrogate_then_replace')) + + cfg = to_native(out, errors='surrogate_then_replace').strip() + _DEVICE_CONFIGS[flag_str] = cfg + return cfg + + +def to_commands(module, commands): + spec = { + 'command': dict(key=True), + 'prompt': dict(), + 'answer': dict() + } + transform = ComplexList(spec, module) + return transform(commands) + + +def run_commands(module, commands, check_rc=True): + responses = list() + connection = get_connection(module) + + for cmd in to_list(commands): + if isinstance(cmd, dict): + command = cmd['command'] + prompt = cmd['prompt'] + answer = cmd['answer'] + else: + command = cmd + prompt = None + answer = None + + try: + out = connection.get(command, prompt, answer) + except ConnectionError as exc: + module.fail_json(msg=to_native(exc, errors='surrogate_then_replace')) + + try: + out = to_native(out, errors='surrogate_or_strict') + except UnicodeError: + module.fail_json( + msg=u'Failed to decode output from %s: %s' % (cmd, to_native(out))) + + responses.append(out) + + return responses + + +def load_config(module, commands): + connection = get_connection(module) + + out = connection.edit_config(commands) diff --git a/collections-debian-merged/ansible_collections/community/routeros/plugins/modules/api.py b/collections-debian-merged/ansible_collections/community/routeros/plugins/modules/api.py new file mode 100644 index 00000000..bb5d7a86 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/plugins/modules/api.py @@ -0,0 +1,480 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Copyright: (c) 2020, Nikolay Dachev <nikolay@dachev.info> +# GNU General Public License v3.0+ https://www.gnu.org/licenses/gpl-3.0.txt + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: api +author: "Nikolay Dachev (@NikolayDachev)" +short_description: Ansible module for RouterOS API +description: + - Ansible module for RouterOS API with python librouteros. + - This module can add, remove, update, query and execute arbitrary command in routeros via API. +notes: + - I(add), I(remove), I(update), I(cmd) and I(query) are mutually exclusive. + - I(check_mode) is not supported. +requirements: + - librouteros + - Python >= 3.6 (for librouteros) +options: + hostname: + description: + - RouterOS hostname API. + required: true + type: str + username: + description: + - RouterOS login user. + required: true + type: str + password: + description: + - RouterOS user password. + required: true + type: str + ssl: + description: + - If is set TLS will be used for RouterOS API connection. + required: false + type: bool + default: false + port: + description: + - RouterOS api port. If ssl is set, port will apply to ssl connection. + - Defaults are C(8728) for the HTTP API, and C(8729) for the HTTPS API. + type: int + path: + description: + - Main path for all other arguments. + - If other arguments are not set, api will return all items in selected path. + - Example C(ip address). Equivalent of RouterOS CLI C(/ip address print). + required: true + type: str + add: + description: + - Will add selected arguments in selected path to RouterOS config. + - Example C(address=1.1.1.1/32 interface=ether1). + - Equivalent in RouterOS CLI C(/ip address add address=1.1.1.1/32 interface=ether1). + type: str + remove: + description: + - Remove config/value from RouterOS by '.id'. + - Example C(*03) will remove config/value with C(id=*03) in selected path. + - Equivalent in RouterOS CLI C(/ip address remove numbers=1). + - Note C(number) in RouterOS CLI is different from C(.id). + type: str + update: + description: + - Update config/value in RouterOS by '.id' in selected path. + - Example C(.id=*03 address=1.1.1.3/32) and path C(ip address) will replace existing ip address with C(.id=*03). + - Equivalent in RouterOS CLI C(/ip address set address=1.1.1.3/32 numbers=1). + - Note C(number) in RouterOS CLI is different from C(.id). + type: str + query: + description: + - Query given path for selected query attributes from RouterOS aip and return '.id'. + - WHERE is key word which extend query. WHERE format is key operator value - with spaces. + - WHERE valid operators are C(==), C(!=), C(>), C(<). + - Example path C(ip address) and query C(.id address) will return only C(.id) and C(address) for all items in C(ip address) path. + - Example path C(ip address) and query C(.id address WHERE address == 1.1.1.3/32). + will return only C(.id) and C(address) for items in C(ip address) path, where address is eq to 1.1.1.3/32. + - Example path C(interface) and query C(mtu name WHERE mut > 1400) will + return only interfaces C(mtu,name) where mtu is bigger than 1400. + - Equivalent in RouterOS CLI C(/interface print where mtu > 1400). + type: str + cmd: + description: + - Execute any/arbitrary command in selected path, after the command we can add C(.id). + - Example path C(system script) and cmd C(run .id=*03) is equivalent in RouterOS CLI C(/system script run number=0). + - Example path C(ip address) and cmd C(print) is equivalent in RouterOS CLI C(/ip address print). + type: str +''' + +EXAMPLES = ''' +--- +- name: Use RouterOS API + hosts: localhost + gather_facts: no + vars: + hostname: "ros_api_hostname/ip" + username: "admin" + password: "secret_password" + + path: "ip address" + + nic: "ether2" + ip1: "1.1.1.1/32" + ip2: "2.2.2.2/32" + ip3: "3.3.3.3/32" + + tasks: + - name: Get "{{ path }} print" + community.routeros.api: + hostname: "{{ hostname }}" + password: "{{ password }}" + username: "{{ username }}" + path: "{{ path }}" + register: print_path + + - name: Dump "{{ path }} print" output + ansible.builtin.debug: + msg: '{{ print_path }}' + + - name: Add ip address "{{ ip1 }}" and "{{ ip2 }}" + community.routeros.api: + hostname: "{{ hostname }}" + password: "{{ password }}" + username: "{{ username }}" + path: "{{ path }}" + add: "{{ item }}" + loop: + - "address={{ ip1 }} interface={{ nic }}" + - "address={{ ip2 }} interface={{ nic }}" + register: addout + + - name: Dump "Add ip address" output - ".id" for new added items + ansible.builtin.debug: + msg: '{{ addout }}' + + - name: Query for ".id" in "{{ path }} WHERE address == {{ ip2 }}" + community.routeros.api: + hostname: "{{ hostname }}" + password: "{{ password }}" + username: "{{ username }}" + path: "{{ path }}" + query: ".id address WHERE address == {{ ip2 }}" + register: queryout + + - name: Dump "Query for" output and set fact with ".id" for "{{ ip2 }}" + ansible.builtin.debug: + msg: '{{ queryout }}' + + - name: Store query_id for later usage + ansible.builtin.set_fact: + query_id: "{{ queryout['msg'][0]['.id'] }}" + + - name: Update ".id = {{ query_id }}" taken with custom fact "fquery_id" + community.routeros.api: + hostname: "{{ hostname }}" + password: "{{ password }}" + username: "{{ username }}" + path: "{{ path }}" + update: ".id={{ query_id }} address={{ ip3 }}" + register: updateout + + - name: Dump "Update" output + ansible.builtin.debug: + msg: '{{ updateout }}' + + - name: Remove ips - stage 1 - query ".id" for "{{ ip2 }}" and "{{ ip3 }}" + community.routeros.api: + hostname: "{{ hostname }}" + password: "{{ password }}" + username: "{{ username }}" + path: "{{ path }}" + query: ".id address WHERE address == {{ item }}" + register: id_to_remove + loop: + - "{{ ip2 }}" + - "{{ ip3 }}" + + - name: Set fact for ".id" from "Remove ips - stage 1 - query" + ansible.builtin.set_fact: + to_be_remove: "{{ to_be_remove |default([]) + [item['msg'][0]['.id']] }}" + loop: "{{ id_to_remove.results }}" + + - name: Dump "Remove ips - stage 1 - query" output + ansible.builtin.debug: + msg: '{{ to_be_remove }}' + + # Remove "{{ rmips }}" with ".id" by "to_be_remove" from query + - name: Remove ips - stage 2 - remove "{{ ip2 }}" and "{{ ip3 }}" by '.id' + community.routeros.api: + hostname: "{{ hostname }}" + password: "{{ password }}" + username: "{{ username }}" + path: "{{ path }}" + remove: "{{ item }}" + register: remove + loop: "{{ to_be_remove }}" + + - name: Dump "Remove ips - stage 2 - remove" output + ansible.builtin.debug: + msg: '{{ remove }}' + + - name: Arbitrary command example "/system identity print" + community.routeros.api: + hostname: "{{ hostname }}" + password: "{{ password }}" + username: "{{ username }}" + path: "system identity" + cmd: "print" + register: cmdout + + - name: Dump "Arbitrary command example" output + ansible.builtin.debug: + msg: "{{ cmdout }}" +''' + +RETURN = ''' +--- +message: + description: All outputs are in list with dictionary elements returned from RouterOS api. + sample: C([{...},{...}]) + type: list + returned: always +''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.basic import missing_required_lib +from ansible.module_utils._text import to_native + +import ssl +import traceback + +LIB_IMP_ERR = None +try: + from librouteros import connect + from librouteros.query import Key + HAS_LIB = True +except Exception as e: + HAS_LIB = False + LIB_IMP_ERR = traceback.format_exc() + + +class ROS_api_module: + def __init__(self): + module_args = (dict( + username=dict(type='str', required=True), + password=dict(type='str', required=True, no_log=True), + hostname=dict(type='str', required=True), + port=dict(type='int'), + ssl=dict(type='bool', default=False), + path=dict(type='str', required=True), + add=dict(type='str'), + remove=dict(type='str'), + update=dict(type='str'), + cmd=dict(type='str'), + query=dict(type='str'))) + + self.module = AnsibleModule(argument_spec=module_args, + supports_check_mode=False, + mutually_exclusive=(('add', 'remove', 'update', + 'cmd', 'query'),),) + + if not HAS_LIB: + self.module.fail_json(msg=missing_required_lib("librouteros"), + exception=LIB_IMP_ERR) + + self.api = self.ros_api_connect(self.module.params['username'], + self.module.params['password'], + self.module.params['hostname'], + self.module.params['port'], + self.module.params['ssl']) + + self.path = self.list_remove_empty(self.module.params['path'].split(' ')) + self.add = self.module.params['add'] + self.remove = self.module.params['remove'] + self.update = self.module.params['update'] + self.arbitrary = self.module.params['cmd'] + + self.where = None + self.query = self.module.params['query'] + if self.query: + if 'WHERE' in self.query: + split = self.query.split('WHERE') + self.query = self.list_remove_empty(split[0].split(' ')) + self.where = self.list_remove_empty(split[1].split(' ')) + else: + self.query = self.list_remove_empty(self.module.params['query'].split(' ')) + + self.result = dict( + message=[]) + + # create api base path + self.api_path = self.api_add_path(self.api, self.path) + + # api call's + if self.add: + self.api_add() + elif self.remove: + self.api_remove() + elif self.update: + self.api_update() + elif self.query: + self.api_query() + elif self.arbitrary: + self.api_arbitrary() + else: + self.api_get_all() + + def list_remove_empty(self, check_list): + while("" in check_list): + check_list.remove("") + return check_list + + def list_to_dic(self, ldict): + dict = {} + for p in ldict: + if '=' not in p: + self.errors("missing '=' after '%s'" % p) + p = p.split('=') + if p[1]: + dict[p[0]] = p[1] + return dict + + def api_add_path(self, api, path): + api_path = api.path() + for p in path: + api_path = api_path.join(p) + return api_path + + def api_get_all(self): + try: + for i in self.api_path: + self.result['message'].append(i) + self.return_result(False, True) + except Exception as e: + self.errors(e) + + def api_add(self): + param = self.list_to_dic(self.add.split(' ')) + try: + self.result['message'].append("added: .id= %s" + % self.api_path.add(**param)) + self.return_result(True) + except Exception as e: + self.errors(e) + + def api_remove(self): + try: + self.api_path.remove(self.remove) + self.result['message'].append("removed: .id= %s" % self.remove) + self.return_result(True) + except Exception as e: + self.errors(e) + + def api_update(self): + param = self.list_to_dic(self.update.split(' ')) + if '.id' not in param.keys(): + self.errors("missing '.id' for %s" % param) + try: + self.api_path.update(**param) + self.result['message'].append("updated: %s" % param) + self.return_result(True) + except Exception as e: + self.errors(e) + + def api_query(self): + keys = {} + for k in self.query: + if 'id' in k and k != ".id": + self.errors("'%s' must be '.id'" % k) + keys[k] = Key(k) + try: + if self.where: + if len(self.where) < 3: + self.errors("invalid syntax for 'WHERE %s'" + % ' '.join(self.where)) + + where = [] + if self.where[1] == '==': + select = self.api_path.select(*keys).where(keys[self.where[0]] == self.where[2]) + elif self.where[1] == '!=': + select = self.api_path.select(*keys).where(keys[self.where[0]] != self.where[2]) + elif self.where[1] == '>': + select = self.api_path.select(*keys).where(keys[self.where[0]] > self.where[2]) + elif self.where[1] == '<': + select = self.api_path.select(*keys).where(keys[self.where[0]] < self.where[2]) + else: + self.errors("'%s' is not operator for 'where'" + % self.where[1]) + for row in select: + self.result['message'].append(row) + else: + for row in self.api_path.select(*keys): + self.result['message'].append(row) + if len(self.result['message']) < 1: + msg = "no results for '%s 'query' %s" % (' '.join(self.path), + ' '.join(self.query)) + if self.where: + msg = msg + ' WHERE %s' % ' '.join(self.where) + self.result['message'].append(msg) + self.return_result(False) + except Exception as e: + self.errors(e) + + def api_arbitrary(self): + param = {} + self.arbitrary = self.arbitrary.split(' ') + arb_cmd = self.arbitrary[0] + if len(self.arbitrary) > 1: + param = self.list_to_dic(self.arbitrary[1:]) + try: + arbitrary_result = self.api_path(arb_cmd, **param) + for i in arbitrary_result: + self.result['message'].append(i) + self.return_result(False) + except Exception as e: + self.errors(e) + + def return_result(self, ch_status=False, status=True): + if status == "False": + self.module.fail_json(msg=to_native(self.result['message'])) + else: + self.module.exit_json(changed=ch_status, + msg=self.result['message']) + + def errors(self, e): + if e.__class__.__name__ == 'TrapError': + self.result['message'].append("%s" % e) + self.return_result(False, True) + self.result['message'].append("%s" % e) + self.return_result(False, False) + + def ros_api_connect(self, username, password, host, port, use_ssl): + # connect to routeros api + conn_status = {"connection": {"username": username, + "hostname": host, + "port": port, + "ssl": use_ssl, + "status": "Connected"}} + try: + if use_ssl is True: + if not port: + port = 8729 + conn_status["connection"]["port"] = port + ctx = ssl.create_default_context() + ctx.check_hostname = False + ctx.set_ciphers('ADH:@SECLEVEL=0') + api = connect(username=username, + password=password, + host=host, + ssl_wrapper=ctx.wrap_socket, + port=port) + else: + if not port: + port = 8728 + conn_status["connection"]["port"] = port + api = connect(username=username, + password=password, + host=host, + port=port) + except Exception as e: + conn_status["connection"]["status"] = "error: %s" % e + self.module.fail_json(msg=to_native([conn_status])) + return api + + +def main(): + + ROS_api_module() + + +if __name__ == '__main__': + main() diff --git a/collections-debian-merged/ansible_collections/community/routeros/plugins/modules/command.py b/collections-debian-merged/ansible_collections/community/routeros/plugins/modules/command.py new file mode 100644 index 00000000..82331a57 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/plugins/modules/command.py @@ -0,0 +1,180 @@ +#!/usr/bin/python + +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: command +author: "Egor Zaitsev (@heuels)" +short_description: Run commands on remote devices running MikroTik RouterOS +description: + - Sends arbitrary commands to an RouterOS node and returns the results + read from the device. This module includes an + argument that will cause the module to wait for a specific condition + before returning or timing out if the condition is not met. +options: + commands: + description: + - List of commands to send to the remote RouterOS device over the + configured provider. The resulting output from the command + is returned. If the I(wait_for) argument is provided, the + module is not returned until the condition is satisfied or + the number of retries has expired. + required: true + wait_for: + description: + - List of conditions to evaluate against the output of the + command. The task will wait for each condition to be true + before moving forward. If the conditional is not true + within the configured number of retries, the task fails. + See examples. + match: + description: + - The I(match) argument is used in conjunction with the + I(wait_for) argument to specify the match policy. Valid + values are C(all) or C(any). If the value is set to C(all) + then all conditionals in the wait_for must be satisfied. If + the value is set to C(any) then only one of the values must be + satisfied. + default: all + choices: ['any', 'all'] + retries: + description: + - Specifies the number of retries a command should by tried + before it is considered failed. The command is run on the + target device every retry and evaluated against the + I(wait_for) conditions. + default: 10 + interval: + description: + - Configures the interval in seconds to wait between retries + of the command. If the command does not pass the specified + conditions, the interval indicates how long to wait before + trying the command again. + default: 1 +''' + +EXAMPLES = """ +- name: Run command on remote devices + community.routeros.command: + commands: /system routerboard print + +- name: Run command and check to see if output contains routeros + community.routeros.command: + commands: /system resource print + wait_for: result[0] contains MikroTik + +- name: Run multiple commands on remote nodes + community.routeros.command: + commands: + - /system routerboard print + - /system identity print + +- name: Run multiple commands and evaluate the output + community.routeros.command: + commands: + - /system routerboard print + - /interface ethernet print + wait_for: + - result[0] contains x86 + - result[1] contains ether1 +""" + +RETURN = """ +stdout: + description: The set of responses from the commands + returned: always apart from low level errors (such as action plugin) + type: list + sample: ['...', '...'] +stdout_lines: + description: The value of stdout split into a list + returned: always apart from low level errors (such as action plugin) + type: list + sample: [['...', '...'], ['...'], ['...']] +failed_conditions: + description: The list of conditionals that have failed + returned: failed + type: list + sample: ['...', '...'] +""" + +import re +import time + +from ansible_collections.community.routeros.plugins.module_utils.routeros import run_commands +from ansible_collections.community.routeros.plugins.module_utils.routeros import routeros_argument_spec +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ComplexList +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.parsing import Conditional +from ansible.module_utils.six import string_types + + +def to_lines(stdout): + for item in stdout: + if isinstance(item, string_types): + item = str(item).split('\n') + yield item + + +def main(): + """main entry point for module execution + """ + argument_spec = dict( + commands=dict(type='list', required=True), + + wait_for=dict(type='list'), + match=dict(default='all', choices=['all', 'any']), + + retries=dict(default=10, type='int'), + interval=dict(default=1, type='int') + ) + + argument_spec.update(routeros_argument_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + result = {'changed': False} + + wait_for = module.params['wait_for'] or list() + conditionals = [Conditional(c) for c in wait_for] + + retries = module.params['retries'] + interval = module.params['interval'] + match = module.params['match'] + + while retries > 0: + responses = run_commands(module, module.params['commands']) + + for item in list(conditionals): + if item(responses): + if match == 'any': + conditionals = list() + break + conditionals.remove(item) + + if not conditionals: + break + + time.sleep(interval) + retries -= 1 + + if conditionals: + failed_conditions = [item.raw for item in conditionals] + msg = 'One or more conditional statements have not been satisfied' + module.fail_json(msg=msg, failed_conditions=failed_conditions) + + result.update({ + 'changed': False, + 'stdout': responses, + 'stdout_lines': list(to_lines(responses)) + }) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/collections-debian-merged/ansible_collections/community/routeros/plugins/modules/facts.py b/collections-debian-merged/ansible_collections/community/routeros/plugins/modules/facts.py new file mode 100644 index 00000000..4a4db7c3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/plugins/modules/facts.py @@ -0,0 +1,625 @@ +#!/usr/bin/python + +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: facts +author: "Egor Zaitsev (@heuels)" +short_description: Collect facts from remote devices running MikroTik RouterOS +description: + - Collects a base set of device facts from a remote device that + is running RotuerOS. This module prepends all of the + base network fact keys with C(ansible_net_<fact>). The facts + module will always collect a base set of facts from the device + and can enable or disable collection of additional facts. +options: + gather_subset: + description: + - When supplied, this argument will restrict the facts collected + to a given subset. Possible values for this argument include + C(all), C(hardware), C(config), and C(interfaces). Can specify a list of + values to include a larger subset. Values can also be used + with an initial C(!) to specify that a specific subset should + not be collected. + required: false + default: '!config' +''' + +EXAMPLES = """ +- name: Collect all facts from the device + community.routeros.facts: + gather_subset: all + +- name: Collect only the config and default facts + community.routeros.facts: + gather_subset: + - config + +- name: Do not collect hardware facts + community.routeros.facts: + gather_subset: + - "!hardware" +""" + +RETURN = """ +ansible_facts: + description: "Dictionary of ip geolocation facts for a host's IP address" + returned: always + type: dict + contains: + ansible_net_gather_subset: + description: The list of fact subsets collected from the device + returned: always + type: list + + # default + ansible_net_model: + description: The model name returned from the device + returned: always + type: str + ansible_net_serialnum: + description: The serial number of the remote device + returned: always + type: str + ansible_net_version: + description: The operating system version running on the remote device + returned: always + type: str + ansible_net_hostname: + description: The configured hostname of the device + returned: always + type: str + ansible_net_arch: + description: The CPU architecture of the device + returned: always + type: str + ansible_net_uptime: + description: The uptime of the device + returned: always + type: str + ansible_net_cpu_load: + description: Current CPU load + returned: always + type: str + + # hardware + ansible_net_spacefree_mb: + description: The available disk space on the remote device in MiB + returned: when hardware is configured + type: dict + ansible_net_spacetotal_mb: + description: The total disk space on the remote device in MiB + returned: when hardware is configured + type: dict + ansible_net_memfree_mb: + description: The available free memory on the remote device in MiB + returned: when hardware is configured + type: int + ansible_net_memtotal_mb: + description: The total memory on the remote device in MiB + returned: when hardware is configured + type: int + + # config + ansible_net_config: + description: The current active config from the device + returned: when config is configured + type: str + + # interfaces + ansible_net_all_ipv4_addresses: + description: All IPv4 addresses configured on the device + returned: when interfaces is configured + type: list + ansible_net_all_ipv6_addresses: + description: All IPv6 addresses configured on the device + returned: when interfaces is configured + type: list + ansible_net_interfaces: + description: A hash of all interfaces running on the system + returned: when interfaces is configured + type: dict + ansible_net_neighbors: + description: The list of neighbors from the remote device + returned: when interfaces is configured + type: dict + + # routing + ansible_net_bgp_peer: + description: The dict bgp peer + returned: peer information + type: dict + ansible_net_bgp_vpnv4_route: + description: The dict bgp vpnv4 route + returned: vpnv4 route information + type: dict + ansible_net_bgp_instance: + description: The dict bgp instance + returned: bgp instance information + type: dict + ansible_net_route: + description: The dict routes in all routing table + returned: routes information in all routing table + type: dict + ansible_net_ospf_instance: + description: The dict ospf instance + returned: ospf instance information + type: dict + ansible_net_ospf_neighbor: + description: The dict ospf neighbor + returned: ospf neighbor information + type: dict +""" +import re + +from ansible_collections.community.routeros.plugins.module_utils.routeros import run_commands +from ansible_collections.community.routeros.plugins.module_utils.routeros import routeros_argument_spec +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.six import iteritems + + +class FactsBase(object): + + COMMANDS = list() + + def __init__(self, module): + self.module = module + self.facts = dict() + self.responses = None + + def populate(self): + self.responses = run_commands(self.module, commands=self.COMMANDS, check_rc=False) + + def run(self, cmd): + return run_commands(self.module, commands=cmd, check_rc=False) + + +class Default(FactsBase): + + COMMANDS = [ + '/system identity print without-paging', + '/system resource print without-paging', + '/system routerboard print without-paging' + ] + + def populate(self): + super(Default, self).populate() + data = self.responses[0] + if data: + self.facts['hostname'] = self.parse_hostname(data) + data = self.responses[1] + if data: + self.facts['version'] = self.parse_version(data) + self.facts['arch'] = self.parse_arch(data) + self.facts['uptime'] = self.parse_uptime(data) + self.facts['cpu_load'] = self.parse_cpu_load(data) + data = self.responses[2] + if data: + self.facts['model'] = self.parse_model(data) + self.facts['serialnum'] = self.parse_serialnum(data) + + def parse_hostname(self, data): + match = re.search(r'name:\s(.*)\s*$', data, re.M) + if match: + return match.group(1) + + def parse_version(self, data): + match = re.search(r'version:\s(.*)\s*$', data, re.M) + if match: + return match.group(1) + + def parse_model(self, data): + match = re.search(r'model:\s(.*)\s*$', data, re.M) + if match: + return match.group(1) + + def parse_arch(self, data): + match = re.search(r'architecture-name:\s(.*)\s*$', data, re.M) + if match: + return match.group(1) + + def parse_uptime(self, data): + match = re.search(r'uptime:\s(.*)\s*$', data, re.M) + if match: + return match.group(1) + + def parse_cpu_load(self, data): + match = re.search(r'cpu-load:\s(.*)\s*$', data, re.M) + if match: + return match.group(1) + + def parse_serialnum(self, data): + match = re.search(r'serial-number:\s(.*)\s*$', data, re.M) + if match: + return match.group(1) + + +class Hardware(FactsBase): + + COMMANDS = [ + '/system resource print without-paging' + ] + + def populate(self): + super(Hardware, self).populate() + data = self.responses[0] + if data: + self.parse_filesystem_info(data) + self.parse_memory_info(data) + + def parse_filesystem_info(self, data): + match = re.search(r'free-hdd-space:\s(.*)([KMG]iB)', data, re.M) + if match: + self.facts['spacefree_mb'] = self.to_megabytes(match) + match = re.search(r'total-hdd-space:\s(.*)([KMG]iB)', data, re.M) + if match: + self.facts['spacetotal_mb'] = self.to_megabytes(match) + + def parse_memory_info(self, data): + match = re.search(r'free-memory:\s(\d+\.?\d*)([KMG]iB)', data, re.M) + if match: + self.facts['memfree_mb'] = self.to_megabytes(match) + match = re.search(r'total-memory:\s(\d+\.?\d*)([KMG]iB)', data, re.M) + if match: + self.facts['memtotal_mb'] = self.to_megabytes(match) + + def to_megabytes(self, data): + if data.group(2) == 'KiB': + return float(data.group(1)) / 1024 + elif data.group(2) == 'MiB': + return float(data.group(1)) + elif data.group(2) == 'GiB': + return float(data.group(1)) * 1024 + else: + return None + + +class Config(FactsBase): + + COMMANDS = ['/export verbose'] + + def populate(self): + super(Config, self).populate() + data = self.responses[0] + if data: + self.facts['config'] = data + + +class Interfaces(FactsBase): + + COMMANDS = [ + '/interface print detail without-paging', + '/ip address print detail without-paging', + '/ipv6 address print detail without-paging', + '/ip neighbor print detail without-paging' + ] + + DETAIL_RE = re.compile(r'([\w\d\-]+)=\"?(\w{3}/\d{2}/\d{4}\s\d{2}:\d{2}:\d{2}|[\w\d\-\.:/]+)') + WRAPPED_LINE_RE = re.compile(r'^\s+(?!\d)') + + def populate(self): + super(Interfaces, self).populate() + + self.facts['interfaces'] = dict() + self.facts['all_ipv4_addresses'] = list() + self.facts['all_ipv6_addresses'] = list() + self.facts['neighbors'] = list() + + data = self.responses[0] + if data: + interfaces = self.parse_interfaces(data) + self.populate_interfaces(interfaces) + + data = self.responses[1] + if data: + data = self.parse_detail(data) + self.populate_addresses(data, 'ipv4') + + data = self.responses[2] + if data: + data = self.parse_detail(data) + self.populate_addresses(data, 'ipv6') + + data = self.responses[3] + if data: + self.facts['neighbors'] = list(self.parse_detail(data)) + + def populate_interfaces(self, data): + for key, value in iteritems(data): + self.facts['interfaces'][key] = value + + def populate_addresses(self, data, family): + for value in data: + key = value['interface'] + if family not in self.facts['interfaces'][key]: + self.facts['interfaces'][key][family] = list() + addr, subnet = value['address'].split("/") + ip = dict(address=addr.strip(), subnet=subnet.strip()) + self.add_ip_address(addr.strip(), family) + self.facts['interfaces'][key][family].append(ip) + + def add_ip_address(self, address, family): + if family == 'ipv4': + self.facts['all_ipv4_addresses'].append(address) + else: + self.facts['all_ipv6_addresses'].append(address) + + def preprocess(self, data): + preprocessed = list() + for line in data.split('\n'): + if len(line) == 0 or line[:5] == 'Flags': + continue + elif not re.match(self.WRAPPED_LINE_RE, line): + preprocessed.append(line) + else: + preprocessed[-1] += line + return preprocessed + + def parse_interfaces(self, data): + facts = dict() + data = self.preprocess(data) + for line in data: + parsed = dict(re.findall(self.DETAIL_RE, line)) + if "name" not in parsed: + continue + facts[parsed["name"]] = dict(re.findall(self.DETAIL_RE, line)) + return facts + + def parse_detail(self, data): + data = self.preprocess(data) + for line in data: + parsed = dict(re.findall(self.DETAIL_RE, line)) + if "interface" not in parsed: + continue + yield parsed + + +class Routing(FactsBase): + + COMMANDS = [ + '/routing bgp peer print detail without-paging', + '/routing bgp vpnv4-route print detail without-paging', + '/routing bgp instance print detail without-paging', + '/ip route print detail without-paging', + '/routing ospf instance print detail without-paging', + '/routing ospf neighbor print detail without-paging' + ] + + DETAIL_RE = re.compile(r'([\w\d\-]+)=\"?(\w{3}/\d{2}/\d{4}\s\d{2}:\d{2}:\d{2}|[\w\d\-\.:/]+)') + WRAPPED_LINE_RE = re.compile(r'^\s+(?!\d)') + + def populate(self): + super(Routing, self).populate() + self.facts['bgp_peer'] = dict() + self.facts['bgp_vpnv4_route'] = dict() + self.facts['bgp_instance'] = dict() + self.facts['route'] = dict() + self.facts['ospf_instance'] = dict() + self.facts['ospf_neighbor'] = dict() + data = self.responses[0] + if data: + peer = self.parse_bgp_peer(data) + self.populate_bgp_peer(peer) + data = self.responses[1] + if data: + vpnv4 = self.parse_vpnv4_route(data) + self.populate_vpnv4_route(vpnv4) + data = self.responses[2] + if data: + instance = self.parse_instance(data) + self.populate_bgp_instance(instance) + data = self.responses[3] + if data: + route = self.parse_route(data) + self.populate_route(route) + data = self.responses[4] + if data: + instance = self.parse_instance(data) + self.populate_ospf_instance(instance) + data = self.responses[5] + if data: + instance = self.parse_ospf_neighbor(data) + self.populate_ospf_neighbor(instance) + + def preprocess(self, data): + preprocessed = list() + for line in data.split('\n'): + if len(line) == 0 or line[:5] == 'Flags': + continue + elif not re.match(self.WRAPPED_LINE_RE, line): + preprocessed.append(line) + else: + preprocessed[-1] += line + return preprocessed + + def parse_name(self, data): + match = re.search(r'name=.(\S+\b)', data, re.M) + if match: + return match.group(1) + + def parse_interface(self, data): + match = re.search(r'interface=([\w\d\-]+)', data, re.M) + if match: + return match.group(1) + + def parse_instance_name(self, data): + match = re.search(r'instance=([\w\d\-]+)', data, re.M) + if match: + return match.group(1) + + def parse_routing_mark(self, data): + match = re.search(r'routing-mark=([\w\d\-]+)', data, re.M) + if match: + return match.group(1) + else: + match = 'main' + return match + + def parse_bgp_peer(self, data): + facts = dict() + data = self.preprocess(data) + for line in data: + name = self.parse_name(line) + facts[name] = dict() + for (key, value) in re.findall(self.DETAIL_RE, line): + facts[name][key] = value + return facts + + def parse_instance(self, data): + facts = dict() + data = self.preprocess(data) + for line in data: + name = self.parse_name(line) + facts[name] = dict() + for (key, value) in re.findall(self.DETAIL_RE, line): + facts[name][key] = value + return facts + + def parse_vpnv4_route(self, data): + facts = dict() + data = self.preprocess(data) + for line in data: + name = self.parse_interface(line) + facts[name] = dict() + for (key, value) in re.findall(self.DETAIL_RE, line): + facts[name][key] = value + return facts + + def parse_route(self, data): + facts = dict() + data = self.preprocess(data) + for line in data: + name = self.parse_routing_mark(line) + facts[name] = dict() + for (key, value) in re.findall(self.DETAIL_RE, line): + facts[name][key] = value + return facts + + def parse_ospf_instance(self, data): + facts = dict() + data = self.preprocess(data) + for line in data: + name = self.parse_name(line) + facts[name] = dict() + for (key, value) in re.findall(self.DETAIL_RE, line): + facts[name][key] = value + return facts + + def parse_ospf_neighbor(self, data): + facts = dict() + data = self.preprocess(data) + for line in data: + name = self.parse_instance_name(line) + facts[name] = dict() + for (key, value) in re.findall(self.DETAIL_RE, line): + facts[name][key] = value + return facts + + def populate_bgp_peer(self, data): + for key, value in iteritems(data): + self.facts['bgp_peer'][key] = value + + def populate_vpnv4_route(self, data): + for key, value in iteritems(data): + self.facts['bgp_vpnv4_route'][key] = value + + def populate_bgp_instance(self, data): + for key, value in iteritems(data): + self.facts['bgp_instance'][key] = value + + def populate_route(self, data): + for key, value in iteritems(data): + self.facts['route'][key] = value + + def populate_ospf_instance(self, data): + for key, value in iteritems(data): + self.facts['ospf_instance'][key] = value + + def populate_ospf_neighbor(self, data): + for key, value in iteritems(data): + self.facts['ospf_neighbor'][key] = value + + +FACT_SUBSETS = dict( + default=Default, + hardware=Hardware, + interfaces=Interfaces, + config=Config, + routing=Routing, +) + +VALID_SUBSETS = frozenset(FACT_SUBSETS.keys()) + +warnings = list() + + +def main(): + """main entry point for module execution + """ + argument_spec = dict( + gather_subset=dict(default=['!config'], type='list') + ) + + argument_spec.update(routeros_argument_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + gather_subset = module.params['gather_subset'] + + runable_subsets = set() + exclude_subsets = set() + + for subset in gather_subset: + if subset == 'all': + runable_subsets.update(VALID_SUBSETS) + continue + + if subset.startswith('!'): + subset = subset[1:] + if subset == 'all': + exclude_subsets.update(VALID_SUBSETS) + continue + exclude = True + else: + exclude = False + + if subset not in VALID_SUBSETS: + module.fail_json(msg='Bad subset: %s' % subset) + + if exclude: + exclude_subsets.add(subset) + else: + runable_subsets.add(subset) + + if not runable_subsets: + runable_subsets.update(VALID_SUBSETS) + + runable_subsets.difference_update(exclude_subsets) + runable_subsets.add('default') + + facts = dict() + facts['gather_subset'] = list(runable_subsets) + + instances = list() + for key in runable_subsets: + instances.append(FACT_SUBSETS[key](module)) + + for inst in instances: + inst.populate() + facts.update(inst.facts) + + ansible_facts = dict() + for key, value in iteritems(facts): + key = 'ansible_net_%s' % key + ansible_facts[key] = value + + module.exit_json(ansible_facts=ansible_facts, warnings=warnings) + + +if __name__ == '__main__': + main() diff --git a/collections-debian-merged/ansible_collections/community/routeros/plugins/terminal/routeros.py b/collections-debian-merged/ansible_collections/community/routeros/plugins/terminal/routeros.py new file mode 100644 index 00000000..2c29d1db --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/plugins/terminal/routeros.py @@ -0,0 +1,69 @@ +# +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. +# +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json +import re + +from ansible.errors import AnsibleConnectionFailure +from ansible.module_utils._text import to_text, to_bytes +from ansible.plugins.terminal import TerminalBase +from ansible.utils.display import Display + +display = Display() + + +class TerminalModule(TerminalBase): + + ansi_re = [ + # check ECMA-48 Section 5.4 (Control Sequences) + re.compile(br'(\x1b\[\?1h\x1b=)'), + re.compile(br'((?:\x9b|\x1b\x5b)[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e])'), + re.compile(br'\x08.') + ] + + terminal_initial_prompt = [ + br'\x1bZ', + ] + + terminal_initial_answer = b'\x1b/Z' + + terminal_stdout_re = [ + re.compile(br"\x1b<"), + re.compile(br"\[[\w\-\.]+\@[\w\s\-\.\/]+\] ?> ?$"), + re.compile(br"Please press \"Enter\" to continue!"), + re.compile(br"Do you want to see the software license\? \[Y\/n\]: ?"), + ] + + terminal_stderr_re = [ + re.compile(br"\nbad command name"), + re.compile(br"\nno such item"), + re.compile(br"\ninvalid value for"), + ] + + def on_open_shell(self): + prompt = self._get_prompt() + try: + if prompt.strip().endswith(b':'): + self._exec_cli_command(b' ') + if prompt.strip().endswith(b'!'): + self._exec_cli_command(b'\n') + except AnsibleConnectionFailure: + raise AnsibleConnectionFailure('unable to bypass license prompt') diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/requirements.yml b/collections-debian-merged/ansible_collections/community/routeros/tests/requirements.yml new file mode 100644 index 00000000..a218740b --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/requirements.yml @@ -0,0 +1,4 @@ +integration_tests_dependencies: +- ansible.netcommon +unit_tests_dependencies: +- ansible.netcommon diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/sanity/ignore-2.10.txt b/collections-debian-merged/ansible_collections/community/routeros/tests/sanity/ignore-2.10.txt new file mode 100644 index 00000000..9d5934b3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/sanity/ignore-2.10.txt @@ -0,0 +1,5 @@ +plugins/modules/command.py validate-modules:doc-missing-type +plugins/modules/command.py validate-modules:parameter-list-no-elements +plugins/modules/command.py validate-modules:parameter-type-not-in-doc +plugins/modules/facts.py validate-modules:parameter-list-no-elements +plugins/modules/facts.py validate-modules:parameter-type-not-in-doc diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/sanity/ignore-2.11.txt b/collections-debian-merged/ansible_collections/community/routeros/tests/sanity/ignore-2.11.txt new file mode 100644 index 00000000..9d5934b3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/sanity/ignore-2.11.txt @@ -0,0 +1,5 @@ +plugins/modules/command.py validate-modules:doc-missing-type +plugins/modules/command.py validate-modules:parameter-list-no-elements +plugins/modules/command.py validate-modules:parameter-type-not-in-doc +plugins/modules/facts.py validate-modules:parameter-list-no-elements +plugins/modules/facts.py validate-modules:parameter-type-not-in-doc diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/sanity/ignore-2.9.txt b/collections-debian-merged/ansible_collections/community/routeros/tests/sanity/ignore-2.9.txt new file mode 100644 index 00000000..c1e40c7d --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/sanity/ignore-2.9.txt @@ -0,0 +1,3 @@ +plugins/modules/command.py validate-modules:doc-missing-type +plugins/modules/command.py validate-modules:parameter-type-not-in-doc +plugins/modules/facts.py validate-modules:parameter-type-not-in-doc diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/__init__.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/__init__.py diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/builtins.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/builtins.py new file mode 100644 index 00000000..f60ee678 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/builtins.py @@ -0,0 +1,33 @@ +# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +# +# Compat for python2.7 +# + +# One unittest needs to import builtins via __import__() so we need to have +# the string that represents it +try: + import __builtin__ +except ImportError: + BUILTINS = 'builtins' +else: + BUILTINS = '__builtin__' diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/mock.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/mock.py new file mode 100644 index 00000000..0972cd2e --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/mock.py @@ -0,0 +1,122 @@ +# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +''' +Compat module for Python3.x's unittest.mock module +''' +import sys + +# Python 2.7 + +# Note: Could use the pypi mock library on python3.x as well as python2.x. It +# is the same as the python3 stdlib mock library + +try: + # Allow wildcard import because we really do want to import all of mock's + # symbols into this compat shim + # pylint: disable=wildcard-import,unused-wildcard-import + from unittest.mock import * +except ImportError: + # Python 2 + # pylint: disable=wildcard-import,unused-wildcard-import + try: + from mock import * + except ImportError: + print('You need the mock library installed on python2.x to run tests') + + +# Prior to 3.4.4, mock_open cannot handle binary read_data +if sys.version_info >= (3,) and sys.version_info < (3, 4, 4): + file_spec = None + + def _iterate_read_data(read_data): + # Helper for mock_open: + # Retrieve lines from read_data via a generator so that separate calls to + # readline, read, and readlines are properly interleaved + sep = b'\n' if isinstance(read_data, bytes) else '\n' + data_as_list = [l + sep for l in read_data.split(sep)] + + if data_as_list[-1] == sep: + # If the last line ended in a newline, the list comprehension will have an + # extra entry that's just a newline. Remove this. + data_as_list = data_as_list[:-1] + else: + # If there wasn't an extra newline by itself, then the file being + # emulated doesn't have a newline to end the last line remove the + # newline that our naive format() added + data_as_list[-1] = data_as_list[-1][:-1] + + for line in data_as_list: + yield line + + def mock_open(mock=None, read_data=''): + """ + A helper function to create a mock to replace the use of `open`. It works + for `open` called directly or used as a context manager. + + The `mock` argument is the mock object to configure. If `None` (the + default) then a `MagicMock` will be created for you, with the API limited + to methods or attributes available on standard file handles. + + `read_data` is a string for the `read` methoddline`, and `readlines` of the + file handle to return. This is an empty string by default. + """ + def _readlines_side_effect(*args, **kwargs): + if handle.readlines.return_value is not None: + return handle.readlines.return_value + return list(_data) + + def _read_side_effect(*args, **kwargs): + if handle.read.return_value is not None: + return handle.read.return_value + return type(read_data)().join(_data) + + def _readline_side_effect(): + if handle.readline.return_value is not None: + while True: + yield handle.readline.return_value + for line in _data: + yield line + + global file_spec + if file_spec is None: + import _io + file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO)))) + + if mock is None: + mock = MagicMock(name='open', spec=open) + + handle = MagicMock(spec=file_spec) + handle.__enter__.return_value = handle + + _data = _iterate_read_data(read_data) + + handle.write.return_value = None + handle.read.return_value = None + handle.readline.return_value = None + handle.readlines.return_value = None + + handle.read.side_effect = _read_side_effect + handle.readline.side_effect = _readline_side_effect() + handle.readlines.side_effect = _readlines_side_effect + + mock.return_value = handle + return mock diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/unittest.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/unittest.py new file mode 100644 index 00000000..98f08ad6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/compat/unittest.py @@ -0,0 +1,38 @@ +# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +''' +Compat module for Python2.7's unittest module +''' + +import sys + +# Allow wildcard import because we really do want to import all of +# unittests's symbols into this compat shim +# pylint: disable=wildcard-import,unused-wildcard-import +if sys.version_info < (2, 7): + try: + # Need unittest2 on python2.6 + from unittest2 import * + except ImportError: + print('You need unittest2 installed on python2.6.x to run tests') +else: + from unittest import * diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/__init__.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/__init__.py diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/__init__.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/__init__.py diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/export_verbose b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/export_verbose new file mode 100644 index 00000000..0f49fefe --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/export_verbose @@ -0,0 +1,26 @@ +# sep/25/2018 10:10:52 by RouterOS 6.42.5 +# software id = 9EER-511K +# +# +# +/interface wireless security-profiles +set [ find default=yes ] supplicant-identity=MikroTik +/tool user-manager customer +set admin access=own-routers,own-users,own-profiles,own-limits,config-payment-gw +/ip address +add address=192.168.88.1/24 comment=defconf interface=ether1 network=192.168.88.0 +/ip dhcp-client +add dhcp-options=hostname,clientid disabled=no interface=ether1 +/system lcd +set contrast=0 enabled=no port=parallel type=24x4 +/system lcd page +set time disabled=yes display-time=5s +set resources disabled=yes display-time=5s +set uptime disabled=yes display-time=5s +set packets disabled=yes display-time=5s +set bits disabled=yes display-time=5s +set version disabled=yes display-time=5s +set identity disabled=yes display-time=5s +set ether1 disabled=yes display-time=5s +/tool user-manager database +set db-path=user-manager diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/interface_print_detail_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/interface_print_detail_without-paging new file mode 100644 index 00000000..9ccddb29 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/interface_print_detail_without-paging @@ -0,0 +1,34 @@ +Flags: D - dynamic, X - disabled, R - running, S - slave + 0 R name="ether1" default-name="ether1" type="ether" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:90 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 + 1 R name="ether2" default-name="ether2" type="ether" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:91 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 + 2 R name="ether3" default-name="ether3" type="ether" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:92 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 + 3 R name="ether4" default-name="ether4" type="ether" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:93 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 + 4 R name="ether5" default-name="ether5" type="ether" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:94 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 + 5 R name="ether6" default-name="ether6" type="ether" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:95 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 + 6 R name="ether7" default-name="ether7" type="ether" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:96 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 + 7 R name="ether8" default-name="ether8" type="ether" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:97 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 + 8 R name="ether9" default-name="ether9" type="ether" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:98 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 + 9 R name="ether10" default-name="ether10" type="ether" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:99 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 +10 R name="pppoe" default-name="pppoe" type="ppp" mtu=1500 actual-mtu=1500 + mac-address=00:1C:42:36:52:00 last-link-up-time=sep/25/2018 06:30:04 + link-downs=0 diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ip_address_print_detail_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ip_address_print_detail_without-paging new file mode 100644 index 00000000..d4fd2bcd --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ip_address_print_detail_without-paging @@ -0,0 +1,10 @@ +Flags: X - disabled, I - invalid, D - dynamic + 0 ;;; defconf + address=192.168.88.1/24 network=192.168.88.0 interface=ether1 + actual-interface=ether1 + + 1 D address=10.37.129.3/24 network=10.37.129.0 interface=ether1 + actual-interface=ether1 + + 2 D address=10.37.0.0/24 network=10.37.0.1 interface=pppoe + actual-interface=pppoe diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ip_neighbor_print_detail_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ip_neighbor_print_detail_without-paging new file mode 100644 index 00000000..906dfb75 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ip_neighbor_print_detail_without-paging @@ -0,0 +1,15 @@ + 0 interface=ether2-master address=10.37.129.3 address4=10.37.129.3 mac-address=D4:CA:6D:C6:16:4C identity="router1" platform="MikroTik" version="6.42.2 (stable)" unpack=none age=59s + uptime=3w19h11m36s software-id="1234-1234" board="RBwAPG-5HacT2HnD" interface-name="bridge" system-description="MikroTik RouterOS 6.42.2 (stable) RBwAPG-5HacT2HnD" + system-caps="" system-caps-enabled="" + + 1 interface=ether3 address=10.37.129.4 address4=10.37.129.4 mac-address=D4:CA:6D:C6:18:2F identity="router2" platform="MikroTik" version="6.42.2 (stable)" unpack=none age=54s + uptime=3w19h11m30s software-id="1234-1234" board="RBwAPG-5HacT2HnD" ipv6=no interface-name="bridge" system-description="MikroTik RouterOS 6.42.2 (stable) RBwAPG-5HacT2HnD" + system-caps="" system-caps-enabled="" + + 2 interface=ether5 address=10.37.129.5 address4=10.37.129.5 mac-address=B8:69:F4:37:F0:C8 identity="router3" platform="MikroTik" version="6.40.8 (bugfix)" unpack=none age=43s + uptime=3d14h25m31s software-id="1234-1234" board="RB960PGS" interface-name="ether1" system-description="MikroTik RouterOS 6.40.8 (bugfix) RB960PGS" system-caps="" + system-caps-enabled="" + + 3 interface=ether10 address=10.37.129.6 address4=10.37.129.6 mac-address=6C:3B:6B:A1:0B:63 identity="router4" platform="MikroTik" version="6.42.2 (stable)" unpack=none age=54s + uptime=3w6d1h11m44s software-id="1234-1234" board="RBSXTLTE3-7" interface-name="bridge" system-description="MikroTik RouterOS 6.42.2 (stable) RBSXTLTE3-7" system-caps="" + system-caps-enabled="" diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ip_route_print_detail_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ip_route_print_detail_without-paging new file mode 100644 index 00000000..6c2e558e --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ip_route_print_detail_without-paging @@ -0,0 +1,19 @@ +Flags: X - disabled, A - active, D - dynamic, +C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, +B - blackhole, U - unreachable, P - prohibit + 0 ADC dst-address=10.10.66.0/30 pref-src=10.10.66.1 gateway=bridge1 + gateway-status=bridge1 reachable distance=0 scope=10 + routing-mark=altegro + + 2 A S dst-address=0.0.0.0/0 gateway=85.15.75.109 + gateway-status=85.15.75.109 reachable via Internet-VTK distance=1 + scope=30 target-scope=10 + + 3 ADC dst-address=10.10.1.0/30 pref-src=10.10.1.1 gateway=GRE_TYRMA + gateway-status=GRE_TYRMA reachable distance=0 scope=10 + + 4 DC dst-address=10.10.1.4/30 pref-src=10.10.1.5 gateway=RB2011 + gateway-status=RB2011 unreachable distance=255 scope=10 + + 5 ADC dst-address=10.10.2.0/30 pref-src=10.10.2.1 gateway=VLAN_SAT.ROUTER + gateway-status=VLAN_SAT.ROUTER reachable distance=0 scope=10 diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ipv6_address_print_detail_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ipv6_address_print_detail_without-paging new file mode 100644 index 00000000..c18e9ea5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ipv6_address_print_detail_without-paging @@ -0,0 +1,3 @@ +Flags: X - disabled, I - invalid, D - dynamic, G - global, L - link-local + 0 DL address=fe80::21c:42ff:fe36:5290/64 from-pool="" interface=ether1 + actual-interface=ether1 eui-64=no advertise=no no-dad=no diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ipv6_address_print_detail_without-paging_no-ipv6 b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ipv6_address_print_detail_without-paging_no-ipv6 new file mode 100644 index 00000000..0ea34bc0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/ipv6_address_print_detail_without-paging_no-ipv6 @@ -0,0 +1 @@ +bad command name address (line 1 column 7) diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_bgp_instance_print_detail_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_bgp_instance_print_detail_without-paging new file mode 100644 index 00000000..8c560e2a --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_bgp_instance_print_detail_without-paging @@ -0,0 +1,10 @@ +Flags: * - default, X - disabled + 0 *X name="default" as=65530 router-id=0.0.0.0 redistribute-connected=no + redistribute-static=no redistribute-rip=no redistribute-ospf=no + redistribute-other-bgp=no out-filter="" client-to-client-reflection=yes + ignore-as-path-len=no routing-table="" + + 1 name="MAIN_AS_STARKDV" as=64520 router-id=10.10.50.1 + redistribute-connected=no redistribute-static=no redistribute-rip=no + redistribute-ospf=no redistribute-other-bgp=no out-filter="" + client-to-client-reflection=yes ignore-as-path-len=no routing-table="" diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_bgp_peer_print_detail_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_bgp_peer_print_detail_without-paging new file mode 100644 index 00000000..1ae4f5bc --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_bgp_peer_print_detail_without-paging @@ -0,0 +1,13 @@ +Flags: X - disabled, E - established + 0 E name="iBGP_BRAS.TYRMA" instance=MAIN_AS_STARKDV remote-address=10.10.100.1 + remote-as=64520 tcp-md5-key="" nexthop-choice=default multihop=no + route-reflect=yes hold-time=3m ttl=default in-filter="" out-filter="" + address-families=ip,l2vpn,vpnv4 update-source=LAN_KHV + default-originate=never remove-private-as=no as-override=no passive=no + use-bfd=yes + + 1 E name="iBGP_BRAS_SAT" instance=MAIN_AS_STARKDV remote-address=10.10.50.230 + remote-as=64520 tcp-md5-key="" nexthop-choice=default multihop=no + route-reflect=yes hold-time=3m ttl=default in-filter="" out-filter="" + address-families=ip default-originate=never remove-private-as=no + as-override=no passive=no use-bfd=yes diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_bgp_vpnv4-route_print_detail_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_bgp_vpnv4-route_print_detail_without-paging new file mode 100644 index 00000000..f64fa6d0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_bgp_vpnv4-route_print_detail_without-paging @@ -0,0 +1,7 @@ +Flags: L - label-present + 0 L route-distinguisher=64520:666 dst-address=10.10.66.8/30 gateway=10.10.100.1 + interface=GRE_TYRMA in-label=6136 out-label=6136 bgp-local-pref=100 + bgp-origin=incomplete bgp-ext-communities="RT:64520:666" + + 1 L route-distinguisher=64520:666 dst-address=10.10.66.0/30 interface=bridge1 + in-label=1790 bgp-ext-communities="RT:64520:666" diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_ospf_instance_print_detail_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_ospf_instance_print_detail_without-paging new file mode 100644 index 00000000..96404663 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_ospf_instance_print_detail_without-paging @@ -0,0 +1,10 @@ +Flags: X - disabled, * - default + 0 * name="default" router-id=10.10.50.1 distribute-default=never redistribute-connected=no + redistribute-static=no redistribute-rip=no redistribute-bgp=no redistribute-other-ospf=no + metric-default=1 metric-connected=20 metric-static=20 metric-rip=20 metric-bgp=auto + metric-other-ospf=auto in-filter=ospf-in out-filter=ospf-out + + 1 name="OSPF_ALTEGRO" router-id=10.10.66.1 distribute-default=never redistribute-connected=no + redistribute-static=no redistribute-rip=no redistribute-bgp=no redistribute-other-ospf=no + metric-default=1 metric-connected=20 metric-static=20 metric-rip=20 metric-bgp=auto + metric-other-ospf=auto in-filter=ospf-in out-filter=ospf-out routing-table=altegro diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_ospf_neighbor_print_detail_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_ospf_neighbor_print_detail_without-paging new file mode 100644 index 00000000..d683b252 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/routing_ospf_neighbor_print_detail_without-paging @@ -0,0 +1,3 @@ +0 instance=default router-id=10.10.100.1 address=10.10.1.2 interface=GRE_TYRMA priority=1 + dr-address=0.0.0.0 backup-dr-address=0.0.0.0 state="Full" state-changes=15 ls-retransmits=0 + ls-requests=0 db-summaries=0 adjacency=6h8m46s diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/system_identity_print_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/system_identity_print_without-paging new file mode 100644 index 00000000..d7dc3ff3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/system_identity_print_without-paging @@ -0,0 +1 @@ + name: MikroTik diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/system_resource_print_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/system_resource_print_without-paging new file mode 100644 index 00000000..79353f79 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/system_resource_print_without-paging @@ -0,0 +1,16 @@ + uptime: 3h28m52s + version: 6.42.5 (stable) + build-time: Jun/26/2018 12:12:08 + free-memory: 988.3MiB + total-memory: 1010.8MiB + cpu: Intel(R) + cpu-count: 2 + cpu-frequency: 2496MHz + cpu-load: 0% + free-hdd-space: 63.4GiB + total-hdd-space: 63.5GiB + write-sect-since-reboot: 4576 + write-sect-total: 4576 + architecture-name: x86 + board-name: x86 + platform: MikroTik diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/system_routerboard_print_without-paging b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/system_routerboard_print_without-paging new file mode 100644 index 00000000..263c9590 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/facts/system_routerboard_print_without-paging @@ -0,0 +1,7 @@ + routerboard: yes + model: RouterBOARD 3011UiAS + serial-number: 1234567890 + firmware-type: ipq8060 + factory-firmware: 3.41 + current-firmware: 3.41 + upgrade-firmware: 6.42.2 diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/system_package_print b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/system_package_print new file mode 100644 index 00000000..3f806211 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/system_package_print @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + MMM MMM KKK TTTTTTTTTTT KKK + + MMMM MMMM KKK TTTTTTTTTTT KKK + + MMM MMMM MMM III KKK KKK RRRRRR OOOOOO TTT III KKK KKK + + MMM MM MMM III KKKKK RRR RRR OOO OOO TTT III KKKKK + + MMM MMM III KKK KKK RRRRRR OOO OOO TTT III KKK KKK + + MMM MMM III KKK KKK RRR RRR OOOOOO TTT III KKK KKK + + + + MikroTik RouterOS 6.42.5 (c) 1999-2018 http://www.mikrotik.com/ + + +[?] Gives the list of available commands + +command [?] Gives help on the command and list of arguments + + + +[Tab] Completes the command/word. If the input is ambiguous, + + a second [Tab] gives possible options + + + +/ Move up to base level + +.. Move up one level + +/command Use command at the base level + +[9999B +[9999BZ [6n<[c[4l[20l[?47l[?7h[?5l[?25h[H[9999B[6n + + + +[admin@MainRouter] > +[admin@MainRouter] > /system routerboard print +[admin@MainRouter] > /system routerboard print + + routerboard: yes + model: 750GL + serial-number: 1234567890AB + firmware-type: ar7240 + factory-firmware: 3.09 + current-firmware: 6.41.2 + upgrade-firmware: 6.42.5 + + + + + +[admin@MainRouter] > +[admin@MainRouter] > /system identity print +[admin@MainRouter] > /system identity print + + name: MikroTik + + + + + +[admin@MainRouter] > +[admin@MainRouter] > /system package print +[admin@MainRouter] > /system package print + +Flags: [m[1mX[m - disabled +[m[1m # NAME VERSION SCHEDULED +[m 0 routeros-mipsbe 6.42.5 + 1 system 6.42.5 + 2 ipv6 6.42.5 + 3 wireless 6.42.5 + 4 hotspot 6.42.5 + 5 dhcp 6.42.5 + 6 mpls 6.42.5 + 7 routing 6.42.5 + 8 ppp 6.42.5 + 9 security 6.42.5 +10 advanced-tools 6.42.5 + + + + + +[admin@MainRouter] > +[admin@MainRouter] >
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/system_resource_print b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/system_resource_print new file mode 100644 index 00000000..63bc3beb --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/fixtures/system_resource_print @@ -0,0 +1,17 @@ +[admin@RB1100test] /system resource> print + uptime: 2w1d23h34m57s + version: "5.0rc1" + free-memory: 385272KiB + total-memory: 516708KiB + cpu: "e500v2" + cpu-count: 1 + cpu-frequency: 799MHz + cpu-load: 9% + free-hdd-space: 466328KiB + total-hdd-space: 520192KiB + write-sect-since-reboot: 1411 + write-sect-total: 70625 + bad-blocks: 0.2% + architecture-name: "powerpc" + board-name: "RB1100" + platform: "MikroTik" diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/routeros_module.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/routeros_module.py new file mode 100644 index 00000000..9cad18e3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/routeros_module.py @@ -0,0 +1,88 @@ +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import os +import json + +from ansible_collections.community.routeros.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase + + +fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') +fixture_data = {} + + +def load_fixture(name): + path = os.path.join(fixture_path, name) + + if path in fixture_data: + return fixture_data[path] + + with open(path) as f: + data = f.read() + + try: + data = json.loads(data) + except Exception: + pass + + fixture_data[path] = data + return data + + +class TestRouterosModule(ModuleTestCase): + + def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False): + + self.load_fixtures(commands) + + if failed: + result = self.failed() + self.assertTrue(result['failed'], result) + else: + result = self.changed(changed) + self.assertEqual(result['changed'], changed, result) + + if commands is not None: + if sort: + self.assertEqual(sorted(commands), sorted(result['commands']), result['commands']) + else: + self.assertEqual(commands, result['commands'], result['commands']) + + return result + + def failed(self): + with self.assertRaises(AnsibleFailJson) as exc: + self.module.main() + + result = exc.exception.args[0] + self.assertTrue(result['failed'], result) + return result + + def changed(self, changed=False): + with self.assertRaises(AnsibleExitJson) as exc: + self.module.main() + + result = exc.exception.args[0] + self.assertEqual(result['changed'], changed, result) + return result + + def load_fixtures(self, commands=None): + pass diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/test_api.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/test_api.py new file mode 100644 index 00000000..1befeff6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/test_api.py @@ -0,0 +1,266 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json +import pytest + +from ansible_collections.community.routeros.tests.unit.compat.mock import patch, MagicMock +from ansible_collections.community.routeros.tests.unit.plugins.modules.utils import set_module_args, basic, AnsibleExitJson, AnsibleFailJson, ModuleTestCase +from ansible_collections.community.routeros.plugins.modules import api + + +class AnsibleExitJson(Exception): + """Exception class to be raised by module.exit_json and caught by the test case""" + pass + + +class AnsibleFailJson(Exception): + """Exception class to be raised by module.fail_json and caught by the test case""" + pass + + +def exit_json(*args, **kwargs): + """function to patch over exit_json; package return data into an exception""" + if 'changed' not in kwargs: + kwargs['changed'] = False + raise AnsibleExitJson(kwargs) + + +def fail_json(*args, **kwargs): + """function to patch over fail_json; package return data into an exception""" + kwargs['failed'] = True + raise AnsibleFailJson(kwargs) + + +# fixtures +class fake_ros_api: + def __init__(self, api, path): + pass + + def path(self, api, path): + fake_bridge = [{".id": "*DC", "name": "b2", "mtu": "auto", "actual-mtu": 1500, + "l2mtu": 65535, "arp": "enabled", "arp-timeout": "auto", + "mac-address": "3A:C1:90:D6:E8:44", "protocol-mode": "rstp", + "fast-forward": "true", "igmp-snooping": "false", + "auto-mac": "true", "ageing-time": "5m", "priority": + "0x8000", "max-message-age": "20s", "forward-delay": "15s", + "transmit-hold-count": 6, "vlan-filtering": "false", + "dhcp-snooping": "false", "running": "true", "disabled": "false"}] + return fake_bridge + + def arbitrary(self, api, path): + def retr(self, *args, **kwargs): + if 'name' not in kwargs.keys(): + raise TrapError(message="no such command") + dummy_test_string = '/interface/bridge add name=unit_test_brige_arbitrary' + result = "/%s/%s add name=%s" % (path[0], path[1], kwargs['name']) + return [result] + return retr + + def add(self, name): + if name == "unit_test_brige_exist": + raise TrapError + return '*A1' + + def remove(self, id): + if id != "*A1": + raise TrapError(message="no such item (4)") + return '*A1' + + def update(self, **kwargs): + if kwargs['.id'] != "*A1" or 'name' not in kwargs.keys(): + raise TrapError(message="no such item (4)") + return ["updated: {'.id': '%s' % kwargs['.id'], 'name': '%s' % kwargs['name']}"] + + def select(self, *args): + dummy_bridge = [{".id": "*A1", "name": "dummy_bridge_A1"}, + {".id": "*A2", "name": "dummy_bridge_A2"}, + {".id": "*A3", "name": "dummy_bridge_A3"}] + + result = [] + for dummy in dummy_bridge: + found = {} + for search in args: + if search in dummy.keys(): + found[search] = dummy[search] + else: + continue + if len(found.keys()) == 2: + result.append(found) + + if result: + return result + else: + return ["no results for 'interface bridge 'query' %s" % ' '.join(args)] + + def select_where(self, api, path): + api_path = Where() + return api_path + + +class Where: + def __init__(self): + pass + + def select(self, *args): + return self + + def where(self, *args): + return ["*A1"] + + +class TrapError(Exception): + def __init__(self, message="failure: already have interface with such name"): + self.message = message + super().__init__(self.message) + + +class Key: + def __init__(self, name): + self.name = name + self.str_return() + + def str_return(self): + return str(self.name) + + +class TestRouterosApiModule(ModuleTestCase): + + def setUp(self): + librouteros = pytest.importorskip("librouteros") + self.module = api + self.module.connect = MagicMock(new=fake_ros_api) + self.module.Key = MagicMock(new=Key) + self.config_module_args = {"username": "admin", + "password": "pаss", + "hostname": "127.0.0.1", + "path": "interface bridge"} + + self.mock_module_helper = patch.multiple(basic.AnsibleModule, + exit_json=exit_json, + fail_json=fail_json) + self.mock_module_helper.start() + self.addCleanup(self.mock_module_helper.stop) + + def test_module_fail_when_required_args_missing(self): + with self.assertRaises(AnsibleFailJson): + set_module_args({}) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api.path) + def test_api_path(self): + with self.assertRaises(AnsibleExitJson): + set_module_args(self.config_module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api.arbitrary) + def test_api_add(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['add'] = "name=unit_test_brige" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api) + def test_api_add_already_exist(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['add'] = "name=unit_test_brige_exist" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api) + def test_api_remove(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['remove'] = "*A1" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api) + def test_api_remove_no_id(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['remove'] = "*A2" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api.arbitrary) + def test_api_cmd(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['cmd'] = "add name=unit_test_brige_arbitrary" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api.arbitrary) + def test_api_cmd_none_existing_cmd(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['cmd'] = "add NONE_EXIST=unit_test_brige_arbitrary" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api) + def test_api_update(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['update'] = ".id=*A1 name=unit_test_brige" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api) + def test_api_update_none_existing_id(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['update'] = ".id=*A2 name=unit_test_brige" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api) + def test_api_query(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['query'] = ".id name" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api) + def test_api_query_missing_key(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['query'] = ".id other" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api.select_where) + def test_api_query_and_WHERE(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['query'] = ".id name WHERE name == dummy_bridge_A2" + set_module_args(module_args) + self.module.main() + + @patch('ansible_collections.community.routeros.plugins.modules.api.ROS_api_module.api_add_path', new=fake_ros_api.select_where) + def test_api_query_and_WHERE_no_cond(self): + with self.assertRaises(AnsibleExitJson): + module_args = self.config_module_args.copy() + module_args['query'] = ".id name WHERE name =! dummy_bridge_A2" + set_module_args(module_args) + self.module.main() diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/test_command.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/test_command.py new file mode 100644 index 00000000..ab045fe5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/test_command.py @@ -0,0 +1,113 @@ +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json + +from ansible_collections.community.routeros.tests.unit.compat.mock import patch +from ansible_collections.community.routeros.plugins.modules import command +from ansible_collections.community.routeros.tests.unit.plugins.modules.utils import set_module_args +from .routeros_module import TestRouterosModule, load_fixture + + +class TestRouterosCommandModule(TestRouterosModule): + + module = command + + def setUp(self): + super(TestRouterosCommandModule, self).setUp() + + self.mock_run_commands = patch('ansible_collections.community.routeros.plugins.modules.command.run_commands') + self.run_commands = self.mock_run_commands.start() + + def tearDown(self): + super(TestRouterosCommandModule, self).tearDown() + self.mock_run_commands.stop() + + def load_fixtures(self, commands=None): + + def load_from_file(*args, **kwargs): + module, commands = args + output = list() + + for item in commands: + try: + obj = json.loads(item) + command = obj + except ValueError: + command = item + filename = str(command).replace(' ', '_').replace('/', '') + output.append(load_fixture(filename)) + return output + + self.run_commands.side_effect = load_from_file + + def test_command_simple(self): + set_module_args(dict(commands=['/system resource print'])) + result = self.execute_module() + self.assertEqual(len(result['stdout']), 1) + self.assertTrue('platform: "MikroTik"' in result['stdout'][0]) + + def test_command_multiple(self): + set_module_args(dict(commands=['/system resource print', '/system resource print'])) + result = self.execute_module() + self.assertEqual(len(result['stdout']), 2) + self.assertTrue('platform: "MikroTik"' in result['stdout'][0]) + + def test_command_wait_for(self): + wait_for = 'result[0] contains "MikroTik"' + set_module_args(dict(commands=['/system resource print'], wait_for=wait_for)) + self.execute_module() + + def test_command_wait_for_fails(self): + wait_for = 'result[0] contains "test string"' + set_module_args(dict(commands=['/system resource print'], wait_for=wait_for)) + self.execute_module(failed=True) + self.assertEqual(self.run_commands.call_count, 10) + + def test_command_retries(self): + wait_for = 'result[0] contains "test string"' + set_module_args(dict(commands=['/system resource print'], wait_for=wait_for, retries=2)) + self.execute_module(failed=True) + self.assertEqual(self.run_commands.call_count, 2) + + def test_command_match_any(self): + wait_for = ['result[0] contains "MikroTik"', + 'result[0] contains "test string"'] + set_module_args(dict(commands=['/system resource print'], wait_for=wait_for, match='any')) + self.execute_module() + + def test_command_match_all(self): + wait_for = ['result[0] contains "MikroTik"', + 'result[0] contains "RB1100"'] + set_module_args(dict(commands=['/system resource print'], wait_for=wait_for, match='all')) + self.execute_module() + + def test_command_match_all_failure(self): + wait_for = ['result[0] contains "MikroTik"', + 'result[0] contains "test string"'] + commands = ['/system resource print', '/system resource print'] + set_module_args(dict(commands=commands, wait_for=wait_for, match='all')) + self.execute_module(failed=True) + + def test_command_wait_for_2(self): + wait_for = 'result[0] contains "wireless"' + set_module_args(dict(commands=['/system package print'], wait_for=wait_for)) + self.execute_module() diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/test_facts.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/test_facts.py new file mode 100644 index 00000000..25fb04e2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/test_facts.py @@ -0,0 +1,342 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible_collections.community.routeros.tests.unit.compat.mock import patch +from ansible_collections.community.routeros.plugins.modules import facts +from ansible_collections.community.routeros.tests.unit.plugins.modules.utils import set_module_args +from .routeros_module import TestRouterosModule, load_fixture + + +class TestRouterosFactsModule(TestRouterosModule): + + module = facts + + def setUp(self): + super(TestRouterosFactsModule, self).setUp() + self.mock_run_commands = patch('ansible_collections.community.routeros.plugins.modules.facts.run_commands') + self.run_commands = self.mock_run_commands.start() + + def tearDown(self): + super(TestRouterosFactsModule, self).tearDown() + self.mock_run_commands.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + module = args + commands = kwargs['commands'] + output = list() + + for command in commands: + filename = str(command).split(' | ')[0].replace(' ', '_') + output.append(load_fixture('facts%s' % filename)) + return output + + self.run_commands.side_effect = load_from_file + + def test_facts_default(self): + set_module_args(dict(gather_subset='default')) + result = self.execute_module() + self.assertEqual( + result['ansible_facts']['ansible_net_hostname'], 'MikroTik' + ) + self.assertEqual( + result['ansible_facts']['ansible_net_version'], '6.42.5 (stable)' + ) + self.assertEqual( + result['ansible_facts']['ansible_net_model'], 'RouterBOARD 3011UiAS' + ) + self.assertEqual( + result['ansible_facts']['ansible_net_serialnum'], '1234567890' + ) + self.assertEqual( + result['ansible_facts']['ansible_net_arch'], 'x86' + ) + self.assertEqual( + result['ansible_facts']['ansible_net_uptime'], '3h28m52s' + ) + + def test_facts_hardware(self): + set_module_args(dict(gather_subset='hardware')) + result = self.execute_module() + self.assertEqual( + result['ansible_facts']['ansible_net_spacefree_mb'], 64921.6 + ) + self.assertEqual( + result['ansible_facts']['ansible_net_spacetotal_mb'], 65024.0 + ) + self.assertEqual( + result['ansible_facts']['ansible_net_memfree_mb'], 988.3 + ) + self.assertEqual( + result['ansible_facts']['ansible_net_memtotal_mb'], 1010.8 + ) + + def test_facts_config(self): + set_module_args(dict(gather_subset='config')) + result = self.execute_module() + self.assertIsInstance( + result['ansible_facts']['ansible_net_config'], str + ) + + def test_facts_interfaces(self): + set_module_args(dict(gather_subset='interfaces')) + result = self.execute_module() + self.assertIn( + result['ansible_facts']['ansible_net_all_ipv4_addresses'][0], ['10.37.129.3', '10.37.0.0', '192.168.88.1'] + ) + self.assertEqual( + result['ansible_facts']['ansible_net_all_ipv6_addresses'], ['fe80::21c:42ff:fe36:5290'] + ) + self.assertEqual( + result['ansible_facts']['ansible_net_all_ipv6_addresses'][0], + result['ansible_facts']['ansible_net_interfaces']['ether1']['ipv6'][0]['address'] + ) + self.assertEqual( + len(result['ansible_facts']['ansible_net_interfaces'].keys()), 11 + ) + self.assertEqual( + len(result['ansible_facts']['ansible_net_neighbors']), 4 + ) + + def test_facts_interfaces_no_ipv6(self): + fixture = load_fixture( + 'facts/ipv6_address_print_detail_without-paging_no-ipv6' + ) + interfaces = self.module.Interfaces(module=self.module) + addresses = interfaces.parse_detail(data=fixture) + result = interfaces.populate_addresses(data=addresses, family='ipv6') + + self.assertEqual(result, None) + + def test_facts_routing(self): + set_module_args(dict(gather_subset='routing')) + result = self.execute_module() + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['name'], ['iBGP_BRAS.TYRMA'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['instance'], ['MAIN_AS_STARKDV'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['remote-address'], ['10.10.100.1'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['remote-as'], ['64520'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['nexthop-choice'], ['default'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['multihop'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['route-reflect'], ['yes'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['hold-time'], ['3m'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['ttl'], ['default'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['address-families'], ['ip'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['update-source'], ['LAN_KHV'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['default-originate'], ['never'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['remove-private-as'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['as-override'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['passive'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_peer']['iBGP_BRAS.TYRMA']['use-bfd'], ['yes'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_vpnv4_route']['GRE_TYRMA']['route-distinguisher'], ['64520:666'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_vpnv4_route']['GRE_TYRMA']['dst-address'], ['10.10.66.8/30'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_vpnv4_route']['GRE_TYRMA']['gateway'], ['10.10.100.1'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_vpnv4_route']['GRE_TYRMA']['interface'], ['GRE_TYRMA'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_vpnv4_route']['GRE_TYRMA']['in-label'], ['6136'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_vpnv4_route']['GRE_TYRMA']['out-label'], ['6136'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_vpnv4_route']['GRE_TYRMA']['bgp-local-pref'], ['100'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_vpnv4_route']['GRE_TYRMA']['bgp-origin'], ['incomplete'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_vpnv4_route']['GRE_TYRMA']['bgp-ext-communities'], ['RT:64520:666'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_instance']['default']['name'], ['default'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_instance']['default']['as'], ['65530'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_instance']['default']['router-id'], ['0.0.0.0'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_instance']['default']['redistribute-connected'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_instance']['default']['redistribute-static'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_instance']['default']['redistribute-rip'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_instance']['default']['redistribute-ospf'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_instance']['default']['redistribute-other-bgp'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_instance']['default']['client-to-client-reflection'], ['yes'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_bgp_instance']['default']['ignore-as-path-len'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_route']['altegro']['dst-address'], ['10.10.66.0/30'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_route']['altegro']['pref-src'], ['10.10.66.1'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_route']['altegro']['gateway'], ['bridge1'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_route']['altegro']['gateway-status'], ['bridge1'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_route']['altegro']['distance'], ['0'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_route']['altegro']['scope'], ['10'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_route']['altegro']['routing-mark'], ['altegro'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['name'], ['default'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['router-id'], ['10.10.50.1'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['distribute-default'], ['never'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['redistribute-connected'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['redistribute-static'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['redistribute-rip'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['redistribute-bgp'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['redistribute-other-ospf'], ['no'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['metric-default'], ['1'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['metric-connected'], ['20'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['metric-static'], ['20'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['metric-rip'], ['20'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['metric-bgp'], ['auto'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['metric-other-ospf'], ['auto'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['in-filter'], ['ospf-in'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_instance']['default']['out-filter'], ['ospf-out'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['instance'], ['default'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['router-id'], ['10.10.100.1'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['address'], ['10.10.1.2'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['interface'], ['GRE_TYRMA'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['priority'], ['1'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['dr-address'], ['0.0.0.0'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['backup-dr-address'], ['0.0.0.0'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['state'], ['Full'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['state-changes'], ['15'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['ls-retransmits'], ['0'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['ls-requests'], ['0'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['db-summaries'], ['0'] + ) + self.assertIn( + result['ansible_facts']['ansible_net_ospf_neighbor']['default']['adjacency'], ['6h8m46s'] + ) diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/utils.py b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/utils.py new file mode 100644 index 00000000..89b4aa25 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/plugins/modules/utils.py @@ -0,0 +1,50 @@ +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +import json + +from ansible_collections.community.routeros.tests.unit.compat import unittest +from ansible_collections.community.routeros.tests.unit.compat.mock import patch +from ansible.module_utils import basic +from ansible.module_utils._text import to_bytes + + +def set_module_args(args): + if '_ansible_remote_tmp' not in args: + args['_ansible_remote_tmp'] = '/tmp' + if '_ansible_keep_remote_files' not in args: + args['_ansible_keep_remote_files'] = False + + args = json.dumps({'ANSIBLE_MODULE_ARGS': args}) + basic._ANSIBLE_ARGS = to_bytes(args) + + +class AnsibleExitJson(Exception): + pass + + +class AnsibleFailJson(Exception): + pass + + +def exit_json(*args, **kwargs): + if 'changed' not in kwargs: + kwargs['changed'] = False + raise AnsibleExitJson(kwargs) + + +def fail_json(*args, **kwargs): + kwargs['failed'] = True + raise AnsibleFailJson(kwargs) + + +class ModuleTestCase(unittest.TestCase): + + def setUp(self): + self.mock_module = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json) + self.mock_module.start() + self.mock_sleep = patch('time.sleep') + self.mock_sleep.start() + set_module_args({}) + self.addCleanup(self.mock_module.stop) + self.addCleanup(self.mock_sleep.stop) diff --git a/collections-debian-merged/ansible_collections/community/routeros/tests/unit/requirements.txt b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/requirements.txt new file mode 100644 index 00000000..eac8a96b --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/routeros/tests/unit/requirements.txt @@ -0,0 +1,4 @@ +unittest2 ; python_version <= '2.6' + +# requirements for api module +librouteros ; python_version >= '3.6' |