Parcourir la 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 il y a 6 ans
Parent
révision
c9fc9b5b8f

+ 8
- 3
novaclient/base.py Voir le fichier

@@ -19,6 +19,7 @@
Base utilities to build API operation managers and objects on top of.
"""

import abc
import contextlib
import hashlib
import os
@@ -167,6 +168,13 @@ class ManagerWithFind(Manager):
"""
Like a `Manager`, but with additional `find()`/`findall()` methods.
"""

__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def list(self):
pass

def find(self, **kwargs):
"""
Find a single item with attributes matching ``**kwargs``.
@@ -204,9 +212,6 @@ class ManagerWithFind(Manager):

return found

def list(self):
raise NotImplementedError


class BootingManagerWithFind(ManagerWithFind):
"""Like a `ManagerWithFind`, but has the ability to boot servers."""

+ 1
- 1
novaclient/v1_1/certs.py Voir le fichier

@@ -29,7 +29,7 @@ class Certificate(base.Resource):
len(self.data))


class CertificateManager(base.ManagerWithFind):
class CertificateManager(base.Manager):
"""
Manage :class:`Certificate` resources.
"""

+ 1
- 1
novaclient/v1_1/coverage_ext.py Voir le fichier

@@ -21,7 +21,7 @@ class Coverage(base.Resource):
return "<Coverage: %s>" % self.name


class CoverageManager(base.ManagerWithFind):
class CoverageManager(base.Manager):

resource_class = Coverage


+ 1
- 1
novaclient/v1_1/fixed_ips.py Voir le fichier

@@ -27,7 +27,7 @@ class FixedIP(base.Resource):
return "<FixedIP: %s>" % self.address


class FixedIPsManager(base.ManagerWithFind):
class FixedIPsManager(base.Manager):
resource_class = FixedIP

def get(self, fixed_ip):

+ 2
- 2
novaclient/v1_1/floating_ip_dns.py Voir le fichier

@@ -47,7 +47,7 @@ class FloatingIPDNSDomain(base.Resource):
return None


class FloatingIPDNSDomainManager(base.ManagerWithFind):
class FloatingIPDNSDomainManager(base.Manager):
resource_class = FloatingIPDNSDomain

def domains(self):
@@ -90,7 +90,7 @@ class FloatingIPDNSEntry(base.Resource):
return self.manager.get(self.domain, self.name)


class FloatingIPDNSEntryManager(base.ManagerWithFind):
class FloatingIPDNSEntryManager(base.Manager):
resource_class = FloatingIPDNSEntry

def get(self, domain, name):

+ 3
- 1
novaclient/v1_1/hosts.py Voir le fichier

@@ -62,8 +62,10 @@ class HostManager(base.ManagerWithFind):
url = '/os-hosts/%s/action' % host
return self.api.client.post(url, body=body)

def list_all(self, zone=None):
def list(self, zone=None):
url = '/os-hosts'
if zone:
url = '/os-hosts?zone=%s' % zone
return self._list(url, "hosts")

list_all = list

+ 1
- 1
novaclient/v1_1/quota_classes.py Voir le fichier

@@ -28,7 +28,7 @@ class QuotaClassSet(base.Resource):
return self.manager.update(self.class_name, *args, **kwargs)


class QuotaClassSetManager(base.ManagerWithFind):
class QuotaClassSetManager(base.Manager):
resource_class = QuotaClassSet

def get(self, class_name):

+ 1
- 1
novaclient/v1_1/quotas.py Voir le fichier

@@ -28,7 +28,7 @@ class QuotaSet(base.Resource):
return self.manager.update(self.tenant_id, *args, **kwargs)


class QuotaSetManager(base.ManagerWithFind):
class QuotaSetManager(base.Manager):
resource_class = QuotaSet

def get(self, tenant_id):

+ 1
- 1
novaclient/v1_1/security_group_rules.py Voir le fichier

@@ -28,7 +28,7 @@ class SecurityGroupRule(base.Resource):
self.manager.delete(self)


class SecurityGroupRuleManager(base.ManagerWithFind):
class SecurityGroupRuleManager(base.Manager):
resource_class = SecurityGroupRule

def create(self, parent_group_id, ip_protocol=None, from_port=None,

+ 1
- 1
novaclient/v1_1/shell.py Voir le fichier

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



+ 2
- 2
tests/v1_1/test_hosts.py Voir le fichier

@@ -14,13 +14,13 @@ class HostsTest(utils.TestCase):
[self.assertTrue(isinstance(h, hosts.Host)) for h in hs]

def test_list_host(self):
hs = cs.hosts.list_all()
hs = cs.hosts.list()
cs.assert_called('GET', '/os-hosts')
[self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
[self.assertEqual(h.zone, 'nova1') for h in hs]

def test_list_host_with_zone(self):
hs = cs.hosts.list_all('nova')
hs = cs.hosts.list('nova')
cs.assert_called('GET', '/os-hosts?zone=nova')
[self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
[self.assertEqual(h.zone, 'nova') for h in hs]

Chargement…
Annuler
Enregistrer