Skip to content

Commit 6af2883

Browse files
author
Tang Chen
committed
Refactor: Set "project_id" for FakeXXX in a consistent style
OpenStack SDK will translate "project_id" into "tenant_id" automatically when referring to "tenant_id" attribute with the name "project_id". So when faking an object returned fron SDK, we need to fake this behavior. The original way is ugly. This patch turns it into a consistent style, and give better comments. Change-Id: I0dfb1f7552fc28eb4e7ebf5c614c9f3bde79ad80
1 parent 5a978b9 commit 6af2883

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

  • openstackclient/tests/network/v2

openstackclient/tests/network/v2/fakes.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,11 @@ def create_one_network(attrs={}, methods={}):
138138
router_external, status, subnets, tenant_id
139139
"""
140140
# Set default attributes.
141-
project_id = 'project-id-' + uuid.uuid4().hex
142141
network_attrs = {
143142
'id': 'network-id-' + uuid.uuid4().hex,
144143
'name': 'network-name-' + uuid.uuid4().hex,
145144
'status': 'ACTIVE',
146-
'tenant_id': project_id,
145+
'tenant_id': 'project-id-' + uuid.uuid4().hex,
147146
'admin_state_up': True,
148147
'shared': False,
149148
'subnets': ['a', 'b'],
@@ -169,7 +168,9 @@ def create_one_network(attrs={}, methods={}):
169168
network = fakes.FakeResource(info=copy.deepcopy(network_attrs),
170169
methods=copy.deepcopy(network_methods),
171170
loaded=True)
172-
network.project_id = project_id
171+
172+
# Set attributes with special mapping in OpenStack SDK.
173+
network.project_id = network_attrs['tenant_id']
173174

174175
return network
175176

@@ -273,7 +274,7 @@ def create_one_port(attrs={}, methods={}):
273274
methods=copy.deepcopy(port_methods),
274275
loaded=True)
275276

276-
# Set attributes with special mappings.
277+
# Set attributes with special mappings in OpenStack SDK.
277278
port.project_id = port_attrs['tenant_id']
278279
port.binding_host_id = port_attrs['binding:host_id']
279280
port.binding_profile = port_attrs['binding:profile']
@@ -695,24 +696,19 @@ def create_one_subnet_pool(attrs={}, methods={}):
695696
A FakeResource object faking the subnet pool
696697
"""
697698
# Set default attributes.
698-
project_id = 'project-id-' + uuid.uuid4().hex
699699
subnet_pool_attrs = {
700700
'id': 'subnet-pool-id-' + uuid.uuid4().hex,
701701
'name': 'subnet-pool-name-' + uuid.uuid4().hex,
702702
'prefixes': ['10.0.0.0/24', '10.1.0.0/24'],
703703
'default_prefixlen': 8,
704704
'address_scope_id': 'address-scope-id-' + uuid.uuid4().hex,
705-
'tenant_id': project_id,
705+
'tenant_id': 'project-id-' + uuid.uuid4().hex,
706706
'is_default': False,
707707
'shared': False,
708708
'max_prefixlen': 32,
709709
'min_prefixlen': 8,
710710
'default_quota': None,
711711
'ip_version': 4,
712-
713-
# OpenStack SDK automatically translates project_id to tenant_id.
714-
# So we need an additional attr to simulate this behavior.
715-
'project_id': project_id,
716712
}
717713

718714
# Overwrite default attributes.
@@ -735,6 +731,9 @@ def create_one_subnet_pool(attrs={}, methods={}):
735731
loaded=True
736732
)
737733

734+
# Set attributes with special mapping in OpenStack SDK.
735+
subnet_pool.project_id = subnet_pool_attrs['tenant_id']
736+
738737
return subnet_pool
739738

740739
@staticmethod

0 commit comments

Comments
 (0)