def test_controller_authentication(self): jboss7_cli.run_operation(self.jboss_config, 'some cli operation') self.assertEqual( self.cmd.get_last_command(), '/opt/jboss/jboss-eap-6.0.1/bin/jboss-cli.sh --connect --controller="123.234.345.456:9999" --user="******" --password="******" --command="some cli operation"' )
def test_controller_without_authentication(self): jboss_config = { 'cli_path': '/opt/jboss/jboss-eap-6.0.1/bin/jboss-cli.sh', 'controller': '123.234.345.456:9999' } jboss7_cli.run_operation(jboss_config, 'some cli operation') self.assertEqual(self.cmd.get_last_command(), '/opt/jboss/jboss-eap-6.0.1/bin/jboss-cli.sh --connect --controller="123.234.345.456:9999" --command="some cli operation"')
def test_operation_execution(self): operation = r'sample_operation' jboss7_cli.run_operation(self.jboss_config, operation) 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="******" --password="******" --command="sample_operation"' )
def test_escaping_operation_with_backslashes_and_quotes(self): operation = r'/subsystem=naming/binding="java:/sampleapp/web-module/ldap/username":add(binding-type=simple, value="DOMAIN\\\\user")' jboss7_cli.run_operation(self.jboss_config, operation) 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="******" --password="******" --command="/subsystem=naming/binding=\"java:/sampleapp/web-module/ldap/username\":add(binding-type=simple, value=\"DOMAIN\\\\\\\\user\")"' )
def test_controller_without_authentication(self): jboss_config = { "cli_path": "/opt/jboss/jboss-eap-6.0.1/bin/jboss-cli.sh", "controller": "123.234.345.456:9999", } jboss7_cli.run_operation(jboss_config, "some cli operation") self.assertEqual( self.cmd.get_last_command(), '/opt/jboss/jboss-eap-6.0.1/bin/jboss-cli.sh --connect --controller="123.234.345.456:9999" --command="some cli operation"', )
def test_handling_cmd_not_exists(self): def command_response(command): return {'retcode': 127, 'stdout': '''Command not exists''', 'stderr': 'some err'} self.cmd.command_response_func = command_response try: jboss7_cli.run_operation(self.jboss_config, 'some cli command') # should throw an exception assert False except CommandExecutionError as err: self.assertTrue(six.text_type(err).startswith('Could not execute jboss-cli.sh script'))
def test_handling_cmd_not_exists(self): def command_response(command): return {'retcode': 127, 'stdout': '''Command not exists''', 'stderr': 'some err'} self.cmd.command_response_func = command_response try: jboss7_cli.run_operation(self.jboss_config, 'some cli command') # should throw an exception assert False except CommandExecutionError as e: self.assertTrue(str(e).startswith('Could not execute jboss-cli.sh script'))
def test_handling_cmd_not_exists(self): def command_response(command): return { "retcode": 127, "stdout": """Command not exists""", "stderr": "some err", } self.cmd.command_response_func = command_response try: jboss7_cli.run_operation(self.jboss_config, "some cli command") # should throw an exception assert False except CommandExecutionError as err: self.assertTrue( str(err).startswith("Could not execute jboss-cli.sh script"))
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")
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")
def test_handling_jboss_error(self): def command_response(command): return {'retcode': 1, 'stdout': r'''{ "outcome" => "failed", "failure-description" => "JBAS014807: Management resource '[ (\"subsystem\" => \"datasources\"), (\"data-source\" => \"non-existing\") ]' not found", "rolled-back" => true, "response-headers" => {"process-state" => "reload-required"} } ''', 'stderr': 'some err'} self.cmd.command_response_func = command_response result = jboss7_cli.run_operation(self.jboss_config, 'some cli command') self.assertFalse(result['success']) self.assertEqual(result['err_code'], 'JBAS014807')
def test_handling_jboss_error(self): def command_response(command): return { "retcode": 1, "stdout": r"""{ "outcome" => "failed", "failure-description" => "JBAS014807: Management resource '[ (\"subsystem\" => \"datasources\"), (\"data-source\" => \"non-existing\") ]' not found", "rolled-back" => true, "response-headers" => {"process-state" => "reload-required"} } """, "stderr": "some err", } self.cmd.command_response_func = command_response result = jboss7_cli.run_operation(self.jboss_config, "some cli command") self.assertFalse(result["success"]) self.assertEqual(result["err_code"], "JBAS014807")
def test_escaping_operation_with_backslashes_and_quotes(self): operation = r'/subsystem=naming/binding="java:/sampleapp/web-module/ldap/username":add(binding-type=simple, value="DOMAIN\\\\user")' jboss7_cli.run_operation(self.jboss_config, operation) 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="******" --password="******" --command="/subsystem=naming/binding=\"java:/sampleapp/web-module/ldap/username\":add(binding-type=simple, value=\"DOMAIN\\\\\\\\user\")"')
def test_controller_authentication(self): jboss7_cli.run_operation(self.jboss_config, 'some cli operation') self.assertEqual(self.cmd.get_last_command(), '/opt/jboss/jboss-eap-6.0.1/bin/jboss-cli.sh --connect --controller="123.234.345.456:9999" --user="******" --password="******" --command="some cli operation"')
def test_operation_execution(self): operation = r'sample_operation' jboss7_cli.run_operation(self.jboss_config, operation) 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="******" --password="******" --command="sample_operation"')