diff --git a/cloudpulse/scenario/plugins/operator_tests/operator.py b/cloudpulse/scenario/plugins/operator_tests/operator.py index 8aad1bd..28d3e46 100644 --- a/cloudpulse/scenario/plugins/operator_tests/operator.py +++ b/cloudpulse/scenario/plugins/operator_tests/operator.py @@ -18,6 +18,7 @@ from cloudpulse.operator.ansible.openstack_node_info_reader import \ from cloudpulse.scenario import base import errno +import netifaces as ni import os from oslo_config import cfg from oslo_utils import importutils @@ -49,6 +50,12 @@ TESTS_OPTS = [ help='name of the ceph cluster container'), ] +INTERFACE_OPTS = [ + cfg.StrOpt('name', + default='eth0', + help='Name of Interface On which Ansible Commands to Run'), +] + PERIODIC_TESTS_OPTS = [ cfg.IntOpt('rabbitmq_check', default=0, @@ -71,7 +78,10 @@ PERIODIC_TESTS_OPTS = [ ] CONF = cfg.CONF - +interface_group =cfg.OptGroup(name='ansible_interface', + title='Name of Interface') +CONF.register_group(interface_group) +CONF.register_opts(INTERFACE_OPTS, interface_group) operator_test_group = cfg.OptGroup(name='operator_test', title='Options for the Operators') CONF.register_group(operator_test_group) @@ -85,6 +95,16 @@ cfg.CONF.import_opt('auth_uri', 'keystonemiddleware.auth_token', group='keystone_authtoken') +def get_ip_by_interface(ifname): + """ + Get IP by Interface e.g. iface, eth0 + """ + try: + ifname_ip = ni.ifaddresses(ifname)[ni.AF_INET][0]['addr'] + return ifname_ip + except Exception as e: + return '127.0.0.1' + def execute(command): try: @@ -107,7 +127,8 @@ def execute(command): def get_container_name(name, container_command='docker'): - cmd = "ansible -o all -i 127.0.0.1, -a '%s ps' -u root" % container_command + iface = get_ip_by_interface(cfg.CONF.ansible_interface.name) + cmd = "ansible -o all -i %s, -a '%s ps' -u root" % (iface, container_command) op = execute(cmd) if op['status']: return None @@ -150,7 +171,8 @@ class operator_scenario(base.Scenario): @base.scenario(admin_only=False, operator=True) def rabbitmq_check(self): self.load() - anscmd = "ansible -o all -i 127.0.0.1, -a " + iface = get_ip_by_interface(cfg.CONF.ansible_interface.name) + anscmd = "ansible -o all -i {}, -a ".format(iface) cmd = "rabbitmqctl cluster_status -q" is_containerized = cfg.CONF.operator_test.containerized @@ -197,7 +219,8 @@ class operator_scenario(base.Scenario): @base.scenario(admin_only=False, operator=True) def galera_check(self): self.load() - anscmd = "ansible -o all -i 127.0.0.1, -a " + iface = get_ip_by_interface(cfg.CONF.ansible_interface.name) + anscmd = "ansible -o all -i {}, -a ".format(iface) galera = self.os_node_info_obj.get_galera_details() cmd = ((r'mysql -u %s -p%s -e "SHOW STATUS;"') % @@ -312,7 +335,8 @@ class operator_scenario(base.Scenario): if is_containerized: ceph_container = get_container_name("cephmon", self.container_command) cmd = ("'%s exec %s %s'" % (self.container_command, ceph_container, cmd)) - anscmd = "ansible -o all -i 127.0.0.1, -a " + iface = get_ip_by_interface(cfg.CONF.ansible_interface.name) + anscmd = "ansible -o all -i {}, -a ".format(iface) cmd = anscmd + cmd + ' -u root' res = execute(cmd) diff --git a/cloudpulse/tests/base.py b/cloudpulse/tests/base.py index d009088..73af075 100644 --- a/cloudpulse/tests/base.py +++ b/cloudpulse/tests/base.py @@ -22,11 +22,11 @@ from cloudpulse.common import context as cpulse_context from cloudpulse.objects import base as objects_base from cloudpulse.tests import conf_fixture -import mock from oslo_config import cfg from oslotest import base import pecan from pecan import testing +from unittest import mock CONF = cfg.CONF CONF.set_override('use_stderr', False) diff --git a/cloudpulse/tests/fakes.py b/cloudpulse/tests/fakes.py index e85350a..229e6a7 100644 --- a/cloudpulse/tests/fakes.py +++ b/cloudpulse/tests/fakes.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock fakeAuthTokenHeaders = {'X-User-Id': '773a902f022949619b5c2f32cd89d419', 'X-Roles': 'admin, ResellerAdmin, _member_', diff --git a/cloudpulse/tests/unit/api/base.py b/cloudpulse/tests/unit/api/base.py index b83ff12..88f59e7 100644 --- a/cloudpulse/tests/unit/api/base.py +++ b/cloudpulse/tests/unit/api/base.py @@ -20,11 +20,11 @@ # NOTE(deva): import auth_token so we can override a config option from keystonemiddleware import auth_token # noqa -import mock from oslo_config import cfg import pecan import pecan.testing from six.moves.urllib import parse as urlparse +from unittest import mock from cloudpulse.api import hooks from cloudpulse.db import api as dbapi diff --git a/cloudpulse/tests/unit/api/controllers/v1/test_cpulse.py b/cloudpulse/tests/unit/api/controllers/v1/test_cpulse.py index 293dd4e..60749a0 100644 --- a/cloudpulse/tests/unit/api/controllers/v1/test_cpulse.py +++ b/cloudpulse/tests/unit/api/controllers/v1/test_cpulse.py @@ -14,8 +14,8 @@ from cloudpulse import objects from cloudpulse.tests.unit.db import base as db_base from cloudpulse.tests.unit.db import utils -import mock -from mock import patch +from unittest import mock +from unittest.mock import patch from webtest.app import AppError diff --git a/cloudpulse/tests/unit/api/test_auth.py b/cloudpulse/tests/unit/api/test_auth.py index 48e6350..47dffd4 100644 --- a/cloudpulse/tests/unit/api/test_auth.py +++ b/cloudpulse/tests/unit/api/test_auth.py @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock from oslo_config import fixture +from unittest import mock from cloudpulse.api import auth from cloudpulse.tests import base diff --git a/cloudpulse/tests/unit/api/test_hooks.py b/cloudpulse/tests/unit/api/test_hooks.py index eabd90c..b2c73f0 100644 --- a/cloudpulse/tests/unit/api/test_hooks.py +++ b/cloudpulse/tests/unit/api/test_hooks.py @@ -15,9 +15,9 @@ import json -import mock from oslo_config import cfg import oslo_messaging as messaging +from unittest import mock from cloudpulse.api.controllers import root from cloudpulse.api import hooks diff --git a/cloudpulse/tests/unit/common/test_timerthread.py b/cloudpulse/tests/unit/common/test_timerthread.py index 45f835e..b33cc3c 100644 --- a/cloudpulse/tests/unit/common/test_timerthread.py +++ b/cloudpulse/tests/unit/common/test_timerthread.py @@ -14,8 +14,8 @@ from cloudpulse import objects from cloudpulse.tests.unit.db import base as db_base from cloudpulse.tests.unit.db import utils -from mock import patch import time +from unittest.mock import patch class Test_Cpulse_TimerThread(db_base.DbTestCase): diff --git a/cloudpulse/tests/unit/objects/test_cpulse.py b/cloudpulse/tests/unit/objects/test_cpulse.py index 4e7646c..7a1e1cf 100644 --- a/cloudpulse/tests/unit/objects/test_cpulse.py +++ b/cloudpulse/tests/unit/objects/test_cpulse.py @@ -15,7 +15,7 @@ from cloudpulse import objects from cloudpulse.tests.unit.db import base from cloudpulse.tests.unit.db import utils -import mock +from unittest import mock class TestCpulseObject(base.DbTestCase): diff --git a/requirements.txt b/requirements.txt index 0da10a1..8ef2c8a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ ansible<2.0.0.0 eventlet!=0.18.3,>=0.18.2 # MIT keystonemiddleware>=4.0.0,!=4.1.0,!=4.5.0 # Apache-2.0 mysql-connector +netifaces!=0.10.0,!=0.10.1 PyMySQL>=0.6.2,!=0.7.7 # MIT License oslo.config>=3.14.0 # Apache-2.0 oslo.concurrency>=3.8.0 # Apache-2.0 diff --git a/test-requirements.txt b/test-requirements.txt index 283be04..cf83be4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -14,4 +14,3 @@ oslotest>=1.10.0 # Apache-2.0 stestr>=2.0.0 testscenarios>=0.4 testtools>=1.4.0 -mock==3.0.5