Skip to content

Commit

Permalink
Fix typos and add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardparis committed Oct 3, 2016
1 parent 8703c25 commit 00d0898
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/registry/dynamic_policies/metrics/bw_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, exchange, queue, routing_key, method):

def attach(self, observer, bw_obs):
"""
Asyncronous method. This method allows to be called remotely. It is called from
Asynchronous method. This method allows to be called remotely. It is called from
observers in order to subscribe in this workload metric. This observer will be
saved in a dictionary type structure where the key will be the tenant assigned in the observer,
and the value will be the PyActive proxy to connect to the observer.
Expand Down
2 changes: 1 addition & 1 deletion api/registry/dynamic_policies/rules/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _add_metric(self, workload_name):
# Trying the new PyActive version. New lookup function.
print " - Rule, Workload name:", workload_name
observer = self.host.lookup(workload_name)
print ' - Rule, Ovserver: ', observer.get_id(), observer
print ' - Rule, Observer: ', observer.get_id(), observer
observer.attach(self.proxy)
self.observers_proxies[workload_name] = observer
self.observers_values[workload_name] = None
Expand Down
26 changes: 25 additions & 1 deletion api/registry/tests_dynamic_policies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import mock
import redis
Expand All @@ -8,6 +9,8 @@
from .dsl_parser import parse
from registry.dynamic_policies.rules.rule import Rule
from registry.dynamic_policies.rules.rule_transient import TransientRule
from registry.dynamic_policies.metrics.bw_info import BwInfo
from registry.dynamic_policies.metrics.swift_metric import SwiftMetric

from httmock import urlmatch, HTTMock

Expand All @@ -32,6 +35,11 @@ def setUp(self):
def tearDown(self):
self.r.flushdb()

#
# rules/rule
#


def test_get_target_ok(self):
self.setup_dsl_parser_data()
has_condition_list, parsed_rule = parse('FOR TENANT:4f0279da74ef4584a29dc72c835fe2c9 WHEN metric1 > 5 DO SET compression')
Expand Down Expand Up @@ -118,7 +126,7 @@ def test_action_delete_is_triggered_undeploy_200(self, mock_stop_actor, mock_adm
self.assertTrue(mock_stop_actor.called)

#
# rule_transient
# rules/rule_transient
#

@mock.patch('registry.dynamic_policies.rules.rule_transient.TransientRule.do_action')
Expand Down Expand Up @@ -155,6 +163,22 @@ def test_transient_action_set_is_triggered_200(self, mock_requests_delete, mock_
self.assertFalse(mock_requests_put.called)
self.assertTrue(mock_requests_delete.called)

#
# metrics/bw_info
#

@mock.patch('registry.dynamic_policies.metrics.swift_metric.Thread.start')
def test_metrics_bw_info(self, mock_thread_start):
bw_info = BwInfo('exchange', 'queue', 'routing_key', 'method')
self.assertTrue(mock_thread_start.called)

@mock.patch('registry.dynamic_policies.metrics.swift_metric.SwiftMetric._send_data_to_logstash')
def test_metrics_swift_metric(self, mock_send_data_to_logstash):
swift_metric = SwiftMetric('exchange', 'metric_id', 'routing_key')
data = {"controller": {"@timestamp": 123456789, "AUTH_bd34c4073b65426894545b36f0d8dcce": 3}}
body = json.dumps(data)
swift_metric.notify(body)
self.assertTrue(mock_send_data_to_logstash.called)

#
# Aux methods
Expand Down

0 comments on commit 00d0898

Please sign in to comment.