diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index 09d8b7f..0000000 --- a/.coveragerc +++ /dev/null @@ -1,7 +0,0 @@ -[run] -branch = True -source = networking_nec -omit = networking_nec/tests/*,networking_nec/openstack/* - -[report] -ignore_errors = True diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f944514..0000000 --- a/.gitignore +++ /dev/null @@ -1,27 +0,0 @@ -*.py[cod] - -# Packages -*.egg-info -dist/ - -# Unit test / coverage reports -cover/ -.coverage -.tox -.testrepository -.venv - -# Translations -*.mo - -# Sphinx -doc/build - -# pbr generates these -AUTHORS -ChangeLog - -# Editors -*~ -.*.swp -.*sw? diff --git a/.gitreview b/.gitreview deleted file mode 100644 index 9262758..0000000 --- a/.gitreview +++ /dev/null @@ -1,4 +0,0 @@ -[gerrit] -host=review.openstack.org -port=29418 -project=openstack/networking-nec.git diff --git a/.mailmap b/.mailmap deleted file mode 100644 index 516ae6f..0000000 --- a/.mailmap +++ /dev/null @@ -1,3 +0,0 @@ -# Format is: -# -# diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index 3375026..0000000 --- a/.pylintrc +++ /dev/null @@ -1,89 +0,0 @@ -# The format of this file isn't really documented; just use --generate-rcfile -[MASTER] -# Add to the black list. It should be a base name, not a -# path. You may set this option multiple times. -# -# Note the 'openstack' below is intended to match only -# networking_nec.openstack.common. If we ever have another 'openstack' -# dirname, then we'll need to expand the ignore features in pylint :/ -ignore=.git,tests,openstack - -[MESSAGES CONTROL] -# NOTE(gus): This is a long list. A number of these are important and -# should be re-enabled once the offending code is fixed (or marked -# with a local disable) -disable= -# "F" Fatal errors that prevent further processing -# flake8 detects import-error - import-error, -# "I" Informational noise - locally-disabled, -# "E" Error for important programming issues (likely bugs) -# "W" Warnings for stylistic problems or minor programming issues - attribute-defined-outside-init, - broad-except, - fixme, - global-statement, - no-init, - protected-access, - unpacking-non-sequence, - unused-argument, - unused-import, -# "C" Coding convention violations -# pylint check is not compatible with flake8 - bad-continuation, - invalid-name, - missing-docstring, -# "R" Refactor recommendations - duplicate-code, - interface-not-implemented, - no-self-use, - too-few-public-methods, - too-many-ancestors, - too-many-arguments, - too-many-return-statements, - -[BASIC] -# Variable names can be 1 to 31 characters long, with lowercase and underscores -variable-rgx=[a-z_][a-z0-9_]{0,30}$ - -# Argument names can be 2 to 31 characters long, with lowercase and underscores -argument-rgx=[a-z_][a-z0-9_]{1,30}$ - -# Method names should be at least 3 characters long -# and be lowecased with underscores -method-rgx=([a-z_][a-z0-9_]{2,}|setUp|tearDown)$ - -# Module names matching neutron-* are ok (files in bin/) -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|(neutron-[a-z0-9_-]+))$ - -# Don't require docstrings on tests. -no-docstring-rgx=((__.*__)|([tT]est.*)|setUp|tearDown)$ - -[FORMAT] -# Maximum number of characters on a single line. -max-line-length=79 - -[VARIABLES] -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -# _ is used by our localization -dummy-variables-rgx=^(__[A-Za-z0-9_]*[A-Za-z0-9]|__)$ - -[CLASSES] -# List of interface methods to ignore, separated by a comma. -ignore-iface-methods= - -[IMPORTS] -# Deprecated modules which should not be used, separated by a comma -deprecated-modules= -# should use openstack.common.jsonutils - json - -[TYPECHECK] -# List of module names for which member attributes should not be checked -ignored-modules=six.moves,_MovedItems - -[REPORTS] -# Tells whether to display a full report or only the messages -reports=no diff --git a/.testr.conf b/.testr.conf deleted file mode 100644 index 2c07076..0000000 --- a/.testr.conf +++ /dev/null @@ -1,8 +0,0 @@ -[DEFAULT] -test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ - OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ - OS_LOG_CAPTURE=${OS_LOG_CAPTURE:-1} \ - OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ - ${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION -test_id_option=--load-list $IDFILE -test_list_option=--list diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst deleted file mode 120000 index a84afb3..0000000 --- a/CONTRIBUTING.rst +++ /dev/null @@ -1 +0,0 @@ -doc/source/contributing.rst \ No newline at end of file diff --git a/HACKING.rst b/HACKING.rst deleted file mode 100644 index 0dbe072..0000000 --- a/HACKING.rst +++ /dev/null @@ -1,4 +0,0 @@ -networking-nec Style Commandments -=============================================== - -Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/ diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 68c771a..0000000 --- a/LICENSE +++ /dev/null @@ -1,176 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index c978a52..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,6 +0,0 @@ -include AUTHORS -include ChangeLog -exclude .gitignore -exclude .gitreview - -global-exclude *.pyc diff --git a/README b/README new file mode 100644 index 0000000..8fcd2b2 --- /dev/null +++ b/README @@ -0,0 +1,14 @@ +This project is no longer maintained. + +The contents of this repository are still available in the Git +source code management system. To see the contents of this +repository before it reached its end of life, please check out the +previous commit with "git checkout HEAD^1". + +For ongoing work on maintaining OpenStack packages in the Debian +distribution, please see the Debian OpenStack packaging team at +https://wiki.debian.org/OpenStack/. + +For any further questions, please email +openstack-dev@lists.openstack.org or join #openstack-dev on +Freenode. diff --git a/README.rst b/README.rst deleted file mode 100644 index 1df899b..0000000 --- a/README.rst +++ /dev/null @@ -1,33 +0,0 @@ -=================================================== -Neutron plugins/drivers for NEC networking products -=================================================== - -.. warning:: - - The current plugin, NEC OpenFlow plugin, is deprecated in - OpenStack Liberty release (2015.2). - A new driver for NEC NWA (Network Automation) product is coming. - Note that the production support will be continued based - on the production support policy. - -``networking-nec`` library provides Neutron plugins/drivers -for `NEC SDN`_ networking products` (mainly OpenFlow related at now) -and `Trema`_ `Sliceable Switch`_ (reference implementation). - -In 2015.1 release (Kilo development cycle) in OpenStack, Neutron -community decided to decompose vendor plugins/drivers from the neutron -code repo to address many pain points. NEC OpenFlow Neutron plugin is -maintained in a separate module. - -* Documentation: https://wiki.openstack.org/wiki/Neutron/NEC_OpenFlow_Plugin -* Source: - - * http://git.openstack.org/cgit/openstack/networking-nec - * https://github.com/openstack/networking-nec - -* Bugs: http://bugs.launchpad.net/networking-nec -* Free software: Apache license - -.. _NEC SDN: http://www.necam.com/SDN/ -.. _Trema: https://github.com/trema/trema -.. _Sliceable Switch: https://github.com/trema/apps/tree/master/sliceable_switch diff --git a/babel.cfg b/babel.cfg deleted file mode 100644 index 15cd6cb..0000000 --- a/babel.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[python: **.py] - diff --git a/devstack/README.rst b/devstack/README.rst deleted file mode 120000 index 8b57ead..0000000 --- a/devstack/README.rst +++ /dev/null @@ -1 +0,0 @@ -../doc/source/nwa/devstack.rst \ No newline at end of file diff --git a/devstack/lib/nec_plugin b/devstack/lib/nec_plugin deleted file mode 100644 index 4f7473c..0000000 --- a/devstack/lib/nec_plugin +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -# Save trace setting -NEC_XTRACE=$(set +o | grep xtrace) -set +o xtrace - -# source $TOP_DIR/lib/neutron_plugins/ovs_base -source $TOP_DIR/lib/neutron_plugins/openvswitch_agent - -# The followig functions are from the above openvswitch_agent. -# If some change is needed, let's redefine the function. -# -# neutron_plugin_create_nova_conf -# neutron_plugin_install_agent_packages -# neutron_plugin_configure_debug_command -# neutron_plugin_configure_dhcp_agent -# neutron_plugin_configure_l3_agent -# neutron_plugin_configure_plugin_agent -# neutron_plugin_setup_interface_driver -# neutron_plugin_check_adv_test_requirements - -# Neutron-server functions required by devstack neutron plugin interfaces. - -function neutron_plugin_configure_common { - Q_PLUGIN_CONF_PATH=etc/neutron/plugins/nec - Q_PLUGIN_CONF_FILENAME=necnwa.ini - Q_PLUGIN_CLASS="necnwa" - if [ -n "$NECNWA_L3_PLUGIN" ]; then - _neutron_service_plugin_class_add $NECNWA_L3_PLUGIN - fi - local plugin_conf_src_abspath=${NETWORKING_NEC_DIR}/${Q_PLUGIN_CONF_PATH} - local plugin_conf_sys_abspath=/${Q_PLUGIN_CONF_PATH} - mkdir -p ${plugin_conf_sys_abspath} - cp ${plugin_conf_src_abspath}/${Q_PLUGIN_CONF_FILENAME} ${plugin_conf_sys_abspath}/ - cp ${plugin_conf_src_abspath}/resource_group.json ${plugin_conf_sys_abspath}/ - chmod 0644 /${Q_PLUGIN_CONF_PATH}/${Q_PLUGIN_CONF_FILENAME} -} - -function neutron_plugin_configure_service { - iniset /$Q_PLUGIN_CONF_FILE NWA server_url $NECNWA_SERVER_URL - iniset /$Q_PLUGIN_CONF_FILE NWA access_key_id $NECNWA_ACCESS_KEY_ID - iniset /$Q_PLUGIN_CONF_FILE NWA secret_access_key $NECNWA_SECRET_ACCESS_KEY - iniset /$Q_PLUGIN_CONF_FILE NWA use_necnwa_router $NECNWA_USE_NECNWA_ROUTER -} - -# NEC plugin specific functions - -function start_nwa_agent { - run_process nwa-agt "$NEUTRON_BIN_DIR/neutron-necnwa-agent --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" -} - -function populate_nwa_database { - $NEUTRON_BIN_DIR/neutron-db-manage --subproject networking-nec --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head -} - -# Restore xtrace -$NEC_XTRACE diff --git a/devstack/override-defaults b/devstack/override-defaults deleted file mode 100644 index 626940f..0000000 --- a/devstack/override-defaults +++ /dev/null @@ -1,4 +0,0 @@ -function has_neutron_plugin_security_group { - # 0 means True here - return 0 -} diff --git a/devstack/plugin.sh b/devstack/plugin.sh deleted file mode 100644 index 786bf36..0000000 --- a/devstack/plugin.sh +++ /dev/null @@ -1,27 +0,0 @@ -NETWORKING_NEC_DIR=$(cd $(dirname $BASH_SOURCE)/.. && pwd) - -function source_plugin { - if [[ "$Q_PLUGIN" == "nec" ]]; then - source $NETWORKING_NEC_DIR/devstack/lib/nec_plugin - fi -} - -if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then - source_plugin -elif [[ "$1" == "stack" && "$2" == "install" ]]; then - setup_develop $NETWORKING_NEC_DIR -elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then - # This must be done after neutron database is populated and - # before starting neutron server. - populate_nwa_database - # It needs to be started before starting neutron-server. - # run_phase extra is too late because create_neutron_initial_network - # will be called just after start_neutron_service_and_check. - start_nwa_agent -elif [[ "$1" == "stack" && "$2" == "extra" ]]; then - : -elif [[ "$1" == "unstack" ]]; then - source_plugin -elif [[ "$1" == "clean" ]]; then - source_plugin -fi diff --git a/devstack/settings b/devstack/settings deleted file mode 100644 index b048bde..0000000 --- a/devstack/settings +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -NECNWA_SERVER_URL=${NECNWA_SERVER_URL:-} -NECNWA_ACCESS_KEY_ID=${NECNWA_ACCESS_KEY_ID:-} -NECNWA_SECRET_ACCESS_KEY=${NECNWA_SECRET_ACCESS_KEY:-} -NECNWA_USE_NECNWA_ROUTER=${NECNWA_USE_NECNWA_ROUTER:-True} -NECNWA_L3_PLUGIN=${NECNWA_L3_PLUGIN:-"necnwa_router"} - -# In addition to the above, you can use configurartion options -# used in devstack/lib/neutron_plugins/openvswitch_agent. diff --git a/doc/source/conf.py b/doc/source/conf.py deleted file mode 100755 index 93c4223..0000000 --- a/doc/source/conf.py +++ /dev/null @@ -1,75 +0,0 @@ -# -*- coding: utf-8 -*- -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys - -sys.path.insert(0, os.path.abspath('../..')) -# -- General configuration ---------------------------------------------------- - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = [ - 'sphinx.ext.autodoc', - # 'sphinx.ext.intersphinx', - # 'oslosphinx' -] - -# autodoc generation is a bit aggressive and a nuisance when doing heavy -# text edit cycles. -# execute "export SPHINX_DEBUG=1" in your terminal to disable - -# The suffix of source filenames. -source_suffix = '.rst' - -# The master toctree document. -master_doc = 'index' - -# General information about the project. -project = u'networking-nec' -copyright = u'2013, OpenStack Foundation' - -# If true, '()' will be appended to :func: etc. cross-reference text. -add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -add_module_names = True - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - -# -- Options for HTML output -------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. Major themes that come with -# Sphinx are currently 'default' and 'sphinxdoc'. -# html_theme_path = ["."] -# html_theme = '_theme' -# html_static_path = ['static'] - -# Output file base name for HTML help builder. -htmlhelp_basename = '%sdoc' % project - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass -# [howto/manual]). -latex_documents = [ - ('index', - '%s.tex' % project, - u'%s Documentation' % project, - u'OpenStack Foundation', 'manual'), -] - -# Example configuration for intersphinx: refer to the Python standard library. -# intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/doc/source/contributing.rst b/doc/source/contributing.rst deleted file mode 100644 index 3a8b538..0000000 --- a/doc/source/contributing.rst +++ /dev/null @@ -1,20 +0,0 @@ -============ -Contributing -============ - -If you would like to contribute to the development of OpenStack, -you must follow the steps in this page: - - http://docs.openstack.org/infra/manual/developers.html - -Once those steps have been completed, changes to OpenStack -should be submitted for review via the Gerrit tool, following -the workflow documented at: - - http://docs.openstack.org/infra/manual/developers.html#development-workflow - -Pull requests submitted through GitHub will be ignored. - -Bugs should be filed on Launchpad, not GitHub: - - https://bugs.launchpad.net/networking-nec diff --git a/doc/source/images/necnwa-plugin-design.png b/doc/source/images/necnwa-plugin-design.png deleted file mode 100644 index c5592d7..0000000 Binary files a/doc/source/images/necnwa-plugin-design.png and /dev/null differ diff --git a/doc/source/index.rst b/doc/source/index.rst deleted file mode 100644 index e4ec006..0000000 --- a/doc/source/index.rst +++ /dev/null @@ -1,59 +0,0 @@ -.. networking-nec documentation master file, created by - sphinx-quickstart on Tue Jul 9 22:26:36 2013. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -=========================================== -Neutron plugins for NEC networking products -=========================================== - -``networking-nec`` library provides Neutron plugins/drivers -for `NEC SDN `_ networking products. - -* Documentation: http://networking-nec.readthedocs.org/ -* Source: http://git.openstack.org/cgit/openstack/networking-nec -* Bugs: http://bugs.launchpad.net/networking-nec -* License: Apache License 2.0 - -NEC NWA plugin -============== - -In Mitaka release, NWA plugin was added as a new integration layer -with NEC NWA (Network Automation) product. -NWA plugin consists of layer-2 core plugin and layer-3 service plugin. - -.. toctree:: - :maxdepth: 1 - - nwa/readme - nwa/installation - nwa/settings - nwa/devstack - -NEC OpenFlow plugin -=================== - -NEC OpenFlow plugin in Liberty or older releases supported -`NEC ProgrammableFlow controller `_ and -`Trema `_ -`Sliceable Switch `_ -(as reference implementation). - -.. warning:: - - NEC OpenFlow plugin was deprecated in OpenStack Liberty release (2015.2) - and removed during Mitaka development cycle. - Note that the production support will be continued based - on the production support policy. - -The documentation on NEC OpenFlow plugin is found at -http://networking-nec.readthedocs.org/en/stable-liberty/. - -Developers Guide -================ - -.. toctree:: - :maxdepth: 2 - - tips - contributing diff --git a/doc/source/nwa/devstack.rst b/doc/source/nwa/devstack.rst deleted file mode 100644 index 3d2470f..0000000 --- a/doc/source/nwa/devstack.rst +++ /dev/null @@ -1,47 +0,0 @@ -.. _nwa-devstack: - -=============================== -DevStack support for NWA plugin -=============================== - -This DevStack external plugin installs NEC plugin library -so that Neutron NEC NWA plugin can be enabled. - -To use this DevStack plugin, add the following to your local.conf:: - - enable_plugin networking-nec https://git.openstack.org/openstack/networking-nec [] - -Examples -======== - -Minimum sample local.conf:: - - [[local|localrc]] - # Enable neutron services - disable_service n-net - enable_service neutron q-svc q-agt - enable_service q-dhcp - enable_service q-meta - - # NEC plugin - Q_PLUGIN=nec - enable_plugin networking-nec https://git.openstack.org/openstack/networking-nec - - # NWA server configurations - NECNWA_SERVER_URL="http://127.0.0.1:12081" - NECNWA_ACCESS_KEY_ID="mjivAk6O3G4Ko/0mD8mHUyQwqugEPgTe0FSli8REyN4=" - NECNWA_SECRET_ACCESS_KEY="/3iSORtq1E3F+SQtQg6YN00eM3GUda0EKqWDUV/mvqo=" - - # Run neutron-nwa-agent - enable_service nwa-agt - - [[post-config|/etc/neutron/dhcp_agent.ini]] - [DEFAULT] - enable_isolated_metadata = True - -References -========== - -* `DevStack externally hosted plugins`_ - -.. _DevStack externally hosted plugins: http://docs.openstack.org/developer/devstack/plugins.html#externally-hosted-plugins diff --git a/doc/source/nwa/installation.rst b/doc/source/nwa/installation.rst deleted file mode 100644 index 0870f0c..0000000 --- a/doc/source/nwa/installation.rst +++ /dev/null @@ -1,30 +0,0 @@ -============================== -Installation of NEC NWA plugin -============================== - -Requirements -============ - -To use the NWA plugin, NWA made by NEC is needed. - -After an OpenStack installation, you need to install networking-nec -Python package, configure the physical network by NWA and configure -the NWA plugin. - -Running with DevStack -===================== - -See :ref:`nwa-devstack` - -Manual Installation -=================== - -The released versions of Python module is available at -https://pypi.python.org/pypi/networking-nec. - -To install:: - - pip install networking-nec~=2.0 - -NEC NWA plugin is available from version ``2.0.0`` or later. -The ``2.y.z`` series of networking-nec supports Neutron Mitaka release. diff --git a/doc/source/nwa/readme.rst b/doc/source/nwa/readme.rst deleted file mode 100644 index e54d503..0000000 --- a/doc/source/nwa/readme.rst +++ /dev/null @@ -1,22 +0,0 @@ -============================== -Introduction of NEC NWA plugin -============================== - -.. toctree:: - :maxdepth: 1 - - Installation - Settings - DevStack support - -The NWA plugin consists of plugin driver and agent. -Using this plugin, you can operate an SDN controller (MasterScope -Network Automation) made by NEC from OpenStack CLI or Dashboard. - -NWA can build a large scale layer 2 network which removes the 4K VLAN -limit. -So you can use the NWA plugin to create, update and delete the network -through OpenStack environment. - -.. image:: ../images/necnwa-plugin-design.png - :width: 700px diff --git a/doc/source/nwa/settings.rst b/doc/source/nwa/settings.rst deleted file mode 100644 index 0acc86d..0000000 --- a/doc/source/nwa/settings.rst +++ /dev/null @@ -1,187 +0,0 @@ -=============================== -Setting of NEC NWA plugin -=============================== - -This section describes the configurations of the releases of NEC NWA plugin. - -neutron.conf -============ - -* **core_plugin**: Needs to be configured to ``necnwa`` to use NEC NWA - plugin as core plugin. :: - - core_plugin = necnwa - -* **service_plugin**: Needs to be configured to ``necnwa_router`` to use - NEC NWA plugin as service plugin. :: - - service_plugin = necnwa_router - -plugin specific configuration -============================= - -It is usually placed at ``/etc/neutron/plugins/nec/necnwa.ini``. - -[ml2] section -------------- - -* **type_drivers**: Needs to be configured to ``vlan`` to use NEC NWA - plugin as type_drivers. :: - - type_drivers = vlan - -* **tenant_network_types**: Needs to be configured to ``vlan`` to use - NEC NWA plugin as tenant_network_types. :: - - tenant_network_types = vlan - -* **mechanism_drivers**: Needs to be configured to ``necnwa`` and - ``openvswitch`` to use NEC NWA plugin as mechanism_drivers. :: - - mechanism_drivers = necnwa,openvswitch - -[ml2_type_vlan] section ------------------------ - -* **network_vlan_ranges**: Specify the name of an available physical - network and a range of VIDs on that network available for allocation - to tenant networks. The physical network should be the same name of - NWA resource group name. :: - - network_vlan_ranges = OpenStack/DC/APP:1000:2999,OpenStack/DC/HA1:10:2999,OpenStack/DC/HA2:10:2999 - -[ovs] section -------------- - -* **bridge_mappings**: Specify list of : - tuples, each specifying an OVS bridge used by the agent for a - physical network to which it is connected. :: - - bridge_mappings = OpenStack/DC/HA1:br-eth1,OpenStack/DC/HA2:br-eth2 - -[NWA] section -------------- - -* **server_url**: The URL of the http/https server listening for NWA - RESTful API:: - - server_url = http://192.168.122.1:12081 - -* **access_key_id**: The access key ID of NWA RESTful API server. The - access key consists of an access key ID and secret access key, which - are used to sign RESTful API requests that you make to NWA. :: - - access_key_id = mjivAk6O3G4Ko/0mD8mHUyQwqugEPgTe0FSli8REyN4= - -* **secret_access_key**: The secret access key of NWA Restful API - server. The access key consists of an access key ID and secret - access key, which are used to sign RESTful API requests that you - make to NWA. :: - - secret_access_key = /3iSORtq1E3F+SQtQg6YN00eM3GUda0EKqWDUV/mvqo= - -* **resource_group_name**: A default rerouce group name when NWA - tenant is created. :: - - resource_group_name = OpenStack/DC/APP - -* **scenario_polling_timer**: Specifies the polling interval of the - scenario in seconds. :: - - scenario_polling_timer = 5 - -* **scenario_polling_count**: Specifies the polling counts of the - scenario. :: - - scenario_polling_count = 300 - -* **region_name**: A region name (It is the prefix of NWA tenant name). :: - - region_name = T01DC - -* **resource_group_file**: Load the table of NWA resource group - from the file. :: - - resource_group_file = resource_group.json - -* **use_necnwa_router**: If you use OpenStack L3 Router instead of NEC NWA Router, - it set to False. The default value is True. :: - - use_necnwa_router = True - -* **use_neutron_vlan_id**: If you want to use a vlan id which is - assigned by neutron, it set to True. The default value is False. In - case of False, the vlan id will be assigned by NWA. :: - - use_neutron_vlan_id = True - -NWA resource group file -======================= - -It is usually placed at -"/etc/neutron/plugins/nec/resource_group.json." - -This file contains a table of NWA resource group. The format of the -file is JSON. - -The ``physical_network`` is a name of physical network which is used -in neutron. It should be set to the same value as -``ResourceGroupName`` member. - -The ``device_owner`` is the owner of the device in OpenStack. - -It is specified as ``compute:AVAILABILITY_ZONE``, the VM that has a -nova boot option ``--available-zone`` is created on the physical -network corresponding with the device owner. - -If the option ``--available-zone`` is not specified in nova boot, -regarded as ``compute:None`` has been specified. - -All available DHCP agent in OpenStack specifies as ``network:dhcp``. - -The ``ResourceGroupName`` is a name of NWA's resource group name. - -:: - - [ - { - "physical_network": "OpenStack/DC/HA1", - "device_owner": "compute:DC01_KVM01_ZONE01", - "ResourceGroupName": "OpenStack/DC/HA1" - }, - { - "physical_network": "OpenStack/DC/HA2", - "device_owner": "compute:DC01_KVM02_ZONE02", - "ResourceGroupName": "OpenStack/DC/HA2" - }, - { - "physical_network": "OpenStack/DC/HA1", - "device_owner": "compute:None", - "ResourceGroupName": "OpenStack/DC/HA1" - }, - { - "physical_network": "OpenStack/DC/HA2", - "device_owner": "compute:None", - "ResourceGroupName": "OpenStack/DC/HA2" - }, - { - "physical_network": "OpenStack/DC/HA1", - "device_owner": "network:dhcp", - "ResourceGroupName": "OpenStack/DC/HA1" - }, - { - "physical_network": "OpenStack/DC/HA2", - "device_owner": "network:dhcp", - "ResourceGroupName": "OpenStack/DC/HA2" - }, - { - "physical_network": "OpenStack/DC/APP", - "device_owner": "network:router_gateway", - "ResourceGroupName": "OpenStack/DC/APP" - }, - { - "physical_network": "OpenStack/DC/APP", - "device_owner": "network:router_interface", - "ResourceGroupName": "OpenStack/DC/APP" - }, - ] diff --git a/doc/source/tips.rst b/doc/source/tips.rst deleted file mode 100644 index 56b46b3..0000000 --- a/doc/source/tips.rst +++ /dev/null @@ -1,147 +0,0 @@ -================ -Development Tips -================ - -Release package ---------------- - -Create a specific release -~~~~~~~~~~~~~~~~~~~~~~~~~ - -The following steps are required to release a package. - -* (Create a stable branch if necessary) -* Add a signed tag to the repository - - .. code-block:: console - - git checkout stable/xxxx (if necessary) - git tag -s - git show - git push gerrit - - .. warning:: - - Before pushing a tag to gerrit, you are strongly suggested to - test whether a generated package works as expected. - - .. code-block:: console - - git checkout - python setup.py sdist - pip install dist/networking-nec-.tar.gz - - To push a tag to gerrit, you must be a member of - ``networking-nec-release`` gerrit group. - -* Push a release package to PyPI. - - .. code-block:: console - - git checkout - python setup.py sdist upload - - Once the upload succeeded, you can find a new release at - https://pypi.python.org/pypi/networking-nec. - - Before uploading a package to PyPI, you need to create your PyPI - account and prepare a proper credential file ``~/.pypirc`` like below. - - .. code-block:: ini - - [distutils] - index-servers = - pypi - - [pypi] - repository=https://pypi.python.org/pypi - username= - password= - -Create a stable branch -~~~~~~~~~~~~~~~~~~~~~~ - -The detail is available at: -http://docs.openstack.org/infra/manual/drivers.html#release-management. - -To create a (stable) branch, you must be a member of -``networking-nec-release`` gerrit group. - -More information -~~~~~~~~~~~~~~~~ - -Most of the release process is explained in -`OpenStack Infrastructure User Manual -`_. - -Requirements update -------------------- - -In OpenStack projects, requirements.txt and test-requirements.txt -should be synced with ``global-requirements.txt`` in -http://git.openstack.org/cgit/openstack/requirements/tree/. - -To sync requirements manually: - -1. Check out requirements repository: - - .. code-block:: console - - git clone https://git.openstack.org/openstack/requirements - -2. Run update.py: - - .. code-block:: console - - cd requirements - tox -e venv -- python update.py - -To sync it automatically, you need to: - -* setup the jenkins job ``gate-{name}-requirements`` - (it is usually unnecessary as ``python-jobs`` contains it), -* add ``check-requirements`` to ``zuul/layout.yaml`` in - project-config, and -* add ``openstack/networking-nec`` to ``projects.txt`` in the - requirements project. - -Documentation -------------- - -Build documentation -~~~~~~~~~~~~~~~~~~~ - -To build the documentation: - -.. code-block:: console - - tox -e docs - -and the generated documentation will be found under ``doc/build/html``. - -Publish documentation -~~~~~~~~~~~~~~~~~~~~~ - -The document is hosted by `Read The Docs `__ -and the documentation is available at -http://networking-nec.readthedocs.org/en/latest/. - -To publish the latest documentation, -visit the `project page `__, -go to **Builds** and click **Build version** after selecting **latest**. -After completing the build, the status will be **Passed** and -you can see the new document. -If the build fails, investigate reasons of the failure. - -Third party CI --------------- - -* The master information about setting up and operating a third party CI - is available at - http://docs.openstack.org/infra/system-config/third_party.html. - It is better to check this site regularly. - -* The status of your third party CI system should be available at - https://wiki.openstack.org/wiki/ThirdPartySystems. - For example, you have a planned power blackout, it is encouraged - to update the corresponding page. diff --git a/etc/neutron/plugins/nec/necnwa.ini b/etc/neutron/plugins/nec/necnwa.ini deleted file mode 100644 index 80e6156..0000000 --- a/etc/neutron/plugins/nec/necnwa.ini +++ /dev/null @@ -1,29 +0,0 @@ -[ml2] -type_drivers = vlan -tenant_network_types = vlan -mechanism_drivers = necnwa,openvswitch -path_mtu = 0 - -[ml2_type_flat] - -[ml2_type_vlan] -network_vlan_ranges = OpenStack/DC/APP:1000:2999,OpenStack/DC/HA1:10:2999,OpenStack/DC/HA2:10:2999 - -[ml2_type_gre] - -[ml2_type_vxlan] - -[securitygroup] -enable_security_group = True - -[NWA] -server_url = http://192.168.122.166:12081 -access_key_id = mjivAk6O3G4Ko/0mD8mHUyQwqugEPgTe0FSli8REyN4= -secret_access_key = /3iSORtq1E3F+SQtQg6YN00eM3GUda0EKqWDUV/mvqo= -use_necnwa_router = True -use_neutron_vlan_id = False -resource_group_name = OpenStack/DC/APP -scenario_polling_timer = 5 -scenario_polling_count = 300 -region_name = T01DC -resource_group_file = resource_group.json diff --git a/etc/neutron/plugins/nec/resource_group.json b/etc/neutron/plugins/nec/resource_group.json deleted file mode 100644 index 65685e0..0000000 --- a/etc/neutron/plugins/nec/resource_group.json +++ /dev/null @@ -1,52 +0,0 @@ -[ - { - "physical_network": "OpenStack/DC/HA1", - "device_owner": "compute:DC01_KVM01_ZONE01", - "ResourceGroupName": "OpenStack/DC/HA1" - }, - { - "physical_network": "OpenStack/DC/HA2", - "device_owner": "compute:DC01_KVM02_ZONE02", - "ResourceGroupName": "OpenStack/DC/HA2" - }, - { - "physical_network": "OpenStack/DC/HA1", - "device_owner": "compute:None", - "ResourceGroupName": "OpenStack/DC/HA1" - }, - { - "physical_network": "OpenStack/DC/HA2", - "device_owner": "compute:None", - "ResourceGroupName": "OpenStack/DC/HA2" - }, - { - "physical_network": "OpenStack/DC/HA1", - "device_owner": "network:dhcp", - "ResourceGroupName": "OpenStack/DC/HA1" - }, - { - "physical_network": "OpenStack/DC/HA2", - "device_owner": "network:dhcp", - "ResourceGroupName": "OpenStack/DC/HA2" - }, - { - "physical_network": "OpenStack/DC/APP", - "device_owner": "network:router_gateway", - "ResourceGroupName": "OpenStack/DC/APP" - }, - { - "physical_network": "OpenStack/DC/APP", - "device_owner": "network:router_interface", - "ResourceGroupName": "OpenStack/DC/APP" - }, - { - "physical_network": "Common/BM/Pod2-Ironic", - "device_owner": "compute:DC01_BMT01_ZONE01", - "ResourceGroupName": "Common/BM/Pod2-Ironic" - }, - { - "physical_network": "Common/BM/Pod2-Ironic", - "device_owner": "ironic:isolation", - "ResourceGroupName": "Common/BM/Pod2-Ironic" - } -] diff --git a/networking_nec/__init__.py b/networking_nec/__init__.py deleted file mode 100644 index b80e859..0000000 --- a/networking_nec/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import pbr.version - - -__version__ = pbr.version.VersionInfo( - 'networking_nec').version_string() diff --git a/networking_nec/_i18n.py b/networking_nec/_i18n.py deleted file mode 100644 index 7047ce1..0000000 --- a/networking_nec/_i18n.py +++ /dev/null @@ -1,30 +0,0 @@ -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import oslo_i18n - -_translators = oslo_i18n.TranslatorFactory(domain='networking_nec') - -# The primary translation function using the well-known name "_" -_ = _translators.primary - -# Translators for log levels. -# -# The abbreviated names are meant to reflect the usual use of a short -# name like '_'. The "L" is for "log" and the other letter comes from -# the level. -_LI = _translators.log_info -_LW = _translators.log_warning -_LE = _translators.log_error -_LC = _translators.log_critical diff --git a/networking_nec/cmd/__init__.py b/networking_nec/cmd/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/cmd/eventlet/__init__.py b/networking_nec/cmd/eventlet/__init__.py deleted file mode 100644 index 01f9f69..0000000 --- a/networking_nec/cmd/eventlet/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.common import eventlet_utils - -eventlet_utils.monkey_patch() diff --git a/networking_nec/cmd/eventlet/nwa_agent.py b/networking_nec/cmd/eventlet/nwa_agent.py deleted file mode 100755 index 0fd11e0..0000000 --- a/networking_nec/cmd/eventlet/nwa_agent.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from networking_nec.nwa.agent import nwa_agent - - -def main(): - nwa_agent.main() diff --git a/networking_nec/common/__init__.py b/networking_nec/common/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/common/utils.py b/networking_nec/common/utils.py deleted file mode 100644 index 8a5cc6e..0000000 --- a/networking_nec/common/utils.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import functools - -from oslo_log import log -from oslo_utils import excutils - -from networking_nec._i18n import _LE - - -LOG = log.getLogger(__name__) - - -def _get_full_class_name(cls): - return '%s.%s' % (cls.__module__, - getattr(cls, '__qualname__', cls.__name__)) - - -def log_method_return_value(method): - - @functools.wraps(method) - def wrapper(*args, **kwargs): - first_arg = args[0] - cls = (first_arg if isinstance(first_arg, type) - else first_arg.__class__) - data = {'class_name': _get_full_class_name(cls), - 'method_name': method.__name__} - try: - ret = method(*args, **kwargs) - data['ret'] = ret - LOG.debug('%(class_name)s method %(method_name)s ' - 'call returned %(ret)s', data) - return ret - except Exception as e: - with excutils.save_and_reraise_exception(): - data['exctype'] = e.__class__.__name__ - data['reason'] = e - LOG.error(_LE('%(class_name)s method %(method_name)s ' - 'call raised %(exctype)s: %(reason)s'), data) - - return wrapper diff --git a/networking_nec/db/__init__.py b/networking_nec/db/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/db/migration/__init__.py b/networking_nec/db/migration/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/db/migration/alembic_migrations/__init__.py b/networking_nec/db/migration/alembic_migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/db/migration/alembic_migrations/env.py b/networking_nec/db/migration/alembic_migrations/env.py deleted file mode 100644 index 3c5fdd9..0000000 --- a/networking_nec/db/migration/alembic_migrations/env.py +++ /dev/null @@ -1,89 +0,0 @@ -# Copyright 2015 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# pylint: disable=no-member -# Silence pylint not complain about alembic.context. - -from logging import config as logging_config - -from alembic import context -from neutron_lib.db import model_base -from oslo_config import cfg -from oslo_db.sqlalchemy import session -import sqlalchemy as sa -from sqlalchemy import event - - -MYSQL_ENGINE = None -NEC_VERSION_TABLE = 'alembic_version_networking_nec' -config = context.config -neutron_config = config.neutron_config -logging_config.fileConfig(config.config_file_name) -target_metadata = model_base.BASEV2.metadata - - -def set_mysql_engine(): - try: - mysql_engine = neutron_config.command.mysql_engine - except cfg.NoSuchOptError: - mysql_engine = None - - global MYSQL_ENGINE - MYSQL_ENGINE = (mysql_engine or - model_base.BASEV2.__table_args__['mysql_engine']) - - -def run_migrations_offline(): - set_mysql_engine() - - kwargs = {} - if neutron_config.database.connection: - kwargs['url'] = neutron_config.database.connection - else: - kwargs['dialect_name'] = neutron_config.database.engine - kwargs['version_table'] = NEC_VERSION_TABLE - context.configure(**kwargs) - - with context.begin_transaction(): - context.run_migrations() - - -@event.listens_for(sa.Table, 'after_parent_attach') -def set_storage_engine(target, parent): - if MYSQL_ENGINE: - target.kwargs['mysql_engine'] = MYSQL_ENGINE - - -def run_migrations_online(): - set_mysql_engine() - engine = session.create_engine(neutron_config.database.connection) - - connection = engine.connect() - context.configure( - connection=connection, - target_metadata=target_metadata, - version_table=NEC_VERSION_TABLE - ) - try: - with context.begin_transaction(): - context.run_migrations() - finally: - connection.close() - engine.dispose() - - -if context.is_offline_mode(): - run_migrations_offline() -else: - run_migrations_online() diff --git a/networking_nec/db/migration/alembic_migrations/script.py.mako b/networking_nec/db/migration/alembic_migrations/script.py.mako deleted file mode 100644 index 8323caa..0000000 --- a/networking_nec/db/migration/alembic_migrations/script.py.mako +++ /dev/null @@ -1,20 +0,0 @@ -"""${message} - -Revision ID: ${up_revision} -Revises: ${down_revision | comma,n} -Create Date: ${create_date} - -""" - -# revision identifiers, used by Alembic. -revision = ${repr(up_revision)} -down_revision = ${repr(down_revision)} -branch_labels = ${repr(branch_labels)} -depends_on = ${repr(depends_on)} - -from alembic import op -import sqlalchemy as sa -${imports if imports else ""} - -def upgrade(): - ${upgrades if upgrades else "pass"} diff --git a/networking_nec/db/migration/alembic_migrations/versions/HEAD b/networking_nec/db/migration/alembic_migrations/versions/HEAD deleted file mode 100644 index 76960e2..0000000 --- a/networking_nec/db/migration/alembic_migrations/versions/HEAD +++ /dev/null @@ -1 +0,0 @@ -d86043b2d0f2 diff --git a/networking_nec/db/migration/alembic_migrations/versions/d86043b2d0f2_add_a_table.py b/networking_nec/db/migration/alembic_migrations/versions/d86043b2d0f2_add_a_table.py deleted file mode 100644 index 007d90f..0000000 --- a/networking_nec/db/migration/alembic_migrations/versions/d86043b2d0f2_add_a_table.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2016 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -"""Add tables for necnwa - -Revision ID: d86043b2d0f2 -Revises: 978466bef2fe -Create Date: 2016-01-12 14:36:11.217570 - -""" - -# revision identifiers, used by Alembic. -revision = 'd86043b2d0f2' -down_revision = '978466bef2fe' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.create_table( - 'nwa_tenant_key_value', - sa.Column('tenant_id', sa.String(length=36), - nullable=False, primary_key=True), - sa.Column('nwa_tenant_id', sa.String(length=64)), - sa.Column('json_key', sa.String(length=192), - nullable=False, primary_key=True), - sa.Column('json_value', sa.String(length=1024), - nullable=False, default='') - ) - - op.create_table( - 'nwa_tenant_queue', - sa.Column('tenant_id', sa.String(length=36), - nullable=False, primary_key=True), - sa.Column('nwa_tenant_id', sa.String(length=64), - nullable=False, default=''), - sa.Column('topic', sa.String(length=122), nullable=False, default='') - ) diff --git a/networking_nec/db/migration/alembic_migrations/versions/start_networking_nec.py b/networking_nec/db/migration/alembic_migrations/versions/start_networking_nec.py deleted file mode 100644 index 9d0e5f9..0000000 --- a/networking_nec/db/migration/alembic_migrations/versions/start_networking_nec.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2016 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -"""start networking-nec db migration - -Revision ID: 978466bef2fe -Revises: None -Create Date: 2016-02-06 20:30:12.217571 - -""" - -# revision identifiers, used by Alembic. -revision = '978466bef2fe' -down_revision = None - - -def upgrade(): - pass diff --git a/networking_nec/nwa/__init__.py b/networking_nec/nwa/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/nwa/agent/__init__.py b/networking_nec/nwa/agent/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/nwa/agent/nwa_agent.py b/networking_nec/nwa/agent/nwa_agent.py deleted file mode 100644 index 6a73e14..0000000 --- a/networking_nec/nwa/agent/nwa_agent.py +++ /dev/null @@ -1,164 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import socket -import sys -import time - -from neutron.agent import rpc as agent_rpc -from neutron.common import config as logging_config -from neutron.common import rpc as n_rpc -from neutron.common import topics -from neutron import context as q_context -from oslo_config import cfg -from oslo_log import log as logging -from oslo_service import loopingcall - -from networking_nec._i18n import _LE -from networking_nec.nwa.agent import proxy_l2 -from networking_nec.nwa.agent import proxy_l3 -from networking_nec.nwa.agent import proxy_tenant -from networking_nec.nwa.agent import server_manager -from networking_nec.nwa.common import constants as nwa_const -from networking_nec.nwa.l2.rpc import nwa_agent_callback -from networking_nec.nwa.l2.rpc import nwa_proxy_callback -from networking_nec.nwa.l2.rpc import tenant_binding_api -from networking_nec.nwa.l3.rpc import nwa_l3_proxy_callback -from networking_nec.nwa.nwalib import client as nwa_cli - - -LOG = logging.getLogger(__name__) - - -# pylint: disable=too-many-instance-attributes -class NECNWANeutronAgent(object): - - rpc_servers = {} - topic = nwa_const.NWA_AGENT_TOPIC - - def __init__(self, polling_interval): - """Constructor. - - @param polling_interval: interval (secs) to check the nwa. - """ - self.polling_interval = polling_interval - self.need_sync = True - - self.conf = cfg.CONF - self.host = socket.gethostname() - self.agent_id = 'necnwa-q-agent.%s' % self.host - self.multi_dc = cfg.CONF.NWA.use_neutron_vlan_id - self.client = nwa_cli.NwaClient() - - self.agent_state = { - 'binary': 'neutron-necnwa-agent', - 'host': cfg.CONF.host, - 'topic': nwa_const.NWA_AGENT_TOPIC, - 'configurations': {}, - 'agent_type': nwa_const.NWA_AGENT_TYPE, - 'start_flag': True} - - self.server_manager = server_manager.ServerManager(self.topic, self) - self.proxy_tenant = proxy_tenant.AgentProxyTenant(self, self.client) - self.proxy_l2 = proxy_l2.AgentProxyL2(self, self.client, self.multi_dc) - self.proxy_l3 = proxy_l3.AgentProxyL3(self, self.client, self.multi_dc) - self.setup_rpc() - - LOG.debug('NWA Agent state %s', self.agent_state) - - def setup_rpc(self): - """setup_rpc """ - - self.context = q_context.get_admin_context_without_session() - - self.nwa_l2_rpc = tenant_binding_api.TenantBindingServerRpcApi( - topics.PLUGIN - ) - - self.state_rpc = agent_rpc.PluginReportStateAPI(topics.REPORTS) - self.callback_nwa = nwa_agent_callback.NwaAgentRpcCallback( - self.context, self.server_manager) - self.callback_proxy = nwa_proxy_callback.NwaProxyCallback( - self.context, self.proxy_l2) - self.callback_l3 = nwa_l3_proxy_callback.NwaL3ProxyCallback( - self.context, self.proxy_l3) - - # lbaas - self.lbaas_driver = None - self.callback_lbaas = None - if self.conf.NWA.lbaas_driver: - pass - - # fwaas - self.fwaas_driver = None - self.callback_fwaas = None - if self.conf.NWA.fwaas_driver: - pass - - # endpoints - self.endpoints = [self.callback_nwa, - self.callback_proxy, - self.callback_l3] - - # create connection - self.conn = n_rpc.create_connection() - - self.conn.create_consumer(self.topic, self.endpoints, - fanout=False) - - self.conn.consume_in_threads() - - report_interval = cfg.CONF.AGENT.report_interval - if report_interval: - heartbeat = loopingcall.FixedIntervalLoopingCall( - self._report_state) - heartbeat.start(interval=report_interval) - - def _report_state(self): - try: - queues = self.server_manager.get_rpc_server_topics() - self.agent_state['configurations']['tenant_queues'] = len(queues) - self.state_rpc.report_state(self.context, - self.agent_state) - self.agent_state.pop('start_flag', None) - - servers = self.server_manager.get_rpc_server_tenant_ids() - self.nwa_l2_rpc.update_tenant_rpc_servers( - self.context, servers - ) - - except Exception as e: - LOG.exception(_LE("Failed reporting state! %s"), e) - - def loop_handler(self): - pass - - def daemon_loop(self): - """Main processing loop for NECNWA Plugin Agent.""" - while True: - self.loop_handler() - time.sleep(self.polling_interval) - - -def main(): - logging_config.init(sys.argv[1:]) - logging_config.setup_logging() - - polling_interval = cfg.CONF.AGENT.polling_interval - agent = NECNWANeutronAgent(polling_interval) - - agent.daemon_loop() - -if __name__ == "__main__": - main() diff --git a/networking_nec/nwa/agent/proxy_l2.py b/networking_nec/nwa/agent/proxy_l2.py deleted file mode 100644 index e42e8df..0000000 --- a/networking_nec/nwa/agent/proxy_l2.py +++ /dev/null @@ -1,640 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import re -import time - -from neutron.common import topics -from neutron.plugins.common import constants as plugin_const -from neutron.plugins.ml2 import driver_api as api -from oslo_log import helpers -from oslo_log import log as logging -import six - -from networking_nec._i18n import _LE, _LI, _LW -from networking_nec.common import utils -from networking_nec.nwa.agent import proxy_tenant as tenant_util -from networking_nec.nwa.common import constants as nwa_const -from networking_nec.nwa.common import exceptions as nwa_exc -from networking_nec.nwa.l2.rpc import nwa_l2_server_api -from networking_nec.nwa.l2.rpc import tenant_binding_api -from networking_nec.nwa.nwalib import data_utils - - -LOG = logging.getLogger(__name__) - -KEY_CREATE_TENANT_NW = 'CreateTenantNW' -WAIT_AGENT_NOTIFIER = 20 -# WAIT_AGENT_NOTIFIER = 1 - - -def check_vlan(network_id, nwa_data): - # dev_key = 'VLAN_' + network_id + '_.*_VlanID$' - # TFW, GDV: VLAN_' + network_id + '_.*_VlanID$ - # TLB: VLAN_LB_' + network_id + '_.*_VlanID$ - vlan_pat = re.compile(r'VLAN_.*' + network_id + '_.*_VlanID$') - matched = [k for k in nwa_data if vlan_pat.match(k)] - if matched: - LOG.debug("find device in network(ids=%s)", network_id) - return len(matched) - - -def count_device_id(device_id, nwa_data): - dev_pat = re.compile(r'DEV_' + device_id + '_') - matched = [k for k in nwa_data if dev_pat.match(k)] - if matched: - LOG.debug("found device with device_id=%s", device_id) - return len(matched) - - -def check_segment(network_id, res_name, nwa_data, dev_type): - dev_pat = re.compile(r'DEV_.*_' + network_id + '_' + res_name) - matched = [k for k in nwa_data - if dev_pat.match(k) and dev_type == nwa_data[k]] - if matched: - LOG.debug("find device in network(id=%(network_id)s)," - " resource_group_name=%(res_name)s, type=%(dev_type)s", - {'network_id': network_id, - 'res_name': res_name, - 'dev_type': dev_type}) - return len(matched) - - -def check_segment_gd(network_id, res_name, nwa_data): - return check_segment(network_id, res_name, nwa_data, - nwa_const.NWA_DEVICE_GDV) - - -def check_segment_tfw(network_id, res_name, nwa_data): - return check_segment(network_id, res_name, nwa_data, - nwa_const.NWA_DEVICE_TFW) - - -def get_resource_group_name(nwa_info, nwa_data, dev_type): - device_id = nwa_info['device']['id'] - network_id = nwa_info['network']['id'] - mac = nwa_info['port']['mac'] - - found_mac = None - found_dev_type = None - dev_prefix = 'DEV_%s_%s_' % (device_id, network_id) - for k, v in six.iteritems(nwa_data): - if not k.startswith(dev_prefix): - continue - if v == mac: - found_mac = k[len(dev_prefix):] - elif v == dev_type: - found_dev_type = k[len(dev_prefix):] - if found_mac and found_dev_type: - return found_dev_type - - -class AgentProxyL2(object): - - def __init__(self, agent_top, client, multi_dc=False): - self.nwa_tenant_rpc = tenant_binding_api.TenantBindingServerRpcApi( - topics.PLUGIN) - self.nwa_l2_rpc = nwa_l2_server_api.NwaL2ServerRpcApi(topics.PLUGIN) - self.agent_top = agent_top - self.client = client - self.multi_dc = multi_dc - - @property - def proxy_tenant(self): - return self.agent_top.proxy_tenant - - @utils.log_method_return_value - @helpers.log_method_call - def _create_tenant_nw(self, context, **kwargs): - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_info = kwargs.get('nwa_info') - - # get resource group name for NWA TenantNW. - resource_group_name = nwa_info['resource_group_name_nw'] - nwa_data = kwargs.get('nwa_data') - - if KEY_CREATE_TENANT_NW not in nwa_data: - LOG.debug("nwa_tenant_id=%(nwa_tenant_id)s, " - "resource_group_name_nw=%(resource_group_name)s", - {'nwa_tenant_id': nwa_tenant_id, - 'resource_group_name': resource_group_name}) - rcode, body = self.client.l2.create_tenant_nw( - nwa_tenant_id, - resource_group_name - ) - - if rcode == 200 and body['status'] == 'SUCCEED': - LOG.debug("CreateTenantNW succeed.") - nwa_data[KEY_CREATE_TENANT_NW] = True - return nwa_data - else: - LOG.error(_LE("CreateTenantNW Failed.")) - raise nwa_exc.AgentProxyException(value=nwa_data) - - @utils.log_method_return_value - def _delete_tenant_nw(self, context, **kwargs): - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_data = kwargs.get('nwa_data') - - rcode, body = self.client.l2.delete_tenant_nw( - nwa_tenant_id, - ) - - if rcode == 200 and body['status'] == 'SUCCEED': - LOG.debug("DeleteTenantNW SUCCEED.") - nwa_data.pop(KEY_CREATE_TENANT_NW) - else: - LOG.error(_LE("DeleteTenantNW %s."), body['status']) - raise nwa_exc.AgentProxyException(value=nwa_data) - - return nwa_data - - @utils.log_method_return_value - def _create_vlan(self, context, **kwargs): - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_info = kwargs.get('nwa_info') - nwa_data = kwargs.get('nwa_data') - - network_id = nwa_info['network']['id'] - nw_vlan_key = data_utils.get_vlan_key(network_id) - if nw_vlan_key in nwa_data: - LOG.warning(_LW("aleady in vlan_key %s"), nw_vlan_key) - return nwa_data - - rcode, body = self.client.l2.create_vlan( - nwa_tenant_id, - nwa_info['subnet']['netaddr'], - nwa_info['subnet']['mask'], - nwa_info['network']['vlan_type'], - openstack_network_id=network_id - ) - - if rcode == 200 and body['status'] == 'SUCCEED': - # create vlan succeed. - LOG.debug("CreateVlan succeed.") - data_utils.set_network_data(nwa_data, network_id, nwa_info, - body['resultdata']['LogicalNWName']) - data_utils.set_vlan_data(nwa_data, network_id, - body['resultdata']['VlanID']) - else: - # create vlan failed. - LOG.error(_LE("CreateVlan Failed.")) - raise nwa_exc.AgentProxyException(value=nwa_data) - - return nwa_data - - @utils.log_method_return_value - def _delete_vlan(self, context, **kwargs): - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_info = kwargs.get('nwa_info') - nwa_data = kwargs.get('nwa_data') - - vlan_type = nwa_info['network']['vlan_type'] - physical_network = nwa_info['physical_network'] - network_id = nwa_info['network']['id'] - - # delete vlan - rcode, body = self.client.l2.delete_vlan( - nwa_tenant_id, - data_utils.get_vlan_logical_name(nwa_data, network_id), - vlan_type - ) - - if rcode == 200 and body['status'] == 'SUCCEED': - LOG.debug("DeleteVlan SUCCEED.") - - data_utils.strip_network_data(nwa_data, network_id) - data_utils.strip_vlan_data(nwa_data, network_id) - - self.nwa_l2_rpc.release_dynamic_segment_from_agent( - context, physical_network, - network_id - ) - - else: - LOG.debug("DeleteVlan FAILED.") - self.proxy_tenant.update_tenant_binding( - context, tenant_id, nwa_tenant_id, nwa_data - ) - raise nwa_exc.AgentProxyException(value=nwa_data) - - return nwa_data - - def _ensure_l2_network(self, context, **kwargs): - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_info = kwargs.get('nwa_info') - network_id = nwa_info['network']['id'] - - LOG.debug("tenant_id=%(tenant_id)s, network_id=%(network_id)s, " - "device_owner=%(device_owner)s", - {'tenant_id': tenant_id, - 'network_id': network_id, - 'device_owner': nwa_info['device']['owner']}) - - nwa_data = self.nwa_tenant_rpc.get_nwa_tenant_binding( - context, tenant_id, nwa_tenant_id - ) - - # create tenant - if not nwa_data: - nwa_data = self.proxy_tenant.create_tenant(context, **kwargs) - if not self.proxy_tenant.update_tenant_binding( - context, tenant_id, nwa_tenant_id, - nwa_data, nwa_created=True): - return - - # create tenant nw - if KEY_CREATE_TENANT_NW not in nwa_data: - # raise AgentProxyException if fail - self._create_tenant_nw(context, nwa_data=nwa_data, **kwargs) - - # create vlan - nw_vlan_key = data_utils.get_network_key(network_id) - if nw_vlan_key not in nwa_data: - # raise AgentProxyException if fail - self._create_vlan(context, nwa_data=nwa_data, **kwargs) - - return nwa_data - - @helpers.log_method_call - @tenant_util.catch_exception_and_update_tenant_binding - def ensure_l2_network(self, context, **kwargs): - return self._ensure_l2_network(context, **kwargs) - - @helpers.log_method_call - @tenant_util.catch_exception_and_update_tenant_binding - def create_general_dev(self, context, **kwargs): - """Create GeneralDev wrapper. - - @param context: contains user information. - @param kwargs: - @return: dict of status and msg. - """ - - nwa_data = self._ensure_l2_network(context, **kwargs) - if not nwa_data: - return - - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_info = kwargs.get('nwa_info') - - network_id = nwa_info['network']['id'] - resource_group_name = nwa_info['resource_group_name'] - - # create general dev - if not check_segment_gd(network_id, resource_group_name, nwa_data): - if self.multi_dc: - sync_vlan_id = self._create_connect_port - else: - sync_vlan_id = self._create_general_dev - # raise AgentProxyException if fail - nwa_data = sync_vlan_id(context, nwa_data=nwa_data, **kwargs) - else: - ret_val = self._create_general_dev_data( - nwa_data=nwa_data, **kwargs) - if ret_val: - nwa_data = ret_val - # agent waits for notifier issue for libviert. - time.sleep(WAIT_AGENT_NOTIFIER) - # create general dev end - - ret = self.proxy_tenant.update_tenant_binding( - context, tenant_id, nwa_tenant_id, nwa_data, - nwa_created=False - ) - - segment = { - api.PHYSICAL_NETWORK: nwa_info['physical_network'], - api.NETWORK_TYPE: plugin_const.TYPE_VLAN, - api.SEGMENTATION_ID: data_utils.get_vp_net_vlan_id( - nwa_data, network_id, resource_group_name, - nwa_const.NWA_DEVICE_GDV) - } - - self.nwa_l2_rpc.update_port_state_with_notifier( - context, nwa_info['device']['id'], self.agent_top.agent_id, - nwa_info['port']['id'], segment, network_id - ) - - return ret - - def _append_device_for_gdv(self, nwa_info, nwa_data): - network_id = nwa_info['network']['id'] - device_id = nwa_info['device']['id'] - resource_group_name = nwa_info['resource_group_name'] - - data_utils.set_gdv_device_data(nwa_data, device_id, nwa_info) - data_utils.set_gdv_interface_data(nwa_data, device_id, network_id, - resource_group_name, nwa_info) - - return nwa_data - - @utils.log_method_return_value - def _create_general_dev_data(self, **kwargs): - nwa_info = kwargs.get('nwa_info') - nwa_data = kwargs.get('nwa_data') - - self._append_device_for_gdv(nwa_info, nwa_data) - - return nwa_data - - @utils.log_method_return_value - @helpers.log_method_call - def _create_general_dev(self, context, **kwargs): - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_info = kwargs.get('nwa_info') - nwa_data = kwargs.get('nwa_data') - - network_id = nwa_info['network']['id'] - resource_group_name = nwa_info['resource_group_name'] - - port_type = None - - rcode, body = self.client.l2.create_general_dev( - nwa_tenant_id, - resource_group_name, - data_utils.get_vlan_logical_name(nwa_data, network_id), - port_type=port_type - ) - - if rcode == 200 and body['status'] == 'SUCCEED': - LOG.debug("CreateGeneralDev SUCCEED") - - vlan_key = data_utils.get_vlan_key(network_id) - if vlan_key not in nwa_data: - LOG.error(_LE("not create vlan.")) - raise nwa_exc.AgentProxyException(value=nwa_data) - - vlan_id = data_utils.get_vlan_id(network_id, nwa_data, - body['resultdata']) - data_utils.set_vp_net_data(nwa_data, network_id, - resource_group_name, - nwa_const.NWA_DEVICE_GDV, - vlan_id) - - self._append_device_for_gdv(nwa_info, nwa_data) - else: - LOG.debug("CreateGeneralDev %s", body['status']) - raise nwa_exc.AgentProxyException(value=nwa_data) - - return nwa_data - - @helpers.log_method_call - @tenant_util.catch_exception_and_update_tenant_binding - def delete_general_dev(self, context, **kwargs): - """Delete GeneralDev. - - @param context: contains user information. - @param kwargs: - @return: dict of status and msg. - """ - - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_info = kwargs.get('nwa_info') - network_id = nwa_info['network']['id'] - resource_group_name = nwa_info['resource_group_name'] - - nwa_data = self.nwa_tenant_rpc.get_nwa_tenant_binding( - context, tenant_id, nwa_tenant_id - ) - - # rpc return empty. - if not nwa_data: - LOG.error(_LE('nwa_tenant_binding not found.' - ' tenant_id=%(tenant_id)s,' - ' nwa_tenant_id=%(nwa_tenant_id)s'), - {'tenant_id': tenant_id, - 'nwa_tenant_id': nwa_tenant_id}) - return {'result': 'FAILED'} - - if not resource_group_name: - resource_group_name = get_resource_group_name( - nwa_info, nwa_data, nwa_const.NWA_DEVICE_GDV) - if not resource_group_name: - LOG.debug('skip delete_general_dev.' - ' No nwa device is associated with' - ' the port %s', nwa_info.get('port')) - return {'result': 'FAILED'} - nwa_info['resource_group_name'] = resource_group_name - - gd_count = check_segment_gd(network_id, resource_group_name, nwa_data) - - if 1 < gd_count: - nwa_data = self._delete_general_dev_data( - nwa_data=nwa_data, **kwargs) - self._delete_general_dev_segment(context, nwa_data, nwa_info) - raise nwa_exc.AgentProxyException(value=nwa_data) - - if self.multi_dc: - sync_vlan_id = self._delete_connect_port - else: - sync_vlan_id = self._delete_general_dev - # raise AgentProxyException if fail - nwa_data = sync_vlan_id(context, nwa_data=nwa_data, **kwargs) - # delete general dev end - - return self._terminate_l2_network(context, nwa_data, **kwargs) - - @helpers.log_method_call - @tenant_util.catch_exception_and_update_tenant_binding - def terminate_l2_network(self, context, **kwargs): - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_data = self.nwa_tenant_rpc.get_nwa_tenant_binding( - context, tenant_id, nwa_tenant_id) - return self._terminate_l2_network(context, nwa_data, **kwargs) - - def _terminate_l2_network(self, context, nwa_data, **kwargs): - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_info = kwargs.get('nwa_info') - network_id = nwa_info['network']['id'] - - # port check on segment. - if check_vlan(network_id, nwa_data): - raise nwa_exc.AgentProxyException(value=nwa_data) - - # delete vlan - # raise AgentProxyException if fail - nwa_data = self._delete_vlan(context, nwa_data=nwa_data, **kwargs) - # delete vlan end. - - # tenant network check. - for k in nwa_data: - if re.match('NW_.*', k): - raise nwa_exc.AgentProxyException(value=nwa_data) - - LOG.info(_LI("delete_tenant_nw")) - # raise AgentProxyException if fail - nwa_data = self._delete_tenant_nw(context, nwa_data=nwa_data, **kwargs) - - # delete tenant - LOG.info(_LI("delete_tenant")) - nwa_data = self.proxy_tenant.delete_tenant( - context, - nwa_data=nwa_data, - **kwargs - ) - # delete tenant end. - - # delete nwa_tenant binding. - LOG.info(_LI("delete_nwa_tenant_binding")) - return self.nwa_tenant_rpc.delete_nwa_tenant_binding( - context, tenant_id, nwa_tenant_id - ) - - @utils.log_method_return_value - def _delete_general_dev_data(self, **kwargs): - nwa_info = kwargs.get('nwa_info') - nwa_data = kwargs.get('nwa_data') - - device_id = nwa_info['device']['id'] - network_id = nwa_info['network']['id'] - resource_group_name = nwa_info['resource_group_name'] - - dev_key = data_utils.get_device_key(device_id) - if dev_key in nwa_data: - data_utils.strip_interface_data( - nwa_data, device_id, network_id, resource_group_name) - if count_device_id(device_id, nwa_data) == 1: - data_utils.strip_device_data(nwa_data, device_id) - - if not check_segment_gd(network_id, resource_group_name, nwa_data): - data_utils.strip_vp_net_data(nwa_data, network_id, - resource_group_name, - nwa_const.NWA_DEVICE_GDV) - - return nwa_data - - def _delete_general_dev_segment(self, context, nwa_data, nwa_info): - network_id = nwa_info['network']['id'] - physical_network = nwa_info['physical_network'] - resource_group_name = nwa_info['resource_group_name'] - if not check_segment_gd(network_id, resource_group_name, nwa_data): - self.nwa_l2_rpc.release_dynamic_segment_from_agent( - context, physical_network, network_id - ) - - @utils.log_method_return_value - @helpers.log_method_call - def _delete_general_dev(self, context, **kwargs): - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_info = kwargs.get('nwa_info') - nwa_data = kwargs.get('nwa_data') - - network_id = nwa_info['network']['id'] - resource_group = nwa_info['resource_group_name'] - - # delete general dev - logical_name = data_utils.get_vlan_logical_name(nwa_data, network_id) - rcode, body = self.client.l2.delete_general_dev( - nwa_tenant_id, - resource_group, - logical_name, - ) - if rcode != 200: - LOG.debug("DeleteGeneralDev Error: invalid response. rcode = %d", - rcode) - # error port send to plugin - raise nwa_exc.AgentProxyException(value=nwa_data) - - if body['status'] == 'SUCCEED': - LOG.debug("DeleteGeneralDev SUCCEED") - nwa_data = self._delete_general_dev_data(**kwargs) - self._delete_general_dev_segment(context, nwa_data, nwa_info) - else: - LOG.debug("DeleteGeneralDev %s", body['status']) - raise nwa_exc.AgentProxyException(value=nwa_data) - # delete general dev end - - return nwa_data - - @utils.log_method_return_value - @helpers.log_method_call - def create_connect_port(self, context, **kwargs): - nwa_info = kwargs['nwa_info'] - nwa_data = kwargs['nwa_data'] - network_id = nwa_info['network']['id'] - vlan_id = nwa_info['network']['vlan_id'] - resource_group_name = nwa_info['resource_group_name'] - rcode, body = self.client.l2.create_connect_port( - kwargs.get('nwa_tenant_id'), - resource_group_name, - data_utils.get_vlan_logical_name(nwa_data, network_id), - nwa_info['network']['vlan_type'], - vlan_id - ) - if rcode == 200 and body['status'] == 'SUCCEED': - LOG.debug("CreateConnectPort SUCCEED") - return body - - @utils.log_method_return_value - @helpers.log_method_call - def _create_connect_port(self, context, **kwargs): - body = self.create_connect_port(context, **kwargs) - if body: - nwa_data = kwargs['nwa_data'] - nwa_info = kwargs['nwa_info'] - network_id = nwa_info['network']['id'] - vlan_id = nwa_info['network']['vlan_id'] - resource_group_name = nwa_info['resource_group_name'] - vlan_key = data_utils.get_vlan_key(network_id) - if vlan_key not in nwa_data: - LOG.error(_LE("not create vlan.")) - raise nwa_exc.AgentProxyException(value=nwa_data) - data_utils.set_vp_net_data(nwa_data, network_id, - resource_group_name, - nwa_const.NWA_DEVICE_GDV, - vlan_id) - self._append_device_for_gdv(nwa_info, nwa_data) - else: - LOG.debug("CreateConnectPort %s", body['status']) - raise nwa_exc.AgentProxyException(value=nwa_data) - return nwa_data - - @utils.log_method_return_value - @helpers.log_method_call - def delete_connect_port(self, context, **kwargs): - nwa_info = kwargs['nwa_info'] - nwa_data = kwargs['nwa_data'] - network_id = nwa_info['network']['id'] - vlan_id = nwa_info['network']['vlan_id'] - resource_group_name = nwa_info['resource_group_name'] - rcode, body = self.client.l2.delete_connect_port( - kwargs['nwa_tenant_id'], - resource_group_name, - data_utils.get_vlan_logical_name(nwa_data, network_id), - nwa_info['network']['vlan_type'], - vlan_id - ) - if rcode == 200 and body['status'] == 'SUCCEED': - LOG.debug("DeleteConnectPort SUCCEED") - return body - - @utils.log_method_return_value - @helpers.log_method_call - def _delete_connect_port(self, context, **kwargs): - body = self.delete_connect_port(context, **kwargs) - if body: - nwa_data = self._delete_general_dev_data(**kwargs) - self._delete_general_dev_segment(context, nwa_data, - kwargs['nwa_info']) - else: - LOG.debug("DeleteConnectPort %s", body['status']) - raise nwa_exc.AgentProxyException(value=kwargs['nwa_data']) - return nwa_data diff --git a/networking_nec/nwa/agent/proxy_l3.py b/networking_nec/nwa/agent/proxy_l3.py deleted file mode 100644 index 95d7114..0000000 --- a/networking_nec/nwa/agent/proxy_l3.py +++ /dev/null @@ -1,440 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import re - -from neutron.common import topics -from neutron.plugins.common import constants as n_constants -from neutron.plugins.ml2 import driver_api as api -from neutron_lib import constants -from oslo_log import helpers -from oslo_log import log as logging - -from networking_nec._i18n import _LE, _LW -from networking_nec.common import utils -from networking_nec.nwa.agent import proxy_l2 as l2 -from networking_nec.nwa.agent import proxy_tenant as tenant_util -from networking_nec.nwa.common import constants as nwa_const -from networking_nec.nwa.common import exceptions as nwa_exc -from networking_nec.nwa.l2.rpc import nwa_l2_server_api -from networking_nec.nwa.l2.rpc import tenant_binding_api -from networking_nec.nwa.l3.rpc import nwa_l3_server_api -from networking_nec.nwa.nwalib import data_utils - - -LOG = logging.getLogger(__name__) - - -# pylint: disable=too-many-instance-attributes -class AgentProxyL3(object): - - def __init__(self, agent_top, client, multi_dc=False, - tenant_fw_create_hook=None, - tenant_fw_delete_hook=None, - tenant_fw_connect_hook=None, - tenant_fw_disconnect_hook=None): - self.nwa_tenant_rpc = tenant_binding_api.TenantBindingServerRpcApi( - topics.PLUGIN) - self.nwa_l2_rpc = nwa_l2_server_api.NwaL2ServerRpcApi(topics.PLUGIN) - self.nwa_l3_rpc = nwa_l3_server_api.NwaL3ServerRpcApi(topics.L3PLUGIN) - self.agent_top = agent_top - self.client = client - self.multi_dc = multi_dc - self.tenant_fw_create_hook = tenant_fw_create_hook - self.tenant_fw_delete_hook = tenant_fw_delete_hook - self.tenant_fw_connect_hook = tenant_fw_connect_hook - self.tenant_fw_disconnect_hook = tenant_fw_disconnect_hook - - @property - def proxy_tenant(self): - return self.agent_top.proxy_tenant - - @property - def proxy_l2(self): - return self.agent_top.proxy_l2 - - @helpers.log_method_call - @tenant_util.catch_exception_and_update_tenant_binding - def create_tenant_fw(self, context, **kwargs): - nwa_data = self.proxy_l2.ensure_l2_network(context, **kwargs) - device_id = kwargs['nwa_info']['device']['id'] - network_id = kwargs['nwa_info']['network']['id'] - dev_key = data_utils.get_device_key(device_id) - net_key = data_utils.get_device_net_key(device_id, network_id) - if dev_key not in nwa_data: - nwa_data = self._create_tenant_fw(nwa_data, context, **kwargs) - elif net_key not in nwa_data: - nwa_data = self._update_tenant_fw( - context, connect='connect', nwa_data=nwa_data, **kwargs) - else: - LOG.warning(_LW("unknown device.")) - - if not nwa_data: - raise nwa_exc.AgentProxyException(value=kwargs['nwa_data']) - ret = self.proxy_tenant.update_tenant_binding( - context, - kwargs['tenant_id'], kwargs['nwa_tenant_id'], - nwa_data - ) - resource_group_name_nw = kwargs['nwa_info']['resource_group_name_nw'] - vlan_id = data_utils.get_vp_net_vlan_id(nwa_data, network_id, - resource_group_name_nw, - nwa_const.NWA_DEVICE_TFW) - - self.nwa_l2_rpc.update_port_state_with_notifier( - context, - device_id, - self.agent_top.agent_id, - kwargs['nwa_info']['port']['id'], - { - api.PHYSICAL_NETWORK: kwargs['nwa_info']['physical_network'], - api.NETWORK_TYPE: n_constants.TYPE_VLAN, - api.SEGMENTATION_ID: vlan_id - }, - network_id - ) - return ret - - @utils.log_method_return_value - def _create_tenant_fw(self, nwa_data, context, **kwargs): - if self.multi_dc: - self.proxy_l2.create_connect_port(context, nwa_data=nwa_data, - **kwargs) - device_id = kwargs['nwa_info']['device']['id'] - network_id = kwargs['nwa_info']['network']['id'] - rcode, body = self.client.l3.create_tenant_fw( - kwargs['nwa_tenant_id'], - kwargs['nwa_info']['resource_group_name'], - kwargs['nwa_info']['port']['ip'], - data_utils.get_vlan_logical_name(nwa_data, network_id), - kwargs['nwa_info']['network']['vlan_type'] - ) - if rcode != 200 or body['status'] != 'SUCCEED': - return None - - LOG.debug("CreateTenantFW SUCCEED.") - - tfw_name = body['resultdata']['TenantFWName'] - resource_group_name_nw = kwargs['nwa_info']['resource_group_name_nw'] - - data_utils.set_tfw_device_data(nwa_data, device_id, - tfw_name, kwargs['nwa_info']) - data_utils.set_tfw_interface_data(nwa_data, device_id, network_id, - resource_group_name_nw, - tfw_name, kwargs['nwa_info']) - vlan_id = data_utils.get_vlan_id(network_id, nwa_data, - body['resultdata']) - data_utils.set_vp_net_data(nwa_data, network_id, - resource_group_name_nw, - nwa_const.NWA_DEVICE_TFW, - vlan_id) - - if self.tenant_fw_create_hook: - self.tenant_fw_create_hook(context, tfw_name, **kwargs) - return nwa_data - - @utils.log_method_return_value - def _update_tenant_fw(self, context, **kwargs): - connect = kwargs.get('connect') - try: - if connect == 'connect': - self._update_tenant_fw_connect(context, **kwargs) - else: # connect == 'disconnect' - self._update_tenant_fw_disconnect(context, **kwargs) - except nwa_exc.AgentProxyException: - return - return kwargs['nwa_data'] - - def _update_tenant_fw_connect(self, context, **kwargs): - if self.multi_dc: - self.proxy_l2.create_connect_port(context, **kwargs) - nwa_data = kwargs.get('nwa_data') - device_id = kwargs['nwa_info']['device']['id'] - network_id = kwargs['nwa_info']['network']['id'] - - rcode, body = self.client.l3.update_tenant_fw( - kwargs['nwa_tenant_id'], - data_utils.get_tfw_device_name(nwa_data, device_id), - kwargs['nwa_info']['port']['ip'], - data_utils.get_vlan_logical_name(nwa_data, network_id), - kwargs['nwa_info']['network']['vlan_type'], - connect='connect') - - if rcode != 200 or body['status'] != 'SUCCEED': - raise nwa_exc.AgentProxyException(value=None) - - LOG.debug("UpdateTenantFW succeed.") - resource_group_name_nw = kwargs['nwa_info']['resource_group_name_nw'] - tfw_name = body['resultdata']['TenantFWName'] - - data_utils.set_tfw_interface_data(nwa_data, device_id, network_id, - resource_group_name_nw, - tfw_name, kwargs['nwa_info']) - vlan_id = data_utils.get_vlan_id(network_id, nwa_data, - body['resultdata']) - data_utils.set_vp_net_data(nwa_data, network_id, - resource_group_name_nw, - nwa_const.NWA_DEVICE_TFW, - vlan_id) - - if self.tenant_fw_connect_hook: - self.tenant_fw_connect_hook(context, tfw_name, **kwargs) - return nwa_data - - @helpers.log_method_call - def _update_tenant_fw_disconnect(self, context, **kwargs): - """Update Tenant FW - - @param context: contains user information. - @param kwargs: - @return: nwa_data - @raise AgentProxyException - """ - if self.multi_dc: - self.proxy_l2.delete_connect_port(context, **kwargs) - nwa_data = kwargs.get('nwa_data') - device_id = kwargs['nwa_info']['device']['id'] - network_id = kwargs['nwa_info']['network']['id'] - device_name = data_utils.get_tfw_device_name(nwa_data, device_id) - - if self.tenant_fw_disconnect_hook: - self.tenant_fw_disconnect_hook(context, device_name, **kwargs) - - rcode, body = self.client.l3.update_tenant_fw( - kwargs['nwa_tenant_id'], - device_name, - kwargs['nwa_info']['port']['ip'], - data_utils.get_vlan_logical_name(nwa_data, network_id), - kwargs['nwa_info']['network']['vlan_type'], - connect='disconnect' - ) - if rcode != 200 or body['status'] != 'SUCCEED': - LOG.error(_LE("UpdateTenantFW(disconnect) FAILED.")) - info = {'status': 'FAILED', - 'msg': 'UpdateTenantFW(disconnect) FAILED.'} - raise nwa_exc.AgentProxyException(value=info) - - LOG.debug("UpdateTenantFW(disconnect) SUCCEED.") - resource_group_name_nw = kwargs['nwa_info']['resource_group_name_nw'] - - data_utils.strip_interface_data(nwa_data, device_id, network_id, - resource_group_name_nw) - data_utils.strip_tfw_data_if_exist(nwa_data, device_id, network_id, - resource_group_name_nw) - - if not l2.check_segment_tfw(network_id, resource_group_name_nw, - nwa_data): - data_utils.strip_vp_net_data(nwa_data, network_id, - resource_group_name_nw, - nwa_const.NWA_DEVICE_TFW) - return nwa_data - - @helpers.log_method_call - def _delete_tenant_fw(self, context, **kwargs): - """Delete Tenant FW - - @param context: contains user information. - @param kwargs: nwa_tenant_id, nwa_tenant_id, nwa_info, nwa_data - @return: resutl(succeed = True, other = False), data(nwa_data or None) - """ - if self.multi_dc: - self.proxy_l2.delete_connect_port(context, **kwargs) - nwa_data = kwargs.get('nwa_data') - nwa_info = kwargs['nwa_info'] - - network_id = nwa_info['network']['id'] - device_id = nwa_info['device']['id'] - - device_name = data_utils.get_tfw_device_name(nwa_data, device_id) - if self.tenant_fw_delete_hook: - self.tenant_fw_delete_hook(context, device_name, **kwargs) - - rcode, body = self.client.l3.delete_tenant_fw( - kwargs['nwa_tenant_id'], - device_name, - 'TFW' - ) - if rcode != 200 or body['status'] != 'SUCCEED': - msg = _LE("DeleteTenantFW %s."), body['status'] - LOG.error(msg) - raise nwa_exc.AgentProxyException(value=nwa_data) - - LOG.debug("DeleteTenantFW SUCCEED.") - - resource_group_name_nw = nwa_info['resource_group_name_nw'] - # delete recode - data_utils.strip_device_data(nwa_data, device_id) - data_utils.strip_interface_data(nwa_data, device_id, network_id, - resource_group_name_nw) - data_utils.strip_tfw_data_if_exist(nwa_data, device_id, network_id, - resource_group_name_nw) - - if not l2.check_segment_tfw(network_id, resource_group_name_nw, - nwa_data): - data_utils.strip_vp_net_data(nwa_data, network_id, - resource_group_name_nw, - nwa_const.NWA_DEVICE_TFW) - return nwa_data - - @utils.log_method_return_value - @helpers.log_method_call - @tenant_util.catch_exception_and_update_tenant_binding - def delete_tenant_fw(self, context, **kwargs): - """Delete Tenant FireWall. - - @param context: contains user information. - @param kwargs: tenant_id, nwa_tenant_id, nwa_info - @return: dict of status and msg. - """ - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_info = kwargs.get('nwa_info') - - network_id = nwa_info['network']['id'] - device_id = nwa_info['device']['id'] - - nwa_data = self.nwa_tenant_rpc.get_nwa_tenant_binding( - context, tenant_id, nwa_tenant_id - ) - - # check tfw interface - tfwif = "^DEV_" + device_id + '_.*_TenantFWName$' - count = sum(not re.match(tfwif, k) is None for k in nwa_data.keys()) - - if 1 < count: - ret_val = self._update_tenant_fw( - context, - nwa_data=nwa_data, - connect='disconnect', - **kwargs - ) - if not ret_val: - LOG.error(_LE("UpdateTenantFW disconnect FAILED")) - tfw_sgif = re.compile("^DEV_.*_" + network_id + '_TYPE$') - sgif_count = len([k for k in nwa_data if tfw_sgif.match(k)]) - if sgif_count: - raise nwa_exc.AgentProxyException(value=nwa_data) - nwa_data = ret_val - elif count == 1: - # raise AgentProxyException if fail - nwa_data = self._delete_tenant_fw( - context, nwa_data=nwa_data, **kwargs) - else: - LOG.error(_LE("count miss match")) - raise nwa_exc.AgentProxyException(value=nwa_data) - - return self.proxy_l2._terminate_l2_network(context, - nwa_data, **kwargs) - - @helpers.log_method_call - def setting_nat(self, context, **kwargs): - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - fip_id = kwargs['floating']['id'] - - nwa_data = self.nwa_tenant_rpc.get_nwa_tenant_binding( - context, tenant_id, nwa_tenant_id) - - try: - ret_val = self._setting_nat(context, nwa_data=nwa_data, **kwargs) - except nwa_exc.AgentProxyException: - self.nwa_l3_rpc.update_floatingip_status( - context, fip_id, constants.FLOATINGIP_STATUS_ERROR) - return - - self.nwa_l3_rpc.update_floatingip_status( - context, fip_id, constants.FLOATINGIP_STATUS_ACTIVE) - return self.proxy_tenant.update_tenant_binding( - context, tenant_id, nwa_tenant_id, ret_val) - - @helpers.log_method_call - def _setting_nat(self, context, **kwargs): - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_data = kwargs.get('nwa_data') - floating = kwargs.get('floating') - - # new code.(neet ut) - nat_key = 'NAT_' + floating['id'] - if nat_key in nwa_data: - LOG.debug('already in use NAT key =%s', nat_key) - raise nwa_exc.AgentProxyException(value=None) - - vlan_logical_name = data_utils.get_vlan_logical_name( - nwa_data, floating['floating_network_id']) - dev_name = data_utils.get_tfw_device_name(nwa_data, - floating['device_id']) - - # setting nat - rcode, body = self.client.l3.setting_nat( - nwa_tenant_id, - vlan_logical_name, 'PublicVLAN', - floating['fixed_ip_address'], - floating['floating_ip_address'], dev_name, data=floating - ) - - if rcode != 200 or body['status'] != 'SUCCEED': - LOG.debug("SettingNat Error: invalid responce." - " rcode=%d status=%s" % (rcode, body)) - raise nwa_exc.AgentProxyException(value=None) - else: - LOG.debug("SettingNat SUCCEED") - data_utils.set_floatingip_data(nwa_data, floating) - return nwa_data - - @helpers.log_method_call - def delete_nat(self, context, **kwargs): - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - fip_id = kwargs['floating']['id'] - - nwa_data = self.nwa_tenant_rpc.get_nwa_tenant_binding( - context, tenant_id, nwa_tenant_id) - - try: - ret_val = self._delete_nat(context, nwa_data=nwa_data, **kwargs) - except nwa_exc.AgentProxyException: - self.nwa_l3_rpc.update_floatingip_status( - context, fip_id, constants.FLOATINGIP_STATUS_ERROR) - return - - self.nwa_l3_rpc.update_floatingip_status( - context, fip_id, constants.FLOATINGIP_STATUS_DOWN) - return self.proxy_tenant.update_tenant_binding( - context, tenant_id, nwa_tenant_id, ret_val) - - @helpers.log_method_call - def _delete_nat(self, context, **kwargs): - nwa_data = kwargs.get('nwa_data') - floating = kwargs.get('floating') - - vlan_logical_name = data_utils.get_vlan_logical_name( - nwa_data, floating['floating_network_id']) - dev_name = data_utils.get_tfw_device_name(nwa_data, - floating['device_id']) - - # setting nat - rcode, body = self.client.l3.delete_nat( - kwargs.get('nwa_tenant_id'), - vlan_logical_name, 'PublicVLAN', - floating['fixed_ip_address'], - floating['floating_ip_address'], dev_name, data=floating) - - if rcode != 200 or body['status'] != 'SUCCEED': - LOG.debug("DeleteNat Error: invalid responce." - " rcode=%d status=%s" % (rcode, body)) - raise nwa_exc.AgentProxyException(value=None) - else: - LOG.debug("DeleteNat SUCCEED") - data_utils.strip_floatingip_data(nwa_data, floating) - return nwa_data diff --git a/networking_nec/nwa/agent/proxy_tenant.py b/networking_nec/nwa/agent/proxy_tenant.py deleted file mode 100644 index a916107..0000000 --- a/networking_nec/nwa/agent/proxy_tenant.py +++ /dev/null @@ -1,109 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.common import topics -from oslo_log import log as logging -from oslo_serialization import jsonutils - -from networking_nec._i18n import _LW -from networking_nec.common import utils -from networking_nec.nwa.common import exceptions as nwa_exc -from networking_nec.nwa.l2.rpc import tenant_binding_api - -LOG = logging.getLogger(__name__) - - -def catch_exception_and_update_tenant_binding(method): - - def wrapper(obj, context, **kwargs): - try: - return method(obj, context, **kwargs) - except nwa_exc.AgentProxyException as e: - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_data = e.value - return obj.proxy_tenant.update_tenant_binding( - context, tenant_id, nwa_tenant_id, nwa_data) - - return wrapper - - -class AgentProxyTenant(object): - - def __init__(self, agent_top, client): - self.agent_top = agent_top - self.client = client - self.nwa_tenant_rpc = tenant_binding_api.TenantBindingServerRpcApi( - topics.PLUGIN) - - @utils.log_method_return_value - def create_tenant(self, context, **kwargs): - """create tenant - - @param context: contains user information. - @param kwargs: nwa_tenant_id - @return: succeed - dict of status, and information. - """ - nwa_tenant_id = kwargs.get('nwa_tenant_id') - - status_code, __data = self.client.tenant.create_tenant(nwa_tenant_id) - if status_code in (200, 500): # success(200), already exists(500) - return { - 'CreateTenant': True, - 'NWA_tenant_id': nwa_tenant_id - } - raise nwa_exc.AgentProxyException(value=status_code) - - @utils.log_method_return_value - def delete_tenant(self, context, **kwargs): - """delete tenant. - - @param context: contains user information. - @param kwargs: nwa_tenant_id - @return: result(succeed = (True, dict(empty) other = False, None) - """ - nwa_tenant_id = kwargs.get('nwa_tenant_id') - rcode, body = self.client.tenant.delete_tenant(nwa_tenant_id) - if rcode != 200: - LOG.warning(_LW('unexpected status code %s in delete_tenant'), - rcode) - return body - - @utils.log_method_return_value - def update_tenant_binding( - self, context, tenant_id, nwa_tenant_id, - nwa_data, nwa_created=False - ): - """Update Tenant Binding on NECNWAL2Plugin. - - @param context:contains user information. - @param tenant_id: Openstack Tenant UUID - @param nwa_tenant_id: NWA Tenand ID - @param nwa_data: nwa_tenant_binding data. - @param nwa_created: flag of operation. True = Create, False = Update - @return: dict of status and msg. - """ - LOG.debug("nwa_data=%s", jsonutils.dumps( - nwa_data, - indent=4, - sort_keys=True - )) - if nwa_created: - return self.nwa_tenant_rpc.add_nwa_tenant_binding( - context, tenant_id, nwa_tenant_id, nwa_data - ) - - return self.nwa_tenant_rpc.set_nwa_tenant_binding( - context, tenant_id, nwa_tenant_id, nwa_data - ) diff --git a/networking_nec/nwa/agent/server_manager.py b/networking_nec/nwa/agent/server_manager.py deleted file mode 100644 index 6b0e1f0..0000000 --- a/networking_nec/nwa/agent/server_manager.py +++ /dev/null @@ -1,130 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import eventlet -from neutron.common import rpc as n_rpc -from oslo_config import cfg -from oslo_log import log as logging -from oslo_messaging.rpc.server import get_rpc_server -from oslo_messaging.target import Target - -from networking_nec._i18n import _LW, _LI, _LE -from networking_nec.nwa.common import constants as nwa_const - -LOG = logging.getLogger(__name__) - - -class ServerManager(object): - """Implementation of nwa_agent_callback.NwaAgentRpcCallback.""" - - rpc_servers = {} - - def __init__(self, topic, agent_top, size=1000): - super(ServerManager, self).__init__() - self.topic = topic - self.agent_top = agent_top - self.greenpool_size = size - self.greenpool = eventlet.greenpool.GreenPool(self.greenpool_size) - - def get_rpc_server_topics(self): - return [v['topic'] for v in self.rpc_servers.values()] - - def get_rpc_server_tenant_ids(self): - return [{'tenant_id': tid} for tid in self.rpc_servers] - - def create_tenant_rpc_server(self, tid): - """create_ blocking rpc server - - @param tid: openstack tenant id - """ - ret = {} - - if tid in self.rpc_servers: - LOG.warning( - _LW("already in message queue and server. queue=%s"), - self.rpc_servers[tid]['topic'] - ) - return {'result': 'FAILED'} - - topic = "%s-%s" % (self.topic, tid) - - target = Target( - topic=topic, server=cfg.CONF.host, fanout=False) - - assert n_rpc.TRANSPORT is not None - serializer = n_rpc.RequestContextSerializer(None) - - server = get_rpc_server( - n_rpc.TRANSPORT, target, - self.agent_top.endpoints, - 'blocking', serializer - ) - - LOG.debug("RPCServer create: topic=%s", topic) - if self.greenpool.free() < 1: - self.greenpool_size += nwa_const.NWA_GREENPOOL_ADD_SIZE - self.greenpool.resize(self.greenpool_size) - LOG.info(_LI('RPCServer greenpool resize %s'), self.greenpool_size) - - def server_start(): - while True: - try: - LOG.debug('RPCServer thread %d start %s', - (self.greenpool.running(), server)) - server.start() - LOG.debug('RPCServer thread end %s', server) - break - except Exception as e: - LOG.exception(_LE('RPCServer thread start failed: %s'), e) - - self.rpc_servers[tid] = { - 'thread': self.greenpool.spawn(server_start), - 'server': server, - 'topic': topic - } - eventlet.sleep(0) - LOG.info(_LI('RPCServer started: %(topic)s server=%(server)s'), - {'topic': topic, 'server': server}) - - ret['result'] = 'SUCCESS' - ret['tenant_id'] = tid - ret['topic'] = topic - - return ret - - def delete_tenant_rpc_server(self, tid): - if tid not in self.rpc_servers: - LOG.warning(_LW("rpc server not found. tid=%s"), tid) - return {'result': 'FAILED'} - - LOG.debug('RPCServer delete: stop %s', tid) - self.rpc_servers[tid]['server'].stop() - - LOG.debug('RPCServer delete: wait %s', tid) - self.rpc_servers[tid]['server'].wait() - - LOG.debug('RPCServer delete: pop %s', tid) - self.rpc_servers.pop(tid) - - LOG.debug('RPCServer delete: sleep %s', tid) - eventlet.sleep(0) - - ret = { - 'result': 'SUCCESS', - 'tenant_id': tid - } - - LOG.debug("RPCServer deleted: %s", ret) - - return ret diff --git a/networking_nec/nwa/common/__init__.py b/networking_nec/nwa/common/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/nwa/common/config.py b/networking_nec/nwa/common/config.py deleted file mode 100644 index f313a74..0000000 --- a/networking_nec/nwa/common/config.py +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.agent.common import config -from oslo_config import cfg - -from networking_nec._i18n import _ - -agent_opts = [ - cfg.IntOpt('polling_interval', default=2, - help=_("The number of seconds the agent will wait between " - "polling for local device changes.")), -] - -cfg.CONF.register_opts(agent_opts, "AGENT") -config.register_agent_state_opts_helper(cfg.CONF) - -# nwa.ini -NWA_opts = [ - cfg.StrOpt('server_url', - help=_("URL for NWA REST API.")), - cfg.StrOpt('access_key_id', - help=_("Access ID for NWA REST API.")), - cfg.StrOpt('secret_access_key', - help=_("Secret key for NWA REST API.")), - cfg.StrOpt('resource_group_name', - help=_( - "Resouce Group Name specified at creating tenant NW.")), - cfg.StrOpt('region_name', - help=_("RegionName for DC."), - default='RegionOne'), - cfg.IntOpt('scenario_polling_first_timer', default=2, - help=_("Timer value for the first scenario status polling.")), - cfg.IntOpt('scenario_polling_timer', default=10, - help=_("Timer value for polling scenario status.")), - cfg.IntOpt('scenario_polling_count', default=6, - help=_("Count value for polling scenario status.")), - cfg.BoolOpt('use_necnwa_router', - help=_("Using necnwa_router instead of the l3-router"), - default=True), - cfg.BoolOpt('use_neutron_vlan_id', - help=_("Using vlan id of neutron instead of NWA"), - default=False), - cfg.StrOpt('ironic_az_prefix', - help=_("The prefix name of device_owner used in ironic"), - default='BM_'), - cfg.BoolOpt('use_setting_fw_policy', - default=False, - help=_('Using setting_fw_policy as default')), - cfg.StrOpt('resource_group_file', - help=_("JSON file which defines relations between " - "physical network of OpenStack and NWA.")), - cfg.StrOpt('resource_group', - deprecated_for_removal=True, - deprecated_reason='In favor of resource_group_file option.', - help=_(""" - Relations between physical network of OpenStack and NWA. - ex) - [ - { - "physical_network": "physnet1", - "ResourceGroupName":"Core/Hypervisor/HV-RG01" - }, - { ... }, - ]""")), - cfg.StrOpt('lbaas_driver', - help=_("LBaaS Driver Name")), - cfg.StrOpt('fwaas_driver', - help=_("Firewall Driver Name")), -] - -Scenario_opts = [ - cfg.StrOpt('CreateTenantFW', - help=_("Scenario ID for the scenario CreateTenantFW.")), - cfg.StrOpt('CreateTenantNW', - help=_("Scenario ID for the scenario CreateTenantNW.")), - cfg.StrOpt('CreateVLAN', - help=_("Scenario ID for the scenario CreateVLAN.")), - cfg.StrOpt('CreateGeneralDev', - help=_( - "Scenario ID for the scenario CreateGeneralDev.")), - cfg.StrOpt('UpdateTenantFW', - help=_("Scenario ID for the scenario UpdateTenantFW.")), - cfg.StrOpt('SettingNAT', - help=_("Scenario ID for the scenario SettingNAT.")), -] - -cfg.CONF.register_opts(NWA_opts, "NWA") -cfg.CONF.register_opts(Scenario_opts, "Scenario") diff --git a/networking_nec/nwa/common/constants.py b/networking_nec/nwa/common/constants.py deleted file mode 100644 index 53e6e75..0000000 --- a/networking_nec/nwa/common/constants.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -NWA_DEVICE_GDV = "GeneralDev" -NWA_DEVICE_TFW = "TenantFW" - -NWA_AGENT_TOPIC = 'nwa_agent' -NWA_AGENT_TYPE = 'NEC NWA Agent' - -NWA_FIREWALL_PLUGIN = 'NECNWAFWaaS' - -# an incremental size if the remaining size is zero. -NWA_GREENPOOL_ADD_SIZE = 32 diff --git a/networking_nec/nwa/common/exceptions.py b/networking_nec/nwa/common/exceptions.py deleted file mode 100644 index b1e9c5f..0000000 --- a/networking_nec/nwa/common/exceptions.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron_lib import exceptions as n_exc - -from networking_nec._i18n import _ - - -class NWAClientError(n_exc.NeutronException): - message = _('NWAClient Error %(msg)s') - - -class NWAUtilsError(n_exc.NeutronException): - message = _('NWAUtils Error %(msg)s') - - -class TenantNotFound(n_exc.NeutronException): - message = _('NWA Tenant %(tenant_id)s not found') - - -class ResourceGroupNameNotFound(n_exc.NotFound): - message = _("ResourceGroupName %(device_owner)s could not be found") - - -class AgentProxyException(Exception): - def __init__(self, value=None): - super(AgentProxyException, self).__init__() - self.value = value diff --git a/networking_nec/nwa/common/utils.py b/networking_nec/nwa/common/utils.py deleted file mode 100644 index 5b02ef5..0000000 --- a/networking_nec/nwa/common/utils.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_config import cfg -from oslo_log import log as logging -from oslo_serialization import jsonutils - -from networking_nec._i18n import _, _LE, _LW -# It is required to register nwa options -from networking_nec.nwa.common import config # noqa - -LOG = logging.getLogger(__name__) - - -def get_nwa_tenant_id(tenant_id): - return cfg.CONF.NWA.region_name + tenant_id - - -def get_tenant_info(context): - tenant_id = context.network.current['tenant_id'] - nwa_tenant_id = get_nwa_tenant_id(tenant_id) - return tenant_id, nwa_tenant_id - - -def load_json_from_file(name, json_file, json_str, default_value): - if json_file: - json_file_abspath = cfg.CONF.find_file(json_file) - if not json_file_abspath: - LOG.error(_LE('Failed to load %(name)s_file' - '"%(json_file)s": file not found'), - {'name': name, 'json_file': json_file}) - raise cfg.Error(_('NECNWA option parse error')) - try: - with open(json_file_abspath) as f: - return jsonutils.loads(f.read()) - except Exception as e: - LOG.error(_LE('Failed to load %(name)s_file ' - '"%(json_file)s": %(reason)s'), - {'reason': e, 'name': name, 'json_file': json_file}) - raise cfg.Error(_('NECNWA option parse error')) - elif json_str: - try: - return jsonutils.loads(json_str) - except Exception as e: - LOG.error(_LE('NECNWA option error during loading %(name)s ' - '(%(data)s): %(reason)s'), - {'reason': e, 'name': name, 'data': json_str}) - raise cfg.Error(_('NECNWA option parse error')) - else: - LOG.warning(_LW('%(name)s is not configured. ' - 'Make sure to set [NWA] %(name)s_file ' - 'in NWA plugin configuration file. ' - 'Using %(default)s as default value.'), - {'name': name, 'default': default_value}) - return default_value diff --git a/networking_nec/nwa/l2/__init__.py b/networking_nec/nwa/l2/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/nwa/l2/db_api.py b/networking_nec/nwa/l2/db_api.py deleted file mode 100644 index 0c65c14..0000000 --- a/networking_nec/nwa/l2/db_api.py +++ /dev/null @@ -1,200 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.plugins.ml2 import models as models_ml2 -import sqlalchemy as sa -from sqlalchemy import and_ - -from networking_nec.nwa.l2 import models as nmodels - - -class NWATenantBinding(object): - """Relation between OpenStack Tenant ID and NWA Tenant ID.""" - def __init__(self, tenant_id, nwa_tenant_id, value_json): - self.tenant_id = tenant_id - self.nwa_tenant_id = nwa_tenant_id - self.value_json = value_json - - def __repr__(self): - return "" % ( - self.tenant_id, self.nwa_tenant_id, self.value_json - ) - - -def add_nwa_tenant_binding(session, tenant_id, nwa_tenant_id, json_value): - try: - if not isinstance(json_value, dict): - return False - nwa = session.query(nmodels.NWATenantKeyValue).filter( - nmodels.NWATenantKeyValue.tenant_id == tenant_id).all() - if nwa: - return False - with session.begin(subtransactions=True): - for json_key, json_value in json_value.items(): - item = nmodels.NWATenantKeyValue(tenant_id, nwa_tenant_id, - json_key, json_value) - session.add(item) - return True - except sa.orm.exc.NoResultFound: - return False - - -def convert_if_special_value(s): - if s == 'True' or s == '1': - return True - if s == 'False' or s == '0': - return False - return s - - -def get_nwa_tenant_binding(session, tenant_id, nwa_tenant_id): - try: - value_json = { - nwa.json_key: convert_if_special_value(nwa.json_value) - for nwa in session.query(nmodels.NWATenantKeyValue).filter( - nmodels.NWATenantKeyValue.tenant_id == tenant_id).filter( - nmodels.NWATenantKeyValue.nwa_tenant_id == - nwa_tenant_id).all() - } - if value_json: - return NWATenantBinding(tenant_id, nwa_tenant_id, value_json) - else: - return None - except sa.orm.exc.NoResultFound: - return None - - -def set_nwa_tenant_binding(session, tenant_id, nwa_tenant_id, value_json): - item = get_nwa_tenant_binding(session, tenant_id, nwa_tenant_id) - if not item: - return False - _json = item.value_json - if not isinstance(_json, dict): - return False - if not isinstance(value_json, dict): - return False - with session.begin(subtransactions=True): - for key, value in value_json.items(): - if key in _json: - if value != _json[key]: - # update - item = session.query(nmodels.NWATenantKeyValue).filter( - and_(nmodels.NWATenantKeyValue.tenant_id == tenant_id, - nmodels.NWATenantKeyValue.json_key == key)).one() - item.json_value = value - else: - # insert - # item = nmodels.NWATenantKeyValue( - # tenant_id, nwa_tenant_id, key, value) - # session.add(item) - insert = ("INSERT INTO nwa_tenant_key_value (tenant_id," - "nwa_tenant_id,json_key,json_value) " - " VALUES (\'%s\',\'%s\',\'%s\',\'%s\') " - "ON DUPLICATE KEY UPDATE " - " json_value=\'%s\'" % (tenant_id, nwa_tenant_id, - key, value, value)) - session.execute(insert) - for key, value in _json.items(): - if key not in value_json: - # delete - item = session.query(nmodels.NWATenantKeyValue).filter( - and_(nmodels.NWATenantKeyValue.tenant_id == tenant_id, - nmodels.NWATenantKeyValue.json_key == key)).one() - session.delete(item) - return True - - -def del_nwa_tenant_binding(session, tenant_id, nwa_tenant_id): - try: - with session.begin(subtransactions=True): - item = get_nwa_tenant_binding(session, tenant_id, nwa_tenant_id) - if not item: - return False - with session.begin(subtransactions=True): - session.query(nmodels.NWATenantKeyValue).filter( - and_(nmodels.NWATenantKeyValue.tenant_id == tenant_id, - nmodels.NWATenantKeyValue.nwa_tenant_id == - nwa_tenant_id)).delete() - return True - except sa.orm.exc.NoResultFound: - return False - - -def ensure_port_binding(session, port_id): - - with session.begin(subtransactions=True): - try: - record = (session.query(models_ml2.PortBindingLevel). - filter_by(port_id=port_id). - one()) - except sa.orm.exc.NoResultFound: - # for kilo(re mearge) - record = (session.query(models_ml2.PortBinding). - filter_by(port_id=port_id). - one()) - return record - - -def add_nwa_tenant_queue(session, tenant_id, nwa_tenant_id='', topic=''): - try: - nwa = session.query(nmodels.NWATenantQueue).filter( - nmodels.NWATenantQueue.tenant_id == tenant_id).all() - if nwa: - return False - with session.begin(subtransactions=True): - nwa = nmodels.NWATenantQueue( - tenant_id, - nwa_tenant_id, - topic - ) - session.add(nwa) - return True - except sa.orm.exc.NoResultFound: - return False - - -def get_nwa_tenant_queue(session, tenant_id): - try: - queue = session.query(nmodels.NWATenantQueue).filter( - nmodels.NWATenantQueue.tenant_id == tenant_id).one() - - if queue: - return queue - else: - return None - except sa.orm.exc.NoResultFound: - return None - - -def get_nwa_tenant_queues(session): - try: - queues = session.query(nmodels.NWATenantQueue).all() - return queues - except sa.orm.exc.NoResultFound: - return None - - -def del_nwa_tenant_queue(session, tenant_id): - try: - with session.begin(subtransactions=True): - item = get_nwa_tenant_queue(session, tenant_id) - if not item: - return False - with session.begin(subtransactions=True): - session.query(nmodels.NWATenantQueue).filter( - nmodels.NWATenantQueue.tenant_id == tenant_id - ).delete() - return True - except sa.orm.exc.NoResultFound: - return False diff --git a/networking_nec/nwa/l2/drivers/__init__.py b/networking_nec/nwa/l2/drivers/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/nwa/l2/drivers/mech_necnwa.py b/networking_nec/nwa/l2/drivers/mech_necnwa.py deleted file mode 100644 index 6fd8daf..0000000 --- a/networking_nec/nwa/l2/drivers/mech_necnwa.py +++ /dev/null @@ -1,261 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.common import constants as neutron_const -from neutron.common import utils -from neutron.db import segments_db as db_ml2 -from neutron.extensions import portbindings -from neutron.extensions import providernet as prov_net -from neutron.plugins.common import constants as plugin_const -from neutron.plugins.ml2 import driver_api as api -from neutron.plugins.ml2.drivers.openvswitch.mech_driver \ - import mech_openvswitch as ovs -from neutron_lib import constants -from oslo_config import cfg -from oslo_log import log as logging - -from networking_nec._i18n import _LW -from networking_nec.nwa.common import exceptions as nwa_exc -from networking_nec.nwa.common import utils as nwa_com_utils -from networking_nec.nwa.l2 import utils as nwa_l2_utils -from networking_nec.nwa.l3 import db_api as nwa_l3_db -from networking_nec.nwa.l3.rpc import nwa_l3_proxy_api - -LOG = logging.getLogger(__name__) - - -class NECNWAMechanismDriver(ovs.OpenvswitchMechanismDriver): - - def initialize(self): - self.resource_groups = nwa_com_utils.load_json_from_file( - 'resource_group', cfg.CONF.NWA.resource_group_file, - cfg.CONF.NWA.resource_group, default_value=[]) - self.necnwa_router = cfg.CONF.NWA.use_necnwa_router - self.multi_dc = cfg.CONF.NWA.use_neutron_vlan_id - - def _get_l2api_proxy(self, context, tenant_id): - proxy = context._plugin.get_nwa_proxy(tenant_id, - context._plugin_context) - return proxy - - def _get_l3api_proxy(self, context, tenant_id): - proxy = context._plugin.get_nwa_proxy(tenant_id, - context.network._plugin_context) - return nwa_l3_proxy_api.NwaL3ProxyApi(proxy.client) - - def is_router(self, device_owner): - return device_owner in (constants.DEVICE_OWNER_ROUTER_INTF, - constants.DEVICE_OWNER_ROUTER_GW) - - def create_port_precommit(self, context): - if not self.necnwa_router: - return - device_owner = context._port['device_owner'] - if not self.is_router(device_owner): - LOG.warning(_LW("device owner missmatch device_owner=%s"), - device_owner) - return - self._l3_create_tenant_fw(context) - physical_network = self._find_nwa_physical_network(context) - if physical_network: - self._bind_segment_to_vif_type(context, physical_network) - - def update_port_precommit(self, context): - new_port = context.current - orig_port = context.original - if (not new_port['device_id'] and orig_port['device_id'] and - not new_port['device_owner'] and orig_port['device_owner']): - # device_id and device_owner are clear on VM deleted. - LOG.debug('original_port=%s', context.original) - LOG.debug('updated_port=%s', context.current) - self._l2_delete_general_dev(context, use_original_port=True) - - def delete_port_precommit(self, context): - tenant_id, nwa_tenant_id = nwa_com_utils.get_tenant_info(context) - device_owner = context._port['device_owner'] - device_id = context._port['device_id'] - - LOG.debug("tenant_id=%(tid)s, nwa_tenant_id=%(nid)s, " - "device_owner=%(dev)s", - {'tid': tenant_id, 'nid': nwa_tenant_id, - 'dev': device_owner}) - - if self.necnwa_router and self.is_router(device_owner): - self._l3_delete_tenant_fw(context) - elif device_owner == constants.DEVICE_OWNER_FLOATINGIP: - pass - elif device_owner == '' and device_id == '': - pass - else: - self._l2_delete_general_dev(context) - - def try_to_bind_segment_for_agent(self, context, segment, agent): - device_owner = context._port['device_owner'] - if not self.necnwa_router or not self.is_router(device_owner): - physical_network = self._find_nwa_physical_network(context, agent) - if physical_network: - self._bind_segment_to_vif_type(context, physical_network) - self._bind_port_nwa_debug_message(context) - self._l2_create_general_dev(context) - return True - LOG.warning(_LW("binding segment not found for agent=%s"), agent) - return super( - NECNWAMechanismDriver, self - ).try_to_bind_segment_for_agent(context, segment, agent) - - def _find_nwa_physical_network(self, context, ovs_agent=None): - mappings = {} - if ovs_agent: - mappings = ovs_agent['configurations'].get('bridge_mappings', {}) - for res in self.resource_groups: - if ovs_agent and res['ResourceGroupName'] not in mappings: - continue - if res['device_owner'] == context._port['device_owner']: - return res['ResourceGroupName'] - - def _bind_segment_to_vif_type(self, context, physical_network): - if self.multi_dc: - return - network_id = context.network.current['id'] - session = context.network._plugin_context.session - dummy_segment = db_ml2.get_dynamic_segment( - session, network_id, physical_network=physical_network) - LOG.debug("1st: dummy segment is %s", dummy_segment) - if not dummy_segment: - dummy_segment = { - api.PHYSICAL_NETWORK: physical_network, - api.NETWORK_TYPE: plugin_const.TYPE_VLAN, - api.SEGMENTATION_ID: 0 - } - db_ml2.add_network_segment( - session, network_id, dummy_segment, is_dynamic=True) - LOG.debug("2nd: dummy segment is %s", dummy_segment) - context.set_binding(dummy_segment[api.ID], - self.vif_type, - {portbindings.CAP_PORT_FILTER: True, - portbindings.OVS_HYBRID_PLUG: True}) - - def _bind_port_nwa_debug_message(self, context): - network_name, network_id = nwa_l2_utils.get_network_info(context) - device_owner = context._port['device_owner'] - - subnet_ids = [] - if 'fixed_ips' in context._port: - for fixed_ip in context._port['fixed_ips']: - subnet_ids.append(fixed_ip['subnet_id']) - - segmentation_id = 0 - if prov_net.PHYSICAL_NETWORK in context.network.current: - segmentation_id = context.network.current[prov_net.SEGMENTATION_ID] - else: - for provider in context.network.current['segments']: - if (provider.get(prov_net.PHYSICAL_NETWORK) == - nwa_l2_utils.get_physical_network( - device_owner, self.resource_groups)): - segmentation_id = provider[prov_net.SEGMENTATION_ID] - break - - LOG.debug("provider segmentation_id = %s", segmentation_id) - LOG.debug("_bind_port_nwa %(network_name)s " - "%(network_id)s %(device_id)s %(device_owner)s " - "%(port_id)s %(mac_address)s %(subnet_ids)s " - "%(segmentation_id)s", - {'network_name': network_name, - 'network_id': network_id, - 'device_id': context._port['device_id'], - 'device_owner': device_owner, - 'port_id': context._port['id'], - 'mac_address': context._port['mac_address'], - 'subnet_ids': subnet_ids, - 'segmentation_id': segmentation_id}) - - def _l2_create_general_dev(self, context): - kwargs = self._make_l2api_kwargs(context) - proxy = self._get_l2api_proxy(context, kwargs['tenant_id']) - proxy.create_general_dev(context.network._plugin_context, **kwargs) - - def _l2_delete_general_dev(self, context, use_original_port=False): - try: - kwargs = self._make_l2api_kwargs( - context, use_original_port=use_original_port) - self._l2_delete_segment(context, kwargs['nwa_info']) - proxy = self._get_l2api_proxy(context, kwargs['tenant_id']) - kwargs['nwa_info'] = self._revert_dhcp_agent_device_id( - context, kwargs['nwa_info']) - proxy.delete_general_dev(context.network._plugin_context, **kwargs) - except nwa_exc.TenantNotFound as e: - LOG.warning(_LW("skip delete_general_dev: %s"), e) - - def _make_l2api_kwargs(self, context, use_original_port=False): - tenant_id, nwa_tenant_id = nwa_com_utils.get_tenant_info(context) - nwa_info = nwa_l2_utils.portcontext_to_nwa_info( - context, self.resource_groups, use_original_port) - return { - 'tenant_id': tenant_id, - 'nwa_tenant_id': nwa_tenant_id, - 'nwa_info': nwa_info - } - - def _revert_dhcp_agent_device_id(self, context, nwa_info): - device_owner = context._port['device_owner'] - device_id = context._port['device_id'] - if device_owner == constants.DEVICE_OWNER_DHCP and \ - device_id == neutron_const.DEVICE_ID_RESERVED_DHCP_PORT: - # get device_id of dhcp agent even if it is reserved. - nwa_info['device']['id'] = utils.get_dhcp_agent_device_id( - context.network.current['id'], - context._port.get('binding:host_id') - ) - return nwa_info - - def _l2_delete_segment(self, context, nwa_info): - session = context.network._plugin_context.session - del_segment = db_ml2.get_dynamic_segment( - session, - context.network.current['id'], - physical_network=nwa_info['physical_network']) - if del_segment: - LOG.debug('delete_network_segment %s', del_segment) - db_ml2.delete_network_segment(session, del_segment['id']) - - def _l3_create_tenant_fw(self, context): - device_owner = context._port['device_owner'] - grplst = [res['device_owner'] for res in self.resource_groups] - if device_owner not in grplst: - raise nwa_exc.ResourceGroupNameNotFound(device_owner=device_owner) - - kwargs = self._make_l3api_kwargs(context) - proxy = self._get_l3api_proxy(context, kwargs['tenant_id']) - proxy.create_tenant_fw(context.network._plugin_context, **kwargs) - - def _l3_delete_tenant_fw(self, context): - kwargs = self._make_l3api_kwargs(context) - proxy = self._get_l3api_proxy(context, kwargs['tenant_id']) - proxy.delete_tenant_fw(context.network._plugin_context, **kwargs) - - def _make_l3api_kwargs(self, context): - rt_tid = nwa_l3_db.get_tenant_id_by_router( - context.network._plugin_context.session, - context._port['device_id'] - ) - nwa_rt_tid = nwa_com_utils.get_nwa_tenant_id(rt_tid) - nwa_info = nwa_l2_utils.portcontext_to_nwa_info( - context, self.resource_groups) - nwa_info['tenant_id'] = rt_tid # overwrite by router's - nwa_info['nwa_tenant_id'] = nwa_rt_tid # tenant_id and nwa_tenant_id - return { - 'tenant_id': rt_tid, - 'nwa_tenant_id': nwa_rt_tid, - 'nwa_info': nwa_info - } diff --git a/networking_nec/nwa/l2/models.py b/networking_nec/nwa/l2/models.py deleted file mode 100644 index 4e1248d..0000000 --- a/networking_nec/nwa/l2/models.py +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron_lib.db import model_base -import sqlalchemy as sa - - -class NWATenantKeyValue(model_base.BASEV2): - """Key and value database of NWW tenant""" - __tablename__ = 'nwa_tenant_key_value' - - tenant_id = sa.Column(sa.String(36), primary_key=True) - nwa_tenant_id = sa.Column(sa.String(64)) - json_key = sa.Column(sa.String(192), nullable=False, - default='', primary_key=True) - json_value = sa.Column(sa.String(1024), nullable=False, - default='') - - def __init__(self, tenant_id, nwa_tenant_id, json_key, json_value): - self.tenant_id = tenant_id - self.nwa_tenant_id = nwa_tenant_id - self.json_key = json_key - self.json_value = json_value - - def __repr__(self): - return "" % ( - self.tenant_id, self.nwa_tenant_id, - {self.json_key: self.json_value} - ) - - -class NWATenantQueue(model_base.BASEV2): - """Queue for each NWA Tenant between server and agent""" - __tablename__ = 'nwa_tenant_queue' - - tenant_id = sa.Column(sa.String(36), primary_key=True) - nwa_tenant_id = sa.Column(sa.String(64)) - topic = sa.Column(sa.String(128), default='') - - def __init__(self, tenant_id, nwa_tenant_id, topic): - self.tenant_id = tenant_id - self.nwa_tenant_id = nwa_tenant_id - self.topic = topic - - def __repr__(self): - return "" % ( - self.tenant_id, - self.nwa_tenant_id, - self.topic - ) diff --git a/networking_nec/nwa/l2/plugin.py b/networking_nec/nwa/l2/plugin.py deleted file mode 100644 index 479b55b..0000000 --- a/networking_nec/nwa/l2/plugin.py +++ /dev/null @@ -1,183 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.api.rpc.handlers import dhcp_rpc -from neutron.api.rpc.handlers import metadata_rpc -from neutron.api.rpc.handlers import securitygroups_rpc -from neutron.common import rpc as n_rpc -from neutron.common import topics -from neutron.db import agents_db -from neutron.db import segments_db as db_ml2 -from neutron.extensions import multiprovidernet as mpnet -from neutron.extensions import providernet as provider -from neutron.plugins.ml2 import driver_api as api -from neutron.plugins.ml2 import plugin as ml2_plugin -from oslo_log import log as logging - -from networking_nec._i18n import _LE, _LI, _LW -from networking_nec.nwa.common import constants as nwa_const -from networking_nec.nwa.l2 import db_api as necnwa_api -from networking_nec.nwa.l2.rpc import ml2_server_callback -from networking_nec.nwa.l2.rpc import nwa_agent_api -from networking_nec.nwa.l2.rpc import nwa_l2_server_callback -from networking_nec.nwa.l2.rpc import nwa_proxy_api -from networking_nec.nwa.l2.rpc import tenant_binding_callback - -LOG = logging.getLogger(__name__) - - -class NECNWAL2Plugin(ml2_plugin.Ml2Plugin): - - def __init__(self): - super(NECNWAL2Plugin, self).__init__() - self._nwa_agent_rpc_setup() - - def _nwa_agent_rpc_setup(self): - self.nwa_rpc = nwa_agent_api.NECNWAAgentApi( - nwa_const.NWA_AGENT_TOPIC - ) - self.nwa_proxies = {} - - def start_rpc_listeners(self): - self.endpoints = [ - ml2_server_callback.NwaML2ServerRpcCallbacks( - self.notifier, self.type_manager), - nwa_l2_server_callback.NwaL2ServerRpcCallback(), - tenant_binding_callback.TenantBindingServerRpcCallback(), - securitygroups_rpc.SecurityGroupServerRpcCallback(), - dhcp_rpc.DhcpRpcCallback(), - agents_db.AgentExtRpcCallback(), - metadata_rpc.MetadataRpcCallback()] - - self.topic = topics.PLUGIN - self.conn = n_rpc.create_connection() - self.conn.create_consumer(self.topic, self.endpoints, - fanout=False) - return self.conn.consume_in_threads() - - def _extend_network_dict_provider(self, context, network): - if 'id' not in network: - LOG.debug("Network has no id") - network[provider.NETWORK_TYPE] = None - network[provider.PHYSICAL_NETWORK] = None - network[provider.SEGMENTATION_ID] = None - return - - net_id = network['id'] - segments = db_ml2.get_network_segments( - context.session, net_id, filter_dynamic=True) - - if not segments: - LOG.debug("Network %s has no segments", net_id) - network[provider.NETWORK_TYPE] = None - network[provider.PHYSICAL_NETWORK] = None - network[provider.SEGMENTATION_ID] = None - elif len(segments) > 1: - network[mpnet.SEGMENTS] = [ - {provider.NETWORK_TYPE: segment[api.NETWORK_TYPE], - provider.PHYSICAL_NETWORK: segment[api.PHYSICAL_NETWORK], - provider.SEGMENTATION_ID: segment[api.SEGMENTATION_ID]} - for segment in segments] - else: - segment = segments[0] - network[provider.NETWORK_TYPE] = segment[api.NETWORK_TYPE] - network[provider.PHYSICAL_NETWORK] = segment[api.PHYSICAL_NETWORK] - network[provider.SEGMENTATION_ID] = segment[api.SEGMENTATION_ID] - - # pylint: disable=redefined-builtin - def get_network(self, context, id, fields=None): - session = context.session - - with session.begin(subtransactions=True): - network = self._get_network(context, id) - result = self._make_network_dict(network, fields) - self._extend_network_dict_provider(context, result) - - return self._fields(result, fields) - - def get_networks(self, context, filters=None, fields=None, - sorts=None, limit=None, marker=None, page_reverse=False): - return super( - NECNWAL2Plugin, - self - ).get_networks(context, filters, None, sorts, - limit, marker, page_reverse) - - def _create_nwa_agent_tenant_queue(self, context, tenant_id): - if ( - self._is_alive_nwa_agent(context) and - necnwa_api.get_nwa_tenant_queue( - context.session, - tenant_id - ) is None - ): - self.nwa_rpc.create_server(context, tenant_id) - necnwa_api.add_nwa_tenant_queue(context.session, tenant_id) - else: - LOG.warning(_LW('%s is not alive.'), - nwa_const.NWA_AGENT_TYPE) - - def create_network(self, context, network): - result = super(NECNWAL2Plugin, - self).create_network(context, network) - self._create_nwa_agent_tenant_queue(context, context.tenant_id) - return result - - def delete_network(self, context, id): - result = super(NECNWAL2Plugin, - self).delete_network(context, id) - return result - - def create_port(self, context, port): - result = super(NECNWAL2Plugin, - self).create_port(context, port) - - return result - - def get_nwa_topics(self, context, tid): - rss = self.nwa_rpc.get_nwa_rpc_servers(context) - if isinstance(rss, dict) and rss.get('nwa_rpc_servers'): - return [t.get('topic') for t in rss['nwa_rpc_servers'] - if t.get('tenant_id') == tid] - else: - return [] - - def get_nwa_proxy(self, tid, context=None): - if tid not in self.nwa_proxies: - self.nwa_proxies[tid] = nwa_proxy_api.NECNWAProxyApi( - nwa_const.NWA_AGENT_TOPIC, tid - ) - if context: - self._create_nwa_agent_tenant_queue(context, tid) - nwa_topics = self.get_nwa_topics(context, tid) - if len(nwa_topics) == 1: - LOG.info(_LI('NWA tenant queue: new topic is %s'), - str(nwa_topics[0])) - else: - LOG.warning(_LW('NWA tenant queue is not created. tid=%s'), - tid) - LOG.debug('proxy tid=%s', tid) - return self.nwa_proxies[tid] - - def _is_alive_nwa_agent(self, context): - agents = self.get_agents( - context, - filters={'agent_type': [nwa_const.NWA_AGENT_TYPE]} - ) - return any(agent['alive'] for agent in agents) - - # This needs to be defined to avoid pylint abstract-method check. - def get_port_from_device(self, context, device): - LOG.error(_LE('This method should not be called. ' - 'get_ports_from_devices is used.')) diff --git a/networking_nec/nwa/l2/rpc/__init__.py b/networking_nec/nwa/l2/rpc/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/nwa/l2/rpc/ml2_server_callback.py b/networking_nec/nwa/l2/rpc/ml2_server_callback.py deleted file mode 100644 index b9a9056..0000000 --- a/networking_nec/nwa/l2/rpc/ml2_server_callback.py +++ /dev/null @@ -1,128 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_config import cfg - -from neutron.extensions import portbindings -from neutron.extensions import portsecurity as psec -from neutron.plugins.ml2 import driver_api as api -from neutron.plugins.ml2 import rpc -from neutron.services.qos import qos_consts -from neutron_lib import constants -from neutron_lib.plugins import directory -from oslo_log import log as logging - -from networking_nec._i18n import _LW, _LI - - -LOG = logging.getLogger(__name__) - - -class NwaML2ServerRpcCallbacks(rpc.RpcCallbacks): - - RPC_VERSION = '1.0' - - def __init__(self, notifier, type_manager, necnwa_router=True): - super(NwaML2ServerRpcCallbacks, self).__init__(notifier, type_manager) - self.necnwa_router = cfg.CONF.NWA.use_necnwa_router - - def get_device_details(self, rpc_context, **kwargs): - """Agent requests device details.""" - agent_id = kwargs.get('agent_id') - device = kwargs.get('device') - host = kwargs.get('host') - # cached networks used for reducing number of network db calls - # for server internal usage only - cached_networks = kwargs.get('cached_networks') - LOG.debug("Device %(device)s details requested by agent " - "%(agent_id)s with host %(host)s", - {'device': device, 'agent_id': agent_id, 'host': host}) - - plugin = directory.get_plugin() - port_id = plugin._device_to_port_id(rpc_context, device) - port_context = plugin.get_bound_port_context(rpc_context, - port_id, - host, - cached_networks) - if not port_context: - LOG.debug("Device %(device)s requested by agent " - "%(agent_id)s not found in database", - {'device': device, 'agent_id': agent_id}) - return {'device': device} - - segment = port_context.bottom_bound_segment - port = port_context.current - # caching information about networks for future use - if cached_networks is not None: - if port['network_id'] not in cached_networks: - cached_networks[port['network_id']] = ( - port_context.network.current) - - if not segment: - LOG.warning(_LW("Device %(device)s requested by agent " - "%(agent_id)s on network %(network_id)s not " - "bound, vif_type: %(vif_type)s"), - {'device': device, - 'agent_id': agent_id, - 'network_id': port['network_id'], - 'vif_type': port_context.vif_type}) - return {'device': device} - - if segment['segmentation_id'] == 0: - entry = {'device': device} - LOG.info(_LI('The segmentation_id is not yet finalized, ' - 'it is replaced to return %s'), entry) - return entry - - if not host or host == port_context.host: - new_status = (constants.PORT_STATUS_BUILD if port['admin_state_up'] - else constants.PORT_STATUS_DOWN) - if ( - port['status'] != new_status and - port['status'] != constants.PORT_STATUS_ACTIVE - ): - plugin.update_port_status(rpc_context, - port_id, - new_status, - host, - port_context.network.current) - - network_qos_policy_id = port_context.network._network.get( - qos_consts.QOS_POLICY_ID) - entry = {'device': device, - 'network_id': port['network_id'], - 'port_id': port['id'], - 'mac_address': port['mac_address'], - 'admin_state_up': port['admin_state_up'], - 'network_type': segment[api.NETWORK_TYPE], - 'segmentation_id': segment[api.SEGMENTATION_ID], - 'physical_network': segment[api.PHYSICAL_NETWORK], - 'fixed_ips': port['fixed_ips'], - 'device_owner': port['device_owner'], - 'allowed_address_pairs': port['allowed_address_pairs'], - 'port_security_enabled': port.get(psec.PORTSECURITY, True), - 'qos_policy_id': port.get(qos_consts.QOS_POLICY_ID), - 'network_qos_policy_id': network_qos_policy_id, - 'profile': port[portbindings.PROFILE]} - if 'security_groups' in port: - entry['security_groups'] = port['security_groups'] - LOG.debug("Returning: %s", entry) - return entry - - def update_device_up(self, rpc_context, **kwargs): - """Device is up on agent.""" - if self.necnwa_router: - return - super(NwaML2ServerRpcCallbacks, self).update_device_up(rpc_context, - **kwargs) diff --git a/networking_nec/nwa/l2/rpc/nwa_agent_api.py b/networking_nec/nwa/l2/rpc/nwa_agent_api.py deleted file mode 100644 index b8943bd..0000000 --- a/networking_nec/nwa/l2/rpc/nwa_agent_api.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -from neutron.common import rpc as n_rpc -import oslo_messaging - - -class NECNWAAgentApi(object): - BASE_RPC_API_VERSION = '1.0' - - def __init__(self, topic): - target = oslo_messaging.Target(topic=topic, - version=self.BASE_RPC_API_VERSION) - self.client = n_rpc.get_client(target) - - def create_server(self, context, tenant_id): - cctxt = self.client.prepare() - return cctxt.cast(context, 'create_server', tenant_id=tenant_id) - - def delete_server(self, context, tenant_id): - cctxt = self.client.prepare() - return cctxt.cast(context, 'delete_server', tenant_id=tenant_id) - - def get_nwa_rpc_servers(self, context): - cctxt = self.client.prepare() - return cctxt.call(context, 'get_nwa_rpc_servers') diff --git a/networking_nec/nwa/l2/rpc/nwa_agent_callback.py b/networking_nec/nwa/l2/rpc/nwa_agent_callback.py deleted file mode 100644 index b6c293c..0000000 --- a/networking_nec/nwa/l2/rpc/nwa_agent_callback.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_log import helpers -import oslo_messaging - - -class NwaAgentRpcCallback(object): - - target = oslo_messaging.Target(version='1.0') - - def __init__(self, context, agent): - self.context = context - self.agent = agent - - @helpers.log_method_call - def get_nwa_rpc_servers(self, context, **kwargs): - return {'nwa_rpc_servers': - [ - { - 'tenant_id': k, - 'topic': v['topic'] - } for k, v in self.agent.rpc_servers.items() - ]} - - @helpers.log_method_call - def create_server(self, context, **kwargs): - tenant_id = kwargs.get('tenant_id') - return self.agent.create_tenant_rpc_server(tenant_id) - - @helpers.log_method_call - def delete_server(self, context, **kwargs): - tenant_id = kwargs.get('tenant_id') - return self.agent.delete_tenant_rpc_server(tenant_id) diff --git a/networking_nec/nwa/l2/rpc/nwa_l2_server_api.py b/networking_nec/nwa/l2/rpc/nwa_l2_server_api.py deleted file mode 100644 index e54a06a..0000000 --- a/networking_nec/nwa/l2/rpc/nwa_l2_server_api.py +++ /dev/null @@ -1,89 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.common import rpc as n_rpc -from neutron.plugins.ml2 import driver_api as api -import oslo_messaging - - -class NwaL2ServerRpcApi(object): - - BASE_RPC_API_VERSION = '1.0' - - def __init__(self, topic): - target = oslo_messaging.Target(topic=topic, - version=self.BASE_RPC_API_VERSION) - self.client = n_rpc.get_client(target) - - def get_nwa_network_by_port_id(self, context, port_id): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'get_nwa_network_by_port_id', - port_id=port_id - ) - - def get_nwa_network_by_subnet_id(self, context, subnet_id): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'get_nwa_network_by_subnet_id', - subnet_id=subnet_id - ) - - def get_nwa_network(self, context, network_id): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'get_nwa_network', - network_id=network_id - ) - - def get_nwa_networks(self, context, tenant_id, nwa_tenant_id): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'get_nwa_networks', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id - ) - - def update_port_state_with_notifier(self, context, device, agent_id, - port_id, segment, network_id): - physical_network = segment[api.PHYSICAL_NETWORK] - network_type = segment[api.NETWORK_TYPE] - segmentation_id = segment[api.SEGMENTATION_ID] - - cctxt = self.client.prepare() - return cctxt.call( - context, - 'update_port_state_with_notifier', - device=device, - agent_id=agent_id, - port_id=port_id, - network_id=network_id, - network_type=network_type, - segmentation_id=segmentation_id, - physical_network=physical_network - ) - - def release_dynamic_segment_from_agent(self, context, physical_network, - network_id): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'release_dynamic_segment_from_agent', - network_id=network_id, - physical_network=physical_network - ) diff --git a/networking_nec/nwa/l2/rpc/nwa_l2_server_callback.py b/networking_nec/nwa/l2/rpc/nwa_l2_server_callback.py deleted file mode 100644 index db6a676..0000000 --- a/networking_nec/nwa/l2/rpc/nwa_l2_server_callback.py +++ /dev/null @@ -1,138 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.db import api as db_api -from neutron.db.models import segment as segments_db -from neutron.db import models_v2 -from neutron.db import segments_db as db_ml2 -from neutron_lib import constants -from neutron_lib.plugins import directory -from oslo_log import helpers -from oslo_log import log as logging -import oslo_messaging -from sqlalchemy.orm import exc as sa_exc - -from networking_nec._i18n import _LE - -LOG = logging.getLogger(__name__) - - -class NwaL2ServerRpcCallback(object): - - target = oslo_messaging.Target(version='1.0') - - def get_nwa_network_by_port_id(self, rpc_context, **kwargs): - plugin = directory.get_plugin() - port_id = kwargs.get('port_id') - port = plugin.get_port(rpc_context, port_id) - - network = plugin.get_network(rpc_context, port['network_id']) - - return network - - def get_nwa_network_by_subnet_id(self, rpc_context, **kwargs): - plugin = directory.get_plugin() - subnet_id = kwargs.get('subnet_id') - subnet = plugin.get_subnet(rpc_context, subnet_id) - - network = plugin.get_network(rpc_context, subnet['network_id']) - - return network - - def get_nwa_network(self, rpc_context, **kwargs): - plugin = directory.get_plugin() - net_id = kwargs.get('network_id') - network = plugin.get_network(rpc_context, net_id) - - return network - - def get_nwa_networks(self, rpc_context, **kwargs): - plugin = directory.get_plugin() - networks = plugin.get_networks(rpc_context) - - return networks - - @helpers.log_method_call - def update_port_state_with_notifier(self, rpc_context, **kwargs): - port_id = kwargs.get('port_id') - network_id = kwargs.get('network_id') - network_type = kwargs.get('network_type') - segmentation_id = kwargs.get('segmentation_id') - physical_network = kwargs.get('physical_network') - - # 1 update segment - session = db_api.get_session() - with session.begin(subtransactions=True): - try: - query = (session.query(segments_db.NetworkSegment). - filter_by(network_id=network_id)) - query = query.filter_by(physical_network=physical_network) - query = query.filter_by(is_dynamic=True) - record = query.one() - record.segmentation_id = segmentation_id - except sa_exc.NoResultFound: - pass - - # 2 change port state - plugin = directory.get_plugin() - plugin.update_port_status( - rpc_context, - port_id, - constants.PORT_STATUS_ACTIVE - ) - - # 3 serch db from port_id - session = db_api.get_session() - port = None - with session.begin(subtransactions=True): - try: - port_db = (session.query(models_v2.Port). - enable_eagerloads(False). - filter(models_v2.Port.id.startswith(port_id)). - one()) - port = plugin._make_port_dict(port_db) - except sa_exc.NoResultFound: - LOG.error(_LE("Can't find port with port_id %s"), - port_id) - except sa_exc.MultipleResultsFound: - LOG.error(_LE("Multiple ports have port_id starting with %s"), - port_id) - # 4 send notifier - if port is not None: - LOG.debug("notifier port_update %(net_type)s, %(seg_id)s, " - "%(physnet)s", - {'net_type': network_type, - 'seg_id': segmentation_id, - 'physnet': physical_network}) - plugin.notifier.port_update( - rpc_context, port, - network_type, - segmentation_id, - physical_network - ) - - return {} - - def release_dynamic_segment_from_agent(self, context, **kwargs): - network_id = kwargs.get('network_id') - physical_network = kwargs.get('physical_network') - - session = db_api.get_session() - del_segment = db_ml2.get_dynamic_segment( - session, network_id, physical_network=physical_network, - ) - if del_segment: - LOG.debug("release_dynamic_segment segment=%s", del_segment) - if del_segment['segmentation_id'] != 0: - db_ml2.delete_network_segment(session, del_segment['id']) diff --git a/networking_nec/nwa/l2/rpc/nwa_proxy_api.py b/networking_nec/nwa/l2/rpc/nwa_proxy_api.py deleted file mode 100644 index 6147758..0000000 --- a/networking_nec/nwa/l2/rpc/nwa_proxy_api.py +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -from neutron.common import rpc as n_rpc -import oslo_messaging - - -class NECNWAProxyApi(object): - BASE_RPC_API_VERSION = '1.0' - - def __init__(self, topic, tenant_id): - target = oslo_messaging.Target(topic='%s-%s' % (topic, tenant_id), - version=self.BASE_RPC_API_VERSION) - self._client = n_rpc.get_client(target) - - @property - def client(self): - return self._client - - def _send_msg(self, context, msg, blocking=False): - cctxt = self.client.prepare() - if blocking: - return cctxt.call(context, msg) - else: - return cctxt.cast(context, msg) - - def create_general_dev(self, context, tenant_id, nwa_tenant_id, nwa_info): - cctxt = self.client.prepare() - return cctxt.cast( - context, - 'create_general_dev', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info - ) - - def delete_general_dev(self, context, tenant_id, nwa_tenant_id, nwa_info): - cctxt = self.client.prepare() - return cctxt.cast( - context, - 'delete_general_dev', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info - ) diff --git a/networking_nec/nwa/l2/rpc/nwa_proxy_callback.py b/networking_nec/nwa/l2/rpc/nwa_proxy_callback.py deleted file mode 100644 index 0980396..0000000 --- a/networking_nec/nwa/l2/rpc/nwa_proxy_callback.py +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_log import log as logging -import oslo_messaging -from oslo_serialization import jsonutils - -LOG = logging.getLogger(__name__) - - -class NwaProxyCallback(object): - target = oslo_messaging.Target(version='1.0') - - def __init__(self, context, agent): - super(NwaProxyCallback, self).__init__() - self.context = context - self.agent = agent - - def create_general_dev(self, context, **kwargs): - LOG.debug("Rpc callback kwargs=%s", jsonutils.dumps( - kwargs, - indent=4, - sort_keys=True - )) - return self.agent.create_general_dev(context, **kwargs) - - def delete_general_dev(self, context, **kwargs): - LOG.debug("Rpc callback kwargs=%s", jsonutils.dumps( - kwargs, - indent=4, - sort_keys=True - )) - return self.agent.delete_general_dev(context, **kwargs) diff --git a/networking_nec/nwa/l2/rpc/tenant_binding_api.py b/networking_nec/nwa/l2/rpc/tenant_binding_api.py deleted file mode 100644 index 8b30755..0000000 --- a/networking_nec/nwa/l2/rpc/tenant_binding_api.py +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.common import rpc as n_rpc -import oslo_messaging - - -class TenantBindingServerRpcApi(object): - - BASE_RPC_API_VERSION = '1.0' - - def __init__(self, topic): - target = oslo_messaging.Target(topic=topic, - version=self.BASE_RPC_API_VERSION) - self.client = n_rpc.get_client(target) - - def get_nwa_tenant_binding(self, context, tenant_id, nwa_tenant_id): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'get_nwa_tenant_binding', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id - ) - - def add_nwa_tenant_binding(self, context, tenant_id, - nwa_tenant_id, nwa_data): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'add_nwa_tenant_binding', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_data=nwa_data - ) - - def set_nwa_tenant_binding(self, context, tenant_id, - nwa_tenant_id, nwa_data): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'set_nwa_tenant_binding', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_data=nwa_data - ) - - def delete_nwa_tenant_binding(self, context, tenant_id, - nwa_tenant_id): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'delete_nwa_tenant_binding', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id - ) - - def update_tenant_rpc_servers(self, context, rpc_servers): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'update_tenant_rpc_servers', - servers=rpc_servers - ) diff --git a/networking_nec/nwa/l2/rpc/tenant_binding_callback.py b/networking_nec/nwa/l2/rpc/tenant_binding_callback.py deleted file mode 100644 index 9d8e7a4..0000000 --- a/networking_nec/nwa/l2/rpc/tenant_binding_callback.py +++ /dev/null @@ -1,137 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.db import api as db_api -from neutron_lib.plugins import directory -from oslo_log import helpers -from oslo_log import log as logging -import oslo_messaging -from oslo_serialization import jsonutils - -from networking_nec._i18n import _LI -from networking_nec.nwa.l2 import db_api as necnwa_api - -LOG = logging.getLogger(__name__) - - -class TenantBindingServerRpcCallback(object): - - target = oslo_messaging.Target(version='1.0') - - @helpers.log_method_call - def get_nwa_tenant_binding(self, rpc_context, **kwargs): - """get nwa_tenant_binding from neutorn db. - - @param rpc_context: rpc context. - @param kwargs: tenant_id, nwa_tenant_id - @return: success = dict of nwa_tenant_binding, error = dict of empty. - """ - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - - session = db_api.get_session() - with session.begin(subtransactions=True): - recode = necnwa_api.get_nwa_tenant_binding( - session, tenant_id, nwa_tenant_id - ) - if recode is not None: - LOG.debug( - "nwa_data=%s", jsonutils.dumps( - recode.value_json, indent=4, sort_keys=True) - ) - return recode.value_json - - return {} - - @helpers.log_method_call - def add_nwa_tenant_binding(self, rpc_context, **kwargs): - """get nwa_tenant_binding from neutorn db. - - @param rpc_context: rpc context. - @param kwargs: tenant_id, nwa_tenant_id - @return: dict of status - """ - - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_data = kwargs.get('nwa_data') - - session = db_api.get_session() - with session.begin(subtransactions=True): - if necnwa_api.add_nwa_tenant_binding( - session, - tenant_id, - nwa_tenant_id, - nwa_data - ): - return {'status': 'SUCCESS'} - - return {'status': 'FAILED'} - - @helpers.log_method_call - def set_nwa_tenant_binding(self, rpc_context, **kwargs): - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - nwa_data = kwargs.get('nwa_data') - LOG.debug( - "nwa_data=%s", jsonutils.dumps(nwa_data, indent=4, sort_keys=True) - ) - - session = db_api.get_session() - with session.begin(subtransactions=True): - if necnwa_api.set_nwa_tenant_binding( - session, - tenant_id, - nwa_tenant_id, - nwa_data - ): - return {'status': 'SUCCESS'} - - return {'status': 'FAILED'} - - @helpers.log_method_call - def delete_nwa_tenant_binding(self, rpc_context, **kwargs): - tenant_id = kwargs.get('tenant_id') - nwa_tenant_id = kwargs.get('nwa_tenant_id') - - session = db_api.get_session() - with session.begin(subtransactions=True): - if necnwa_api.del_nwa_tenant_binding( - session, - tenant_id, - nwa_tenant_id - ): - return {'status': 'SUCCESS'} - - return {'status': 'FAILED'} - - def update_tenant_rpc_servers(self, rpc_context, **kwargs): - session = db_api.get_session() - - with session.begin(subtransactions=True): - q_tids = [q.tenant_id - for q in necnwa_api.get_nwa_tenant_queues(session)] - plugin = directory.get_plugin() - tenant_ids = [server['tenant_id'] for server in kwargs['servers']] - ret = [] - for tenant_id in set(q_tids) - set(tenant_ids): - LOG.info(_LI("RPCServer only db tid=%s, send create_server"), - tenant_id) - plugin.nwa_rpc.create_server(rpc_context, tenant_id) - ret.append({'tenant_id': tenant_id}) - for tenant_id in set(tenant_ids) - set(q_tids): - LOG.info(_LI("RPCServer only agent tid=%s, send delete_server"), - tenant_id) - plugin.nwa_rpc.delete_server(rpc_context, tenant_id) - return {'servers': ret} diff --git a/networking_nec/nwa/l2/utils.py b/networking_nec/nwa/l2/utils.py deleted file mode 100644 index 23b4526..0000000 --- a/networking_nec/nwa/l2/utils.py +++ /dev/null @@ -1,150 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.db.models import external_net as external_net_db -from neutron.db import segments_db as db_ml2 -from neutron.plugins.ml2 import driver_api as api -from neutron_lib import constants -from oslo_config import cfg -from oslo_log import log as logging -from sqlalchemy.orm import exc as sa_exc - -from networking_nec.nwa.common import utils as nwa_com_utils - -LOG = logging.getLogger(__name__) - - -def get_network_info(context): - name = context.network.current['name'] - network_id = context.network.current['id'] - return name, network_id - - -def get_physical_network(device_owner, resource_groups, - resource_group_name=None): - for physnet in resource_groups: - physnets = [physnet['physical_network'] for physnet in resource_groups - if (physnet['device_owner'] == device_owner and - (not resource_group_name or - physnet['ResourceGroupName'] == resource_group_name))] - if physnets: - return physnets[0] - return None - - -def is_external_network(context, net_id): - if hasattr(context, 'session'): - session = context.session - else: - session = context.network._plugin_context.session - try: - session.query( - external_net_db.ExternalNetwork).filter_by( - network_id=net_id - ).one() - return True - - except sa_exc.NoResultFound: - return False - - -def get_vlan_id_of_physical_network(context, network_id, physical_network): - if hasattr(context, 'session'): - session = context.session - else: - session = context.network._plugin_context.session - segments = db_ml2.get_network_segments(session, network_id) - if not segments: - return '' - for segment in segments: - if segment[api.PHYSICAL_NETWORK] == physical_network: - return str(segment[api.SEGMENTATION_ID]) - return str(segments[0][api.SEGMENTATION_ID]) - - -# pylint: disable=too-many-locals -def portcontext_to_nwa_info(context, resource_groups, - use_original_port=False): - tenant_id, nwa_tenant_id = nwa_com_utils.get_tenant_info(context) - network_name, network_id = get_network_info(context) - - port = context.original if use_original_port else context.current - device_owner = port['device_owner'] - resource_group_name = _get_resource_group_name(context, resource_groups, - use_original_port) - physical_network = get_physical_network(device_owner, resource_groups, - resource_group_name) - vlan_id = get_vlan_id_of_physical_network(context, network_id, - physical_network) - vlan_type = 'PublicVLAN' if is_external_network(context, network_id) \ - else 'BusinessVLAN' - - dbcontext = context._plugin_context - - nwa_info = { - 'tenant_id': tenant_id, - 'nwa_tenant_id': nwa_tenant_id, - 'network': {'id': network_id, - 'name': network_name, - 'vlan_id': vlan_id, - 'vlan_type': vlan_type}, - 'device': {'owner': device_owner, - 'id': port['device_id']}, - } - - if port['fixed_ips']: - subnet_id = port['fixed_ips'][0]['subnet_id'] - subnet = context._plugin.get_subnet(dbcontext, subnet_id) - nwa_info['subnet'] = {'id': subnet_id, - 'netaddr': subnet['cidr'].split('/')[0], - 'mask': subnet['cidr'].split('/')[1]} - nwa_info['port'] = {'id': port['id'], - 'ip': port['fixed_ips'][0]['ip_address'], - 'mac': port['mac_address']} - else: - nwa_info['subnet'] = {'id': '', - 'netaddr': '', - 'mask': ''} - nwa_info['port'] = {'id': port['id'], - 'ip': '', - 'mac': port['mac_address']} - - nwa_info['resource_group_name'] = resource_group_name - nwa_info['resource_group_name_nw'] = cfg.CONF.NWA.resource_group_name - nwa_info['physical_network'] = physical_network - return nwa_info - - -# Private methods - -def _get_resource_group_name(context, resource_groups, - use_original_port=False): - port = context.original if use_original_port else context.current - device_owner = port['device_owner'] - for agent in context.host_agents(constants.AGENT_TYPE_OVS): - if agent['alive']: - mappings = agent['configurations'].get('bridge_mappings', {}) - for res_grp in resource_groups: - if not res_grp['ResourceGroupName'] in mappings: - continue - if res_grp['device_owner'] == device_owner: - return res_grp['ResourceGroupName'] - - if (device_owner == constants.DEVICE_OWNER_ROUTER_INTF or - device_owner == constants.DEVICE_OWNER_ROUTER_GW): - for res_grp in resource_groups: - if res_grp['device_owner'] == device_owner: - return res_grp['ResourceGroupName'] - - return None diff --git a/networking_nec/nwa/l3/__init__.py b/networking_nec/nwa/l3/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/nwa/l3/db_api.py b/networking_nec/nwa/l3/db_api.py deleted file mode 100644 index 815db13..0000000 --- a/networking_nec/nwa/l3/db_api.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from sqlalchemy.orm import exc as sa_exc - -from neutron.db.models import l3 as l3_db -from oslo_log import log as logging - -LOG = logging.getLogger(__name__) - - -def get_tenant_id_by_router(session, router_id): - with session.begin(subtransactions=True): - try: - router = session.query(l3_db.Router).filter_by(id=router_id).one() - rt_tid = router.tenant_id - LOG.debug("rt_tid=%s", rt_tid) - return rt_tid - except sa_exc.NoResultFound: - LOG.debug("router not found %s", router_id) diff --git a/networking_nec/nwa/l3/plugin.py b/networking_nec/nwa/l3/plugin.py deleted file mode 100644 index 10f92da..0000000 --- a/networking_nec/nwa/l3/plugin.py +++ /dev/null @@ -1,229 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import sqlalchemy as sa -from sqlalchemy import or_ - -from neutron.api.rpc.agentnotifiers import l3_rpc_agent_api -from neutron.api.rpc.handlers import l3_rpc -from neutron.common import rpc as n_rpc -from neutron.common import topics -from neutron.db import common_db_mixin -from neutron.db import extraroute_db -from neutron.db import l3_agentschedulers_db -from neutron.db import l3_gwmode_db -from neutron.db.models import l3 as l3_db -from neutron.plugins.common import constants -from neutron.plugins.ml2 import driver_context -from neutron.services import service_base -from neutron_lib import constants as n_const -from neutron_lib import exceptions as exc -from oslo_config import cfg -from oslo_log import helpers -from oslo_log import log as logging - -from networking_nec._i18n import _LI, _LW, _LE -from networking_nec.nwa.common import utils as nwa_com_utils -from networking_nec.nwa.l2 import db_api as nwa_db -from networking_nec.nwa.l2 import utils as nwa_l2_utils -from networking_nec.nwa.l3 import db_api as nwa_l3_db -from networking_nec.nwa.l3.rpc import nwa_l3_proxy_api -from networking_nec.nwa.l3.rpc import nwa_l3_server_callback - -LOG = logging.getLogger(__name__) - - -class NECNWAL3Plugin(service_base.ServicePluginBase, - common_db_mixin.CommonDbMixin, - extraroute_db.ExtraRoute_db_mixin, - l3_gwmode_db.L3_NAT_db_mixin, - l3_agentschedulers_db.L3AgentSchedulerDbMixin): - - supported_extension_aliases = ["router", "ext-gw-mode", - "extraroute"] - - def __init__(self): - super(NECNWAL3Plugin, self).__init__() - # l3_db.subscribe() - self.start_rpc_listeners() - self.nwa_proxies = {} - self.resource_groups = nwa_com_utils.load_json_from_file( - 'resource_group', cfg.CONF.NWA.resource_group_file, - cfg.CONF.NWA.resource_group, default_value=[]) - - @helpers.log_method_call - def start_rpc_listeners(self): - # RPC support - self.topic = topics.L3PLUGIN - self.conn = n_rpc.create_connection() - self.agent_notifiers.update( - {n_const.AGENT_TYPE_L3: l3_rpc_agent_api.L3AgentNotifyAPI()}) - self.endpoints = [l3_rpc.L3RpcCallback(), - nwa_l3_server_callback.NwaL3ServerRpcCallback()] - self.conn.create_consumer(self.topic, self.endpoints, - fanout=False) - return self.conn.consume_in_threads() - - def get_plugin_type(self): - return constants.L3_ROUTER_NAT - - def get_plugin_description(self): - """Returns string description of the plugin.""" - return "NEC NWA Plugin based routing" - - @helpers.log_method_call - def create_floatingip(self, context, floatingip, - initial_status=n_const.FLOATINGIP_STATUS_DOWN): - return super(NECNWAL3Plugin, self).create_floatingip( - context, floatingip, initial_status) - - def _delete_nat(self, context, fip): - if not fip['router_id'] or not fip['fixed_ip_address']: - LOG.debug('already deleted %s', fip) - return - tenant_id = nwa_l3_db.get_tenant_id_by_router( - context.session, fip['router_id'] - ) - nwa_tenant_id = nwa_com_utils.get_nwa_tenant_id(tenant_id) - - fl_data = { - 'floating_ip_address': fip['floating_ip_address'], - 'fixed_ip_address': fip['fixed_ip_address'], - 'id': fip['id'], - 'device_id': fip['router_id'], - 'floating_network_id': fip['floating_network_id'], - 'tenant_id': fip['tenant_id'] - } - LOG.info(_LI('delete_nat fl_data=%s'), fl_data) - - proxy = self._get_nwa_proxy(self, tenant_id) - proxy.delete_nat( - context, tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - floating=fl_data - ) - - # pylint: disable=arguments-differ - @helpers.log_method_call - def disassociate_floatingips(self, context, port_id, do_notify=True): - floating_ips = context.session.query(l3_db.FloatingIP).filter( - or_(l3_db.FloatingIP.fixed_port_id == port_id, - l3_db.FloatingIP.floating_port_id == port_id) - ) - if not floating_ips: - LOG.warning(_LW('floatingip not found %s'), port_id) - for fip in floating_ips: - self._delete_nat(context, fip) - router_ids = super(NECNWAL3Plugin, self).disassociate_floatingips( - context, port_id, do_notify) - return router_ids - - @helpers.log_method_call - def update_floatingip(self, context, fpid, floatingip): - port_id_specified = 'port_id' in floatingip['floatingip'] - if not port_id_specified: - LOG.error(_LE("port_id key is not found in %s"), floatingip) - raise exc.PortNotFound(port_id=None) - - port_id = floatingip['floatingip'].get('port_id') - try: - if port_id_specified and not port_id: - floating = context.session.query(l3_db.FloatingIP).filter_by( - id=fpid).one() - self._delete_nat(context, floating) - except sa.orm.exc.NoResultFound: - raise exc.PortNotFound(port_id=port_id) - - ret = super(NECNWAL3Plugin, self).update_floatingip( - context, fpid, floatingip) - - try: - if port_id_specified and port_id: - floating = context.session.query(l3_db.FloatingIP).filter_by( - id=fpid).one() - tenant_id = nwa_l3_db.get_tenant_id_by_router( - context.session, - floating['router_id'] - ) - nwa_tenant_id = nwa_com_utils.get_nwa_tenant_id(tenant_id) - - fl_data = { - 'floating_ip_address': floating['floating_ip_address'], - 'fixed_ip_address': floating['fixed_ip_address'], - 'id': fpid, 'device_id': floating['router_id'], - 'floating_network_id': floating['floating_network_id'], - 'tenant_id': floating['tenant_id'], - 'floating_port_id': floating['floating_port_id'] - } - LOG.info(_LI('setting_nat fl_data is %s'), fl_data) - proxy = self._get_nwa_proxy(self, tenant_id) - proxy.setting_nat( - context, tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - floating=fl_data - ) - - except sa.orm.exc.NoResultFound: - raise exc.PortNotFound(port_id=port_id) - - return ret - - def add_router_interface(self, context, router_id, interface_info): - ret = super(NECNWAL3Plugin, self).add_router_interface( - context, - router_id, - interface_info - ) - if 'port_id' in interface_info: - self._add_router_interface_by_port( - self, context, router_id, interface_info - ) - return ret - - def _add_router_interface_by_port(self, plugin, context, router_id, - interface_info): - try: - session = context.session - port = plugin._core_plugin._get_port(context, - interface_info['port_id']) - network = plugin._core_plugin.get_network(context, - port['network_id']) - - binding = nwa_db.ensure_port_binding(session, port['id']) - port_context = driver_context.PortContext(plugin._core_plugin, - context, port, - network, binding, None) - - nwa_info = nwa_l2_utils.portcontext_to_nwa_info( - port_context, self.resource_groups) - rt_tid = nwa_l3_db.get_tenant_id_by_router( - session, router_id - ) - nwa_rt_tid = nwa_com_utils.get_nwa_tenant_id(rt_tid) - nwa_info['tenant_id'] = rt_tid - nwa_info['nwa_tenant_id'] = nwa_rt_tid - proxy = self._get_nwa_proxy(plugin, rt_tid) - proxy.create_tenant_fw( - port_context.network._plugin_context, - rt_tid, - nwa_rt_tid, - nwa_info - ) - - except Exception as e: - LOG.exception(_LE("create tenant firewall %s"), e) - - def _get_nwa_proxy(self, plugin, tenant_id): - proxy = plugin._core_plugin.get_nwa_proxy(tenant_id) - return nwa_l3_proxy_api.NwaL3ProxyApi(proxy.client) diff --git a/networking_nec/nwa/l3/rpc/__init__.py b/networking_nec/nwa/l3/rpc/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/nwa/l3/rpc/nwa_l3_proxy_api.py b/networking_nec/nwa/l3/rpc/nwa_l3_proxy_api.py deleted file mode 100644 index 9939fac..0000000 --- a/networking_nec/nwa/l3/rpc/nwa_l3_proxy_api.py +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_log import log as logging - -LOG = logging.getLogger(__name__) - - -class NwaL3ProxyApi(object): - - def __init__(self, client): - self.client = client - - def create_tenant_fw(self, context, tenant_id, nwa_tenant_id, nwa_info): - cctxt = self.client.prepare() - return cctxt.cast( - context, - 'create_tenant_fw', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info - ) - - def delete_tenant_fw(self, context, tenant_id, nwa_tenant_id, nwa_info): - cctxt = self.client.prepare() - return cctxt.cast( - context, - 'delete_tenant_fw', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info - ) - - def setting_nat(self, context, tenant_id, nwa_tenant_id, floating): - cctxt = self.client.prepare() - return cctxt.cast( - context, - 'setting_nat', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - floating=floating - ) - - def delete_nat(self, context, tenant_id, nwa_tenant_id, floating): - cctxt = self.client.prepare() - return cctxt.cast( - context, - 'delete_nat', - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - floating=floating - ) diff --git a/networking_nec/nwa/l3/rpc/nwa_l3_proxy_callback.py b/networking_nec/nwa/l3/rpc/nwa_l3_proxy_callback.py deleted file mode 100644 index c1b19fd..0000000 --- a/networking_nec/nwa/l3/rpc/nwa_l3_proxy_callback.py +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_log import helpers -from oslo_log import log as logging -import oslo_messaging - -LOG = logging.getLogger(__name__) - - -class NwaL3ProxyCallback(object): - - target = oslo_messaging.Target(version='1.0') - - def __init__(self, context, agent): - self.context = context - self.agent = agent - - @helpers.log_method_call - def create_tenant_fw(self, context, **kwargs): - return self.agent.create_tenant_fw(context, **kwargs) - - @helpers.log_method_call - def delete_tenant_fw(self, context, **kwargs): - return self.agent.delete_tenant_fw(context, **kwargs) - - @helpers.log_method_call - def setting_nat(self, context, **kwargs): - return self.agent.setting_nat(context, **kwargs) - - @helpers.log_method_call - def delete_nat(self, context, **kwargs): - return self.agent.delete_nat(context, **kwargs) diff --git a/networking_nec/nwa/l3/rpc/nwa_l3_server_api.py b/networking_nec/nwa/l3/rpc/nwa_l3_server_api.py deleted file mode 100644 index 70636c1..0000000 --- a/networking_nec/nwa/l3/rpc/nwa_l3_server_api.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.common import rpc as n_rpc -from oslo_log import log as logging -import oslo_messaging - -LOG = logging.getLogger(__name__) - - -class NwaL3ServerRpcApi(object): - - BASE_RPC_API_VERSION = '1.0' - - def __init__(self, topic): - target = oslo_messaging.Target(topic=topic, - version=self.BASE_RPC_API_VERSION) - self.client = n_rpc.get_client(target) - - def update_floatingip_status(self, context, floatingip_id, status): - cctxt = self.client.prepare() - return cctxt.call( - context, - 'update_floatingip_status', - floatingip_id=floatingip_id, - status=status - ) diff --git a/networking_nec/nwa/l3/rpc/nwa_l3_server_callback.py b/networking_nec/nwa/l3/rpc/nwa_l3_server_callback.py deleted file mode 100644 index 9337c18..0000000 --- a/networking_nec/nwa/l3/rpc/nwa_l3_server_callback.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.extensions import l3 -from neutron_lib import constants -from neutron_lib.plugins import directory -from oslo_log import log as logging -import oslo_messaging - -LOG = logging.getLogger(__name__) - - -class NwaL3ServerRpcCallback(object): - - target = oslo_messaging.Target(version='1.0') - - @property - def l3plugin(self): - if not hasattr(self, '_l3plugin'): - self._l3plugin = directory.get_plugin(constants.L3) - return self._l3plugin - - def update_floatingip_status(self, context, floatingip_id, status): - '''Update operational status for a floating IP.''' - with context.session.begin(subtransactions=True): - LOG.debug('New status for floating IP %s: %s' % - (floatingip_id, status)) - try: - self.l3plugin.update_floatingip_status(context, - floatingip_id, - status) - except l3.FloatingIPNotFound: - LOG.debug("Floating IP: %s no longer present.", - floatingip_id) diff --git a/networking_nec/nwa/nwalib/__init__.py b/networking_nec/nwa/nwalib/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/nwa/nwalib/client.py b/networking_nec/nwa/nwalib/client.py deleted file mode 100644 index 08eb6bf..0000000 --- a/networking_nec/nwa/nwalib/client.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from networking_nec.nwa.nwalib import client_fwaas -from networking_nec.nwa.nwalib import client_l2 -from networking_nec.nwa.nwalib import client_l3 -from networking_nec.nwa.nwalib import client_lbaas -from networking_nec.nwa.nwalib import client_tenant -from networking_nec.nwa.nwalib import nwa_restclient - - -class NwaClient(nwa_restclient.NwaRestClient): - '''Client class of NWA. ''' - - def __init__(self, *args, **kwargs): - super(NwaClient, self).__init__(*args, **kwargs) - - self.tenant = client_tenant.NwaClientTenant(self) - self.l2 = client_l2.NwaClientL2(self) - self.l3 = client_l3.NwaClientL3(self) - self.fwaas = client_fwaas.NwaClientFWaaS(self) - self.lbaas = client_lbaas.NwaClientLBaaS(self) diff --git a/networking_nec/nwa/nwalib/client_fwaas.py b/networking_nec/nwa/nwalib/client_fwaas.py deleted file mode 100644 index 62fc3e0..0000000 --- a/networking_nec/nwa/nwalib/client_fwaas.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from debtcollector import removals - - -class NwaClientFWaaS(object): - - def __init__(self, client): - self.client = client - - @removals.remove( - message='It is no longer async. Use setting_fw_policy instead.') - def setting_fw_policy_async(self, tenant_id, fw_name, props): - return self.setting_fw_policy(tenant_id, fw_name, props) - - def setting_fw_policy(self, tenant_id, fw_name, props): - body = { - 'TenantID': tenant_id, - 'DCResourceType': 'TFW_Policy', - 'DCResourceOperation': 'Setting', - 'DeviceInfo': { - 'Type': 'TFW', - 'DeviceName': fw_name, - }, - 'Property': props - } - return self.client.call_workflow( - tenant_id, self.client.post, 'SettingFWPolicy', body) diff --git a/networking_nec/nwa/nwalib/client_l2.py b/networking_nec/nwa/nwalib/client_l2.py deleted file mode 100644 index 235a7e7..0000000 --- a/networking_nec/nwa/nwalib/client_l2.py +++ /dev/null @@ -1,148 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_log import log as logging - -from networking_nec._i18n import _LW - - -LOG = logging.getLogger(__name__) - - -class NwaClientL2(object): - - def __init__(self, client): - self.client = client - - # --- Tenant Network --- - - def create_tenant_nw(self, tenant_id, dc_resource_group_name): - body = { - "TenantID": tenant_id, - "CreateNW_DCResourceGroupName": dc_resource_group_name, - 'CreateNW_OperationType': 'CreateTenantNW' - } - return self.client.call_workflow( - tenant_id, self.client.post, 'CreateTenantNW', body - ) - - def delete_tenant_nw(self, tenant_id): - body = { - "TenantID": tenant_id, - } - return self.client.call_workflow( - tenant_id, self.client.post, 'DeleteTenantNW', body - ) - - # --- VLan --- - - def create_vlan(self, tenant_id, ipaddr, mask, - vlan_type='BusinessVLAN', openstack_network_id=None): - body = { - 'TenantID': tenant_id, - 'CreateNW_VlanType1': vlan_type, - 'CreateNW_IPSubnetAddress1': ipaddr, - 'CreateNW_IPSubnetMask1': mask - } - if openstack_network_id: - body['CreateNW_VlanLogicalID1'] = openstack_network_id - return self.client.call_workflow( - tenant_id, self.client.post, 'CreateVLAN', body - ) - - def delete_vlan(self, tenant_id, logical_name, vlan_type='BusinessVLAN'): - body = { - 'TenantID': tenant_id, - 'DeleteNW_VlanLogicalName1': logical_name, - 'DeleteNW_VlanType1': vlan_type - } - return self.client.call_workflow( - tenant_id, self.client.post, 'DeleteVLAN', body - ) - - # --- General Dev --- - - def create_general_dev(self, tenant_id, dc_resource_group_name, - logical_name, vlan_type='BusinessVLAN', - port_type=None, openstack_network_id=None): - body = { - 'CreateNW_DeviceType1': 'GeneralDev', - 'TenantID': tenant_id, - 'CreateNW_VlanLogicalName1': logical_name, - 'CreateNW_VlanType1': vlan_type, - 'CreateNW_DCResourceGroupName': dc_resource_group_name - } - if logical_name and openstack_network_id: - LOG.warning(_LW('VLAN logical name and id to be specified ' - 'in the exclusive.')) - if openstack_network_id: - body['CreateNW_VlanLogicalID1'] = openstack_network_id - if port_type: - body['CreateNW_PortType1'] = port_type - return self.client.call_workflow( - tenant_id, self.client.post, 'CreateGeneralDev', body - ) - - def delete_general_dev(self, tenant_id, dc_resource_group_name, - logical_name, vlan_type='BusinessVLAN', - port_type=None, openstack_network_id=None): - body = { - 'DeleteNW_DeviceType1': 'GeneralDev', - 'TenantID': tenant_id, - 'DeleteNW_VlanLogicalName1': logical_name, - 'DeleteNW_VlanType1': vlan_type, - 'DeleteNW_DCResourceGroupName': dc_resource_group_name - } - if logical_name and openstack_network_id: - LOG.warning(_LW('VLAN logical name and id to be specified ' - 'in the exclusive.')) - if openstack_network_id: - body['DeleteNW_VlanLogicalID1'] = openstack_network_id - if port_type: - body['DeleteNW_PortType1'] = port_type - return self.client.call_workflow( - tenant_id, self.client.post, 'DeleteGeneralDev', body - ) - - # --- Connect Port --- - - def create_connect_port(self, tenant_id, dc_resource_group_name, - logical_name, vlan_type, vlan_id): - body = { - 'CreateNW_DCResourceGroupName': dc_resource_group_name, - 'CreateNW_DeviceType1': 'GeneralDev', - 'CreateNW_OperationType': 'CreateConnectPort', - 'CreateNW_VlanID1': vlan_id, - 'CreateNW_VlanLogicalName1': logical_name, - 'CreateNW_VlanType1': vlan_type, - 'TenantID': tenant_id, - } - return self.client.call_workflow( - tenant_id, self.client.post, 'CreateConnectPort', body - ) - - def delete_connect_port(self, tenant_id, dc_resource_group_name, - logical_name, vlan_type, vlan_id): - body = { - 'DeleteNW_DCResourceGroupName': dc_resource_group_name, - 'DeleteNW_DeviceType1': 'GeneralDev', - 'DeleteNW_OperationType': 'DeleteConnectPort', - 'DeleteNW_VlanID1': vlan_id, - 'DeleteNW_VlanLogicalName1': logical_name, - 'DeleteNW_VlanType1': vlan_type, - 'TenantID': tenant_id, - } - return self.client.call_workflow( - tenant_id, self.client.post, 'DeleteConnectPort', body - ) diff --git a/networking_nec/nwa/nwalib/client_l3.py b/networking_nec/nwa/nwalib/client_l3.py deleted file mode 100644 index 4e3a3b9..0000000 --- a/networking_nec/nwa/nwalib/client_l3.py +++ /dev/null @@ -1,117 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_log import log as logging - -from networking_nec._i18n import _LE - - -LOG = logging.getLogger(__name__) - - -class NwaClientL3(object): - - def __init__(self, client): - self.client = client - - # --- Tenant FW --- - - def create_tenant_fw(self, tenant_id, dc_resource_group_name, - vlan_devaddr, vlan_logical_name, - vlan_type='BusinessVLAN', router_id=None): - body = { - 'CreateNW_DeviceType1': 'TFW', - 'TenantID': tenant_id, - 'CreateNW_Vlan_DeviceAddress1': vlan_devaddr, - 'CreateNW_VlanLogicalName1': vlan_logical_name, - 'CreateNW_VlanType1': vlan_type, - 'CreateNW_DCResourceGroupName': dc_resource_group_name - } - return self.client.call_workflow( - tenant_id, self.client.post, 'CreateTenantFW', body) - - def update_tenant_fw(self, tenant_id, device_name, vlan_devaddr, - vlan_logical_name, vlan_type, - connect=None, router_id=None): - body = { - 'ReconfigNW_DeviceName1': device_name, - 'ReconfigNW_DeviceType1': 'TFW', - 'ReconfigNW_Vlan_DeviceAddress1': vlan_devaddr, - 'ReconfigNW_VlanLogicalName1': vlan_logical_name, - 'ReconfigNW_VlanType1': vlan_type, - 'TenantID': tenant_id - } - if connect: - body['ReconfigNW_Vlan_ConnectDevice1'] = connect - - return self.client.call_workflow( - tenant_id, self.client.post, 'UpdateTenantFW', body) - - def delete_tenant_fw(self, tenant_id, device_name, device_type, - router_id=None): - body = { - 'DeleteNW_DeviceName1': device_name, - 'DeleteNW_DeviceType1': device_type, - 'TenantID': tenant_id - } - return self.client.call_workflow( - tenant_id, self.client.post, 'DeleteTenantFW', body) - - # --- Nat --- - - def setting_nat(self, tenant_id, vlan_logical_name, vlan_type, - local_ip, global_ip, dev_name, data=None, router_id=None): - body = { - 'ReconfigNW_DeviceName1': dev_name, - 'ReconfigNW_DeviceType1': 'TFW', - 'ReconfigNW_VlanLogicalName1': vlan_logical_name, - 'ReconfigNW_VlanType1': vlan_type, - 'LocalIP': local_ip, - 'GlobalIP': global_ip, - 'TenantID': tenant_id, - } - return self.client.call_workflow( - tenant_id, self.client.post, 'SettingNAT', body) - - def delete_nat(self, tenant_id, vlan_logical_name, vlan_type, - local_ip, global_ip, dev_name, data=None, router_id=None): - body = { - 'DeleteNW_DeviceName1': dev_name, - 'DeleteNW_DeviceType1': 'TFW', - 'DeleteNW_VlanLogicalName1': vlan_logical_name, - 'DeleteNW_VlanType1': vlan_type, - 'LocalIP': local_ip, - 'GlobalIP': global_ip, - 'TenantID': tenant_id, - } - return self.client.call_workflow( - tenant_id, self.client.post, 'DeleteNAT', body) - - def update_nat(self, tenant_id, vlan_logical_name, vlan_type, - local_ip, global_ip, dev_name, data=None, router_id=None): - try: - http_status, rj = self.delete_nat(tenant_id, - vlan_logical_name, vlan_type, - local_ip, global_ip, dev_name, - data=data) - except Exception as e: - LOG.exception(_LE('%s'), e) - http_status = -1 - rj = None - - self.setting_nat(tenant_id, vlan_logical_name, vlan_type, - local_ip, global_ip, dev_name, - data=data, router_id=router_id) - - return http_status, rj diff --git a/networking_nec/nwa/nwalib/client_lbaas.py b/networking_nec/nwa/nwalib/client_lbaas.py deleted file mode 100644 index 7a24794..0000000 --- a/networking_nec/nwa/nwalib/client_lbaas.py +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import re - - -class NwaClientLBaaS(object): - - def __init__(self, client): - self.client = client - - def create_tenant_lb(self, tenant_id, - dc_resource_group_name, - vlan_logical_name, vlan_type, vif_ipaddr): - body = { - 'CreateNW_DeviceType1': 'LB', - 'TenantID': tenant_id, - 'CreateNW_Vlan_DeviceAddress1': vif_ipaddr, - 'CreateNW_VlanLogicalName1': vlan_logical_name, - 'CreateNW_VlanType1': vlan_type, - 'CreateNW_DCResourceGroupName': dc_resource_group_name - } - return self.client.call_workflow( - tenant_id, self.client.post, 'CreateTenantLB', body) - - def delete_tenant_lb(self, tenant_id, device_name): - body = { - 'DeleteNW_DeviceName1': device_name, - 'DeleteNW_DeviceType1': 'LB', - 'TenantID': tenant_id, - } - return self.client.call_workflow( - tenant_id, self.client.post, 'DeleteTenantLB', body) - - def update_tenant_lbn(self, tenant_id, - device_name, actions): - body = { - 'ReconfigNW_DeviceName1': device_name, - 'ReconfigNW_DeviceType1': 'LB', - 'TenantID': tenant_id - } - for n, a in enumerate(actions): - i = str(n + 1) - if a[0] is not None: - body['ReconfigNW_Vlan_ConnectDevice' + i] = a[0] - lwn = a[1] - body['ReconfigNW_VlanLogicalName' + i] = lwn - if len(a) > 2: - body['ReconfigNW_Vlan_DeviceAddress' + i] = a[2] - if len(a) > 3: - body['ReconfigNW_VlanType' + i] = a[3] - else: - if re.search(lwn, '_PublicVLAN_'): - body['ReconfigNW_VlanType' + i] = 'PublicVLAN' - else: - body['ReconfigNW_VlanType' + i] = 'BusinessVLAN' - - return self.client.call_workflow( - tenant_id, self.client.post, 'UpdateTenantLB', body) - - def setting_lb_policy(self, tenant_id, lb_name, props): - body = { - 'TenantID': tenant_id, - 'DCResourceType': 'LB_Policy', - 'DCResourceOperation': 'Setting', - 'DeviceInfo': { - 'Type': 'LB', - 'DeviceName': lb_name, - }, - 'Property': props - } - return self.client.call_workflow( - tenant_id, self.client.post, 'SettingLBPolicy', body) diff --git a/networking_nec/nwa/nwalib/client_tenant.py b/networking_nec/nwa/nwalib/client_tenant.py deleted file mode 100644 index 1dcca36..0000000 --- a/networking_nec/nwa/nwalib/client_tenant.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from networking_nec.nwa.nwalib import semaphore as nwa_sem - - -class NwaClientTenant(object): - - def __init__(self, client): - self.client = client - - def create_tenant(self, tenant_id): - body = { - 'TenantName': tenant_id, - } - return self.client.post('/umf/tenant/' + tenant_id, body) - - def delete_tenant(self, tenant_id): - status_code, data = self.client.delete('/umf/tenant/' + tenant_id) - if status_code == 200: - nwa_sem.Semaphore.delete_tenant_semaphore(tenant_id) - return status_code, data diff --git a/networking_nec/nwa/nwalib/data_utils.py b/networking_nec/nwa/nwalib/data_utils.py deleted file mode 100644 index 60a84e2..0000000 --- a/networking_nec/nwa/nwalib/data_utils.py +++ /dev/null @@ -1,189 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from networking_nec.nwa.common import constants as nwa_const - -VLAN_OWN_GDV = 'GD' -VLAN_OWN_TFW = 'TFW' - -NWA_DEVICE_MAP = { - nwa_const.NWA_DEVICE_GDV: VLAN_OWN_GDV, - nwa_const.NWA_DEVICE_TFW: VLAN_OWN_TFW, -} - - -def get_network_key(network_id): - return 'NW_' + network_id - - -def get_vlan_key(network_id): - return 'VLAN_' + network_id - - -def get_device_key(device_id): - return 'DEV_' + device_id - - -def get_tfw_device_name(nwa_data, device_id): - return nwa_data['DEV_' + device_id + '_TenantFWName'] - - -def get_device_net_key(device_id, network_id): - return 'DEV_%s_%s' % (device_id, network_id) - - -def get_vlan_logical_name(nwa_data, network_id): - return nwa_data['NW_' + network_id + '_nwa_network_name'] - - -def get_vlan_id(network_id, nwa_data, resultdata): - vlan_key = 'VLAN_' + network_id - if nwa_data[vlan_key + '_CreateVlan'] == '': - return resultdata['VlanID'] - else: - return nwa_data[vlan_key + '_VlanID'] - - -def get_vp_net_vlan_id(nwa_data, network_id, resource_group_name_nw, - device_type): - seg_key = 'VLAN_%s_%s_%s' % (network_id, resource_group_name_nw, - NWA_DEVICE_MAP[device_type]) - return int(nwa_data[seg_key + '_VlanID'], 10) - - -def set_network_data(nwa_data, network_id, nwa_info, logical_name): - nw_net = 'NW_' + network_id - nwa_data[nw_net] = nwa_info['network']['name'] - nwa_data[nw_net + '_network_id'] = network_id - nwa_data[nw_net + '_subnet_id'] = nwa_info['subnet']['id'] - nwa_data[nw_net + '_subnet'] = nwa_info['subnet']['netaddr'] - nwa_data[nw_net + '_nwa_network_name'] = logical_name - - -def strip_network_data(nwa_data, network_id): - nw_net = 'NW_' + network_id - nwa_data.pop(nw_net) - nwa_data.pop(nw_net + '_network_id') - nwa_data.pop(nw_net + '_subnet_id') - nwa_data.pop(nw_net + '_subnet') - nwa_data.pop(nw_net + '_nwa_network_name') - - -def set_vlan_data(nwa_data, network_id, vlan_id): - vp_net = 'VLAN_' + network_id - nwa_data[vp_net] = 'physical_network' - nwa_data[vp_net + '_VlanID'] = vlan_id - nwa_data[vp_net + '_CreateVlan'] = '' - - -def strip_vlan_data(nwa_data, network_id): - vp_net = 'VLAN_' + network_id - nwa_data.pop(vp_net) - nwa_data.pop(vp_net + '_VlanID') - nwa_data.pop(vp_net + '_CreateVlan') - - -def set_gdv_device_data(nwa_data, device_id, nwa_info): - dev_key = 'DEV_%s' % device_id - nwa_data[dev_key] = 'device_id' - nwa_data[dev_key + '_device_owner'] = nwa_info['device']['owner'] - - -def set_tfw_device_data(nwa_data, device_id, tfw_name, nwa_info): - dev_key = 'DEV_%s' % device_id - nwa_data[dev_key] = 'device_id' - nwa_data[dev_key + '_device_owner'] = nwa_info['device']['owner'] - nwa_data[dev_key + '_TenantFWName'] = tfw_name - - -def strip_device_data(nwa_data, device_id): - dev_key = 'DEV_%s' % device_id - nwa_data.pop(dev_key) - nwa_data.pop(dev_key + '_device_owner') - nwa_data.pop(dev_key + '_TenantFWName', None) - - -def set_gdv_interface_data(nwa_data, device_id, network_id, - resource_group_name_nw, nwa_info): - net_key = 'DEV_%s_%s' % (device_id, network_id) - nwa_data[net_key] = nwa_info['network']['name'] - nwa_data[net_key + '_ip_address'] = nwa_info['port']['ip'] - nwa_data[net_key + '_mac_address'] = nwa_info['port']['mac'] - nwa_data[net_key + '_' + resource_group_name_nw] = nwa_const.NWA_DEVICE_GDV - - -def set_tfw_interface_data(nwa_data, device_id, network_id, - resource_group_name_nw, tfw_name, nwa_info): - net_key = 'DEV_%s_%s' % (device_id, network_id) - nwa_data[net_key] = nwa_info['network']['name'] - nwa_data[net_key + '_ip_address'] = nwa_info['port']['ip'] - nwa_data[net_key + '_mac_address'] = nwa_info['port']['mac'] - nwa_data[net_key + '_TenantFWName'] = tfw_name - nwa_data[net_key + '_' + resource_group_name_nw] = nwa_const.NWA_DEVICE_TFW - - -def strip_interface_data(nwa_data, device_id, network_id, - resource_group_name_nw): - net_key = 'DEV_%s_%s' % (device_id, network_id) - nwa_data.pop(net_key) - nwa_data.pop(net_key + '_ip_address') - nwa_data.pop(net_key + '_mac_address') - nwa_data.pop(net_key + '_TenantFWName', None) - nwa_data.pop(net_key + '_' + resource_group_name_nw) - - -def set_vp_net_data(nwa_data, network_id, resource_group_name_nw, device_type, - vlan_id): - seg_key = ('VLAN_%(network_id)s_%(group)s_%(dev_type)s' % - {'network_id': network_id, - 'group': resource_group_name_nw, - 'dev_type': NWA_DEVICE_MAP[device_type]}) - nwa_data[seg_key] = 'physical_network' - nwa_data[seg_key + '_VlanID'] = vlan_id - - -def strip_vp_net_data(nwa_data, network_id, resource_group_name_nw, - device_type): - seg_key = ('VLAN_%(network_id)s_%(group)s_%(dev_type)s' % - {'network_id': network_id, - 'group': resource_group_name_nw, - 'dev_type': NWA_DEVICE_MAP[device_type]}) - nwa_data.pop(seg_key) - nwa_data.pop(seg_key + '_VlanID') - - -def strip_tfw_data_if_exist(nwa_data, device_id, network_id, - resource_group_name_nw): - tfw_key = 'VLAN_%s_%s_TFW_FW_TFW%s' % (network_id, - resource_group_name_nw, - device_id) - if tfw_key in nwa_data: - nwa_data.pop(tfw_key) - - -def set_floatingip_data(nwa_data, floating): - fip_key = 'NAT_' + floating['id'] - nwa_data[fip_key] = floating['device_id'] - nwa_data[fip_key + '_network_id'] = floating['floating_network_id'] - nwa_data[fip_key + '_floating_ip_address'] = \ - floating['floating_ip_address'] - nwa_data[fip_key + '_fixed_ip_address'] = floating['fixed_ip_address'] - - -def strip_floatingip_data(nwa_data, floating): - fip_key = 'NAT_' + floating['id'] - nwa_data.pop(fip_key) - nwa_data.pop(fip_key + '_network_id') - nwa_data.pop(fip_key + '_floating_ip_address') - nwa_data.pop(fip_key + '_fixed_ip_address') diff --git a/networking_nec/nwa/nwalib/exceptions.py b/networking_nec/nwa/nwalib/exceptions.py deleted file mode 100644 index 2f36806..0000000 --- a/networking_nec/nwa/nwalib/exceptions.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -class NwaException(Exception): - '''Raised when there is an error in Nwa. ''' - def __init__(self, http_status, errmsg, orgexc=None): - super(NwaException, self).__init__() - self.http_status = http_status - self.errmsg = errmsg - self.orgexc = orgexc - - def __str__(self): - return 'http status: %s, %s' % (self.http_status, self.errmsg) diff --git a/networking_nec/nwa/nwalib/nwa_restclient.py b/networking_nec/nwa/nwalib/nwa_restclient.py deleted file mode 100644 index e76a389..0000000 --- a/networking_nec/nwa/nwalib/nwa_restclient.py +++ /dev/null @@ -1,271 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import base64 -import copy -import hashlib -import hmac -import re - -import eventlet -from oslo_config import cfg -from oslo_log import log as logging -from oslo_serialization import jsonutils -from oslo_utils import encodeutils -import six -from six.moves.urllib import parse as urlparse - -from networking_nec._i18n import _LI, _LW, _LE -from networking_nec.nwa.common import config as nwaconf -from networking_nec.nwa.nwalib import exceptions as nwa_exc -from networking_nec.nwa.nwalib import restclient -from networking_nec.nwa.nwalib import semaphore as nwa_sem -from networking_nec.nwa.nwalib import workflow - - -LOG = logging.getLogger(__name__) - -cfgNWA = nwaconf.cfg.CONF.NWA - -CRLF = '\x0D\x0A' - - -class NwaRestClient(restclient.RestClient): - '''Client class of NWA rest. ''' - - workflow_list_is_loaded = False - - def __init__(self, host=None, port=None, use_ssl=True, auth=None, - access_key_id=None, secret_access_key=None, **kwargs): - load_workflow_list = kwargs.pop('load_workflow_list', True) - if auth is None: - auth = self._define_auth_function(access_key_id, secret_access_key) - if not host or not port: - if not cfgNWA.server_url: - raise cfg.Error("'server_url' or (host, port) " - "must be specified.") - host, port, use_ssl = self._parse_server_url(cfgNWA.server_url) - super(NwaRestClient, self).__init__(host, port, use_ssl, auth, - **kwargs) - self._post_data = None - self.workflow_first_wait = cfg.CONF.NWA.scenario_polling_first_timer - self.workflow_wait_sleep = cfg.CONF.NWA.scenario_polling_timer - self.workflow_retry_count = cfg.CONF.NWA.scenario_polling_count - LOG.info(_LI('NWA init: workflow wait: %(first_wait)ss + ' - '%(wait_sleep)ss x %(retry_count)s times.'), - {'first_wait': self.workflow_first_wait, - 'wait_sleep': self.workflow_wait_sleep, - 'retry_count': self.workflow_retry_count}) - if load_workflow_list and not NwaRestClient.workflow_list_is_loaded: - self.update_workflow_list() - NwaRestClient.workflow_list_is_loaded = True - - def _parse_server_url(self, url): - url_parts = urlparse.urlparse(url) - return (url_parts.hostname, - url_parts.port, - url_parts.scheme == 'https') - - def _define_auth_function(self, access_key_id, secret_access_key): - access_key_id = access_key_id or cfgNWA.access_key_id - secret_access_key = secret_access_key or cfgNWA.secret_access_key - if not access_key_id or not secret_access_key: - # XXX: Don't we need to raise an error? - # raise cfg.Error('access_key_id and secret_access_key must ' - # 'be specified.') - return - - def azure_auth(datestr, path): - signature = hmac.new( - encodeutils.safe_encode(secret_access_key), - encodeutils.safe_encode(datestr + CRLF + path), - hashlib.sha256 - ).digest() - return (encodeutils.safe_encode('SharedKeyLite %s:' - % access_key_id) + - base64.b64encode(signature)) - - return azure_auth - - def workflow_polling_log_post_data(self, url, body): - self._post_data = (url, body) - - def _log_rest_request(self, method, url, body): - name = workflow.NwaWorkflow.name(url) - body_str = '' - if isinstance(body, dict): - body_str = jsonutils.dumps(body, sort_keys=True) - if name: - LOG.info(_LI('NWA workflow: %(name)s %(body)s'), - {'name': name, 'body': body_str}) - else: - LOG.info(_LI('NWA %(method)s %(url)s %(body)s'), - {'method': method, - 'url': self._url(url), - 'body': body_str}) - - def _log_workflow_success(self, data): - name = '' - if self._post_data: - post_url = self._post_data[0] - name = (workflow.NwaWorkflow.name(post_url) or post_url) - LOG.info(_LI("NWA workflow: %(name)s %(workflow)s"), - {'name': name, - 'workflow': jsonutils.dumps(data, indent=4, sort_keys=True)}) - - def _log_workflow_error(self, data): - errno = workflow.NwaWorkflow.get_errno_from_resultdata(data) - if not self._post_data: - return '' - post_url, post_body = self._post_data - if isinstance(post_body, dict): - post_body = jsonutils.dumps(post_body, indent=4, sort_keys=True) - name = (workflow.NwaWorkflow.name(post_url) or post_url) - reason = workflow.NwaWorkflow.strerror(errno) - LOG.error(_LE("NWA workflow: %(name)s reason(%(errno)s)=%(reason)s " - "request=%(request)s, response=%(response)s"), - {'name': name, - 'errno': errno, - 'reason': reason, - 'request': post_body, - 'response': jsonutils.dumps(data, indent=4, sort_keys=True) - }) - - def _log_rest_response(self, status_code, data): - status = '' - progress = '' - if isinstance(data, dict) and data.get('status'): - status = data.get('status') - progress = data.get('progress') - LOG.info(_LI("NWA HTTP %(code)s %(status)s %(progress)s"), - {'code': status_code, - 'status': status, 'progress': progress}) - if status == 'FAILED': - self._log_workflow_error(data) - elif status == 'SUCCEED': - self._log_workflow_success(data) - - def rest_api(self, method, url, body=None): - status_code = 200 - try: - self._log_rest_request(method, url, body) - status_code, data = super(NwaRestClient, - self).rest_api(method, url, body) - self._log_rest_response(status_code, data) - return status_code, data - - except nwa_exc.NwaException as e: - status_code = e.http_status - return status_code, None - - def workflowinstance(self, execution_id): - return self.get('/umf/workflowinstance/' + execution_id) - - def stop_workflowinstance(self, execution_id): - return self.delete('/umf/workflowinstance/' + execution_id) - - def workflow_kick_and_wait(self, call, url, body): - http_status = -1 - rj = None - (http_status, rj) = call(url, body) - - if not isinstance(rj, dict): - return (http_status, None) - - exeid = rj.get('executionid') - if not isinstance(exeid, six.string_types): - LOG.error(_LE('Invalid executin id %s'), exeid) - try: - wait_time = self.workflow_first_wait - eventlet.sleep(wait_time) - for __ in range(self.workflow_retry_count): - (http_status, rw) = self.workflowinstance(exeid) - if not isinstance(rw, dict): - LOG.error( - _LE('NWA workflow: failed %(http_status)s %(body)s'), - {'http_status': http_status, 'body': rw} - ) - return (http_status, None) - if rw.get('status') != 'RUNNING': - LOG.debug('%s', rw) - return (http_status, rw) - eventlet.sleep(wait_time) - wait_time = self.workflow_wait_sleep - LOG.warning(_LW('NWA workflow: retry over. retry count is %s.'), - self.workflow_retry_count) - except Exception as e: - LOG.error(_LE('NWA workflow: %s'), e) - return (http_status, None) - - def call_workflow(self, tenant_id, post, name, body): - url = workflow.NwaWorkflow.path(name) - try: - wkf = nwa_sem.Semaphore.get_tenant_semaphore(tenant_id) - if wkf.sem.locked(): - LOG.info(_LI('NWA sem %s(count)s: %(name)s %(url)s %(body)s'), - {'count': wkf.sem.balance, - 'name': post.__name__, - 'url': url, - 'body': body}) - with wkf.sem: - n = copy.copy(self) - n.workflow_polling_log_post_data(url, body) - http_status, rj = n.workflow_kick_and_wait(post, url, body) - return http_status, rj - except Exception as e: - LOG.exception(_LE('%s'), e) - return -1, None - - def wait_workflow_done(self, thr): - LOG.debug('*** start wait') - thr.wait() - LOG.debug('*** end wait') - - def get_tenant_resource(self, tenant_id): - return self.get('/umf/reserveddcresource/' + tenant_id) - - def get_dc_resource_groups(self, group=None): - if not group: - url = '/umf/dcresource/groups' - else: - url = '/umf/dcresource/groups/' + str(group) - return self.get(url) - - def get_reserved_dc_resource(self, tenant_id): - url = '/umf/reserveddcresource/' + str(tenant_id) - return self.get(url) - - def get_workflow_list(self): - try: - url = '/umf/workflow/list' - return self.get(url) - except Exception as e: - LOG.warning(_LW('The initial worklist is not updated,' - ' using default worklist. (%s)'), e) - return None, None - - def update_workflow_list(self): - __, rj = self.get_workflow_list() - nameid = {} - if isinstance(rj, dict) and rj.get('Workflows'): - def new_nameid(wf): - path = wf.get('Path') - if isinstance(path, six.string_types): - m = re.search(r'\\([a-zA-Z0-9_]+)$', path) - if m: - key = str(m.group(1)) - nameid[key] = str(wf.get('Id')) - for _wf in rj.get('Workflows'): - new_nameid(_wf) - workflow.NwaWorkflow.update_nameid(nameid) diff --git a/networking_nec/nwa/nwalib/restclient.py b/networking_nec/nwa/nwalib/restclient.py deleted file mode 100644 index e77c8fb..0000000 --- a/networking_nec/nwa/nwalib/restclient.py +++ /dev/null @@ -1,148 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import datetime - -from oslo_log import log as logging -from oslo_serialization import jsonutils -import requests - -from networking_nec._i18n import _, _LI -from networking_nec.nwa.nwalib import exceptions as nwa_exc - - -LOG = logging.getLogger(__name__) - -DATE_HEADER_FORMAT = '%a, %d %b %Y %H:%M:%S GMT' - -UMF_API_VERSION = '2.0.2.1.201502' -OLD_UMF_API_VERSION = '2.0.2.201402' - - -# datetime.datetime.utcnow cannot be mocked. -# It is required to mock utcnow in unit test. -def utcnow(): - return datetime.datetime.utcnow() - - -class RestClient(object): - """A HTTP/HTTPS client for NEC NWA Drivers.""" - - def __init__(self, host=None, port=None, use_ssl=True, auth=None, - umf_api_version=UMF_API_VERSION): - """Creates a new client to some NWA. - - :param host: The host where service resides - :param port: The port where service resides - :param use_ssl: True to use SSL, False to use HTTP - :param: auth: function to generate Authorization header. - """ - self.host = host - self.port = port - self.use_ssl = use_ssl - self.auth = auth - self.umf_api_version = umf_api_version - - LOG.info( - _LI('NWA init: host=%(host)s port=%(port)s use_ssl=%(use_ssl)s ' - 'auth=%(auth)s'), - {'host': self.host, 'port': self.port, 'use_ssl': self.use_ssl, - 'auth': self.auth} - ) - LOG.info(_LI('NWA init: umf api version: %s'), - self.umf_api_version) - - def _url(self, path): - protocol = "http" - if self.use_ssl: - protocol = "https" - return '%s://%s:%s%s' % (protocol, self.host, self.port, path) - - def _make_headers(self, path): - datestr = utcnow().strftime(DATE_HEADER_FORMAT) - headers = { - # XXX: If auth is None, RestClient will be broken. - 'Authorization': self.auth(datestr, path), - 'Content-Type': 'application/json', - 'Date': datestr, - 'X-UMF-API-Version': self.umf_api_version - } - return headers - - def _send_receive(self, method, path, body=None): - scheme = "http" - if self.use_ssl: - scheme = "https" - - url = "%s://%s:%d%s" % (scheme, self.host, int(self.port), path) - headers = self._make_headers(path) - LOG.debug('NWA HTTP Headers %s', headers) - res = requests.request(method, url, data=body, headers=headers, - verify=False, proxies={'no': 'pass'}) - return res - - def rest_api(self, method, url, body=None): - if isinstance(body, dict): - body = jsonutils.dumps(body, indent=4, sort_keys=True) - - LOG.debug("NWA %(method)s %(host)s:%(port)s%(url)s body=%(body)s", - {'method': method, 'host': self.host, 'port': self.port, - 'url': url, 'body': body}) - - status_code = -1 - try: - res = self._send_receive(method, url, body) - except requests.exceptions.RequestException as e: - msg = _("NWA Failed to connect %(host)s:%(port)s: %(reason)s") - msg_params = {'host': self.host, - 'port': self.port, - 'reason': e} - LOG.error(msg, msg_params) - raise nwa_exc.NwaException(status_code, msg % msg_params, e) - - data = res.text - LOG.debug("NWA returns: httpStatus=%(status)s body=%(data)s", - {'status': res.status_code, - 'data': data}) - try: - data = jsonutils.loads(data) - except (ValueError, TypeError): - pass - status_code = int(res.status_code) - if 200 <= status_code and status_code <= 209: - return (status_code, data) - else: - msg = _("NWA failed: %(method)s %(host)s:%(port)s%(url)s " - "(HTTP/1.1 %(status_code)s %(reason)s) body=%(data)s") - msg_params = {'method': method, - 'host': self.host, - 'port': self.port, - 'url': url, - 'status_code': res.status_code, - 'reason': res.reason, - 'data': data} - LOG.warning(msg, msg_params) - raise nwa_exc.NwaException(status_code, msg % msg_params) - - def get(self, url): - return self.rest_api("GET", url) - - def post(self, url, body=None): - return self.rest_api("POST", url, body=body) - - def put(self, url, body=None): - return self.rest_api("PUT", url, body=body) - - def delete(self, url): - return self.rest_api("DELETE", url) diff --git a/networking_nec/nwa/nwalib/semaphore.py b/networking_nec/nwa/nwalib/semaphore.py deleted file mode 100644 index 0e39cdd..0000000 --- a/networking_nec/nwa/nwalib/semaphore.py +++ /dev/null @@ -1,62 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import eventlet -from oslo_log import log as logging -import six - -from networking_nec._i18n import _, _LI - - -LOG = logging.getLogger(__name__) - - -class Thread(object): - def __init__(self, thread): - self.thread = thread - - def stop(self): - self.thread.kill() - - def wait(self): - return self.thread.wait() - - -class Semaphore(object): - lock = eventlet.semaphore.Semaphore(1) - tenants = {} - - @classmethod - def get_tenant_semaphore(cls, tenant_id): - if not isinstance(tenant_id, six.string_types) or tenant_id == '': - raise TypeError(_('%s is not a string') % tenant_id) - with Semaphore.lock: - if tenant_id not in Semaphore.tenants: - LOG.info(_LI('create semaphore for %s'), tenant_id) - Semaphore.tenants[tenant_id] = Semaphore() - return Semaphore.tenants[tenant_id] - - @classmethod - def delete_tenant_semaphore(cls, tenant_id): - with Semaphore.lock: - if tenant_id in Semaphore.tenants: - LOG.info(_LI('delete semaphore for %s'), tenant_id) - del Semaphore.tenants[tenant_id] - - def __init__(self): - self._sem = eventlet.semaphore.Semaphore(1) - - @property - def sem(self): - return self._sem diff --git a/networking_nec/nwa/nwalib/workflow.py b/networking_nec/nwa/nwalib/workflow.py deleted file mode 100644 index aceeaf1..0000000 --- a/networking_nec/nwa/nwalib/workflow.py +++ /dev/null @@ -1,178 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import re - -import six - - -class NwaWorkflow(object): - '''Workflow definition of NWA. ''' - _path_prefix = '/umf/workflow/' - _nameid_initialized = False - _nameid = { - 'CreateTenantNW': '40030001', - 'DeleteTenantNW': '40030016', - 'CreateVLAN': '40030002', - 'DeleteVLAN': '40030018', - 'CreateGeneralDev': '40030021', - 'DeleteGeneralDev': '40030022', - 'CreateTenantFW': '40030019', - 'UpdateTenantFW': '40030009', - 'DeleteTenantFW': '40030020', - 'SettingNAT': '40030005', - 'DeleteNAT': '40030011', - 'SettingFWPolicy': '40030081', - 'SettingLBPolicy': '40030091', - 'CreateTenantLB': '40030092', - 'UpdateTenantLB': '40030093', - 'DeleteTenantLB': '40030094', - 'CreateConnectPort': '50000001', - 'DeleteConnectPort': '50000002', - } - _errno = { - '1': 'Unknown parent node', - '2': 'Already exists', - '3': 'Resources are insufficient', - '4': 'Unknown node', - '5': 'Can not access the file', - '6': 'Unknown parameters', - '7': 'Undefined parameters', - '8': 'Permission error', - '9': 'It is not possible to remove because it is in use', - '10': 'An error occurred while deleting the node', - '11': 'Execution environment is invalid', - '31': 'Specified IP subnet does not exist', - '32': 'Specified IP address does not exist', - '33': 'Can not allocate IP subnet to be paid out', - '34': 'IP subnet will not exceed the threshold', - '101': 'An unknown error has occurred', - '102': 'An internal error has occurred', - '103': 'Failed to connect to CMDB', - '104': 'Out of memory', - '105': 'An error occurred in the select process to the CMDB', - '106': 'An error occurred in the update process to the CMDB', - '107': 'An error occurred in the insert process to the CMDB', - '108': 'Input parameter is invalid', - '109': 'An error occurred in the file processing', - '110': 'An error occurred in the delete process to the CMDB', - '201': 'There is no free VLAN ID', - '202': 'Exceeded the threshold of VLAN', - '203': 'Exceeded the threshold ot Tenant equipment', - '204': 'Resource group is not specified in the input', - '205': 'Tenant-ID is not specified in the input', - '206': 'Tenant-Network is already created', - '207': 'There is no available devices', - '208': 'IP address depletion for assignment of LB', - '209': 'The device in the cluster group is 0 or 2 or more', - '210': 'The device in the cluster group is 0', - '211': 'There is no specified resource group', - '212': 'There is no character "/" in the resource group name', - '213': 'Tenant-FW is not specified one', - '214': 'Tenant-FW is specified two or more', - '215': 'Can not be extended because there is no PFS', - '216': 'Logical NW name is not specified', - '217': 'There is no Registered SSL-VPN equipment', - '218': 'Tenant network is not yet created', - '219': 'There is no free LoadBalancer', - '220': 'Can not get the physical server uuid', - '221': 'There is no deletion of VLAN', - '222': 'Tenant ID in use is still exists', - '223': 'Tenant-FW not found', - '224': 'There is no specified device name', - '225': 'Can not get the information of tenant vlan', - '226': 'There is no specified logical NW', - '227': 'Can not get the device information of the tenant in use', - '228': 'For updated is in use, it could not be updated', - '229': 'For deletion is in use, it could not be deleted', - '230': 'Exceeded the threshold', - '231': 'Exceeded the allocation possible number', - '232': 'Exceeded the allocation range', - '233': 'Authentication setting is incorrect', - '234': 'Usable IP address range setting of is invalid', - '235': 'IP address specified is invalid', - '236': 'There is no available for allocation Tenant FW', - '237': 'IP address depletion for assignment of FW', - '238': 'IP address is invalid', - '239': 'Can not set the number of records to zero', - '240': 'The specification does not include a payout already IP subnet', - '241': 'Not specified LogicalPort under the same controller or domain', - '242': 'IP address depletion for assignment of SSL', - '243': 'IP address is invalid', - '244': 'The type of controller is invalid', - '245': 'Device or VDOM name is invalid specified', - '246': 'Exceeds the upper limit of naming convention', - '251': 'In the same tenant, scenario there are still concurrent or ' - 'reservation ID', - '252': '(unused)', - '253': 'The preceding scenario, can not be reserved', - '254': 'Can not get the reserved id because of the preceding scenario', - '298': 'Resources are insufficient', - '299': 'Unknown error', - } - - @staticmethod - def init(name): - pass # pragma: no cover - - @staticmethod - def path(name): - """Returns path of workflow. - - :param name: The name of workflow. - """ - return '%s%s/execute' % (NwaWorkflow._path_prefix, - NwaWorkflow._nameid[name]) - - @staticmethod - def name(path): - """Returns name of workflow. - - :param name: The name of workflow. - """ - wid = path[len(NwaWorkflow._path_prefix):-len('/execute')] - for (name, _id) in NwaWorkflow._nameid.items(): - if _id == wid: - return name - return None - - @staticmethod - def strerror(errno): - """Returns error name of errno. - - :param errno: The number of error. - """ - return NwaWorkflow._errno.get(errno) - - @staticmethod - def get_errno_from_resultdata(data): - resultdata = data.get('resultdata') - if resultdata: - errmsg = resultdata.get('ErrorMessage') - if isinstance(errmsg, six.string_types): - m = re.search(r'ErrorNumber=(\d+)', errmsg) - if m: - return m.group(1) - m = re.search(r'ReservationErrorCode = (\d+)', errmsg, re.M) - if m: - return m.group(1) - return None - - @staticmethod - def update_nameid(new_nameid): - if NwaWorkflow._nameid_initialized: - return - if new_nameid: - NwaWorkflow._nameid = new_nameid - NwaWorkflow._nameid_initialized = True diff --git a/networking_nec/tests/__init__.py b/networking_nec/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/__init__.py b/networking_nec/tests/unit/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/nwa/__init__.py b/networking_nec/tests/unit/nwa/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/nwa/agent/__init__.py b/networking_nec/tests/unit/nwa/agent/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/nwa/agent/base.py b/networking_nec/tests/unit/nwa/agent/base.py deleted file mode 100644 index ec93a95..0000000 --- a/networking_nec/tests/unit/nwa/agent/base.py +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.common import rpc -from neutron.tests import base -from oslo_config import cfg - -from networking_nec.nwa.agent import nwa_agent - - -def _init_nwa_client_patch(mocked_nwacli): - succeed = (200, { - 'status': 'SUCCEED', - 'resultdata': { - 'LogicalNWName': 'LNW_BusinessVLAN_4000', - 'TenantFWName': 'T1', - 'VlanID': '4000', - } - }) - mocked_nwacli.tenant.create_tenant.return_value = succeed - mocked_nwacli.tenant.delete_tenant.return_value = succeed - - mocked_nwacli.l2.create_general_dev.return_value = succeed - mocked_nwacli.l2.create_tenant_nw.return_value = succeed - mocked_nwacli.l2.create_vlan.return_value = succeed - mocked_nwacli.l2.create_connect_port.return_value = succeed - - mocked_nwacli.l2.delete_general_dev.return_value = succeed - mocked_nwacli.l2.delete_tenant_nw.return_value = succeed - mocked_nwacli.l2.delete_vlan.return_value = succeed - mocked_nwacli.l2.delete_connect_port.return_value = succeed - - -class TestNWAAgentBase(base.BaseTestCase): - - @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall') - @mock.patch('neutron.common.rpc.Connection.consume_in_threads') - @mock.patch('neutron.common.rpc.create_connection') - @mock.patch('neutron.agent.rpc.PluginReportStateAPI') - @mock.patch('neutron.common.rpc.get_client') - def setUp(self, f1, f2, f3, f4, f5): - super(TestNWAAgentBase, self).setUp() - - cli = mock.patch('networking_nec.nwa.nwalib.client.NwaClient').start() - self.nwacli = cli.return_value - _init_nwa_client_patch(self.nwacli) - - self.agent = nwa_agent.NECNWANeutronAgent(10) - rpc.init(cfg.ConfigOpts()) diff --git a/networking_nec/tests/unit/nwa/agent/test_data/add_router_interface_nwa_info.json b/networking_nec/tests/unit/nwa/agent/test_data/add_router_interface_nwa_info.json deleted file mode 100644 index 8e03aa5..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/add_router_interface_nwa_info.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "device": { - "id": "6b34210c-bd74-47f0-8dc3-3bad9bc333c3", - "owner": "network:router_interface" - }, - "network": { - "id": "546a8551-5c2b-4050-a769-cc3c962fc5cf", - "name": "net100", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "physical_network": "OpenStack/DC1/APP", - "port": { - "id": "5174b4d2-f4dc-4292-9d9e-7862f885abdf", - "ip": "192.168.100.1", - "mac": "fa:16:3e:45:98:7d" - }, - "resource_group": "OpenStack/DC1/APP", - "resource_group_name": "OpenStack/DC1", - "resource_group_name_nw": "OpenStack/DC1", - "subnet": { - "id": "7dabadaa-06fc-45fb-af0b-33384cf291c4", - "mask": "24", - "netaddr": "192.168.100.0" - } -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/add_router_interface_nwa_info_2.json b/networking_nec/tests/unit/nwa/agent/test_data/add_router_interface_nwa_info_2.json deleted file mode 100644 index 36b15bc..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/add_router_interface_nwa_info_2.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "device": { - "id": "6b34210c-bd74-47f0-8dc3-3bad9bc333c3", - "owner": "network:router_interface" - }, - "network": { - "id": "b2246c56-d465-49c7-a332-f329aa524277", - "name": "net101", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "physical_network": "OpenStack/DC1/APP", - "port": { - "id": "254c3a42-b3aa-4083-9b7b-2e4c62b2ffbb", - "ip": "192.168.101.1", - "mac": "fa:16:3e:34:9a:c9" - }, - "resource_group": "OpenStack/DC1/APP", - "resource_group_name": "OpenStack/DC1", - "resource_group_name_nw": "OpenStack/DC1", - "subnet": { - "id": "ec3d84a5-ce49-48ee-a041-a7b9c9867899", - "mask": "24", - "netaddr": "192.168.101.0" - } -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/create_general_dev_nwa_info.json b/networking_nec/tests/unit/nwa/agent/test_data/create_general_dev_nwa_info.json deleted file mode 100644 index 578b72e..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/create_general_dev_nwa_info.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "device": { - "id": "36509c40-58e0-4293-8b16-48b409959b8f", - "owner": "compute:DC1_KVM" - }, - "network": { - "id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4", - "name": "pj1-net100", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d", - "physical_network": "OpenStack/DC1/APP", - "port": { - "id": "c61583dd-b52b-4bd7-b586-a6b33780090f", - "ip": "192.168.200.132", - "mac": "fa:16:3e:a6:1d:00" - }, - "resource_group": "OpenStack/DC1/APP", - "resource_group_name": "OpenStack/DC1/APP", - "resource_group_name_nw": "OpenStack/DC1/APP", - "subnet": { - "id": "94fdaea5-33ae-4411-b6e0-71e4b099d470", - "mask": "24", - "netaddr": "192.168.200.0" - }, - "tenant_id": "844eb55f21e84a289e9c22098d387e5d" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/create_general_dev_nwa_info_2.json b/networking_nec/tests/unit/nwa/agent/test_data/create_general_dev_nwa_info_2.json deleted file mode 100644 index 578b72e..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/create_general_dev_nwa_info_2.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "device": { - "id": "36509c40-58e0-4293-8b16-48b409959b8f", - "owner": "compute:DC1_KVM" - }, - "network": { - "id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4", - "name": "pj1-net100", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d", - "physical_network": "OpenStack/DC1/APP", - "port": { - "id": "c61583dd-b52b-4bd7-b586-a6b33780090f", - "ip": "192.168.200.132", - "mac": "fa:16:3e:a6:1d:00" - }, - "resource_group": "OpenStack/DC1/APP", - "resource_group_name": "OpenStack/DC1/APP", - "resource_group_name_nw": "OpenStack/DC1/APP", - "subnet": { - "id": "94fdaea5-33ae-4411-b6e0-71e4b099d470", - "mask": "24", - "netaddr": "192.168.200.0" - }, - "tenant_id": "844eb55f21e84a289e9c22098d387e5d" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/create_general_dev_result.json b/networking_nec/tests/unit/nwa/agent/test_data/create_general_dev_result.json deleted file mode 100644 index 86436e9..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/create_general_dev_result.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "progress": 100, - "resultdata": { - "CreateNW_PortType1": "", - "DCResourceReserveID": "1", - "ErrorMessage": "", - "NWAResult": "No result log\r\n", - "ResourceGroupName": "OpenStack/DC1/APP", - "TenantID": "DC1_844eb55f21e84a289e9c22098d387e5d", - "VlanID": "200", - "VlanLoopCounter": "1" - }, - "status": "SUCCESS" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/create_tenant_nw_result.json b/networking_nec/tests/unit/nwa/agent/test_data/create_tenant_nw_result.json deleted file mode 100644 index eaa05c0..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/create_tenant_nw_result.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "progress": 100, - "resultdata": { - "AutoRecovery": "0", - "BackEndFWInfo": "FortiGate", - "DCResourceReserveID": "1", - "DCResourceReserveID_Delete": "", - "ErrorMessage": "", - "InJsonFileName": "", - "ManagementLogicalNWName": "LNW_ManagementVLAN_88", - "ManagementVlanFwIpAddress": "100.64.0.254", - "ManagementVlanID": "1", - "ManagementVlanIPSubnet": "100.64.0.0", - "ManagementVlanSubnetMask": "255.255.255.0", - "OutJsonFileName": "", - "ResourceGroupName": "OpenStack/DC1/APP", - "TenantFWAccessInfo": "", - "TenantFWInfo": "", - "TenantFWName": "", - "TenantID": "DC1_844eb55f21e84a289e9c22098d387e5d", - "TenantLogicalNWName": "LNW_TenantVLAN_89", - "TenantVlanFwIpAddress": "", - "TenantVlanID": "", - "TenantVlanIPSubnet": "100.64.1.0", - "TenantVlanSubnetMask": "255.255.255.0" - }, - "status": "SUCCEED" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/create_vlan_result.json b/networking_nec/tests/unit/nwa/agent/test_data/create_vlan_result.json deleted file mode 100644 index b4f6587..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/create_vlan_result.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "progress": 100, - "resultdata": { - "AutoRecovery": "0", - "BackEndFWInfo": "", - "DCResourceReserveID": "1", - "DCResourceReserveID_Delete": "", - "ErrorMessage": "", - "InJsonFileName": "", - "LogicalNWName": "LNW_BusinessVLAN_100", - "OutJsonFileName": "", - "ResourceGroupName": "", - "RouterInfo": "", - "TenantFWAccessInfo": "", - "TenantFWInfo": "", - "TenantID": "DC1_844eb55f21e84a289e9c22098d387e5d", - "VlanFwIpAddress": "", - "VlanID": "", - "VlanIPSubnet": "192.168.100.0", - "VlanSubnetMask": "255.255.255.0" - }, - "status": "SUCCEED" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/delete_general_dev_nwa_info.json b/networking_nec/tests/unit/nwa/agent/test_data/delete_general_dev_nwa_info.json deleted file mode 100644 index 2c9abf7..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/delete_general_dev_nwa_info.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "device": { - "id": "36509c40-58e0-4293-8b16-48b409959b8f", - "owner": "compute:DC1_KVM" - }, - "network": { - "id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4", - "name": "pj1-net100", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d", - "physical_network": "OpenStack/DC1/APP", - "port": { - "id": "68ef8ee1-277b-4570-cb28-ad514a7699e7", - "ip": "192.168.200.161", - "mac": "fa:16:3e:bc:18:00" - }, - "resource_group": "OpenStack/DC1/APP", - "resource_group_name": "OpenStack/DC1/APP", - "subnet": { - "id": "94fdaea5-33ae-4411-b6e0-71e4b099d470", - "mask": "24", - "netaddr": "192.168.200.0" - }, - "tenant_id": "844eb55f21e84a289e9c22098d387e5d" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/delete_general_dev_result.json b/networking_nec/tests/unit/nwa/agent/test_data/delete_general_dev_result.json deleted file mode 100644 index bb799f9..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/delete_general_dev_result.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "progress": 100, - "resultdata": { - "DCResourceReserveID": "1", - "ErrorMessage": "", - "NWAResult": "No result log\r\n", - "ResourceGroupName": "OpenStack/DC1/APP", - "TenantID": "DC1_844eb55f21e84a289e9c22098d387e5d", - "UNC_LoopCounter": "1", - "VlanLoopCounter": "0" - }, - "status": "SUCCEED" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/delete_general_dev_result_fail.json b/networking_nec/tests/unit/nwa/agent/test_data/delete_general_dev_result_fail.json deleted file mode 100644 index 4f12c02..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/delete_general_dev_result_fail.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "progress": 100, - "resultdata": { - "DCResourceReserveID": "1", - "ErrorMessage": "", - "NWAResult": "No result log\r\n", - "ResourceGroupName": "OpenStack/DC1/APP", - "TenantID": "DC1_844eb55f21e84a289e9c22098d387e5d", - "UNC_LoopCounter": "1", - "VlanLoopCounter": "0" - }, - "status": "FAILED" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/delete_tenant_nw_result.json b/networking_nec/tests/unit/nwa/agent/test_data/delete_tenant_nw_result.json deleted file mode 100644 index 2b6d100..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/delete_tenant_nw_result.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "progress": 100, - "resultdata": { - "DCResourceReserveID": "1", - "DevType": "", - "ErrorMessage": "", - "GUID": "", - "LogicalNWName_Del": "LNW_TenantVLAN_89", - "ManagerName": "", - "Mode": "", - "NWAResult": "No result log\r\n", - "NumOfTenantNWDev": "", - "ResourceGroupName": "Common/App/Pod3", - "SSLAuthFlag": "", - "Section": "", - "TFWAuthFlag": "", - "TFWCount": "", - "TenantID": "DC1_844eb55f21e84a289e9c22098d387e5d", - "UNC_LoopCounter": "1", - "VlanID_Del": "5", - "VlanLoopCounter": "0", - "VlanType": "" - }, - "status": "SUCCEED" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/delete_vlan_result.json b/networking_nec/tests/unit/nwa/agent/test_data/delete_vlan_result.json deleted file mode 100644 index 7860a61..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/delete_vlan_result.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "progress": 100, - "resultdata": { - "DCResourceReserveID": "1", - "ErrorMessage": "", - "NWAResult": "No result log\r\n", - "TenantID": "DC1_844eb55f21e84a289e9c22098d387e5d", - "UNC_LoopCounter": "1", - "VlanLoopCounter": "0" - }, - "status": "SUCCEED" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/expected_proxy_create_vlan_succeed1.json b/networking_nec/tests/unit/nwa/agent/test_data/expected_proxy_create_vlan_succeed1.json deleted file mode 100644 index 0883d5e..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/expected_proxy_create_vlan_succeed1.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "NW_546a8551-5c2b-4050-a769-cc3c962fc5cf": "net100", - "NW_546a8551-5c2b-4050-a769-cc3c962fc5cf_network_id": "546a8551-5c2b-4050-a769-cc3c962fc5cf", - "NW_546a8551-5c2b-4050-a769-cc3c962fc5cf_nwa_network_name": "LNW_BusinessVLAN_100", - "NW_546a8551-5c2b-4050-a769-cc3c962fc5cf_subnet": "192.168.100.0", - "NW_546a8551-5c2b-4050-a769-cc3c962fc5cf_subnet_id": "7dabadaa-06fc-45fb-af0b-33384cf291c4", - "VLAN_546a8551-5c2b-4050-a769-cc3c962fc5cf": "physical_network", - "VLAN_546a8551-5c2b-4050-a769-cc3c962fc5cf_CreateVlan": "", - "VLAN_546a8551-5c2b-4050-a769-cc3c962fc5cf_VlanID": "300" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_check_segment.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_check_segment.json deleted file mode 100644 index 3b8e2ae..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_check_segment.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "CreateTenantNW": "1", - "DEV_843bc108-2f17-4be4-b9cb-44e00abe78d1": "device_id", - "DEV_843bc108-2f17-4be4-b9cb-44e00abe78d1_TenantFWName": "TFW3", - "DEV_843bc108-2f17-4be4-b9cb-44e00abe78d1_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "DEV_843bc108-2f17-4be4-b9cb-44e00abe78d1_a94fd0fc-2282-4092-9485-b0f438b0f6c4_TYPE": "TenantFW", - "DEV_843bc108-2f17-4be4-b9cb-44e00abe78d1_a94fd0fc-2282-4092-9485-b0f438b0f6c4_TenantFWName": "TFW3", - "DEV_843bc108-2f17-4be4-b9cb-44e00abe78d1_a94fd0fc-2282-4092-9485-b0f438b0f6c4_ip_address": "192.168.200.1", - "DEV_843bc108-2f17-4be4-b9cb-44e00abe78d1_a94fd0fc-2282-4092-9485-b0f438b0f6c4_mac_address": "fa:16:3e:17:41:b4", - "DEV_843bc108-2f17-4be4-b9cb-44e00abe78d1_device_owner": "network:router_interface", - "DEV_843bc108-2f17-4be4-b9cb-44e00abe78d1_physical_network": "OpenStack/DC1/APP", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_network_id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_nwa_network_name": "LNW_BusinessVLAN_103", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_subnet": "192.168.200.0", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_subnet_id": "94fdaea5-33ae-4411-b6e0-71e4b099d470", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_CreateVlan": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP": "physical_network", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_CreateVlan": "CreateVlan", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_FW_TFW843bc108-2f17-4be4-b9cb-44e00abe78d1": "connected", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_VlanID": "37", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_VlanID": "4000" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_create_general_dev_ex1.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_create_general_dev_ex1.json deleted file mode 100644 index af9bae1..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_create_general_dev_ex1.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "CreateTenant": 1, - "CreateTenantNW": 1, - "DEV_4b18c7ba-1370-410e-af4c-8578fbb3ab99": "device_id", - "DEV_4b18c7ba-1370-410e-af4c-8578fbb3ab99_0ed65870-9acb-48ce-8c0b-e803d527a9d2": "net100", - "DEV_4b18c7ba-1370-410e-af4c-8578fbb3ab99_0ed65870-9acb-48ce-8c0b-e803d527a9d2_TYPE": "TenantFW", - "DEV_4b18c7ba-1370-410e-af4c-8578fbb3ab99_0ed65870-9acb-48ce-8c0b-e803d527a9d2_TenantFWName": "TFW8", - "DEV_4b18c7ba-1370-410e-af4c-8578fbb3ab99_0ed65870-9acb-48ce-8c0b-e803d527a9d2_ip_address": "192.168.100.1", - "DEV_4b18c7ba-1370-410e-af4c-8578fbb3ab99_0ed65870-9acb-48ce-8c0b-e803d527a9d2_mac_address": "fa:16:3e:97:4f:d4", - "DEV_4b18c7ba-1370-410e-af4c-8578fbb3ab99_TenantFWName": "TFW8", - "DEV_4b18c7ba-1370-410e-af4c-8578fbb3ab99_device_owner": "network:router_interface", - "DEV_4b18c7ba-1370-410e-af4c-8578fbb3ab99_physical_network": "OpenStack/DC1/APP", - "NWA_tenant_id": "DC02_844eb55f21e84a289e9c22098d387e5d", - "NW_0ed65870-9acb-48ce-8c0b-e803d527a9d2": "net100", - "NW_0ed65870-9acb-48ce-8c0b-e803d527a9d2_network_id": "0ed65870-9acb-48ce-8c0b-e803d527a9d2", - "NW_0ed65870-9acb-48ce-8c0b-e803d527a9d2_nwa_network_name": "LNW_BusinessVLAN_108", - "NW_0ed65870-9acb-48ce-8c0b-e803d527a9d2_subnet": "192.168.100.0", - "NW_0ed65870-9acb-48ce-8c0b-e803d527a9d2_subnet_id": "df2a7b8a-e027-49ab-bf84-ade82a3c096c", - "VLAN_0ed65870-9acb-48ce-8c0b-e803d527a9d2_OpenStack/DC1/APP": "physical_network", - "VLAN_0ed65870-9acb-48ce-8c0b-e803d527a9d2_OpenStack/DC1/APP_CreateVlan": "CreateVlan", - "VLAN_0ed65870-9acb-48ce-8c0b-e803d527a9d2_OpenStack/DC1/APP_FW_TFW4b18c7ba-1370-410e-af4c-8578fbb3ab99": "connected", - "VLAN_0ed65870-9acb-48ce-8c0b-e803d527a9d2_OpenStack/DC1/APP_VlanID": "53" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_create_general_dev_succeed2.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_create_general_dev_succeed2.json deleted file mode 100644 index feac0b8..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_create_general_dev_succeed2.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "CreateTenant": 1, - "CreateTenantNW": 1, - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "device_id", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1": "GeneralDev", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_ip_address": "192.168.0.1", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_mac_address": "fa:16:3e:76:ab:0e", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_device_owner": "network:dhcp", - "NWA_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_network_id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_nwa_network_name": "LNW_BusinessVLAN_100", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_subnet": "192.168.0.0", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_subnet_id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_CreateVlan": "", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1_GD": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1_GD_VlanID": "49", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_VlanID": "4000" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_create_general_dev_succeed3.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_create_general_dev_succeed3.json deleted file mode 100644 index feac0b8..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_create_general_dev_succeed3.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "CreateTenant": 1, - "CreateTenantNW": 1, - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "device_id", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1": "GeneralDev", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_ip_address": "192.168.0.1", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_mac_address": "fa:16:3e:76:ab:0e", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_device_owner": "network:dhcp", - "NWA_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_network_id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_nwa_network_name": "LNW_BusinessVLAN_100", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_subnet": "192.168.0.0", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_subnet_id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_CreateVlan": "", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1_GD": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1_GD_VlanID": "49", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_VlanID": "4000" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_general_dev_succeed1.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_general_dev_succeed1.json deleted file mode 100644 index fe9410e..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_general_dev_succeed1.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "CreateTenant": 1, - "CreateTenantNW": 1, - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "device_id", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1": "GeneralDev", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_ip_address": "192.168.0.1", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_mac_address": "fa:16:3e:76:ab:0e", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_device_owner": "network:dhcp", - "NWA_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_network_id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_nwa_network_name": "LNW_BusinessVLAN_100", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_subnet": "192.168.0.0", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_subnet_id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_CreateVlan": "", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1_GD": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1_GD_VlanID": "52", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_VlanID": "4000" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_general_dev_succeed2.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_general_dev_succeed2.json deleted file mode 100644 index 18cf090..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_general_dev_succeed2.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "CreateTenant": 1, - "CreateTenantNW": 1, - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21": "device_id", - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1": "GeneralDev", - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_ip_address": "192.168.0.3", - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_mac_address": "fa:16:3e:5c:3f:c2", - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21_device_owner": "compute:DC01_KVM02_ZONE02", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "device_id", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1": "GeneralDev", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_ip_address": "192.168.0.1", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_mac_address": "fa:16:3e:76:ab:0e", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_device_owner": "network:dhcp", - "NWA_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_network_id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_nwa_network_name": "LNW_BusinessVLAN_100", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_subnet": "192.168.0.0", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_subnet_id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_CreateVlan": "", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1_GD": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1_GD_VlanID": "49", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_VlanID": "4000" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_general_dev_succeed3.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_general_dev_succeed3.json deleted file mode 100644 index 501a252..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_general_dev_succeed3.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "CreateTenant": 1, - "CreateTenantNW": 1, - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21": "device_id", - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA2": "GeneralDev", - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_ip_address": "192.168.0.3", - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_mac_address": "fa:16:3e:5c:3f:c2", - "DEV_18972752-f0f4-4cf7-b185-971ff6539d21_device_owner": "compute:DC01_KVM02_ZONE02", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "device_id", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1": "GeneralDev", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_ip_address": "192.168.0.1", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_mac_address": "fa:16:3e:76:ab:0e", - "DEV_dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_device_owner": "network:dhcp", - "NWA_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "net01", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_network_id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_nwa_network_name": "LNW_BusinessVLAN_100", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_subnet": "192.168.0.0", - "NW_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_subnet_id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_CreateVlan": "", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1_GD": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA1_GD_VlanID": "49", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA2_GD": "physical_network", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_OpenStack/DC/HA2_GD_VlanID": "53", - "VLAN_0f17fa8f-40fe-43bd-8573-1a1e1bfb699d_VlanID": "4000" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_vlan_succeed1.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_vlan_succeed1.json deleted file mode 100644 index 232bacc..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_delete_vlan_succeed1.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "CreateTenant": "1", - "CreateTenantNW": true, - "DEV_6b34210c-bd74-47f0-8dc3-3bad9bc333c3": "device_id", - "DEV_6b34210c-bd74-47f0-8dc3-3bad9bc333c3_546a8551-5c2b-4050-a769-cc3c962fc5cf": "net100", - "DEV_6b34210c-bd74-47f0-8dc3-3bad9bc333c3_546a8551-5c2b-4050-a769-cc3c962fc5cf_TYPE": "TenantFW", - "DEV_6b34210c-bd74-47f0-8dc3-3bad9bc333c3_546a8551-5c2b-4050-a769-cc3c962fc5cf_TenantFWName": "TFW27", - "DEV_6b34210c-bd74-47f0-8dc3-3bad9bc333c3_546a8551-5c2b-4050-a769-cc3c962fc5cf_ip_address": "192.168.100.1", - "DEV_6b34210c-bd74-47f0-8dc3-3bad9bc333c3_546a8551-5c2b-4050-a769-cc3c962fc5cf_mac_address": "fa:16:3e:04:d3:28", - "DEV_6b34210c-bd74-47f0-8dc3-3bad9bc333c3_TenantFWName": "TFW27", - "DEV_6b34210c-bd74-47f0-8dc3-3bad9bc333c3_device_owner": "network:router_interface", - "DEV_6b34210c-bd74-47f0-8dc3-3bad9bc333c3_physical_network": "OpenStack/DC1/APP", - "NWA_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d", - "NW_546a8551-5c2b-4050-a769-cc3c962fc5cf": "net100", - "NW_546a8551-5c2b-4050-a769-cc3c962fc5cf_network_id": "546a8551-5c2b-4050-a769-cc3c962fc5cf", - "NW_546a8551-5c2b-4050-a769-cc3c962fc5cf_nwa_network_name": "LNW_BusinessVLAN_120", - "NW_546a8551-5c2b-4050-a769-cc3c962fc5cf_subnet": "192.168.100.0", - "NW_546a8551-5c2b-4050-a769-cc3c962fc5cf_subnet_id": "7dabadaa-06fc-45fb-af0b-33384cf291c4", - "VLAN_546a8551-5c2b-4050-a769-cc3c962fc5cf": "physical_network", - "VLAN_546a8551-5c2b-4050-a769-cc3c962fc5cf_CreateVlan": "", - "VLAN_546a8551-5c2b-4050-a769-cc3c962fc5cf_OpenStack/DC1/APP": "physical_network", - "VLAN_546a8551-5c2b-4050-a769-cc3c962fc5cf_OpenStack/DC1/APP_CreateVlan": "CreateVlan", - "VLAN_546a8551-5c2b-4050-a769-cc3c962fc5cf_OpenStack/DC1/APP_FW_TFW6b34210c-bd74-47f0-8dc3-3bad9bc333c3": "connected", - "VLAN_546a8551-5c2b-4050-a769-cc3c962fc5cf_OpenStack/DC1/APP_VlanID": "62", - "VLAN_546a8551-5c2b-4050-a769-cc3c962fc5cf_VlanID": "4000" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_get_resource_group_name.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_get_resource_group_name.json deleted file mode 100644 index 0070a17..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_get_resource_group_name.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "CreateTenant": true, - "CreateTenantNW": true, - "DEV_dhcpcea0d383-9268-577e-ba23-10e5e2d43886-315414a5-8d06-4d8e-8932-6f73665e5733": "device_id", - "DEV_dhcpcea0d383-9268-577e-ba23-10e5e2d43886-315414a5-8d06-4d8e-8932-6f73665e5733_315414a5-8d06-4d8e-8932-6f73665e5733": "LNetA", - "DEV_dhcpcea0d383-9268-577e-ba23-10e5e2d43886-315414a5-8d06-4d8e-8932-6f73665e5733_315414a5-8d06-4d8e-8932-6f73665e5733_OpenStack/DC/HA1": "GeneralDev", - "DEV_dhcpcea0d383-9268-577e-ba23-10e5e2d43886-315414a5-8d06-4d8e-8932-6f73665e5733_315414a5-8d06-4d8e-8932-6f73665e5733_ip_address": "192.168.1.1", - "DEV_dhcpcea0d383-9268-577e-ba23-10e5e2d43886-315414a5-8d06-4d8e-8932-6f73665e5733_315414a5-8d06-4d8e-8932-6f73665e5733_mac_address": "fa:16:3e:71:5c:2c", - "DEV_dhcpcea0d383-9268-577e-ba23-10e5e2d43886-315414a5-8d06-4d8e-8932-6f73665e5733_device_owner": "network:dhcp", - "NWA_tenant_id": "T01DC7483b391c2c647c59097240d59e705d4", - "NW_315414a5-8d06-4d8e-8932-6f73665e5733": "LNetA", - "NW_315414a5-8d06-4d8e-8932-6f73665e5733_network_id": "315414a5-8d06-4d8e-8932-6f73665e5733", - "NW_315414a5-8d06-4d8e-8932-6f73665e5733_nwa_network_name": "LNW_BusinessVLAN_448", - "NW_315414a5-8d06-4d8e-8932-6f73665e5733_subnet": "192.168.201.0", - "NW_315414a5-8d06-4d8e-8932-6f73665e5733_subnet_id": "44345c6f-f597-48c7-b97b-a0d8df39059b", - "VLAN_315414a5-8d06-4d8e-8932-6f73665e5733": "physical_network", - "VLAN_315414a5-8d06-4d8e-8932-6f73665e5733_CreateVlan": "", - "VLAN_315414a5-8d06-4d8e-8932-6f73665e5733_OpenStack/DC/HA1_GD": "physical_network", - "VLAN_315414a5-8d06-4d8e-8932-6f73665e5733_OpenStack/DC/HA1_GD_VlanID": "685", - "VLAN_315414a5-8d06-4d8e-8932-6f73665e5733_VlanID": "" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_one_general_dev.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_one_general_dev.json deleted file mode 100644 index 361778a..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_one_general_dev.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "CreateTenant": 1, - "CreateTenantNW": 1, - "DEV_36509c40-58e0-4293-8b16-48b409959b8f": "device_id", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP": "", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_TYPE": "GeneralDev", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_ip_address": "192.168.200.132", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_mac_address": "fa:16:3e:a6:1d:00", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_device_owner": "compute:DC1_KVM", - "NWA_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_network_id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_nwa_network_name": "LNW_BusinessVLAN_100", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_subnet": "192.168.200.0", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_subnet_id": "94fdaea5-33ae-4411-b6e0-71e4b099d470", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_CreateVlan": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP": "physical_network", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_CreateVlan": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_GD": "connected", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_GD_VlanID": "4000", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_VlanID": "38", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_VlanID": "4000" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_two_general_dev.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_two_general_dev.json deleted file mode 100644 index 0bdb0c4..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_two_general_dev.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "CreateTenant": 1, - "CreateTenantNW": 1, - "DEV_1547cdd1-5fcc-437e-b2fb-30b0021a0054": "device_id", - "DEV_1547cdd1-5fcc-437e-b2fb-30b0021a0054_device_owner": "compute:DC1_KVM", - "DEV_1547cdd1-5fcc-437e-b2fb-30b0021a0054_f058200f-8fa9-446e-a9d0-86aed2d25a73": "pj1-net101", - "DEV_1547cdd1-5fcc-437e-b2fb-30b0021a0054_f058200f-8fa9-446e-a9d0-86aed2d25a73_TYPE": "GeneralDev", - "DEV_1547cdd1-5fcc-437e-b2fb-30b0021a0054_f058200f-8fa9-446e-a9d0-86aed2d25a73_ip_address": "192.168.100.27", - "DEV_1547cdd1-5fcc-437e-b2fb-30b0021a0054_f058200f-8fa9-446e-a9d0-86aed2d25a73_mac_address": "fa:16:3e:9b:b0:de", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f": "device_id", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP": "", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_TYPE": "GeneralDev", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_ip_address": "192.168.200.132", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_mac_address": "fa:16:3e:a6:1d:00", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_device_owner": "compute:DC1_KVM", - "NWA_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_network_id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_nwa_network_name": "LNW_BusinessVLAN_100", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_subnet": "192.168.200.0", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_subnet_id": "94fdaea5-33ae-4411-b6e0-71e4b099d470", - "NW_f058200f-8fa9-446e-a9d0-86aed2d25a73": "pj1-net101", - "NW_f058200f-8fa9-446e-a9d0-86aed2d25a73_network_id": "f058200f-8fa9-446e-a9d0-86aed2d25a73", - "NW_f058200f-8fa9-446e-a9d0-86aed2d25a73_nwa_network_name": "LNW_BusinessVLAN_107", - "NW_f058200f-8fa9-446e-a9d0-86aed2d25a73_subnet": "192.168.100.0", - "NW_f058200f-8fa9-446e-a9d0-86aed2d25a73_subnet_id": "292af468-18d7-4212-abc5-d55f4ffff656", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_CreateVlan": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP": "physical_network", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_CreateVlan": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_GD": "connected", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_GD_VlanID": "4000", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_VlanID": "38", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_VlanID": "4000", - "VLAN_f058200f-8fa9-446e-a9d0-86aed2d25a73_OpenStack/DC1/APP": "physical_network", - "VLAN_f058200f-8fa9-446e-a9d0-86aed2d25a73_OpenStack/DC1/APP_CreateVlan": "CreateVlan", - "VLAN_f058200f-8fa9-446e-a9d0-86aed2d25a73_OpenStack/DC1/APP_VlanID": "45" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_two_port_general_dev.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_two_port_general_dev.json deleted file mode 100644 index 98faf34..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_two_port_general_dev.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "CreateTenant": 1, - "CreateTenantNW": 1, - "DEV_2180ae23-ad33-4a89-8eef-f2f28e62e789": "device_id", - "DEV_2180ae23-ad33-4a89-8eef-f2f28e62e789_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "DEV_2180ae23-ad33-4a89-8eef-f2f28e62e789_a94fd0fc-2282-4092-9485-b0f438b0f6c4_TYPE": "GeneralDev", - "DEV_2180ae23-ad33-4a89-8eef-f2f28e62e789_a94fd0fc-2282-4092-9485-b0f438b0f6c4_ip_address": "192.168.200.133", - "DEV_2180ae23-ad33-4a89-8eef-f2f28e62e789_a94fd0fc-2282-4092-9485-b0f438b0f6c4_mac_address": "fa:16:3e:bc:18:00", - "DEV_2180ae23-ad33-4a89-8eef-f2f28e62e789_device_owner": "compute:DC1_KVM", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f": "device_id", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP": "", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_TYPE": "GeneralDev", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_ip_address": "192.168.200.132", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_mac_address": "fa:16:3e:a6:1d:00", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_device_owner": "compute:DC1_KVM", - "NWA_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_network_id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_nwa_network_name": "LNW_BusinessVLAN_100", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_subnet": "192.168.200.0", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_subnet_id": "94fdaea5-33ae-4411-b6e0-71e4b099d470", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_CreateVlan": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP": "physical_network", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_CreateVlan": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_GD": "connected", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_GD_VlanID": "4000", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_VlanID": "38", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_VlanID": "4000" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_two_port_general_dev_fail.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_two_port_general_dev_fail.json deleted file mode 100644 index 57f32cb..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_data_two_port_general_dev_fail.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "CreateTenant": 1, - "CreateTenantNW": 1, - "DEV_2180ae23-ad33-4a89-8eef-f2f28e62e789_a94fd0fc-2282-4092-9485-b0f438b0f6c4_TYPE": "GeneralDev", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f": "device_id", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP": "", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_TYPE": "GeneralDev", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_ip_address": "192.168.200.132", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_a94fd0fc-2282-4092-9485-b0f438b0f6c4_mac_address": "fa:16:3e:a6:1d:00", - "DEV_36509c40-58e0-4293-8b16-48b409959b8f_device_owner": "compute:DC1_KVM", - "NWA_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "pj1-net100", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_network_id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_nwa_network_name": "LNW_BusinessVLAN_100", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_subnet": "192.168.200.0", - "NW_a94fd0fc-2282-4092-9485-b0f438b0f6c4_subnet_id": "94fdaea5-33ae-4411-b6e0-71e4b099d470", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_CreateVlan": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP": "physical_network", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_CreateVlan": "", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_GD": "connected", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_GD_VlanID": "37", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_OpenStack/DC1/APP_VlanID": "38", - "VLAN_a94fd0fc-2282-4092-9485-b0f438b0f6c4_VlanID": "4000" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_ex1.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_ex1.json deleted file mode 100644 index 4cb0b74..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_ex1.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "device": { - "id": "171fff51-ac4c-444e-99a2-8957ca0fad6e", - "owner": "compute:DC1_KVM" - }, - "network": { - "id": "0ed65870-9acb-48ce-8c0b-e803d527a9d2", - "name": "net100", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "DC02_844eb55f21e84a289e9c22098d387e5d", - "physical_network": "OpenStack/DC1/APP", - "port": { - "id": "81f78799-fd82-48ce-98c3-3df91fb4768c", - "ip": "192.168.100.102", - "mac": "fa:16:3e:1b:27:f9" - }, - "resource_group": "OpenStack/DC1/APP", - "resource_group_name": "OpenStack/DC1/APP", - "resource_group_name_nw": "OpenStack/DC1/APP", - "subnet": { - "id": "df2a7b8a-e027-49ab-bf84-ade82a3c096c", - "mask": "24", - "netaddr": "192.168.100.0" - }, - "tenant_id": "844eb55f21e84a289e9c22098d387e5d" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_succeed1.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_succeed1.json deleted file mode 100644 index e6d938d..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_succeed1.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "device": { - "id": "dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "owner": "network:dhcp" - }, - "network": { - "id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "name": "net01", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "physical_network": "OpenStack/DC/HA1", - "port": { - "id": "519c51b8-9328-455a-8ae7-b204754eacea", - "ip": "192.168.0.1", - "mac": "fa:16:3e:76:ab:0e" - }, - "resource_group_name": "OpenStack/DC/HA1", - "resource_group_name_nw": "OpenStack/DC/APP", - "subnet": { - "id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "mask": "24", - "netaddr": "192.168.0.0" - }, - "tenant_id": "5d9c51b1d6a34133bb735d4988b309c2" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_succeed2.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_succeed2.json deleted file mode 100644 index 4f0234f..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_succeed2.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "device": { - "id": "18972752-f0f4-4cf7-b185-971ff6539d21", - "owner": "compute:DC01_KVM02_ZONE02" - }, - "network": { - "id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "name": "net01", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "physical_network": "OpenStack/DC/HA1", - "port": { - "id": "faa923cc-3bfc-44d1-a66a-31b75b5aad7a", - "ip": "192.168.0.3", - "mac": "fa:16:3e:5c:3f:c2" - }, - "resource_group_name": "OpenStack/DC/HA1", - "resource_group_name_nw": "OpenStack/DC/APP", - "subnet": { - "id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "mask": "24", - "netaddr": "192.168.0.0" - }, - "tenant_id": "5d9c51b1d6a34133bb735d4988b309c2" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_succeed3.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_succeed3.json deleted file mode 100644 index d29b5a0..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_create_general_dev_succeed3.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "device": { - "id": "18972752-f0f4-4cf7-b185-971ff6539d21", - "owner": "compute:DC01_KVM02_ZONE02" - }, - "network": { - "id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "name": "net01", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "physical_network": "OpenStack/DC/HA2", - "port": { - "id": "faa923cc-3bfc-44d1-a66a-31b75b5aad7a", - "ip": "192.168.0.3", - "mac": "fa:16:3e:5c:3f:c2" - }, - "resource_group_name": "OpenStack/DC/HA2", - "resource_group_name_nw": "OpenStack/DC/APP", - "subnet": { - "id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "mask": "24", - "netaddr": "192.168.0.0" - }, - "tenant_id": "5d9c51b1d6a34133bb735d4988b309c2" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_delete_general_dev_succeed1.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_delete_general_dev_succeed1.json deleted file mode 100644 index e6d938d..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_delete_general_dev_succeed1.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "device": { - "id": "dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "owner": "network:dhcp" - }, - "network": { - "id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "name": "net01", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "physical_network": "OpenStack/DC/HA1", - "port": { - "id": "519c51b8-9328-455a-8ae7-b204754eacea", - "ip": "192.168.0.1", - "mac": "fa:16:3e:76:ab:0e" - }, - "resource_group_name": "OpenStack/DC/HA1", - "resource_group_name_nw": "OpenStack/DC/APP", - "subnet": { - "id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "mask": "24", - "netaddr": "192.168.0.0" - }, - "tenant_id": "5d9c51b1d6a34133bb735d4988b309c2" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_delete_general_dev_succeed2.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_delete_general_dev_succeed2.json deleted file mode 100644 index e6d938d..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_delete_general_dev_succeed2.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "device": { - "id": "dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "owner": "network:dhcp" - }, - "network": { - "id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "name": "net01", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "physical_network": "OpenStack/DC/HA1", - "port": { - "id": "519c51b8-9328-455a-8ae7-b204754eacea", - "ip": "192.168.0.1", - "mac": "fa:16:3e:76:ab:0e" - }, - "resource_group_name": "OpenStack/DC/HA1", - "resource_group_name_nw": "OpenStack/DC/APP", - "subnet": { - "id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "mask": "24", - "netaddr": "192.168.0.0" - }, - "tenant_id": "5d9c51b1d6a34133bb735d4988b309c2" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_delete_general_dev_succeed3.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_delete_general_dev_succeed3.json deleted file mode 100644 index e6d938d..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_delete_general_dev_succeed3.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "device": { - "id": "dhcp754b775b-af0d-5760-b6fc-64c290f9fc0b-0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "owner": "network:dhcp" - }, - "network": { - "id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d", - "name": "net01", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2", - "physical_network": "OpenStack/DC/HA1", - "port": { - "id": "519c51b8-9328-455a-8ae7-b204754eacea", - "ip": "192.168.0.1", - "mac": "fa:16:3e:76:ab:0e" - }, - "resource_group_name": "OpenStack/DC/HA1", - "resource_group_name_nw": "OpenStack/DC/APP", - "subnet": { - "id": "3ba921f6-0788-40c8-b273-286b777d8cfe", - "mask": "24", - "netaddr": "192.168.0.0" - }, - "tenant_id": "5d9c51b1d6a34133bb735d4988b309c2" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_get_resource_group_name.json b/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_get_resource_group_name.json deleted file mode 100644 index 9490ac9..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_data/nwa_info_get_resource_group_name.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "device": { - "id": "dhcpcea0d383-9268-577e-ba23-10e5e2d43886-315414a5-8d06-4d8e-8932-6f73665e5733", - "owner": "compute:DC01_KVM01_ZONE01" - }, - "network": { - "id": "315414a5-8d06-4d8e-8932-6f73665e5733", - "name": "LNetA", - "vlan_id": "123", - "vlan_type": "BusinessVLAN" - }, - "nwa_tenant_id": "T01DC7483b391c2c647c59097240d59e705d4", - "physical_network": "OpenStack/DC/HA1", - "port": { - "id": "4693c521-280c-4052-a95d-f2fd53052824", - "ip": "192.168.1.3", - "mac": "fa:16:3e:71:5c:2c" - }, - "resource_group_name": null, - "resource_group_name_nw": "OpenStack/DC/APP", - "subnet": { - "id": "85fcc2a6-a121-4635-814d-04df134090ab", - "mask": "24", - "netaddr": "192.168.1.0" - }, - "tenant_id": "7483b391c2c647c59097240d59e705d4" -} diff --git a/networking_nec/tests/unit/nwa/agent/test_nwa_agent.py b/networking_nec/tests/unit/nwa/agent/test_nwa_agent.py deleted file mode 100644 index 070706d..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_nwa_agent.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from mock import patch -from oslo_config import cfg - -from networking_nec.nwa.agent import nwa_agent -from networking_nec.tests.unit.nwa.agent import base - - -class TestNECNWANeutronAgentAsNwaClient(base.TestNWAAgentBase): - - @patch('neutron.common.rpc.Connection') - @patch('neutron.agent.rpc.PluginReportStateAPI') - @patch('networking_nec.nwa.l2.rpc.tenant_binding_api.' - 'TenantBindingServerRpcApi') - def test__setup_rpc(self, f1, f2, f3): - self.agent.setup_rpc() - self.assertIsNotNone(self.agent.host) - self.assertIsNotNone(self.agent.agent_id) - self.assertIsNotNone(self.agent.context) - self.assertIsNotNone(self.agent.nwa_l2_rpc) - self.assertIsNotNone(self.agent.state_rpc) - self.assertIsNotNone(self.agent.callback_nwa) - self.assertIsNotNone(self.agent.callback_proxy) - - @patch('neutron.common.rpc.Connection') - @patch('neutron.agent.rpc.PluginReportStateAPI') - @patch('networking_nec.nwa.l2.rpc.tenant_binding_api.' - 'TenantBindingServerRpcApi') - def test__setup_rpc_no_report_interval(self, f1, f2, f3): - self.agent.conf.NWA.lbaas_driver = True - self.agent.conf.NWA.fwaas_driver = True - cfg.CONF.AGENT.report_interval = 0 - self.agent.setup_rpc() - self.assertIsNotNone(self.agent.host) - self.assertIsNotNone(self.agent.agent_id) - self.assertIsNotNone(self.agent.context) - self.assertIsNotNone(self.agent.nwa_l2_rpc) - self.assertIsNotNone(self.agent.state_rpc) - self.assertIsNotNone(self.agent.callback_nwa) - self.assertIsNotNone(self.agent.callback_proxy) - - def test__report_state(self): - self.assertIsNone(self.agent._report_state()) - - def test_loop_handler(self): - self.assertIsNone(self.agent.loop_handler()) - - @patch('time.sleep') - def test_daemon_loop(self, f1): - f1.side_effect = ValueError('dummy exception') - self.assertRaises( - ValueError, - self.agent.daemon_loop - ) - - -@patch('networking_nec.nwa.agent.nwa_agent.NECNWANeutronAgent') -@patch('neutron.common.config') -@patch('sys.argv') -def test_main(f1, f2, f3): - nwa_agent.main() diff --git a/networking_nec/tests/unit/nwa/agent/test_proxy_l2.py b/networking_nec/tests/unit/nwa/agent/test_proxy_l2.py deleted file mode 100644 index 40b4a6d..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_proxy_l2.py +++ /dev/null @@ -1,532 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import os.path - -import mock -from oslo_serialization import jsonutils -import six -import testscenarios - -from networking_nec.nwa.agent import proxy_l2 -from networking_nec.nwa.common import exceptions as nwa_exc -from networking_nec.tests.unit.nwa.agent import base - - -def load_data_file(name): - base_dir = os.path.dirname(__file__) - fn = os.path.join(base_dir, 'test_data', name) - with open(fn) as f: - return jsonutils.loads(f.read()) - - -class TestAgentProxyL2(base.TestNWAAgentBase): - - def test__create_tenant_nw_fail(self): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - nwa_tenant_id = 'DC1_' + tenant_id - resource_group_name = 'OpenStack/DC1/APP' - nwa_data1 = {} - nwa_info = { - 'resource_group_name': resource_group_name, - 'resource_group_name_nw': resource_group_name, - } - self.nwacli.l2.create_tenant_nw.return_value = 500, {} - e = self.assertRaises( - nwa_exc.AgentProxyException, - self.agent.proxy_l2._create_tenant_nw, - mock.sentinel.context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - resource_group_name=resource_group_name, - nwa_data=nwa_data1, - nwa_info=nwa_info, - ) - ret_val = e.value - self.assertEqual(ret_val, nwa_data1) - - def test__create_tenant_nw_with_key(self): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - nwa_tenant_id = 'DC1_' + tenant_id - resource_group_name = 'OpenStack/DC1/APP' - nwa_data1 = {proxy_l2.KEY_CREATE_TENANT_NW: True} - nwa_info = { - 'resource_group_name': resource_group_name, - 'resource_group_name_nw': resource_group_name, - } - result = self.agent.proxy_l2._create_tenant_nw( - mock.sentinel.context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - resource_group_name=resource_group_name, - nwa_data=nwa_data1, - nwa_info=nwa_info, - ) - self.assertIsNone(result) - - def test__create_vlan_succeed1(self): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - nwa_tenant_id = 'DC1_' + '844eb55f21e84a289e9c22098d387e5d' - # resource_group_name = 'OpenStack/DC1/APP' - nwa_data = {} - nwa_info = load_data_file('add_router_interface_nwa_info.json') - ret_vln = load_data_file('create_vlan_result.json') - ret_vln['resultdata']['VlanID'] = '300' - self.nwacli.l2.create_vlan.return_value = (200, ret_vln) - result = self.agent.proxy_l2._create_vlan( - mock.sentinel.context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info, - nwa_data=nwa_data - ) - exp_data = load_data_file('expected_proxy_create_vlan_succeed1.json') - self.assertDictEqual(exp_data, result) - - def test__create_vlan_succeed2(self): - net_id = '546a8551-5c2b-4050-a769-cc3c962fc5cf' - vlan_id_key = 'VLAN_' + net_id - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - nwa_tenant_id = 'DC1_' + '844eb55f21e84a289e9c22098d387e5d' - # resource_group_name = 'OpenStack/DC1/APP' - nwa_data = {vlan_id_key: 'net-uuid-1'} - nwa_info = load_data_file('add_router_interface_nwa_info.json') - ret_vln = load_data_file('create_vlan_result.json') - ret_vln['resultdata']['VlanID'] = '300' - ret_vln['resultdata'][net_id] = 'net-uuid-1' - self.nwacli.l2.create_vlan.return_value = (200, ret_vln) - result = self.agent.proxy_l2._create_vlan( - mock.sentinel.context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info, - nwa_data=nwa_data - ) - self.assertDictEqual(nwa_data, result) - - def test__create_vlan_fail1(self): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - nwa_tenant_id = 'DC1_' + '844eb55f21e84a289e9c22098d387e5d' - # resource_group_name = 'OpenStack/DC1/APP' - nwa_data = {'NW_546a8551-5c2b-4050-a769-cc3c962fc5cf': 'net100'} - nwa_info = load_data_file('add_router_interface_nwa_info.json') - self.nwacli.l2.create_vlan.return_value = 500, {} - self.assertRaises( - nwa_exc.AgentProxyException, - self.agent.proxy_l2._create_vlan, - mock.sentinel.context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info, - nwa_data=nwa_data - ) - - def test__delete_vlan_succeed1(self): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - nwa_tenant_id = 'DC1_' + '844eb55f21e84a289e9c22098d387e5d' - # resource_group_name = 'OpenStack/DC1/APP' - nwa_data = load_data_file('nwa_data_delete_vlan_succeed1.json') - nwa_info = load_data_file('add_router_interface_nwa_info.json') - dvl_result = load_data_file('delete_vlan_result.json') - self.nwacli.l2.create_vlan.return_value = (200, dvl_result) - result = self.agent.proxy_l2._delete_vlan( - mock.sentinel.context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info, - nwa_data=nwa_data - ) - self.assertDictEqual(nwa_data, result) - - def test_check_vlan_for_tenant_fw(self): - network_id = '546a8551-5c2b-4050-a769-cc3c962fc5cf' - segment = 'OpenStack/DC1/APP' - nwa_data = {'VLAN_%s_%s_VlanID' % (network_id, segment): '4000'} - self.assertEqual(1, proxy_l2.check_vlan(network_id, nwa_data)) - - def test_check_vlan_for_tenant_lb(self): - network_id = '546a8551-5c2b-4050-a769-cc3c962fc5cf' - segment = 'OpenStack/DC1/APP' - nwa_data = {'VLAN_LB_%s_%s_VlanID' % (network_id, segment): '4000'} - self.assertEqual(1, proxy_l2.check_vlan(network_id, nwa_data)) - - -class TestAgentProxyL2CreateGeneralDev(testscenarios.WithScenarios, - base.TestNWAAgentBase): - - scenarios = [ - ('succeed1', - {'retval_create_tenant': (200, {}), - 'retval_create_tenant_nw': (200, 'create_tenant_nw_result.json'), - 'retval_create_vlan': (200, 'create_vlan_result.json'), - 'nwa_info': 'create_general_dev_nwa_info.json', - 'gtb_data': {}}, - ), - ('succeed2', - {'retval_create_tenant': (200, {}), - 'retval_create_tenant_nw': (200, 'create_tenant_nw_result.json'), - 'retval_create_vlan': (200, 'create_vlan_result.json'), - 'nwa_info': 'create_general_dev_nwa_info_2.json', - 'gtb_data': 'nwa_data_one_general_dev.json'}, - ), - ('fail1', - {'retval_create_tenant': (200, {}), - 'retval_create_tenant_nw': (200, 'create_tenant_nw_result.json'), - 'retval_create_vlan': (200, 'create_vlan_result.json'), - 'nwa_info': 'create_general_dev_nwa_info.json', - 'gtb_data': {}}, - ), - ('fail2', - {'retval_create_tenant': (200, {}), - 'retval_create_tenant_nw': (200, 'create_tenant_nw_result.json'), - 'retval_create_vlan': (500, 'create_vlan_result.json'), - 'nwa_info': 'create_general_dev_nwa_info.json', - 'gtb_data': {}}, - ), - ('fail3', - {'retval_create_tenant': (200, {}), - 'retval_create_tenant_nw': (500, 'create_tenant_nw_result.json'), - 'retval_create_vlan': (200, 'create_vlan_result.json'), - 'nwa_info': 'create_general_dev_nwa_info.json', - 'gtb_data': {}}, - ), - ('fail4', - {'retval_create_tenant': (501, {}), - 'retval_create_tenant_nw': (200, 'create_tenant_nw_result.json'), - 'retval_create_vlan': (200, 'create_vlan_result.json'), - 'nwa_info': 'create_general_dev_nwa_info.json', - 'gtb_data': {}}, - ), - ('ex1', - {'retval_create_tenant': (200, {}), - 'retval_create_tenant_nw': (200, 'create_tenant_nw_result.json'), - 'retval_create_vlan': (200, 'create_vlan_result.json'), - 'nwa_info': 'nwa_info_create_general_dev_ex1.json', - 'gtb_data': 'nwa_data_create_general_dev_ex1.json'}, - ), - ] - - @mock.patch('networking_nec.nwa.l2.rpc.tenant_binding_api.' - 'TenantBindingServerRpcApi.get_nwa_tenant_binding') - @mock.patch('networking_nec.nwa.l2.rpc.tenant_binding_api.' - 'TenantBindingServerRpcApi.set_nwa_tenant_binding') - @mock.patch('networking_nec.nwa.agent.proxy_tenant.' - 'AgentProxyTenant.update_tenant_binding') - def test_create_general_dev(self, utb, stb, gtb): - context = mock.MagicMock() - tenant_id = "844eb55f21e84a289e9c22098d387e5d" - nwa_tenant_id = 'DC1_' + tenant_id - - nwa_info = load_data_file(self.nwa_info) - - self.nwacli.tenant.create_tenant.return_value = \ - self.retval_create_tenant - self.nwacli.l2.create_tenant_nw.return_value = ( - self.retval_create_tenant_nw[0], - load_data_file(self.retval_create_tenant_nw[1]) - ) - self.nwacli.l2.create_vlan.return_value = ( - self.retval_create_vlan[0], - load_data_file(self.retval_create_vlan[1]) - ) - - self.agent.proxy_l2.multi_dc = False - if isinstance(self.gtb_data, six.string_types): - gtb.return_value = load_data_file(self.gtb_data) - else: - gtb.return_value = self.gtb_data - self.agent.proxy_l2.create_general_dev( - context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info - ) - - self.agent.proxy_l2.multi_dc = True - if isinstance(self.gtb_data, six.string_types): - gtb.return_value = load_data_file(self.gtb_data) - else: - gtb.return_value = self.gtb_data - self.agent.proxy_l2.create_general_dev( - context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info - ) - - -class TestAgentProxyL2DeleteGeneralDev(testscenarios.WithScenarios, - base.TestNWAAgentBase): - - scenarios = [ - ('succeed1', - {'retval_delete_tenant': (200, {}), - 'retval_delete_tenant_nw': (200, 'delete_tenant_nw_result.json'), - 'retval_delete_vlan': (200, 'delete_vlan_result.json'), - 'nwa_info': 'delete_general_dev_nwa_info.json', - 'gtb_data': 'nwa_data_one_general_dev.json', - }, - ), - ('succeed2', - {'retval_delete_tenant': (200, {}), - 'retval_delete_tenant_nw': (200, 'delete_tenant_nw_result.json'), - 'retval_delete_vlan': (200, 'delete_vlan_result.json'), - 'nwa_info': 'delete_general_dev_nwa_info.json', - 'gtb_data': 'nwa_data_two_general_dev.json', - }, - ), - ('succeed3', - {'retval_delete_tenant': (200, {}), - 'retval_delete_tenant_nw': (200, 'delete_tenant_nw_result.json'), - 'retval_delete_vlan': (200, 'delete_vlan_result.json'), - 'nwa_info': 'delete_general_dev_nwa_info.json', - 'gtb_data': 'nwa_data_two_port_general_dev.json', - }, - ), - ('fail1', - {'retval_delete_tenant': (200, {}), - 'retval_delete_tenant_nw': (200, 'delete_tenant_nw_result.json'), - 'retval_delete_vlan': (200, 'delete_vlan_result.json'), - 'nwa_info': 'delete_general_dev_nwa_info.json', - 'gtb_data': 'nwa_data_one_general_dev.json', - }, - ), - ('fail2', - {'retval_delete_tenant': (200, {}), - 'retval_delete_tenant_nw': (200, 'delete_tenant_nw_result.json'), - 'retval_delete_vlan': (200, 'delete_vlan_result.json'), - 'nwa_info': 'delete_general_dev_nwa_info.json', - 'gtb_data': 'nwa_data_one_general_dev.json', - }, - ), - ('fail3', - {'retval_delete_tenant': (500, {}), - 'retval_delete_tenant_nw': (200, 'delete_tenant_nw_result.json'), - 'retval_delete_vlan': (200, 'delete_vlan_result.json'), - 'nwa_info': 'delete_general_dev_nwa_info.json', - 'gtb_data': 'nwa_data_one_general_dev.json', - }, - ), - ('fail4', - {'retval_delete_tenant': (200, {}), - 'retval_delete_tenant_nw': (500, 'delete_tenant_nw_result.json'), - 'retval_delete_vlan': (200, 'delete_vlan_result.json'), - 'nwa_info': 'delete_general_dev_nwa_info.json', - 'gtb_data': 'nwa_data_one_general_dev.json', - }, - ), - ('fail5', - {'retval_delete_tenant': (200, {}), - 'retval_delete_tenant_nw': (200, 'delete_tenant_nw_result.json'), - 'retval_delete_vlan': (500, 'delete_vlan_result.json'), - 'nwa_info': 'delete_general_dev_nwa_info.json', - 'gtb_data': 'nwa_data_one_general_dev.json', - }, - ), - ('fail6', - {'retval_delete_tenant': (200, {}), - 'retval_delete_tenant_nw': (200, 'delete_tenant_nw_result.json'), - 'retval_delete_vlan': (200, 'delete_vlan_result.json'), - 'nwa_info': 'delete_general_dev_nwa_info.json', - 'gtb_data': 'nwa_data_two_port_general_dev_fail.json', - }, - ), - ('fail7', - {'retval_delete_tenant': (200, {}), - 'retval_delete_tenant_nw': (200, 'delete_tenant_nw_result.json'), - 'retval_delete_vlan': (200, 'delete_vlan_result.json'), - 'nwa_info': 'delete_general_dev_nwa_info.json', - 'gtb_data': {}, - }, - ), - ] - - @mock.patch('networking_nec.nwa.l2.rpc.tenant_binding_api.' - 'TenantBindingServerRpcApi.get_nwa_tenant_binding') - @mock.patch('networking_nec.nwa.l2.rpc.tenant_binding_api.' - 'TenantBindingServerRpcApi.set_nwa_tenant_binding') - @mock.patch('networking_nec.nwa.agent.proxy_tenant.' - 'AgentProxyTenant.update_tenant_binding') - def test_delete_general_dev(self, utb, stb, gtb): - context = mock.MagicMock() - tenant_id = "844eb55f21e84a289e9c22098d387e5d" - nwa_tenant_id = 'DC1_' + tenant_id - - nwa_info = load_data_file(self.nwa_info) - - self.nwacli.tenant.delete_tenant.return_value = \ - self.retval_delete_tenant - self.nwacli.l2.delete_tenant_nw.return_value = ( - self.retval_delete_tenant_nw[0], - load_data_file(self.retval_delete_tenant_nw[1]) - ) - self.nwacli.l2.delete_vlan.return_value = ( - self.retval_delete_vlan[0], - load_data_file(self.retval_delete_vlan[1]) - ) - - self.agent.proxy_l2.multi_dc = False - if isinstance(self.gtb_data, six.string_types): - gtb.return_value = load_data_file(self.gtb_data) - else: - gtb.return_value = self.gtb_data - self.agent.proxy_l2.delete_general_dev( - context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info - ) - - self.agent.proxy_l2.multi_dc = True - if isinstance(self.gtb_data, six.string_types): - gtb.return_value = load_data_file(self.gtb_data) - else: - gtb.return_value = self.gtb_data - self.agent.proxy_l2.delete_general_dev( - context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info - ) - - -def test_check_segment(): - network_id = 'a94fd0fc-2282-4092-9485-b0f438b0f6c4' - nwa_data = load_data_file('nwa_data_check_segment.json') - proxy_l2.check_segment(network_id, nwa_data) - - -class TestGetResourceGroupName(base.TestNWAAgentBase): - - def setUp(self): - super(TestGetResourceGroupName, self).setUp() - self.nwa_info = load_data_file('nwa_info_get_resource_group_name.json') - self.nwa_data = load_data_file('nwa_data_get_resource_group_name.json') - self.dev_type = 'GeneralDev' - self.resource_group_name = 'OpenStack/DC/HA1' - - def test_resource_group_name_found(self): - self.assertEqual( - proxy_l2.get_resource_group_name(self.nwa_info, self.nwa_data, - self.dev_type), - self.resource_group_name - ) - - def test_mac_not_found(self): - self.nwa_info['port']['mac'] = 'X' - self.assertIsNone( - proxy_l2.get_resource_group_name(self.nwa_info, self.nwa_data, - self.dev_type)) - - def test_network_id_not_found(self): - self.nwa_info['network']['id'] = 'X' - self.assertIsNone( - proxy_l2.get_resource_group_name(self.nwa_info, self.nwa_data, - self.dev_type)) - - def test_device_id_not_found(self): - self.nwa_info['device']['id'] = 'X' - self.assertIsNone( - proxy_l2.get_resource_group_name(self.nwa_info, self.nwa_data, - self.dev_type)) - - def test_dev_type_not_found(self): - dev_type = 'X' - self.assertIsNone( - proxy_l2.get_resource_group_name(self.nwa_info, self.nwa_data, - dev_type)) - - -class TestNECNWANeutronAgentRpc(testscenarios.WithScenarios, - base.TestNWAAgentBase): - - scenarios = [ - # ### GeneralDev: None - # ### add Openstack/DC/HA1 - ('create_general_dev_succeed1', - {'mode': 'create_general_dev', - 'gtb_data': None, - 'nwa_info': 'nwa_info_create_general_dev_succeed1.json'}), - # ### GeneralDev: Openstack/DC/HA1 - # ### add Openstack/DC/HA1 - ('create_general_dev_succeed2', - {'mode': 'create_general_dev', - 'gtb_data': 'nwa_data_create_general_dev_succeed2.json', - 'nwa_info': 'nwa_info_create_general_dev_succeed2.json', - 'mock_wait_agent_notifier': True}), - # ### GeneralDev: Openstack/DC/HA1 - # ### add Openstack/DC/HA2 - ('create_general_dev_succeed3', - {'mode': 'create_general_dev', - 'gtb_data': 'nwa_data_create_general_dev_succeed3.json', - 'nwa_info': 'nwa_info_create_general_dev_succeed3.json'}), - # ### GeneralDev: Openstack/DC/HA1 x1 - # ### del Openstack/DC/HA1 - ('delete_general_dev_succeed1', - {'mode': 'delete_general_dev', - 'gtb_data': 'nwa_data_delete_general_dev_succeed1.json', - 'nwa_info': 'nwa_info_delete_general_dev_succeed1.json'}), - # ### GeneralDev: Openstack/DC/HA1 x2 - # ### del Openstack/DC/HA1 - ('delete_general_dev_succeed2', - {'mode': 'delete_general_dev', - 'gtb_data': 'nwa_data_delete_general_dev_succeed2.json', - 'nwa_info': 'nwa_info_delete_general_dev_succeed2.json'}), - # ### GeneralDev: Openstack/DC/HA1 x1, Openstack/DC/HA2 x1 - # ### del Openstack/DC/HA1 - ('delete_general_dev_succeed3', - {'mode': 'delete_general_dev', - 'gtb_data': 'nwa_data_delete_general_dev_succeed3.json', - 'nwa_info': 'nwa_info_delete_general_dev_succeed3.json'}), - ] - - @mock.patch('networking_nec.nwa.l2.rpc.tenant_binding_api.' - 'TenantBindingServerRpcApi.get_nwa_tenant_binding') - @mock.patch('networking_nec.nwa.agent.proxy_tenant.' - 'AgentProxyTenant.update_tenant_binding') - @mock.patch('networking_nec.nwa.l2.rpc.tenant_binding_api.' - 'TenantBindingServerRpcApi.set_nwa_tenant_binding') - def test_general_dev(self, stb, utb, gtb): - nwa_tenant_id = "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2" - tenant_id = "5d9c51b1d6a34133bb735d4988b309c2" - - context = mock.MagicMock() - stb.return_value = {} - utb.return_value = {'status': 'SUCCEED'} - if self.gtb_data: - gtb.return_value = load_data_file(self.gtb_data) - else: - gtb.return_value = None - nwa_info = load_data_file(self.nwa_info) - - if getattr(self, 'mock_wait_agent_notifier', False): - mock.patch('networking_nec.nwa.agent.proxy_l2.WAIT_AGENT_NOTIFIER', - new=0).start() - - if self.mode == 'create_general_dev': - rc = self.agent.proxy_l2.create_general_dev( - context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info) - self.assertTrue(rc) - elif self.mode == 'delete_general_dev': - rc = self.agent.proxy_l2.delete_general_dev( - context, - tenant_id=tenant_id, - nwa_tenant_id=nwa_tenant_id, - nwa_info=nwa_info) - self.assertTrue(rc) - else: - self.fail('mode %s is invalide' % self.mode) diff --git a/networking_nec/tests/unit/nwa/agent/test_proxy_tenant.py b/networking_nec/tests/unit/nwa/agent/test_proxy_tenant.py deleted file mode 100644 index 6d31aa9..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_proxy_tenant.py +++ /dev/null @@ -1,109 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock - -from networking_nec.nwa.common import exceptions as nwa_exc -from networking_nec.tests.unit.nwa.agent import base - - -class TestAgentProxyTenant(base.TestNWAAgentBase): - - def test__create_tenant_succeed(self): - nwa_tenant_id = 'DC1_844eb55f21e84a289e9c22098d387e5d' - - self.nwacli.tenant.create_tenant.return_value = 200, {} - - body = self.agent.proxy_tenant.create_tenant( - mock.sentinel.context, - nwa_tenant_id=nwa_tenant_id - ) - exp_data = { - 'CreateTenant': True, - 'NWA_tenant_id': 'DC1_844eb55f21e84a289e9c22098d387e5d' - } - self.assertEqual(exp_data, body) - - def test__create_tenant_already_exists(self): - nwa_tenant_id = 'DC1_844eb55f21e84a289e9c22098d387e5d' - self.nwacli.tenant.create_tenant.return_value = 500, {} - body = self.agent.proxy_tenant.create_tenant( - mock.sentinel.context, - nwa_tenant_id=nwa_tenant_id - ) - exp_data = { - 'CreateTenant': True, - 'NWA_tenant_id': 'DC1_844eb55f21e84a289e9c22098d387e5d' - } - self.assertEqual(exp_data, body) - - def test__create_tenant_failed(self): - nwa_tenant_id = 'DC1_844eb55f21e84a289e9c22098d387e5d' - self.nwacli.tenant.create_tenant.return_value = 400, {} - e = self.assertRaises( - nwa_exc.AgentProxyException, - self.agent.proxy_tenant.create_tenant, - mock.sentinel.context, - nwa_tenant_id=nwa_tenant_id - ) - self.assertEqual(400, e.value) - - def test__delete_tenant(self): - nwa_tenant_id = 'DC1_844eb55f21e84a289e9c22098d387e5d' - nwa_data = self.agent.proxy_tenant.delete_tenant( - mock.sentinel.context, - nwa_tenant_id=nwa_tenant_id - ) - self.assertIsInstance(nwa_data, dict) - exp_data = { - 'resultdata': {'LogicalNWName': 'LNW_BusinessVLAN_4000', - 'TenantFWName': 'T1', - 'VlanID': '4000'}, - 'status': 'SUCCEED'} - self.assertDictEqual(exp_data, nwa_data) - - def test__delete_tenant_failed(self): - nwa_tenant_id = 'DC1_844eb55f21e84a289e9c22098d387e5d' - self.nwacli.tenant.delete_tenant.return_value = 500, {} - nwa_data = self.agent.proxy_tenant.delete_tenant( - mock.sentinel.context, - nwa_tenant_id=nwa_tenant_id - ) - self.assertDictEqual({}, nwa_data) - - def test__update_tenant_binding_true(self): - context = mock.MagicMock() - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - nwa_tenant_id = 'DC1_844eb55f21e84a289e9c22098d387e5d', - nwa_data = {} - self.agent.proxy_tenant.update_tenant_binding( - context, - tenant_id, - nwa_tenant_id, - nwa_data, - True - ) - - def test__update_tenant_binding_false(self): - context = mock.MagicMock() - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - nwa_tenant_id = 'DC1_844eb55f21e84a289e9c22098d387e5d', - nwa_data = {} - self.agent.proxy_tenant.update_tenant_binding( - context, - tenant_id, - nwa_tenant_id, - nwa_data, - False - ) diff --git a/networking_nec/tests/unit/nwa/agent/test_server_manager.py b/networking_nec/tests/unit/nwa/agent/test_server_manager.py deleted file mode 100644 index f7114a0..0000000 --- a/networking_nec/tests/unit/nwa/agent/test_server_manager.py +++ /dev/null @@ -1,89 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import eventlet -import mock - -from networking_nec.nwa.agent import server_manager -from networking_nec.nwa.common import constants as nwa_const -from networking_nec.tests.unit.nwa.agent import base - - -class TestAgentServerManager(base.TestNWAAgentBase): - - @mock.patch('oslo_messaging.server.service.ServiceBase') - def test_create_tenant_rpc_server(self, f1): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - rd = self.agent.server_manager.create_tenant_rpc_server(tenant_id) - self.assertIsInstance(rd, dict) - self.assertEqual(rd['result'], 'SUCCESS') - self.assertEqual(rd['tenant_id'], tenant_id) - - def _wait_greenpool_resized(self, *args, **kwargs): - class Server(object): - def start(self): - eventlet.sleep(5) - return Server() - - @mock.patch('oslo_messaging.server.service.ServiceBase') - def test_create_tenant_rpc_server_greenpool_resize(self, mhs): - poolsize = 3 - manager = server_manager.ServerManager(self.agent.topic, self.agent, - size=poolsize) - mhs.side_effect = self._wait_greenpool_resized - for i in range(poolsize + 1): - tenant_id = 'T-%d' % i - rd = manager.create_tenant_rpc_server(tenant_id) - self.assertIsInstance(rd, dict) - self.assertEqual(rd['result'], 'SUCCESS') - self.assertEqual(rd['tenant_id'], tenant_id) - self.assertEqual(manager.greenpool_size, - poolsize + nwa_const.NWA_GREENPOOL_ADD_SIZE) - - @mock.patch('oslo_messaging.rpc.server.get_rpc_server') - @mock.patch('networking_nec.nwa.agent.nwa_agent') - @mock.patch('neutron.common.rpc.Connection') - @mock.patch('neutron.agent.rpc.PluginReportStateAPI') - @mock.patch('networking_nec.nwa.l2.rpc.tenant_binding_api.' - 'TenantBindingServerRpcApi') - def test_create_tenant_rpc_server_fail(self, f1, f2, f3, f4, f5): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - self.agent.server_manager.rpc_servers[tenant_id] = { - 'server': None, - 'topic': "%s-%s" % (self.agent.topic, tenant_id) - } - rd = self.agent.server_manager.create_tenant_rpc_server(tenant_id) - self.assertIsInstance(rd, dict) - self.assertEqual(rd['result'], 'FAILED') - - @mock.patch('oslo_messaging.rpc.server.get_rpc_server') - def test_delete_tenant_rpc_server(self, f1): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - self.agent.server_manager.rpc_servers = { - tenant_id: { - 'server': f1, - 'topic': "%s-%s" % (self.agent.topic, tenant_id) - } - } - rd = self.agent.server_manager.delete_tenant_rpc_server(tenant_id) - self.assertIsInstance(rd, dict) - self.assertEqual(rd['result'], 'SUCCESS') - self.assertEqual(rd['tenant_id'], tenant_id) - - def test_delete_tenant_rpc_server_fail(self): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - self.agent.server_manager.rpc_servers = {} - rd = self.agent.server_manager.delete_tenant_rpc_server(tenant_id) - self.assertIsInstance(rd, dict) - self.assertEqual(rd['result'], 'FAILED') diff --git a/networking_nec/tests/unit/nwa/common/__init__.py b/networking_nec/tests/unit/nwa/common/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/nwa/common/test_config.py b/networking_nec/tests/unit/nwa/common/test_config.py deleted file mode 100644 index 4bd34a2..0000000 --- a/networking_nec/tests/unit/nwa/common/test_config.py +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from neutron.tests import base -from oslo_config import cfg - -# It is required to register nwa options -from networking_nec.nwa.common import config # noqa - - -class TestNWAConfig(base.BaseTestCase): - - def test_section_default_NWA_server_url(self): - self.assertIsNone(cfg.CONF.NWA.server_url) - - def test_section_default_NWA_access_key_id(self): - self.assertIsNone(cfg.CONF.NWA.access_key_id) - - def test_section_default_NWA_secret_access_key(self): - self.assertIsNone(cfg.CONF.NWA.secret_access_key) - - def test_section_default_NWA_resource_group_name(self): - self.assertIsNone(cfg.CONF.NWA.resource_group_name) - - def test_section_default_NWA_region_name(self): - self.assertEqual(cfg.CONF.NWA.region_name, 'RegionOne') - - def test_section_default_NWA_scenario_polling_timer(self): - self.assertEqual(cfg.CONF.NWA.scenario_polling_timer, 10) - - def test_section_default_NWA_scenario_polling_count(self): - self.assertEqual(cfg.CONF.NWA.scenario_polling_count, 6) - - def test_section_default_NWA_use_necnwa_router(self): - self.assertIsInstance(cfg.CONF.NWA.use_necnwa_router, bool) - self.assertTrue(cfg.CONF.NWA.use_necnwa_router) - - def test_section_default_NWA_use_neutron_vlan_id(self): - self.assertIsInstance(cfg.CONF.NWA.use_neutron_vlan_id, bool) - self.assertFalse(cfg.CONF.NWA.use_neutron_vlan_id) - - def test_section_default_NWA_ironic_az_prefix(self): - self.assertEqual(cfg.CONF.NWA.ironic_az_prefix, 'BM_') - - def test_section_default_NWA_use_setting_fw_policy(self): - self.assertFalse(cfg.CONF.NWA.use_setting_fw_policy) - - def test_section_default_NWA_resource_group(self): - self.assertIsNone(cfg.CONF.NWA.resource_group) - - def test_section_default_NWA_resource_group_file(self): - self.assertIsNone(cfg.CONF.NWA.resource_group_file) diff --git a/networking_nec/tests/unit/nwa/common/test_utils.py b/networking_nec/tests/unit/nwa/common/test_utils.py deleted file mode 100644 index 000678c..0000000 --- a/networking_nec/tests/unit/nwa/common/test_utils.py +++ /dev/null @@ -1,87 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base -from oslo_config import cfg -from oslo_serialization import jsonutils - -from networking_nec.nwa.common import utils as nwa_com_utils - - -class TestCommonUtils(base.BaseTestCase): - - def test_get_tenant_info(self): - - class network_context(object): - network = mock.MagicMock() - current = mock.MagicMock() - _plugin = mock.MagicMock() - _plugin_context = mock.MagicMock() - - context = network_context() - context.network.current = {} - context.network.current['tenant_id'] = 'T1' - context.network.current['name'] = 'PublicVLAN_100' - context.network.current['id'] = 'Uuid-PublicVLAN_100' - - tid, nid = nwa_com_utils.get_tenant_info(context) - self.assertEqual(tid, 'T1') - self.assertEqual(nid, 'RegionOneT1') - - def _test_load_json_from_file_from_file(self, json_str=None): - json_data = {'foo': 'bar'} - json_file = self.get_temp_file_path('test.json') - with open(json_file, 'w') as f: - f.write(jsonutils.dumps(json_data)) - ret = nwa_com_utils.load_json_from_file('test', json_file, - json_str, []) - self.assertEqual(json_data, ret) - - def test_load_json_from_file_from_file(self): - self._test_load_json_from_file_from_file() - - def test_load_json_from_file_from_str(self): - json_data = {'foo': 'bar'} - json_str = jsonutils.dumps(json_data) - ret = nwa_com_utils.load_json_from_file('test', None, json_str, []) - self.assertEqual(json_data, ret) - - def test_load_json_from_file_both_specified(self): - # json_file has priority. json_str passed here is not evaluated. - self._test_load_json_from_file_from_file(json_str='invalid') - - def test_load_json_from_file_no_json_file_abspath(self): - json_file = 'test.json' - self.assertRaises(cfg.Error, - nwa_com_utils.load_json_from_file, - 'test', json_file, None, []) - - def test_load_json_from_file_with_invalid_json_file(self): - json_file = self.get_temp_file_path('test.json') - with open(json_file, 'w') as f: - f.write('invalid json data') - self.assertRaises(cfg.Error, - nwa_com_utils.load_json_from_file, - 'test', json_file, None, []) - - def test_load_json_from_file_with_invalid_json_str(self): - self.assertRaises(cfg.Error, - nwa_com_utils.load_json_from_file, - 'test', None, 'invalid json str', []) - - def test_load_json_from_file_default_value(self): - self.assertEqual( - 'test_data', - nwa_com_utils.load_json_from_file('test', None, None, 'test_data')) diff --git a/networking_nec/tests/unit/nwa/l2/__init__.py b/networking_nec/tests/unit/nwa/l2/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/nwa/l2/drivers/__init__.py b/networking_nec/tests/unit/nwa/l2/drivers/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/nwa/l2/drivers/test_mech_necnwa.py b/networking_nec/tests/unit/nwa/l2/drivers/test_mech_necnwa.py deleted file mode 100644 index 99c378b..0000000 --- a/networking_nec/tests/unit/nwa/l2/drivers/test_mech_necnwa.py +++ /dev/null @@ -1,655 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from mock import MagicMock -from mock import patch - -from neutron.common import constants as neutron_const -from neutron import context -from neutron.extensions import providernet as prov_net -from neutron.tests.unit import testlib_api -from neutron_lib import constants -from oslo_config import cfg -from oslo_serialization import jsonutils - -from networking_nec.nwa.common import constants as nwa_const -from networking_nec.nwa.common import exceptions as nwa_exc -from networking_nec.nwa.l2.drivers import mech_necnwa as mech - - -class TestMechNwa(testlib_api.SqlTestCase): - def setUp(self): - super(TestMechNwa, self).setUp() - - class network_context(object): - network = MagicMock() - current = MagicMock() - _plugin = MagicMock() - _plugin_context = MagicMock() - _binding = MagicMock() - - _plugin_context.session = context.get_admin_context().session - - def set_binding(self, segment_id, vif_type, vif_details, - status=None): - self._binding.segment = segment_id - self._binding.vif_type = vif_type - self._binding.vif_details = vif_details - self._new_port_status = status - - self.context = network_context() - self.context.network.current = { - 'tenant_id': 'tenant201', - 'name': 'tenant 201', - 'id': '61', - 'network_type': 'vlan', - 'physical_network': 'Common/App/Pod3', - 'segments': [] - } - self.context._port = { - 'binding:vif_details': {}, - 'binding:vif_type': 'ovs', - 'binding:vnic_type': 'normal', - 'id': 'uuid-port-100', - 'device_owner': constants.DEVICE_OWNER_ROUTER_INTF, - 'device_id': 'uuid-device_id_100', - 'fixed_ips': [ - {'ip_address': '192.168.120.1', - 'subnet_id': '65e6bc06-09b5-4a16-b093-cbc177818b9e'} - ], - 'mac_address': '12:34:56:78:9a:bc' - } - self.context._binding.segment = '' - self.context._binding.vif_type = '' - - self.host_agents = [ - { - "binary": "neutron-openvswitch-agent", - "description": None, - "admin_state_up": True, - "alive": True, - "topic": "N/A", - "host": "harry", - "agent_type": "Open vSwitch agent", - "id": "a01dc42f-0d15-43ff-8f80-22e15cfe715d", - "configurations": { - "tunnel_types": [], - "tunneling_ip": "", - "bridge_mappings": { - "Common/App/Pod3": "br-eth1", - "Common/KVM/Pod1-1": "br-eth2" - }, - "l2_population": False, - "devices": 0 - }, - "alive": True - }, - { - "binary": "neutron-openvswitch-agent", - "description": None, - "admin_state_up": True, - "alive": True, - "topic": "N/A", - "host": "harry", - "agent_type": "Open vSwitch agent", - "id": "a01dc42f-0d15-43ff-8f80-22e15cfe715d", - "configurations": { - "tunnel_types": [], - "tunneling_ip": "", - "bridge_mappings": { - "Common/App/Pod4": "br-eth1" - }, - "l2_population": False, - "devices": 0 - }, - "alive": False - } - ] - self.context.host_agents = MagicMock(return_value=self.host_agents) - - self.network_segments = [ - { - "provider:network_type": "vlan", - "provider:physical_network": "Common/KVM/Pod1-1", - "id": "uuid-1-1", - "provider:segmentation_id": 100 - }, - { - "network_type": "vlan", - "physical_network": "Common/KVM/Pod1-2", - "id": "uuid-1-2", - "provider:segmentation_id": 101 - }, - { - "provider:network_type": "vlan", - "provider:physical_network": "Common/App/Pod3", - "id": "61", - "provider:segmentation_id": 102 - } - ] - self.context.network.network_segments = self.network_segments - self.context.original = MagicMock() - - resource_group = [ - { - "physical_network": "Common/KVM/Pod1-1", - "device_owner": "compute:AZ1", - "ResourceGroupName": "Common/KVM/Pod1-1" - }, - { - "physical_network": "Common/App/Pod3", - "device_owner": "ironic:isolation", - "ResourceGroupName": "Common/App/Pod3" - }, - { - "physical_network": "Common/App/Pod3", - "device_owner": "network:dhcp", - "ResourceGroupName": "Common/App/Pod3" - }, - { - "physical_network": "Common/App/Pod3", - "device_owner": constants.DEVICE_OWNER_ROUTER_GW, - "ResourceGroupName": "Common/App/Pod3" - }, - { - "physical_network": "Common/App/Pod3", - "device_owner": constants.DEVICE_OWNER_ROUTER_INTF, - "ResourceGroupName": "Common/App/Pod3" - } - ] - - fn_resource_group = self.get_temp_file_path('resource_group.json') - with open(fn_resource_group, 'w') as f: - f.write(jsonutils.dumps(resource_group)) - cfg.CONF.set_override('resource_group_file', fn_resource_group, - group='NWA') - - -class TestNECNWAMechanismDriver(TestMechNwa): - def setUp(self): - super(TestNECNWAMechanismDriver, self).setUp() - self.driver = mech.NECNWAMechanismDriver() - self.driver.initialize() - - self.rcode = MagicMock() - self.rcode.value_json = { - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201' - } - - def _get_nwa_tenant_binding(self, value_json): - rcode = MagicMock() - rcode.value_json = value_json - return rcode - - def test_create_port_precommit_compute(self): - self.context._port['device_owner'] = 'compute:DC01_KVM01_ZONE01' - self.driver.create_port_precommit(self.context) - - def test_create_port_precommit_group_not_found(self): - self.driver.resource_groups = [ - { - "physical_network": "Common/App/Pod3", - "device_owner": constants.DEVICE_OWNER_ROUTER_GW, - "ResourceGroupName": "Common/App/Pod3" - } - ] - self.assertRaises(nwa_exc.ResourceGroupNameNotFound, - self.driver.create_port_precommit, self.context) - - @patch('networking_nec.nwa.l2.db_api.add_nwa_tenant_binding') - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_create_port_precommit_owner_router_intf(self, gntb, antb): - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.return_value = self.rcode - self.driver.create_port_precommit(self.context) - - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_62': constants.DEVICE_OWNER_ROUTER_INTF, - 'DEV_uuid-device_id_100_62_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_62_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver.create_port_precommit(self.context) - - @patch('networking_nec.nwa.l2.db_api.add_nwa_tenant_binding') - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_create_port_precommit_owner_router_gw(self, gntb, antb): - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_GW - gntb.return_value = self.rcode - self.driver.create_port_precommit(self.context) - - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_GW - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_62': constants.DEVICE_OWNER_ROUTER_GW, - 'DEV_uuid-device_id_100_62_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_62_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver.create_port_precommit(self.context) - - def test_update_port_precommit(self): - for device_owner in (constants.DEVICE_OWNER_ROUTER_INTF, - constants.DEVICE_OWNER_ROUTER_GW): - self.context._port['device_owner'] = device_owner - self.driver.update_port_precommit(self.context) - - @patch('networking_nec.nwa.l2.utils.portcontext_to_nwa_info') - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_update_port_precommit_current_none(self, gntb, ptni): - self.context.current = self.context._port - self.context.current['device_id'] = None - self.context.current['device_owner'] = None - self.context.original[ - 'device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - self.context.original['device_id'] = 'uuid-device_id_000' - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100_61': constants.DEVICE_OWNER_ROUTER_INTF, - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc'} - ) - ptni.return_value = { - 'tenant_id': 'Tenant1', - 'nwa_tenant_id': 'RegionOnetenant201', - 'resource_group_name': 'Common/App/Pod3', - 'physical_network': 'Common/App/Pod3'} - self.driver.update_port_precommit(self.context) - - @patch('networking_nec.nwa.l2.db_api.set_nwa_tenant_binding') - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_delete_port_precommit_owner_router_interface(self, gntb, sntb): - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.return_value = self.rcode - self.driver.delete_port_precommit(self.context) - - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100_61': constants.DEVICE_OWNER_ROUTER_INTF, - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver.delete_port_precommit(self.context) - - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100_61': constants.DEVICE_OWNER_ROUTER_INTF, - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver.delete_port_precommit(self.context) - - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100_61': constants.DEVICE_OWNER_ROUTER_INTF, - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc', - 'DEV_uuid-device_id_100_62_ip_address': '192.168.120.2'} - ) - self.driver.delete_port_precommit(self.context) - - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100_61': 'net001', - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc', - 'DEV_uuid-device_id_100_62_ip_address': '192.168.120.2'} - ) - self.driver.delete_port_precommit(self.context) - - @patch('networking_nec.nwa.l2.db_api.set_nwa_tenant_binding') - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_delete_port_precommit_owner_network_floatingip(self, gntb, sntb): - self.context._port['device_owner'] = 'network:floatingip' - gntb.return_value = self.rcode - router_intf = constants.DEVICE_OWNER_ROUTER_INTF - self.context._port['device_owner'] = router_intf - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_device_owner': router_intf, - 'DEV_uuid-device_id_100_61': 'net001', - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc', - 'DEV_uuid-device_id_101_61': '12'} - ) - self.driver.delete_port_precommit(self.context) - - self.context._port['device_owner'] = router_intf - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_device_owner': router_intf, - 'DEV_uuid-device_id_100_61': 'net001', - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver.delete_port_precommit(self.context) - - self.context._port['device_owner'] = router_intf - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_device_owner': router_intf, - 'DEV_uuid-device_id_100_61': 'net001', - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver.delete_port_precommit(self.context) - - @patch('networking_nec.nwa.l2.db_api.set_nwa_tenant_binding') - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_delete_port_precommit_owner_router_gateway(self, gntb, sntb): - router_gw = constants.DEVICE_OWNER_ROUTER_GW - self.context._port['device_owner'] = router_gw - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': 1, - 'CreateTenantNW': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_device_owner': router_gw, - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61': 'public001', - 'DEV_uuid-device_id_100_61_ip_address': '172.16.1.23', - 'DEV_uuid-device_id_100_63_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver.delete_port_precommit(self.context) - - @patch('networking_nec.nwa.l2.db_api.set_nwa_tenant_binding') - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_delete_port_precommit_owner_floatingip(self, gntb, sntb): - floatingip = constants.DEVICE_OWNER_FLOATINGIP - self.context._port['device_owner'] = floatingip - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': 1, - 'CreateTenantNW': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_device_owner': floatingip, - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61': 'public001', - 'DEV_uuid-device_id_100_61_ip_address': '172.16.1.23', - 'DEV_uuid-device_id_100_63_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver.delete_port_precommit(self.context) - - @patch('networking_nec.nwa.l2.db_api.set_nwa_tenant_binding') - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_delete_port_precommit_owner_none(self, gntb, sntb): - self.context._port['device_owner'] = '' - self.context._port['device_id'] = '' - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': 1, - 'CreateTenantNW': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_device_owner': '', - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61': 'public001', - 'DEV_uuid-device_id_100_61_ip_address': '172.16.1.23', - 'DEV_uuid-device_id_100_63_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver.delete_port_precommit(self.context) - - @patch('networking_nec.nwa.l2.utils.portcontext_to_nwa_info') - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_delete_port_precommit_owner_dhcp(self, gntb, ptni): - self.context._port['device_owner'] = constants.DEVICE_OWNER_DHCP - self.context._port[ - 'device_id'] = neutron_const.DEVICE_ID_RESERVED_DHCP_PORT - self.context._port['binding:host_id'] = 'myhost' - - # _revert_dhcp_agent_device - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': 1, - 'CreateTenantNW': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_device_owner': constants.DEVICE_OWNER_DHCP, - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_TFW, - 'DEV_uuid-device_id_100_61': 'public001', - 'DEV_uuid-device_id_100_61_ip_address': '172.16.1.23', - 'DEV_uuid-device_id_100_63_mac_address': '12:34:56:78:9a:bc'} - ) - ptni.return_value = { - 'tenant_id': 'Tenant1', - 'nwa_tenant_id': 'RegionOnetenant201', - 'device': { - 'owner': constants.DEVICE_OWNER_DHCP, - 'id': 'device_id'}, - 'resource_group_name': 'Common/App/Pod3', - 'physical_network': 'Common/App/Pod3'} - self.driver.delete_port_precommit(self.context) - - @patch('networking_nec.nwa.l2.db_api.set_nwa_tenant_binding') - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_delete_port_precommit_owner_compute_az(self, gntb, sntb): - # 1 net 1 port(compute:AZ1) - self.context.current = self.context._port - self.context.current['device_owner'] = 'compute:AZ1' - self.context._port['device_owner'] = 'compute:AZ1' - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_device_owner': 'compute:AZ1', - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_GDV, - 'DEV_uuid-device_id_100_61': 'net001', - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver.delete_port_precommit(self.context) - - # 1 net 2 port(compute:AZ1) - self.context._port['device_owner'] = 'compute:AZ1' - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_device_owner': 'compute:AZ1', - 'DEV_uuid-device_id_100_61_TYPE': nwa_const.NWA_DEVICE_GDV, - 'DEV_uuid-device_id_100_61': 'net001', - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc', - 'DEV_uuid-device_id_200': 'device_id', - 'DEV_uuid-device_id_200_device_owner': 'compute:AZ1', - 'DEV_uuid-device_id_200_61_TYPE': nwa_const.NWA_DEVICE_GDV, - 'DEV_uuid-device_id_200_61': 'net001', - 'DEV_uuid-device_id_200_61_ip_address': '192.168.120.2', - 'DEV_uuid-device_id_200_61_mac_address': 'fe:34:56:78:9a:bc'} - ) - self.driver.delete_port_precommit(self.context) - - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_try_to_bind_segment_for_agent(self, gntb): - # in segment - self.context._port['device_owner'] = 'network:dhcp' - self.context._port['fixed_ips'] = [] - self.context.current = self.context._port - rb = self.driver.try_to_bind_segment_for_agent( - self.context, self.network_segments[1], self.host_agents[0]) - self.assertEqual(rb, True) - - # in physical_network - self.context.network.current[ - 'provider:physical_network'] = 'Common/App/Pod3' - self.context.network.current['provider:segmentation_id'] = 199 - self.context.current = self.context._port - rb = self.driver.try_to_bind_segment_for_agent( - self.context, self.network_segments[1], self.host_agents[0]) - self.assertEqual(rb, True) - - # not in segment - rb = self.driver.try_to_bind_segment_for_agent( - self.context, self.network_segments[1], self.host_agents[1]) - self.assertEqual(rb, False) - - # device_owner is router_gw - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_GW - rb = self.driver.try_to_bind_segment_for_agent( - self.context, self.network_segments[1], self.host_agents[0]) - self.assertEqual(rb, False) - - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_try_to_bind_segment_for_agent_in_segments(self, gntb): - # in segment - self.context._port['device_owner'] = 'network:dhcp' - self.context.network.current['segments'] = self.network_segments - self.context.current = self.context._port - rb = self.driver.try_to_bind_segment_for_agent( - self.context, self.network_segments[2], self.host_agents[0]) - self.assertEqual(rb, True) - - def test__find_nwa_physical_network(self): - pod3_eth1 = self.host_agents[0] - physnet = self.driver._find_nwa_physical_network(self.context, - pod3_eth1) - self.assertEqual(physnet, 'Common/App/Pod3') - - def test__find_nwa_physical_network_no_match(self): - physnet = self.driver._find_nwa_physical_network(self.context, - self.host_agents[1]) - self.assertIsNone(physnet) - - def test__find_nwa_physical_network_agent_none(self): - physnet = self.driver._find_nwa_physical_network(self.context) - self.assertEqual(physnet, 'Common/App/Pod3') - - @patch('neutron.db.segments_db.get_dynamic_segment') - def test__bind_segment_to_vif_type_dummy_segment_none(self, gds): - gds.return_value = None - physnet = 'Common/App/Pod3' - rd = self.driver._bind_segment_to_vif_type(self.context, physnet) - self.assertIsNone(rd) - - @patch('neutron.db.segments_db.get_dynamic_segment') - @patch('neutron.db.segments_db.add_network_segment') - def test__bind_segment_to_vif_type_dummy_segment_exists(self, ans, gds): - gds.return_value = self.network_segments[1] - physnet = 'Common/KVM/Pod1-2' - self.driver._bind_segment_to_vif_type(self.context, physnet) - self.assertEqual(0, ans.call_count) - - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def _test__bind_port_nwa(self, gntb): - # if prov_net.PHYSICAL_NETWORK in self.context.network.current: - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - self.context.network.current[ - 'provider:physical_network'] = 'Common/App/Pod3' - self.context.network.current['provider:segmentation_id'] = 199 - gntb.return_value = None - self.driver._bind_port_nwa(self.context) - - # else: - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - self.context.network.current['segments'] = self.network_segments - gntb.return_value = None - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.return_value = None - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_GW - gntb.return_value = None - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.return_value = self._get_nwa_tenant_binding({ - 'CreateTenant': True, - 'NWA_tenant_id': 'RegionOnetenant201', - 'DEV_uuid-device_id_100': 'device_id', - 'DEV_uuid-device_id_100_61': constants.DEVICE_OWNER_ROUTER_INTF, - 'DEV_uuid-device_id_100_61_ip_address': '192.168.120.1', - 'DEV_uuid-device_id_100_61_mac_address': '12:34:56:78:9a:bc'} - ) - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.return_value = self.rcode - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = 'network:floatingip' - gntb.return_value = self.rcode - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = 'ironic:isolation' - gntb.return_value = self.rcode - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = 'ironic:isolation' - gntb.return_value = self.rcode - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = 'compute:BM_001' - gntb.return_value = self.rcode - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = 'compute:BM_001' - gntb.return_value = self.rcode - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = 'compute:az_001' - gntb.return_value = self.rcode - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = 'compute:az_001' - gntb.return_value = self.rcode - self.driver._bind_port_nwa(self.context) - - self.context._port['device_owner'] = 'compute:AZ1' - gntb.return_value = self.rcode - self.context.network.current.pop(prov_net.PHYSICAL_NETWORK) - self.driver._bind_port_nwa(self.context) - - # Exception - self.context._port['device_owner'] = constants.DEVICE_OWNER_ROUTER_INTF - gntb.side_effect = Exception - self.driver._bind_port_nwa(self.context) - - @patch('neutron.db.segments_db.get_dynamic_segment') - @patch('neutron.db.segments_db.delete_network_segment') - def test__l2_delete_segment(self, dns, gds): - gds.return_value = None - self.driver._l2_delete_segment(self.context, MagicMock()) - self.assertEqual(0, dns.call_count) - - dns.mock_reset() - gds.return_value = {'id': 'ID-100'} - self.driver._l2_delete_segment(self.context, MagicMock()) - self.assertEqual(1, dns.call_count) diff --git a/networking_nec/tests/unit/nwa/l2/rpc/__init__.py b/networking_nec/tests/unit/nwa/l2/rpc/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/nwa/l2/rpc/test_ml2_server_callback.py b/networking_nec/tests/unit/nwa/l2/rpc/test_ml2_server_callback.py deleted file mode 100644 index b14bd0f..0000000 --- a/networking_nec/tests/unit/nwa/l2/rpc/test_ml2_server_callback.py +++ /dev/null @@ -1,244 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.extensions import portbindings -from neutron.tests import base -from neutron_lib import constants - -from networking_nec.nwa.l2 import plugin -from networking_nec.nwa.l2.rpc import ml2_server_callback - - -class TestNECNWAServerRpcCallbacks(base.BaseTestCase): - - @mock.patch('networking_nec.nwa.l2.plugin.NECNWAL2Plugin._setup_rpc') - @mock.patch('neutron.plugins.ml2.managers.TypeManager.initialize') - def setUp(self, f1, f2): - super(TestNECNWAServerRpcCallbacks, self).setUp() - notifier = mock.MagicMock() - type_manager = mock.MagicMock() - - self.rpc = ml2_server_callback.NwaML2ServerRpcCallbacks( - notifier, type_manager) - - f1.return_value = None - f2.return_value = None - self.l2_plugin = plugin.NECNWAL2Plugin() - - class PortBinding(object): - segment = {'segmentation_id': 1000, - portbindings.VIF_TYPE: 'vlan'} - vif_type = None - segment_id = 'seg-id-1000' - - class PortContext(object): - bound_segment = None - current = {'network_id': 'a70fed9f-52b8-4290-a3ed-cdcc837b78d8', - portbindings.VIF_TYPE: 'vlan', - 'admin_state_up': True, - 'status': constants.PORT_STATUS_DOWN, - 'mac_address': '00:0c:29:1f:f5:1c', - 'fixed_ips': '192.168.1.1', - 'device_owner': 'compute:DC01_KVM01_ZONE01', - portbindings.PROFILE: 'dummy'} - - self.port_binding = PortBinding - self.port_context = PortContext - self.port_context.bottom_bound_segment = mock.MagicMock() - self.port_context.current = mock.MagicMock() - self.port_context.network = mock.MagicMock() - - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin.get_bound_port_context') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin._device_to_port_id') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - def test_get_device_details(self, f1, f2, f3): - rpc_context = mock.MagicMock() - f1.return_value = self.l2_plugin - f2.return_value = None - f3.return_value = None - - device = self.rpc.get_device_details(rpc_context, kwargs={'test': - "sample"}) - self.assertTrue(device) - - @mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.update_port_status') - @mock.patch('neutron.db.segments_db.get_network_segments') - @mock.patch('neutron.db.api.get_session') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin.get_bound_port_context') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin._device_to_port_id') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - def test_get_device_details_no_segment(self, f1, f2, f3, f4, f5, f6): - rpc_context = mock.MagicMock() - f1.return_value = self.l2_plugin - f2.return_value = None - f3.current = True - f4.begin.return_value = None - f5.return_value = None - - device = self.rpc.get_device_details(rpc_context, kwargs={'test': - "sample"}) - self.assertTrue(device) - - @mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.update_port_status') - @mock.patch('neutron.db.segments_db.get_network_segments') - @mock.patch('neutron.db.api.get_session') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin.get_bound_port_context') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin._device_to_port_id') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - def test_get_device_details_multi_segment(self, f1, f2, f3, f4, f5, f6): - rpc_context = mock.MagicMock() - f1.return_value = self.l2_plugin - f2.return_value = None - f3.current = True - f4.begin.return_value = None - f5.return_value = [{}, {}] - - device = self.rpc.get_device_details(rpc_context, kwargs={'test': - "sample"}) - self.assertTrue(device) - - @mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.update_port_status') - @mock.patch('neutron.db.segments_db.get_network_segments') - @mock.patch('neutron.db.api.get_session') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin.get_bound_port_context') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin._device_to_port_id') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - def test_get_device_details_segment_size_miss_match(self, f1, f2, f3, f4, - f5, f6): - rpc_context = mock.MagicMock() - f1.return_value = self.l2_plugin - f2.return_value = None - f3.current = True - f4.begin.return_value = None - f5.return_value = [{}, {}] - - self.rpc.get_device_details(rpc_context, kwargs={'test': "sample"}) - - @mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.update_port_status') - @mock.patch('neutron.db.segments_db.get_network_segments') - @mock.patch('neutron.db.api.get_session') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin.get_bound_port_context') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin._device_to_port_id') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - def test_get_device_details_segment_zero(self, f1, f2, f3, f4, f5, f6): - rpc_context = mock.MagicMock() - f1.return_value = self.l2_plugin - f2.return_value = None - f3.current = True - f3.bottom_bound_segment = mock.MagicMock() - f4.begin.return_value = None - f5.return_value = [{'segmentation_id': 0}] - device = self.rpc.get_device_details(rpc_context, kwargs={'test': - "sample"}) - self.assertIsInstance(device, dict) - - @mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.update_port_status') - @mock.patch('networking_nec.nwa.l2.db_api.ensure_port_binding') - @mock.patch('neutron.db.segments_db.get_network_segments') - @mock.patch('neutron.db.api.get_session') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin.get_bound_port_context') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin._device_to_port_id') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - def test_get_device_details_segment_not_binding(self, f1, f2, f3, f4, f5, - f6, f7): - rpc_context = mock.MagicMock() - f1.return_value = self.l2_plugin - f2.return_value = None - f3.current = True - f4.begin.return_value = None - f5.return_value = [{'segmentation_id': 1000}] - - class PortBinding(object): - segment = None - vif_type = None - segment_id = None - - f6.return_value = PortBinding() - - device = self.rpc.get_device_details(rpc_context, kwargs={'test': - "sample"}) - self.assertTrue(device) - - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin.update_port_status') - @mock.patch('networking_nec.nwa.l2.db_api.ensure_port_binding') - @mock.patch('neutron.db.segments_db.get_network_segments') - @mock.patch('neutron.db.api.get_session') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin.get_bound_port_context') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin._device_to_port_id') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - def test_get_device_details_bound_segment(self, f1, f2, f3, f4, f5, - f6, f7): - - rpc_context = mock.MagicMock() - f1.return_value = self.l2_plugin - f2.return_value = None - f3.return_value = self.port_context - f4.begin.return_value = None - f5.return_value = [{'segmentation_id': 1000, - 'network_type': 'vlan', - 'physical_network': 'OpenStack/DC1/APP'}] - f6.return_value = self.port_binding - device = self.rpc.get_device_details(rpc_context, - kwargs={'test': "sample"}) - self.assertTrue(device) - - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin.update_port_status') - @mock.patch('networking_nec.nwa.l2.db_api.ensure_port_binding') - @mock.patch('neutron.db.segments_db.get_network_segments') - @mock.patch('neutron.db.api.get_session') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin.get_bound_port_context') - @mock.patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin._device_to_port_id') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - def test_get_device_details_port_state_change(self, f1, f2, f3, f4, f5, - f6, f7): - rpc_context = mock.MagicMock() - f1.return_value = self.l2_plugin - f2.return_value = None - - self.port_context.bound_segment = 'dummy segment' - f3.return_value = self.port_context - f4.begin.return_value = None - f5.return_value = [{'segmentation_id': 1000, - 'network_type': 'vlan', - 'physical_network': 'OpenStack/DC1/APP'}] - f6.return_value = self.port_binding - - device = self.rpc.get_device_details(rpc_context, - kwargs={'test': "sample"}) - self.assertTrue(device) - - @mock.patch('neutron_lib.plugins.directory.get_plugin') - def test_update_device_up(self, dummy1): - rpc_context = mock.MagicMock() - dummy1.return_value = None - self.rpc.update_device_up(rpc_context) diff --git a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_agent_api.py b/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_agent_api.py deleted file mode 100644 index 3bfb9ab..0000000 --- a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_agent_api.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base - -from networking_nec.nwa.l2.rpc import nwa_agent_api - - -class TestNECNWAAgentApi(base.BaseTestCase): - - @mock.patch('neutron.common.rpc.get_client') - def setUp(self, f1): - super(TestNECNWAAgentApi, self).setUp() - self.proxy = nwa_agent_api.NECNWAAgentApi("dummy-topic") - self.context = mock.MagicMock() - - def test_create_server(self): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - self.proxy.create_server(self.context, tenant_id) - - def test_delete_server(self): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - self.proxy.delete_server(self.context, tenant_id) - - def test_get_nwa_rpc_servers(self): - self.proxy.get_nwa_rpc_servers(self.context) diff --git a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_agent_callback.py b/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_agent_callback.py deleted file mode 100644 index 7c89a52..0000000 --- a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_agent_callback.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base - -from networking_nec.nwa.l2.rpc import nwa_agent_callback - - -class TestNECNWAAgentRpcCallback(base.BaseTestCase): - - def setUp(self): - super(TestNECNWAAgentRpcCallback, self).setUp() - self.context = mock.MagicMock() - self.agent = mock.MagicMock() - self.callback = nwa_agent_callback.NwaAgentRpcCallback( - self.context, self.agent - ) - - def test_get_nwa_rpc_server(self): - rd = self.callback.get_nwa_rpc_servers(self.context, kwargs={}) - self.assertIsInstance(rd, dict) - - def test_create_server(self): - params = {'tenant_id': 'T1'} - rd = self.callback.create_server(self.context, kwargs=params) - self.assertIsNotNone(rd) - - def test_delete_server(self): - params = {'tenant_id': 'T1'} - rd = self.callback.delete_server(self.context, kwargs=params) - self.assertIsNotNone(rd) diff --git a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_l2_server_api.py b/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_l2_server_api.py deleted file mode 100644 index 2a50887..0000000 --- a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_l2_server_api.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base - -from networking_nec.nwa.l2.rpc import nwa_l2_server_api - - -class TestNwaL2ServerApi(base.BaseTestCase): - - @mock.patch('neutron.common.rpc.get_client') - def setUp(self, f1): - super(TestNwaL2ServerApi, self).setUp() - self.proxy = nwa_l2_server_api.NwaL2ServerRpcApi("dummy-topic") - self.context = mock.MagicMock() - - def test_release_dynamic_segment_from_agent(self): - cctxt = mock.MagicMock() - self.proxy.client.prepare.return_value = cctxt - self.proxy.release_dynamic_segment_from_agent( - self.context, 'physical_network', 'network_id') - self.assertEqual(1, cctxt.call.call_count) diff --git a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_l2_server_callback.py b/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_l2_server_callback.py deleted file mode 100644 index 09fa806..0000000 --- a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_l2_server_callback.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base - -from networking_nec.nwa.l2.rpc import nwa_l2_server_callback - - -class TestNwaL2ServerRpcCallback(base.BaseTestCase): - - def setUp(self): - super(TestNwaL2ServerRpcCallback, self).setUp() - self.callback = nwa_l2_server_callback.NwaL2ServerRpcCallback() - self.context = mock.MagicMock() - - @mock.patch('neutron.db.api.get_session') - @mock.patch('neutron.db.segments_db.get_dynamic_segment') - @mock.patch('neutron.db.segments_db.delete_network_segment') - def test_release_dynamic_segment_from_agent(self, dns, gds, gs): - del_segment = {'segmentation_id': 0, 'id': 'ID-0'} - gds.return_value = del_segment - self.callback.release_dynamic_segment_from_agent( - self.context, - network_id='network-id', - physical_network='physical-network') - self.assertEqual(0, dns.call_count) - - dns.reset_mock() - del_segment = {'segmentation_id': 4000, 'id': 'ID-4000'} - gds.return_value = del_segment - self.callback.release_dynamic_segment_from_agent( - self.context, - network_id='network-id', - physical_network='physical-network') - self.assertEqual(1, dns.call_count) diff --git a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_proxy_api.py b/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_proxy_api.py deleted file mode 100644 index c56a015..0000000 --- a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_proxy_api.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base - -from networking_nec.nwa.l2.rpc import nwa_proxy_api - - -class TestNECNWAProxyApi(base.BaseTestCase): - - @mock.patch('neutron.common.rpc.get_client') - def setUp(self, f1): - super(TestNECNWAProxyApi, self).setUp() - self.proxy = nwa_proxy_api.NECNWAProxyApi("dummy-topic", - "dummy-tenant-id") - self.context = mock.MagicMock() - - def test__send_msg_true(self): - msg = mock.MagicMock() - self.assertTrue( - self.proxy._send_msg(self.context, msg, blocking=True) - ) - - def test__send_msg_false(self): - msg = mock.MagicMock() - self.assertTrue( - self.proxy._send_msg(self.context, msg, blocking=False) - ) - - def test_create_general_dev(self): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - nwa_tenant_id = 'DC1_' + tenant_id - nwa_info = {} - self.proxy.create_general_dev(self.context, tenant_id, nwa_tenant_id, - nwa_info) - - def test_delete_general_dev(self): - tenant_id = '844eb55f21e84a289e9c22098d387e5d' - nwa_tenant_id = 'DC1_' + tenant_id - nwa_info = {} - self.proxy.delete_general_dev(self.context, tenant_id, nwa_tenant_id, - nwa_info) diff --git a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_proxy_callback.py b/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_proxy_callback.py deleted file mode 100644 index b3f3b23..0000000 --- a/networking_nec/tests/unit/nwa/l2/rpc/test_nwa_proxy_callback.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base - -from networking_nec.nwa.l2.rpc import nwa_proxy_callback - - -class TestNECNWAProxyCallback(base.BaseTestCase): - - def setUp(self): - super(TestNECNWAProxyCallback, self).setUp() - self.context = mock.MagicMock() - self.agent = mock.MagicMock() - self.callback = nwa_proxy_callback.NwaProxyCallback(self.context, - self.agent) - - def test_create_general_dev(self): - params = {} - self.callback.create_general_dev(self.context, kwargs=params) - - def test_delete_general_dev(self): - params = {} - self.callback.delete_general_dev(self.context, kwargs=params) diff --git a/networking_nec/tests/unit/nwa/l2/rpc/test_tenant_binding_callback.py b/networking_nec/tests/unit/nwa/l2/rpc/test_tenant_binding_callback.py deleted file mode 100644 index d5820d7..0000000 --- a/networking_nec/tests/unit/nwa/l2/rpc/test_tenant_binding_callback.py +++ /dev/null @@ -1,82 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base - -from networking_nec.nwa.l2.rpc import tenant_binding_callback as tenant_cb - - -class TestTenantBindingServerRpcCallback(base.BaseTestCase): - - def setUp(self): - super(TestTenantBindingServerRpcCallback, self).setUp() - self.rpc_context = mock.MagicMock() - self.callback = tenant_cb.TenantBindingServerRpcCallback() - - @mock.patch('neutron.db.api.get_session') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - @mock.patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_queues') - def test_update_tenant_rpc_servers_both_empty(self, gntq, gs, gp): - gntq.return_value = [] - kwargs = {'servers': []} - rd = self.callback.update_tenant_rpc_servers(self.rpc_context, - **kwargs) - self.assertEqual(rd, {'servers': []}) - - @mock.patch('neutron.db.api.get_session') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - @mock.patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_queues') - def test_update_tenant_rpc_servers_both_equal(self, gntq, plugin, gs): - q1 = mock.MagicMock() - q1.tenant_id = 'T-1' - gntq.return_value = [q1] - kwargs = {'servers': [{'tenant_id': 'T-1'}]} - rd = self.callback.update_tenant_rpc_servers(self.rpc_context, - **kwargs) - self.assertEqual(rd, {'servers': []}) - self.assertEqual(plugin.nwa_rpc.create_server.call_count, 0) - self.assertEqual(plugin.nwa_rpc.delete_server.call_count, 0) - - @mock.patch('neutron.db.api.get_session') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - @mock.patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_queues') - def test_update_tenant_rpc_servers_create(self, gntq, gp, gs): - q1 = mock.MagicMock() - q1.tenant_id = 'T-2' - gntq.return_value = [q1] - plugin = mock.MagicMock() - gp.return_value = plugin - plugin.nwa_rpc.create_server = mock.MagicMock() - kwargs = {'servers': []} - rd = self.callback.update_tenant_rpc_servers(self.rpc_context, - **kwargs) - self.assertEqual(rd, {'servers': [{'tenant_id': 'T-2'}]}) - self.assertEqual(plugin.nwa_rpc.create_server.call_count, 1) - self.assertEqual(plugin.nwa_rpc.delete_server.call_count, 0) - - @mock.patch('neutron.db.api.get_session') - @mock.patch('neutron_lib.plugins.directory.get_plugin') - @mock.patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_queues') - def test_update_tenant_rpc_servers_delete(self, gntq, gp, gs): - gntq.return_value = [] - plugin = mock.MagicMock() - gp.return_value = plugin - plugin.nwa_rpc.create_server = mock.MagicMock() - kwargs = {'servers': [{'tenant_id': 'T-1'}]} - rd = self.callback.update_tenant_rpc_servers(self.rpc_context, - **kwargs) - self.assertEqual(rd, {'servers': []}) - self.assertEqual(plugin.nwa_rpc.create_server.call_count, 0) - self.assertEqual(plugin.nwa_rpc.delete_server.call_count, 1) diff --git a/networking_nec/tests/unit/nwa/l2/test_db_api.py b/networking_nec/tests/unit/nwa/l2/test_db_api.py deleted file mode 100644 index f669e37..0000000 --- a/networking_nec/tests/unit/nwa/l2/test_db_api.py +++ /dev/null @@ -1,450 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from mock import MagicMock -from mock import patch -from sqlalchemy.orm.exc import NoResultFound -import testscenarios - -from neutron import context -from neutron.tests import base -from neutron.tests.unit import testlib_api - -from networking_nec.nwa.l2 import db_api - -TENANT_ID = 'T1' -NWA_TENANT_ID = 'NWA-T1' -JSON_VALUE = {'a': 1} -VALUE_JSON = {'a': 1} -NETWORK_ID = 'uuid-network_id-1' -DEVICE_ID = 'uuid-device_id-1' -PHYSICAL_NETWORK = 'DC1/Pod1-1' -NETWORK_NAME = 'PublicVLAN_1001' -DEVICE_OWNER = 'network:router_interface' -IP_ADDRESS = '10.0.0.1' -MAC_ADDRESS = '12:34:56:78:9a' -CIDR = 24 - - -class itemval(base.BaseTestCase): - value_json = None - - def __init__(self, v): - self.value_json = v - - def __repr__(self): - return str(self.value_json) - - -class TestNWATenantBinding(base.BaseTestCase): - def test_nwa_tenant_binding(self): - ntb = db_api.NWATenantBinding('T1', 'NWA-T1', {'key': 'value'}) - self.assertIsNotNone(ntb) - self.assertEqual(str(ntb), - "") - - -class TestAddNwaTenantBinding(testlib_api.SqlTestCaseLight): - nwa_tenant1 = 'NWA01' - nwa_tenant2 = 'NWA02' - tenant1 = 'ffffffffff0000000000000000000001' - tenant2 = 'ffffffffff0000000000000000000002' - key1 = 'Key-1' - key2 = 'Key-2' - value1 = 'Value-1' - value2 = 'Value-2' - value_json1 = {key1: value1} - value_json2 = {key2: value2} - - def setUp(self): - super(TestAddNwaTenantBinding, self).setUp() - self.ssn = context.get_admin_context().session - - def get_t1(self): - return db_api.get_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant1) - - def add_t1(self, value_json): - return db_api.add_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant1, value_json) - - def del_t1(self): - return db_api.del_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant1) - - def test_add_del(self): - self.assertIsNone(self.get_t1()) # not found - self.assertTrue(self.add_t1(self.value_json1)) - - # already added - self.assertFalse(self.add_t1(self.value_json2)) - self.assertEqual(self.get_t1().value_json, self.value_json1) - - self.assertTrue(self.del_t1()) - # already deleted - self.assertFalse(self.del_t1()) - self.assertIsNone(self.get_t1()) - - def test_add_del_tenant_id_difference(self): - self.assertIsNone(self.get_t1()) # not found - self.assertTrue(self.add_t1(self.value_json1)) - - self.assertFalse( # already exits - db_api.add_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant2, - self.value_json2)) - self.assertTrue( # diffrent tenant id - db_api.add_nwa_tenant_binding( - self.ssn, self.tenant2, self.nwa_tenant1, - self.value_json2)) - - self.assertEqual(self.get_t1().value_json, self.value_json1) - self.assertEqual( - db_api.get_nwa_tenant_binding( - self.ssn, self.tenant2, self.nwa_tenant1).value_json, - self.value_json2) - - self.assertTrue(self.del_t1()) - self.assertEqual( # no effect - db_api.get_nwa_tenant_binding( - self.ssn, self.tenant2, self.nwa_tenant1).value_json, - self.value_json2) - - def test_tenant_id_no_match(self): - self.assertIsNone(self.get_t1()) # not found - self.assertTrue( # succeed - db_api.add_nwa_tenant_binding( - self.ssn, self.tenant2, self.nwa_tenant1, - {self.key1: self.value1})) - self.assertFalse( # not found - db_api.get_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant1)) - self.assertEqual( # get same value - db_api.get_nwa_tenant_binding( - self.ssn, self.tenant2, self.nwa_tenant1).value_json, - {self.key1: self.value1}) - - def test_nwa_tenant_id_no_match(self): - self.assertIsNone(self.get_t1()) # not found - self.assertTrue( # succeed - db_api.add_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant2, - {self.key2: self.value2})) - self.assertFalse( # not found - db_api.get_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant1)) - self.assertEqual( # get same value - db_api.get_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant2).value_json, - {self.key2: self.value2}) - - def test_value_is_empty_string(self): - self.assertTrue( - db_api.add_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant1, {self.key1: ''})) - self.assertEqual( - db_api.get_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant1).value_json, - {self.key1: ''}) - - def test_value_is_none(self): - self.assertTrue( - db_api.add_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant1, {self.key1: None})) - self.assertEqual( - db_api.get_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant1).value_json, - {self.key1: u''}) - - def test_value_is_true(self): - self.assertTrue( - db_api.add_nwa_tenant_binding( - self.ssn, self.tenant2, self.nwa_tenant1, {self.key1: True})) - self.assertEqual( - db_api.get_nwa_tenant_binding( - self.ssn, self.tenant2, self.nwa_tenant1).value_json, - {self.key1: True}) - - def test_value_is_false(self): - self.assertTrue( - db_api.add_nwa_tenant_binding( - self.ssn, self.tenant2, self.nwa_tenant2, {self.key1: False})) - self.assertEqual( - db_api.get_nwa_tenant_binding( - self.ssn, self.tenant2, self.nwa_tenant2).value_json, - {self.key1: False}) - - def test_json_value_not_dict(self): - self.assertFalse( - db_api.add_nwa_tenant_binding( - self.ssn, self.tenant1, self.nwa_tenant1, - [self.value1, self.value2])) # list - - -class TestGetNwaTenantBinding(base.BaseTestCase): - def setUp(self): - super(TestGetNwaTenantBinding, self).setUp() - self.session = MagicMock() - - def test_get_nwa_tenant_binding(self): - self.session.query().filter().filter().all.return_value = [] - rc = db_api.get_nwa_tenant_binding(self.session, - TENANT_ID, NWA_TENANT_ID) - self.assertIsNone(rc) - - def test_get_nwa_tenant_binding_1(self): - nwa = MagicMock() - nwa.json_key, nwa.json_value = 'a', 1 - self.session.query().filter().filter().all.return_value = [nwa] - rc = db_api.get_nwa_tenant_binding(self.session, - TENANT_ID, NWA_TENANT_ID) - self.assertEqual(rc.value_json, {'a': 1}) - - def test_get_nwa_tenant_binding_no_result_found(self): - self.session.query().filter().filter().all.side_effect = NoResultFound - rc = db_api.get_nwa_tenant_binding(self.session, - TENANT_ID, NWA_TENANT_ID) - self.assertIsNone(rc) - - -class TestSetNwaTenantBinding(testscenarios.WithScenarios, base.BaseTestCase): - - scenarios = [ - ('old new json None', - { - 'expected_return_value': False, - 'old_value_json': None, - 'new_value_json': None - }), - ('old json is 1 and new json is None', - { - 'expected_return_value': False, - 'old_value_json': itemval(1), - 'new_value_json': None - }), - ('old json is dict and new json is None', - { - 'expected_return_value': False, - 'old_value_json': itemval({'a': 1}), - 'new_value_json': None - }), - ('old and new json have same key and value', - { - # same key, same value - 'expected_return_value': True, - 'old_value_json': itemval({'a': 1}), - 'new_value_json': {'a': 1}, - 'call_count_update': 0, - 'call_count_insert': 0, - 'call_count_delete': 0 - }), - ('old and new json have same key and same value (True, "True")', - { - # same key, same value (True, "True") XXX - 'expected_return_value': True, - 'old_value_json': itemval({'a': "True"}), - 'new_value_json': {'a': True}, - 'call_count_update': 1, - 'call_count_insert': 0, - 'call_count_delete': 0 - }), - ('old and new json have same key (ignore case)', - { - # same key, same value (ignore case) - 'expected_return_value': True, - 'old_value_json': itemval({'A': 1}), - 'new_value_json': {'a': 1}, - 'call_count_update': 1, - 'call_count_insert': 1, - 'call_count_delete': 1 - }), - ('old and new json has same key and different value', - { - # same key, different value - 'expected_return_value': True, - 'old_value_json': itemval({'a': 1}), - 'new_value_json': {'a': 2}, - 'call_count_update': 1, - 'call_count_insert': 0, - 'call_count_delete': 0 - }), - ('old and new json has different keys', - { - # different key - 'expected_return_value': True, - 'old_value_json': itemval({'a': 1}), - 'new_value_json': {'b': 2}, - 'call_count_update': 1, - 'call_count_insert': 1, - 'call_count_delete': 1 - }), - ('old and new json has multiple different keys', - { - # different key, multiple - 'expected_return_value': True, - 'old_value_json': itemval({ - 'a': 0, - 'b': 1 - }), - 'new_value_json': { - 'b': 1, - 'c': 2 - }, - 'call_count_update': 1, - 'call_count_insert': 1, - 'call_count_delete': 1 - }), - ] - - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_set_nwa_tenant_binding(self, gntb): - - self.session = MagicMock() - gntb.return_value = self.old_value_json - rc = db_api.set_nwa_tenant_binding( - self.session, TENANT_ID, NWA_TENANT_ID, self.new_value_json - ) - self.assertEqual(rc, self.expected_return_value) - if self.expected_return_value: - self.assertEqual(self.session.query().filter().one.call_count, - self.call_count_update) - self.assertEqual(self.session.execute.call_count, - self.call_count_insert) - self.assertEqual(self.session.delete.call_count, - self.call_count_delete) - - -class TestDelNwaTenantBinding(testscenarios.WithScenarios, base.BaseTestCase): - - scenarios = [ - ('old value json is None', - { - 'expected_return_value': False, - 'old_value_json': None - }), - ('old value json is 1', - { - 'expected_return_value': True, - 'old_value_json': 1 - }), - ('no result found', - { - 'expected_return_value': False, - 'old_value_json': 1, - 'delete_not_found': True, - }), - ] - - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_binding') - def test_del_nwa_tenant_binding(self, gntb): - gntb.return_value = self.old_value_json - self.session = MagicMock() - if getattr(self, 'delete_not_found', False): - self.session.query().filter().delete.side_effect = NoResultFound - rc = db_api.del_nwa_tenant_binding(self.session, TENANT_ID, - NWA_TENANT_ID) - self.assertEqual(rc, self.expected_return_value) - - -class TestEnsurePortBinding(base.BaseTestCase): - def setUp(self): - super(TestEnsurePortBinding, self).setUp() - self.session = MagicMock() - - def test_ensure_port_binding(self): - port_id = 'uuid-port_id-1' - self.session.query().filter_by().one.return_value = port_id - rc = db_api.ensure_port_binding(self.session, port_id) - self.assertEqual(rc, port_id) - - @patch('neutron.plugins.ml2.models.PortBinding') - def test_ensure_port_binding_no_result_found(self, mpb): - port_id = 'uuid-port_id-1' - self.session.query().filter_by().one.side_effect = NoResultFound - mpb.return_value = 'uuid-port_id-2' - self.assertRaises( - NoResultFound, - db_api.ensure_port_binding, self.session, port_id - ) - - -class TestTenantQueue(testlib_api.SqlTestCase): - - tenant1 = 'ffffffffff0000000000000000000001' - tenant2 = 'ffffffffff0000000000000000000002' - tenant3 = 'ffffffffff0000000000000000000003' - - def setUp(self): - super(TestTenantQueue, self).setUp() - self.ssn = context.get_admin_context().session - - def test_add_del_tenant_queue(self): - ret = db_api.get_nwa_tenant_queue(self.ssn, self.tenant1) - self.assertFalse(ret) # not found - ret = db_api.add_nwa_tenant_queue(self.ssn, self.tenant1) - self.assertTrue(ret) # succeed - ret = db_api.add_nwa_tenant_queue(self.ssn, self.tenant1) - self.assertFalse(ret) # already registered - ret = db_api.get_nwa_tenant_queue(self.ssn, self.tenant1) - self.assertTrue(ret) # item found - ret = db_api.del_nwa_tenant_queue(self.ssn, self.tenant1) - self.assertTrue(ret) # delete succeed - ret = db_api.del_nwa_tenant_queue(self.ssn, self.tenant1) - self.assertFalse(ret) # do nothing - ret = db_api.get_nwa_tenant_queue(self.ssn, self.tenant1) - self.assertFalse(ret) # not found - - def test_add_tenant_queue_no_result_found(self): - session = MagicMock() - session.query().filter().all.side_effect = NoResultFound - self.assertFalse( - db_api.add_nwa_tenant_queue(session, self.tenant1)) - - def test_add_tenant_queue_detail(self): - ret = db_api.add_nwa_tenant_queue( - self.ssn, self.tenant1, 'nwa_%s' % self.tenant1, topic='foo') - self.assertTrue(ret) - ret = db_api.get_nwa_tenant_queue(self.ssn, self.tenant1) - self.assertEqual(self.tenant1, ret.tenant_id) - self.assertEqual('nwa_%s' % self.tenant1, ret.nwa_tenant_id) - self.assertEqual('foo', ret.topic) - - ret = db_api.add_nwa_tenant_queue(self.ssn, self.tenant2) - self.assertTrue(ret) - ret = db_api.get_nwa_tenant_queue(self.ssn, self.tenant2) - self.assertEqual(self.tenant2, ret.tenant_id) - self.assertEqual('', ret.nwa_tenant_id) - self.assertEqual('', ret.topic) - - def test_get_tenant_queues(self): - ret = db_api.get_nwa_tenant_queues(self.ssn) - self.assertEqual(0, len(ret)) - - self.assertTrue(db_api.add_nwa_tenant_queue(self.ssn, self.tenant1)) - self.assertTrue(db_api.add_nwa_tenant_queue(self.ssn, self.tenant2)) - self.assertTrue(db_api.add_nwa_tenant_queue(self.ssn, self.tenant3)) - - ret = db_api.get_nwa_tenant_queues(self.ssn) - self.assertEqual(3, len(ret)) - - self.assertTrue(db_api.del_nwa_tenant_queue(self.ssn, self.tenant1)) - - ret = db_api.get_nwa_tenant_queues(self.ssn) - self.assertEqual(2, len(ret)) - - self.assertTrue(db_api.del_nwa_tenant_queue(self.ssn, self.tenant2)) - self.assertTrue(db_api.del_nwa_tenant_queue(self.ssn, self.tenant3)) - - ret = db_api.get_nwa_tenant_queues(self.ssn) - self.assertEqual(0, len(ret)) diff --git a/networking_nec/tests/unit/nwa/l2/test_models.py b/networking_nec/tests/unit/nwa/l2/test_models.py deleted file mode 100644 index 3f965f6..0000000 --- a/networking_nec/tests/unit/nwa/l2/test_models.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# -*- mode: python; coding: utf-8 -*- -# GIT: $Id$ - -from neutron.tests import base - -from networking_nec.nwa.l2 import models - - -class TestNWATenantKeyValue(base.BaseTestCase): - def test_nwa_tenant_key_value(self): - ntkv = models.NWATenantKeyValue('T1', 'NWA-T1', 'key', 'value') - self.assertIsNotNone(ntkv) - self.assertEqual(str(ntkv), - "") - - -class TestNWATenantQueue(base.BaseTestCase): - def test_nwa_tenant_queue(self): - ntq = models.NWATenantQueue('T1', 'NWA-T1', 'topic-1') - self.assertIsNotNone(ntq) - self.assertEqual(str(ntq), - "") diff --git a/networking_nec/tests/unit/nwa/l2/test_plugin.py b/networking_nec/tests/unit/nwa/l2/test_plugin.py deleted file mode 100644 index 0463b85..0000000 --- a/networking_nec/tests/unit/nwa/l2/test_plugin.py +++ /dev/null @@ -1,238 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from mock import MagicMock -from mock import patch -import six - -from neutron.common.test_lib import test_config -from neutron.tests import base -from oslo_config import cfg - -from networking_nec.nwa.l2 import plugin - - -class TestNECNWAL2Plugin(base.BaseTestCase): - - @patch('networking_nec.nwa.l2.plugin.NECNWAL2Plugin._setup_rpc') - @patch('neutron.plugins.ml2.managers.TypeManager.initialize') - def setUp(self, f1, f2): - super(TestNECNWAL2Plugin, self).setUp() - l3_plugin = ('neutron.tests.unit.test_l3_plugin.' - 'TestL3NatServicePlugin') - - service_plugins = {'l3_plugin_name': l3_plugin} - - cfg.CONF.set_override( - 'service_plugins', - [test_config.get(key, default) - for key, default in six.iteritems(service_plugins or {})] - ) - - f1.return_value = None - f2.return_value = None - - self.l2_plugin = plugin.NECNWAL2Plugin() - - def test_extend_network_dict_providor_no_id(self): - context = MagicMock() - network = {} - - result = self.l2_plugin._extend_network_dict_provider(context, - network) - - self.assertIsNone(result) - - @patch('neutron.db.segments_db.get_network_segments') - def test_extend_network_dict_provider_segment_none(self, f1): - context = MagicMock() - network = {'id': '99f771b4-af69-45cc-942f-a76be4e8cd1d'} - f1.return_value = None - - result = self.l2_plugin._extend_network_dict_provider(context, - network) - self.assertIsNone(result) - - @patch('neutron.db.segments_db.get_network_segments') - def test_extend_network_dict_provider_segment_one(self, f1): - context = MagicMock() - network = {'id': '99f771b4-af69-45cc-942f-a76be4e8cd1d'} - f1.return_value = [{'segmentation_id': 1000, - 'network_type': 'vlan', - 'physical_network': 'OpenStack/DC1/APP'}] - - result = self.l2_plugin._extend_network_dict_provider(context, - network) - self.assertIsNone(result) - - @patch('neutron.db.segments_db.get_network_segments') - def test_extend_network_dict_provider_segment_multi(self, f1): - context = MagicMock() - network = {'id': '99f771b4-af69-45cc-942f-a76be4e8cd1d'} - f1.return_value = [{'segmentation_id': 1000, - 'network_type': 'vlan', - 'physical_network': 'OpenStack/DC1/APP'}, - {'segmentation_id': 1001, - 'network_type': 'vlan', - 'physical_network': 'OpenStack/DC1/APP'}] - - result = self.l2_plugin._extend_network_dict_provider(context, - network) - self.assertIsNone(result) - - @patch('neutron.common.rpc.Connection.create_consumer') - def test_start_rpc_listeners(self, f1): - self.l2_plugin.notifier = MagicMock() - self.l2_plugin.type_manager = MagicMock() - self.l2_plugin.start_rpc_listeners() - - @patch('neutron.db.db_base_plugin_common.' - 'DbBasePluginCommon._make_network_dict') - @patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin._extend_network_dict_provider') - @patch('neutron.plugins.ml2.plugin.Ml2Plugin.get_network') - def test_get_network(self, f1, f2, f3): - id = "99f771b4-af69-45cc-942f-a76be4e8cd1d" - context = MagicMock() - fields = MagicMock() - self.l2_plugin.get_network(context, id, fields) - - @patch('neutron.plugins.ml2.plugin.Ml2Plugin.get_networks') - def test_get_networks(self, f1): - context = MagicMock() - filters = MagicMock() - fields = MagicMock() - sorts = MagicMock() - limit = MagicMock() - marker = MagicMock() - page_reverse = False - result = self.l2_plugin.get_networks(context, filters, fields, - sorts, limit, marker, - page_reverse) - self.assertTrue(result) - - @patch('networking_nec.nwa.l2.db_api.get_nwa_tenant_queue') - @patch('networking_nec.nwa.l2.plugin.NECNWAL2Plugin._is_alive_nwa_agent') - def test_create_nwa_agent_tenant_queue(self, f1, f2): - context = MagicMock() - tid = 'Tenant1' - f1.return_value = True - f2.return_value = None - self.l2_plugin._create_nwa_agent_tenant_queue(context, tid) - - def test_create_nwa_agent_tenant_queue_not_alive(self): - context = MagicMock() - tid = 'Tenant1' - self.l2_plugin._create_nwa_agent_tenant_queue(context, tid) - - @patch('neutron.plugins.ml2.plugin.Ml2Plugin.delete_network') - @patch('networking_nec.nwa.l2.plugin.' - 'NECNWAL2Plugin._create_nwa_agent_tenant_queue') - @patch('neutron.plugins.ml2.plugin.Ml2Plugin.create_network') - def test_create_delete_network(self, f1, f2, f3): - context = MagicMock() - context.tenant_id = 'Tenant1' - network = {'id': '99f771b4-af69-45cc-942f-a76be4e8cd1d'} - - result = self.l2_plugin.create_network(context, network) - - self.assertTrue(result) - - result = self.l2_plugin.delete_network(context, result.id) - - self.assertTrue(result) - - @patch('neutron.plugins.ml2.plugin.Ml2Plugin.create_port') - def test_create_port(self, f1): - context = MagicMock() - port = MagicMock() - - result = self.l2_plugin.create_port(context, port) - self.assertTrue(result) - - @patch('networking_nec.nwa.l2.rpc.nwa_agent_api.' - 'NECNWAAgentApi.get_nwa_rpc_servers') - def test_get_nwa_topics(self, f1): - context = MagicMock() - id = 'Tenant1' # Tenant ID - f1.return_value = {'nwa_rpc_servers': - [{'tenant_id': 'Tenant1', 'topic': 'topic1'}, - {'tenant_id': 'Tenant2', 'topic': 'topic2'}, - {'tenant_id': 'Tenant1', 'topic': 'topic11'}]} - - result = self.l2_plugin.get_nwa_topics(context, id) - self.assertEqual(len(result), 2) - - @patch('networking_nec.nwa.l2.rpc.nwa_agent_api.' - 'NECNWAAgentApi.get_nwa_rpc_servers') - def test_get_nwa_topics_not_dict(self, f1): - context = MagicMock() - id = 'Tenant1' # Tenant ID - f1.return_value = ['topic1', 'topic2'] # not dict - - result = self.l2_plugin.get_nwa_topics(context, id) - self.assertEqual(len(result), 0) - - def test_get_nwa_proxy(self): - tid = 'Tenant1' - result = self.l2_plugin.get_nwa_proxy(tid) - - self.assertTrue(result) - - def test_get_nwa_proxy_in_nwa_proxies(self): - tid = 'Tenant1' - proxy = MagicMock() - self.l2_plugin.nwa_proxies = {tid: proxy} - result = self.l2_plugin.get_nwa_proxy(tid) - - self.assertEqual(result, proxy) - - @patch('networking_nec.nwa.l2.plugin.NECNWAL2Plugin.get_nwa_topics') - def test_get_nwa_proxy_with_context(self, f1): - tid = 'Tenant1' - context = MagicMock() - f1.return_value = ['topic1'] - result = self.l2_plugin.get_nwa_proxy(tid, context) - - self.assertTrue(result) - - @patch('networking_nec.nwa.l2.plugin.NECNWAL2Plugin.get_nwa_topics') - def test_get_nwa_proxy_no_topics(self, f1): - tid = 'Tenant1' - context = MagicMock() - f1.return_value = [] - result = self.l2_plugin.get_nwa_proxy(tid, context) - - self.assertTrue(result) - - @patch('networking_nec.nwa.l2.plugin.NECNWAL2Plugin.get_agents') - def test_is_alive_nwa_agent(self, f1): - context = MagicMock() - f1.return_value = [{'alive': True}, {'alive': False}] - - result = self.l2_plugin._is_alive_nwa_agent(context) - self.assertTrue(result) - - @patch('networking_nec.nwa.l2.plugin.NECNWAL2Plugin.get_agents') - def test_is_alive_nwa_agent_not_alive(self, f1): - context = MagicMock() - f1.return_value = [{'alive': False}] - - result = self.l2_plugin._is_alive_nwa_agent(context) - self.assertFalse(result) - - def test_get_port_from_device(self): - context = MagicMock() - device = 'device' - self.l2_plugin.get_port_from_device(context, device) diff --git a/networking_nec/tests/unit/nwa/l2/test_utils.py b/networking_nec/tests/unit/nwa/l2/test_utils.py deleted file mode 100644 index 83d880c..0000000 --- a/networking_nec/tests/unit/nwa/l2/test_utils.py +++ /dev/null @@ -1,359 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from mock import MagicMock -from sqlalchemy.orm import exc as sa_exc - -from neutron.tests import base -from oslo_config import cfg -from oslo_serialization import jsonutils - -from networking_nec.nwa.l2 import utils as nwa_l2_utils - - -class TestNwa(base.BaseTestCase): - def setUp(self): - super(TestNwa, self).setUp() - - class network_context(object): - network = MagicMock() - current = MagicMock() - _plugin = MagicMock() - _plugin_context = MagicMock() - - class db_session(object): - def query(self): - return - pass - - class network_segment(object): - id = '1' - network_id = 0 - network_type = 'vlan' - physical_network = 'Phys1' - segmentation_id = '1001' - - def __init__(self, id_, nid, ntype, physnet, vid): - self.id = id_ - self.network_id = nid - self.network_type = ntype - self.physical_network = physnet - self.segmentation_id = vid - - self.context = network_context() - self.context.network.current = {} - self.context.network.current['tenant_id'] = 'T1' - self.context.network.current['name'] = 'PublicVLAN_100' - self.context.network.current['id'] = 'Uuid-PublicVLAN_100' - self.context._port = { - 'id': 'uuid-port-100', - 'device_owner': 'network:router_interface', - 'device_id': 'uuid-device_id_100', - 'fixed_ips': [ - {'ip_address': '192.168.120.1', - 'subnet_id': 'Uuid-Subnet-Id-1'} - ], - 'mac_address': '12:34:56:78:9a:bc' - } - self.host_agent = [ - { - "binary": "neutron-openvswitch-agent", - "description": None, - "admin_state_up": True, - "alive": True, - "topic": "N/A", - "host": "harry", - "agent_type": "Open vSwitch agent", - "id": "a01dc42f-0d15-43ff-8f80-22e15cfe715d", - "configurations": { - "tunnel_types": [], - "tunneling_ip": "", - "bridge_mappings": { - "Common/App/Pod3": "br-eth1" - }, - "l2_population": False, - "devices": 0 - } - }, - { - "alive": False - } - ] - - self.context.host_agents = MagicMock(return_value=self.host_agent) - self.context.current = {} - - self.network_segments = [ - { - "physical_network": "Common/KVM/Pod1-1", - "id": "uuid-1-1", - "segmentation_id": '100' - }, - { - "physical_network": "Common/KVM/Pod1-2", - "id": "uuid-1-2", - "segmentation_id": '101' - }, - { - "physical_network": "Common/App/Pod3", - "id": "uuid-1-3", - "segmentation_id": '102' - } - ] - - self.segments_db = [] - for segment in self.network_segments: - self.segments_db.append(network_segment( - self.context.network.current['id'], - segment['id'], 'vlan', - segment['physical_network'], segment['segmentation_id'])) - - self.resource_group = [ - { - "physical_network": "Common/BM/Pod1-1", - "device_owner": "compute:BM_AZ1", - "ResourceGroupName": "Common/BM/Pod1" - }, - { - "physical_network": "Common/KVM/Pod1-1", - "device_owner": "compute:AZ1", - "ResourceGroupName": "Common/KVM/Pod1" - }, - { - "physical_network": "Common/KVM/Pod1-2", - "device_owner": "compute:AZ2", - "ResourceGroupName": "Common/KVM/Pod2" - }, - { - "physical_network": "Common/App/Pod3", - "device_owner": "compute:DC01_BMT01_ZONE01", - "ResourceGroupName": "Common/App/Pod3" - }, - { - "physical_network": "Common/App/Pod3", - "device_owner": "ironic:isolation", - "ResourceGroupName": "Common/App/Pod3" - }, - { - "physical_network": "Common/App/Pod3", - "device_owner": "network:dhcp", - "ResourceGroupName": "Common/App/Pod3" - }, - { - "physical_network": "Common/App/Pod4", - "device_owner": "network:router_gateway", - "ResourceGroupName": "Common/App/Pod4" - }, - { - "physical_network": "Common/App/Pod4", - "device_owner": "network:router_interface", - "ResourceGroupName": "Common/App/Pod4" - } - ] - - fn_resource_group = self.get_temp_file_path('resource_group.json') - with open(fn_resource_group, 'w') as f: - f.write(jsonutils.dumps(self.resource_group)) - cfg.CONF.set_override('resource_group_file', fn_resource_group, - group='NWA') - - self.nwa_data = {} - self.jbody = { - 'resultdata': { - 'ResourceGroupName': 'Common/App/Pod3', - 'VlanID': '2015', - 'TenantID': 'TenantID-2015', - 'TenantFWName': 'TFW2015', - 'LogicalNWName': 'PublicVLAN_2015' - } - } - self.rcode = MagicMock() - - -class TestGetNetworkInfo(TestNwa): - def test_get_network_info(self): - net, nid = nwa_l2_utils.get_network_info(self.context) - self.assertEqual(net, 'PublicVLAN_100') - self.assertEqual(nid, 'Uuid-PublicVLAN_100') - - -class TestGetPhysicalNetwork(TestNwa): - def test_get_physical_network(self): - pnet = nwa_l2_utils.get_physical_network('compute:AZ1', - self.resource_group) - self.assertEqual(pnet, 'Common/KVM/Pod1-1') - - pnet = nwa_l2_utils.get_physical_network('compute:AZ1', - self.resource_group, - 'Common/KVM/Pod1') - self.assertEqual(pnet, 'Common/KVM/Pod1-1') - - def test_get_physical_network_not_found(self): - pnet = nwa_l2_utils.get_physical_network('network:router_interface1', - self.resource_group) - self.assertIsNone(pnet) - - pnet = nwa_l2_utils.get_physical_network('compute:AZ1', - self.resource_group, - 'Common/KVM/Pod2') - self.assertIsNone(pnet) - - -class TestGetVlanIdOfPhysicalNetwork(TestNwa): - def test_segment_not_found(self): - network_id = 'uuid-1-2' - physical_network = 'Common/KVM/Pod1-2' - self.context.network.session = MagicMock() - self.context.network.session.query().filter().order_by().filter_by().\ - all.return_value = [] - vid = nwa_l2_utils.get_vlan_id_of_physical_network( - self.context.network, network_id, physical_network) - self.assertEqual(vid, '') - - def test_physical_network_not_found(self): - network_id = 'uuid-1-2' - physical_network = 'Common/KVM/Pod1-X' - self.context.network.session = MagicMock() - self.context.network.session.query().filter().order_by().filter_by().\ - all.return_value = [self.segments_db[1]] - vid = nwa_l2_utils.get_vlan_id_of_physical_network( - self.context.network, network_id, physical_network) - self.assertEqual(vid, '101') - - def test_found(self): - network_id = 'uuid-1-2' - physical_network = 'Common/KVM/Pod1-2' - self.context.network.session = MagicMock() - self.context.network.session.query().filter().order_by().filter_by().\ - all.return_value = [self.segments_db[1]] - vid = nwa_l2_utils.get_vlan_id_of_physical_network( - self.context.network, network_id, physical_network) - self.assertEqual(vid, '101') - - -class TestPortcontextToNwaInfo(TestNwa): - def test_portcontext_to_nwa_info(self): - self.context.current = self.context._port - rd = nwa_l2_utils.portcontext_to_nwa_info(self.context, - self.resource_group) - self.assertIsInstance(rd, dict) - p = self.context._port - self.assertEqual(rd['device']['owner'], p['device_owner']) - self.assertEqual(rd['device']['id'], p['device_id']) - self.assertEqual(rd['subnet']['id'], p['fixed_ips'][0]['subnet_id']) - self.assertEqual(rd['port']['id'], p['id']) - self.assertEqual(rd['port']['ip'], p['fixed_ips'][0]['ip_address']) - self.assertEqual(rd['port']['mac'], p['mac_address']) - c = self.context.network.current - self.assertEqual(rd['network']['id'], c['id']) - self.assertEqual(rd['network']['name'], c['name']) - self.assertEqual(rd['network']['vlan_type'], 'PublicVLAN') - self.assertEqual(rd['network']['vlan_id'], '') - - def test_portcontext_to_nwa_info_business_vlan(self): - # session in context - self.context.session = MagicMock() - # external network is not found - self.context.session.query().filter_by().\ - one.side_effect = sa_exc.NoResultFound - self.context.network.current['name'] = 'BusinessVLAN_200' - self.context.network.current['id'] = 'Uuid-BusinessVLAN_200' - self.context.current = self.context._port - rd = nwa_l2_utils.portcontext_to_nwa_info(self.context, - self.resource_group) - self.assertIsInstance(rd, dict) - self.assertEqual(rd['network']['vlan_type'], 'BusinessVLAN') - - def test_portcontext_to_nwa_info_original_port(self): - device_owner = 'do-1' - device_id = 'di-1' - id_ = 'id-1' - subnet_id = 'sid-1' - ip_address = '192.168.120.1' - mac = 'mac-1' - self.context.original = { - 'device_owner': device_owner, - 'device_id': device_id, - 'id': id_, - 'fixed_ips': [ - {'ip_address': ip_address, - 'subnet_id': subnet_id}, - ], - 'mac_address': mac, - } - rd = nwa_l2_utils.portcontext_to_nwa_info(self.context, - self.resource_group, - True) - self.assertIsInstance(rd, dict) - self.assertEqual(rd['device']['owner'], device_owner) - self.assertEqual(rd['device']['id'], device_id) - self.assertEqual(rd['subnet']['id'], subnet_id) - self.assertEqual(rd['port']['id'], id_) - self.assertEqual(rd['port']['ip'], ip_address) - self.assertEqual(rd['port']['mac'], mac) - - def test_portcontext_to_nwa_info_original_port_no_fixedip(self): - device_owner = 'do-2' - device_id = 'di-2' - id_ = 'id-2' - subnet_id = '' - ip_address = '' - mac = '' - self.context.original = { - 'device_owner': device_owner, - 'device_id': device_id, - 'id': id_, - 'fixed_ips': [], - 'mac_address': mac, - } - rd = nwa_l2_utils.portcontext_to_nwa_info(self.context, - self.resource_group, - True) - self.assertIsInstance(rd, dict) - self.assertEqual(rd['device']['owner'], device_owner) - self.assertEqual(rd['device']['id'], device_id) - self.assertEqual(rd['subnet']['id'], subnet_id) - self.assertEqual(rd['port']['id'], id_) - self.assertEqual(rd['port']['ip'], ip_address) - self.assertEqual(rd['port']['mac'], mac) - - -class test__getResourceGroupName(TestNwa): - def test__get_resource_group_name(self): - self.context.current['device_owner'] = 'network:dhcp' - rc = nwa_l2_utils._get_resource_group_name(self.context, - self.resource_group) - self.assertEqual(rc, 'Common/App/Pod3') - - self.context.current['device_owner'] = 'network:router_interface' - rc = nwa_l2_utils._get_resource_group_name(self.context, - self.resource_group) - self.assertEqual(rc, 'Common/App/Pod4') - - self.context.current['device_owner'] = 'network:router_gateway' - rc = nwa_l2_utils._get_resource_group_name(self.context, - self.resource_group) - self.assertEqual(rc, 'Common/App/Pod4') - - self.context.current['device_owner'] = 'compute:AZ1' - rc = nwa_l2_utils._get_resource_group_name(self.context, - self.resource_group) - self.assertIsNone(rc) - - self.context.current['device_owner'] = 'network:router_interface' - self.host_agent[0]['alive'] = False - self.resource_group = [] - rc = nwa_l2_utils._get_resource_group_name(self.context, - self.resource_group) - self.assertIsNone(rc) diff --git a/networking_nec/tests/unit/nwa/l3/__init__.py b/networking_nec/tests/unit/nwa/l3/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/nwa/l3/rpc/__init__.py b/networking_nec/tests/unit/nwa/l3/rpc/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/nwa/l3/rpc/test_nwa_l3_proxy_api.py b/networking_nec/tests/unit/nwa/l3/rpc/test_nwa_l3_proxy_api.py deleted file mode 100644 index 7bde935..0000000 --- a/networking_nec/tests/unit/nwa/l3/rpc/test_nwa_l3_proxy_api.py +++ /dev/null @@ -1,82 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock - -from neutron.tests import base - -from networking_nec.nwa.l3.rpc.nwa_l3_proxy_api import NwaL3ProxyApi - - -class TestNwaL3ProxyApi(base.BaseTestCase): - - def setUp(self): - self.context = mock.ANY - self.tenant_id = 'T1' - self.nwa_tenant_id = 'DC1T1' - self.client = mock.MagicMock() - self.proxy = NwaL3ProxyApi(self.client) - super(TestNwaL3ProxyApi, self).setUp() - - def test_create_tenant_fw(self): - cctxt = mock.Mock() - self.client.prepare.return_value = cctxt - nwa_info1 = [{'a': 1}, {'b': 2}, {'c': 3}] - self.proxy.create_tenant_fw(self.context, self.tenant_id, - self.nwa_tenant_id, nwa_info1) - cctxt.cast.assert_called_with( - self.context, 'create_tenant_fw', - tenant_id=self.tenant_id, - nwa_tenant_id=self.nwa_tenant_id, - nwa_info=nwa_info1 - ) - - def test_delete_tenant_fw(self): - cctxt = mock.Mock() - self.client.prepare.return_value = cctxt - nwa_info2 = [{'a': 4}, {'b': 5}, {'c': 6}] - self.proxy.delete_tenant_fw(self.context, self.tenant_id, - self.nwa_tenant_id, nwa_info2) - cctxt.cast.assert_called_with( - self.context, 'delete_tenant_fw', - tenant_id=self.tenant_id, - nwa_tenant_id=self.nwa_tenant_id, - nwa_info=nwa_info2 - ) - - def test_setting_nat(self): - cctxt = mock.Mock() - self.client.prepare.return_value = cctxt - floating1 = [{'x': 1}, {'y': 2}, {'z': 3}] - self.proxy.setting_nat(self.context, self.tenant_id, - self.nwa_tenant_id, floating1) - cctxt.cast.assert_called_with( - self.context, 'setting_nat', - tenant_id=self.tenant_id, - nwa_tenant_id=self.nwa_tenant_id, - floating=floating1 - ) - - def test_delete_nat(self): - cctxt = mock.Mock() - self.client.prepare.return_value = cctxt - floating2 = [{'x': 4}, {'y': 5}, {'z': 6}] - self.proxy.delete_nat(self.context, self.tenant_id, - self.nwa_tenant_id, floating2) - cctxt.cast.assert_called_with( - self.context, 'delete_nat', - tenant_id=self.tenant_id, - nwa_tenant_id=self.nwa_tenant_id, - floating=floating2 - ) diff --git a/networking_nec/tests/unit/nwa/l3/test_plugin.py b/networking_nec/tests/unit/nwa/l3/test_plugin.py deleted file mode 100644 index cb0b6eb..0000000 --- a/networking_nec/tests/unit/nwa/l3/test_plugin.py +++ /dev/null @@ -1,110 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from mock import MagicMock -from mock import patch -from sqlalchemy.orm import exc as sa_exc - -from neutron.tests import base -from neutron_lib import exceptions as n_exc - -from networking_nec.nwa.l3.plugin import NECNWAL3Plugin - - -class TestNECNWAL3Plugin(base.BaseTestCase): - - @patch('neutron.services.l3_router.l3_router_plugin.' - 'L3RouterPlugin.__init__') - def setUp(self, l3p): - super(TestNECNWAL3Plugin, self).setUp() - self.plg = NECNWAL3Plugin() - self.context = MagicMock() - self.floating = { - 'floating_ip_address': '172.16.0.107', - 'fixed_ip_address': '192.168.120.107', - 'router_id': 'uuid-router_id-107', - 'floating_network_id': 'uuid-network_id-107', - 'tenant_id': 'T-107', - 'floating_port_id': 'uuid-floating_port_id-107', - } - - @patch('neutron.db.l3_db.L3_NAT_db_mixin.create_floatingip') - def test_create_floatingip(self, cfip): - floatingip = MagicMock() - cfip.return_value = 0 - rc = self.plg.create_floatingip(self.context, floatingip) - self.assertEqual(rc, 0) - - @patch('neutron.db.l3_db.L3_NAT_db_mixin.update_floatingip') - @patch('networking_nec.nwa.l3_plugin.NECNWAL3Plugin._delete_nat') - @patch('neutron.services.l3_router.l3_router_plugin.' - 'L3RouterPlugin.update_floatingip') - def _test_update_floatingip(self, ufip, ndn, nsn): - floatingip = { - 'floatingip': { - 'port_id': None - } - } - fid = 'uuid-fid-100' - ufip.return_value = 0 - self.context.session.query().filter_by().one.return_value = \ - self.floating - rc = self.plg.update_floatingip(self.context, fid, floatingip) - self.assertEqual(rc, 0) - - floatingip = { - 'floatingip': { - 'port_id': 'uuid-port_id-101' - } - } - rc = self.plg.update_floatingip(self.context, fid, floatingip) - self.assertEqual(rc, 0) - - floatingip = { - 'floatingip': { - 'port_id1': 'uuid-port_id-102' - } - } - rc = self.plg.update_floatingip(self.context, fid, floatingip) - self.assertEqual(rc, 0) - - def test_update_floatingip_raise_before_super_call(self): - floatingip = { - 'floatingip': { - 'port_id': None - } - } - fid = 'uuid-fid-111' - self.context.session.query().filter_by().one.side_effect = \ - sa_exc.NoResultFound - self.assertRaises( - n_exc.PortNotFound, - self.plg.update_floatingip, self.context, fid, floatingip - ) - - @patch('neutron.services.l3_router.l3_router_plugin.' - 'L3RouterPlugin.update_floatingip') - def _test_update_floatingip_raise_after_super_call(self, uifp): - floatingip = { - 'floatingip': { - 'port_id': 'uuid-port_id_112' - } - } - fid = 'uuid-fid-112' - self.context.session.query().filter_by().one.side_effect = \ - sa_exc.NoResultFound - self.assertRaises( - n_exc.PortNotFound, - self.plg.update_floatingip, self.context, fid, floatingip - ) diff --git a/networking_nec/tests/unit/nwa/nwalib/__init__.py b/networking_nec/tests/unit/nwa/nwalib/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/networking_nec/tests/unit/nwa/nwalib/test_client.py b/networking_nec/tests/unit/nwa/nwalib/test_client.py deleted file mode 100644 index 3fd5032..0000000 --- a/networking_nec/tests/unit/nwa/nwalib/test_client.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from mock import patch -from neutron.tests import base - -from networking_nec.nwa.nwalib import client - - -class TestNwaClientBase(base.BaseTestCase): - - def setUp(self): - super(TestNwaClientBase, self).setUp() - host = '127.0.0.1' - port = '12081' - access_key_id = 'PzGIIoLbL7ttHFkDHqLguFz/7+VsVJbDmV0iLWAkJ0g=' - secret_access_key = 'nbvX65iujFoYomXTKROF9GKUN6L2rAM/sI+cvNdW7sw=' - - self.nwa = client.NwaClient( - host=host, port=port, access_key_id=access_key_id, - secret_access_key=secret_access_key, - load_workflow_list=False - ) - self.nwa.workflow_first_wait = 0 - - wki = patch('networking_nec.nwa.nwalib.nwa_restclient.' - 'NwaRestClient.workflowinstance').start() - wki.return_value = (200, {'status': 'SUCCESS'}) - - self.post = patch('networking_nec.nwa.nwalib.restclient.' - 'RestClient.post').start() - self.post.__name__ = 'post' - self.post.return_value = (200, {'status': 'SUCCESS', - 'executionid': "01"}) diff --git a/networking_nec/tests/unit/nwa/nwalib/test_client_fwaas.py b/networking_nec/tests/unit/nwa/nwalib/test_client_fwaas.py deleted file mode 100644 index cb70e8c..0000000 --- a/networking_nec/tests/unit/nwa/nwalib/test_client_fwaas.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from networking_nec.nwa.nwalib import workflow -from networking_nec.tests.unit.nwa.nwalib import test_client - -TENANT_ID = 'OpenT9004' - - -class TestNwaClientFWaaS(test_client.TestNwaClientBase): - - def test_setting_fw_policy(self): - fw_name = 'TFW8' - props = {'properties': [1]} - rd, rj = self.nwa.fwaas.setting_fw_policy_async( - TENANT_ID, fw_name, props - ) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('SettingFWPolicy'), - {'TenantID': TENANT_ID, - 'DCResourceType': 'TFW_Policy', - 'DCResourceOperation': 'Setting', - 'DeviceInfo': {'Type': 'TFW', 'DeviceName': fw_name}, - 'Property': props}) diff --git a/networking_nec/tests/unit/nwa/nwalib/test_client_l2.py b/networking_nec/tests/unit/nwa/nwalib/test_client_l2.py deleted file mode 100644 index 4ec4f13..0000000 --- a/networking_nec/tests/unit/nwa/nwalib/test_client_l2.py +++ /dev/null @@ -1,258 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import testscenarios - -from networking_nec.nwa.nwalib import workflow -from networking_nec.tests.unit.nwa.nwalib import test_client - -TENANT_ID = 'OpenT9004' -DC_RESOURCE_GROUP_POD1 = 'OpenStack/DC1/Common/Pod1Grp/Pod1' -DC_RESOURCE_GROUP_APP1 = 'OpenStack/DC1/Common/App1Grp/App1' - - -class TestNwaClientL2Scenario(testscenarios.WithScenarios, - test_client.TestNwaClientBase): - - scenarios = [ - ('test 1', - {'operations': [ - ('delete', 'vlan-A'), - ('delete', 'vlan-B'), - ('delete', 'vlan-C'), - ('delete', 'vlan-D'), - ('delete', 'vlan-A') - ]}), - ('test 2', - {'operations': [ - ('delete', 'vlan-1'), - ('delete', 'vlan-2'), - ('delete', 'vlan-3'), - ('delete', 'vlan-1') - ]}), - # delete to "create" - ('test 3', - {'operations': [ - ('create', 'vlan-A'), - ('delete', 'vlan-A'), - ('create', 'vlan-A')]}), - # don't delete if name is not same. - ('test 4', - {'operations': [ - ('create', 'vlan-1'), - ('delete', 'vlan-2'), - ('create', 'vlan-1') - ]}), - ('test 5', - {'operations': [ - ('create', 'vlan-B'), - ('delete', 'vlan-B'), - ('create', 'vlan-C') - ]}), - ('test 6', - {'operations': [ - ('create', 'vlan-X'), - ('delete', 'vlan-X'), - ('create', 'vlan-X'), - ('delete', 'vlan-X') - ]}), - ('test 7', - {'operations': [ - ('create', 'vlan-1'), - ('create', 'vlan-2'), - ('delete', 'vlan-1'), - ('delete', 'vlan-2'), - ('create', 'vlan-1'), - ('delete', 'vlan-1') - ]}), - ('test 8', - {'operations': [ - ('create', 'vlan-E'), - ('delete', 'vlan-E'), - ('delete', 'vlan-E'), - ('delete', 'vlan-E') - ]}), - ] - - def test_general_dev(self): - dcresgrp_name = 'Common/App/Pod3' - for operation, vlan_name in self.operations: - method = getattr(self.nwa.l2, '%s_general_dev' % operation) - rd, rj = method(TENANT_ID, dcresgrp_name, vlan_name) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, len(self.operations)) - - -class TestNwaClientL2(test_client.TestNwaClientBase): - - def test_create_tenant_nw(self): - rd, rj = self.nwa.l2.create_tenant_nw(TENANT_ID, - DC_RESOURCE_GROUP_APP1) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('CreateTenantNW'), - {'TenantID': TENANT_ID, - 'CreateNW_DCResourceGroupName': DC_RESOURCE_GROUP_APP1, - 'CreateNW_OperationType': 'CreateTenantNW'}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_delete_tenant_nw(self): - rd, rj = self.nwa.l2.delete_tenant_nw(TENANT_ID) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('DeleteTenantNW'), - {'TenantID': TENANT_ID}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_create_vlan(self): - vlan_type = 'BusinessVLAN' - ipaddr = '10.0.0.0' - mask = 24 - open_nid = 'UUID' - - rd, rj = self.nwa.l2.create_vlan( - TENANT_ID, ipaddr, mask, vlan_type, open_nid - ) - - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('CreateVLAN'), - {'TenantID': TENANT_ID, - 'CreateNW_IPSubnetMask1': mask, - 'CreateNW_IPSubnetAddress1': ipaddr, - 'CreateNW_VlanType1': vlan_type, - 'CreateNW_VlanLogicalID1': open_nid}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_create_vlan_without_open_nid(self): - vlan_type = 'BusinessVLAN' - ipaddr = '10.0.0.0' - mask = 24 - - rd, rj = self.nwa.l2.create_vlan( - TENANT_ID, ipaddr, mask, vlan_type - ) - - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('CreateVLAN'), - {'TenantID': TENANT_ID, - 'CreateNW_IPSubnetMask1': mask, - 'CreateNW_IPSubnetAddress1': ipaddr, - 'CreateNW_VlanType1': vlan_type}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_delete_vlan(self): - vlan_name = 'LNW_BusinessVLAN_49' - vlan_type = 'BusinessVLAN' - rd, rj = self.nwa.l2.delete_vlan( - TENANT_ID, vlan_name, vlan_type - ) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('DeleteVLAN'), - {'TenantID': TENANT_ID, - 'DeleteNW_VlanLogicalName1': vlan_name, - 'DeleteNW_VlanType1': vlan_type}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_create_general_dev(self): - vlan_name = 'LNW_BusinessVLAN_49' - vlan_type = 'BusinessVLAN' - port_type = 'BM' - rd, rj = self.nwa.l2.create_general_dev( - TENANT_ID, DC_RESOURCE_GROUP_POD1, - vlan_name, vlan_type, port_type, 'vlan-logical-id-1' - ) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('CreateGeneralDev'), - {'TenantID': TENANT_ID, - 'CreateNW_DeviceType1': 'GeneralDev', - 'CreateNW_DCResourceGroupName': DC_RESOURCE_GROUP_POD1, - 'CreateNW_VlanLogicalName1': vlan_name, - 'CreateNW_VlanType1': vlan_type, - 'CreateNW_PortType1': port_type, - 'CreateNW_VlanLogicalID1': 'vlan-logical-id-1'}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_delete_general_dev(self): - vlan_name = 'LNW_BusinessVLAN_49' - vlan_type = 'BusinessVLAN' - port_type = 'BM' - rd, rj = self.nwa.l2.delete_general_dev( - TENANT_ID, DC_RESOURCE_GROUP_POD1, - vlan_name, vlan_type, port_type, 'vlan-logical-id-2' - ) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('DeleteGeneralDev'), - {'TenantID': TENANT_ID, - 'DeleteNW_DeviceType1': 'GeneralDev', - 'DeleteNW_DCResourceGroupName': DC_RESOURCE_GROUP_POD1, - 'DeleteNW_VlanLogicalName1': vlan_name, - 'DeleteNW_VlanType1': vlan_type, - 'DeleteNW_PortType1': port_type, - 'DeleteNW_VlanLogicalID1': 'vlan-logical-id-2'}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_create_connect_port(self): - vlan_name = 'LNW_BusinessVLAN_49' - vlan_type = 'BusinessVLAN' - vlan_id = 1001 - rd, rj = self.nwa.l2.create_connect_port( - TENANT_ID, DC_RESOURCE_GROUP_POD1, - vlan_name, vlan_type, vlan_id - ) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('CreateConnectPort'), - {'CreateNW_DCResourceGroupName': DC_RESOURCE_GROUP_POD1, - 'CreateNW_DeviceType1': 'GeneralDev', - 'CreateNW_OperationType': 'CreateConnectPort', - 'CreateNW_VlanID1': vlan_id, - 'CreateNW_VlanLogicalName1': vlan_name, - 'CreateNW_VlanType1': vlan_type, - 'TenantID': TENANT_ID}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_delete_connect_port(self): - vlan_name = 'LNW_BusinessVLAN_49' - vlan_type = 'BusinessVLAN' - vlan_id = 1001 - rd, rj = self.nwa.l2.delete_connect_port( - TENANT_ID, DC_RESOURCE_GROUP_POD1, - vlan_name, vlan_type, vlan_id - ) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('DeleteConnectPort'), - {'DeleteNW_DCResourceGroupName': DC_RESOURCE_GROUP_POD1, - 'DeleteNW_DeviceType1': 'GeneralDev', - 'DeleteNW_OperationType': 'DeleteConnectPort', - 'DeleteNW_VlanID1': vlan_id, - 'DeleteNW_VlanLogicalName1': vlan_name, - 'DeleteNW_VlanType1': vlan_type, - 'TenantID': TENANT_ID}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) diff --git a/networking_nec/tests/unit/nwa/nwalib/test_client_l3.py b/networking_nec/tests/unit/nwa/nwalib/test_client_l3.py deleted file mode 100644 index ccde652..0000000 --- a/networking_nec/tests/unit/nwa/nwalib/test_client_l3.py +++ /dev/null @@ -1,169 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock - -from networking_nec.nwa.nwalib import workflow -from networking_nec.tests.unit.nwa.nwalib import test_client - -TENANT_ID = 'OpenT9004' - -# create tenant nw -DC_RESOURCE_GROUP_APP1 = 'OpenStack/DC1/Common/App1Grp/App1' - - -class TestNwaClientL3(test_client.TestNwaClientBase): - - def test_create_tenant_fw(self): - vlan_devaddr = '10.0.0.254' - vlan_name = 'LNW_BusinessVLAN_49' - vlan_type = 'BusinessVLAN' - rd, rj = self.nwa.l3.create_tenant_fw( - TENANT_ID, DC_RESOURCE_GROUP_APP1, - vlan_devaddr, vlan_name, vlan_type - ) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('CreateTenantFW'), - {'TenantID': TENANT_ID, - 'CreateNW_DeviceType1': 'TFW', - 'CreateNW_DCResourceGroupName': DC_RESOURCE_GROUP_APP1, - 'CreateNW_Vlan_DeviceAddress1': vlan_devaddr, - 'CreateNW_VlanLogicalName1': vlan_name, - 'CreateNW_VlanType1': vlan_type}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_update_tenant_fw(self): - device_name = 'TFW0' - device_type = 'TFW' - vlan_name = 'LNW_BusinessVLAN_49' - vlan_type = 'BusinessVLAN' - rd, rj = self.nwa.l3.update_tenant_fw( - TENANT_ID, - device_name, mock.sentinel.vlan_devaddr, - vlan_name, vlan_type, 'connect' - ) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('UpdateTenantFW'), - {'TenantID': TENANT_ID, - 'ReconfigNW_DeviceName1': device_name, - 'ReconfigNW_DeviceType1': device_type, - 'ReconfigNW_VlanLogicalName1': vlan_name, - 'ReconfigNW_Vlan_DeviceAddress1': mock.sentinel.vlan_devaddr, - 'ReconfigNW_VlanType1': vlan_type, - 'ReconfigNW_Vlan_ConnectDevice1': 'connect'}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_update_tenant_fw_without_connect(self): - device_name = 'TFW0' - device_type = 'TFW' - vlan_name = 'LNW_BusinessVLAN_49' - vlan_type = 'BusinessVLAN' - rd, rj = self.nwa.l3.update_tenant_fw( - TENANT_ID, - device_name, mock.sentinel.vlan_devaddr, - vlan_name, vlan_type - ) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('UpdateTenantFW'), - {'TenantID': TENANT_ID, - 'ReconfigNW_DeviceName1': device_name, - 'ReconfigNW_DeviceType1': device_type, - 'ReconfigNW_VlanLogicalName1': vlan_name, - 'ReconfigNW_Vlan_DeviceAddress1': mock.sentinel.vlan_devaddr, - 'ReconfigNW_VlanType1': vlan_type}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_delete_tenant_fw(self): - device_name = 'TFW0' - device_type = 'TFW' - rd, rj = self.nwa.l3.delete_tenant_fw( - TENANT_ID, - device_name, device_type, - ) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('DeleteTenantFW'), - {'TenantID': TENANT_ID, - 'DeleteNW_DeviceName1': device_name, - 'DeleteNW_DeviceType1': device_type}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_setting_nat(self): - fw_name = 'TFW8' - vlan_name = 'LNW_PublicVLAN_46' - vlan_type = 'PublicVLAN' - local_ip = '172.16.0.2' - global_ip = '10.0.0.10' - rd, rj = self.nwa.l3.setting_nat( - TENANT_ID, - vlan_name, vlan_type, local_ip, global_ip, fw_name - ) - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('SettingNAT'), - {'TenantID': TENANT_ID, - 'ReconfigNW_VlanLogicalName1': vlan_name, - 'ReconfigNW_VlanType1': vlan_type, - 'ReconfigNW_DeviceType1': 'TFW', - 'ReconfigNW_DeviceName1': fw_name, - 'LocalIP': local_ip, - 'GlobalIP': global_ip}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_delete_nat(self): - fw_name = 'TFW8' - vlan_name = 'LNW_PublicVLAN_46' - vlan_type = 'PublicVLAN' - local_ip = '172.16.0.2' - global_ip = '10.0.0.10' - - rd, rj = self.nwa.l3.delete_nat( - TENANT_ID, - vlan_name, vlan_type, local_ip, global_ip, fw_name - ) - - self.post.assert_called_once_with( - workflow.NwaWorkflow.path('DeleteNAT'), - {'TenantID': TENANT_ID, - 'DeleteNW_VlanLogicalName1': vlan_name, - 'DeleteNW_VlanType1': vlan_type, - 'DeleteNW_DeviceType1': 'TFW', - 'DeleteNW_DeviceName1': fw_name, - 'LocalIP': local_ip, - 'GlobalIP': global_ip}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def test_update_nat(self): - fw_name = 'TFW8' - vlan_name = 'LNW_PublicVLAN_46' - vlan_type = 'PublicVLAN' - local_ip = '172.16.0.2' - global_ip = '10.0.0.10' - rd, rj = self.nwa.l3.update_nat( - TENANT_ID, - vlan_name, vlan_type, local_ip, global_ip, fw_name - ) - - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 2) diff --git a/networking_nec/tests/unit/nwa/nwalib/test_client_tenant.py b/networking_nec/tests/unit/nwa/nwalib/test_client_tenant.py deleted file mode 100644 index c2b3e28..0000000 --- a/networking_nec/tests/unit/nwa/nwalib/test_client_tenant.py +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock - -from networking_nec.tests.unit.nwa.nwalib import test_client - -TENANT_ID = 'OpenT9004' -DC_RESOURCE_GROUP_POD1 = 'OpenStack/DC1/Common/Pod1Grp/Pod1' -DC_RESOURCE_GROUP_APP1 = 'OpenStack/DC1/Common/App1Grp/App1' - - -class TestNwaClientTenant(test_client.TestNwaClientBase): - - def test_create_tenant(self): - rd, rj = self.nwa.tenant.create_tenant(TENANT_ID) - self.post.assert_called_once_with( - '/umf/tenant/%s' % TENANT_ID, - {'TenantName': TENANT_ID}) - self.assertEqual(rd, 200) - self.assertEqual(rj['status'], 'SUCCESS') - self.assertEqual(self.post.call_count, 1) - - def _test_delete_tenant(self, status_code, sem_delete_tenant_called): - with mock.patch('networking_nec.nwa.nwalib.restclient.' - 'RestClient.delete') as mock_delete, \ - mock.patch('networking_nec.nwa.nwalib.semaphore.' - 'Semaphore.delete_tenant_semaphore') as mock_sem_del: - mock_delete.return_value = (status_code, mock.sentinel.data) - rd, rj = self.nwa.tenant.delete_tenant(TENANT_ID) - - mock_delete.assert_called_once_with('/umf/tenant/%s' % TENANT_ID) - if sem_delete_tenant_called: - mock_sem_del.assert_called_once_with(TENANT_ID) - else: - self.assertEqual(0, mock_sem_del.call_count) - self.assertEqual(rd, status_code) - self.assertEqual(mock.sentinel.data, rj) - self.assertEqual(0, self.post.call_count) - self.assertEqual(1, mock_delete.call_count) - - def test_delete_tenant(self): - self._test_delete_tenant(200, sem_delete_tenant_called=True) - - def test_delete_tenant_non_200(self): - self._test_delete_tenant(500, sem_delete_tenant_called=False) diff --git a/networking_nec/tests/unit/nwa/nwalib/test_exceptions.py b/networking_nec/tests/unit/nwa/nwalib/test_exceptions.py deleted file mode 100644 index b707201..0000000 --- a/networking_nec/tests/unit/nwa/nwalib/test_exceptions.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base - -from networking_nec.nwa.nwalib import exceptions as nwa_exc - - -class TestNwaException(base.BaseTestCase): - def test___str__(self): - exc = nwa_exc.NwaException(200, 'msg1', mock.MagicMock()) - self.assertEqual(str(exc), 'http status: 200, msg1') diff --git a/networking_nec/tests/unit/nwa/nwalib/test_nwa_restclient.py b/networking_nec/tests/unit/nwa/nwalib/test_nwa_restclient.py deleted file mode 100644 index 0f47258..0000000 --- a/networking_nec/tests/unit/nwa/nwalib/test_nwa_restclient.py +++ /dev/null @@ -1,237 +0,0 @@ -# Copyright 2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base -from oslo_config import cfg - -from networking_nec.nwa.nwalib import exceptions as nwa_exc -from networking_nec.nwa.nwalib import nwa_restclient - -TENANT_ID = 'OpenT9004' - - -class TestNwaRestClient(base.BaseTestCase): - - def test_get_client_with_host_port(self): - client = nwa_restclient.NwaRestClient('127.0.0.1', 8080, True) - self.assertEqual('127.0.0.1', client.host) - self.assertEqual(8080, client.port) - self.assertIs(True, client.use_ssl) - - def test_get_client_with_url(self): - cfg.CONF.set_override('server_url', 'http://127.0.0.1:8888', - group='NWA') - client = nwa_restclient.NwaRestClient() - self.assertEqual('127.0.0.1', client.host) - self.assertEqual(8888, client.port) - self.assertIs(False, client.use_ssl) - - def test_get_client_with_url_with_https(self): - cfg.CONF.set_override('server_url', 'https://192.168.1.1:8080', - group='NWA') - client = nwa_restclient.NwaRestClient() - self.assertEqual('192.168.1.1', client.host) - self.assertEqual(8080, client.port) - self.assertIs(True, client.use_ssl) - - def test_get_client_with_no_parameter(self): - self.assertRaises(cfg.Error, nwa_restclient.NwaRestClient) - - def test_get_client_auth_function(self): - cfg.CONF.set_override('access_key_id', - '5g2ZMAdMwZ1gQqZagNqbJSrlopQUAUHILcP2nmxVs28=', - group='NWA') - cfg.CONF.set_override('secret_access_key', - 'JE35Lup5CvI68lneFS4EtSGCh1DnG8dBtTRycPQ83QA=', - group='NWA') - client = nwa_restclient.NwaRestClient('127.0.0.1', 8080, True) - self.assertEqual( - client.auth( - 'Wed, 11 Feb 2015 17:24:51 GMT', - '/umf/tenant/DC1' - ), - b'SharedKeyLite 5g2ZMAdMwZ1gQqZagNqbJSrlopQUAUHILcP2nmxVs28=' - b':mNd/AZJdMawfhJpVUT/lQcH7fPMz+4AocKti1jD1lCI=' - ) - - def test_get_client_auth_function_with_parameters(self): - client = nwa_restclient.NwaRestClient('127.0.0.1', 8080, True, - access_key_id='user', - secret_access_key='password') - self.assertEqual( - client.auth( - 'Wed, 11 Feb 2015 17:24:51 GMT', - '/umf/tenant/DC1' - ), - b'SharedKeyLite user:d7ym8ADuKFoIphXojb1a36lvMb5KZK7fPYKz7RlDcpw=' - ) - - @mock.patch('networking_nec.nwa.nwalib.restclient.RestClient.rest_api') - def test_rest_api_return_check(self, ra): - client = nwa_restclient.NwaRestClient('127.0.0.5', 8085, False) - - body = {'a': 1} - url = '/path' - ra.return_value = (200, None) - hst, rd = client.rest_api('GET', url, body) - self.assertEqual(hst, 200) - self.assertIsNone(rd) - - failed = { - 'status': 'FAILED', 'progress': '100' - } - ra.return_value = (200, failed) - client.post_data = url, body - hst, rd = client.rest_api('GET', url, body) - self.assertEqual(hst, 200) - self.assertEqual(rd, failed) - - ra.side_effect = nwa_exc.NwaException(200, 'msg1', None) - hst, rd = client.rest_api('GET', url, body) - self.assertEqual(hst, 200) - self.assertIsNone(rd) - - @mock.patch('requests.request') - def test_rest_api_raise(self, rr): - def myauth(a, b): - pass - - rr.side_effect = OSError - rcl = nwa_restclient.NwaRestClient('127.0.0.3', 8083, True, myauth) - body = {'a': 1} - url = 'http://127.0.0.5:8085/path' - self.assertRaises( - OSError, - rcl.rest_api, 'GET', url, body - ) - - -class TestNwaRestClientWorkflow(base.BaseTestCase): - - def setUp(self): - super(TestNwaRestClientWorkflow, self).setUp() - host = '127.0.0.1' - port = '12081' - access_key_id = 'PzGIIoLbL7ttHFkDHqLguFz/7+VsVJbDmV0iLWAkJ0g=' - secret_access_key = 'nbvX65iujFoYomXTKROF9GKUN6L2rAM/sI+cvNdW7sw=' - - self.nwa = nwa_restclient.NwaRestClient( - host=host, port=port, access_key_id=access_key_id, - secret_access_key=secret_access_key - ) - self.nwa.workflow_first_wait = 0 - - def test_get_client_workflow_parameters(self): - cfg.CONF.set_override('scenario_polling_first_timer', 1, group='NWA') - cfg.CONF.set_override('scenario_polling_timer', 2, group='NWA') - cfg.CONF.set_override('scenario_polling_count', 3, group='NWA') - nwa_client = nwa_restclient.NwaRestClient('127.0.0.1', 8080, True) - self.assertEqual(1, nwa_client.workflow_first_wait) - self.assertEqual(2, nwa_client.workflow_wait_sleep) - self.assertEqual(3, nwa_client.workflow_retry_count) - - def test_workflow_kick_and_wait_raise(self): - call_ne = mock.MagicMock( - side_effect=nwa_exc.NwaException(200, 'm1', None)) - call_ne.__name__ = 'POST' - self.assertRaises( - nwa_exc.NwaException, - self.nwa.workflow_kick_and_wait, call_ne, None, None - ) - - @mock.patch('eventlet.semaphore.Semaphore.locked') - @mock.patch('networking_nec.nwa.nwalib.nwa_restclient.NwaRestClient.' - 'workflowinstance') - def test_workflow_kick_and_wait(self, wki, lock): - call = mock.MagicMock() - call.__name__ = 'POST' - call.return_value = 200, None - hst, rd = self.nwa.workflow_kick_and_wait(call, None, None) - self.assertEqual(hst, 200) - self.assertIsNone(rd) - - call.return_value = 200, {'executionid': 1} - wki.return_value = 201, None - hst, rd = self.nwa.workflow_kick_and_wait(call, None, None) - self.assertEqual(hst, 201) - self.assertIsNone(rd) - - call.return_value = 200, {'executionid': '1'} - wki.return_value = 202, None - hst, rd = self.nwa.workflow_kick_and_wait(call, None, None) - self.assertEqual(hst, 202) - self.assertIsNone(rd) - - wki.return_value = 201, {'status': 'RUNNING'} - self.nwa.workflow_retry_count = 1 - hst, rd = self.nwa.workflow_kick_and_wait(call, None, None) - self.assertEqual(hst, 201) - self.assertIsNone(rd) - - wki.side_effect = Exception - hst, rd = self.nwa.workflow_kick_and_wait(call, None, None) - self.assertEqual(hst, 200) - self.assertIsNone(rd) - - @mock.patch('eventlet.semaphore.Semaphore.locked') - @mock.patch('networking_nec.nwa.nwalib.nwa_restclient.NwaRestClient.' - 'workflow_kick_and_wait') - @mock.patch('networking_nec.nwa.nwalib.workflow.NwaWorkflow._nameid', - new_callable=mock.PropertyMock) - def test_call_workflow(self, nameid, wkaw, lock): - call = mock.MagicMock() - call.__name__ = 'POST' - - wkaw.return_value = 200, '0' - nameid.return_value = {'name_0': 'url_0'} - hst, rd = self.nwa.call_workflow('0', call, 'name_0', 'body_0') - self.assertEqual(hst, 200) - self.assertEqual(rd, '0') - - wkaw.return_value = 201, '1' - nameid.return_value = {'name_1': 'url_1'} - hst, rd = self.nwa.call_workflow('1', call, 'name_1', 'body_1') - self.assertEqual(hst, 201) - self.assertEqual(rd, '1') - - def test_get_reserved_dc_resource(self): - self.nwa.get_reserved_dc_resource(TENANT_ID) - - def test_get_tenant_resource(self): - self.nwa.get_tenant_resource(TENANT_ID) - - def test_get_dc_resource_groups(self): - self.nwa.get_dc_resource_groups('OpenStack/DC1/Common/Pod2Grp/Pod2') - - @mock.patch('networking_nec.nwa.nwalib.nwa_restclient.NwaRestClient.get') - def test_get_workflow_list(self, get): - get.return_value = 209, None - hst, rd = self.nwa.get_workflow_list() - self.assertEqual(hst, 209) - self.assertIsNone(rd) - - get.side_effect = Exception - hst, rd = self.nwa.get_workflow_list() - self.assertIsNone(hst) - self.assertIsNone(rd) - - def test_stop_workflowinstance(self): - self.nwa.stop_workflowinstance('id-0') - - def test_update_workflow_list(self): - self.nwa.update_workflow_list() - - def test_wait_workflow_done(self): - self.nwa.wait_workflow_done(mock.MagicMock()) diff --git a/networking_nec/tests/unit/nwa/nwalib/test_restclient.py b/networking_nec/tests/unit/nwa/nwalib/test_restclient.py deleted file mode 100644 index 821d34b..0000000 --- a/networking_nec/tests/unit/nwa/nwalib/test_restclient.py +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import datetime - -import mock -from neutron.tests import base -import requests - -from networking_nec.nwa.nwalib import exceptions as nwa_exc -from networking_nec.nwa.nwalib import restclient - - -class TestRestClient(base.BaseTestCase): - def setUp(self): - super(TestRestClient, self).setUp() - self.rcl = restclient.RestClient() - - def test__url(self): - rcl = restclient.RestClient('127.0.0.2', 8081, True) - path = '/path' - u = rcl._url(path) - self.assertEqual(u, 'https://127.0.0.2:8081' + path) - - @mock.patch('networking_nec.nwa.nwalib.restclient.utcnow') - @mock.patch('requests.request') - def test__send_receive(self, rr, utcnow): - now_for_test = datetime.datetime(2016, 2, 24, 5, 23) - now_string = 'Wed, 24 Feb 2016 05:23:00 GMT' - utcnow.return_value = now_for_test - myauth = mock.Mock() - myauth.return_value = mock.sentinel.auth_val - rcl = restclient.RestClient('127.0.0.3', 8083, True, myauth) - rcl._send_receive('GET', '/path') - rr.assert_called_once_with( - 'GET', 'https://127.0.0.3:8083/path', - data=None, - headers={'Authorization': mock.sentinel.auth_val, - 'Content-Type': 'application/json', - 'Date': now_string, - 'X-UMF-API-Version': restclient.UMF_API_VERSION}, - verify=False, - proxies={'no': 'pass'}) - myauth.assert_called_once_with(now_string, '/path') - - @mock.patch('requests.request') - def test_rest_api(self, rr): - def myauth(a, b): - pass - - rcl = restclient.RestClient('127.0.0.4', 8084, True, myauth) - body = {} - url = 'http://127.0.0.4:8084/path' - rr.side_effect = requests.exceptions.RequestException - self.assertRaises( - nwa_exc.NwaException, - rcl.rest_api, 'GET', url, body - ) - - @mock.patch('requests.request') - def test_rest_api_raise(self, rr): - def myauth(a, b): - pass - - rr.side_effect = OSError - rcl = restclient.RestClient('127.0.0.3', 8083, True, myauth) - body = {'a': 1} - url = 'http://127.0.0.5:8085/path' - self.assertRaises( - OSError, - rcl.rest_api, 'GET', url, body - ) - - @mock.patch('networking_nec.nwa.nwalib.restclient.RestClient.rest_api') - def test_get(self, rarc): - self.rcl.get('') - self.assertEqual(rarc.call_count, 1) - - @mock.patch('networking_nec.nwa.nwalib.restclient.RestClient.rest_api') - def test_post(self, rarc): - self.rcl.post('') - self.assertEqual(rarc.call_count, 1) - - @mock.patch('networking_nec.nwa.nwalib.restclient.RestClient.rest_api') - def test_put(self, rarc): - self.rcl.put('') - self.assertEqual(rarc.call_count, 1) - - @mock.patch('networking_nec.nwa.nwalib.restclient.RestClient.rest_api') - def test_delete(self, rarc): - self.rcl.delete('') - self.assertEqual(rarc.call_count, 1) diff --git a/networking_nec/tests/unit/nwa/nwalib/test_semaphore.py b/networking_nec/tests/unit/nwa/nwalib/test_semaphore.py deleted file mode 100644 index 402ea6b..0000000 --- a/networking_nec/tests/unit/nwa/nwalib/test_semaphore.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base - -from networking_nec.nwa.nwalib import semaphore as nwa_sem - - -class TestThread(base.BaseTestCase): - def test_stop(self): - t1 = nwa_sem.Thread(mock.MagicMock()) - t1.stop() - - def test_wait(self): - t1 = nwa_sem.Thread(mock.MagicMock()) - t1.wait() - - -class TestSemaphore(base.BaseTestCase): - def test_get_tenant_semaphore(self): - sem1 = nwa_sem.Semaphore.get_tenant_semaphore('T1') - sem2 = nwa_sem.Semaphore.get_tenant_semaphore('T1') - self.assertEqual(sem1, sem2) - - sem3 = nwa_sem.Semaphore.get_tenant_semaphore('T2') - self.assertTrue(sem1 != sem3) - - nwa_sem.Semaphore.delete_tenant_semaphore('T1') - sem4 = nwa_sem.Semaphore.get_tenant_semaphore('T1') - self.assertTrue(sem1 != sem4) - - def test_get_tenant_semaphore_raise1(self): - self.assertRaises( - TypeError, - nwa_sem.Semaphore.get_tenant_semaphore, 0 - ) - - def test_get_tenant_semaphore_raise2(self): - self.assertRaises( - TypeError, - nwa_sem.Semaphore.get_tenant_semaphore, '' - ) - - def test_delete_tenant_semaphore(self): - nwa_sem.Semaphore.delete_tenant_semaphore('T11') - self.assertTrue(True) diff --git a/networking_nec/tests/unit/nwa/nwalib/test_workflow.py b/networking_nec/tests/unit/nwa/nwalib/test_workflow.py deleted file mode 100644 index cad68ae..0000000 --- a/networking_nec/tests/unit/nwa/nwalib/test_workflow.py +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright 2015-2016 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from neutron.tests import base - -from networking_nec.nwa.nwalib import workflow - - -class TestNwaWorkflow(base.BaseTestCase): - def test_strerror(self): - em = workflow.NwaWorkflow.strerror('1') - self.assertEqual(em, 'Unknown parent node') - em = workflow.NwaWorkflow.strerror('299') - self.assertEqual(em, 'Unknown error') - - def test_get_errno_from_resultdata(self): - geterrno = workflow.NwaWorkflow.get_errno_from_resultdata - rc = geterrno({}) - self.assertIsNone(rc) - - rc = geterrno({ - 'resultdata': {} - }) - self.assertIsNone(rc) - - rc = geterrno({ - 'resultdata': { - 'ErrorMessage': '' - } - }) - self.assertIsNone(rc) - - rc = geterrno({ - 'resultdata': { - 'ErrorMessage': 'ErrorNumber=100' - } - }) - self.assertEqual(rc, '100') - - rc = geterrno({ - 'resultdata': { - 'ErrorMessage': 'ReservationErrorCode = 101' - } - }) - self.assertEqual(rc, '101') - - def test_update_nameid(self): - with mock.patch('networking_nec.nwa.nwalib.workflow' - '.NwaWorkflow._nameid', - new_callable=mock.PropertyMock) as nameid, \ - mock.patch('networking_nec.nwa.nwalib.workflow' - '.NwaWorkflow._nameid_initialized', - new_callable=mock.PropertyMock): - - # When nameid is initialized, nameid will be unchanged. - workflow.NwaWorkflow._nameid_initialized = True - nameid.return_value = mock.sentinel.nameid - workflow.NwaWorkflow.update_nameid({'foo': '1'}) - self.assertTrue(workflow.NwaWorkflow._nameid_initialized) - self.assertIs(mock.sentinel.nameid, workflow.NwaWorkflow._nameid) - - # If passed nameid is empty, nameid will be unchanged. - workflow.NwaWorkflow._nameid_initialized = False - nameid.return_value = mock.sentinel.nameid - workflow.NwaWorkflow.update_nameid({}) - self.assertFalse(workflow.NwaWorkflow._nameid_initialized) - self.assertIs(mock.sentinel.nameid, workflow.NwaWorkflow._nameid) - - # If nameid is not initialized and passed nameid is not empty, - # nameid will be initialized. - workflow.NwaWorkflow._nameid_initialized = False - workflow.NwaWorkflow.update_nameid({'foo': '1'}) - self.assertTrue(workflow.NwaWorkflow._nameid_initialized) - self.assertDictEqual({'foo': '1'}, workflow.NwaWorkflow._nameid) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 8d829c7..0000000 --- a/requirements.txt +++ /dev/null @@ -1,27 +0,0 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. - -pbr>=1.6 # Apache-2.0 - -Babel>=2.3.4 # BSD -debtcollector>=1.2.0 # Apache-2.0 -eventlet!=0.18.3,>=0.18.2 # MIT -netaddr!=0.7.16,>=0.7.13 # BSD -neutron-lib>=0.4.0 # Apache-2.0 -oslo.config>=3.14.0 # Apache-2.0 -oslo.i18n>=2.1.0 # Apache-2.0 -oslo.log>=1.14.0 # Apache-2.0 -oslo.messaging>=5.2.0 # Apache-2.0 -oslo.serialization>=1.10.0 # Apache-2.0 -oslo.service>=1.10.0 # Apache-2.0 -oslo.utils>=3.16.0 # Apache-2.0 -requests>=2.10.0 # Apache-2.0 -six>=1.9.0 # MIT -SQLAlchemy<1.1.0,>=1.0.10 # MIT -WebOb>=1.2.3 # MIT - -# This project does depend on neutron as a library, but the -# openstack tooling does not play nicely with projects that -# are not publicly available in pypi. -# -e git+https://git.openstack.org/openstack/neutron#egg=neutron diff --git a/rpm/neutron-necnwa-agent.service b/rpm/neutron-necnwa-agent.service deleted file mode 100644 index 063f703..0000000 --- a/rpm/neutron-necnwa-agent.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=OpenStack Neutron NEC NWA Agent -After=syslog.target network.target - -[Service] -Type=simple -User=neutron -ExecStart=/usr/bin/neutron-necnwa-agent --config-file /usr/share/neutron/neutron-dist.conf --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini --log-file /var/log/neutron/necnwa-agent.log -PrivateTmp=false - -[Install] -WantedBy=multi-user.target diff --git a/rpm/neutron-necnwa-cleanup b/rpm/neutron-necnwa-cleanup deleted file mode 100755 index 3ee106c..0000000 --- a/rpm/neutron-necnwa-cleanup +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -debug=true -interval=300 -conf=/etc/neutron/neutron.conf -logfile=/var/log/neutron/necnwa-cleanup.log -keyconf=/etc/keystone/keystone.conf - -while [[ $# > 1 ]] -do - key="$1" - case $key in - --config-file) - conf="$2" - shift - ;; - --log-file) - logfile="$2" - shift - ;; - *) - ;; - esac - shift -done - -exec 6>&1 -exec >> $logfile 2>&1 - -line=$(sed -n -r 's,^\s*connection\s*=\s*mysql://([^:]?+):([^@]?+)@.*,\1 \2,p' $conf) -set -- $line -db_user=$1 -db_password=$2 - -if [ -z "$db_user" ]; then - echo 1>&2 "Error: db_user is not defined" - exit 1 -fi -if [ -z "$db_password" ]; then - echo 1>&2 "Error: db_password is not defined" - exit 1 -fi -db_table=neutron -mysql="mysql -u$db_user -p$db_password $db_table" - -line=$(sed -n -r 's,^\s*connection\s*=\s*mysql://([^:]?+):([^@]?+)@.*,\1 \2,p' $keyconf) -set -- $line -key_user=$1 -key_pass=$2 -list_cmd="mysql -u$key_user -p$key_pass keystone" - -while true -do - date=$(date '+%Y-%m-%d %H:%M:%S.000') - project_list=$($list_cmd -e 'select * from project;' 2>/dev/null | \ - egrep -v -e 'id *name' |awk '{print $1;}') - queue_list=$($mysql -e 'select * from nwa_tenant_queue;' | \ - egrep -v -e '\-\-|tenant_id' | awk '{print $1;}') - for q in $queue_list; do - remove=true - for p in $project_list; do - if [[ $p == $q ]]; then - remove=false - break - fi - done - if $remove; then - op="delete from nwa_tenant_queue where tenant_id = '$q';" - echo "$date $$ INFO $op" >>$logfile 2>&1 - $mysql -e "$op" - fi - done - sleep $interval -done -# echo "Now, execute the following command:" -# echo " $ sudo systemctl restart neutron-server neutron-necnwa-agent" diff --git a/rpm/neutron-necnwa-cleanup.service b/rpm/neutron-necnwa-cleanup.service deleted file mode 100644 index c011b0e..0000000 --- a/rpm/neutron-necnwa-cleanup.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=OpenStack Neutron NECNWA Agent Cleanup Queue -After=syslog.target network.target - -[Service] -Type=simple -User=neutron -ExecStart=/usr/bin/neutron-necnwa-cleanup --config-file /etc/neutron/neutron.conf --log-file /var/log/neutron/necnwa-cleanup.log -PrivateTmp=false - -[Install] -WantedBy=multi-user.target diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b246926..0000000 --- a/setup.cfg +++ /dev/null @@ -1,66 +0,0 @@ -[metadata] -name = networking-nec -summary = Neutron plugins/drivers for NEC networking products -description-file = - README.rst -author = OpenStack -author-email = openstack-dev@lists.openstack.org -home-page = http://www.openstack.org/ -classifier = - Environment :: OpenStack - Intended Audience :: Information Technology - Intended Audience :: System Administrators - License :: OSI Approved :: Apache Software License - Operating System :: POSIX :: Linux - Programming Language :: Python - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.7 - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.4 - -[files] -packages = - networking_nec -data_files = - etc/ = etc/* - -[entry_points] -console_scripts = - neutron-necnwa-agent = networking_nec.cmd.eventlet.nwa_agent:main -neutron.core_plugins = - necnwa = networking_nec.nwa.l2.plugin:NECNWAL2Plugin -neutron.service_plugins = - necnwa_router = networking_nec.nwa.l3.plugin:NECNWAL3Plugin -neutron.ml2.mechanism_drivers = - necnwa = networking_nec.nwa.l2.drivers.mech_necnwa:NECNWAMechanismDriver -neutron.db.alembic_migrations = - networking-nec = networking_nec.db.migration:alembic_migrations - -[global] -setup-hooks = - pbr.hooks.setup_hook - -[build_sphinx] -source-dir = doc/source -build-dir = doc/build -all_files = 1 - -[upload_sphinx] -upload-dir = doc/build/html - -[compile_catalog] -directory = networking_nec/locale -domain = networking_nec - -[update_catalog] -domain = networking_nec -output_dir = networking_nec/locale -input_file = networking_nec/locale/networking_nec.pot - -[extract_messages] -keywords = _ gettext ngettext l_ lazy_gettext -mapping_file = babel.cfg -output_file = networking_nec/locale/networking_nec.pot - -[wheel] -universal = 1 diff --git a/setup.py b/setup.py deleted file mode 100644 index 782bb21..0000000 --- a/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT -import setuptools - -# In python < 2.7.4, a lazy loading of package `pbr` will break -# setuptools if some other modules registered functions in `atexit`. -# solution from: http://bugs.python.org/issue15881#msg170215 -try: - import multiprocessing # noqa -except ImportError: - pass - -setuptools.setup( - setup_requires=['pbr>=1.8'], - pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt deleted file mode 100644 index 45282c5..0000000 --- a/test-requirements.txt +++ /dev/null @@ -1,22 +0,0 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. - -hacking<0.11,>=0.10.0 - -astroid<1.4.0 # LGPLv2.1 # breaks pylint 1.4.4 -coverage>=3.6 # Apache-2.0 -fixtures>=3.0.0 # Apache-2.0/BSD -mock>=2.0 # BSD -pylint==1.4.5 # GPLv2 -python-subunit>=0.0.18 # Apache-2.0/BSD -requests-mock>=1.0 # Apache-2.0 -sphinx!=1.3b1,<1.3,>=1.2.1 # BSD -oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0 -oslotest>=1.10.0 # Apache-2.0 -tempest-lib>=0.14.0 # Apache-2.0 -testrepository>=0.0.18 # Apache-2.0/BSD -testresources>=0.2.4 # Apache-2.0/BSD -testscenarios>=0.4 # Apache-2.0/BSD -testtools>=1.4.0 # MIT -WebTest>=2.0 # MIT diff --git a/tools/coding-checks.sh b/tools/coding-checks.sh deleted file mode 100644 index 550658a..0000000 --- a/tools/coding-checks.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh - -set -eu - -usage () { - echo "Usage: $0 [OPTION]..." - echo "Run Neutron's coding check(s)" - echo "" - echo " -Y, --pylint [] Run pylint check on the entire networking_nec module or just files changed in basecommit (e.g. HEAD~1)" - echo " -h, --help Print this usage message" - echo - exit 0 -} - -process_options () { - i=1 - while [ $i -le $# ]; do - eval opt=\$$i - case $opt in - -h|--help) usage;; - -Y|--pylint) pylint=1;; - *) scriptargs="$scriptargs $opt" - esac - i=$((i+1)) - done -} - -run_pylint () { - local target="${scriptargs:-all}" - - if [ "$target" = "all" ]; then - files="networking_nec" - else - case "$target" in - *HEAD~[0-9]*) files=$(git diff --diff-filter=AM --name-only $target -- "*.py");; - *) echo "$target is an unrecognized basecommit"; exit 1;; - esac - fi - - echo "Running pylint..." - echo "You can speed this up by running it on 'HEAD~[0-9]' (e.g. HEAD~1, this change only)..." - if [ -n "${files}" ]; then - pylint --rcfile=.pylintrc --output-format=colorized ${files} - else - echo "No python changes in this commit, pylint check not required." - exit 0 - fi -} - -scriptargs= -pylint=1 - -process_options $@ - -if [ $pylint -eq 1 ]; then - run_pylint - exit 0 -fi diff --git a/tools/pretty_tox.sh b/tools/pretty_tox.sh deleted file mode 100755 index 61d5bfd..0000000 --- a/tools/pretty_tox.sh +++ /dev/null @@ -1,13 +0,0 @@ -#! /bin/sh - -TESTRARGS=$1 - -# Delete bytecodes from normal directories before running tests. -# Note that bytecodes in dot directories will not be deleted -# to keep bytecodes of python modules installed into virtualenvs. -sh -c "find . -type d -name '.?*' -prune -o \ - \( -type d -name '__pycache__' -o -type f -name '*.py[co]' \) \ - -print0 | xargs -0 rm -rf" - -exec 3>&1 -status=$(exec 4>&1 >&3; ( python setup.py testr --slowest --testr-args="--subunit $TESTRARGS"; echo $? >&4 ) | subunit-trace -f) && exit $status diff --git a/tools/tox_install.sh b/tools/tox_install.sh deleted file mode 100755 index e40f212..0000000 --- a/tools/tox_install.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh - -# Many of neutron's repos suffer from the problem of depending on neutron, -# but it not existing on pypi. - -# This wrapper for tox's package installer will use the existing package -# if it exists, else use zuul-cloner if that program exists, else grab it -# from neutron master via a hard-coded URL. That last case should only -# happen with devs running unit tests locally. - -# From the tox.ini config page: -# install_command=ARGV -# default: -# pip install {opts} {packages} - -ZUUL_CLONER=/usr/zuul-env/bin/zuul-cloner -neutron_installed=$(echo "import neutron" | python 2>/dev/null ; echo $?) -# Neutron branch to be used -BRANCH_NAME=master - -set -e - -CONSTRAINTS_FILE=$1 -shift - -install_cmd="pip install" -if [ $CONSTRAINTS_FILE != "unconstrained" ]; then - install_cmd="$install_cmd -c$CONSTRAINTS_FILE" -fi - -if [ $neutron_installed -eq 0 ]; then - echo "ALREADY INSTALLED" > /tmp/tox_install.txt - echo "Neutron already installed; using existing package" -elif [ -x "$ZUUL_CLONER" ]; then - echo "ZUUL CLONER" > /tmp/tox_install.txt - cwd=$(/bin/pwd) - cd /tmp - $ZUUL_CLONER --cache-dir \ - /opt/git \ - --branch $BRANCH_NAME \ - git://git.openstack.org \ - openstack/neutron - cd openstack/neutron - $install_cmd -e . - cd "$cwd" -else - echo "PIP HARDCODE" > /tmp/tox_install.txt - $install_cmd -U -egit+https://git.openstack.org/openstack/neutron.git@$BRANCH_NAME#egg=neutron -fi - -$install_cmd -U $* -exit $? diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 153399a..0000000 --- a/tox.ini +++ /dev/null @@ -1,52 +0,0 @@ -[tox] -minversion = 1.6 -envlist = py34,py27,pep8 -skipsdist = True - -[testenv] -usedevelop = True -install_command = - # networking-nec is still targetted to Mitaka development, - # so we need to use upper-constraints.txt from stable/mitaka branch. - {toxinidir}/tools/tox_install.sh {env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=master} {opts} {packages} -# Note the hash seed is set to 0 until neutron can be tested with a -# random hash seed successfully. -setenv = - VIRTUAL_ENV={envdir} - PYTHONWARNINGS=default::DeprecationWarning -deps = -r{toxinidir}/test-requirements.txt -whitelist_externals = sh -commands = - sh tools/pretty_tox.sh '{posargs}' -# there is also secret magic in pretty_tox.sh which lets you run in a fail only -# mode. To do this define the TRACE_FAILONLY environmental variable. - -[testenv:pep8] -deps = - {[testenv]deps} -commands = - flake8 - sh ./tools/coding-checks.sh --pylint '{posargs}' - neutron-db-manage --subproject networking-nec --database-connection sqlite:// check_migration - -[testenv:venv] -commands = {posargs} - -[testenv:cover] -commands = python setup.py test --coverage --coverage-package-name=networking_nec --testr-args='{posargs}' - -[testenv:docs] -commands = sphinx-build -W -b html doc/source doc/build/html - -[testenv:debug] -commands = oslo_debug_helper {posargs} - -[flake8] -# TODO(dougwig) -- uncomment this to test for remaining linkages -# N530 direct neutron imports not allowed -ignore = N530 -exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build - -[hacking] -import_exceptions = networking_nec._i18n -local-check-factory = neutron_lib.hacking.checks.factory