Skip to content

Commit

Permalink
add module testwq
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcmarrow committed Jan 6, 2020
1 parent 70036f4 commit 234af0d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 6 additions & 2 deletions salt/modules/jboss7_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ def run_operation(jboss_config, operation, fail_on_error=True, retries=1):
if match is None:
match = re.search(r'^(WFLYCTL\d+):', cli_result['failure-description'])

cli_result['err_code'] = match.group(1)
if match is not None:
cli_result['err_code'] = match.group(1)
else:
# Could not find err_code
log.error("Jboss 7 operation failed! Error Code could not be found!")
cli_result['err_code'] = '-1'

cli_result['stdout'] = cli_command_result['stdout']
else:
Expand Down Expand Up @@ -164,7 +169,6 @@ def _call_cli(jboss_config, command, retries=1):
if cli_command_result['retcode'] == 1 and 'Unable to authenticate against controller' in cli_command_result['stderr']:
raise CommandExecutionError('Could not authenticate against controller, please check username and password for the management console. Err code: {retcode}, stdout: {stdout}, stderr: {stderr}'.format(**cli_command_result))

# It may happen that eventhough server is up it may not respond to the call
# TODO add WFLYCTL code
if cli_command_result['retcode'] == 1 and 'JBAS012144' in cli_command_result['stderr'] and retries > 0: # Cannot connect to cli
log.debug('Command failed, retrying... (%d tries left)', retries)
Expand Down
15 changes: 13 additions & 2 deletions tests/unit/modules/test_jboss7_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,5 +440,16 @@ def test_escaping_operation_with_backslashes_and_quotes(self):

self.assertEqual(self.cmd.get_last_command(), r'/opt/jboss/jboss-eap-6.0.1/bin/jboss-cli.sh --connect --controller="123.234.345.456:9999" --user="jbossadm" --password="jbossadm" --command="/subsystem=naming/binding=\"java:/sampleapp/web-module/ldap/username\":add(binding-type=simple, value=\"DOMAIN\\\\\\\\user\")"')

def test_run_operation_WFLYCTL_support(self):
x = jboss7_cli._call_cli
def test_run_operation_wflyctl_error(self):
call_cli_ret = {'retcode': 1,
'stdout': '{"failure-description" => "WFLYCTL0234523: ops"}'}
with patch('salt.modules.jboss7_cli._call_cli', return_value=call_cli_ret) as _call_cli:
ret = jboss7_cli.run_operation(None, "ls", False)
self.assertEqual(ret['err_code'], "WFLYCTL0234523")

def test_run_operation_no_code_error(self):
call_cli_ret = {'retcode': 1,
'stdout': '{"failure-description" => "ERROR234523: ops"}'}
with patch('salt.modules.jboss7_cli._call_cli', return_value=call_cli_ret) as _call_cli:
ret = jboss7_cli.run_operation(None, "ls", False)
self.assertEqual(ret['err_code'], "-1")

0 comments on commit 234af0d

Please sign in to comment.