Refactor network fakes to sdk properties PART6

Included resources:
router
security_group
security_group_rule

Change-Id: I2423fc31d94f85aeefc7b0a205dfb38829417a29
This commit is contained in:
Stephen Finucane 2025-04-03 16:19:23 +01:00
parent f870548c7f
commit d96c81ff7f
13 changed files with 353 additions and 410 deletions

View File

@ -76,7 +76,7 @@ def _get_columns(item):
}
if hasattr(item, 'interfaces_info'):
column_map['interfaces_info'] = 'interfaces_info'
invisible_columns = ['location']
invisible_columns = ['location', 'tenant_id']
if item.is_ha is None:
invisible_columns.append('is_ha')
column_map.pop('is_ha')

View File

@ -89,9 +89,8 @@ def _get_columns(item):
# We still support Nova managed security groups, where we have tenant_id.
column_map = {
'security_group_rules': 'rules',
'tenant_id': 'project_id',
}
hidden_columns = ['location']
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item, column_map, hidden_columns
)
@ -186,7 +185,8 @@ class CreateSecurityGroup(
parsed_args.name,
description,
)
display_columns, property_columns = _get_columns(obj)
display_columns = ('description', 'id', 'name', 'project_id', 'rules')
property_columns = ('description', 'id', 'name', 'tenant_id', 'rules')
data = utils.get_dict_properties(
obj, property_columns, formatters=_formatters_compute
)
@ -420,7 +420,8 @@ class ShowSecurityGroup(common.NetworkAndComputeShowOne):
def take_action_compute(self, client, parsed_args):
obj = compute_v2.find_security_group(client, parsed_args.group)
display_columns, property_columns = _get_columns(obj)
display_columns = ('description', 'id', 'name', 'project_id', 'rules')
property_columns = ('description', 'id', 'name', 'tenant_id', 'rules')
data = utils.get_dict_properties(
obj, property_columns, formatters=_formatters_compute
)

View File

@ -30,7 +30,7 @@ LOG = logging.getLogger(__name__)
def _get_columns(item):
hidden_columns = ['location', 'tenant_id']
hidden_columns = ['location', 'name', 'tenant_id', 'tags']
return utils.get_osc_show_columns_for_sdk_resource(
item, {}, hidden_columns
)

View File

