1313# under the License.
1414#
1515
16- import copy
1716import random
1817import re
1918from unittest import mock
3231from openstack .compute .v2 import server_migration as _server_migration
3332from openstack .compute .v2 import volume_attachment as _volume_attachment
3433
35- from openstackclient .tests .unit import fakes
3634from openstackclient .tests .unit .identity .v3 import fakes as identity_fakes
3735from openstackclient .tests .unit .image .v2 import fakes as image_fakes
3836from openstackclient .tests .unit .network .v2 import fakes as network_fakes
@@ -79,16 +77,14 @@ class TestComputev2(
7977def create_one_agent (attrs = None ):
8078 """Create a fake agent.
8179
82- :param dict attrs:
83- A dictionary with all attributes
84- :return:
85- A FakeResource object, with agent_id, os, and so on
80+ :param dict attrs: A dictionary with all attributes
81+ :return: A dicionarty faking the agent
8682 """
8783
8884 attrs = attrs or {}
8985
9086 # set default attributes.
91- agent_info = {
87+ agent_attrs = {
9288 'agent_id' : 'agent-id-' + uuid .uuid4 ().hex ,
9389 'os' : 'agent-os-' + uuid .uuid4 ().hex ,
9490 'architecture' : 'agent-architecture' ,
@@ -98,22 +94,20 @@ def create_one_agent(attrs=None):
9894 'hypervisor' : 'hypervisor' ,
9995 }
10096
97+ assert not set (attrs ) - set (agent_attrs ), 'unknown keys'
98+
10199 # Overwrite default attributes.
102- agent_info .update (attrs )
100+ agent_attrs .update (attrs )
103101
104- agent = fakes .FakeResource (info = copy .deepcopy (agent_info ), loaded = True )
105- return agent
102+ return agent_attrs
106103
107104
108105def create_agents (attrs = None , count = 2 ):
109106 """Create multiple fake agents.
110107
111- :param dict attrs:
112- A dictionary with all attributes
113- :param int count:
114- The number of agents to fake
115- :return:
116- A list of FakeResource objects faking the agents
108+ :param dict attrs: A dictionary with all attributes
109+ :param int count: The number of agents to fake
110+ :return: A list of dictionaries faking the agents
117111 """
118112 agents = []
119113 for i in range (0 , count ):
@@ -158,10 +152,8 @@ def create_one_extension(attrs=None):
158152def create_one_security_group (attrs = None ):
159153 """Create a fake security group.
160154
161- :param dict attrs:
162- A dictionary with all attributes
163- :return:
164- A FakeResource object, with id, name, etc.
155+ :param dict attrs: A dictionary with all attributes
156+ :return: A dictionary faking the security group
165157 """
166158 attrs = attrs or {}
167159
@@ -174,6 +166,8 @@ def create_one_security_group(attrs=None):
174166 'rules' : [],
175167 }
176168
169+ assert not set (attrs ) - set (security_group_attrs ), 'unknown keys'
170+
177171 # Overwrite default attributes.
178172 security_group_attrs .update (attrs )
179173 return security_group_attrs
@@ -182,12 +176,9 @@ def create_one_security_group(attrs=None):
182176def create_security_groups (attrs = None , count = 2 ):
183177 """Create multiple fake security groups.
184178
185- :param dict attrs:
186- A dictionary with all attributes
187- :param int count:
188- The number of security groups to fake
189- :return:
190- A list of FakeResource objects faking the security groups
179+ :param dict attrs: A dictionary with all attributes
180+ :param int count: The number of security groups to fake
181+ :return: A list of dictionaries faking the security groups
191182 """
192183 security_groups = []
193184 for i in range (0 , count ):
@@ -199,10 +190,8 @@ def create_security_groups(attrs=None, count=2):
199190def create_one_security_group_rule (attrs = None ):
200191 """Create a fake security group rule.
201192
202- :param dict attrs:
203- A dictionary with all attributes
204- :return:
205- A FakeResource object, with id, etc.
193+ :param dict attrs: A dictionary with all attributes
194+ :return: A dictionary faking the security group rule
206195 """
207196 attrs = attrs or {}
208197
@@ -217,6 +206,8 @@ def create_one_security_group_rule(attrs=None):
217206 'to_port' : 0 ,
218207 }
219208
209+ assert not set (attrs ) - set (security_group_rule_attrs ), 'unknown keys'
210+
220211 # Overwrite default attributes.
221212 security_group_rule_attrs .update (attrs )
222213
@@ -226,12 +217,9 @@ def create_one_security_group_rule(attrs=None):
226217def create_security_group_rules (attrs = None , count = 2 ):
227218 """Create multiple fake security group rules.
228219
229- :param dict attrs:
230- A dictionary with all attributes
231- :param int count:
232- The number of security group rules to fake
233- :return:
234- A list of FakeResource objects faking the security group rules
220+ :param dict attrs: A dictionary with all attributes
221+ :param int count: The number of security group rules to fake
222+ :return: A list of dictionaries faking the security group rules
235223 """
236224 security_group_rules = []
237225 for i in range (0 , count ):
@@ -379,10 +367,8 @@ def create_flavors(attrs=None, count=2):
379367def create_one_flavor_access (attrs = None ):
380368 """Create a fake flavor access.
381369
382- :param dict attrs:
383- A dictionary with all attributes
384- :return:
385- A FakeResource object, with flavor_id, tenat_id
370+ :param dict attrs: A dictionary with all attributes
371+ :return: A dictionary faking the flavor access
386372 """
387373 attrs = attrs or {}
388374
@@ -392,14 +378,12 @@ def create_one_flavor_access(attrs=None):
392378 'tenant_id' : 'tenant-id-' + uuid .uuid4 ().hex ,
393379 }
394380
381+ assert not set (attrs ) - set (flavor_access_info ), 'unknown keys'
382+
395383 # Overwrite default attributes.
396384 flavor_access_info .update (attrs )
397385
398- flavor_access = fakes .FakeResource (
399- info = copy .deepcopy (flavor_access_info ), loaded = True
400- )
401-
402- return flavor_access
386+ return flavor_access_info
403387
404388
405389def create_one_availability_zone (attrs = None ):
@@ -454,12 +438,10 @@ def create_availability_zones(attrs=None, count=2):
454438
455439
456440def create_one_floating_ip (attrs = None ):
457- """Create a fake floating ip .
441+ """Create a fake floating IP .
458442
459- :param dict attrs:
460- A dictionary with all attributes
461- :return:
462- A FakeResource object, with id, ip, and so on
443+ :param dict attrs: A dictionary with all attributes
444+ :return: A dictionary faking the floating IP
463445 """
464446 attrs = attrs or {}
465447
@@ -472,54 +454,32 @@ def create_one_floating_ip(attrs=None):
472454 'pool' : 'public' ,
473455 }
474456
457+ assert not set (attrs ) - set (floating_ip_attrs ), 'unknown keys'
458+
475459 # Overwrite default attributes.
476460 floating_ip_attrs .update (attrs )
477461
478462 return floating_ip_attrs
479463
480464
481465def create_floating_ips (attrs = None , count = 2 ):
482- """Create multiple fake floating ips.
483-
484- :param dict attrs:
485- A dictionary with all attributes
486- :param int count:
487- The number of floating ips to fake
488- :return:
489- A list of FakeResource objects faking the floating ips
466+ """Create multiple fake floating IPs.
467+
468+ :param dict attrs: A dictionary with all attributes
469+ :param int count: The number of floating IPs to fake
470+ :return: A list of dictionaries faking the floating IPs
490471 """
491472 floating_ips = []
492473 for i in range (0 , count ):
493474 floating_ips .append (create_one_floating_ip (attrs ))
494475 return floating_ips
495476
496477
497- def get_floating_ips (floating_ips = None , count = 2 ):
498- """Get an iterable MagicMock object with a list of faked floating ips.
499-
500- If floating_ips list is provided, then initialize the Mock object
501- with the list. Otherwise create one.
502-
503- :param List floating_ips:
504- A list of FakeResource objects faking floating ips
505- :param int count:
506- The number of floating ips to fake
507- :return:
508- An iterable Mock object with side_effect set to a list of faked
509- floating ips
510- """
511- if floating_ips is None :
512- floating_ips = create_floating_ips (count )
513- return mock .Mock (side_effect = floating_ips )
514-
515-
516478def create_one_floating_ip_pool (attrs = None ):
517- """Create a fake floating ip pool.
479+ """Create a fake floating IP pool.
518480
519- :param dict attrs:
520- A dictionary with all attributes
521- :return:
522- A FakeResource object, with name, etc
481+ :param dict attrs: A dictionary with all attributes
482+ :return: A dictionary faking the floating IP pool
523483 """
524484 if attrs is None :
525485 attrs = {}
@@ -529,21 +489,20 @@ def create_one_floating_ip_pool(attrs=None):
529489 'name' : 'floating-ip-pool-name-' + uuid .uuid4 ().hex ,
530490 }
531491
492+ assert not set (attrs ) - set (floating_ip_pool_attrs ), 'unknown keys'
493+
532494 # Overwrite default attributes.
533495 floating_ip_pool_attrs .update (attrs )
534496
535497 return floating_ip_pool_attrs
536498
537499
538500def create_floating_ip_pools (attrs = None , count = 2 ):
539- """Create multiple fake floating ip pools.
540-
541- :param dict attrs:
542- A dictionary with all attributes
543- :param int count:
544- The number of floating ip pools to fake
545- :return:
546- A list of FakeResource objects faking the floating ip pools
501+ """Create multiple fake floating IP pools.
502+
503+ :param dict attrs: A dictionary with all attributes
504+ :param int count: The number of floating IP pools to fake
505+ :return: A list of dictionaries faking the floating IP pools
547506 """
548507 floating_ip_pools = []
549508 for i in range (0 , count ):
@@ -554,10 +513,8 @@ def create_floating_ip_pools(attrs=None, count=2):
554513def create_one_network (attrs = None ):
555514 """Create a fake network.
556515
557- :param dict attrs:
558- A dictionary with all attributes
559- :return:
560- A FakeResource object, with id, label, cidr and so on
516+ :param dict attrs: A dictionary with all attributes
517+ :return: A dictionary faking the network
561518 """
562519 attrs = attrs or {}
563520
@@ -597,6 +554,8 @@ def create_one_network(attrs=None):
597554 'vpn_public_port' : None ,
598555 }
599556
557+ assert not set (attrs ) - set (network_attrs ), 'unknown keys'
558+
600559 # Overwrite default attributes.
601560 network_attrs .update (attrs )
602561
@@ -606,12 +565,9 @@ def create_one_network(attrs=None):
606565def create_networks (attrs = None , count = 2 ):
607566 """Create multiple fake networks.
608567
609- :param dict attrs:
610- A dictionary with all attributes
611- :param int count:
612- The number of networks to fake
613- :return:
614- A list of FakeResource objects faking the networks
568+ :param dict attrs: A dictionary with all attributes
569+ :param int count: The number of networks to fake
570+ :return: A list of dictionaries faking the networks
615571 """
616572 networks = []
617573 for i in range (0 , count ):
0 commit comments