]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Switch to using abc in the retargetable client
authorMaru Newby <marun@redhat.com>
Tue, 20 Jan 2015 02:23:48 +0000 (02:23 +0000)
committerMaru Newby <marun@redhat.com>
Tue, 20 Jan 2015 02:23:48 +0000 (02:23 +0000)
abc is preferable to raising NotImplementedError because it will
prevent instantiation of a subclass that doesn't implement the
required methods rather than failing only when a missing method is
called.

Change-Id: I1043eefde675dd3b653d5b508be22cfd52d2fe8f
Implements: bp retargetable-functional-testing

neutron/tests/api/base_v2.py

index 5b3a2eae92986a887abec045a1ef63e94464d5d5..2a59e8df7237d3ef092e8b7f3f079270c1508583 100644 (file)
@@ -47,6 +47,9 @@ Examples of use include:
 Reference: https://pypi.python.org/pypi/testscenarios/
 """
 
+import abc
+
+import six
 import testtools
 
 from neutron.tests import sub_base
@@ -65,6 +68,7 @@ class AttributeDict(dict):
         raise AttributeError(_("Unknown attribute '%s'.") % name)
 
 
+@six.add_metaclass(abc.ABCMeta)
 class BaseNeutronClient(object):
     """
     Base class for a client that can interact the neutron api in some
@@ -80,30 +84,34 @@ class BaseNeutronClient(object):
         """
         self.test_case = test_case
 
-    @property
+    @abc.abstractproperty
     def NotFound(self):
         """The exception that indicates a resource could not be found.
 
         Tests can use this property to assert for a missing resource
         in a client-agnostic way.
         """
-        raise NotImplementedError()
 
+    @abc.abstractmethod
     def create_network(self, **kwargs):
-        raise NotImplementedError()
+        pass
 
+    @abc.abstractmethod
     def update_network(self, id_, **kwargs):
-        raise NotImplementedError()
+        pass
 
+    @abc.abstractmethod
     def get_network(self, id_, fields=None):
-        raise NotImplementedError()
+        pass
 
+    @abc.abstractmethod
     def get_networks(self, filters=None, fields=None,
                      sorts=None, limit=None, marker=None, page_reverse=False):
-        raise NotImplementedError()
+        pass
 
+    @abc.abstractmethod
     def delete_network(self, id_):
-        raise NotImplementedError()
+        pass
 
 
 class BaseTestApi(sub_base.SubBaseTestCase):