| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
import abc |
| 14 |
|
| 15 |
from neutron_lib.services import base |
| 16 |
from neutron_lib.tests import _base as test_base |
| 17 |
|
| 18 |
|
| 19 |
class _Worker(base.WorkerBase): |
| 20 |
pass |
| 21 |
|
| 22 |
|
| 23 |
class Test_WorkerSupportServiceMixin(test_base.BaseTestCase): |
| 24 |
|
| 25 |
def setUp(self): |
| 26 |
super().setUp() |
| 27 |
self.worker = _Worker() |
| 28 |
|
| 29 |
def test_allocate_workers(self): |
| 30 |
self.assertEqual([], self.worker.get_workers()) |
| 31 |
|
| 32 |
def test_add_worker(self): |
| 33 |
workers = [object(), object()] |
| 34 |
for w in workers: |
| 35 |
self.worker.add_worker(w) |
| 36 |
|
| 37 |
self.assertSequenceEqual(workers, self.worker.get_workers()) |
| 38 |
|
| 39 |
def test_add_workers(self): |
| 40 |
workers = [object(), object(), object()] |
| 41 |
self.worker.add_workers(workers) |
| 42 |
|
| 43 |
self.assertSequenceEqual(workers, self.worker.get_workers()) |
| 44 |
|
| 45 |
|
| 46 |
class TestPluginInterface(test_base.BaseTestCase): |
| 47 |
|
| 48 |
class ServicePluginStub(base.ServicePluginBase): |
| 49 |
def get_plugin_type(self): |
| 50 |
pass |
| 51 |
|
| 52 |
def get_plugin_description(self): |
| 53 |
pass |
| 54 |
|
| 55 |
def test_issubclass_hook(self): |
| 56 |
class A(TestPluginInterface.ServicePluginStub): |
| 57 |
def f(self): |
| 58 |
pass |
| 59 |
|
| 60 |
class B(base.ServicePluginBase): |
| 61 |
@abc.abstractmethod |
| 62 |
def f(self): |
| 63 |
pass |
| 64 |
|
| 65 |
self.assertTrue(issubclass(A, B)) |
| 66 |
|
| 67 |
def test_issubclass_hook_class_without_abstract_methods(self): |
| 68 |
class A: |
| 69 |
def f(self): |
| 70 |
pass |
| 71 |
|
| 72 |
class B(base.ServicePluginBase): |
| 73 |
def f(self): |
| 74 |
pass |
| 75 |
|
| 76 |
self.assertFalse(issubclass(A, B)) |
| 77 |
|
| 78 |
def test_issubclass_hook_not_all_methods_implemented(self): |
| 79 |
class A(TestPluginInterface.ServicePluginStub): |
| 80 |
def f(self): |
| 81 |
pass |
| 82 |
|
| 83 |
class B(base.ServicePluginBase): |
| 84 |
@abc.abstractmethod |
| 85 |
def f(self): |
| 86 |
pass |
| 87 |
|
| 88 |
@abc.abstractmethod |
| 89 |
def g(self): |
| 90 |
pass |
| 91 |
|
| 92 |
self.assertFalse(issubclass(A, B)) |