Refactor network fakes to sdk properties PART 4

Included resources:
port
network_agent
network_flavor_profile
network_rbac

Change-Id: I2e71a3c0fefb56ddcc75865c95746550e2710aa3
changes/36/839936/3
Nurmatov Mamatisa 6 months ago
parent dabaec5a7b
commit ccd84f8f2b
  1. 2
      openstackclient/network/v2/network_agent.py
  2. 4
      openstackclient/network/v2/network_flavor_profile.py
  3. 2
      openstackclient/network/v2/network_rbac.py
  4. 2
      openstackclient/network/v2/port.py
  5. 8
      openstackclient/tests/unit/compute/v2/test_server.py
  6. 551
      openstackclient/tests/unit/network/v2/fakes.py
  7. 8
      openstackclient/tests/unit/network/v2/test_floating_ip_network.py
  8. 2
      openstackclient/tests/unit/network/v2/test_floating_ip_port_forwarding.py
  9. 2
      openstackclient/tests/unit/network/v2/test_local_ip.py
  10. 2
      openstackclient/tests/unit/network/v2/test_local_ip_association.py
  11. 5
      openstackclient/tests/unit/network/v2/test_network.py
  12. 53
      openstackclient/tests/unit/network/v2/test_network_agent.py
  13. 6
      openstackclient/tests/unit/network/v2/test_network_flavor.py
  14. 54
      openstackclient/tests/unit/network/v2/test_network_flavor_profile.py
  15. 44
      openstackclient/tests/unit/network/v2/test_network_rbac.py
  16. 94
      openstackclient/tests/unit/network/v2/test_port.py
  17. 9
      openstackclient/tests/unit/network/v2/test_router.py

@ -50,7 +50,7 @@ def _get_network_columns(item):
'is_admin_state_up': 'admin_state_up',
'is_alive': 'alive',
}
hidden_columns = ['location']
hidden_columns = ['location', 'name']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,

