Skip to content

Commit b228382

Browse files
authored
Merge pull request QualiSystems#80 from QualiSystems/asaf_general
Merge help-branch to master for release 1.2.0 (8.1EA)
2 parents b5aeeb2 + dae3e42 commit b228382

5 files changed

Lines changed: 28 additions & 11 deletions

File tree

package/cloudshell/cm/ansible/ansible_shell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ def _wait_for_all_hosts_to_be_deployed(self, ansi_conf, logger, output_writer):
162162
host.parameters[HostVarsFile.ANSIBLE_PORT] is not None):
163163
ansible_port = host.parameters[HostVarsFile.ANSIBLE_PORT]
164164

165-
port_ansible_port = "Ansible Timeout:" + str(ansi_conf.timeout_minutes) + " Ansible port : " + ansible_port
165+
port_ansible_port = "Ansible Timeout: " + str(ansi_conf.timeout_minutes) + " Ansible port: " + ansible_port
166166

167167
logger.info(port_ansible_port)
168-
output_writer.write("Waiting for host :" + host.ip)
168+
output_writer.write("Waiting for host: " + host.ip)
169169
output_writer.write(port_ansible_port)
170170

171171
self.connection_service.check_connection(logger, host, ansible_port=ansible_port,

package/cloudshell/cm/ansible/domain/host_vars_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __exit__(self, type, value, traceback):
3333
with self.file_system.create_file(self.file_path) as file_stream:
3434
lines = ['---']
3535
for key, value in sorted(self.vars.iteritems()):
36-
lines.append(str(key) + ': ' + str(value))
36+
lines.append(str(key) + ': "' + str(value) + '"')
3737
file_stream.write(os.linesep.join(lines))
3838
self.logger.debug(os.linesep.join(lines))
3939
self.logger.info('Done.')

package/cloudshell/cm/ansible/domain/output/ansible_result.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def _load(self):
2929
host_results = []
3030
recap_table = self._get_final_table()
3131
error_by_host = self._get_failing_hosts_errors()
32+
general_error = self._get_parsed_error()
3233
for ip in self.ips:
3334
# Success
3435
if recap_table.get(ip) == True:
@@ -41,7 +42,7 @@ def _load(self):
4142
host_results.append(HostResult(ip, False, self.error))
4243
# Didn't run at all (no information for this ip)
4344
else:
44-
host_results.append(HostResult(ip, False, self.DID_NOT_RUN_ERROR+os.linesep+self.error))
45+
host_results.append(HostResult(ip, False, self.DID_NOT_RUN_ERROR+os.linesep+general_error))
4546
return host_results
4647

4748
def _get_final_table(self):
@@ -63,6 +64,15 @@ def _scan_for_groups(self, pattern):
6364
matches = [m.groupdict() for m in matches]
6465
return matches
6566

67+
def _get_parsed_error(self):
68+
pattern = '^('+self.START+')(\[ERROR\]\:|ERROR\!)\s*(?P<txt>.*)\s*('+self.END+')\s*'
69+
minimized_error = self.error.replace(os.linesep + os.linesep, os.linesep)
70+
matches = list(re.finditer(pattern, minimized_error, re.MULTILINE|re.DOTALL))
71+
if(matches):
72+
return '\n'.join([m.groupdict()['txt'] for m in matches])
73+
else:
74+
return self.error
75+
6676

6777
class HostResult(object):
6878
def __init__(self, ip, success, error = None):

package/tests/test_ansible_result.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ class TestAnsibleResult(TestCase):
1212
def setUp(self):
1313
self.file_system = FileSystemServiceMock()
1414

15+
def test_result_should_fail_on_general_ansible_error(self):
16+
resultTxt = """
17+
\033[0;31mERROR! 'tasks_SFSDFEG' is not a valid attribute for a Play"""+os.linesep+"""The error appears to have\033[0m"""
18+
result = AnsibleResult('', resultTxt, ['192.168.85.11'])
19+
self.assertFalse(result.success)
20+
self.assertEquals('Did not run / no information for this host.'+os.linesep+'\'tasks_SFSDFEG\' is not a valid attribute for a Play'+os.linesep+'The error appears to have',
21+
get_error_for(result, '192.168.85.11'))
22+
1523
def test_result_should_fail_on_unreachable(self):
1624
resultTxt = """
1725
PLAY [linux_servers] ***********************************************************
@@ -94,7 +102,6 @@ def test_result_should_contain_error_for_unrun_hosts(self):
94102
self.assertIn(AnsibleResult.DID_NOT_RUN_ERROR,
95103
get_error_for(result, '192.168.85.11'))
96104

97-
98105
def test_result_to_json(self):
99106
result = AnsibleResult('', 'error', ['192.168.85.11','192.168.85.12'])
100107
json_str = result.to_json()

package/tests/test_host_vars_file.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,36 @@ def test_first_call_creates_the_folder(self):
1818
def test_can_add_connection_type(self):
1919
with HostVarsFile(self.file_system, 'host1', Mock()) as f:
2020
f.add_connection_type('winrm')
21-
self.assertEquals(os.linesep.join(['---', 'ansible_connection: winrm']),
21+
self.assertEquals(os.linesep.join(['---', 'ansible_connection: "winrm"']),
2222
self.file_system.read_all_lines('host_vars', 'host1'))
2323

2424
def test_can_add_connection_type(self):
2525
with HostVarsFile(self.file_system, 'host1', Mock()) as f:
2626
f.add_username('admin')
27-
self.assertEquals(os.linesep.join(['---', 'ansible_user: admin']),
27+
self.assertEquals(os.linesep.join(['---', 'ansible_user: "admin"']),
2828
self.file_system.read_all_lines('host_vars', 'host1'))
2929

3030
def test_can_add_connection_type(self):
3131
with HostVarsFile(self.file_system, 'host1', Mock()) as f:
3232
f.add_password('1234')
33-
self.assertEquals(os.linesep.join(['---', 'ansible_ssh_pass: 1234']),
33+
self.assertEquals(os.linesep.join(['---', 'ansible_ssh_pass: "1234"']),
3434
self.file_system.read_all_lines('host_vars', 'host1'))
3535

3636
def test_can_add_connection_key_file(self):
3737
with HostVarsFile(self.file_system, 'host1', Mock()) as f:
3838
f.add_conn_file('mycert.pem')
39-
self.assertEquals(os.linesep.join(['---', 'ansible_ssh_private_key_file: mycert.pem']),
39+
self.assertEquals(os.linesep.join(['---', 'ansible_ssh_private_key_file: "mycert.pem"']),
4040
self.file_system.read_all_lines('host_vars', 'host1'))
4141

4242
def test_can_add_port(self):
4343
with HostVarsFile(self.file_system, 'host1', Mock()) as f:
4444
f.add_port('1234')
45-
self.assertEquals(os.linesep.join(['---', 'ansible_port: 1234']),
45+
self.assertEquals(os.linesep.join(['---', 'ansible_port: "1234"']),
4646
self.file_system.read_all_lines('host_vars', 'host1'))
4747

4848
def test_can_add_custom_vars(self):
4949
with HostVarsFile(self.file_system, 'host1', Mock()) as f:
5050
f.add_vars({'param1': 'abc', 'param2': '123'})
5151
f.add_vars({'param3': 'W'})
52-
self.assertEquals(os.linesep.join(['---', 'param1: abc', 'param2: 123', 'param3: W']),
52+
self.assertEquals(os.linesep.join(['---', 'param1: "abc"', 'param2: "123"', 'param3: "W"']),
5353
self.file_system.read_all_lines('host_vars', 'host1'))

0 commit comments

Comments
 (0)