Adding configurable ansible interface instead of using localhost

Change-Id: I318ed1c8206e3be7ea68780c240f14d44767f698
This commit is contained in:
Anand Shanmugam 2021-02-26 11:35:00 +05:30
parent 3df51704bd
commit 9d6224fc90
11 changed files with 39 additions and 15 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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_',

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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

View File

@ -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