Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions dynamic_dynamodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions dynamic_dynamodb/aws/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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():
Expand All @@ -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

Expand Down Expand Up @@ -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 []

Expand Down
8 changes: 4 additions & 4 deletions dynamic_dynamodb/config/command_line_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import os.path
import argparse
import ConfigParser
import configparser


def parse():
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions dynamic_dynamodb/config/config_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')))
Expand All @@ -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<header>.*) *\]")
config_file.optionxform = lambda option: option
config_file.read(config_path)
Expand Down Expand Up @@ -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: <table_name>] section in {0}'.format(
Expand All @@ -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()))
2 changes: 1 addition & 1 deletion dynamic_dynamodb/config_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []

Expand Down
2 changes: 1 addition & 1 deletion dynamic_dynamodb/core/gsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion dynamic_dynamodb/core/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions dynamic_dynamodb/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion dynamic_dynamodb/dynamic-dynamodb.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[general]
version: 2.5.1
version: 3.0.0
20 changes: 10 additions & 10 deletions dynamic_dynamodb/test_calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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__':
Expand Down
16 changes: 8 additions & 8 deletions dynamic_dynamodb/test_scaling_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,53 @@
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):
"""
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):
"""
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):
"""
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):
"""
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):
"""
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)
Loading