Merge ~mpontillo/maas:fix-attrib-deprecation-warnings into maas:master

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: d1cccf36c05627a4e8317d426fa60fe0501fbd44
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~mpontillo/maas:fix-attrib-deprecation-warnings
Merge into: maas:master
Diff against target: 250 lines (+65/-62)
4 files modified
src/maasserver/regiondservices/ntp.py (+2/-2)
src/provisioningserver/dhcp/detect.py (+3/-3)
src/provisioningserver/drivers/pod/__init__.py (+56/-53)
src/provisioningserver/rackdservices/ntp.py (+4/-4)
Reviewer Review Type Date Requested Status
MAAS Lander Needs Fixing
Andres Rodriguez (community) Approve
Review via email: mp+336883@code.launchpad.net

Commit message

Fix deprecated attr.ib paramter.

 * Rename 'convert=' to 'converter='.
   See https://github.com/python-attrs/attrs/issues/307

Description of the change

Just a drive-by fix for some annoying warnings I was seeing during development.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Lgtm!!!

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-attrib-deprecation-warnings lp:~mpontillo/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/1350/console
COMMIT: 5e2abdb08d1268d7c6e8a7aad608e6304131fed9

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/regiondservices/ntp.py b/src/maasserver/regiondservices/ntp.py
2index cb7a7a9..3d0e9d7 100644
3--- a/src/maasserver/regiondservices/ntp.py
4+++ b/src/maasserver/regiondservices/ntp.py
5@@ -107,7 +107,7 @@ class _Configuration:
6 """Configuration for the region's NTP servers."""
7
8 # Addresses or hostnames of reference time servers.
9- references = attr.ib(convert=frozenset)
10+ references = attr.ib(converter=frozenset)
11
12 # Addresses of peer region controller hosts.
13- peers = attr.ib(convert=frozenset)
14+ peers = attr.ib(converter=frozenset)
15diff --git a/src/provisioningserver/dhcp/detect.py b/src/provisioningserver/dhcp/detect.py
16index 61ce666..aab6c13 100644
17--- a/src/provisioningserver/dhcp/detect.py
18+++ b/src/provisioningserver/dhcp/detect.py
19@@ -450,7 +450,7 @@ class DHCPRequestMonitor:
20 log.info(
21 "External DHCP server(s) discovered on interface '{ifname}': "
22 "{servers}", ifname=self.ifname, servers=', '.join(
23- str(server) for server in servers))
24+ str(server) for server in sorted(list(servers))))
25 self.servers = servers
26
27 @property
28@@ -464,8 +464,8 @@ class DHCPRequestMonitor:
29
30 @attr.s(hash=True)
31 class DHCPServer:
32- server = attr.ib(convert=IPAddress)
33- address = attr.ib(convert=IPAddress)
34+ server = attr.ib(converter=IPAddress)
35+ address = attr.ib(converter=IPAddress)
36
37 def __str__(self):
38 """Returns either a longer format string (if the address we received
39diff --git a/src/provisioningserver/drivers/pod/__init__.py b/src/provisioningserver/drivers/pod/__init__.py
40index 992ecfc..56b290b 100644
41--- a/src/provisioningserver/drivers/pod/__init__.py
42+++ b/src/provisioningserver/drivers/pod/__init__.py
43@@ -96,9 +96,9 @@ class PodActionError(PodError):
44 or `discover`."""
45
46
47-def convert_obj(expected, optional=False):
48+def converter_obj(expected, optional=False):
49 """Convert the given value to an object of type `expected`."""
50- def convert(value):
51+ def converter(value):
52 if optional and value is None:
53 return None
54 if isinstance(value, expected):
55@@ -108,12 +108,12 @@ def convert_obj(expected, optional=False):
56 else:
57 raise TypeError(
58 "%r is not of type %s or dict" % (value, expected))
59- return convert
60+ return converter
61
62
63-def convert_list(expected):
64+def converter_list(expected):
65 """Convert the given value to a list of objects of type `expected`."""
66- def convert(value):
67+ def converter(value):
68 if isinstance(value, list):
69 if len(value) == 0:
70 return value
71@@ -131,7 +131,7 @@ def convert_list(expected):
72 return new_list
73 else:
74 raise TypeError("%r is not of type list" % value)
75- return convert
76+ return converter
77
78
79 class Capabilities:
80@@ -184,45 +184,46 @@ class AttrHelperMixin:
81 @attr.s
82 class DiscoveredMachineInterface(AttrHelperMixin):
83 """Discovered machine interface."""
84- mac_address = attr.ib(convert=str)
85- vid = attr.ib(convert=int, default=-1)
86- tags = attr.ib(convert=convert_list(str), default=attr.Factory(list))
87- boot = attr.ib(convert=bool, default=False)
88+ mac_address = attr.ib(converter=str)
89+ vid = attr.ib(converter=int, default=-1)
90+ tags = attr.ib(converter=converter_list(str), default=attr.Factory(list))
91+ boot = attr.ib(converter=bool, default=False)
92
93
94 @attr.s
95 class DiscoveredMachineBlockDevice(AttrHelperMixin):
96 """Discovered machine block device."""
97- model = attr.ib(convert=convert_obj(str, optional=True))
98- serial = attr.ib(convert=convert_obj(str, optional=True))
99- size = attr.ib(convert=int)
100- block_size = attr.ib(convert=int, default=512)
101- tags = attr.ib(convert=convert_list(str), default=attr.Factory(list))
102- id_path = attr.ib(convert=convert_obj(str, optional=True), default=None)
103- type = attr.ib(convert=str, default=BlockDeviceType.PHYSICAL)
104+ model = attr.ib(converter=converter_obj(str, optional=True))
105+ serial = attr.ib(converter=converter_obj(str, optional=True))
106+ size = attr.ib(converter=int)
107+ block_size = attr.ib(converter=int, default=512)
108+ tags = attr.ib(converter=converter_list(str), default=attr.Factory(list))
109+ id_path = attr.ib(
110+ converter=converter_obj(str, optional=True), default=None)
111+ type = attr.ib(converter=str, default=BlockDeviceType.PHYSICAL)
112
113 # Used when `type` is set to `BlockDeviceType.ISCSI`. The pod driver must
114 # define an `iscsi_target` or it will not create the device for the
115 # discovered machine.
116 iscsi_target = attr.ib(
117- convert=convert_obj(str, optional=True), default=None)
118+ converter=converter_obj(str, optional=True), default=None)
119
120
121 @attr.s
122 class DiscoveredMachine(AttrHelperMixin):
123 """Discovered machine."""
124- architecture = attr.ib(convert=str)
125- cores = attr.ib(convert=int)
126- cpu_speed = attr.ib(convert=int)
127- memory = attr.ib(convert=int)
128- interfaces = attr.ib(convert=convert_list(DiscoveredMachineInterface))
129+ architecture = attr.ib(converter=str)
130+ cores = attr.ib(converter=int)
131+ cpu_speed = attr.ib(converter=int)
132+ memory = attr.ib(converter=int)
133+ interfaces = attr.ib(converter=converter_list(DiscoveredMachineInterface))
134 block_devices = attr.ib(
135- convert=convert_list(DiscoveredMachineBlockDevice))
136- power_state = attr.ib(convert=str, default='unknown')
137+ converter=converter_list(DiscoveredMachineBlockDevice))
138+ power_state = attr.ib(converter=str, default='unknown')
139 power_parameters = attr.ib(
140- convert=convert_obj(dict), default=attr.Factory(dict))
141- tags = attr.ib(convert=convert_list(str), default=attr.Factory(list))
142- hostname = attr.ib(convert=str, default=None)
143+ converter=converter_obj(dict), default=attr.Factory(dict))
144+ tags = attr.ib(converter=converter_list(str), default=attr.Factory(list))
145+ hostname = attr.ib(converter=str, default=None)
146
147
148 @attr.s
149@@ -232,37 +233,38 @@ class DiscoveredPodHints(AttrHelperMixin):
150 Hints provide helpful information to a user trying to compose a machine.
151 Limiting the maximum cores allow request on a per machine basis.
152 """
153- cores = attr.ib(convert=int)
154- cpu_speed = attr.ib(convert=int)
155- memory = attr.ib(convert=int)
156- local_storage = attr.ib(convert=int)
157- local_disks = attr.ib(convert=int, default=-1)
158- iscsi_storage = attr.ib(convert=int, default=-1)
159+ cores = attr.ib(converter=int)
160+ cpu_speed = attr.ib(converter=int)
161+ memory = attr.ib(converter=int)
162+ local_storage = attr.ib(converter=int)
163+ local_disks = attr.ib(converter=int, default=-1)
164+ iscsi_storage = attr.ib(converter=int, default=-1)
165
166
167 @attr.s
168 class DiscoveredPod(AttrHelperMixin):
169 """Discovered pod information."""
170- architectures = attr.ib(convert=convert_list(str))
171- cores = attr.ib(convert=int)
172- cpu_speed = attr.ib(convert=int)
173- memory = attr.ib(convert=int)
174- local_storage = attr.ib(convert=int)
175- hints = attr.ib(convert=convert_obj(DiscoveredPodHints))
176- local_disks = attr.ib(convert=int, default=-1)
177- iscsi_storage = attr.ib(convert=int, default=-1)
178+ architectures = attr.ib(converter=converter_list(str))
179+ cores = attr.ib(converter=int)
180+ cpu_speed = attr.ib(converter=int)
181+ memory = attr.ib(converter=int)
182+ local_storage = attr.ib(converter=int)
183+ hints = attr.ib(converter=converter_obj(DiscoveredPodHints))
184+ local_disks = attr.ib(converter=int, default=-1)
185+ iscsi_storage = attr.ib(converter=int, default=-1)
186 capabilities = attr.ib(
187- convert=convert_list(str), default=attr.Factory(
188+ converter=converter_list(str), default=attr.Factory(
189 lambda: [Capabilities.FIXED_LOCAL_STORAGE]))
190 machines = attr.ib(
191- convert=convert_list(DiscoveredMachine), default=attr.Factory(list))
192+ converter=converter_list(DiscoveredMachine),
193+ default=attr.Factory(list))
194
195
196 @attr.s
197 class RequestedMachineBlockDevice(AttrHelperMixin):
198 """Requested machine block device information."""
199- size = attr.ib(convert=int)
200- tags = attr.ib(convert=convert_list(str), default=attr.Factory(list))
201+ size = attr.ib(converter=int)
202+ tags = attr.ib(converter=converter_list(str), default=attr.Factory(list))
203
204
205 @attr.s
206@@ -274,16 +276,17 @@ class RequestedMachineInterface(AttrHelperMixin):
207 @attr.s
208 class RequestedMachine(AttrHelperMixin):
209 """Requested machine information."""
210- hostname = attr.ib(convert=str)
211- architecture = attr.ib(convert=str)
212- cores = attr.ib(convert=int)
213- memory = attr.ib(convert=int)
214- block_devices = attr.ib(convert=convert_list(RequestedMachineBlockDevice))
215- interfaces = attr.ib(convert=convert_list(RequestedMachineInterface))
216+ hostname = attr.ib(converter=str)
217+ architecture = attr.ib(converter=str)
218+ cores = attr.ib(converter=int)
219+ memory = attr.ib(converter=int)
220+ block_devices = attr.ib(
221+ converter=converter_list(RequestedMachineBlockDevice))
222+ interfaces = attr.ib(converter=converter_list(RequestedMachineInterface))
223
224 # Optional fields.
225 cpu_speed = attr.ib(
226- convert=convert_obj(int, optional=True), default=None)
227+ converter=converter_obj(int, optional=True), default=None)
228
229 @classmethod
230 def fromdict(cls, data):
231diff --git a/src/provisioningserver/rackdservices/ntp.py b/src/provisioningserver/rackdservices/ntp.py
232index 4a11be6..39be675 100644
233--- a/src/provisioningserver/rackdservices/ntp.py
234+++ b/src/provisioningserver/rackdservices/ntp.py
235@@ -117,11 +117,11 @@ class _Configuration:
236 """Configuration for the rack's NTP servers."""
237
238 # Addresses or hostnames of reference time servers.
239- references = attr.ib(convert=frozenset)
240+ references = attr.ib(converter=frozenset)
241 # Addresses of peer time servers.
242- peers = attr.ib(convert=frozenset)
243+ peers = attr.ib(converter=frozenset)
244
245 # The type of this controller. It's fair to assume that is_rack is true,
246 # but check nevertheless before applying this configuration.
247- is_region = attr.ib(convert=bool)
248- is_rack = attr.ib(convert=bool)
249+ is_region = attr.ib(converter=bool)
250+ is_rack = attr.ib(converter=bool)

Subscribers

People subscribed via source and target branches