Remove munch
openstacksdk no longer uses this and we don't need to either. Instead, create fake version of the actual resources openstacksdk would return. This is more realistic and let's us remove munch entirely. Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Change-Id: I4549340611cf4da74d525e2adaf724c3cb749f57 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
3f80fc43a3
commit
6f2a8daf36
|
@ -12,8 +12,10 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import munch
|
||||
|
||||
from openstack import exceptions as os_exc
|
||||
from openstack.network.v2 import floating_ip as os_fip
|
||||
from openstack.network.v2 import subnet as os_subnet
|
||||
from unittest import mock
|
||||
|
||||
from oslo_config import cfg
|
||||
|
@ -48,9 +50,11 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.4',
|
||||
'port_id': None,
|
||||
'id': 'a2a62ea7-e3bf-40df-8c09-aa0c29876a6b'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.4',
|
||||
port_id=None,
|
||||
id='a2a62ea7-e3bf-40df-8c09-aa0c29876a6b',
|
||||
)
|
||||
os_net.ips.return_value = (ip for ip in [fip])
|
||||
project_id = mock.sentinel.project_id
|
||||
spec_type = 'LoadBalancer'
|
||||
|
@ -75,8 +79,10 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'port_id': None})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
port_id=None,
|
||||
)
|
||||
os_net.ips.return_value = (ip for ip in [fip])
|
||||
|
||||
project_id = mock.sentinel.project_id
|
||||
|
@ -94,8 +100,10 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.4',
|
||||
'port_id': 'ec29d641-fec4-4f67-928a-124a76b3a8e6'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.4',
|
||||
port_id='ec29d641-fec4-4f67-928a-124a76b3a8e6',
|
||||
)
|
||||
os_net.ips.return_value = (ip for ip in [fip])
|
||||
|
||||
project_id = mock.sentinel.project_id
|
||||
|
@ -131,10 +139,13 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
m_cfg.neutron_defaults.external_svc_net = public_net
|
||||
m_cfg.neutron_defaults.external_svc_subnet = None
|
||||
|
||||
os_net.get_subnet.return_value = munch.Munch(
|
||||
{'network_id': 'ec29d641-fec4-4f67-928a-124a76b3a8e6'})
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
os_net.get_subnet.return_value = os_subnet.Subnet(
|
||||
network_id='ec29d641-fec4-4f67-928a-124a76b3a8e6',
|
||||
)
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
os_net.create_ip.return_value = fip
|
||||
|
||||
project_id = mock.sentinel.project_id
|
||||
|
@ -160,10 +171,13 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
m_cfg.neutron_defaults.external_svc_subnet = (mock.sentinel
|
||||
.external_svc_subnet)
|
||||
|
||||
os_net.get_subnet.return_value = munch.Munch(
|
||||
{'network_id': 'ec29d641-fec4-4f67-928a-124a76b3a8e6'})
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
os_net.get_subnet.return_value = os_subnet.Subnet(
|
||||
network_id='ec29d641-fec4-4f67-928a-124a76b3a8e6',
|
||||
)
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
os_net.create_ip.return_value = fip
|
||||
|
||||
project_id = mock.sentinel.project_id
|
||||
|
@ -192,8 +206,10 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
cls = d_lb_public_ip.FloatingIpServicePubIPDriver
|
||||
m_driver = mock.Mock(spec=cls)
|
||||
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
|
||||
service_pub_ip_info = {
|
||||
'ip_id': fip.id,
|
||||
|
@ -208,8 +224,10 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
cls = d_lb_public_ip.FloatingIpServicePubIPDriver
|
||||
m_driver = mock.Mock(spec=cls)
|
||||
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
|
||||
service_pub_ip_info = {
|
||||
'ip_id': fip.id,
|
||||
|
@ -227,8 +245,10 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
os_net.delete_ip.side_effect = os_exc.SDKException
|
||||
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
|
||||
service_pub_ip_info = {
|
||||
'ip_id': fip.id,
|
||||
|
@ -244,8 +264,10 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
|
||||
self.useFixture(k_fix.MockNetworkClient()).client
|
||||
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
|
||||
service_pub_ip_info = {
|
||||
'ip_id': fip.id,
|
||||
|
@ -275,8 +297,10 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
os_net.update_floatingip.return_value = None
|
||||
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
|
||||
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
service_pub_ip_info = (obj_lbaas
|
||||
.LBaaSPubIp(ip_id=0,
|
||||
ip_addr=fip.floating_ip_address,
|
||||
|
@ -300,8 +324,10 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
os_net.update_ip.side_effect = os_exc.SDKException
|
||||
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
|
||||
service_pub_ip_info = {
|
||||
'ip_id': fip.id,
|
||||
|
@ -329,8 +355,10 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
os_net.update_floatingip.return_value = None
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
service_pub_ip_info = {
|
||||
'ip_id': 0,
|
||||
'ip_addr': fip.floating_ip_address,
|
||||
|
@ -347,8 +375,10 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
|
|||
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
os_net.update_ip.side_effect = os_exc.SDKException
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
|
||||
service_pub_ip_info = {
|
||||
'ip_id': fip.id,
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import munch
|
||||
from unittest import mock
|
||||
|
||||
from openstack import exceptions as os_exc
|
||||
|
@ -21,6 +20,7 @@ from openstack.load_balancer.v2 import listener as o_lis
|
|||
from openstack.load_balancer.v2 import load_balancer as o_lb
|
||||
from openstack.load_balancer.v2 import member as o_mem
|
||||
from openstack.load_balancer.v2 import pool as o_pool
|
||||
from openstack.network.v2 import port as os_port
|
||||
from oslo_config import cfg
|
||||
|
||||
from kuryr_kubernetes import constants as k_const
|
||||
|
@ -255,8 +255,9 @@ class TestLBaaSv2Driver(test_base.TestCase):
|
|||
os_net.security_group_rules.return_value = (x for x in [])
|
||||
cls = d_lbaasv2.LBaaSv2Driver
|
||||
m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
|
||||
m_driver._get_vip_port.return_value = munch.Munch({
|
||||
'security_group_ids': [mock.sentinel.sg_id]})
|
||||
m_driver._get_vip_port.return_value = os_port.Port(
|
||||
security_group_ids=[mock.sentinel.sg_id],
|
||||
)
|
||||
loadbalancer = {
|
||||
'name': 'TEST_NAME',
|
||||
'project_id': 'TEST_PROJECT',
|
||||
|
@ -418,8 +419,9 @@ class TestLBaaSv2Driver(test_base.TestCase):
|
|||
}
|
||||
resp = o_lb.LoadBalancer(id=loadbalancer_id, provider='haproxy')
|
||||
lbaas.create_load_balancer.return_value = resp
|
||||
m_driver._get_vip_port.return_value = munch.Munch(
|
||||
{'id': mock.sentinel.port_id})
|
||||
m_driver._get_vip_port.return_value = os_port.Port(
|
||||
id=mock.sentinel.port_id,
|
||||
)
|
||||
|
||||
ret = cls._create_loadbalancer(m_driver, loadbalancer)
|
||||
lbaas.create_load_balancer.assert_called_once_with(**req)
|
||||
|
@ -448,8 +450,9 @@ class TestLBaaSv2Driver(test_base.TestCase):
|
|||
}
|
||||
resp = o_lb.LoadBalancer(id=loadbalancer_id, provider='amphora')
|
||||
lbaas.create_load_balancer.return_value = resp
|
||||
m_driver._get_vip_port.return_value = munch.Munch(
|
||||
{'id': mock.sentinel.port_id})
|
||||
m_driver._get_vip_port.return_value = os_port.Port(
|
||||
id=mock.sentinel.port_id,
|
||||
)
|
||||
|
||||
ret = cls._create_loadbalancer(m_driver, loadbalancer)
|
||||
lbaas.create_load_balancer.assert_called_once_with(**req)
|
||||
|
@ -478,8 +481,9 @@ class TestLBaaSv2Driver(test_base.TestCase):
|
|||
}
|
||||
resp = o_lb.LoadBalancer(id=loadbalancer_id, provider='haproxy')
|
||||
lbaas.create_load_balancer.return_value = resp
|
||||
m_driver._get_vip_port.return_value = munch.Munch(
|
||||
{'id': mock.sentinel.port_id})
|
||||
m_driver._get_vip_port.return_value = os_port.Port(
|
||||
id=mock.sentinel.port_id,
|
||||
)
|
||||
|
||||
ret = cls._create_loadbalancer(m_driver, loadbalancer)
|
||||
lbaas.create_load_balancer.assert_called_once_with(**req)
|
||||
|
@ -501,8 +505,9 @@ class TestLBaaSv2Driver(test_base.TestCase):
|
|||
resp = iter([o_lb.LoadBalancer(id=loadbalancer_id, provider='haproxy',
|
||||
provisioning_status='ACTIVE')])
|
||||
lbaas.load_balancers.return_value = resp
|
||||
m_driver._get_vip_port.return_value = munch.Munch(
|
||||
{'id': mock.sentinel.port_id})
|
||||
m_driver._get_vip_port.return_value = os_port.Port(
|
||||
id=mock.sentinel.port_id,
|
||||
)
|
||||
|
||||
ret = cls._find_loadbalancer(m_driver, loadbalancer)
|
||||
lbaas.load_balancers.assert_called_once_with(
|
||||
|
@ -557,8 +562,9 @@ class TestLBaaSv2Driver(test_base.TestCase):
|
|||
resp = iter([o_lb.LoadBalancer(id=loadbalancer_id, provider='haproxy',
|
||||
provisioning_status='ERROR')])
|
||||
lbaas.load_balancers.return_value = resp
|
||||
m_driver._get_vip_port.return_value = munch.Munch(
|
||||
{'id': mock.sentinel.port_id})
|
||||
m_driver._get_vip_port.return_value = os_port.Port(
|
||||
id=mock.sentinel.port_id,
|
||||
)
|
||||
|
||||
ret = cls._find_loadbalancer(m_driver, loadbalancer)
|
||||
lbaas.load_balancers.assert_called_once_with(
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
|
||||
from unittest import mock
|
||||
|
||||
import munch
|
||||
from openstack import exceptions as os_exc
|
||||
from openstack.network.v2 import network as os_network
|
||||
from openstack.network.v2 import subnet as os_subnet
|
||||
from oslo_config import cfg as oslo_cfg
|
||||
|
||||
from kuryr_kubernetes.controller.drivers import namespace_subnet as subnet_drv
|
||||
|
@ -167,7 +168,7 @@ class TestNamespacePodSubnetDriver(test_base.TestCase):
|
|||
project_id = mock.sentinel.project_id
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
os_net.networks.return_value = iter([])
|
||||
net = munch.Munch({'id': mock.sentinel.net})
|
||||
net = os_network.Network(id=mock.sentinel.net)
|
||||
os_net.create_network.return_value = net
|
||||
|
||||
net_id_resp = cls.create_network(m_driver, namespace, project_id)
|
||||
|
@ -184,8 +185,11 @@ class TestNamespacePodSubnetDriver(test_base.TestCase):
|
|||
namespace = {'metadata': {'name': 'test', 'uid': ns_uid}}
|
||||
project_id = mock.sentinel.project_id
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
net = munch.Munch({'id': mock.sentinel.net, 'description': ns_uid,
|
||||
'name': 'test'})
|
||||
net = os_network.Network(
|
||||
id=mock.sentinel.net,
|
||||
description=ns_uid,
|
||||
name='test',
|
||||
)
|
||||
os_net.networks.return_value = iter([net])
|
||||
|
||||
net_id_resp = cls.create_network(m_driver, namespace, project_id)
|
||||
|
@ -202,8 +206,10 @@ class TestNamespacePodSubnetDriver(test_base.TestCase):
|
|||
namespace = {'metadata': {'name': 'test', 'uid': ns_uid}}
|
||||
project_id = mock.sentinel.project_id
|
||||
net_id = mock.sentinel.net_id
|
||||
subnet = munch.Munch({'id': mock.sentinel.subnet,
|
||||
'cidr': mock.sentinel.cidr})
|
||||
subnet = os_subnet.Subnet(
|
||||
id=mock.sentinel.subnet,
|
||||
cidr=mock.sentinel.cidr,
|
||||
)
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
os_net.subnets.return_value = iter([])
|
||||
os_net.create_subnet.return_value = subnet
|
||||
|
@ -224,8 +230,10 @@ class TestNamespacePodSubnetDriver(test_base.TestCase):
|
|||
namespace = {'metadata': {'name': 'test', 'uid': ns_uid}}
|
||||
project_id = mock.sentinel.project_id
|
||||
net_id = mock.sentinel.net_id
|
||||
subnet = munch.Munch({'id': mock.sentinel.subnet,
|
||||
'cidr': mock.sentinel.cidr})
|
||||
subnet = os_subnet.Subnet(
|
||||
id=mock.sentinel.subnet,
|
||||
cidr=mock.sentinel.cidr,
|
||||
)
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
os_net.subnets.return_value = iter([subnet])
|
||||
|
||||
|
|
|
@ -9,13 +9,15 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import eventlet
|
||||
import munch
|
||||
from unittest import mock
|
||||
|
||||
from kuryr.lib import constants as kl_const
|
||||
from kuryr.lib import exceptions as kl_exc
|
||||
from openstack import exceptions as os_exc
|
||||
from openstack.network.v2 import port as os_port
|
||||
from openstack.network.v2 import trunk as os_trunk
|
||||
from oslo_config import cfg as oslo_cfg
|
||||
|
||||
from kuryr_kubernetes import constants
|
||||
|
@ -43,7 +45,7 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
parent_port = mock.sentinel.parent_port
|
||||
trunk_id = mock.sentinel.trunk_id
|
||||
port_id = mock.sentinel.port_id
|
||||
port = munch.Munch({'id': port_id})
|
||||
port = os_port.Port(id=port_id)
|
||||
port_request = {'project_id': project_id,
|
||||
'name': mock.sentinel.name,
|
||||
'network_id': mock.sentinel.network_id,
|
||||
|
@ -95,7 +97,7 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
{'segmentation_id': 2,
|
||||
'port_id': '',
|
||||
'segmentation_type': 'vlan'}]
|
||||
port = munch.Munch({'id': mock.sentinel.id})
|
||||
port = os_port.Port(id=mock.sentinel.id)
|
||||
vif = mock.sentinel.vif
|
||||
|
||||
bulk_rq = [port_request for _ in range(len(subports_info))]
|
||||
|
@ -224,7 +226,7 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
{'segmentation_id': 2,
|
||||
'port_id': '',
|
||||
'segmentation_type': 'vlan'}]
|
||||
port = munch.Munch({'id': mock.sentinel.id})
|
||||
port = os_port.Port(id=mock.sentinel.id)
|
||||
|
||||
bulk_rq = [port_request for _ in range(len(subports_info))]
|
||||
|
||||
|
@ -271,7 +273,7 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
{'segmentation_id': 2,
|
||||
'port_id': '',
|
||||
'segmentation_type': 'vlan'}]
|
||||
port = munch.Munch({'id': mock.sentinel.id})
|
||||
port = os_port.Port(id=mock.sentinel.id)
|
||||
|
||||
bulk_rq = [port_request for _ in range(len(subports_info))]
|
||||
|
||||
|
@ -642,8 +644,8 @@ class TestNestedVlanPodVIFDriver(test_base.TestCase):
|
|||
trunk_id = mock.sentinel.trunk_id
|
||||
vlan_ids.add('100')
|
||||
|
||||
port = munch.Munch({'segmentation_id': '100'})
|
||||
trunk_obj = munch.Munch({'sub_ports': [port]})
|
||||
port = os_port.Port(segmentation_id='100')
|
||||
trunk_obj = os_trunk.Trunk(sub_ports=[port])
|
||||
os_net.get_trunk.return_value = trunk_obj
|
||||
self.assertEqual(vlan_ids,
|
||||
cls._get_in_use_vlan_ids_set(m_driver, trunk_id))
|
||||
|
|
|
@ -16,8 +16,8 @@ import eventlet
|
|||
from unittest import mock
|
||||
|
||||
from kuryr.lib import constants as kl_const
|
||||
import munch
|
||||
from openstack import exceptions as os_exc
|
||||
from openstack.network.v2 import port as os_port
|
||||
from oslo_config import cfg as oslo_cfg
|
||||
|
||||
from kuryr_kubernetes import constants
|
||||
|
@ -41,7 +41,7 @@ class NeutronPodVIFDriver(test_base.TestCase):
|
|||
project_id = mock.sentinel.project_id
|
||||
subnets = mock.sentinel.subnets
|
||||
security_groups = mock.sentinel.security_groups
|
||||
port = munch.Munch({'id': '910b1183-1f4a-450a-a298-0e80ad06ec8b'})
|
||||
port = os_port.Port(id='910b1183-1f4a-450a-a298-0e80ad06ec8b')
|
||||
port_request = {'fake_req': mock.sentinel.port_request}
|
||||
vif = mock.sentinel.vif
|
||||
vif_plugin = mock.sentinel.vif_plugin
|
||||
|
@ -74,7 +74,7 @@ class NeutronPodVIFDriver(test_base.TestCase):
|
|||
|
||||
port_request = mock.sentinel.port_request
|
||||
m_driver._get_port_request.return_value = port_request
|
||||
port = munch.Munch({'id': '910b1183-1f4a-450a-a298-0e80ad06ec8b'})
|
||||
port = os_port.Port(id='910b1183-1f4a-450a-a298-0e80ad06ec8b')
|
||||
vif_plugin = mock.sentinel.vif_plugin
|
||||
port.binding_vif_type = vif_plugin
|
||||
vif = mock.sentinel.vif
|
||||
|
@ -111,10 +111,10 @@ class NeutronPodVIFDriver(test_base.TestCase):
|
|||
port_request = mock.sentinel.port_request
|
||||
m_driver._get_port_request.return_value = port_request
|
||||
port_id = mock.sentinel.port_id
|
||||
port1 = munch.Munch({'id': port_id, 'binding_vif_type': 'unbound'})
|
||||
port1 = os_port.Port(id=port_id, binding_vif_type='unbound')
|
||||
vif_plugin = mock.sentinel.vif_plugin
|
||||
port2 = munch.Munch({'id': port_id, 'binding_vif_type': vif_plugin})
|
||||
port1_1 = munch.Munch({'id': port_id, 'binding_vif_type': vif_plugin})
|
||||
port2 = os_port.Port(id=port_id, binding_vif_type=vif_plugin)
|
||||
port1_1 = os_port.Port(id=port_id, binding_vif_type=vif_plugin)
|
||||
vif = mock.sentinel.vif
|
||||
bulk_rq = [port_request for _ in range(num_ports)]
|
||||
semaphore = mock.MagicMock(spec=eventlet.semaphore.Semaphore(20))
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
from unittest import mock
|
||||
|
||||
import munch
|
||||
from openstack import exceptions as os_exc
|
||||
from openstack.network.v2 import subnet as os_subnet
|
||||
from oslo_config import cfg
|
||||
|
||||
from kuryr_kubernetes.controller.drivers import node_subnets
|
||||
|
@ -252,7 +252,7 @@ class TestOpenShiftNodesSubnetsDriver(test_base.TestCase):
|
|||
driver = node_subnets.OpenShiftNodesSubnets()
|
||||
psub = '622c5fd4-804c-40e8-95ab-ecd1565ac8e2'
|
||||
m_net = mock.Mock()
|
||||
m_net.find_subnet.return_value = munch.Munch({'id': psub})
|
||||
m_net.find_subnet.return_value = os_subnet.Subnet(id=psub)
|
||||
m_get_net.return_value = m_net
|
||||
self.machine['spec']['providerSpec']['value']['primarySubnet'] = psub
|
||||
|
||||
|
@ -403,7 +403,7 @@ class TestOpenShiftNodesSubnetsDriver(test_base.TestCase):
|
|||
sname = 'single named subnet'
|
||||
subnet_id = '9bcf85c8-1f15-4e3d-8e1e-0e2270ffd2b9'
|
||||
m_net = mock.Mock()
|
||||
m_net.find_subnet.return_value = munch.Munch({'id': subnet_id})
|
||||
m_net.find_subnet.return_value = os_subnet.Subnet(id=subnet_id)
|
||||
m_get_net.return_value = m_net
|
||||
self.machine['spec']['providerSpec']['value']['primarySubnet'] = sname
|
||||
|
||||
|
|
|
@ -12,8 +12,9 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import munch
|
||||
|
||||
from openstack import exceptions as os_exc
|
||||
from openstack.network.v2 import floating_ip as os_fip
|
||||
from unittest import mock
|
||||
|
||||
from kuryr_kubernetes.controller.drivers import public_ip\
|
||||
|
@ -33,9 +34,11 @@ class TestFipPubIpDriver(test_base.TestCase):
|
|||
self.assertIsNone(fip_id)
|
||||
|
||||
def test_is_ip_available_ip_not_exist(self):
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.4',
|
||||
'port_id': None,
|
||||
'id': 'a2a62ea7-e3bf-40df-8c09-aa0c29876a6b'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.4',
|
||||
port_id=None,
|
||||
id='a2a62ea7-e3bf-40df-8c09-aa0c29876a6b',
|
||||
)
|
||||
self.os_net.ips.return_value = (ip for ip in [fip])
|
||||
|
||||
fip_ip_addr = '1.1.1.1'
|
||||
|
@ -50,16 +53,21 @@ class TestFipPubIpDriver(test_base.TestCase):
|
|||
self.assertIsNone(fip_id)
|
||||
|
||||
def test_is_ip_available_occupied_fip(self):
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.4',
|
||||
'port_id': 'ec29d641-fec4-4f67-928a-124a76b3a8e6'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.4',
|
||||
port_id='ec29d641-fec4-4f67-928a-124a76b3a8e6',
|
||||
)
|
||||
self.os_net.ips.return_value = (ip for ip in [fip])
|
||||
fip_ip_addr = '1.2.3.4'
|
||||
fip_id = self.driver.is_ip_available(fip_ip_addr)
|
||||
self.assertIsNone(fip_id)
|
||||
|
||||
def test_is_ip_available_ip_exist_and_available(self):
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.4', 'port_id': None,
|
||||
'id': 'a2a62ea7-e3bf-40df-8c09-aa0c29876a6b'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.4',
|
||||
port_id=None,
|
||||
id='a2a62ea7-e3bf-40df-8c09-aa0c29876a6b',
|
||||
)
|
||||
self.os_net.ips.return_value = (ip for ip in [fip])
|
||||
|
||||
fip_ip_addr = '1.2.3.4'
|
||||
|
@ -72,8 +80,10 @@ class TestFipPubIpDriver(test_base.TestCase):
|
|||
project_id = mock.sentinel.project_id
|
||||
description = mock.sentinel.description
|
||||
|
||||
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
|
||||
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
|
||||
fip = os_fip.FloatingIP(
|
||||
floating_ip_address='1.2.3.5',
|
||||
id='ec29d641-fec4-4f67-928a-124a76b3a888',
|
||||
)
|
||||
self.os_net.create_ip.return_value = fip
|
||||
|
||||
fip_id, fip_addr = self.driver.allocate_ip(pub_net_id, project_id,
|
||||
|
@ -121,8 +131,9 @@ class TestFipPubIpDriver(test_base.TestCase):
|
|||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
os_net.update_ip.side_effect = os_exc.ConflictException
|
||||
os_net.get_ip.return_value = munch.Munch({'id': res_id,
|
||||
'port_id': vip_port_id})
|
||||
os_net.get_ip.return_value = os_fip.FloatingIP(
|
||||
id=res_id, port_id=vip_port_id,
|
||||
)
|
||||
self.assertIsNone(driver.associate(res_id, vip_port_id))
|
||||
|
||||
def test_associate_conflict_incorrect(self):
|
||||
|
@ -132,8 +143,9 @@ class TestFipPubIpDriver(test_base.TestCase):
|
|||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
os_net.update_ip.side_effect = os_exc.ConflictException
|
||||
os_net.get_ip.return_value = munch.Munch({'id': res_id,
|
||||
'port_id': 'foo'})
|
||||
os_net.get_ip.return_value = os_fip.FloatingIP(
|
||||
id=res_id, port_id='foo',
|
||||
)
|
||||
self.assertRaises(os_exc.ConflictException, driver.associate, res_id,
|
||||
vip_port_id)
|
||||
|
||||
|
|
|
@ -20,8 +20,9 @@ from unittest import mock
|
|||
import uuid
|
||||
|
||||
import ddt
|
||||
import munch
|
||||
from openstack import exceptions as os_exc
|
||||
from openstack.network.v2 import network as os_network
|
||||
from openstack.network.v2 import port as os_port
|
||||
from oslo_config import cfg as oslo_cfg
|
||||
|
||||
from os_vif.objects import network as osv_network
|
||||
|
@ -85,10 +86,12 @@ class BaseVIFPool(test_base.TestCase):
|
|||
project_id = str(uuid.uuid4())
|
||||
subnet_id = str(uuid.uuid4())
|
||||
net_id = str(uuid.uuid4())
|
||||
_net = munch.Munch({'id': net_id,
|
||||
'name': None,
|
||||
'mtu': None,
|
||||
'provider_network_type': None})
|
||||
_net = os_network.Network(
|
||||
id=net_id,
|
||||
name=None,
|
||||
mtu=None,
|
||||
provider_network_type=None,
|
||||
)
|
||||
network = ovu.neutron_to_osvif_network(_net)
|
||||
subnets = {subnet_id: network}
|
||||
security_groups = [mock.sentinel.security_groups]
|
||||
|
@ -117,10 +120,12 @@ class BaseVIFPool(test_base.TestCase):
|
|||
project_id = str(uuid.uuid4())
|
||||
subnet_id = str(uuid.uuid4())
|
||||
net_id = str(uuid.uuid4())
|
||||
_net = munch.Munch({'id': net_id,
|
||||
'name': None,
|
||||
'mtu': None,
|
||||
'provider_network_type': None})
|
||||
_net = os_network.Network(
|
||||
id=net_id,
|
||||
name=None,
|
||||
mtu=None,
|
||||
provider_network_type=None,
|
||||
)
|
||||
network = ovu.neutron_to_osvif_network(_net)
|
||||
subnets = {subnet_id: network}
|
||||
security_groups = [mock.sentinel.security_groups]
|
||||
|
@ -299,10 +304,12 @@ class BaseVIFPool(test_base.TestCase):
|
|||
project_id = mock.sentinel.project_id
|
||||
security_groups = [mock.sentinel.security_groups]
|
||||
net_id = str(uuid.uuid4())
|
||||
_net = munch.Munch({'id': net_id,
|
||||
'name': None,
|
||||
'mtu': None,
|
||||
'provider_network_type': None})
|
||||
_net = os_network.Network(
|
||||
id=net_id,
|
||||
name=None,
|
||||
mtu=None,
|
||||
provider_network_type=None,
|
||||
)
|
||||
network = ovu.neutron_to_osvif_network(_net)
|
||||
vif = osv_vif.VIFOpenVSwitch(id='0fa0e837-d34e-4580-a6c4-04f5f607d93e',
|
||||
network=network)
|
||||
|
@ -363,7 +370,7 @@ class BaseVIFPool(test_base.TestCase):
|
|||
self.addCleanup(oslo_cfg.CONF.clear_override, 'resource_tags',
|
||||
group='neutron_defaults')
|
||||
|
||||
os_net.networks.return_value = [munch.Munch({'id': net_id})]
|
||||
os_net.networks.return_value = [os_network.Network(id=net_id)]
|
||||
|
||||
cls._cleanup_leftover_ports(m_driver)
|
||||
os_net.networks.assert_called()
|
||||
|
@ -410,7 +417,7 @@ class BaseVIFPool(test_base.TestCase):
|
|||
self.addCleanup(oslo_cfg.CONF.clear_override, 'resource_tags',
|
||||
group='neutron_defaults')
|
||||
|
||||
os_net.networks.return_value = [munch.Munch({'id': net_id})]
|
||||
os_net.networks.return_value = [os_network.Network(id=net_id)]
|
||||
|
||||
cls._cleanup_leftover_ports(m_driver)
|
||||
os_net.networks.assert_called()
|
||||
|
@ -433,7 +440,7 @@ class BaseVIFPool(test_base.TestCase):
|
|||
self.addCleanup(oslo_cfg.CONF.clear_override, 'resource_tags',
|
||||
group='neutron_defaults')
|
||||
|
||||
os_net.networks.return_value = [munch.Munch({'id': net_id})]
|
||||
os_net.networks.return_value = [os_network.Network(id=net_id)]
|
||||
|
||||
cls._cleanup_leftover_ports(m_driver)
|
||||
os_net.networks.assert_called()
|
||||
|
@ -637,8 +644,11 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
True,
|
||||
group='kubernetes')
|
||||
os_net.ports.return_value = [
|
||||
munch.Munch({'id': port_id,
|
||||
'security_group_ids': ['security_group_modified']})]
|
||||
os_port.Port(
|
||||
id=port_id,
|
||||
security_group_ids=['security_group_modified'],
|
||||
),
|
||||
]
|
||||
m_driver._get_pool_size.return_value = pool_length
|
||||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
@ -697,8 +707,11 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
10,
|
||||
group='vif_pool')
|
||||
os_net.ports.return_value = [
|
||||
munch.Munch({'id': port_id,
|
||||
'security_group_ids': ['security_group_modified']})]
|
||||
os_port.Port(
|
||||
id=port_id,
|
||||
security_group_ids=['security_group_modified'],
|
||||
),
|
||||
]
|
||||
m_driver._get_pool_size.return_value = pool_length
|
||||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
@ -729,8 +742,11 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
True,
|
||||
group='kubernetes')
|
||||
os_net.ports.return_value = [
|
||||
munch.Munch({'id': port_id,
|
||||
'security_group_ids': ['security_group_modified']})]
|
||||
os_port.Port(
|
||||
id=port_id,
|
||||
security_group_ids=['security_group_modified'],
|
||||
),
|
||||
]
|
||||
m_driver._get_pool_size.return_value = pool_length
|
||||
os_net.update_port.side_effect = os_exc.SDKException
|
||||
|
||||
|
@ -759,8 +775,11 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
5,
|
||||
group='vif_pool')
|
||||
os_net.ports.return_value = [
|
||||
munch.Munch({'id': port_id,
|
||||
'security_group_ids': ['security_group_modified']})]
|
||||
os_port.Port(
|
||||
id=port_id,
|
||||
security_group_ids=['security_group_modified'],
|
||||
),
|
||||
]
|
||||
m_driver._get_pool_size.return_value = pool_length
|
||||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
@ -786,8 +805,11 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
5,
|
||||
group='vif_pool')
|
||||
os_net.ports.return_value = [
|
||||
munch.Munch({'id': port_id,
|
||||
'security_group_ids': ['security_group_modified']})]
|
||||
os_port.Port(
|
||||
id=port_id,
|
||||
security_group_ids=['security_group_modified'],
|
||||
),
|
||||
]
|
||||
m_driver._get_pool_size.return_value = pool_length
|
||||
|
||||
cls._trigger_return_to_pool(m_driver)
|
||||
|
@ -822,10 +844,12 @@ class NeutronVIFPool(test_base.TestCase):
|
|||
|
||||
subnet_id = port.fixed_ips[0]['subnet_id']
|
||||
net_id = str(uuid.uuid4())
|
||||
_net = munch.Munch({'id': net_id,
|
||||
'name': None,
|
||||
'mtu': None,
|
||||
'provider_network_type': None})
|
||||
_net = os_network.Network(
|
||||
id=net_id,
|
||||
name=None,
|
||||
mtu=None,
|
||||
provider_network_type=None,
|
||||
)
|
||||
network = ovu.neutron_to_osvif_network(_net)
|
||||
subnet = {subnet_id: network}
|
||||
m_get_subnet.return_value = network
|
||||
|
@ -1138,8 +1162,11 @@ class NestedVIFPool(test_base.TestCase):
|
|||
True,
|
||||
group='kubernetes')
|
||||
os_net.ports.return_value = [
|
||||
munch.Munch({'id': port_id,
|
||||
'security_group_ids': ['security_group_modified']})]
|
||||
os_port.Port(
|
||||
id=port_id,
|
||||
security_group_ids=['security_group_modified'],
|
||||
),
|
||||
]
|
||||
m_driver._get_pool_size.return_value = pool_length
|
||||
m_driver._recovered_pools = True
|
||||
|
||||
|
@ -1413,10 +1440,12 @@ class NestedVIFPool(test_base.TestCase):
|
|||
a_subports = {port_id: port}
|
||||
subnet_id = port.fixed_ips[0]['subnet_id']
|
||||
net_id = str(uuid.uuid4())
|
||||
_net = munch.Munch({'id': net_id,
|
||||
'name': None,
|
||||
'mtu': None,
|
||||
'provider_network_type': None})
|
||||
_net = os_network.Network(
|
||||
id=net_id,
|
||||
name=None,
|
||||
mtu=None,
|
||||
provider_network_type=None,
|
||||
)
|
||||
network = ovu.neutron_to_osvif_network(_net)
|
||||
subnets = {subnet_id: {subnet_id: network}}
|
||||
m_driver._get_trunks_info.return_value = (p_ports, a_subports,
|
||||
|
@ -1462,10 +1491,12 @@ class NestedVIFPool(test_base.TestCase):
|
|||
a_subports = {port_id: port, port_to_delete_id: port_to_delete}
|
||||
subnet_id = port.fixed_ips[0]['subnet_id']
|
||||
net_id = str(uuid.uuid4())
|
||||
_net = munch.Munch({'id': net_id,
|
||||
'name': None,
|
||||
'mtu': None,
|
||||
'provider_network_type': None})
|
||||
_net = os_network.Network(
|
||||
id=net_id,
|
||||
name=None,
|
||||
mtu=None,
|
||||
provider_network_type=None,
|
||||
)
|
||||
network = ovu.neutron_to_osvif_network(_net)
|
||||
subnets = {subnet_id: {subnet_id: network}}
|
||||
m_driver._get_trunks_info.return_value = (p_ports, a_subports,
|
||||
|
@ -1507,10 +1538,12 @@ class NestedVIFPool(test_base.TestCase):
|
|||
a_subports = {port_id: port}
|
||||
subnet_id = port.fixed_ips[0]['subnet_id']
|
||||
net_id = str(uuid.uuid4())
|
||||
_net = munch.Munch({'id': net_id,
|
||||
'name': None,
|
||||
'mtu': None,
|
||||
'provider_network_type': None})
|
||||
_net = os_network.Network(
|
||||
id=net_id,
|
||||
name=None,
|
||||
mtu=None,
|
||||
provider_network_type=None,
|
||||
)
|
||||
network = ovu.neutron_to_osvif_network(_net)
|
||||
subnets = {subnet_id: {subnet_id: network}}
|
||||
m_driver._get_trunks_info.return_value = (p_ports, a_subports,
|
||||
|
@ -1570,10 +1603,12 @@ class NestedVIFPool(test_base.TestCase):
|
|||
a_subports = {port_id1: port1, port_id2: port2}
|
||||
subnet_id = port1.fixed_ips[0]['subnet_id']
|
||||
net_id = str(uuid.uuid4())
|
||||
_net = munch.Munch({'id': net_id,
|
||||
'name': None,
|
||||
'mtu': None,
|
||||
'provider_network_type': None})
|
||||
_net = os_network.Network(
|
||||
id=net_id,
|
||||
name=None,
|
||||
mtu=None,
|
||||
provider_network_type=None,
|
||||
)
|
||||
network = ovu.neutron_to_osvif_network(_net)
|
||||
subnets = {subnet_id: {subnet_id: network}}
|
||||
|
||||
|
@ -1621,10 +1656,12 @@ class NestedVIFPool(test_base.TestCase):
|
|||
a_subports = {port_id1: port1, port_id2: port2}
|
||||
subnet_id = port1.fixed_ips[0]['subnet_id']
|
||||
net_id = str(uuid.uuid4())
|
||||
_net = munch.Munch({'id': net_id,
|
||||
'name': None,
|
||||
'mtu': None,
|
||||
'provider_network_type': None})
|
||||
_net = os_network.Network(
|
||||
id=net_id,
|
||||
name=None,
|
||||
mtu=None,
|
||||
provider_network_type=None,
|
||||
)
|
||||
network = ovu.neutron_to_osvif_network(_net)
|
||||
subnets = {subnet_id: {subnet_id: network}}
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
|
||||
from unittest import mock
|
||||
|
||||
import munch
|
||||
from openstack.network.v2 import network as os_network
|
||||
from openstack.network.v2 import subnet as os_subnet
|
||||
from oslo_config import cfg as oslo_cfg
|
||||
|
||||
from kuryr_kubernetes.controller.drivers import base as drivers
|
||||
|
@ -252,8 +253,9 @@ class TestKuryrNetworkHandler(test_base.TestCase):
|
|||
m_get_svc.return_value = []
|
||||
net_mock = mock.MagicMock()
|
||||
net_id = '1612ffb1-ff7d-4590-bd9c-95aeb043705a'
|
||||
net_mock.networks.return_value = [munch.Munch({'id': net_id,
|
||||
'description': ''})]
|
||||
net_mock.networks.return_value = [
|
||||
os_network.Network(id=net_id, description=''),
|
||||
]
|
||||
m_get_net_client.return_value = net_mock
|
||||
self._handler.k8s.get.return_value = (
|
||||
{'metadata': {'name': 'test-namespace', 'uid': net_id}})
|
||||
|
@ -279,9 +281,10 @@ class TestKuryrNetworkHandler(test_base.TestCase):
|
|||
ns_id = '0b6d6f0b-4e44-4a1b-a711-71ab6c79bee8'
|
||||
subnet_id = 'a595fc4b-6885-48ff-b90c-d3f7aefd6d1a'
|
||||
net_mock = mock.MagicMock()
|
||||
net_mock.networks.return_value = [munch.Munch({'id': net_id,
|
||||
'description': ns_id})]
|
||||
net_mock.subnets.return_value = [munch.Munch({'id': subnet_id})]
|
||||
net_mock.networks.return_value = [
|
||||
os_network.Network(id=net_id, description=ns_id),
|
||||
]
|
||||
net_mock.subnets.return_value = [os_subnet.Subnet(id=subnet_id)]
|
||||
m_get_net_client.return_value = net_mock
|
||||
self._handler.k8s.get.return_value = (
|
||||
{'metadata': {'name': 'test-namespace', 'uid': ns_id}})
|
||||
|
@ -307,9 +310,10 @@ class TestKuryrNetworkHandler(test_base.TestCase):
|
|||
ns_id = '0b6d6f0b-4e44-4a1b-a711-71ab6c79bee8'
|
||||
subnet_id = 'a595fc4b-6885-48ff-b90c-d3f7aefd6d1a'
|
||||
net_mock = mock.MagicMock()
|
||||
net_mock.networks.return_value = [munch.Munch({'id': net_id,
|
||||
'description': ns_id})]
|
||||
net_mock.subnets.return_value = [munch.Munch({'id': subnet_id})]
|
||||
net_mock.networks.return_value = [
|
||||
os_network.Network(id=net_id, description=ns_id),
|
||||
]
|
||||
net_mock.subnets.return_value = [os_subnet.Subnet(id=subnet_id)]
|
||||
m_get_net_client.return_value = net_mock
|
||||
self._handler.k8s.get.return_value = (
|
||||
{'metadata': {'name': 'test-namespace', 'uid': net_id}})
|
||||
|
|
|
@ -11,10 +11,14 @@
|
|||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import munch
|
||||
|
||||
import prometheus_client
|
||||
from unittest import mock
|
||||
|
||||
from openstack.load_balancer.v2 import load_balancer as os_lb
|
||||
from openstack.load_balancer.v2 import pool as os_pool
|
||||
from openstack.network.v2 import subnet as os_subnet
|
||||
|
||||
from kuryr_kubernetes.controller.managers import prometheus_exporter
|
||||
from kuryr_kubernetes.tests import base
|
||||
from kuryr_kubernetes.tests.unit import kuryr_fixtures as k_fix
|
||||
|
@ -97,10 +101,16 @@ class TestControllerPrometheusExporter(base.TestCase):
|
|||
subnet_id = mock.sentinel.id
|
||||
subnet_name = 'ns/cluster-version-net'
|
||||
network_id = mock.sentinel.network_id
|
||||
subnets = [munch.Munch(
|
||||
{'id': subnet_id, 'name': subnet_name,
|
||||
'network_id': network_id, 'allocation_pools': [
|
||||
{'start': '10.128.70.2', 'end': '10.128.71.254'}]})]
|
||||
subnets = [
|
||||
os_subnet.Subnet(
|
||||
id=subnet_id,
|
||||
name=subnet_name,
|
||||
network_id=network_id,
|
||||
allocation_pools=[
|
||||
{'start': '10.128.70.2', 'end': '10.128.71.254'},
|
||||
],
|
||||
),
|
||||
]
|
||||
ports = [mock.MagicMock()]
|
||||
self.srv._os_net.subnets.return_value = subnets
|
||||
self.srv._os_net.ports.return_value = ports
|
||||
|
@ -123,13 +133,20 @@ class TestControllerPrometheusExporter(base.TestCase):
|
|||
}
|
||||
}
|
||||
}
|
||||
self.srv._os_lb.find_load_balancer.return_value = munch.Munch(
|
||||
{'id': lb_id, 'name': lb_name,
|
||||
'provisioning_status': lb_state, 'pools': [{'id': pool_id}]})
|
||||
self.srv._os_lb.pools.return_value = [munch.Munch(
|
||||
{'id': pool_id, 'name': pool_name,
|
||||
'loadbalancers': [{'id': lb_id}],
|
||||
'members': [{'id': mock.sentinel.id}]})]
|
||||
self.srv._os_lb.find_load_balancer.return_value = os_lb.LoadBalancer(
|
||||
id=lb_id,
|
||||
name=lb_name,
|
||||
provisioning_status=lb_state,
|
||||
pools=[{'id': pool_id}],
|
||||
)
|
||||
self.srv._os_lb.pools.return_value = [
|
||||
os_pool.Pool(
|
||||
id=pool_id,
|
||||
name=pool_name,
|
||||
loadbalancers=[{'id': lb_id}],
|
||||
members=[{'id': mock.sentinel.id}],
|
||||
),
|
||||
]
|
||||
|
||||
self.cls._record_lbs_metrics(self.srv)
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
from unittest import mock
|
||||
import uuid
|
||||
|
||||
import munch
|
||||
|
||||
from openstack.network.v2 import network as os_network
|
||||
from openstack.network.v2 import subnet as os_subnet
|
||||
from os_vif.objects import fixed_ip as osv_fixed_ip
|
||||
from os_vif.objects import network as osv_network
|
||||
from os_vif.objects import route as osv_route
|
||||
|
@ -40,12 +40,12 @@ class TestOSVIFUtils(test_base.TestCase):
|
|||
network_id = str(uuid.uuid4())
|
||||
network_name = 'test-net'
|
||||
network_mtu = 1500
|
||||
neutron_network = munch.Munch({
|
||||
'id': network_id,
|
||||
'name': network_name,
|
||||
'mtu': network_mtu,
|
||||
'provider_network_type': None
|
||||
})
|
||||
neutron_network = os_network.Network(
|
||||
id=network_id,
|
||||
name=network_name,
|
||||
mtu=network_mtu,
|
||||
provider_network_type=None,
|
||||
)
|
||||
|
||||
network = ovu.neutron_to_osvif_network(neutron_network)
|
||||
|
||||
|
@ -56,12 +56,12 @@ class TestOSVIFUtils(test_base.TestCase):
|
|||
def test_neutron_to_osvif_network_no_name(self):
|
||||
network_id = str(uuid.uuid4())
|
||||
network_mtu = 1500
|
||||
neutron_network = munch.Munch({
|
||||
'id': network_id,
|
||||
'name': None,
|
||||
'mtu': network_mtu,
|
||||
'provider_network_type': None
|
||||
})
|
||||
neutron_network = os_network.Network(
|
||||
id=network_id,
|
||||
name=None,
|
||||
mtu=network_mtu,
|
||||
provider_network_type=None,
|
||||
)
|
||||
|
||||
network = ovu.neutron_to_osvif_network(neutron_network)
|
||||
|
||||
|
@ -70,12 +70,12 @@ class TestOSVIFUtils(test_base.TestCase):
|
|||
def test_neutron_to_osvif_network_no_mtu(self):
|
||||
network_id = str(uuid.uuid4())
|
||||
network_name = 'test-net'
|
||||
neutron_network = munch.Munch({
|
||||
'id': network_id,
|
||||
'name': network_name,
|
||||
'mtu': None,
|
||||
'provider_network_type': None
|
||||
})
|
||||
neutron_network = os_network.Network(
|
||||
id=network_id,
|
||||
name=network_name,
|
||||
mtu=None,
|
||||
provider_network_type=None,
|
||||
)
|
||||
|
||||
network = ovu.neutron_to_osvif_network(neutron_network)
|
||||
|
||||
|
@ -86,16 +86,16 @@ class TestOSVIFUtils(test_base.TestCase):
|
|||
gateway = '1.1.1.1'
|
||||
cidr = '1.1.1.1/8'
|
||||
dns = ['2.2.2.2', '3.3.3.3']
|
||||
host_routes = mock.sentinel.host_routes
|
||||
host_routes = [mock.sentinel.host_route]
|
||||
route_list = osv_route.RouteList(objects=[
|
||||
osv_route.Route(cidr='4.4.4.4/8', gateway='5.5.5.5')])
|
||||
m_conv_routes.return_value = route_list
|
||||
neutron_subnet = munch.Munch({
|
||||
'cidr': cidr,
|
||||
'dns_nameservers': dns,
|
||||
'host_routes': host_routes,
|
||||
'gateway_ip': gateway,
|
||||
})
|
||||
neutron_subnet = os_subnet.Subnet(
|
||||
cidr=cidr,
|
||||
dns_nameservers=dns,
|
||||
host_routes=host_routes,
|
||||
gateway_ip=gateway,
|
||||
)
|
||||
|
||||
subnet = ovu.neutron_to_osvif_subnet(neutron_subnet)
|
||||
|
||||
|
@ -110,12 +110,12 @@ class TestOSVIFUtils(test_base.TestCase):
|
|||
cidr = '1.1.1.1/8'
|
||||
route_list = osv_route.RouteList()
|
||||
m_conv_routes.return_value = route_list
|
||||
neutron_subnet = munch.Munch({
|
||||
'cidr': cidr,
|
||||
'dns_nameservers': [],
|
||||
'host_routes': [],
|
||||
'gateway_ip': None
|
||||
})
|
||||
neutron_subnet = os_subnet.Subnet(
|
||||
cidr=cidr,
|
||||
dns_nameservers=[],
|
||||
host_routes=[],
|
||||
gateway_ip=None,
|
||||
)
|
||||
|
||||
subnet = ovu.neutron_to_osvif_subnet(neutron_subnet)
|
||||
|
||||
|
|
|
@ -11,11 +11,13 @@
|
|||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from unittest import mock
|
||||
import uuid
|
||||
|
||||
import munch
|
||||
from openstack import exceptions as os_exc
|
||||
from openstack.network.v2 import port as os_port
|
||||
from openstack.network.v2 import subnet as os_subnet
|
||||
from os_vif import objects
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import timeutils
|
||||
|
@ -80,7 +82,7 @@ class TestUtils(test_base.TestCase):
|
|||
subnet_id = mock.sentinel.subnet_id
|
||||
network_id = mock.sentinel.network_id
|
||||
|
||||
neutron_subnet = munch.Munch({'network_id': network_id})
|
||||
neutron_subnet = os_subnet.Subnet(**{'network_id': network_id})
|
||||
neutron_network = mock.sentinel.neutron_network
|
||||
|
||||
os_net.get_subnet.return_value = neutron_subnet
|
||||
|
@ -300,18 +302,22 @@ class TestUtils(test_base.TestCase):
|
|||
|
||||
def test_get_nodes_ips(self):
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
ip1 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.1',
|
||||
'subnet_id': 'foo'}],
|
||||
'trunk_details': True})
|
||||
ip2 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.2',
|
||||
'subnet_id': 'bar'}],
|
||||
'trunk_details': True})
|
||||
ip3 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.3',
|
||||
'subnet_id': 'baz'}],
|
||||
'trunk_details': None})
|
||||
ip4 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.4',
|
||||
'subnet_id': 'zab'}],
|
||||
'trunk_details': True})
|
||||
ip1 = os_port.Port(
|
||||
fixed_ips=[{'ip_address': '10.0.0.1', 'subnet_id': 'foo'}],
|
||||
trunk_details={'trunk_id': 'wow', 'sub_ports': []},
|
||||
)
|
||||
ip2 = os_port.Port(
|
||||
fixed_ips=[{'ip_address': '10.0.0.2', 'subnet_id': 'bar'}],
|
||||
trunk_details={'trunk_id': 'odd', 'sub_ports': []},
|
||||
)
|
||||
ip3 = os_port.Port(
|
||||
fixed_ips=[{'ip_address': '10.0.0.3', 'subnet_id': 'baz'}],
|
||||
trunk_details=None,
|
||||
)
|
||||
ip4 = os_port.Port(
|
||||
fixed_ips=[{'ip_address': '10.0.0.4', 'subnet_id': 'zab'}],
|
||||
trunk_details={'trunk_id': 'eek', 'sub_ports': []},
|
||||
)
|
||||
ports = (p for p in [ip1, ip2, ip3, ip4])
|
||||
|
||||
os_net.ports.return_value = ports
|
||||
|
@ -326,12 +332,14 @@ class TestUtils(test_base.TestCase):
|
|||
group='neutron_defaults')
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
ip1 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.1',
|
||||
'subnet_id': 'foo'}],
|
||||
'trunk_details': True})
|
||||
ip2 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.2',
|
||||
'subnet_id': 'bar'}],
|
||||
'trunk_details': False})
|
||||
ip1 = os_port.Port(
|
||||
fixed_ips=[{'ip_address': '10.0.0.1', 'subnet_id': 'foo'}],
|
||||
trunk_details={'trunk_id': 'wow', 'sub_ports': []},
|
||||
)
|
||||
ip2 = os_port.Port(
|
||||
fixed_ips=[{'ip_address': '10.0.0.2', 'subnet_id': 'bar'}],
|
||||
trunk_details=None,
|
||||
)
|
||||
ports = (p for p in [ip1, ip2])
|
||||
|
||||
os_net.ports.return_value = ports
|
||||
|
@ -342,7 +350,7 @@ class TestUtils(test_base.TestCase):
|
|||
def test_get_subnet_cidr(self):
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
subnet_id = mock.sentinel.subnet_id
|
||||
subnet = munch.Munch(cidr='10.0.0.0/24')
|
||||
subnet = os_subnet.Subnet(cidr='10.0.0.0/24')
|
||||
os_net.get_subnet.return_value = subnet
|
||||
|
||||
result = utils.get_subnet_cidr(subnet_id)
|
||||
|
@ -503,7 +511,7 @@ class TestUtils(test_base.TestCase):
|
|||
time1 = '2022-04-14T09:00:00Z'
|
||||
now = '2022-04-14T09:00:00Z'
|
||||
m_utcnow.return_value = timeutils.parse_isotime(now)
|
||||
port = munch.Munch({'updated_at': time1, 'tags': ['foo']})
|
||||
port = os_port.Port(updated_at=time1, tags=['foo'])
|
||||
m_net.ports.return_value = iter((port,))
|
||||
m_get_net.return_value = m_net
|
||||
|
||||
|
@ -526,7 +534,7 @@ class TestUtils(test_base.TestCase):
|
|||
time1 = '2022-04-14T09:00:00Z'
|
||||
now = '2022-04-14T09:16:00Z'
|
||||
m_utcnow.return_value = timeutils.parse_isotime(now)
|
||||
port = munch.Munch({'updated_at': time1, 'tags': []})
|
||||
port = os_port.Port(updated_at=time1, tags=[])
|
||||
m_net.ports.return_value = iter((port,))
|
||||
m_get_net.return_value = m_net
|
||||
|
||||
|
|
Loading…
Reference in New Issue