Fixes of pylint violations

This commit is contained in:
starzyk1 2014-11-25 12:49:14 +01:00
parent 0759323c99
commit 4bdede0700
5 changed files with 38 additions and 49 deletions

View File

@ -200,6 +200,7 @@ def _get_artifact_metadata(artifactory_url, repository, group_id, artifact_id):
'latest_version': latest_version
}
# functions for handling snapshots
def _get_snapshot_version_metadata_url(artifactory_url, repository, group_id, artifact_id, version):
group_url = __get_group_id_subpath(group_id)
@ -213,6 +214,7 @@ def _get_snapshot_version_metadata_url(artifactory_url, repository, group_id, ar
log.debug('snapshot_version_metadata_url=%s', snapshot_version_metadata_url)
return snapshot_version_metadata_url
def _get_snapshot_version_metadata_xml(artifactory_url, repository, group_id, artifact_id, version):
snapshot_version_metadata_url = _get_snapshot_version_metadata_url(artifactory_url=artifactory_url, repository=repository, group_id=group_id, artifact_id=artifact_id, version=version)
try:
@ -243,14 +245,12 @@ def _get_snapshot_version_metadata(artifactory_url, repository, group_id, artifa
}
def __save_artifact(artifact_url, target_file):
log.debug("__save_artifact(%s, %s)", artifact_url, target_file)
result = {
'status': False,
'changes': {},
'comment':''
'comment': ''
}
if os.path.isfile(target_file):

View File

@ -166,7 +166,7 @@ def datasource_exists(name, jboss_config, datasource_properties, recreate=False)
read_result = __salt__['jboss7.read_datasource'](jboss_config=jboss_config, name=name)
ds_new_properties = read_result['result']
else:
if ds_result['err_code'] == 'JBAS014807': #ok, resource not exists:
if ds_result['err_code'] == 'JBAS014807': # ok, resource not exists:
create_result = __salt__['jboss7.create_datasource'](jboss_config=jboss_config, name=name, datasource_properties=datasource_properties)
if create_result['success']:
read_result = __salt__['jboss7.read_datasource'](jboss_config=jboss_config, name=name)

View File

@ -14,6 +14,7 @@ except NameError:
# if executed separately we need to export __salt__ dictionary ourselves
__builtin__.__salt__ = {}
class CmdMock(object):
commands = []
command_response_func = None # if you want to test complete response object (with retcode, stdout and stderr)
@ -21,14 +22,14 @@ class CmdMock(object):
default_response = {'retcode': 0, 'stdout': ''' {
"outcome" => "success"
}''', 'stderr':''}
}''', 'stderr': ''}
def __init__(self, command_response_func=None):
self.command_response_func = command_response_func
def run_all(self, command):
self.commands.append(command)
if not self.command_response_func is None:
if self.command_response_func is not None:
return self.command_response_func(command)
cli_command = self.__get_cli_command(command)
@ -38,7 +39,7 @@ class CmdMock(object):
@staticmethod
def __get_cli_command(command):
command_re = re.compile(r'--command=\"\s*(.+?)\s*\"$', re.DOTALL)
m = command_re.search(command) #--command has to be the last argument
m = command_re.search(command) # --command has to be the last argument
if m:
cli_command = m.group(1)
return cli_command
@ -71,7 +72,7 @@ class JBoss7CliTestCase(TestCase):
'instance_name': 'Instance1',
'cli_user': 'jbossadm',
'cli_password': 'jbossadm',
'status_url' : 'http://sampleapp.company.com:8080/'
'status_url': 'http://sampleapp.company.com:8080/'
}
def setUp(self):
@ -89,7 +90,6 @@ class JBoss7CliTestCase(TestCase):
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="jbossadm" --password="jbossadm" --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',
@ -99,14 +99,12 @@ class JBoss7CliTestCase(TestCase):
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="jbossadm" --password="jbossadm" --command="sample_operation"')
def test_handling_jboss_error(self):
def command_response(command):
return {'retcode': 1,
@ -182,7 +180,6 @@ class JBoss7CliTestCase(TestCase):
self.assertEqual(result['key1'], 'value1')
self.assertEqual(result['key2'], 'value2')
def test_parse_nested_dictionary(self):
text = '''{
"key1" => "value1",
@ -352,7 +349,6 @@ class JBoss7CliTestCase(TestCase):
self.assertIsNone(result['result']['url-delimiter'])
self.assertFalse(result['result']['validate-on-match'])
def test_datasource_resource_one_attribute_description(self):
cli_output = '''{
"outcome" => "success",
@ -391,7 +387,6 @@ class JBoss7CliTestCase(TestCase):
self.assertEqual(conn_url_attributes['storage'], 'configuration')
self.assertEqual(conn_url_attributes['restart-required'], 'no-services')
def test_datasource_complete_resource_description(self):
cli_output = '''{
"outcome" => "success",
@ -431,15 +426,8 @@ class JBoss7CliTestCase(TestCase):
self.assertEqual(conn_url_attributes['storage'], 'configuration')
self.assertEqual(conn_url_attributes['restart-required'], 'no-services')
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="jbossadm" --password="jbossadm" --command="/subsystem=naming/binding=\"java:/sampleapp/web-module/ldap/username\":add(binding-type=simple, value=\"DOMAIN\\\\\\\\user\")"')

View File

@ -98,7 +98,7 @@ class JBoss7TestCase(TestCase):
return {'outcome': 'success',
'result': {
'attributes': {
'use-ccm': {'type' : 'BOOLEAN'}
'use-ccm': {'type': 'BOOLEAN'}
}
}
}
@ -136,7 +136,7 @@ class JBoss7TestCase(TestCase):
return {'outcome': 'success',
'result': {
'attributes': {
'min-pool-size': {'type' : 'INT'}
'min-pool-size': {'type': 'INT'}
}
}
}
@ -155,7 +155,7 @@ class JBoss7TestCase(TestCase):
return {'outcome': 'success',
'result': {
'attributes': {
'min-pool-size': {'type' : 'INT'}
'min-pool-size': {'type': 'INT'}
}
}
}
@ -174,11 +174,11 @@ class JBoss7TestCase(TestCase):
return {
'outcome' : 'success',
'result' : {
'driver-name' : 'mysql',
'connection-url' : 'jdbc:mysql://localhost:3306/app',
'jndi-name' : 'java:jboss/datasources/appDS',
'user-name' : 'app',
'password' : 'app_password'
'driver-name': 'mysql',
'connection-url': 'jdbc:mysql://localhost:3306/app',
'jndi-name': 'java:jboss/datasources/appDS',
'user-name': 'app',
'password': 'app_password'
}
}
@ -197,7 +197,7 @@ class JBoss7TestCase(TestCase):
datasource_properties = {'driver-name': 'mysql',
'connection-url': 'jdbc:mysql://localhost:3306/app',
'jndi-name': 'java:jboss/datasources/appDS',
'user-name' : 'newuser',
'user-name': 'newuser',
'password': 'app_password'}
def cli_command_response(jboss_config, cli_command, fail_on_error=False):
@ -205,11 +205,11 @@ class JBoss7TestCase(TestCase):
return {'outcome': 'success',
'result': {
'attributes': {
'driver-name': {'type' : 'STRING'},
'connection-url': {'type' : 'STRING'},
'jndi-name': {'type' : 'STRING'},
'user-name': {'type' : 'STRING'},
'password': {'type' : 'STRING'}
'driver-name': {'type': 'STRING'},
'connection-url': {'type': 'STRING'},
'jndi-name': {'type': 'STRING'},
'user-name': {'type': 'STRING'},
'password': {'type': 'STRING'}
}
}
}
@ -218,17 +218,17 @@ class JBoss7TestCase(TestCase):
return {
'outcome' : 'success',
'result' : {
'driver-name' : 'mysql',
'connection-url' : 'jdbc:mysql://localhost:3306/app',
'jndi-name' : 'java:jboss/datasources/appDS',
'user-name' : 'app',
'password' : 'app_password'
'driver-name': 'mysql',
'connection-url': 'jdbc:mysql://localhost:3306/app',
'jndi-name': 'java:jboss/datasources/appDS',
'user-name': 'app',
'password': 'app_password'
}
}
elif cli_command == '/subsystem=datasources/data-source="appDS":write-attribute(name="user-name",value="newuser")':
return {
'outcome' : 'success',
'outcome': 'success',
'success': True
}
@ -237,4 +237,3 @@ class JBoss7TestCase(TestCase):
jboss7.update_datasource(self.jboss_config, 'appDS', datasource_properties)
__salt__['jboss7_cli.run_operation'].assert_any_call(self.jboss_config, '/subsystem=datasources/data-source="appDS":write-attribute(name="user-name",value="newuser")', fail_on_error=False)

View File

@ -47,7 +47,7 @@ class JBoss7StateTestCase(TestCase):
def read_func(jboss_config, name):
if ds_status['created']:
return {'success': True, 'result':datasource_properties}
return {'success': True, 'result': datasource_properties}
else:
return {'success': False, 'err_code': 'JBAS014807'}
@ -73,7 +73,7 @@ class JBoss7StateTestCase(TestCase):
if ds_status['updated']:
return {'success': True, 'result': {'connection-url': 'jdbc:/new-connection-url'}}
else:
return {'success': True, 'result':{'connection-url': 'jdbc:/old-connection-url'}}
return {'success': True, 'result': {'connection-url': 'jdbc:/old-connection-url'}}
def update_func(jboss_config, name, new_properties):
ds_status['updated'] = True
@ -125,9 +125,10 @@ class JBoss7StateTestCase(TestCase):
def test_should_create_binding_if_not_exists(self):
# given
binding_status = {'created': False}
def read_func(jboss_config, binding_name):
if binding_status['created']:
return {'success': True, 'result': {'value' : 'DEV'}}
return {'success': True, 'result': {'value': 'DEV'}}
else:
return {'success': False, 'err_code': 'JBAS014807'}
@ -150,11 +151,12 @@ class JBoss7StateTestCase(TestCase):
def test_should_update_bindings_if_exists_and_different(self):
# given
binding_status = {'updated': False}
def read_func(jboss_config, binding_name):
if binding_status['updated']:
return {'success': True, 'result': {'value' : 'DEV2'}}
return {'success': True, 'result': {'value': 'DEV2'}}
else:
return {'success': True, 'result':{'value' : 'DEV'}}
return {'success': True, 'result': {'value': 'DEV'}}
def update_func(jboss_config, binding_name, value):
binding_status['updated'] = True
@ -174,7 +176,7 @@ class JBoss7StateTestCase(TestCase):
def test_should_not_update_bindings_if_same(self):
# given
__salt__['jboss7.read_simple_binding'].return_value = {'success': True, 'result': {'value' : 'DEV2'}}
__salt__['jboss7.read_simple_binding'].return_value = {'success': True, 'result': {'value': 'DEV2'}}
# when
result = jboss7.bindings_exist(name='bindings', jboss_config={}, bindings={'env': 'DEV2'})
@ -204,7 +206,7 @@ class JBoss7StateTestCase(TestCase):
def test_should_raise_exception_if_cannot_update_binding(self):
def read_func(jboss_config, binding_name):
return {'success': True, 'result': {'value' : 'DEV'}}
return {'success': True, 'result': {'value': 'DEV'}}
def update_func(jboss_config, binding_name, value):
return {'success': False, 'failure-description': 'Incorrect binding name.'}