Unify auth parameters between drivers
Change-Id: I4b5f4f2920e1592459e8ffe6632c4c3cb007acc9
This commit is contained in:
parent
fedc060158
commit
601c49cca0
|
@ -28,6 +28,9 @@ from os_faults.api import error
|
|||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
STDOUT_LIMIT = 4096 # Symbols count
|
||||
ANSIBLE_FORKS = 100
|
||||
|
||||
STATUS_OK = 'OK'
|
||||
STATUS_FAILED = 'FAILED'
|
||||
STATUS_UNREACHABLE = 'UNREACHABLE'
|
||||
|
@ -39,8 +42,6 @@ SSH_COMMON_ARGS = ('-o UserKnownHostsFile=/dev/null '
|
|||
'-o StrictHostKeyChecking=no '
|
||||
'-o ConnectTimeout=60')
|
||||
|
||||
STDOUT_LIMIT = 4096 # Symbols count
|
||||
|
||||
|
||||
class AnsibleExecutionException(Exception):
|
||||
pass
|
||||
|
@ -100,36 +101,18 @@ def make_module_path_option():
|
|||
|
||||
Options = collections.namedtuple(
|
||||
'Options',
|
||||
['connection', 'module_path', 'forks',
|
||||
'remote_user', 'private_key_file',
|
||||
'ssh_common_args', 'ssh_extra_args', 'sftp_extra_args',
|
||||
'scp_extra_args', 'become', 'become_method',
|
||||
'become_user', 'verbosity', 'check', 'diff'])
|
||||
['connection', 'module_path', 'forks'])
|
||||
|
||||
|
||||
class AnsibleRunner(object):
|
||||
def __init__(self, remote_user='root', password=None, forks=100,
|
||||
jump_host=None, jump_user=None, private_key_file=None,
|
||||
become=None, become_password=None, serial=None):
|
||||
def __init__(self, auth=None, forks=ANSIBLE_FORKS, serial=None):
|
||||
super(AnsibleRunner, self).__init__()
|
||||
|
||||
ssh_common_args = SSH_COMMON_ARGS
|
||||
if jump_host:
|
||||
ssh_common_args += self._build_proxy_arg(
|
||||
jump_host=jump_host,
|
||||
jump_user=jump_user or remote_user,
|
||||
private_key_file=private_key_file)
|
||||
|
||||
self.passwords = dict(conn_pass=password, become_pass=become_password)
|
||||
self.default_host_vars = self._build_auth_host_vars(auth)
|
||||
self.options = Options(
|
||||
connection='smart',
|
||||
module_path=make_module_path_option(),
|
||||
forks=forks, remote_user=remote_user,
|
||||
private_key_file=private_key_file,
|
||||
ssh_common_args=ssh_common_args, ssh_extra_args=None,
|
||||
sftp_extra_args=None, scp_extra_args=None,
|
||||
become=become, become_method='sudo', become_user='root',
|
||||
verbosity=100, check=False, diff=None)
|
||||
forks=forks)
|
||||
self.serial = serial or 10
|
||||
self.ansible = find_ansible()
|
||||
|
||||
|
@ -145,15 +128,11 @@ class AnsibleRunner(object):
|
|||
inventory = {}
|
||||
|
||||
for host, variables in host_vars.items():
|
||||
host_vars = {}
|
||||
host_vars = dict((k, v)
|
||||
for k, v in self.default_host_vars.items() if v)
|
||||
host_vars.update(dict((k, v) for k, v in variables.items() if v))
|
||||
|
||||
for var_name, value in variables.items():
|
||||
if value is not None:
|
||||
host_vars[var_name] = value
|
||||
inventory[host] = host_vars
|
||||
|
||||
inventory[host]['ansible_ssh_common_args'] = (
|
||||
self.options.ssh_common_args)
|
||||
inventory[host]['ansible_connection'] = self.options.connection
|
||||
|
||||
full_inventory = {'all': {'hosts': inventory}}
|
||||
|
@ -217,7 +196,7 @@ class AnsibleRunner(object):
|
|||
|
||||
return result
|
||||
|
||||
def execute(self, hosts, task, raise_on_statuses=DEFAULT_ERROR_STATUSES):
|
||||
def execute(self, hosts, task, raise_on_statuses=None):
|
||||
"""Executes the task on every host from the list
|
||||
|
||||
Raises exception if any of the commands fails with one of specified
|
||||
|
@ -228,10 +207,11 @@ class AnsibleRunner(object):
|
|||
any of these statuses
|
||||
:return: execution result, type AnsibleExecutionRecord
|
||||
"""
|
||||
raise_on_statuses = raise_on_statuses or DEFAULT_ERROR_STATUSES
|
||||
LOG.debug('Executing task: %s on hosts: %s with serial: %s',
|
||||
task, hosts, self.serial)
|
||||
|
||||
host_vars = {h.ip: self._build_host_vars(h) for h in hosts}
|
||||
host_vars = {h.ip: self._build_auth_host_vars(h.auth) for h in hosts}
|
||||
task_play = {'hosts': [h.ip for h in hosts],
|
||||
'tasks': [task],
|
||||
'serial': self.serial}
|
||||
|
@ -268,25 +248,24 @@ class AnsibleRunner(object):
|
|||
|
||||
return result
|
||||
|
||||
def _build_host_vars(self, host):
|
||||
if not host.auth:
|
||||
def _build_auth_host_vars(self, auth):
|
||||
if not auth:
|
||||
return {}
|
||||
|
||||
ssh_common_args = None
|
||||
if 'jump' in host.auth:
|
||||
ssh_common_args = SSH_COMMON_ARGS
|
||||
ssh_common_args = SSH_COMMON_ARGS
|
||||
if 'jump' in auth:
|
||||
ssh_common_args += self._build_proxy_arg(
|
||||
jump_host=host.auth['jump']['host'],
|
||||
jump_user=host.auth['jump'].get(
|
||||
'username', self.options.remote_user),
|
||||
private_key_file=host.auth['jump'].get(
|
||||
'private_key_file', self.options.private_key_file))
|
||||
jump_host=auth['jump']['host'],
|
||||
jump_user=auth['jump'].get(
|
||||
'username', auth.get('username')),
|
||||
private_key_file=auth['jump'].get('private_key_file'))
|
||||
|
||||
return {
|
||||
'ansible_user': host.auth.get('username'),
|
||||
'ansible_ssh_pass': host.auth.get('password'),
|
||||
'ansible_become': host.auth.get('become') or host.auth.get('sudo'),
|
||||
'ansible_become_password': host.auth.get('become_password'),
|
||||
'ansible_ssh_private_key_file': host.auth.get('private_key_file'),
|
||||
'ansible_user': auth.get('username'),
|
||||
'ansible_ssh_pass': auth.get('password'),
|
||||
'ansible_become_user': auth.get('become_username'),
|
||||
'ansible_become_pass': auth.get('become_password'),
|
||||
'ansible_become_method': auth.get('become_method'),
|
||||
'ansible_ssh_private_key_file': auth.get('private_key_file'),
|
||||
'ansible_ssh_common_args': ssh_common_args,
|
||||
}
|
||||
|
|
|
@ -49,9 +49,6 @@ class DevStackManagement(cloud_management.CloudManagement,
|
|||
username: ubuntu
|
||||
password: ubuntu_pass
|
||||
private_key_file: ~/.ssh/id_rsa_devstack
|
||||
slaves:
|
||||
- 192.168.1.11
|
||||
- 192.168.1.12
|
||||
iface: eth1
|
||||
|
||||
parameters:
|
||||
|
@ -60,14 +57,11 @@ class DevStackManagement(cloud_management.CloudManagement,
|
|||
- **username** - username for all nodes
|
||||
- **password** - password for all nodes (optional)
|
||||
- **private_key_file** - path to key file (optional)
|
||||
- **slaves** - list of ips for additional nodes (optional)
|
||||
- **iface** - network interface name to retrieve mac address (optional)
|
||||
- **serial** - how many hosts Ansible should manage at a single time.
|
||||
(optional) default: 10
|
||||
"""
|
||||
|
||||
NAME = 'devstack'
|
||||
DESCRIPTION = 'DevStack management driver using Systemd'
|
||||
DESCRIPTION = 'DevStack driver'
|
||||
NODE_CLS = DevStackNode
|
||||
SERVICES = {
|
||||
'cinder-api': {
|
||||
|
@ -91,6 +85,13 @@ class DevStackManagement(cloud_management.CloudManagement,
|
|||
'service_name': 'devstack@c-vol',
|
||||
}
|
||||
},
|
||||
'etcd': {
|
||||
'driver': 'system_service',
|
||||
'args': {
|
||||
'grep': 'etcd',
|
||||
'service_name': 'devstack@etcd',
|
||||
}
|
||||
},
|
||||
'glance-api': {
|
||||
'driver': 'system_service',
|
||||
'args': {
|
||||
|
@ -119,6 +120,13 @@ class DevStackManagement(cloud_management.CloudManagement,
|
|||
'service_name': 'devstack@keystone',
|
||||
}
|
||||
},
|
||||
'memcached': {
|
||||
'driver': 'system_service',
|
||||
'args': {
|
||||
'grep': 'memcached',
|
||||
'service_name': 'memcached',
|
||||
}
|
||||
},
|
||||
'mysql': {
|
||||
'driver': 'system_service',
|
||||
'args': {
|
||||
|
@ -205,12 +213,7 @@ class DevStackManagement(cloud_management.CloudManagement,
|
|||
'properties': {
|
||||
'address': {'type': 'string'},
|
||||
'auth': shared_schemas.AUTH_SCHEMA,
|
||||
'slaves': {
|
||||
'type': 'array',
|
||||
'items': {'type': 'string'},
|
||||
},
|
||||
'iface': {'type': 'string'},
|
||||
'serial': {'type': 'integer', 'minimum': 1},
|
||||
},
|
||||
'required': ['address', 'auth'],
|
||||
'additionalProperties': False,
|
||||
|
@ -222,19 +225,11 @@ class DevStackManagement(cloud_management.CloudManagement,
|
|||
|
||||
address = cloud_management_params['address']
|
||||
auth = cloud_management_params['auth']
|
||||
slaves = cloud_management_params.get('slaves', [])
|
||||
self.iface = cloud_management_params.get('iface', 'eth0')
|
||||
|
||||
self.cloud_executor = executor.AnsibleRunner(
|
||||
remote_user=auth['username'],
|
||||
private_key_file=auth.get('private_key_file'),
|
||||
password=auth.get('password'),
|
||||
serial=(cloud_management_params.get('serial')))
|
||||
self.cloud_executor = executor.AnsibleRunner(auth=auth)
|
||||
|
||||
self.hosts = [node_collection.Host(ip=address)]
|
||||
if slaves:
|
||||
self.hosts.extend([node_collection.Host(ip=h)
|
||||
for h in slaves])
|
||||
self.nodes = None
|
||||
|
||||
def verify(self):
|
||||
|
|
|
@ -19,6 +19,7 @@ from os_faults.ansible import executor
|
|||
from os_faults.api import cloud_management
|
||||
from os_faults.api import node_collection
|
||||
from os_faults.api import node_discover
|
||||
from os_faults.drivers import shared_schemas
|
||||
from os_faults import error
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -47,13 +48,14 @@ class TCPCloudManagement(cloud_management.CloudManagement,
|
|||
driver: tcpcloud
|
||||
args:
|
||||
address: 192.168.1.10
|
||||
username: root
|
||||
password: root_pass
|
||||
private_key_file: ~/.ssh/id_rsa_tcpcloud
|
||||
slave_username: ubuntu
|
||||
slave_password: ubuntu_pass
|
||||
master_sudo: False
|
||||
slave_sudo: True
|
||||
auth:
|
||||
username: root
|
||||
password: root_pass
|
||||
private_key_file: ~/.ssh/id_rsa_tcpcloud
|
||||
slave_auth:
|
||||
username: ubuntu
|
||||
password: ubuntu_pass
|
||||
become_username: root
|
||||
slave_name_regexp: ^(?!cfg|mon)
|
||||
slave_direct_ssh: True
|
||||
get_ips_cmd: pillar.get _param:single_address
|
||||
|
@ -308,13 +310,8 @@ class TCPCloudManagement(cloud_management.CloudManagement,
|
|||
'$schema': 'http://json-schema.org/draft-04/schema#',
|
||||
'properties': {
|
||||
'address': {'type': 'string'},
|
||||
'username': {'type': 'string'},
|
||||
'password': {'type': 'string'},
|
||||
'private_key_file': {'type': 'string'},
|
||||
'slave_username': {'type': 'string'},
|
||||
'slave_password': {'type': 'string'},
|
||||
'master_sudo': {'type': 'boolean'},
|
||||
'slave_sudo': {'type': 'boolean'},
|
||||
'auth': shared_schemas.AUTH_SCHEMA,
|
||||
'slave_auth': shared_schemas.AUTH_SCHEMA,
|
||||
'slave_name_regexp': {'type': 'string'},
|
||||
'slave_direct_ssh': {'type': 'boolean'},
|
||||
'get_ips_cmd': {'type': 'string'},
|
||||
|
@ -330,10 +327,6 @@ class TCPCloudManagement(cloud_management.CloudManagement,
|
|||
|
||||
self.master_node_address = cloud_management_params['address']
|
||||
self._master_host = node_collection.Host(ip=self.master_node_address)
|
||||
self.username = cloud_management_params['username']
|
||||
self.slave_username = cloud_management_params.get(
|
||||
'slave_username', self.username)
|
||||
self.private_key_file = cloud_management_params.get('private_key_file')
|
||||
self.slave_direct_ssh = cloud_management_params.get(
|
||||
'slave_direct_ssh', False)
|
||||
use_jump = not self.slave_direct_ssh
|
||||
|
@ -341,20 +334,21 @@ class TCPCloudManagement(cloud_management.CloudManagement,
|
|||
'get_ips_cmd', 'pillar.get _param:single_address')
|
||||
self.serial = cloud_management_params.get('serial')
|
||||
|
||||
password = cloud_management_params.get('password')
|
||||
self.master_node_executor = executor.AnsibleRunner(
|
||||
remote_user=self.username,
|
||||
password=password,
|
||||
private_key_file=self.private_key_file,
|
||||
become=cloud_management_params.get('master_sudo'))
|
||||
auth=cloud_management_params.get('auth'))
|
||||
|
||||
slave_auth = cloud_management_params.get('slave_auth') or {}
|
||||
if use_jump:
|
||||
slave_auth['jump'] = {}
|
||||
jump = slave_auth['jump']
|
||||
jump['host'] = self.master_node_address
|
||||
if not jump.get('username'):
|
||||
jump['username'] = (
|
||||
slave_auth.get('username') or
|
||||
cloud_management_params['auth']['username'])
|
||||
|
||||
self.cloud_executor = executor.AnsibleRunner(
|
||||
remote_user=self.slave_username,
|
||||
password=cloud_management_params.get('slave_password', password),
|
||||
private_key_file=self.private_key_file,
|
||||
jump_host=self.master_node_address if use_jump else None,
|
||||
jump_user=self.username if use_jump else None,
|
||||
become=cloud_management_params.get('slave_sudo'),
|
||||
auth=slave_auth,
|
||||
serial=self.serial)
|
||||
|
||||
# get all nodes except salt master (that has cfg* hostname) by default
|
||||
|
|
|
@ -28,7 +28,9 @@ AUTH_SCHEMA = {
|
|||
'username': {'type': 'string'},
|
||||
'password': {'type': 'string'},
|
||||
'private_key_file': {'type': 'string'},
|
||||
'become_username': {'type': 'string'},
|
||||
'become_password': {'type': 'string'},
|
||||
'become_method': {'type': 'string'},
|
||||
'jump': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
|
|
|
@ -37,78 +37,63 @@ class AnsibleRunnerTestCase(test.TestCase):
|
|||
@mock.patch.object(executor, 'Options')
|
||||
@ddt.data((
|
||||
{},
|
||||
dict(become=None, become_method='sudo', become_user='root',
|
||||
check=False, connection='smart', diff=None, forks=100,
|
||||
private_key_file=None,
|
||||
remote_user='root', scp_extra_args=None, sftp_extra_args=None,
|
||||
ssh_common_args=executor.SSH_COMMON_ARGS,
|
||||
ssh_extra_args=None, verbosity=100),
|
||||
dict(conn_pass=None, become_pass=None),
|
||||
{},
|
||||
), (
|
||||
dict(remote_user='root', password='foobar'),
|
||||
dict(become=None, become_method='sudo', become_user='root',
|
||||
check=False, connection='smart', diff=None, forks=100,
|
||||
private_key_file=None,
|
||||
remote_user='root', scp_extra_args=None, sftp_extra_args=None,
|
||||
ssh_common_args=executor.SSH_COMMON_ARGS,
|
||||
ssh_extra_args=None, verbosity=100),
|
||||
dict(conn_pass='foobar', become_pass=None),
|
||||
dict(username='root', password='foobar'),
|
||||
dict(ansible_user='root', ansible_ssh_pass='foobar',
|
||||
ansible_become_user=None, ansible_become_pass=None,
|
||||
ansible_become_method=None,
|
||||
ansible_ssh_private_key_file=None,
|
||||
ansible_ssh_common_args=executor.SSH_COMMON_ARGS),
|
||||
), (
|
||||
dict(remote_user='root', password='foobar', become_password='secret'),
|
||||
dict(become=None, become_method='sudo', become_user='root',
|
||||
check=False, connection='smart', diff=None, forks=100,
|
||||
private_key_file=None,
|
||||
remote_user='root', scp_extra_args=None, sftp_extra_args=None,
|
||||
ssh_common_args=executor.SSH_COMMON_ARGS,
|
||||
ssh_extra_args=None, verbosity=100),
|
||||
dict(conn_pass='foobar', become_pass='secret'),
|
||||
dict(username='dev', password='foobar', become_password='secret'),
|
||||
dict(ansible_user='dev', ansible_ssh_pass='foobar',
|
||||
ansible_become_user=None, ansible_become_pass='secret',
|
||||
ansible_become_method=None,
|
||||
ansible_ssh_private_key_file=None,
|
||||
ansible_ssh_common_args=executor.SSH_COMMON_ARGS),
|
||||
), (
|
||||
dict(remote_user='root', jump_host='jhost.com',
|
||||
dict(username='dev', jump={'host': 'jhost.com'},
|
||||
private_key_file='/path/my.key'),
|
||||
dict(become=None, become_method='sudo', become_user='root',
|
||||
check=False, connection='smart', diff=None, forks=100,
|
||||
private_key_file='/path/my.key',
|
||||
remote_user='root', scp_extra_args=None, sftp_extra_args=None,
|
||||
ssh_common_args=('-o UserKnownHostsFile=/dev/null '
|
||||
'-o StrictHostKeyChecking=no '
|
||||
'-o ConnectTimeout=60 '
|
||||
'-o ProxyCommand='
|
||||
'"ssh -i /path/my.key '
|
||||
'-W %h:%p '
|
||||
'-o UserKnownHostsFile=/dev/null '
|
||||
'-o StrictHostKeyChecking=no '
|
||||
'-o ConnectTimeout=60 '
|
||||
'root@jhost.com"'),
|
||||
ssh_extra_args=None, verbosity=100),
|
||||
dict(conn_pass=None, become_pass=None),
|
||||
dict(ansible_user='dev', ansible_ssh_pass=None,
|
||||
ansible_become_user=None, ansible_become_pass=None,
|
||||
ansible_become_method=None,
|
||||
ansible_ssh_private_key_file='/path/my.key',
|
||||
ansible_ssh_common_args=('-o UserKnownHostsFile=/dev/null '
|
||||
'-o StrictHostKeyChecking=no '
|
||||
'-o ConnectTimeout=60 '
|
||||
'-o ProxyCommand='
|
||||
'"ssh '
|
||||
'-W %h:%p '
|
||||
'-o UserKnownHostsFile=/dev/null '
|
||||
'-o StrictHostKeyChecking=no '
|
||||
'-o ConnectTimeout=60 '
|
||||
'dev@jhost.com"')),
|
||||
), (
|
||||
dict(remote_user='root', jump_host='jhost.com', jump_user='juser',
|
||||
private_key_file='/path/my.key'),
|
||||
dict(become=None, become_method='sudo', become_user='root',
|
||||
check=False, connection='smart', diff=None, forks=100,
|
||||
private_key_file='/path/my.key',
|
||||
remote_user='root', scp_extra_args=None, sftp_extra_args=None,
|
||||
ssh_common_args=('-o UserKnownHostsFile=/dev/null '
|
||||
'-o StrictHostKeyChecking=no '
|
||||
'-o ConnectTimeout=60 '
|
||||
'-o ProxyCommand='
|
||||
'"ssh -i /path/my.key '
|
||||
'-W %h:%p '
|
||||
'-o UserKnownHostsFile=/dev/null '
|
||||
'-o StrictHostKeyChecking=no '
|
||||
'-o ConnectTimeout=60 '
|
||||
'juser@jhost.com"'),
|
||||
ssh_extra_args=None, verbosity=100),
|
||||
dict(conn_pass=None, become_pass=None),
|
||||
dict(username='dev', jump={'host': 'jhost.com', 'username': 'juser',
|
||||
'private_key_file': '/path/my.key'}),
|
||||
dict(ansible_user='dev', ansible_ssh_pass=None,
|
||||
ansible_become_user=None, ansible_become_pass=None,
|
||||
ansible_become_method=None,
|
||||
ansible_ssh_private_key_file=None,
|
||||
ansible_ssh_common_args=('-o UserKnownHostsFile=/dev/null '
|
||||
'-o StrictHostKeyChecking=no '
|
||||
'-o ConnectTimeout=60 '
|
||||
'-o ProxyCommand='
|
||||
'"ssh -i /path/my.key '
|
||||
'-W %h:%p '
|
||||
'-o UserKnownHostsFile=/dev/null '
|
||||
'-o StrictHostKeyChecking=no '
|
||||
'-o ConnectTimeout=60 '
|
||||
'juser@jhost.com"')),
|
||||
))
|
||||
@ddt.unpack
|
||||
def test___init__options(self, config, options_args, passwords,
|
||||
mock_options):
|
||||
runner = executor.AnsibleRunner(**config)
|
||||
def test___init__options(self, auth, default_host_vars, mock_options):
|
||||
runner = executor.AnsibleRunner(auth=auth)
|
||||
module_path = executor.make_module_path_option()
|
||||
mock_options.assert_called_once_with(module_path=module_path,
|
||||
**options_args)
|
||||
self.assertEqual(passwords, runner.passwords)
|
||||
mock_options.assert_called_once_with(
|
||||
module_path=module_path, connection='smart', forks=100)
|
||||
self.assertEqual(default_host_vars, runner.default_host_vars)
|
||||
|
||||
@mock.patch('os_faults.ansible.executor.AnsibleRunner._run_play')
|
||||
def test_run_playbook(self, mock_run_play):
|
||||
|
@ -137,7 +122,7 @@ class AnsibleRunnerTestCase(test.TestCase):
|
|||
my_hosts = [
|
||||
node_collection.Host('0.0.0.0', auth={'username': 'foo',
|
||||
'password': 'bar',
|
||||
'sudo': True}),
|
||||
'become_username': 'root'}),
|
||||
node_collection.Host('255.255.255.255',
|
||||
auth={'jump': {'host': '192.168.1.100',
|
||||
'username': 'foo'}})]
|
||||
|
@ -152,16 +137,18 @@ class AnsibleRunnerTestCase(test.TestCase):
|
|||
'0.0.0.0': {
|
||||
'ansible_user': 'foo',
|
||||
'ansible_ssh_pass': 'bar',
|
||||
'ansible_become': True,
|
||||
'ansible_become_password': None,
|
||||
'ansible_become_method': None,
|
||||
'ansible_become_user': 'root',
|
||||
'ansible_become_pass': None,
|
||||
'ansible_ssh_private_key_file': None,
|
||||
'ansible_ssh_common_args': None,
|
||||
'ansible_ssh_common_args': executor.SSH_COMMON_ARGS,
|
||||
},
|
||||
'255.255.255.255': {
|
||||
'ansible_user': None,
|
||||
'ansible_ssh_pass': None,
|
||||
'ansible_become': None,
|
||||
'ansible_become_password': None,
|
||||
'ansible_become_method': None,
|
||||
'ansible_become_user': None,
|
||||
'ansible_become_pass': None,
|
||||
'ansible_ssh_private_key_file': None,
|
||||
'ansible_ssh_common_args':
|
||||
'-o UserKnownHostsFile=/dev/null '
|
||||
|
|
|
@ -69,37 +69,6 @@ class DevStackManagementTestCase(test.TestCase):
|
|||
{'command': 'cat /sys/class/net/eth0/address'}),
|
||||
])
|
||||
|
||||
@mock.patch('os_faults.ansible.executor.AnsibleRunner', autospec=True)
|
||||
def test_verify_slaves(self, mock_ansible_runner):
|
||||
self.conf['slaves'] = ['10.0.0.3', '10.0.0.4']
|
||||
ansible_runner_inst = mock_ansible_runner.return_value
|
||||
ansible_runner_inst.execute.side_effect = [
|
||||
[fakes.FakeAnsibleResult(payload={'stdout': 'mac1'},
|
||||
host='10.0.0.2'),
|
||||
fakes.FakeAnsibleResult(payload={'stdout': 'mac2'},
|
||||
host='10.0.0.3'),
|
||||
fakes.FakeAnsibleResult(payload={'stdout': 'mac3'},
|
||||
host='10.0.0.4')],
|
||||
[fakes.FakeAnsibleResult(payload={'stdout': ''},
|
||||
host='10.0.0.2'),
|
||||
fakes.FakeAnsibleResult(payload={'stdout': ''},
|
||||
host='10.0.0.3'),
|
||||
fakes.FakeAnsibleResult(payload={'stdout': ''},
|
||||
host='10.0.0.4')],
|
||||
]
|
||||
devstack_management = devstack.DevStackManagement(self.conf)
|
||||
devstack_management.verify()
|
||||
|
||||
hosts = [
|
||||
node_collection.Host('10.0.0.2'),
|
||||
node_collection.Host('10.0.0.3'),
|
||||
node_collection.Host('10.0.0.4')
|
||||
]
|
||||
|
||||
ansible_runner_inst.execute.assert_has_calls([
|
||||
mock.call(hosts, {'command': 'cat /sys/class/net/eth0/address'}),
|
||||
])
|
||||
|
||||
@mock.patch('os_faults.ansible.executor.AnsibleRunner', autospec=True)
|
||||
def test_execute_on_cloud(self, mock_ansible_runner):
|
||||
ansible_runner_inst = mock_ansible_runner.return_value
|
||||
|
@ -134,40 +103,6 @@ class DevStackManagementTestCase(test.TestCase):
|
|||
fqdn='')],
|
||||
nodes.hosts)
|
||||
|
||||
@mock.patch('os_faults.ansible.executor.AnsibleRunner', autospec=True)
|
||||
def test_get_nodes_with_slaves(self, mock_ansible_runner):
|
||||
self.conf['slaves'] = ['10.0.0.3', '10.0.0.4']
|
||||
self.conf['iface'] = 'eth1'
|
||||
ansible_runner_inst = mock_ansible_runner.return_value
|
||||
ansible_runner_inst.execute.side_effect = [
|
||||
[fakes.FakeAnsibleResult(payload={'stdout': '09:7b:74:90:63:c1'},
|
||||
host='10.0.0.2'),
|
||||
fakes.FakeAnsibleResult(payload={'stdout': '09:7b:74:90:63:c2'},
|
||||
host='10.0.0.3'),
|
||||
fakes.FakeAnsibleResult(payload={'stdout': '09:7b:74:90:63:c3'},
|
||||
host='10.0.0.4')],
|
||||
]
|
||||
hosts = [
|
||||
node_collection.Host('10.0.0.2'),
|
||||
node_collection.Host('10.0.0.3'),
|
||||
node_collection.Host('10.0.0.4')
|
||||
]
|
||||
devstack_management = devstack.DevStackManagement(self.conf)
|
||||
nodes = devstack_management.get_nodes()
|
||||
|
||||
ansible_runner_inst.execute.assert_called_once_with(
|
||||
hosts, {'command': 'cat /sys/class/net/eth1/address'})
|
||||
|
||||
self.assertIsInstance(nodes, devstack.DevStackNode)
|
||||
self.assertEqual(
|
||||
[node_collection.Host(ip='10.0.0.2', mac='09:7b:74:90:63:c1',
|
||||
fqdn=''),
|
||||
node_collection.Host(ip='10.0.0.3', mac='09:7b:74:90:63:c2',
|
||||
fqdn=''),
|
||||
node_collection.Host(ip='10.0.0.4', mac='09:7b:74:90:63:c3',
|
||||
fqdn='')],
|
||||
nodes.hosts)
|
||||
|
||||
@mock.patch('os_faults.ansible.executor.AnsibleRunner', autospec=True)
|
||||
@ddt.data(*devstack.DevStackManagement.SERVICES.keys())
|
||||
def test_get_service_nodes(self, service_name, mock_ansible_runner):
|
||||
|
|
|
@ -57,7 +57,9 @@ class TCPCloudManagementTestCase(test.TestCase):
|
|||
|
||||
self.tcp_conf = {
|
||||
'address': 'tcp.local',
|
||||
'username': 'root',
|
||||
'auth': {
|
||||
'username': 'root',
|
||||
}
|
||||
}
|
||||
self.get_nodes_cmd = (
|
||||
"salt -E '^(?!cfg|mon)' network.interfaces --out=yaml")
|
||||
|
@ -74,55 +76,23 @@ class TCPCloudManagementTestCase(test.TestCase):
|
|||
|
||||
@mock.patch('os_faults.ansible.executor.AnsibleRunner', autospec=True)
|
||||
@ddt.data((
|
||||
dict(address='tcp.local', username='root'),
|
||||
(mock.call(become=None, private_key_file=None, remote_user='root',
|
||||
password=None),
|
||||
mock.call(become=None, jump_host='tcp.local', jump_user='root',
|
||||
private_key_file=None, remote_user='root',
|
||||
password=None, serial=None))
|
||||
dict(address='tcp.local', auth=dict(username='root')),
|
||||
(mock.call(auth=dict(username='root')),
|
||||
mock.call(auth=dict(jump=dict(username='root', host='tcp.local')),
|
||||
serial=None))
|
||||
), (
|
||||
dict(address='tcp.local', username='ubuntu',
|
||||
slave_username='root', master_sudo=True,
|
||||
private_key_file='/path/id_rsa'),
|
||||
(mock.call(become=True, private_key_file='/path/id_rsa',
|
||||
remote_user='ubuntu', password=None),
|
||||
mock.call(become=None, jump_host='tcp.local', jump_user='ubuntu',
|
||||
private_key_file='/path/id_rsa', remote_user='root',
|
||||
password=None, serial=None))
|
||||
), (
|
||||
dict(address='tcp.local', username='ubuntu',
|
||||
slave_username='root', slave_sudo=True,
|
||||
private_key_file='/path/id_rsa'),
|
||||
(mock.call(become=None, private_key_file='/path/id_rsa',
|
||||
remote_user='ubuntu', password=None),
|
||||
mock.call(become=True, jump_host='tcp.local', jump_user='ubuntu',
|
||||
private_key_file='/path/id_rsa', remote_user='root',
|
||||
password=None, serial=None))
|
||||
), (
|
||||
dict(address='tcp.local', username='ubuntu',
|
||||
slave_username='root', slave_sudo=True,
|
||||
private_key_file='/path/id_rsa',
|
||||
slave_direct_ssh=True),
|
||||
(mock.call(become=None, private_key_file='/path/id_rsa',
|
||||
remote_user='ubuntu', password=None),
|
||||
mock.call(become=True, jump_host=None, jump_user=None,
|
||||
private_key_file='/path/id_rsa', remote_user='root',
|
||||
password=None, serial=None))
|
||||
), (
|
||||
dict(address='tcp.local', username='root', password='root_pass'),
|
||||
(mock.call(become=None, private_key_file=None, remote_user='root',
|
||||
password='root_pass'),
|
||||
mock.call(become=None, jump_host='tcp.local', jump_user='root',
|
||||
private_key_file=None, remote_user='root',
|
||||
password='root_pass', serial=None))
|
||||
), (
|
||||
dict(address='tcp.local', username='root',
|
||||
slave_password='slave_pass', serial=42),
|
||||
(mock.call(become=None, private_key_file=None, remote_user='root',
|
||||
password=None),
|
||||
mock.call(become=None, jump_host='tcp.local', jump_user='root',
|
||||
private_key_file=None, remote_user='root',
|
||||
password='slave_pass', serial=42))
|
||||
dict(address='tcp.local',
|
||||
auth=dict(username='ubuntu',
|
||||
private_key_file='/path/id_rsa'),
|
||||
slave_auth=dict(username='root',
|
||||
private_key_file='/path/id_rsa'),
|
||||
master_sudo=True),
|
||||
(mock.call(auth=dict(username='ubuntu',
|
||||
private_key_file='/path/id_rsa')),
|
||||
mock.call(auth=dict(username='root',
|
||||
private_key_file='/path/id_rsa',
|
||||
jump=dict(username='root', host='tcp.local')),
|
||||
serial=None))
|
||||
))
|
||||
@ddt.unpack
|
||||
def test_init(self, config, expected_runner_calls, mock_ansible_runner):
|
||||
|
@ -288,7 +258,7 @@ class TCPCloudServiceTestCase(test.TestCase):
|
|||
|
||||
self.tcp_conf = {
|
||||
'address': 'tcp.local',
|
||||
'username': 'root',
|
||||
'auth': {'username': 'root'},
|
||||
}
|
||||
self.get_nodes_cmd = (
|
||||
"salt -E '^(?!cfg|mon)' network.interfaces --out=yaml")
|
||||
|
|
Loading…
Reference in New Issue