def calculate_weighted_sd(self, metrics, sd_case): weighted_sd = 0 for metric, value in zip(self.metrics, sd_case): try: weighted_sd += value * float(self.weights[metric + '_weight']) except KeyError, exc: LOG.exception(exc) raise exception.WatcherException( _("Incorrect mapping: could not find " "associated '%s_weight' for" " '%s' in weight dict.").format(metric))
def calculate_weighted_sd(self, sd_case): """Calculate common standard deviation among meters on host""" weighted_sd = 0 for metric, value in zip(self.metrics, sd_case): try: weighted_sd += value * float(self.weights[metric + '_weight']) except KeyError as exc: LOG.exception(exc) raise exception.WatcherException( _("Incorrect mapping: could not find associated weight" " for %s in weight dict.") % metric) return weighted_sd
def define_from_goal(self, goal_name, osc=None): """:param osc: an OpenStackClients instance""" strategy_to_load = None try: strategy_to_load = CONF.watcher_goals.goals[goal_name] return self.strategy_loader.load(strategy_to_load, osc=osc) except KeyError as exc: LOG.exception(exc) raise exception.WatcherException( _("Incorrect mapping: could not find " "associated strategy for '%s'") % goal_name )
def test_send_action_execution_with_error(self): action = utils.create_test_action(mock.Mock(), state=objects.action.State.FAILED, action_type='nop', input_parameters={ 'param1': 1, 'param2': 2 }, parents=[], action_plan_id=self.action_plan.id) try: # This is to load the exception in sys.exc_info() raise exception.WatcherException("TEST") except exception.WatcherException: notifications.action.send_execution_notification(mock.MagicMock(), action, 'execution', phase='error', host='node0', priority='error') self.assertEqual(1, self.m_notifier.error.call_count) notification = self.m_notifier.error.call_args[1] self.assertEqual("infra-optim:node0", self.m_notifier.publisher_id) self.assertDictEqual( { 'event_type': 'action.execution.error', 'payload': { 'watcher_object.namespace': 'watcher', 'watcher_object.version': '1.0', 'watcher_object.name': 'ActionExecutionPayload', 'watcher_object.data': { 'uuid': '10a47dd1-4874-4298-91cf-eff046dbdb8d', 'input_parameters': { 'param2': 2, 'param1': 1 }, 'created_at': '2016-10-18T09:52:05Z', 'fault': { 'watcher_object.data': { 'exception': u'WatcherException', 'exception_message': u'TEST', 'function_name': ('test_send_action_execution_with_error'), 'module_name': ('watcher.tests.notifications.' 'test_action_notification') }, 'watcher_object.name': 'ExceptionPayload', 'watcher_object.namespace': 'watcher', 'watcher_object.version': '1.0' }, 'updated_at': None, 'state': 'FAILED', 'action_plan': { 'watcher_object.namespace': 'watcher', 'watcher_object.version': '1.0', 'watcher_object.name': 'TerseActionPlanPayload', 'watcher_object.data': { 'uuid': '76be87bd-3422-43f9-93a0-e85a577e3061', 'global_efficacy': {}, 'created_at': '2016-10-18T09:52:05Z', 'updated_at': None, 'state': 'ONGOING', 'audit_uuid': '10a47dd1-4874-4298' '-91cf-eff046dbdb8d', 'strategy_uuid': 'cb3d0b58-4415-4d90' '-b75b-1e96878730e3', 'deleted_at': None } }, 'parents': [], 'action_type': 'nop', 'deleted_at': None } } }, notification)
def test_send_action_plan_cancel_with_error(self): action_plan = utils.create_test_action_plan( mock.Mock(), state=objects.action_plan.State.ONGOING, audit_id=self.audit.id, strategy_id=self.strategy.id, audit=self.audit, strategy=self.strategy) try: # This is to load the exception in sys.exc_info() raise exception.WatcherException("TEST") except exception.WatcherException: notifications.action_plan.send_cancel_notification( mock.MagicMock(), action_plan, host='node0', action='cancel', priority='error', phase='error') self.assertEqual(1, self.m_notifier.error.call_count) notification = self.m_notifier.error.call_args[1] self.assertEqual("infra-optim:node0", self.m_notifier.publisher_id) self.assertDictEqual( { "event_type": "action_plan.cancel.error", "payload": { "watcher_object.data": { "created_at": "2016-10-18T09:52:05Z", "deleted_at": None, "fault": { "watcher_object.data": { "exception": "WatcherException", "exception_message": "TEST", "function_name": ( "test_send_action_plan_cancel_with_error"), "module_name": "watcher.tests.notifications." "test_action_plan_notification" }, "watcher_object.name": "ExceptionPayload", "watcher_object.namespace": "watcher", "watcher_object.version": "1.0" }, "audit_uuid": "10a47dd1-4874-4298-91cf-eff046dbdb8d", "audit": { "watcher_object.data": { "interval": None, "next_run_time": None, "auto_trigger": False, "parameters": {}, "uuid": "10a47dd1-4874-4298-91cf-eff046dbdb8d", 'name': 'My Audit', "strategy_uuid": None, "goal_uuid": ( "f7ad87ae-4298-91cf-93a0-f35a852e3652"), "deleted_at": None, "scope": [], "state": "PENDING", "updated_at": None, "created_at": "2016-10-18T09:52:05Z", "audit_type": "ONESHOT" }, "watcher_object.name": "TerseAuditPayload", "watcher_object.namespace": "watcher", "watcher_object.version": "1.2" }, "global_efficacy": [], "state": "ONGOING", "strategy_uuid": ( "cb3d0b58-4415-4d90-b75b-1e96878730e3"), "strategy": { "watcher_object.data": { "created_at": "2016-10-18T09:52:05Z", "deleted_at": None, "display_name": "test strategy", "name": "TEST", "parameters_spec": {}, "updated_at": None, "uuid": "cb3d0b58-4415-4d90-b75b-1e96878730e3" }, "watcher_object.name": "StrategyPayload", "watcher_object.namespace": "watcher", "watcher_object.version": "1.0" }, "updated_at": None, "uuid": "76be87bd-3422-43f9-93a0-e85a577e3061" }, "watcher_object.name": "ActionPlanCancelPayload", "watcher_object.namespace": "watcher", "watcher_object.version": "1.1" } }, notification )