Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardparis committed Oct 6, 2016
1 parent ad30262 commit 21db647
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion api/registry/tests_dynamic_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from registry.dynamic_policies.metrics.bw_info_ssync import BwInfoSSYNC
from registry.dynamic_policies.metrics.swift_metric import SwiftMetric
from registry.dynamic_policies.rules.min_bandwidth_per_tenant import SimpleMinBandwidthPerTenant
from registry.dynamic_policies.rules.min_slo_tenant_global_share_spare_bw import MinTenantSLOGlobalSpareBWShare
from registry.dynamic_policies.rules.simple_proportional_bandwidth import SimpleProportionalBandwidthPerTenant
from registry.dynamic_policies.rules.simple_proportional_replication_bandwidth import SimpleProportionalReplicationBandwidth

from httmock import urlmatch, HTTMock

Expand Down Expand Up @@ -250,13 +253,52 @@ def test_metrics_swift_metric_send_data_to_logstash(self, mock_socket):
#

@mock.patch('registry.dynamic_policies.rules.base_bw_rule.pika')
def test_simple_min_bandwidth_per_tenant(self, mock_pika):
def test_min_bandwidth_per_tenant(self, mock_pika):
smin = SimpleMinBandwidthPerTenant('the_name', 'the_method')
self.assertTrue(mock_pika.PlainCredentials.called)
info = {'1234567890abcdef': {'192.168.2.21': {'1': {u'sdb1': 655350.0}}}}
computed = smin.compute_algorithm(info)
self.assertEqual(computed, {'1234567890abcdef': {'192.168.2.21-1-sdb1': 115.0}})

#
# rules/min_bandwidth_per_tenant
#

@mock.patch('registry.dynamic_policies.rules.base_bw_rule.pika')
def test_min_tenant_slo_global_spare_bw_share(self, mock_pika):
smin = MinTenantSLOGlobalSpareBWShare('the_name', 'the_method')
self.assertTrue(mock_pika.PlainCredentials.called)
info = {'1234567890abcdef': {'192.168.2.21': {'1': {u'sdb1': 655350.0}}}}
computed = smin.compute_algorithm(info)
self.assertEqual(computed, {'1234567890abcdef': {'192.168.2.21-1-sdb1': 100.0}})

#
# rules/simple_proportional_bandwidth
#

@mock.patch('registry.dynamic_policies.rules.base_bw_rule.pika')
def test_simple_proportional_bandwidth_per_tenant(self, mock_pika):
smin = SimpleProportionalBandwidthPerTenant('the_name', 'the_method')
self.assertTrue(mock_pika.PlainCredentials.called)
info = {'1234567890abcdef': {'192.168.2.21': {'1': {u'sdb1': 655350.0}}}}
computed = smin.compute_algorithm(info)
self.assertEqual(computed, {'1234567890abcdef': {'192.168.2.21-1-sdb1': 100.0}})

#
# rules/simple_proportional_replication_bandwidth
#

@mock.patch('registry.dynamic_policies.rules.simple_proportional_replication_bandwidth.SimpleProportionalReplicationBandwidth._get_redis_bw')
@mock.patch('registry.dynamic_policies.rules.base_bw_rule.pika')
def test_simple_proportional_bandwidth_per_tenant(self, mock_pika, mock_get_redis_bw):
mock_get_redis_bw.return_value = 120.0

smin = SimpleProportionalReplicationBandwidth('the_name', 'the_method')
self.assertTrue(mock_pika.PlainCredentials.called)
info = {'1234567890abcdef': {'192.168.2.21': {'1': {u'sdb1': 655350.0}}}}
computed = smin.compute_algorithm(info)
self.assertEqual(computed, {'1234567890abcdef': {'192.168.2.21': 120.0}})

#
# Aux methods
#
Expand Down

0 comments on commit 21db647

Please sign in to comment.