Merge "Implement watcher datamodel list in watcher-decision-engine"

This commit is contained in:
Zuul
2019-09-10 07:33:34 +00:00
committed by Gerrit Code Review
7 changed files with 174 additions and 3 deletions

View File

@@ -0,0 +1,54 @@
# -*- encoding: utf-8 -*-
# Copyright 2019 ZTE Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
import unittest
from watcher.common import exception
from watcher.common import utils
from watcher.decision_engine.messaging import data_model_endpoint
from watcher.decision_engine.model.collector import manager
from watcher.objects import audit
class TestDataModelEndpoint(unittest.TestCase):
def setUp(self):
self.endpoint_instance = data_model_endpoint.DataModelEndpoint('fake')
@mock.patch.object(audit.Audit, 'get')
def test_get_audit_scope(self, mock_get):
mock_get.return_value = mock.Mock(scope='fake_scope')
audit_uuid = utils.generate_uuid()
result = self.endpoint_instance.get_audit_scope(
context=None,
audit=audit_uuid)
self.assertEqual('fake_scope', result)
@mock.patch.object(audit.Audit, 'get_by_name')
def test_get_audit_scope_with_error_name(self, mock_get_by_name):
mock_get_by_name.side_effect = exception.AuditNotFound()
audit_name = 'error_audit_name'
self.assertRaises(
exception.InvalidIdentity,
self.endpoint_instance.get_audit_scope,
context=None,
audit=audit_name)
@mock.patch.object(manager, 'CollectorManager', mock.Mock())
def test_get_data_model_info(self):
result = self.endpoint_instance.get_data_model_info(context='fake')
self.assertIn('context', result)

View File

@@ -16,6 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
import os
from oslo_utils import uuidutils
@@ -63,6 +64,27 @@ class TestModel(base.TestCase):
model = model_root.ModelRoot.from_xml(struct_str)
self.assertEqual(expected_model.to_string(), model.to_string())
@mock.patch.object(model_root.ModelRoot, 'get_all_compute_nodes')
@mock.patch.object(model_root.ModelRoot, 'get_node_instances')
def test_get_model_to_list(self, mock_instances, mock_nodes):
fake_compute_node = mock.MagicMock(
uuid='fake_node_uuid',
fields=['uuid'])
fake_instance = mock.MagicMock(
uuid='fake_instance_uuid',
fields=['uuid'])
mock_nodes.return_value = {'fake_node_uuid': fake_compute_node}
mock_instances.return_value = [fake_instance]
expected_keys = ['server_uuid', 'node_uuid']
result = model_root.ModelRoot().to_list()
self.assertEqual(1, len(result))
result_keys = result[0].keys()
self.assertEqual(sorted(expected_keys), sorted(result_keys))
def test_get_node_by_instance_uuid(self):
model = model_root.ModelRoot()
uuid_ = "{0}".format(uuidutils.generate_uuid())

View File

@@ -52,3 +52,14 @@ class TestDecisionEngineAPI(base.TestCase):
self.api.get_strategy_info(self.context, "dummy")
mock_call.assert_called_once_with(
self.context, 'get_strategy_info', strategy_name="dummy")
def test_get_data_model_info(self):
with mock.patch.object(om.RPCClient, 'call') as mock_call:
self.api.get_data_model_info(
self.context,
data_model_type='compute',
audit=None)
mock_call.assert_called_once_with(
self.context, 'get_data_model_info',
data_model_type='compute',
audit=None)