diff --git a/Makefile b/Makefile index cbe7f9e..e66114e 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ gen-docs: cd docs; make html install: - python setup.py build - python setup.py install + python3 setup.py build + python3 setup.py install release: - python setup.py register - python setup.py sdist upload + python3 setup.py register + python3 setup.py sdist upload diff --git a/dynamic_dynamodb/__init__.py b/dynamic_dynamodb/__init__.py index 3ed99bf..35d1aca 100644 --- a/dynamic_dynamodb/__init__.py +++ b/dynamic_dynamodb/__init__.py @@ -57,7 +57,7 @@ def main(): """ Main function called from dynamic-dynamodb """ try: if get_global_option('show_config'): - print json.dumps(config.get_configuration(), indent=2) + print(json.dumps(config.get_configuration(), indent=2)) elif get_global_option('daemon'): daemon = DynamicDynamoDBDaemon( '{0}/dynamic-dynamodb.{1}.pid'.format( @@ -141,10 +141,10 @@ def execute(): gsi_names = set() # Add regexp table names for gst_instance in dynamodb.table_gsis(table_name): - gsi_name = gst_instance[u'IndexName'] + gsi_name = gst_instance['IndexName'] try: - gsi_keys = get_table_option(table_key, 'gsis').keys() + gsi_keys = list(get_table_option(table_key, 'gsis').keys()) except AttributeError: # Continue if there are not GSIs configured diff --git a/dynamic_dynamodb/aws/dynamodb.py b/dynamic_dynamodb/aws/dynamodb.py index b660833..addcd8c 100644 --- a/dynamic_dynamodb/aws/dynamodb.py +++ b/dynamic_dynamodb/aws/dynamodb.py @@ -99,9 +99,9 @@ def get_gsi_status(table_name, gsi_name): except JSONResponseError: raise - for gsi in desc[u'Table'][u'GlobalSecondaryIndexes']: - if gsi[u'IndexName'] == gsi_name: - return gsi[u'IndexStatus'] + for gsi in desc['Table']['GlobalSecondaryIndexes']: + if gsi['IndexName'] == gsi_name: + return gsi['IndexStatus'] def get_provisioned_gsi_read_units(table_name, gsi_name): @@ -118,10 +118,10 @@ def get_provisioned_gsi_read_units(table_name, gsi_name): except JSONResponseError: raise - for gsi in desc[u'Table'][u'GlobalSecondaryIndexes']: - if gsi[u'IndexName'] == gsi_name: + for gsi in desc['Table']['GlobalSecondaryIndexes']: + if gsi['IndexName'] == gsi_name: read_units = int( - gsi[u'ProvisionedThroughput'][u'ReadCapacityUnits']) + gsi['ProvisionedThroughput']['ReadCapacityUnits']) break logger.debug( @@ -144,10 +144,10 @@ def get_provisioned_gsi_write_units(table_name, gsi_name): except JSONResponseError: raise - for gsi in desc[u'Table'][u'GlobalSecondaryIndexes']: - if gsi[u'IndexName'] == gsi_name: + for gsi in desc['Table']['GlobalSecondaryIndexes']: + if gsi['IndexName'] == gsi_name: write_units = int( - gsi[u'ProvisionedThroughput'][u'WriteCapacityUnits']) + gsi['ProvisionedThroughput']['WriteCapacityUnits']) break logger.debug( @@ -169,7 +169,7 @@ def get_provisioned_table_read_units(table_name): raise read_units = int( - desc[u'Table'][u'ProvisionedThroughput'][u'ReadCapacityUnits']) + desc['Table']['ProvisionedThroughput']['ReadCapacityUnits']) logger.debug('{0} - Currently provisioned read units: {1:d}'.format( table_name, read_units)) @@ -189,7 +189,7 @@ def get_provisioned_table_write_units(table_name): raise write_units = int( - desc[u'Table'][u'ProvisionedThroughput'][u'WriteCapacityUnits']) + desc['Table']['ProvisionedThroughput']['WriteCapacityUnits']) logger.debug('{0} - Currently provisioned write units: {1:d}'.format( table_name, write_units)) @@ -208,7 +208,7 @@ def get_table_status(table_name): except JSONResponseError: raise - return desc[u'Table'][u'TableStatus'] + return desc['Table']['TableStatus'] def list_tables(): @@ -221,12 +221,12 @@ def list_tables(): try: table_list = DYNAMODB_CONNECTION.list_tables() while True: - for table_name in table_list[u'TableNames']: + for table_name in table_list['TableNames']: tables.append(get_table(table_name)) - if u'LastEvaluatedTableName' in table_list: + if 'LastEvaluatedTableName' in table_list: table_list = DYNAMODB_CONNECTION.list_tables( - table_list[u'LastEvaluatedTableName']) + table_list['LastEvaluatedTableName']) else: break @@ -607,12 +607,12 @@ def table_gsis(table_name): :returns: list -- List of GSI names """ try: - desc = DYNAMODB_CONNECTION.describe_table(table_name)[u'Table'] + desc = DYNAMODB_CONNECTION.describe_table(table_name)['Table'] except JSONResponseError: raise - if u'GlobalSecondaryIndexes' in desc: - return desc[u'GlobalSecondaryIndexes'] + if 'GlobalSecondaryIndexes' in desc: + return desc['GlobalSecondaryIndexes'] return [] diff --git a/dynamic_dynamodb/config/command_line_parser.py b/dynamic_dynamodb/config/command_line_parser.py index ff93263..f70447f 100644 --- a/dynamic_dynamodb/config/command_line_parser.py +++ b/dynamic_dynamodb/config/command_line_parser.py @@ -3,7 +3,7 @@ import sys import os.path import argparse -import ConfigParser +import configparser def parse(): @@ -197,15 +197,15 @@ def parse(): # Print the version and quit if args.version: # Read the dynamic-dynamodb.conf configuration file - internal_config_file = ConfigParser.RawConfigParser() + internal_config_file = configparser.RawConfigParser() internal_config_file.optionxform = lambda option: option internal_config_file.read( os.path.abspath( os.path.join( os.path.dirname(__file__), '../dynamic-dynamodb.conf'))) - print 'Dynamic DynamoDB version: {0}'.format( - internal_config_file.get('general', 'version')) + print('Dynamic DynamoDB version: {0}'.format( + internal_config_file.get('general', 'version'))) sys.exit(0) # Replace any new values in the configuration diff --git a/dynamic_dynamodb/config/config_file_parser.py b/dynamic_dynamodb/config/config_file_parser.py index 38e78f6..be5215c 100644 --- a/dynamic_dynamodb/config/config_file_parser.py +++ b/dynamic_dynamodb/config/config_file_parser.py @@ -2,7 +2,7 @@ """ Command line configuration parser """ import sys import os.path -import ConfigParser +import configparser import re import ast from copy import deepcopy @@ -444,7 +444,7 @@ def __parse_options(config_file, section, options): else: configuration[option.get('key')] = \ config_file.get(section, option.get('option')) - except ConfigParser.NoOptionError: + except configparser.NoOptionError: if option.get('required'): print('Missing [{0}] option "{1}" in configuration'.format( section, option.get('option'))) @@ -462,7 +462,7 @@ def parse(config_path): config_path = os.path.expanduser(config_path) # Read the configuration file - config_file = ConfigParser.RawConfigParser() + config_file = configparser.RawConfigParser() config_file.SECTCRE = re.compile(r"\[ *(?P
.*) *\]") config_file.optionxform = lambda option: option config_file.read(config_path) @@ -569,8 +569,8 @@ def parse(config_path): found_table = True current_table_name = current_section.rsplit(':', 1)[1].strip() table_config['tables'][current_table_name] = \ - dict(default_options.items() + __parse_options( - config_file, current_section, TABLE_CONFIG_OPTIONS).items()) + dict(list(default_options.items()) + list(__parse_options( + config_file, current_section, TABLE_CONFIG_OPTIONS).items())) if not found_table: print('Could not find a [table: ] section in {0}'.format( @@ -597,10 +597,10 @@ def parse(config_path): table_config['tables'][table_key]['gsis'] = {} table_config['tables'][table_key]['gsis'][gsi_key] = \ - ordereddict(default_options.items() + __parse_options( - config_file, current_section, TABLE_CONFIG_OPTIONS).items()) + ordereddict(list(default_options.items()) + list(__parse_options( + config_file, current_section, TABLE_CONFIG_OPTIONS).items())) return ordereddict( - global_config.items() + - logging_config.items() + - table_config.items()) + list(global_config.items()) + + list(logging_config.items()) + + list(table_config.items())) diff --git a/dynamic_dynamodb/config_handler.py b/dynamic_dynamodb/config_handler.py index 010dbf5..70e0018 100644 --- a/dynamic_dynamodb/config_handler.py +++ b/dynamic_dynamodb/config_handler.py @@ -11,7 +11,7 @@ def get_configured_tables(): :returns: list -- List of tables """ try: - return CONFIGURATION['tables'].keys() + return list(CONFIGURATION['tables'].keys()) except KeyError: return [] diff --git a/dynamic_dynamodb/core/gsi.py b/dynamic_dynamodb/core/gsi.py index 139ebf2..7f83730 100644 --- a/dynamic_dynamodb/core/gsi.py +++ b/dynamic_dynamodb/core/gsi.py @@ -1232,7 +1232,7 @@ def scale_reader_decrease(provision_decrease_scale, current_value): """ scale_value = 0 if provision_decrease_scale: - for limits in sorted(provision_decrease_scale.keys(), reverse=True): + for limits in sorted(list(provision_decrease_scale.keys()), reverse=True): if current_value > limits: return scale_value else: diff --git a/dynamic_dynamodb/core/table.py b/dynamic_dynamodb/core/table.py index 136c73c..d32b7a2 100644 --- a/dynamic_dynamodb/core/table.py +++ b/dynamic_dynamodb/core/table.py @@ -1074,7 +1074,7 @@ def scale_reader_decrease(provision_decrease_scale, current_value): """ scale_value = 0 if provision_decrease_scale: - for limits in sorted(provision_decrease_scale.keys(), reverse=True): + for limits in sorted(list(provision_decrease_scale.keys()), reverse=True): if current_value > limits: return scale_value else: diff --git a/dynamic_dynamodb/daemon.py b/dynamic_dynamodb/daemon.py index 1ec3772..80e0c4a 100644 --- a/dynamic_dynamodb/daemon.py +++ b/dynamic_dynamodb/daemon.py @@ -120,13 +120,13 @@ def stop(self): while 1: os.kill(pid, SIGTERM) time.sleep(0.1) - except OSError, err: + except OSError as err: err = str(err) if err.find("No such process") > 0: if os.path.exists(self.pidfile): os.remove(self.pidfile) else: - print str(err) + print(str(err)) sys.exit(1) def restart(self, *args, **kwargs): diff --git a/dynamic_dynamodb/dynamic-dynamodb.conf b/dynamic_dynamodb/dynamic-dynamodb.conf index 6b4084d..6649ab7 100644 --- a/dynamic_dynamodb/dynamic-dynamodb.conf +++ b/dynamic_dynamodb/dynamic-dynamodb.conf @@ -1,2 +1,2 @@ [general] -version: 2.5.1 +version: 3.0.0 diff --git a/dynamic_dynamodb/test_calculators.py b/dynamic_dynamodb/test_calculators.py index 386fdf8..458df28 100644 --- a/dynamic_dynamodb/test_calculators.py +++ b/dynamic_dynamodb/test_calculators.py @@ -85,17 +85,17 @@ def test_decrease_writes_in_units_hit_min_value(self): def test_increase_reads_in_percent(self): """ Ensure that a regular increase works """ - result = calculators.increase_reads_in_percent(200, 50, 400, 'test') + result = calculators.increase_reads_in_percent(200, 50, 400, 2,'test') self.assertEqual(result, 300) def test_increase_reads_in_percent_hit_max_value(self): """ Check that max values are honoured """ - result = calculators.increase_reads_in_percent(20, 50, 15, 'test') + result = calculators.increase_reads_in_percent(20, 50, 15, 2,'test') self.assertEqual(result, 15) def test_increase_reads_in_percent_more_than_100_percent(self): """ Handle increases of more that 100% """ - result = calculators.increase_reads_in_percent(20, 120, 1, 'test') + result = calculators.increase_reads_in_percent(20, 120, 1, 2,'test') self.assertEqual(result, 1) def test_increase_reads_in_percent_type_current_provisioning(self): @@ -110,17 +110,17 @@ def test_increase_reads_in_percent_type_current_provisioning(self): def test_increase_writes_in_percent(self): """ Ensure that a regular increase works """ - result = calculators.increase_writes_in_percent(200, 50, 400, 'test') + result = calculators.increase_writes_in_percent(200, 50, 400, 2,'test') self.assertEqual(result, 300) def test_increase_writes_in_percent_hit_max_value(self): """ Check that max values are honoured """ - result = calculators.increase_writes_in_percent(20, 50, 15, 'test') + result = calculators.increase_writes_in_percent(20, 50, 15, 2,'test') self.assertEqual(result, 15) def test_increase_writes_in_percent_more_than_100_percent(self): """ Handle increases of more that 100% """ - result = calculators.increase_writes_in_percent(20, 120, 1, 'test') + result = calculators.increase_writes_in_percent(20, 120, 1, 2,'test') self.assertEqual(result, 1) def test_increase_writes_in_percent_type_current_provisioning(self): @@ -135,22 +135,22 @@ def test_increase_writes_in_percent_type_current_provisioning(self): def test_increase_reads_in_units(self): """ Ensure that a regular increase works """ - result = calculators.increase_reads_in_units(200, 90, 300, 'test') + result = calculators.increase_reads_in_units(200, 90, 300, 2,'test') self.assertEqual(result, 290) def test_increase_reads_in_units_hit_max_units(self): """ Check that max values are honoured """ - result = calculators.increase_reads_in_units(20, 50, 25, 'test') + result = calculators.increase_reads_in_units(20, 50, 25, 2,'test') self.assertEqual(result, 25) def test_increase_writes_in_units(self): """ Ensure that a regular increase works """ - result = calculators.increase_writes_in_units(200, 90, 300, 'test') + result = calculators.increase_writes_in_units(200, 90, 300, 2,'test') self.assertEqual(result, 290) def test_increase_writes_in_units_hit_max_value(self): """ Check that max values are honoured """ - result = calculators.increase_writes_in_units(20, 10, 25, 'test') + result = calculators.increase_writes_in_units(20, 10, 25, 2,'test') self.assertEqual(result, 25) if __name__ == '__main__': diff --git a/dynamic_dynamodb/test_scaling_metrics.py b/dynamic_dynamodb/test_scaling_metrics.py index f75b9ab..253c224 100644 --- a/dynamic_dynamodb/test_scaling_metrics.py +++ b/dynamic_dynamodb/test_scaling_metrics.py @@ -8,12 +8,12 @@ class TestScaleReader(unittest.TestCase): """ Test the scale reader method """ - def __init__(self): + def setUp(self): self.value = {0: 0, 0.25: 5, 0.5: 10, 1: 20, 2: 50, 5: 100} def test_scale_reader_zero(self): """ Ensure that using a current_value of zero returns zero """ - result = scale_reader(self.value, 0, 80) + result = scale_reader(self.value, 0) self.assertEqual(result, 0) def test_scale_reader_lower_threshold(self): @@ -21,7 +21,7 @@ def test_scale_reader_lower_threshold(self): Ensure that when current_value is above zero but before the lowest threshold zero is returned """ - result = scale_reader(self.value, 0.1, 80) + result = scale_reader(self.value, 0.1) self.assertEquals(result, 0) def test_scale_reader_upper_threshold(self): @@ -29,7 +29,7 @@ def test_scale_reader_upper_threshold(self): Ensure that when current_value is above the highest threshold the highest scaling configured is used """ - result = scale_reader(self.value, 7, 80) + result = scale_reader(self.value, 7) self.assertEquals(result, 100) def test_scale_reader_boundary_value_lower(self): @@ -37,7 +37,7 @@ def test_scale_reader_boundary_value_lower(self): Ensure that correct scaling is used when current_value is on the lower end of a boundary """ - result = scale_reader(self.value, 1, 80) + result = scale_reader(self.value, 0.5) self.assertEquals(result, 10) def test_scale_reader_boundary_value_upper(self): @@ -45,7 +45,7 @@ def test_scale_reader_boundary_value_upper(self): Ensure that correct scaling is used when current_value is on the upper end of a boundary """ - result = scale_reader(self.value, 1.01, 80) + result = scale_reader(self.value, 1.01) self.assertEquals(result, 20) def test_scale_reader_default_scale(self): @@ -53,8 +53,8 @@ def test_scale_reader_default_scale(self): Ensure that if no provision_increase_scale is provided the default_scale_with value is used """ - result = scale_reader({}, 5, 80) - self.assertEquals(result, 80) + result = scale_reader({}, 5) + self.assertEquals(result, 0) if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/setup.py b/setup.py index 56bac9c..49b0f17 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import os import sys from setuptools import setup -from ConfigParser import SafeConfigParser +from configparser import SafeConfigParser settings = SafeConfigParser() settings.read(os.path.realpath('dynamic_dynamodb/dynamic-dynamodb.conf'))