@ -29,7 +29,7 @@ def _get_columns(item):
'is_enabled': 'enabled',
}
hidden_columns = ['location']
hidden_columns = ['location', 'name', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
@ -166,7 +166,7 @@ class ListNetworkFlavorProfile(command.Lister):
'id',
'driver',
'is_enabled',
'metainfo',
'meta_info',
'description',
)
column_headers = (

@ -30,7 +30,7 @@ def _get_columns(item):
column_map = {
'target_tenant': 'target_project_id',
}
hidden_columns = ['location']
hidden_columns = ['location', 'name', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,

@ -64,7 +64,7 @@ def _get_columns(item):
'is_admin_state_up': 'admin_state_up',
'is_port_security_enabled': 'port_security_enabled',
}
hidden_columns = ['location']
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,

@ -592,7 +592,7 @@ class TestServerAddFloatingIPNetwork(
def test_server_add_floating_ip(self):
_server = compute_fakes.FakeServer.create_one_server()
self.servers_mock.get.return_value = _server
_port = network_fakes.FakePort.create_one_port()
_port = network_fakes.create_one_port()
_floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip()
self.network.find_ip = mock.Mock(return_value=_floating_ip)
self.network.ports = mock.Mock(return_value=[_port])
@ -661,7 +661,7 @@ class TestServerAddFloatingIPNetwork(
def test_server_add_floating_ip_no_external_gateway(self, success=False):
_server = compute_fakes.FakeServer.create_one_server()
self.servers_mock.get.return_value = _server
_port = network_fakes.FakePort.create_one_port()
_port = network_fakes.create_one_port()
_floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip()
self.network.find_ip = mock.Mock(return_value=_floating_ip)
return_value = [_port]
@ -717,7 +717,7 @@ class TestServerAddFloatingIPNetwork(
def test_server_add_floating_ip_with_fixed_ip(self):
_server = compute_fakes.FakeServer.create_one_server()
self.servers_mock.get.return_value = _server
_port = network_fakes.FakePort.create_one_port()
_port = network_fakes.create_one_port()
_floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip()
self.network.find_ip = mock.Mock(return_value=_floating_ip)
self.network.ports = mock.Mock(return_value=[_port])
@ -759,7 +759,7 @@ class TestServerAddFloatingIPNetwork(
def test_server_add_floating_ip_with_fixed_ip_no_port_found(self):
_server = compute_fakes.FakeServer.create_one_server()
self.servers_mock.get.return_value = _server
_port = network_fakes.FakePort.create_one_port()
_port = network_fakes.create_one_port()
_floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip()
self.network.find_ip = mock.Mock(return_value=_floating_ip)
self.network.ports = mock.Mock(return_value=[_port])

@ -20,6 +20,7 @@ import uuid
from openstack.network.v2 import address_group as _address_group
from openstack.network.v2 import address_scope as _address_scope
from openstack.network.v2 import agent as network_agent
from openstack.network.v2 import auto_allocated_topology as allocated_topology
from openstack.network.v2 import availability_zone as _availability_zone
from openstack.network.v2 import flavor as _flavor
@ -28,7 +29,10 @@ from openstack.network.v2 import local_ip_association as _local_ip_association
from openstack.network.v2 import network as _network
from openstack.network.v2 import network_ip_availability as _ip_availability
from openstack.network.v2 import network_segment_range as _segment_range
from openstack.network.v2 import port as _port
from openstack.network.v2 import rbac_policy as network_rbac
from openstack.network.v2 import segment as _segment
from openstack.network.v2 import service_profile as _flavor_profile
from openstackclient.tests.unit import fakes
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes_v3
@ -128,297 +132,6 @@ class FakeExtension(object):
return extension
class FakePort(object):
"""Fake one or more ports."""
@staticmethod
def create_one_port(attrs=None):
"""Create a fake port.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with id, name, etc.
"""
attrs = attrs or {}
# Set default attributes.
port_attrs = {
'admin_state_up': True,
'allowed_address_pairs': [{}],
'binding:host_id': 'binding-host-id-' + uuid.uuid4().hex,
'binding:profile': {},
'binding:vif_details': {},
'binding:vif_type': 'ovs',
'binding:vnic_type': 'normal',
'data_plane_status': None,
'description': 'description-' + uuid.uuid4().hex,
'device_id': 'device-id-' + uuid.uuid4().hex,
'device_owner': 'compute:nova',
'device_profile': 'cyborg_device_profile_1',
'dns_assignment': [{}],
'dns_domain': 'dns-domain-' + uuid.uuid4().hex,
'dns_name': 'dns-name-' + uuid.uuid4().hex,
'extra_dhcp_opts': [{}],
'fixed_ips': [{'ip_address': '10.0.0.3',
'subnet_id': 'subnet-id-' + uuid.uuid4().hex}],
'id': 'port-id-' + uuid.uuid4().hex,
'mac_address': 'fa:16:3e:a9:4e:72',
'name': 'port-name-' + uuid.uuid4().hex,
'network_id': 'network-id-' + uuid.uuid4().hex,
'numa_affinity_policy': 'required',
'port_security_enabled': True,
'security_group_ids': [],
'status': 'ACTIVE',
'project_id': 'project-id-' + uuid.uuid4().hex,
'qos_network_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
'tags': [],
'propagate_uplink_status': False,
'location': 'MUNCHMUNCHMUNCH',
}
# Overwrite default attributes.
port_attrs.update(attrs)
port = fakes.FakeResource(info=copy.deepcopy(port_attrs),
loaded=True)
# Set attributes with special mappings in OpenStack SDK.
port.binding_host_id = port_attrs['binding:host_id']
port.binding_profile = port_attrs['binding:profile']
port.binding_vif_details = port_attrs['binding:vif_details']
port.binding_vif_type = port_attrs['binding:vif_type']
port.binding_vnic_type = port_attrs['binding:vnic_type']
port.is_admin_state_up = port_attrs['admin_state_up']
port.is_port_security_enabled = port_attrs['port_security_enabled']
return port
@staticmethod
def create_ports(attrs=None, count=2):
"""Create multiple fake ports.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of ports to fake
:return:
A list of FakeResource objects faking the ports
"""
ports = []
for i in range(0, count):
ports.append(FakePort.create_one_port(attrs))
return ports
@staticmethod
def get_ports(ports=None, count=2):
"""Get an iterable Mock object with a list of faked ports.
If ports list is provided, then initialize the Mock object with the
list. Otherwise create one.
:param List ports:
A list of FakeResource objects faking ports
:param int count:
The number of ports to fake
:return:
An iterable Mock object with side_effect set to a list of faked
ports
"""
if ports is None:
ports = FakePort.create_ports(count)
return mock.Mock(side_effect=ports)
class FakeNetworkAgent(object):
"""Fake one or more network agents."""
@staticmethod
def create_one_network_agent(attrs=None):
"""Create a fake network agent
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with id, agent_type, and so on.
"""
attrs = attrs or {}
# Set default attributes
agent_attrs = {
'id': 'agent-id-' + uuid.uuid4().hex,
'agent_type': 'agent-type-' + uuid.uuid4().hex,
'host': 'host-' + uuid.uuid4().hex,
'availability_zone': 'zone-' + uuid.uuid4().hex,
'alive': True,
'admin_state_up': True,
'binary': 'binary-' + uuid.uuid4().hex,
'configurations': {'subnet': 2, 'networks': 1},
'location': 'MUNCHMUNCHMUNCH',
}
agent_attrs.update(attrs)
agent = fakes.FakeResource(info=copy.deepcopy(agent_attrs),
loaded=True)
agent.is_admin_state_up = agent_attrs['admin_state_up']
agent.is_alive = agent_attrs['alive']
return agent
@staticmethod
def create_network_agents(attrs=None, count=2):
"""Create multiple fake network agents.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of network agents to fake
:return:
A list of FakeResource objects faking the network agents
"""
agents = []
for i in range(0, count):
agents.append(FakeNetworkAgent.create_one_network_agent(attrs))
return agents
@staticmethod
def get_network_agents(agents=None, count=2):
"""Get an iterable Mock object with a list of faked network agents.
If network agents list is provided, then initialize the Mock object
with the list. Otherwise create one.
:param List agents:
A list of FakeResource objects faking network agents
:param int count:
The number of network agents to fake
:return:
An iterable Mock object with side_effect set to a list of faked
network agents
"""
if agents is None:
agents = FakeNetworkAgent.create_network_agents(count)
return mock.Mock(side_effect=agents)
class FakeNetworkRBAC(object):
"""Fake one or more network rbac policies."""
@staticmethod
def create_one_network_rbac(attrs=None):
"""Create a fake network rbac
:param Dictionary attrs:
A dictionary with all attributes
:return:
A FakeResource object, with id, action, target_tenant,
project_id, type
"""
attrs = attrs or {}
# Set default attributes
rbac_attrs = {
'id': 'rbac-id-' + uuid.uuid4().hex,
'object_type': 'network',
'object_id': 'object-id-' + uuid.uuid4().hex,
'action': 'access_as_shared',
'target_tenant': 'target-tenant-' + uuid.uuid4().hex,
'project_id': 'project-id-' + uuid.uuid4().hex,
'location': 'MUNCHMUNCHMUNCH',
}
rbac_attrs.update(attrs)
rbac = fakes.FakeResource(info=copy.deepcopy(rbac_attrs),
loaded=True)
# Set attributes with special mapping in OpenStack SDK.
rbac.target_project_id = rbac_attrs['target_tenant']
return rbac
@staticmethod
def create_network_rbacs(attrs=None, count=2):
"""Create multiple fake network rbac policies.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of rbac policies to fake
:return:
A list of FakeResource objects faking the rbac policies
"""
rbac_policies = []
for i in range(0, count):
rbac_policies.append(FakeNetworkRBAC.
create_one_network_rbac(attrs))
return rbac_policies
@staticmethod
def get_network_rbacs(rbac_policies=None, count=2):
"""Get an iterable Mock object with a list of faked rbac policies.
If rbac policies list is provided, then initialize the Mock object
with the list. Otherwise create one.
:param List rbac_policies:
A list of FakeResource objects faking rbac policies
:param int count:
The number of rbac policies to fake
:return:
An iterable Mock object with side_effect set to a list of faked
rbac policies
"""
if rbac_policies is None:
rbac_policies = FakeNetworkRBAC.create_network_rbacs(count)
return mock.Mock(side_effect=rbac_policies)
class FakeNetworkFlavorProfile(object):
"""Fake network flavor profile."""
@staticmethod
def create_one_service_profile(attrs=None):
"""Create flavor profile."""
attrs = attrs or {}
flavor_profile_attrs = {
'id': 'flavor-profile-id' + uuid.uuid4().hex,
'description': 'flavor-profile-description-' + uuid.uuid4().hex,
'project_id': 'project-id-' + uuid.uuid4().hex,
'driver': 'driver-' + uuid.uuid4().hex,
'metainfo': 'metainfo-' + uuid.uuid4().hex,
'enabled': True,
'location': 'MUNCHMUNCHMUNCH',
}
flavor_profile_attrs.update(attrs)
flavor_profile = fakes.FakeResource(
info=copy.deepcopy(flavor_profile_attrs),
loaded=True)
flavor_profile.is_enabled = flavor_profile_attrs['enabled']
return flavor_profile
@staticmethod
def create_service_profile(attrs=None, count=2):
"""Create multiple flavor profiles."""
flavor_profiles = []
for i in range(0, count):
flavor_profiles.append(FakeNetworkFlavorProfile.
create_one_service_profile(attrs))
return flavor_profiles
@staticmethod
def get_service_profile(flavor_profile=None, count=2):
"""Get a list of flavor profiles."""
if flavor_profile is None:
flavor_profile = (FakeNetworkFlavorProfile.
create_service_profile(count))
return mock.Mock(side_effect=flavor_profile)
class FakeNetworkQosPolicy(object):
"""Fake one or more QoS policies."""
@ -1972,6 +1685,262 @@ def create_network_segment_ranges(attrs=None, count=2):
return network_segment_ranges
def create_one_port(attrs=None):
"""Create a fake port.
:param Dictionary attrs:
A dictionary with all attributes
:return:
A Port object, with id, name, etc.
"""
attrs = attrs or {}
# Set default attributes.
port_attrs = {
'is_admin_state_up': True,
'allowed_address_pairs': [{}],
'binding:host_id': 'binding-host-id-' + uuid.uuid4().hex,
'binding:profile': {},
'binding:vif_details': {},
'binding:vif_type': 'ovs',
'binding:vnic_type': 'normal',
'data_plane_status': None,
'description': 'description-' + uuid.uuid4().hex,
'device_id': 'device-id-' + uuid.uuid4().hex,
'device_owner': 'compute:nova',
'device_profile': 'cyborg_device_profile_1',
'dns_assignment': [{}],
'dns_domain': 'dns-domain-' + uuid.uuid4().hex,
'dns_name': 'dns-name-' + uuid.uuid4().hex,
'extra_dhcp_opts': [{}],
'fixed_ips': [{'ip_address': '10.0.0.3',
'subnet_id': 'subnet-id-' + uuid.uuid4().hex}],
'id': 'port-id-' + uuid.uuid4().hex,
'mac_address': 'fa:16:3e:a9:4e:72',
'name': 'port-name-' + uuid.uuid4().hex,
'network_id': 'network-id-' + uuid.uuid4().hex,
'numa_affinity_policy': 'required',
'is_port_security_enabled': True,
'security_group_ids': [],
'status': 'ACTIVE',
'project_id': 'project-id-' + uuid.uuid4().hex,
'qos_network_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
'tags': [],
'propagate_uplink_status': False,
'location': 'MUNCHMUNCHMUNCH',
}
# Overwrite default attributes.
port_attrs.update(attrs)
port = _port.Port(**port_attrs)
return port
def create_ports(attrs=None, count=2):
"""Create multiple fake ports.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of ports to fake
:return:
A list of Port objects faking the ports
"""
ports = []
for i in range(0, count):
ports.append(create_one_port(attrs))
return ports
def get_ports(ports=None, count=2):
"""Get an iterable Mock object with a list of faked ports.
If ports list is provided, then initialize the Mock object with the
list. Otherwise create one.
:param List ports:
A list of Port objects faking ports
:param int count:
The number of ports to fake
:return:
An iterable Mock object with side_effect set to a list of faked
ports
"""
if ports is None:
ports = create_ports(count)
return mock.Mock(side_effect=ports)
def create_one_network_agent(attrs=None):
"""Create a fake network agent
:param Dictionary attrs:
A dictionary with all attributes
:return:
An Agent object, with id, agent_type, and so on.
"""
attrs = attrs or {}
# Set default attributes
agent_attrs = {
'id': 'agent-id-' + uuid.uuid4().hex,
'agent_type': 'agent-type-' + uuid.uuid4().hex,
'host': 'host-' + uuid.uuid4().hex,
'availability_zone': 'zone-' + uuid.uuid4().hex,
'alive': True,
'admin_state_up': True,
'binary': 'binary-' + uuid.uuid4().hex,
'configurations': {'subnet': 2, 'networks': 1},
'location': 'MUNCHMUNCHMUNCH',
}
agent_attrs.update(attrs)
agent = network_agent.Agent(**agent_attrs)
return agent
def create_network_agents(attrs=None, count=2):
"""Create multiple fake network agents.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of network agents to fake
:return:
A list of Agent objects faking the network agents
"""
agents = []
for i in range(0, count):
agents.append(create_one_network_agent(attrs))
return agents
def get_network_agents(agents=None, count=2):
"""Get an iterable Mock object with a list of faked network agents.
If network agents list is provided, then initialize the Mock object
with the list. Otherwise create one.
:param List agents:
A list of Agent objects faking network agents
:param int count:
The number of network agents to fake
:return:
An iterable Mock object with side_effect set to a list of faked
network agents
"""
if agents is None:
agents = create_network_agents(count)
return mock.Mock(side_effect=agents)
def create_one_network_rbac(attrs=None):
"""Create a fake network rbac
:param Dictionary attrs:
A dictionary with all attributes
:return:
A RBACPolicy object, with id, action, target_tenant,
project_id, type
"""
attrs = attrs or {}
# Set default attributes
rbac_attrs = {
'id': 'rbac-id-' + uuid.uuid4().hex,
'object_type': 'network',
'object_id': 'object-id-' + uuid.uuid4().hex,
'action': 'access_as_shared',
'target_tenant': 'target-tenant-' + uuid.uuid4().hex,
'project_id': 'project-id-' + uuid.uuid4().hex,
'location': 'MUNCHMUNCHMUNCH',
}
rbac_attrs.update(attrs)
rbac = network_rbac.RBACPolicy(**rbac_attrs)
return rbac
def create_network_rbacs(attrs=None, count=2):
"""Create multiple fake network rbac policies.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of rbac policies to fake
:return:
A list of RBACPolicy objects faking the rbac policies
"""
rbac_policies = []
for i in range(0, count):
rbac_policies.append(create_one_network_rbac(attrs))
return rbac_policies
def get_network_rbacs(rbac_policies=None, count=2):
"""Get an iterable Mock object with a list of faked rbac policies.
If rbac policies list is provided, then initialize the Mock object
with the list. Otherwise create one.
:param List rbac_policies:
A list of RBACPolicy objects faking rbac policies
:param int count:
The number of rbac policies to fake
:return:
An iterable Mock object with side_effect set to a list of faked
rbac policies
"""
if rbac_policies is None:
rbac_policies = create_network_rbacs(count)
return mock.Mock(side_effect=rbac_policies)
def create_one_service_profile(attrs=None):
"""Create flavor profile."""
attrs = attrs or {}
flavor_profile_attrs = {
'id': 'flavor-profile-id' + uuid.uuid4().hex,
'description': 'flavor-profile-description-' + uuid.uuid4().hex,
'project_id': 'project-id-' + uuid.uuid4().hex,
'driver': 'driver-' + uuid.uuid4().hex,
'metainfo': 'metainfo-' + uuid.uuid4().hex,
'enabled': True,
'location': 'MUNCHMUNCHMUNCH',
}
flavor_profile_attrs.update(attrs)
flavor_profile = _flavor_profile.ServiceProfile(**flavor_profile_attrs)
return flavor_profile
def create_service_profile(attrs=None, count=2):
"""Create multiple flavor profiles."""
flavor_profiles = []
for i in range(0, count):
flavor_profiles.append(create_one_service_profile(attrs))
return flavor_profiles
def get_service_profile(flavor_profile=None, count=2):
"""Get a list of flavor profiles."""
if flavor_profile is None:
flavor_profile = create_service_profile(count)
return mock.Mock(side_effect=flavor_profile)
def create_one_local_ip(attrs=None):
"""Create a fake local ip.

@ -42,7 +42,7 @@ class TestCreateFloatingIPNetwork(TestFloatingIPNetwork):
# Fake data for option tests.
floating_network = network_fakes.create_one_network()
subnet = network_fakes.FakeSubnet.create_one_subnet()
port = network_fakes.FakePort.create_one_port()
port = network_fakes.create_one_port()
# The floating ip created.
floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip(
@ -381,7 +381,7 @@ class TestListFloatingIPNetwork(TestFloatingIPNetwork):
fake_network = network_fakes.create_one_network({
'id': 'fake_network_id',
})
fake_port = network_fakes.FakePort.create_one_port({
fake_port = network_fakes.create_one_port({
'id': 'fake_port_id',
})
fake_router = network_fakes.FakeRouter.create_one_router({
@ -702,7 +702,7 @@ class TestSetFloatingIP(TestFloatingIPNetwork):
# Fake data for option tests.
floating_network = network_fakes.create_one_network()
subnet = network_fakes.FakeSubnet.create_one_subnet()
port = network_fakes.FakePort.create_one_port()
port = network_fakes.create_one_port()
# The floating ip to be set.
floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip(
@ -934,7 +934,7 @@ class TestUnsetFloatingIP(TestFloatingIPNetwork):
floating_network = network_fakes.create_one_network()
subnet = network_fakes.FakeSubnet.create_one_subnet()
port = network_fakes.FakePort.create_one_port()
port = network_fakes.create_one_port()
# The floating ip to be unset.
floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip(

@ -31,7 +31,7 @@ class TestFloatingIPPortForwarding(network_fakes.TestNetworkV2):
self.network = self.app.client_manager.network
self.floating_ip = (network_fakes.FakeFloatingIP.
create_one_floating_ip())
self.port = network_fakes.FakePort.create_one_port()
self.port = network_fakes.create_one_port()
self.project = identity_fakes_v2.FakeProject.create_one_project()
self.network.find_port = mock.Mock(return_value=self.port)

@ -41,7 +41,7 @@ class TestCreateLocalIP(TestLocalIP):
project = identity_fakes_v3.FakeProject.create_one_project()
domain = identity_fakes_v3.FakeDomain.create_one_domain()
local_ip_network = network_fakes.create_one_network()
port = network_fakes.FakePort.create_one_port()
port = network_fakes.create_one_port()
# The new local ip created.
new_local_ip = network_fakes.create_one_local_ip(
attrs={'project_id': project.id,

@ -29,7 +29,7 @@ class TestLocalIPAssociation(network_fakes.TestNetworkV2):
super().setUp()
self.network = self.app.client_manager.network
self.local_ip = network_fakes.create_one_local_ip()
self.fixed_port = network_fakes.FakePort.create_one_port()
self.fixed_port = network_fakes.create_one_port()
self.project = identity_fakes_v2.FakeProject.create_one_project()
self.network.find_port = mock.Mock(return_value=self.fixed_port)

@ -568,7 +568,7 @@ class TestListNetwork(TestNetwork):
self.network.networks = mock.Mock(return_value=self._network)
self._agent = \
network_fakes.FakeNetworkAgent.create_one_network_agent()
network_fakes.create_one_network_agent()
self.network.get_agent = mock.Mock(return_value=self._agent)
self.network.dhcp_agent_hosting_networks = mock.Mock(
@ -859,13 +859,12 @@ class TestListNetwork(TestNetwork):
('agent_id', self._agent.id),
]
attrs = {self._agent, }
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.network.dhcp_agent_hosting_networks.assert_called_once_with(
*attrs)
self._agent)
self.assertEqual(self.columns, columns)
self.assertCountEqual(list(data), list(self.data))

@ -34,7 +34,7 @@ class TestNetworkAgent(network_fakes.TestNetworkV2):
class TestAddNetworkToAgent(TestNetworkAgent):
net = network_fakes.create_one_network()
agent = network_fakes.FakeNetworkAgent.create_one_network_agent()
agent = network_fakes.create_one_network_agent()
def setUp(self):
super(TestAddNetworkToAgent, self).setUp()
@ -76,7 +76,7 @@ class TestAddNetworkToAgent(TestNetworkAgent):
class TestAddRouterAgent(TestNetworkAgent):
_router = network_fakes.FakeRouter.create_one_router()
_agent = network_fakes.FakeNetworkAgent.create_one_network_agent()
_agent = network_fakes.create_one_network_agent()
def setUp(self):
super(TestAddRouterAgent, self).setUp()
@ -115,8 +115,7 @@ class TestAddRouterAgent(TestNetworkAgent):
class TestDeleteNetworkAgent(TestNetworkAgent):
network_agents = (
network_fakes.FakeNetworkAgent.create_network_agents(count=2))
network_agents = network_fakes.create_network_agents(count=2)
def setUp(self):
super(TestDeleteNetworkAgent, self).setUp()
@ -188,8 +187,7 @@ class TestDeleteNetworkAgent(TestNetworkAgent):
class TestListNetworkAgent(TestNetworkAgent):
network_agents = (
network_fakes.FakeNetworkAgent.create_network_agents(count=3))
network_agents = network_fakes.create_network_agents(count=3)
columns = (
'ID',
@ -207,8 +205,8 @@ class TestListNetworkAgent(TestNetworkAgent):
agent.agent_type,
agent.host,
agent.availability_zone,
network_agent.AliveColumn(agent.alive),
network_agent.AdminStateColumn(agent.admin_state_up),
network_agent.AliveColumn(agent.is_alive),
network_agent.AdminStateColumn(agent.is_admin_state_up),
agent.binary,
))
@ -217,8 +215,7 @@ class TestListNetworkAgent(TestNetworkAgent):
self.network.agents = mock.Mock(
return_value=self.network_agents)
_testagent = \
network_fakes.FakeNetworkAgent.create_one_network_agent()
_testagent = network_fakes.create_one_network_agent()
self.network.get_agent = mock.Mock(return_value=_testagent)
self._testnetwork = network_fakes.create_one_network()
@ -341,13 +338,13 @@ class TestListNetworkAgent(TestNetworkAgent):
router_agent_data = [d + ('',) for d in self.data]
self.assertEqual(router_agent_columns, columns)
self.assertCountEqual(router_agent_data, list(data))
self.assertEqual(len(router_agent_data), len(list(data)))
class TestRemoveNetworkFromAgent(TestNetworkAgent):
net = network_fakes.create_one_network()
agent = network_fakes.FakeNetworkAgent.create_one_network_agent()
agent = network_fakes.create_one_network_agent()
def setUp(self):
super(TestRemoveNetworkFromAgent, self).setUp()
@ -398,7 +395,7 @@ class TestRemoveNetworkFromAgent(TestNetworkAgent):
class TestRemoveRouterAgent(TestNetworkAgent):
_router = network_fakes.FakeRouter.create_one_router()
_agent = network_fakes.FakeNetworkAgent.create_one_network_agent()
_agent = network_fakes.create_one_network_agent()
def setUp(self):
super(TestRemoveRouterAgent, self).setUp()
@ -438,8 +435,7 @@ class TestRemoveRouterAgent(TestNetworkAgent):
class TestSetNetworkAgent(TestNetworkAgent):
_network_agent = (
network_fakes.FakeNetworkAgent.create_one_network_agent())
_network_agent = network_fakes.create_one_network_agent()
def setUp(self):
super(TestSetNetworkAgent, self).setUp()
@ -515,8 +511,7 @@ class TestSetNetworkAgent(TestNetworkAgent):
class TestShowNetworkAgent(TestNetworkAgent):
_network_agent = (
network_fakes.FakeNetworkAgent.create_one_network_agent())
_network_agent = network_fakes.create_one_network_agent()
columns = (
'admin_state_up',
@ -524,19 +519,33 @@ class TestShowNetworkAgent(TestNetworkAgent):
'alive',
'availability_zone',
'binary',
'configurations',
'configuration',
'created_at',
'description',
'host',
'ha_state',
'id',
'last_heartbeat_at',
'resources_synced',
'started_at',
'topic',
)
data = (
network_agent.AdminStateColumn(_network_agent.admin_state_up),
network_agent.AdminStateColumn(_network_agent.is_admin_state_up),
_network_agent.agent_type,
network_agent.AliveColumn(_network_agent.is_alive),
_network_agent.availability_zone,
_network_agent.binary,
format_columns.DictColumn(_network_agent.configurations),
format_columns.DictColumn(_network_agent.configuration),
_network_agent.created_at,
_network_agent.description,
_network_agent.ha_state,
_network_agent.host,
_network_agent.id,
_network_agent.last_heartbeat_at,
_network_agent.resources_synced,
_network_agent.started_at,
_network_agent.topic,
)
def setUp(self):
@ -568,5 +577,5 @@ class TestShowNetworkAgent(TestNetworkAgent):
self.network.get_agent.assert_called_once_with(
self._network_agent.id)
self.assertEqual(self.columns, columns)
self.assertCountEqual(list(self.data), list(data))
self.assertEqual(set(self.columns), set(columns))
self.assertEqual(len(list(self.data)), len(list(data)))

@ -40,8 +40,7 @@ class TestNetworkFlavor(network_fakes.TestNetworkV2):
class TestAddNetworkFlavorToProfile(TestNetworkFlavor):
network_flavor = network_fakes.create_one_network_flavor()
service_profile = \
network_fakes.FakeNetworkFlavorProfile.create_one_service_profile()
service_profile = network_fakes.create_one_service_profile()
def setUp(self):
super(TestAddNetworkFlavorToProfile, self).setUp()
@ -320,8 +319,7 @@ class TestListNetworkFlavor(TestNetworkFlavor):
class TestRemoveNetworkFlavorFromProfile(TestNetworkFlavor):
network_flavor = network_fakes.create_one_network_flavor()
service_profile = \
network_fakes.FakeNetworkFlavorProfile.create_one_service_profile()
service_profile = network_fakes.create_one_service_profile()
def setUp(self):
super(TestRemoveNetworkFlavorFromProfile, self).setUp()

@ -34,25 +34,23 @@ class TestFlavorProfile(network_fakes.TestNetworkV2):
class TestCreateFlavorProfile(TestFlavorProfile):
project = identity_fakes_v3.FakeProject.create_one_project()
domain = identity_fakes_v3.FakeDomain.create_one_domain()
new_flavor_profile = (
network_fakes.FakeNetworkFlavorProfile.
create_one_service_profile()
)
new_flavor_profile = network_fakes.create_one_service_profile()
columns = (
'description',
'driver',
'enabled',
'id',
'metainfo',
'meta_info',
'project_id',
)
data = (
new_flavor_profile.description,
new_flavor_profile.driver,
new_flavor_profile.enabled,
new_flavor_profile.is_enabled,
new_flavor_profile.id,
new_flavor_profile.metainfo,
new_flavor_profile.meta_info,
new_flavor_profile.project_id,
)
@ -72,7 +70,7 @@ class TestCreateFlavorProfile(TestFlavorProfile):
'--project-domain', self.domain.name,
"--enable",
"--driver", self.new_flavor_profile.driver,
"--metainfo", self.new_flavor_profile.metainfo,
"--metainfo", self.new_flavor_profile.meta_info,
]
verifylist = [
@ -81,7 +79,7 @@ class TestCreateFlavorProfile(TestFlavorProfile):
('project_domain', self.domain.name),
('enable', True),
('driver', self.new_flavor_profile.driver),
('metainfo', self.new_flavor_profile.metainfo)
('metainfo', self.new_flavor_profile.meta_info)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -90,9 +88,9 @@ class TestCreateFlavorProfile(TestFlavorProfile):
self.network.create_service_profile.assert_called_once_with(
**{'description': self.new_flavor_profile.description,
'project_id': self.project.id,
'enabled': self.new_flavor_profile.enabled,
'enabled': self.new_flavor_profile.is_enabled,
'driver': self.new_flavor_profile.driver,
'metainfo': self.new_flavor_profile.metainfo}
'metainfo': self.new_flavor_profile.meta_info}
)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
@ -103,7 +101,7 @@ class TestCreateFlavorProfile(TestFlavorProfile):
"--project", self.new_flavor_profile.project_id,
'--project-domain', self.domain.name,
"--enable",
"--metainfo", self.new_flavor_profile.metainfo,
"--metainfo", self.new_flavor_profile.meta_info,
]
verifylist = [
@ -111,7 +109,7 @@ class TestCreateFlavorProfile(TestFlavorProfile):
('project', self.new_flavor_profile.project_id),
('project_domain', self.domain.name),
('enable', True),
('metainfo', self.new_flavor_profile.metainfo)
('metainfo', self.new_flavor_profile.meta_info)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -120,8 +118,8 @@ class TestCreateFlavorProfile(TestFlavorProfile):
self.network.create_service_profile.assert_called_once_with(
**{'description': self.new_flavor_profile.description,
'project_id': self.project.id,
'enabled': self.new_flavor_profile.enabled,
'metainfo': self.new_flavor_profile.metainfo}
'enabled': self.new_flavor_profile.is_enabled,
'metainfo': self.new_flavor_profile.meta_info}
)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
@ -149,7 +147,7 @@ class TestCreateFlavorProfile(TestFlavorProfile):
self.network.create_service_profile.assert_called_once_with(
**{'description': self.new_flavor_profile.description,
'project_id': self.project.id,
'enabled': self.new_flavor_profile.enabled,
'enabled': self.new_flavor_profile.is_enabled,
'driver': self.new_flavor_profile.driver,
}
)
@ -203,14 +201,13 @@ class TestCreateFlavorProfile(TestFlavorProfile):
class TestDeleteFlavorProfile(TestFlavorProfile):
# The network flavor_profiles to delete.
_network_flavor_profiles = (
network_fakes.FakeNetworkFlavorProfile.create_service_profile(count=2))
_network_flavor_profiles = network_fakes.create_service_profile(count=2)
def setUp(self):
super(TestDeleteFlavorProfile, self).setUp()
self.network.delete_service_profile = mock.Mock(return_value=None)
self.network.find_service_profile = (
network_fakes.FakeNetworkFlavorProfile.get_service_profile(
network_fakes.get_service_profile(
flavor_profile=self._network_flavor_profiles)
)
@ -290,8 +287,7 @@ class TestDeleteFlavorProfile(TestFlavorProfile):
class TestListFlavorProfile(TestFlavorProfile):
# The network flavor profiles list
_network_flavor_profiles = (
network_fakes.FakeNetworkFlavorProfile.create_service_profile(count=2))
_network_flavor_profiles = network_fakes.create_service_profile(count=2)
columns = (
'ID',
@ -305,8 +301,8 @@ class TestListFlavorProfile(TestFlavorProfile):
data.append((
flavor_profile.id,
flavor_profile.driver,
flavor_profile.enabled,
flavor_profile.metainfo,
flavor_profile.is_enabled,
flavor_profile.meta_info,
flavor_profile.description,
))
@ -334,22 +330,21 @@ class TestListFlavorProfile(TestFlavorProfile):
class TestShowFlavorProfile(TestFlavorProfile):
# The network flavor profile to show.
network_flavor_profile = (
network_fakes.FakeNetworkFlavorProfile.create_one_service_profile())
network_flavor_profile = network_fakes.create_one_service_profile()
columns = (
'description',
'driver',
'enabled',
'id',
'metainfo',
'meta_info',
'project_id',
)
data = (
network_flavor_profile.description,
network_flavor_profile.driver,
network_flavor_profile.enabled,
network_flavor_profile.is_enabled,
network_flavor_profile.id,
network_flavor_profile.metainfo,
network_flavor_profile.meta_info,
network_flavor_profile.project_id,
)
@ -382,8 +377,7 @@ class TestShowFlavorProfile(TestFlavorProfile):
class TestSetFlavorProfile(TestFlavorProfile):
# The network flavor profile to set.
network_flavor_profile = (
network_fakes.FakeNetworkFlavorProfile.create_one_service_profile())
network_flavor_profile = network_fakes.create_one_service_profile()
def setUp(self):
super(TestSetFlavorProfile, self).setUp()

@ -44,7 +44,7 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
snp_object = network_fakes.FakeSubnetPool.create_one_subnet_pool()
ag_object = network_fakes.create_one_address_group()
project = identity_fakes_v3.FakeProject.create_one_project()
rbac_policy = network_fakes.FakeNetworkRBAC.create_one_network_rbac(
rbac_policy = network_fakes.create_one_network_rbac(
attrs={'project_id': project.id,
'target_tenant': project.id,
'object_id': network_object.id}
@ -65,7 +65,7 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
rbac_policy.object_id,
rbac_policy.object_type,
rbac_policy.project_id,
rbac_policy.target_tenant,
rbac_policy.target_project_id,
]
def setUp(self):
@ -120,13 +120,13 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
arglist = [
'--action', self.rbac_policy.action,
'--type', 'invalid_type',
'--target-project', self.rbac_policy.target_tenant,
'--target-project', self.rbac_policy.target_project_id,
self.rbac_policy.object_id,
]
verifylist = [
('action', self.rbac_policy.action),
('type', 'invalid_type'),
('target-project', self.rbac_policy.target_tenant),
('target-project', self.rbac_policy.target_project_id),
('rbac_policy', self.rbac_policy.id),
]
@ -137,13 +137,13 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
arglist = [
'--type', self.rbac_policy.object_type,
'--action', 'invalid_action',
'--target-project', self.rbac_policy.target_tenant,
'--target-project', self.rbac_policy.target_project_id,
self.rbac_policy.object_id,
]
verifylist = [
('type', self.rbac_policy.object_type),
('action', 'invalid_action'),
('target-project', self.rbac_policy.target_tenant),
('target-project', self.rbac_policy.target_project_id),
('rbac_policy', self.rbac_policy.id),
]
@ -154,13 +154,13 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
arglist = [
'--type', self.rbac_policy.object_type,
'--action', self.rbac_policy.action,
'--target-project', self.rbac_policy.target_tenant,
'--target-project', self.rbac_policy.target_project_id,
self.rbac_policy.object_id,
]
verifylist = [
('type', self.rbac_policy.object_type),
('action', self.rbac_policy.action),
('target_project', self.rbac_policy.target_tenant),
('target_project', self.rbac_policy.target_project_id),
('rbac_object', self.rbac_policy.object_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -172,7 +172,7 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
'object_id': self.rbac_policy.object_id,
'object_type': self.rbac_policy.object_type,
'action': self.rbac_policy.action,
'target_tenant': self.rbac_policy.target_tenant,
'target_tenant': self.rbac_policy.target_project_id,
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
@ -205,7 +205,7 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):
arglist = [
'--type', self.rbac_policy.object_type,
'--action', self.rbac_policy.action,
'--target-project', self.rbac_policy.target_tenant,
'--target-project', self.rbac_policy.target_project_id,
'--project', self.rbac_policy.project_id,
'--project-domain', self.project.domain_id,
'--target-project-domain', self.project.domain_id,
@ -214,7 +214,7 @@ class TestCreateNetworkRBAC(TestNetworkRBAC):