New configuration parameters for TCPCloud driver

* Allow to configure domain names and network interface
  names for slaves on TcpCloud driver.
* Fixed test_utils.py

Change-Id: I12482e0d382c3c10427e26585277ffb454a0d9f7
This commit is contained in:
Anton Studenov 2016-12-12 15:25:45 +03:00
parent 59b2489674
commit c7004ea52c
3 changed files with 19 additions and 8 deletions

View File

@ -217,6 +217,8 @@ class TCPCloudManagement(cloud_management.CloudManagement):
'slave_username': {'type': 'string'},
'master_sudo': {'type': 'boolean'},
'slave_sudo': {'type': 'boolean'},
'slave_iface': {'type': 'string'},
'slave_name_regexp': {'type': 'string'},
},
'required': ['address', 'username'],
'additionalProperties': False,
@ -243,6 +245,12 @@ class TCPCloudManagement(cloud_management.CloudManagement):
jump_user=self.username,
become=cloud_management_params.get('slave_sudo'))
self.slave_iface = cloud_management_params.get('slave_iface', 'eth0')
# get all nodes except salt master (that has cfg* hostname) by default
self.slave_name_regexp = cloud_management_params.get(
'slave_name_regexp', '^(?!cfg)')
self.cached_cloud_hosts = list()
self.fqdn_to_hosts = dict()
@ -261,14 +269,14 @@ class TCPCloudManagement(cloud_management.CloudManagement):
def _get_cloud_hosts(self):
if not self.cached_cloud_hosts:
# get all nodes except salt master (that has cfg* hostname)
cmd = "salt -E '^(?!cfg)' network.interfaces --out=yaml"
cmd = "salt -E '{}' network.interfaces --out=yaml".format(
self.slave_name_regexp)
result = self.execute_on_master_node({'command': cmd})
stdout = result[0].payload['stdout']
for fqdn, net_data in yaml.load(stdout).items():
host = node_collection.Host(
ip=net_data['eth0']['inet'][0]['address'],
mac=net_data['eth0']['hwaddr'],
ip=net_data[self.slave_iface]['inet'][0]['address'],
mac=net_data[self.slave_iface]['hwaddr'],
fqdn=fqdn)
self.cached_cloud_hosts.append(host)
self.fqdn_to_hosts[host.fqdn] = host

View File

@ -29,12 +29,12 @@ class TCPCloudManagementTestCase(test.TestCase):
self.fake_ansible_result = fakes.FakeAnsibleResult(
payload={
'stdout': 'cmp01.mk20.local:\n'
' eth0:\n'
' eth1:\n'
' hwaddr: 09:7b:74:90:63:c2\n'
' inet:\n'
' - address: 10.0.0.2\n'
'cmp02.mk20.local:\n'
' eth0:\n'
' eth1:\n'
' hwaddr: 09:7b:74:90:63:c3\n'
' inet:\n'
' - address: 10.0.0.3\n'
@ -42,6 +42,7 @@ class TCPCloudManagementTestCase(test.TestCase):
self.tcp_conf = {
'address': 'tcp.local',
'username': 'root',
'slave_iface': 'eth1',
}
self.get_nodes_cmd = (
"salt -E '^(?!cfg)' network.interfaces --out=yaml")
@ -87,11 +88,13 @@ class TCPCloudManagementTestCase(test.TestCase):
[fakes.FakeAnsibleResult(payload={'stdout': ''}),
fakes.FakeAnsibleResult(payload={'stdout': ''})],
]
self.tcp_conf['slave_name_regexp'] = '(ctl*|cmp*)'
tcp_managment = tcpcloud.TCPCloudManagement(self.tcp_conf)
tcp_managment.verify()
get_nodes_cmd = "salt -E '(ctl*|cmp*)' network.interfaces --out=yaml"
ansible_runner_inst.execute.assert_has_calls([
mock.call(['tcp.local'], {'command': self.get_nodes_cmd}),
mock.call(['tcp.local'], {'command': get_nodes_cmd}),
mock.call(['10.0.0.2', '10.0.0.3'], {'command': 'hostname'}),
])

View File

@ -29,7 +29,7 @@ class UtilsTestCase(test.TestCase):
target = mock.Mock()
utils.run(target, [{'mac_address': '01'}, {'mac_address': '02'}])
target.assert_has_calls([mock.call(mac_address='01'),
mock.call(mac_address='02')])
mock.call(mac_address='02')], any_order=True)
def test_run_raise_exception(self):
target = mock.Mock()