Browse Source

Make ManagerWithFind abstract and fix its descendants

ManagerWithFind requires list() method in its descendants.
Make it abstract and fix its improper descendants that do
not implement list() (SecurityGroupRuleManager and many others).

Fixes: bug #1180393
Change-Id: Ic8b466a57554018092c31c6d6b3ea62f181d7000
tags/2.14.0
Alessio Ababilov 6 years ago
parent
commit
c9fc9b5b8f

+ 8
- 3
novaclient/base.py View File

@@ -19,6 +19,7 @@
19 19
 Base utilities to build API operation managers and objects on top of.
20 20
 """
21 21
 
22
+import abc
22 23
 import contextlib
23 24
 import hashlib
24 25
 import os
@@ -167,6 +168,13 @@ class ManagerWithFind(Manager):
167 168
     """
168 169
     Like a `Manager`, but with additional `find()`/`findall()` methods.
169 170
     """
171
+
172
+    __metaclass__ = abc.ABCMeta
173
+
174
+    @abc.abstractmethod
175
+    def list(self):
176
+        pass
177
+
170 178
     def find(self, **kwargs):
171 179
         """
172 180
         Find a single item with attributes matching ``**kwargs``.
@@ -204,9 +212,6 @@ class ManagerWithFind(Manager):
204 212
 
205 213
         return found
206 214
 
207
-    def list(self):
208
-        raise NotImplementedError
209
-
210 215
 
211 216
 class BootingManagerWithFind(ManagerWithFind):
212 217
     """Like a `ManagerWithFind`, but has the ability to boot servers."""

+ 1
- 1
novaclient/v1_1/certs.py View File

@@ -29,7 +29,7 @@ class Certificate(base.Resource):
29 29
                          len(self.data))
30 30
 
31 31
 
32
-class CertificateManager(base.ManagerWithFind):
32
+class CertificateManager(base.Manager):
33 33
     """
34 34
     Manage :class:`Certificate` resources.
35 35
     """

+ 1
- 1
novaclient/v1_1/coverage_ext.py View File

@@ -21,7 +21,7 @@ class Coverage(base.Resource):
21 21
         return "<Coverage: %s>" % self.name
22 22
 
23 23
 
24
-class CoverageManager(base.ManagerWithFind):
24
+class CoverageManager(base.Manager):
25 25
 
26 26
     resource_class = Coverage
27 27
 

+ 1
- 1
novaclient/v1_1/fixed_ips.py View File

@@ -27,7 +27,7 @@ class FixedIP(base.Resource):
27 27
         return "<FixedIP: %s>" % self.address
28 28
 
29 29
 
30
-class FixedIPsManager(base.ManagerWithFind):
30
+class FixedIPsManager(base.Manager):
31 31
     resource_class = FixedIP
32 32
 
33 33
     def get(self, fixed_ip):

+ 2
- 2
novaclient/v1_1/floating_ip_dns.py View File

@@ -47,7 +47,7 @@ class FloatingIPDNSDomain(base.Resource):
47 47
         return None
48 48
 
49 49
 
50
-class FloatingIPDNSDomainManager(base.ManagerWithFind):
50
+class FloatingIPDNSDomainManager(base.Manager):
51 51
     resource_class = FloatingIPDNSDomain
52 52
 
53 53
     def domains(self):
@@ -90,7 +90,7 @@ class FloatingIPDNSEntry(base.Resource):
90 90
         return self.manager.get(self.domain, self.name)
91 91
 
92 92
 
93
-class FloatingIPDNSEntryManager(base.ManagerWithFind):
93
+class FloatingIPDNSEntryManager(base.Manager):
94 94
     resource_class = FloatingIPDNSEntry
95 95
 
96 96
     def get(self, domain, name):

+ 3
- 1
novaclient/v1_1/hosts.py View File

@@ -62,8 +62,10 @@ class HostManager(base.ManagerWithFind):
62 62
         url = '/os-hosts/%s/action' % host
63 63
         return self.api.client.post(url, body=body)
64 64
 
65
-    def list_all(self, zone=None):
65
+    def list(self, zone=None):
66 66
         url = '/os-hosts'
67 67
         if zone:
68 68
             url = '/os-hosts?zone=%s' % zone
69 69
         return self._list(url, "hosts")
70
+
71
+    list_all = list

+ 1
- 1
novaclient/v1_1/quota_classes.py View File

@@ -28,7 +28,7 @@ class QuotaClassSet(base.Resource):
28 28
         return self.manager.update(self.class_name, *args, **kwargs)
29 29
 
30 30
 
31
-class QuotaClassSetManager(base.ManagerWithFind):
31
+class QuotaClassSetManager(base.Manager):
32 32
     resource_class = QuotaClassSet
33 33
 
34 34
     def get(self, class_name):

+ 1
- 1
novaclient/v1_1/quotas.py View File

@@ -28,7 +28,7 @@ class QuotaSet(base.Resource):
28 28
         return self.manager.update(self.tenant_id, *args, **kwargs)
29 29
 
30 30
 
31
-class QuotaSetManager(base.ManagerWithFind):
31
+class QuotaSetManager(base.Manager):
32 32
     resource_class = QuotaSet
33 33
 
34 34
     def get(self, tenant_id):

+ 1
- 1
novaclient/v1_1/security_group_rules.py View File

@@ -28,7 +28,7 @@ class SecurityGroupRule(base.Resource):
28 28
         self.manager.delete(self)
29 29
 
30 30
 
31
-class SecurityGroupRuleManager(base.ManagerWithFind):
31
+class SecurityGroupRuleManager(base.Manager):
32 32
     resource_class = SecurityGroupRule
33 33
 
34 34
     def create(self, parent_group_id, ip_protocol=None, from_port=None,

+ 1
- 1
novaclient/v1_1/shell.py View File

@@ -2503,7 +2503,7 @@ def do_host_describe(cs, args):
2503 2503
 def do_host_list(cs, args):
2504 2504
     """List all hosts by service"""
2505 2505
     columns = ["host_name", "service", "zone"]
2506
-    result = cs.hosts.list_all(args.zone)
2506
+    result = cs.hosts.list(args.zone)
2507 2507
     utils.print_list(result, columns)
2508 2508
 
2509 2509
 

+ 2
- 2
tests/v1_1/test_hosts.py View File

@@ -14,13 +14,13 @@ class HostsTest(utils.TestCase):
14 14
         [self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
15 15
 
16 16
     def test_list_host(self):
17
-        hs = cs.hosts.list_all()
17
+        hs = cs.hosts.list()
18 18
         cs.assert_called('GET', '/os-hosts')
19 19
         [self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
20 20
         [self.assertEqual(h.zone, 'nova1') for h in hs]
21 21
 
22 22
     def test_list_host_with_zone(self):
23
-        hs = cs.hosts.list_all('nova')
23
+        hs = cs.hosts.list('nova')
24 24
         cs.assert_called('GET', '/os-hosts?zone=nova')
25 25
         [self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
26 26
         [self.assertEqual(h.zone, 'nova') for h in hs]

Loading…
Cancel
Save