def _neutron_to_osvif_routes(neutron_routes): """Converts Neutron host_routes to os-vif RouteList. :param neutron_routes: list of routes as returned by neutron client's 'show_subnet' in 'host_routes' attribute :return: an os-vif RouteList object """ obj_list = [osv_route.Route(cidr=route['destination'], gateway=route['nexthop']) for route in neutron_routes] return osv_route.RouteList(objects=obj_list)
def _neutron_to_osvif_routes(neutron_routes): """Converts Neutron host_routes to os-vif RouteList. :param neutron_routes: list of routes as returned by neutron client's 'show_subnet' in 'host_routes' attribute :return: an os-vif RouteList object """ # NOTE(gryf): Nested attributes for OpenStackSDK objects are simple types, # like dicts and lists, that's why neutron_routes is a list of dicts. obj_list = [osv_route.Route(cidr=route['destination'], gateway=route['nexthop']) for route in neutron_routes] return osv_route.RouteList(objects=obj_list)
def test_neutron_to_osvif_subnet(self, m_conv_routes): 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 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 = { 'cidr': cidr, 'dns_nameservers': dns, 'host_routes': host_routes, 'gateway_ip': gateway, } subnet = ovu.neutron_to_osvif_subnet(neutron_subnet) self.assertEqual(cidr, str(subnet.cidr)) self.assertEqual(route_list, subnet.routes) self.assertEqual(set(dns), set([str(addr) for addr in subnet.dns])) self.assertEqual(gateway, str(subnet.gateway)) m_conv_routes.assert_called_once_with(host_routes)