initial version
Change-Id: I699e0ab082657880998d8618fe29eb7f56c6c661
This commit is contained in:
0
watcher/tests/applier/__init__.py
Normal file
0
watcher/tests/applier/__init__.py
Normal file
0
watcher/tests/applier/demo/__init__.py
Normal file
0
watcher/tests/applier/demo/__init__.py
Normal file
65
watcher/tests/applier/demo/test_applier.py
Normal file
65
watcher/tests/applier/demo/test_applier.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
from oslo_config import cfg
|
||||
|
||||
from watcher.applier.framework.default_applier import DefaultApplier
|
||||
|
||||
from watcher.common import utils
|
||||
from watcher.decision_engine.framework.default_planner import DefaultPlanner
|
||||
from watcher.decision_engine.strategies.basic_consolidation import \
|
||||
BasicConsolidation
|
||||
from watcher.openstack.common import log
|
||||
from watcher.tests.db import base
|
||||
from watcher.tests.db import utils as db_utils
|
||||
from watcher.tests.decision_engine.faker_cluster_state import \
|
||||
FakerStateCollector
|
||||
from watcher.tests.decision_engine.faker_metrics_collector import \
|
||||
FakerMetricsCollector
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
CONF = cfg.CONF
|
||||
""
|
||||
class TestApplier(base.DbTestCase):
|
||||
default_planner = DefaultPlanner()
|
||||
|
||||
def create_solution(self):
|
||||
metrics = FakerMetricsCollector()
|
||||
current_state_cluster = FakerStateCollector()
|
||||
sercon = BasicConsolidation()
|
||||
sercon.set_metrics_resource_collector(metrics)
|
||||
return sercon.execute(current_state_cluster.generate_scenario_1())
|
||||
|
||||
def test_scheduler_w(self):
|
||||
CONF.debug = True
|
||||
log.setup('watcher-sercon-demo')
|
||||
|
||||
CONF.keystone_authtoken.auth_uri = "http://10.50.0.105:5000/v3"
|
||||
CONF.keystone_authtoken.admin_user = "admin"
|
||||
CONF.keystone_authtoken.admin_password = "openstacktest"
|
||||
CONF.keystone_authtoken.admin_tenant_name = "test"
|
||||
|
||||
audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
|
||||
|
||||
action_plan = self.default_planner.schedule(self.context,
|
||||
audit.id,
|
||||
self.create_solution())
|
||||
|
||||
applier = DefaultApplier()
|
||||
applier.execute(self.context, action_plan.uuid)
|
||||
"""""
|
||||
99
watcher/tests/applier/demo/test_migrate.py
Normal file
99
watcher/tests/applier/demo/test_migrate.py
Normal file
@@ -0,0 +1,99 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
"""
|
||||
from keystoneclient import session
|
||||
|
||||
from keystoneclient.auth.identity import v3
|
||||
|
||||
import cinderclient.v2.client as ciclient
|
||||
import glanceclient.v2.client as glclient
|
||||
import keystoneclient.v3.client as ksclient
|
||||
import neutronclient.neutron.client as netclient
|
||||
import novaclient.v2.client as nvclient
|
||||
|
||||
from watcher.common.utils import CONF
|
||||
from oslo_config import cfg
|
||||
from watcher.applier.framework.command.migrate_command import MigrateCommand
|
||||
from watcher.applier.framework.command.wrapper.nova_wrapper import NovaWrapper
|
||||
from watcher.decision_engine.framework.default_planner import Primitives
|
||||
from watcher.openstack.common import log
|
||||
|
||||
cfg.CONF.import_opt('auth_uri', 'keystoneclient.middleware.auth_token',
|
||||
group='keystone_authtoken')
|
||||
cfg.CONF.import_opt('admin_user', 'keystoneclient.middleware.auth_token',
|
||||
group='keystone_authtoken')
|
||||
cfg.CONF.import_opt('admin_password', 'keystoneclient.middleware.auth_token',
|
||||
group='keystone_authtoken')
|
||||
cfg.CONF.import_opt('admin_tenant_name',
|
||||
'keystoneclient.middleware.auth_token',
|
||||
group='keystone_authtoken')
|
||||
|
||||
cfg.CONF.keystone_authtoken.auth_uri = "http://10.50.0.105:5000/v3/"
|
||||
cfg.CONF.keystone_authtoken.admin_user = "admin"
|
||||
cfg.CONF.keystone_authtoken.admin_password = "openstacktest"
|
||||
cfg.CONF.keystone_authtoken.admin_tenant_name = "test"
|
||||
|
||||
try:
|
||||
cfg.CONF.debug = True
|
||||
log.setup('watcher-sercon-demo')
|
||||
creds = \
|
||||
{'auth_url': CONF.keystone_authtoken.auth_uri,
|
||||
'username': CONF.keystone_authtoken.admin_user,
|
||||
'password': CONF.keystone_authtoken.admin_password,
|
||||
'project_name': CONF.keystone_authtoken.admin_tenant_name,
|
||||
'user_domain_name': "default",
|
||||
'project_domain_name': "default"}
|
||||
auth = v3.Password(auth_url=creds['auth_url'],
|
||||
username=creds['username'],
|
||||
password=creds['password'],
|
||||
project_name=creds['project_name'],
|
||||
user_domain_name=creds[
|
||||
'user_domain_name'],
|
||||
project_domain_name=creds[
|
||||
'project_domain_name'])
|
||||
sess = session.Session(auth=auth)
|
||||
nova = nvclient.Client("3", session=sess)
|
||||
neutron = netclient.Client('2.0', session=sess)
|
||||
neutron.format = 'json'
|
||||
keystone = ksclient.Client(**creds)
|
||||
|
||||
glance_endpoint = keystone. \
|
||||
service_catalog.url_for(service_type='image',
|
||||
endpoint_type='publicURL')
|
||||
glance = glclient.Client(glance_endpoint,
|
||||
token=keystone.auth_token)
|
||||
|
||||
cinder = ciclient.Client('2', session=sess)
|
||||
wrapper = NovaWrapper(user=creds['username'], nova=nova,
|
||||
neutron=neutron, glance=glance,
|
||||
cinder=cinder)
|
||||
instance = wrapper. \
|
||||
create_instance(hypervisor_id='ldev-indeedsrv006',
|
||||
inst_name="demo_instance_1",
|
||||
keypair_name='admin',
|
||||
image_id=
|
||||
"2b958331-379b-4618-b2ba-fbe8a608b2bb")
|
||||
|
||||
cmd = MigrateCommand(instance.id, Primitives.COLD_MIGRATE,
|
||||
'ldev-indeedsrv006',
|
||||
'ldev-indeedsrv005')
|
||||
resu = cmd.execute(cmd)
|
||||
resu.result()
|
||||
# wrapper.delete_instance(instance.id)
|
||||
except Exception as e:
|
||||
print("rollback " + unicode(e))
|
||||
"""""
|
||||
0
watcher/tests/applier/framework/__init__.py
Normal file
0
watcher/tests/applier/framework/__init__.py
Normal file
0
watcher/tests/applier/framework/command/__init__.py
Normal file
0
watcher/tests/applier/framework/command/__init__.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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.
|
||||
from mock import call
|
||||
from mock import MagicMock
|
||||
|
||||
|
||||
from watcher.applier.framework.messaging.events import Events
|
||||
from watcher.applier.framework.messaging.launch_action_plan import \
|
||||
LaunchActionPlanCommand
|
||||
|
||||
from watcher.objects.action_plan import Status
|
||||
from watcher.objects import ActionPlan
|
||||
from watcher.tests.db.base import DbTestCase
|
||||
from watcher.tests.objects import utils as obj_utils
|
||||
|
||||
|
||||
class TestLaunchActionPlanCommand(DbTestCase):
|
||||
def setUp(self):
|
||||
super(TestLaunchActionPlanCommand, self).setUp()
|
||||
self.action_plan = obj_utils.create_test_action_plan(
|
||||
self.context)
|
||||
|
||||
def test_launch_action_plan_wihout_errors(self):
|
||||
try:
|
||||
|
||||
command = LaunchActionPlanCommand(self.context, MagicMock(),
|
||||
self.action_plan.uuid)
|
||||
command.execute()
|
||||
except Exception as e:
|
||||
self.fail(
|
||||
"The ActionPlan should be trigged wihtour error" + unicode(e))
|
||||
|
||||
def test_launch_action_plan_state_failed(self):
|
||||
command = LaunchActionPlanCommand(self.context, MagicMock(),
|
||||
self.action_plan.uuid)
|
||||
command.execute()
|
||||
action_plan = ActionPlan.get_by_uuid(self.context,
|
||||
self.action_plan.uuid)
|
||||
self.assertEqual(Status.SUCCESS, action_plan.state)
|
||||
|
||||
def test_trigger_audit_send_notification(self):
|
||||
messaging = MagicMock()
|
||||
command = LaunchActionPlanCommand(self.context, messaging,
|
||||
self.action_plan.uuid)
|
||||
command.execute()
|
||||
|
||||
call_on_going = call(Events.LAUNCH_ACTION_PLAN.name, {
|
||||
'action_plan_status': Status.ONGOING,
|
||||
'action_plan__uuid': self.action_plan.uuid})
|
||||
call_success = call(Events.LAUNCH_ACTION_PLAN.name, {
|
||||
'action_plan_status': Status.SUCCESS,
|
||||
'action_plan__uuid': self.action_plan.uuid})
|
||||
|
||||
calls = [call_on_going, call_success]
|
||||
messaging.topic_status.publish_event.assert_has_calls(calls)
|
||||
self.assertEqual(2, messaging.topic_status.publish_event.call_count)
|
||||
@@ -0,0 +1,64 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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 time
|
||||
from watcher.applier.framework.command.wrapper.nova_wrapper import NovaWrapper
|
||||
from watcher.common import utils
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestNovaWrapper(base.TestCase):
|
||||
@mock.patch('keystoneclient.v3.client.Client')
|
||||
def setUp(self, mock_ksclient):
|
||||
super(TestNovaWrapper, self).setUp()
|
||||
self.instance_uuid = "fb5311b7-37f3-457e-9cde-6494a3c59bfe"
|
||||
self.source_hypervisor = "ldev-indeedsrv005"
|
||||
self.destination_hypervisor = "ldev-indeedsrv006"
|
||||
|
||||
self.creds = mock.MagicMock()
|
||||
self.session = mock.MagicMock()
|
||||
self.wrapper = NovaWrapper(creds=self.creds, session=self.session)
|
||||
|
||||
def test_stop_instance(self):
|
||||
instance_id = utils.generate_uuid()
|
||||
server = mock.MagicMock()
|
||||
server.id = instance_id
|
||||
setattr(server, 'OS-EXT-STS:vm_state', 'stopped')
|
||||
self.wrapper.nova.servers = mock.MagicMock()
|
||||
self.wrapper.nova.servers.find.return_value = server
|
||||
self.wrapper.nova.servers.list.return_value = [server]
|
||||
|
||||
result = self.wrapper.stop_instance(instance_id)
|
||||
self.assertEqual(result, True)
|
||||
|
||||
def test_set_host_offline(self):
|
||||
host = mock.MagicMock()
|
||||
self.wrapper.nova.hosts = mock.MagicMock()
|
||||
self.wrapper.nova.hosts.get.return_value = host
|
||||
result = self.wrapper.set_host_offline("rennes")
|
||||
self.assertEqual(result, True)
|
||||
|
||||
def test_live_migrate_instance(self):
|
||||
server = mock.MagicMock()
|
||||
server.id = self.instance_uuid
|
||||
self.wrapper.nova.servers = mock.MagicMock()
|
||||
self.wrapper.nova.servers.list.return_value = [server]
|
||||
with mock.patch.object(time, 'sleep'):
|
||||
instance = self.wrapper.live_migrate_instance(
|
||||
self.instance_uuid,
|
||||
self.destination_hypervisor)
|
||||
self.assertIsNotNone(instance)
|
||||
@@ -0,0 +1,38 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
from mock import MagicMock
|
||||
from watcher.applier.framework.messaging.trigger_action_plan import \
|
||||
TriggerActionPlan
|
||||
from watcher.common import utils
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestTriggerActionPlan(base.TestCase):
|
||||
def __init__(self, *args, **kwds):
|
||||
super(TestTriggerActionPlan, self).__init__(*args, **kwds)
|
||||
self.applier = MagicMock()
|
||||
self.endpoint = TriggerActionPlan(self.applier)
|
||||
|
||||
def setUp(self):
|
||||
super(TestTriggerActionPlan, self).setUp()
|
||||
|
||||
def test_launch_action_plan(self):
|
||||
action_plan_uuid = utils.generate_uuid()
|
||||
expected_uuid = self.endpoint.launch_action_plan(self.context,
|
||||
action_plan_uuid)
|
||||
self.assertEqual(action_plan_uuid, expected_uuid)
|
||||
29
watcher/tests/applier/framework/test_applier_manager.py
Normal file
29
watcher/tests/applier/framework/test_applier_manager.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
from watcher.applier.framework.manager_applier import ApplierManager
|
||||
from watcher.common.messaging.events.event import Event
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestApplierManager(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestApplierManager, self).setUp()
|
||||
self.applier = ApplierManager()
|
||||
|
||||
def test_evt(self):
|
||||
e = Event()
|
||||
self.applier.event_receive(e)
|
||||
60
watcher/tests/applier/framework/test_command_executor.py
Normal file
60
watcher/tests/applier/framework/test_command_executor.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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
|
||||
|
||||
from watcher.applier.framework.command_executor import CommandExecutor
|
||||
from watcher import objects
|
||||
|
||||
from watcher.common import utils
|
||||
from watcher.decision_engine.framework.default_planner import Primitives
|
||||
from watcher.objects.action import Action
|
||||
from watcher.objects.action import Status
|
||||
from watcher.tests.db.base import DbTestCase
|
||||
|
||||
|
||||
class TestCommandExecutor(DbTestCase):
|
||||
def setUp(self):
|
||||
super(TestCommandExecutor, self).setUp()
|
||||
self.applier = mock.MagicMock()
|
||||
self.executor = CommandExecutor(self.applier, self.context)
|
||||
|
||||
def test_execute(self):
|
||||
actions = mock.MagicMock()
|
||||
result = self.executor.execute(actions)
|
||||
self.assertEqual(result, True)
|
||||
|
||||
def test_execute_with_actions(self):
|
||||
actions = []
|
||||
action = {
|
||||
'uuid': utils.generate_uuid(),
|
||||
'action_plan_id': 0,
|
||||
'action_type': Primitives.NOP.value,
|
||||
'applies_to': '',
|
||||
'src': '',
|
||||
'dst': '',
|
||||
'parameter': '',
|
||||
'description': '',
|
||||
'state': Status.PENDING,
|
||||
'alarm': None,
|
||||
'next': None,
|
||||
}
|
||||
new_action = objects.Action(self.context, **action)
|
||||
new_action.create(self.context)
|
||||
new_action.save()
|
||||
actions.append(Action.get_by_uuid(self.context, action['uuid']))
|
||||
result = self.executor.execute(actions)
|
||||
self.assertEqual(result, True)
|
||||
56
watcher/tests/applier/framework/test_command_mapper.py
Normal file
56
watcher/tests/applier/framework/test_command_mapper.py
Normal file
@@ -0,0 +1,56 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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
|
||||
from watcher.applier.framework.default_command_mapper import \
|
||||
DefaultCommandMapper
|
||||
from watcher.decision_engine.framework.default_planner import Primitives
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestCommandMapper(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestCommandMapper, self).setUp()
|
||||
self.mapper = DefaultCommandMapper()
|
||||
|
||||
def test_build_command_cold(self):
|
||||
action = mock.MagicMock()
|
||||
action.action_type = Primitives.COLD_MIGRATE.value
|
||||
cmd = self.mapper.build_primitive_command(action)
|
||||
self.assertIsNotNone(cmd)
|
||||
|
||||
def test_build_command_live(self):
|
||||
action = mock.MagicMock()
|
||||
action.action_type = Primitives.LIVE_MIGRATE.value
|
||||
cmd = self.mapper.build_primitive_command(action)
|
||||
self.assertIsNotNone(cmd)
|
||||
|
||||
def test_build_command_h_s(self):
|
||||
action = mock.MagicMock()
|
||||
action.action_type = Primitives.HYPERVISOR_STATE.value
|
||||
cmd = self.mapper.build_primitive_command(action)
|
||||
self.assertIsNotNone(cmd)
|
||||
|
||||
def test_build_command_p_s(self):
|
||||
action = mock.MagicMock()
|
||||
action.action_type = Primitives.POWER_STATE.value
|
||||
cmd = self.mapper.build_primitive_command(action)
|
||||
self.assertIsNotNone(cmd)
|
||||
|
||||
def test_build_command_exception_attribute(self):
|
||||
action = mock.MagicMock
|
||||
self.assertRaises(AttributeError, self.mapper.build_primitive_command,
|
||||
action)
|
||||
31
watcher/tests/applier/framework/test_manager.py
Normal file
31
watcher/tests/applier/framework/test_manager.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
from watcher.decision_engine.framework.manager_decision_engine import \
|
||||
DecisionEngineManager
|
||||
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestApplierdManager(base.TestCase):
|
||||
manager = DecisionEngineManager()
|
||||
|
||||
def setUp(self):
|
||||
super(TestApplierdManager, self).setUp()
|
||||
|
||||
def test_event_receive(self):
|
||||
pass
|
||||
58
watcher/tests/applier/framework/test_rpcapi.py
Normal file
58
watcher/tests/applier/framework/test_rpcapi.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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 oslo.messaging as om
|
||||
from watcher.applier.framework.rpcapi import ApplierAPI
|
||||
|
||||
from watcher.common import exception
|
||||
from watcher.common import utils
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestApplierAPI(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestApplierAPI, self).setUp()
|
||||
|
||||
api = ApplierAPI()
|
||||
|
||||
def test_get_version(self):
|
||||
expected_version = self.api.API_VERSION
|
||||
self.assertEqual(expected_version, self.api.get_version())
|
||||
|
||||
def test_get_api_version(self):
|
||||
with mock.patch.object(om.RPCClient, 'call') as mock_call:
|
||||
expected_context = self.context
|
||||
self.api.check_api_version(expected_context)
|
||||
mock_call.assert_called_once_with(
|
||||
expected_context.to_dict(),
|
||||
'check_api_version',
|
||||
api_version=ApplierAPI().API_VERSION)
|
||||
|
||||
def test_execute_action_plan_throw_exception(self):
|
||||
action_plan_uuid = "uuid"
|
||||
self.assertRaises(exception.InvalidUuidOrName,
|
||||
self.api.launch_action_plan,
|
||||
action_plan_uuid)
|
||||
|
||||
def test_execute_audit_without_error(self):
|
||||
with mock.patch.object(om.RPCClient, 'call') as mock_call:
|
||||
action_plan_uuid = utils.generate_uuid()
|
||||
self.api.launch_action_plan(self.context, action_plan_uuid)
|
||||
mock_call.assert_called_once_with(
|
||||
self.context.to_dict(),
|
||||
'launch_action_plan',
|
||||
action_plan_uuid=action_plan_uuid)
|
||||
Reference in New Issue
Block a user