@ -46,7 +46,9 @@ from openstack.network.v2 import (
from openstack.network.v2 import qos_policy as _qos_policy
from openstack.network.v2 import qos_rule_type as _qos_rule_type
from openstack.network.v2 import rbac_policy as network_rbac
from openstack.network.v2 import router as _router
from openstack.network.v2 import security_group as _security_group
from openstack.network.v2 import security_group_rule as _security_group_rule
from openstack.network.v2 import segment as _segment
from openstack.network.v2 import service_profile as _service_profile
from openstack.network.v2 import trunk as _trunk
@ -132,246 +134,6 @@ def create_one_extension(attrs=None):
return extension
class FakeRouter:
"""Fake one or more routers."""
@staticmethod
def create_one_router(attrs=None):
"""Create a fake router.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with id, name, admin_state_up,
status, project_id
"""
attrs = attrs or {}
# Set default attributes.
router_attrs = {
'id': 'router-id-' + uuid.uuid4().hex,
'name': 'router-name-' + uuid.uuid4().hex,
'status': 'ACTIVE',
'admin_state_up': True,
'description': 'router-description-' + uuid.uuid4().hex,
'distributed': False,
'ha': False,
'project_id': 'project-id-' + uuid.uuid4().hex,
'routes': [],
'external_gateway_info': {},
'availability_zone_hints': [],
'availability_zones': [],
'tags': [],
'location': 'MUNCHMUNCHMUNCH',
}
# Overwrite default attributes.
router_attrs.update(attrs)
router = fakes.FakeResource(
info=copy.deepcopy(router_attrs), loaded=True
)
# Set attributes with special mapping in OpenStack SDK.
router.is_admin_state_up = router_attrs['admin_state_up']
router.is_distributed = router_attrs['distributed']
router.is_ha = router_attrs['ha']
return router
@staticmethod
def create_routers(attrs=None, count=2):
"""Create multiple fake routers.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of routers to fake
:return:
A list of FakeResource objects faking the routers
"""
routers = []
for i in range(0, count):
routers.append(FakeRouter.create_one_router(attrs))
return routers
@staticmethod
def get_routers(routers=None, count=2):
"""Get an iterable Mock object with a list of faked routers.
If routers list is provided, then initialize the Mock object with the
list. Otherwise create one.
:param List routers:
A list of FakeResource objects faking routers
:param int count:
The number of routers to fake
:return:
An iterable Mock object with side_effect set to a list of faked
routers
"""
if routers is None:
routers = FakeRouter.create_routers(count)
return mock.Mock(side_effect=routers)
class FakeSecurityGroup:
"""Fake one or more security groups."""
@staticmethod
def create_one_security_group(attrs=None):
"""Create a fake security group.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with id, name, etc.
"""
attrs = attrs or {}
# Set default attributes.
security_group_attrs = {
'id': 'security-group-id-' + uuid.uuid4().hex,
'name': 'security-group-name-' + uuid.uuid4().hex,
'description': 'security-group-description-' + uuid.uuid4().hex,
'stateful': True,
'project_id': 'project-id-' + uuid.uuid4().hex,
'security_group_rules': [],
'tags': [],
'location': 'MUNCHMUNCHMUNCH',
}
# Overwrite default attributes.
security_group_attrs.update(attrs)
security_group = fakes.FakeResource(
info=copy.deepcopy(security_group_attrs), loaded=True
)
return security_group
@staticmethod
def create_security_groups(attrs=None, count=2):
"""Create multiple fake security groups.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of security groups to fake
:return:
A list of FakeResource objects faking the security groups
"""
security_groups = []
for i in range(0, count):
security_groups.append(
FakeSecurityGroup.create_one_security_group(attrs)
)
return security_groups
@staticmethod
def get_security_groups(security_groups=None, count=2):
"""Get an iterable Mock object with a list of faked security groups.
If security groups list is provided, then initialize the Mock object
with the list. Otherwise create one.
:param List security_groups:
A list of FakeResource objects faking security groups
:param int count:
The number of security groups to fake
:return:
An iterable Mock object with side_effect set to a list of faked
security groups
"""
if security_groups is None:
security_groups = FakeSecurityGroup.create_security_groups(count)
return mock.Mock(side_effect=security_groups)
class FakeSecurityGroupRule:
"""Fake one or more security group rules."""
@staticmethod
def create_one_security_group_rule(attrs=None):
"""Create a fake security group rule.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with id, etc.
"""
attrs = attrs or {}
# Set default attributes.
security_group_rule_attrs = {
'description': 'security-group-rule-description-'
+ uuid.uuid4().hex,
'direction': 'ingress',
'ether_type': 'IPv4',
'id': 'security-group-rule-id-' + uuid.uuid4().hex,
'port_range_max': None,
'port_range_min': None,
'protocol': None,
'remote_group_id': None,
'remote_address_group_id': None,
'remote_ip_prefix': '0.0.0.0/0',
'security_group_id': 'security-group-id-' + uuid.uuid4().hex,
'project_id': 'project-id-' + uuid.uuid4().hex,
'location': 'MUNCHMUNCHMUNCH',
}
# Overwrite default attributes.
security_group_rule_attrs.update(attrs)
security_group_rule = fakes.FakeResource(
info=copy.deepcopy(security_group_rule_attrs), loaded=True
)
return security_group_rule
@staticmethod
def create_security_group_rules(attrs=None, count=2):
"""Create multiple fake security group rules.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of security group rules to fake
:return:
A list of FakeResource objects faking the security group rules
"""
security_group_rules = []
for i in range(0, count):
security_group_rules.append(
FakeSecurityGroupRule.create_one_security_group_rule(attrs)
)
return security_group_rules
@staticmethod
def get_security_group_rules(security_group_rules=None, count=2):
"""Get an iterable Mock with a list of faked security group rules.
If security group rules list is provided, then initialize the Mock
object with the list. Otherwise create one.
:param List security_group_rules:
A list of FakeResource objects faking security group rules
:param int count:
The number of security group rules to fake
:return:
An iterable Mock object with side_effect set to a list of faked
security group rules
"""
if security_group_rules is None:
security_group_rules = (
FakeSecurityGroupRule.create_security_group_rules(count)
)
return mock.Mock(side_effect=security_group_rules)
class FakeSubnet:
"""Fake one or more subnets."""
@ -1631,20 +1393,32 @@ def get_network_rbacs(rbac_policies=None, count=2):
def create_one_security_group(attrs=None):
"""Create a security group."""
"""Create a fake security group.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A SecurityGroup object, with id, name, etc.
"""
attrs = attrs or {}
# Set default attributes.
security_group_attrs = {
'name': 'security-group-name-' + uuid.uuid4().hex,
'id': 'security-group-id-' + uuid.uuid4().hex,
'project_id': 'project-id-' + uuid.uuid4().hex,
'name': 'security-group-name-' + uuid.uuid4().hex,
'description': 'security-group-description-' + uuid.uuid4().hex,
'stateful': True,
'project_id': 'project-id-' + uuid.uuid4().hex,
'security_group_rules': [],
'tags': [],
'location': 'MUNCHMUNCHMUNCH',
}
# Overwrite default attributes.
security_group_attrs.update(attrs)
security_group = _security_group.SecurityGroup(**security_group_attrs)
security_group.tenant_id = None # unset deprecated opts
return security_group
@ -1652,9 +1426,12 @@ def create_one_security_group(attrs=None):
def create_security_groups(attrs=None, count=2):
"""Create multiple fake security groups.
:param dict attrs: A dictionary with all attributes
:param int count: The number of security groups to fake
:return: A list of fake SecurityGroup objects
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of security groups to fake
:return:
A list of SecurityGroup objects faking the security groups
"""
security_groups = []
for i in range(0, count):
@ -1663,6 +1440,99 @@ def create_security_groups(attrs=None, count=2):
return security_groups
def get_security_groups(security_groups=None, count=2):
"""Get an iterable Mock object with a list of faked security groups.
If security groups list is provided, then initialize the Mock object
with the list. Otherwise create one.
:param List security_groups:
A list of SecurityGroup objects faking security groups
:param int count:
The number of security groups to fake
:return:
An iterable Mock object with side_effect set to a list of faked
security groups
"""
if security_groups is None:
security_groups = create_security_groups(count)
return mock.Mock(side_effect=security_groups)
def create_one_security_group_rule(attrs=None):
"""Create a fake security group rule.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with id, etc.
"""
attrs = attrs or {}
# Set default attributes.
security_group_rule_attrs = {
'description': 'security-group-rule-description-' + uuid.uuid4().hex,
'direction': 'ingress',
'ether_type': 'IPv4',
'id': 'security-group-rule-id-' + uuid.uuid4().hex,
'port_range_max': None,
'port_range_min': None,
'protocol': None,
'remote_group_id': None,
'remote_address_group_id': None,
'remote_ip_prefix': '0.0.0.0/0',
'security_group_id': 'security-group-id-' + uuid.uuid4().hex,
'project_id': 'project-id-' + uuid.uuid4().hex,
'location': 'MUNCHMUNCHMUNCH',
}
# Overwrite default attributes.
security_group_rule_attrs.update(attrs)
security_group_rule = _security_group_rule.SecurityGroupRule(
**security_group_rule_attrs
)
security_group_rule.tenant_id = None # unset deprecated opts
return security_group_rule
def create_security_group_rules(attrs=None, count=2):
"""Create multiple fake security group rules.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of security group rules to fake
:return:
A list of SecurityGroupRule objects faking the security group rules
"""
security_group_rules = []
for i in range(0, count):
security_group_rules.append(create_one_security_group_rule(attrs))
return security_group_rules
def get_security_group_rules(security_group_rules=None, count=2):
"""Get an iterable Mock with a list of faked security group rules.
If security group rules list is provided, then initialize the Mock
object with the list. Otherwise create one.
:param List security_group_rules:
A list of SecurityGroupRule objects faking security group rules
:param int count:
The number of security group rules to fake
:return:
An iterable Mock object with side_effect set to a list of faked
security group rules
"""
if security_group_rules is None:
security_group_rules = create_security_group_rules(count)
return mock.Mock(side_effect=security_group_rules)
def create_one_service_profile(attrs=None):
"""Create service profile."""
attrs = attrs or {}
@ -1902,6 +1772,80 @@ def create_qos_rule_types(attrs=None, count=2):
return qos_rule_types
def create_one_router(attrs=None):
"""Create a fake router.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A Router object, with id, name, admin_state_up,
status, project_id
"""
attrs = attrs or {}
# Set default attributes.
router_attrs = {
'id': 'router-id-' + uuid.uuid4().hex,
'name': 'router-name-' + uuid.uuid4().hex,
'status': 'ACTIVE',
'is_admin_state_up': True,
'description': 'router-description-' + uuid.uuid4().hex,
'distributed': False,
'ha': False,
'project_id': 'project-id-' + uuid.uuid4().hex,
'routes': [],
'external_gateway_info': {},
'availability_zone_hints': [],
'availability_zones': [],
'tags': [],
'location': 'MUNCHMUNCHMUNCH',
}
# Overwrite default attributes.
router_attrs.update(attrs)
router = _router.Router(**router_attrs)
router.tenant_id = None # unset deprecated opts
return router
def create_routers(attrs=None, count=2):
"""Create multiple fake routers.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of routers to fake
:return:
A list of Router objects faking the routers
"""
routers = []
for i in range(0, count):
routers.append(create_one_router(attrs))
return routers
def get_routers(routers=None, count=2):
"""Get an iterable Mock object with a list of faked routers.
If routers list is provided, then initialize the Mock object with the
list. Otherwise create one.
:param List routers:
A list of Router objects faking routers
:param int count:
The number of routers to fake
:return:
An iterable Mock object with side_effect set to a list of faked
routers
"""
if routers is None:
routers = create_routers(count)
return mock.Mock(side_effect=routers)
def create_one_local_ip(attrs=None):
"""Create a fake local ip.

View File

@ -414,7 +414,7 @@ class TestListFloatingIPNetwork(TestFloatingIPNetwork):
'id': 'fake_port_id',
}
)
fake_router = network_fakes.FakeRouter.create_one_router(
fake_router = network_fakes.create_one_router(
{
'id': 'fake_router_id',
}

View File

@ -24,8 +24,8 @@ class TestConntrackHelper(network_fakes.TestNetworkV2):
def setUp(self):
super().setUp()
self.router = network_fakes.FakeRouter.create_one_router()
self.network_client.find_router = mock.Mock(return_value=self.router)
self.router = network_fakes.create_one_router()
self.network_client.find_router.return_value = self.router
class TestCreateL3ConntrackHelper(TestConntrackHelper):

View File

@ -30,9 +30,7 @@ class TestNDPProxy(network_fakes.TestNetworkV2):
# Get a shortcut to the DomainManager Mock
self.domains_mock = self.identity_client.domains
self.router = network_fakes.FakeRouter.create_one_router(
{'id': 'fake-router-id'}
)
self.router = network_fakes.create_one_router({'id': 'fake-router-id'})
self.network_client.find_router = mock.Mock(return_value=self.router)
self.port = network_fakes.create_one_port()
self.network_client.find_port = mock.Mock(return_value=self.port)

View File

@ -70,7 +70,7 @@ class TestAddNetworkToAgent(TestNetworkAgent):
class TestAddRouterAgent(TestNetworkAgent):
_router = network_fakes.FakeRouter.create_one_router()
_router = network_fakes.create_one_router()
_agent = network_fakes.create_one_network_agent()
def setUp(self):
@ -219,30 +219,24 @@ class TestListNetworkAgent(TestNetworkAgent):
def setUp(self):
super().setUp()
self.network_client.agents = mock.Mock(
return_value=self.network_agents
self.network_client.agents.return_value = self.network_agents
self.network_client.routers_hosting_l3_agents.return_value = (
self.network_agents
)
_testagent = network_fakes.create_one_network_agent()
self.network_client.get_agent = mock.Mock(return_value=_testagent)
self.network_client.get_agent.return_value = _testagent
self.network_client.get_agent.return_value = _testagent
self._testnetwork = network_fakes.create_one_network()
self.network_client.find_network = mock.Mock(
return_value=self._testnetwork
)
self.network_client.network_hosting_dhcp_agents = mock.Mock(
return_value=self.network_agents
self.network_client.find_network.return_value = self._testnetwork
self.network_client.network_hosting_dhcp_agents.return_value = (
self.network_agents
)
self.network_client.get_agent = mock.Mock(return_value=_testagent)
self._testrouter = network_fakes.FakeRouter.create_one_router()
self.network_client.find_router = mock.Mock(
return_value=self._testrouter
)
self.network_client.routers_hosting_l3_agents = mock.Mock(
return_value=self.network_agents
)
self._testrouter = network_fakes.create_one_router()
self.network_client.find_router.return_value = self._testrouter
# Get the command object to test
self.cmd = network_agent.ListNetworkAgent(self.app, None)
@ -323,15 +317,11 @@ class TestListNetworkAgent(TestNetworkAgent):
]
verifylist = [('router', self._testrouter.id), ('long', False)]
attrs = {
self._testrouter,
}
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.network_client.routers_hosting_l3_agents.assert_called_once_with(
*attrs
self._testrouter
)
self.assertEqual(self.columns, columns)
@ -345,15 +335,11 @@ class TestListNetworkAgent(TestNetworkAgent):
]
verifylist = [('router', self._testrouter.id), ('long', True)]
attrs = {
self._testrouter,
}
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.network_client.routers_hosting_l3_agents.assert_called_once_with(
*attrs
self._testrouter
)
# Add a column 'HA State' and corresponding data.
@ -422,7 +408,7 @@ class TestRemoveNetworkFromAgent(TestNetworkAgent):
class TestRemoveRouterAgent(TestNetworkAgent):
_router = network_fakes.FakeRouter.create_one_router()
_router = network_fakes.create_one_router()
_agent = network_fakes.create_one_network_agent()
def setUp(self):

View File

@ -35,7 +35,7 @@ class TestNetworkRBAC(network_fakes.TestNetworkV2):
class TestCreateNetworkRBAC(TestNetworkRBAC):
network_object = network_fakes.create_one_network()
qos_object = network_fakes.create_one_qos_policy()
sg_object = network_fakes.FakeSecurityGroup.create_one_security_group()
sg_object = network_fakes.create_one_security_group()
as_object = network_fakes.create_one_address_scope()
snp_object = network_fakes.FakeSubnetPool.create_one_subnet_pool()
ag_object = network_fakes.create_one_address_group()

View File

@ -320,7 +320,7 @@ class TestCreatePort(TestPort):
self.assertCountEqual(self.data, data)
def test_create_with_security_group(self):
secgroup = network_fakes.FakeSecurityGroup.create_one_security_group()
secgroup = network_fakes.create_one_security_group()
self.network_client.find_security_group = mock.Mock(
return_value=secgroup
)
@ -391,8 +391,8 @@ class TestCreatePort(TestPort):
self.assertCountEqual(self.data, data)
def test_create_with_security_groups(self):
sg_1 = network_fakes.FakeSecurityGroup.create_one_security_group()
sg_2 = network_fakes.FakeSecurityGroup.create_one_security_group()
sg_1 = network_fakes.create_one_security_group()
sg_2 = network_fakes.create_one_security_group()
self.network_client.find_security_group = mock.Mock(
side_effect=[sg_1, sg_2]
)
@ -1325,7 +1325,7 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort):
super().setUp()
self.network_client.ports = mock.Mock(return_value=self._ports)
fake_router = network_fakes.FakeRouter.create_one_router(
fake_router = network_fakes.create_one_router(
{
'id': 'fake-router-id',
}
@ -2096,7 +2096,7 @@ class TestSetPort(TestPort):
self.assertIsNone(result)
def test_set_port_security_group(self):
sg = network_fakes.FakeSecurityGroup.create_one_security_group()
sg = network_fakes.create_one_security_group()
self.network_client.find_security_group = mock.Mock(return_value=sg)
arglist = [
'--security-group',
@ -2119,9 +2119,9 @@ class TestSetPort(TestPort):
self.assertIsNone(result)
def test_set_port_security_group_append(self):
sg_1 = network_fakes.FakeSecurityGroup.create_one_security_group()
sg_2 = network_fakes.FakeSecurityGroup.create_one_security_group()
sg_3 = network_fakes.FakeSecurityGroup.create_one_security_group()
sg_1 = network_fakes.create_one_security_group()
sg_2 = network_fakes.create_one_security_group()
sg_3 = network_fakes.create_one_security_group()
self.network_client.find_security_group = mock.Mock(
side_effect=[sg_2, sg_3]
)
@ -2172,8 +2172,8 @@ class TestSetPort(TestPort):
self.assertIsNone(result)
def test_set_port_security_group_replace(self):
sg1 = network_fakes.FakeSecurityGroup.create_one_security_group()
sg2 = network_fakes.FakeSecurityGroup.create_one_security_group()
sg1 = network_fakes.create_one_security_group()
sg2 = network_fakes.create_one_security_group()
_testport = network_fakes.create_one_port(
{'security_group_ids': [sg1.id]}
)
@ -2821,8 +2821,8 @@ class TestUnsetPort(TestPort):
)
def test_unset_security_group(self):
_fake_sg1 = network_fakes.FakeSecurityGroup.create_one_security_group()
_fake_sg2 = network_fakes.FakeSecurityGroup.create_one_security_group()
_fake_sg1 = network_fakes.create_one_security_group()
_fake_sg2 = network_fakes.create_one_security_group()
_fake_port = network_fakes.create_one_port(
{'security_group_ids': [_fake_sg1.id, _fake_sg2.id]}
)
@ -2849,8 +2849,8 @@ class TestUnsetPort(TestPort):
self.assertIsNone(result)
def test_unset_port_security_group_not_existent(self):
_fake_sg1 = network_fakes.FakeSecurityGroup.create_one_security_group()
_fake_sg2 = network_fakes.FakeSecurityGroup.create_one_security_group()
_fake_sg1 = network_fakes.create_one_security_group()
_fake_sg2 = network_fakes.create_one_security_group()
_fake_port = network_fakes.create_one_port(
{'security_group_ids': [_fake_sg1.id]}
)

View File

@ -34,9 +34,7 @@ class TestAddPortToRouter(TestRouter):
'''Add port to Router'''
_port = network_fakes.create_one_port()
_router = network_fakes.FakeRouter.create_one_router(
attrs={'port': _port.id}
)
_router = network_fakes.create_one_router(attrs={'port': _port.id})
def setUp(self):
super().setUp()
@ -84,9 +82,7 @@ class TestAddSubnetToRouter(TestRouter):
'''Add subnet to Router'''
_subnet = network_fakes.FakeSubnet.create_one_subnet()
_router = network_fakes.FakeRouter.create_one_router(
attrs={'subnet': _subnet.id}
)
_router = network_fakes.create_one_router(attrs={'subnet': _subnet.id})
def setUp(self):
super().setUp()
@ -129,38 +125,48 @@ class TestAddSubnetToRouter(TestRouter):
class TestCreateRouter(TestRouter):
# The new router created.
new_router = network_fakes.FakeRouter.create_one_router()
new_router = network_fakes.create_one_router()
_extensions = {'fake': network_fakes.create_one_extension()}
columns = (
'admin_state_up',
'availability_zone_hints',
'availability_zones',
'created_at',
'description',
'distributed',
'enable_ndp_proxy',
'external_gateway_info',
'flavor_id',
'ha',
'id',
'name',
'project_id',
'revision_number',
'routes',
'status',
'tags',
'updated_at',
)
data = (
router.AdminStateColumn(new_router.admin_state_up),
router.AdminStateColumn(new_router.is_admin_state_up),
format_columns.ListColumn(new_router.availability_zone_hints),
format_columns.ListColumn(new_router.availability_zones),
new_router.created_at,
new_router.description,
new_router.distributed,
new_router.is_distributed,
new_router.enable_ndp_proxy,
router.RouterInfoColumn(new_router.external_gateway_info),
new_router.ha,
new_router.flavor_id,
new_router.is_ha,
new_router.id,
new_router.name,
new_router.project_id,
new_router.revision_number,
router.RoutesColumn(new_router.routes),
new_router.status,
format_columns.ListColumn(new_router.tags),
new_router.updated_at,
)
def setUp(self):
@ -614,14 +620,14 @@ class TestCreateRouter(TestRouter):
class TestDeleteRouter(TestRouter):
# The routers to delete.
_routers = network_fakes.FakeRouter.create_routers(count=2)
_routers = network_fakes.create_routers(count=2)
def setUp(self):
super().setUp()
self.network_client.delete_router = mock.Mock(return_value=None)
self.network_client.find_router = network_fakes.FakeRouter.get_routers(
self.network_client.find_router = network_fakes.get_routers(
self._routers
)
@ -696,7 +702,7 @@ class TestDeleteRouter(TestRouter):
class TestListRouter(TestRouter):
# The routers going to be listed up.
routers = network_fakes.FakeRouter.create_routers(count=3)
routers = network_fakes.create_routers(count=3)
extensions = network_fakes.create_one_extension()
columns = (
@ -727,10 +733,10 @@ class TestListRouter(TestRouter):
r.id,
r.name,
r.status,
router.AdminStateColumn(r.admin_state_up),
router.AdminStateColumn(r.is_admin_state_up),
r.project_id,
r.distributed,
r.ha,
r.is_distributed,
r.is_ha,
)
)
@ -813,7 +819,7 @@ class TestListRouter(TestRouter):
self.assertCountEqual(self.data, list(data))
def test_router_list_no_ha_no_distributed(self):
_routers = network_fakes.FakeRouter.create_routers(
_routers = network_fakes.create_routers(
{'ha': None, 'distributed': None}, count=3
)
@ -1033,9 +1039,7 @@ class TestRemovePortFromRouter(TestRouter):
'''Remove port from a Router'''
_port = network_fakes.create_one_port()
_router = network_fakes.FakeRouter.create_one_router(
attrs={'port': _port.id}
)
_router = network_fakes.create_one_router(attrs={'port': _port.id})
def setUp(self):
super().setUp()
@ -1080,9 +1084,7 @@ class TestRemoveSubnetFromRouter(TestRouter):
'''Remove subnet from Router'''
_subnet = network_fakes.FakeSubnet.create_one_subnet()
_router = network_fakes.FakeRouter.create_one_router(
attrs={'subnet': _subnet.id}
)
_router = network_fakes.create_one_router(attrs={'subnet': _subnet.id})
def setUp(self):
super().setUp()
@ -1123,7 +1125,7 @@ class TestRemoveSubnetFromRouter(TestRouter):
class TestAddExtraRoutesToRouter(TestRouter):
_router = network_fakes.FakeRouter.create_one_router()
_router = network_fakes.create_one_router()
def setUp(self):
super().setUp()
@ -1212,7 +1214,7 @@ class TestAddExtraRoutesToRouter(TestRouter):
class TestRemoveExtraRoutesFromRouter(TestRouter):
_router = network_fakes.FakeRouter.create_one_router()
_router = network_fakes.create_one_router()
def setUp(self):
super().setUp()
@ -1307,7 +1309,7 @@ class TestSetRouter(TestRouter):
_subnet = network_fakes.FakeSubnet.create_one_subnet(
attrs={'network_id': _network.id}
)
_router = network_fakes.FakeRouter.create_one_router(
_router = network_fakes.create_one_router(
attrs={'routes': [_default_route], 'tags': ['green', 'red']}
)
_extensions = {'fake': network_fakes.create_one_extension()}
@ -1454,7 +1456,7 @@ class TestSetRouter(TestRouter):
self.assertIsNone(result)
def test_set_route_overwrite_route(self):
_testrouter = network_fakes.FakeRouter.create_one_router(
_testrouter = network_fakes.create_one_router(
{'routes': [{"destination": "10.0.0.2", "nexthop": "1.1.1.1"}]}
)
self.network_client.find_router = mock.Mock(return_value=_testrouter)
@ -1753,7 +1755,7 @@ class TestSetRouter(TestRouter):
self.network_client.find_qos_policy = mock.Mock(
return_value=qos_policy
)
router = network_fakes.FakeRouter.create_one_router()
router = network_fakes.create_one_router()
self.network_client.find_router = mock.Mock(return_value=router)
arglist = [
"--qos-policy",
@ -1775,7 +1777,7 @@ class TestSetRouter(TestRouter):
self.network_client.find_qos_policy = mock.Mock(
return_value=qos_policy
)
router = network_fakes.FakeRouter.create_one_router()
router = network_fakes.create_one_router()
self.network_client.find_router = mock.Mock(return_value=router)
arglist = [
"--no-qos-policy",
@ -1793,7 +1795,7 @@ class TestSetRouter(TestRouter):
class TestShowRouter(TestRouter):
# The router to set.
_router = network_fakes.FakeRouter.create_one_router()
_router = network_fakes.create_one_router()
_port = network_fakes.create_one_port(
{'device_owner': 'network:router_interface', 'device_id': _router.id}
)
@ -1813,33 +1815,43 @@ class TestShowRouter(TestRouter):
'admin_state_up',
'availability_zone_hints',
'availability_zones',
'created_at',
'description',
'distributed',
'enable_ndp_proxy',
'external_gateway_info',
'flavor_id',
'ha',
'id',
'interfaces_info',
'name',
'project_id',
'revision_number',
'routes',
'status',
'tags',
'updated_at',
)
data = (
router.AdminStateColumn(_router.admin_state_up),
router.AdminStateColumn(_router.is_admin_state_up),
format_columns.ListColumn(_router.availability_zone_hints),
format_columns.ListColumn(_router.availability_zones),
_router.created_at,
_router.description,
_router.distributed,
_router.is_distributed,
_router.enable_ndp_proxy,
router.RouterInfoColumn(_router.external_gateway_info),
_router.ha,
_router.flavor_id,
_router.is_ha,
_router.id,
router.RouterInfoColumn(_router.interfaces_info),
_router.name,
_router.project_id,
_router.revision_number,
router.RoutesColumn(_router.routes),
_router.status,
format_columns.ListColumn(_router.tags),
_router.updated_at,
)
def setUp(self):
@ -1884,7 +1896,7 @@ class TestShowRouter(TestRouter):
self.assertCountEqual(self.data, data)
def test_show_no_ha_no_distributed(self):
_router = network_fakes.FakeRouter.create_one_router(
_router = network_fakes.create_one_router(
{'ha': None, 'distributed': None}
)
@ -1905,7 +1917,7 @@ class TestShowRouter(TestRouter):
self.assertNotIn("is_ha", columns)
def test_show_no_extra_route_extension(self):
_router = network_fakes.FakeRouter.create_one_router({'routes': None})
_router = network_fakes.create_one_router({'routes': None})
arglist = [
_router.name,
@ -1929,7 +1941,7 @@ class TestUnsetRouter(TestRouter):
super().setUp()
self.fake_network = network_fakes.create_one_network()
self.fake_qos_policy = network_fakes.create_one_qos_policy()
self._testrouter = network_fakes.FakeRouter.create_one_router(
self._testrouter = network_fakes.create_one_router(
{
'routes': [
{
@ -2100,7 +2112,7 @@ class TestUnsetRouter(TestRouter):
self.network_client.find_qos_policy = mock.Mock(
return_value=qos_policy
)
router = network_fakes.FakeRouter.create_one_router()
router = network_fakes.create_one_router()
self.network_client.find_router = mock.Mock(return_value=router)
arglist = [
"--qos-policy",
@ -2120,7 +2132,7 @@ class TestUnsetRouter(TestRouter):
self.network_client.find_qos_policy = mock.Mock(
return_value=qos_policy
)
router = network_fakes.FakeRouter.create_one_router(
router = network_fakes.create_one_router(
{"external_gateway_info": {"network_id": "fake-id"}}
)
self.network_client.find_router = mock.Mock(return_value=router)
@ -2145,7 +2157,7 @@ class TestGatewayOps(TestRouter):
self._network = network_fakes.create_one_network()
self._networks.append(self._network)
self._router = network_fakes.FakeRouter.create_one_router(
self._router = network_fakes.create_one_router(
{
'external_gateway_info': {
'network_id': self._network.id,
@ -2189,16 +2201,21 @@ class TestCreateMultipleGateways(TestGatewayOps):
'admin_state_up',
'availability_zone_hints',
'availability_zones',
'created_at',
'description',
'distributed',
'enable_ndp_proxy',
'external_gateway_info',
'flavor_id',
'ha',
'id',
'name',
'project_id',
'revision_number',
'routes',
'status',
'tags',
'updated_at',
)
def setUp(self):
@ -2215,19 +2232,24 @@ class TestCreateMultipleGateways(TestGatewayOps):
)
self._data = (
router.AdminStateColumn(self._router.admin_state_up),
router.AdminStateColumn(self._router.is_admin_state_up),
format_columns.ListColumn(self._router.availability_zone_hints),
format_columns.ListColumn(self._router.availability_zones),
self._router.created_at,
self._router.description,
self._router.distributed,
self._router.is_distributed,
self._router.enable_ndp_proxy,
router.RouterInfoColumn(self._router.external_gateway_info),
self._router.ha,
self._router.flavor_id,
self._router.is_ha,
self._router.id,
self._router.name,
self._router.project_id,
self._router.revision_number,
router.RoutesColumn(self._router.routes),
self._router.status,
format_columns.ListColumn(self._router.tags),
self._router.updated_at,
)
self.cmd = router.CreateRouter(self.app, None)

View File

@ -36,28 +36,32 @@ class TestCreateSecurityGroupNetwork(TestSecurityGroupNetwork):
project = identity_fakes.FakeProject.create_one_project()
domain = identity_fakes.FakeDomain.create_one_domain()
# The security group to be created.
_security_group = (
network_fakes.FakeSecurityGroup.create_one_security_group()
)
_security_group = network_fakes.create_one_security_group()
columns = (
'created_at',
'description',
'id',
'name',
'project_id',
'revision_number',
'rules',
'stateful',
'tags',
'updated_at',
)
data = (
_security_group.created_at,
_security_group.description,
_security_group.id,
_security_group.name,
_security_group.project_id,
_security_group.revision_number,
security_group.NetworkSecurityGroupRulesColumn([]),
_security_group.stateful,
_security_group.tags,
_security_group.updated_at,
)
def setUp(self):
@ -163,7 +167,7 @@ class TestCreateSecurityGroupNetwork(TestSecurityGroupNetwork):
else:
self.assertFalse(self.network_client.set_tags.called)
self.assertEqual(self.columns, columns)
self.assertCountEqual(self.data, data)
self.assertEqual(self.data, data)
def test_create_with_tags(self):
self._test_create_with_tag(add_tags=True)
@ -174,7 +178,7 @@ class TestCreateSecurityGroupNetwork(TestSecurityGroupNetwork):
class TestDeleteSecurityGroupNetwork(TestSecurityGroupNetwork):
# The security groups to be deleted.
_security_groups = network_fakes.FakeSecurityGroup.create_security_groups()
_security_groups = network_fakes.create_security_groups()
def setUp(self):
super().setUp()
@ -184,9 +188,7 @@ class TestDeleteSecurityGroupNetwork(TestSecurityGroupNetwork):
)
self.network_client.find_security_group = (
network_fakes.FakeSecurityGroup.get_security_groups(
self._security_groups
)
network_fakes.get_security_groups(self._security_groups)
)
# Get the command object to test
@ -264,9 +266,7 @@ class TestDeleteSecurityGroupNetwork(TestSecurityGroupNetwork):
class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
# The security group to be listed.
_security_groups = network_fakes.FakeSecurityGroup.create_security_groups(
count=3
)
_security_groups = network_fakes.create_security_groups(count=3)
columns = (
'ID',
@ -412,10 +412,8 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
class TestSetSecurityGroupNetwork(TestSecurityGroupNetwork):
# The security group to be set.
_security_group = (
network_fakes.FakeSecurityGroup.create_one_security_group(
attrs={'tags': ['green', 'red']}
)
_security_group = network_fakes.create_one_security_group(
attrs={'tags': ['green', 'red']}
)
def setUp(self):
@ -515,37 +513,39 @@ class TestSetSecurityGroupNetwork(TestSecurityGroupNetwork):
class TestShowSecurityGroupNetwork(TestSecurityGroupNetwork):
# The security group rule to be shown with the group.
_security_group_rule = (
network_fakes.FakeSecurityGroupRule.create_one_security_group_rule()
)
_security_group_rule = network_fakes.create_one_security_group_rule()
# The security group to be shown.
_security_group = (
network_fakes.FakeSecurityGroup.create_one_security_group(
attrs={'security_group_rules': [_security_group_rule._info]}
)
_security_group = network_fakes.create_one_security_group(
attrs={'security_group_rules': [dict(_security_group_rule)]}
)
columns = (
'created_at',
'description',
'id',
'name',
'project_id',
'revision_number',
'rules',
'stateful',
'tags',
'updated_at',
)
data = (
_security_group.created_at,
_security_group.description,
_security_group.id,
_security_group.name,
_security_group.project_id,
_security_group.revision_number,
security_group.NetworkSecurityGroupRulesColumn(
[_security_group_rule._info]
[dict(_security_group_rule)]
),
_security_group.stateful,
_security_group.tags,
_security_group.updated_at,
)
def setUp(self):
@ -583,10 +583,8 @@ class TestShowSecurityGroupNetwork(TestSecurityGroupNetwork):
class TestUnsetSecurityGroupNetwork(TestSecurityGroupNetwork):
# The security group to be unset.
_security_group = (
network_fakes.FakeSecurityGroup.create_one_security_group(
attrs={'tags': ['green', 'red']}
)
_security_group = network_fakes.create_one_security_group(
attrs={'tags': ['green', 'red']}
)
def setUp(self):

View File

@ -40,14 +40,13 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
_security_group_rule = None
# The security group that will contain the rule created.
_security_group = (
network_fakes.FakeSecurityGroup.create_one_security_group()
)
_security_group = network_fakes.create_one_security_group()
# The address group to be used in security group rules
_address_group = network_fakes.create_one_address_group()
expected_columns = (
'created_at',
'description',
'direction',
'ether_type',
@ -59,21 +58,22 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
'remote_address_group_id',
'remote_group_id',
'remote_ip_prefix',
'revision_number',
'security_group_id',
'updated_at',
)
expected_data = None
def _setup_security_group_rule(self, attrs=None):
self._security_group_rule = (
network_fakes.FakeSecurityGroupRule.create_one_security_group_rule(
attrs
)
network_fakes.create_one_security_group_rule(attrs)
)
self.network_client.create_security_group_rule = mock.Mock(
return_value=self._security_group_rule
)
self.expected_data = (
self._security_group_rule.created_at,
self._security_group_rule.description,
self._security_group_rule.direction,
self._security_group_rule.ether_type,
@ -85,7 +85,9 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
self._security_group_rule.remote_address_group_id,
self._security_group_rule.remote_group_id,
self._security_group_rule.remote_ip_prefix,
self._security_group_rule.revision_number,
self._security_group_rule.security_group_id,
self._security_group_rule.updated_at,
)
def setUp(self):
@ -963,11 +965,7 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
class TestDeleteSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
# The security group rules to be deleted.
_security_group_rules = (
network_fakes.FakeSecurityGroupRule.create_security_group_rules(
count=2
)
)
_security_group_rules = network_fakes.create_security_group_rules(count=2)
def setUp(self):
super().setUp()
@ -977,9 +975,7 @@ class TestDeleteSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
)
self.network_client.find_security_group_rule = (
network_fakes.FakeSecurityGroupRule.get_security_group_rules(
self._security_group_rules
)
network_fakes.get_security_group_rules(self._security_group_rules)
)
# Get the command object to test
@ -1057,33 +1053,27 @@ class TestDeleteSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
class TestListSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
# The security group to hold the rules.
_security_group = (
network_fakes.FakeSecurityGroup.create_one_security_group()
)
_security_group = network_fakes.create_one_security_group()
# The security group rule to be listed.
_security_group_rule_tcp = (
network_fakes.FakeSecurityGroupRule.create_one_security_group_rule(
{
'protocol': 'tcp',
'port_range_max': 80,
'port_range_min': 80,
'security_group_id': _security_group.id,
}
)
_security_group_rule_tcp = network_fakes.create_one_security_group_rule(
{
'protocol': 'tcp',
'port_range_max': 80,
'port_range_min': 80,
'security_group_id': _security_group.id,
}
)
_security_group_rule_icmp = (
network_fakes.FakeSecurityGroupRule.create_one_security_group_rule(
{
'protocol': 'icmp',
'remote_ip_prefix': '10.0.2.0/24',
'security_group_id': _security_group.id,
}
)
_security_group_rule_icmp = network_fakes.create_one_security_group_rule(
{
'protocol': 'icmp',
'remote_ip_prefix': '10.0.2.0/24',
'security_group_id': _security_group.id,
}
)
_security_group.security_group_rules = [
_security_group_rule_tcp._info,
_security_group_rule_icmp._info,
dict(_security_group_rule_tcp),
dict(_security_group_rule_icmp),
]
_security_group_rules = [
_security_group_rule_tcp,
@ -1264,11 +1254,10 @@ class TestListSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
class TestShowSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
# The security group rule to be shown.
_security_group_rule = (
network_fakes.FakeSecurityGroupRule.create_one_security_group_rule()
)
_security_group_rule = network_fakes.create_one_security_group_rule()
columns = (
'created_at',
'description',
'direction',
'ether_type',
@ -1280,10 +1269,13 @@ class TestShowSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
'remote_address_group_id',
'remote_group_id',
'remote_ip_prefix',
'revision_number',
'security_group_id',
'updated_at',
)
data = (
_security_group_rule.created_at,
_security_group_rule.description,
_security_group_rule.direction,
_security_group_rule.ether_type,
@ -1295,7 +1287,9 @@ class TestShowSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
_security_group_rule.remote_address_group_id,
_security_group_rule.remote_group_id,
_security_group_rule.remote_ip_prefix,
_security_group_rule.revision_number,
_security_group_rule.security_group_id,
_security_group_rule.updated_at,
)
def setUp(self):