def _setUp(self): super(FakeFullstackMachine, self)._setUp() if not self.neutron_port: self.neutron_port = self.safe_client.create_port( network_id=self.network_id, tenant_id=self.tenant_id, hostname=self.host_binding) self.neutron_port_id = self.neutron_port['id'] mac_address = self.neutron_port['mac_address'] self.port = self.useFixture( net_helpers.PortFixture.get(self.bridge, self.namespace, mac_address, self.neutron_port_id)).port self._ip = self.neutron_port['fixed_ips'][0]['ip_address'] subnet_id = self.neutron_port['fixed_ips'][0]['subnet_id'] subnet = self.safe_client.client.show_subnet(subnet_id) prefixlen = netaddr.IPNetwork(subnet['subnet']['cidr']).prefixlen self._ip_cidr = '%s/%s' % (self._ip, prefixlen) # TODO(amuller): Support DHCP self.port.addr.add(self.ip_cidr) self.gateway_ip = subnet['subnet']['gateway_ip'] if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def _setUp(self): super(FakeFullstackMachine, self)._setUp() if not self.neutron_port: self.neutron_port = self.safe_client.create_port( network_id=self.network_id, tenant_id=self.tenant_id, hostname=self.host_binding ) self.neutron_port_id = self.neutron_port["id"] mac_address = self.neutron_port["mac_address"] self.port = self.useFixture( net_helpers.PortFixture.get(self.bridge, self.namespace, mac_address, self.neutron_port_id) ).port self._ip = self.neutron_port["fixed_ips"][0]["ip_address"] subnet_id = self.neutron_port["fixed_ips"][0]["subnet_id"] subnet = self.safe_client.client.show_subnet(subnet_id) prefixlen = netaddr.IPNetwork(subnet["subnet"]["cidr"]).prefixlen self._ip_cidr = "%s/%s" % (self._ip, prefixlen) # TODO(amuller): Support DHCP self.port.addr.add(self.ip_cidr) self.gateway_ip = subnet["subnet"]["gateway_ip"] if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def _setUp(self): super(FakeFullstackMachine, self)._setUp() self.bridge = self.host.get_bridge(self.network_id) if not self.neutron_port: self.neutron_port = self.safe_client.create_port( network_id=self.network_id, tenant_id=self.tenant_id, hostname=self.host.hostname) mac_address = self.neutron_port['mac_address'] self.port = self.useFixture( net_helpers.PortFixture.get( self.bridge, self.namespace, mac_address, self.neutron_port['id'])).port self._ip = self.neutron_port['fixed_ips'][0]['ip_address'] subnet_id = self.neutron_port['fixed_ips'][0]['subnet_id'] subnet = self.safe_client.client.show_subnet(subnet_id) prefixlen = netaddr.IPNetwork(subnet['subnet']['cidr']).prefixlen self._ip_cidr = '%s/%s' % (self._ip, prefixlen) # TODO(amuller): Support DHCP self.port.addr.add(self.ip_cidr) self.gateway_ip = subnet['subnet']['gateway_ip'] if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def _configure_static_ipaddress(self): self.port.addr.add(self.ip_cidr) if self.gateway_ip: net = netaddr.IPNetwork(self.ip_cidr) gateway_ip = netaddr.IPAddress(self.gateway_ip) if gateway_ip in net: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def _setUp(self): super(FakeMachine, self)._setUp() self.port = self.useFixture(net_helpers.PortFixture.get(self.bridge, self.namespace)).port self.port.addr.add(self._ip_cidr) if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def _setUp(self): super(FakeMachine, self)._setUp() self.port = self.useFixture( net_helpers.PortFixture.get(self.bridge, self.namespace)).port self.port.addr.add(self._ip_cidr) if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def _setUp(self): ns_fixture = self.useFixture(net_helpers.NamespaceFixture()) self.namespace = ns_fixture.name self.port = self.useFixture( net_helpers.PortFixture.get(self.bridge, self.namespace)).port self.port.addr.add(self._ip_cidr) if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def _setUp(self): ns_fixture = self.useFixture( net_helpers.NamespaceFixture()) self.namespace = ns_fixture.name self.port = self.useFixture( net_helpers.PortFixture.get(self.bridge, self.namespace)).port self.port.addr.add(self._ip_cidr) if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def test_access_to_metadata_proxy(self): """Test access to the l3-agent metadata proxy. The test creates: * A l3-agent metadata service: * A router (which creates a metadata proxy in the router namespace), * A fake metadata server * A "client" namespace (simulating a vm) with a port on router internal subnet. The test queries from the "client" namespace the metadata proxy on http://169.254.169.254 and asserts that the metadata proxy added the X-Forwarded-For and X-Neutron-Router-Id headers to the request and forwarded the http request to the fake metadata server and the response to the "client" namespace. """ router_info = self.generate_router_info(enable_ha=False) router = self.manage_router(self.agent, router_info) self._create_metadata_fake_server(webob.exc.HTTPOk.code) # Create and configure client namespace client_ns = self._create_namespace() router_ip_cidr = self._port_first_ip_cidr(router.internal_ports[0]) ip_cidr = net_helpers.increment_ip_cidr(router_ip_cidr) br_int = get_ovs_bridge(self.agent.conf.ovs_integration_bridge) # FIXME(cbrandily): temporary, will be replaced by a fake machine port = self.useFixture( net_helpers.OVSPortFixture(br_int, client_ns.namespace)).port port.addr.add(ip_cidr) net_helpers.set_namespace_gateway(port, router_ip_cidr.partition('/')[0]) # Query metadata proxy url = 'http://%(host)s:%(port)s' % { 'host': dhcp.METADATA_DEFAULT_IP, 'port': dhcp.METADATA_PORT } cmd = 'curl', '--max-time', METADATA_REQUEST_TIMEOUT, '-D-', url try: raw_headers = client_ns.netns.execute(cmd) except RuntimeError: self.fail('metadata proxy unreachable on %s before timeout' % url) # Check status code firstline = raw_headers.splitlines()[0] self.assertIn(str(webob.exc.HTTPOk.code), firstline.split())
def _configure_ipaddress(self, fixed_ip): if netaddr.IPAddress(fixed_ip["ip_address"]).version == constants.IP_VERSION_6: # v6Address/default_route is auto-configured. self._ipv6 = fixed_ip["ip_address"] else: self._ip = fixed_ip["ip_address"] subnet_id = fixed_ip["subnet_id"] subnet = self.safe_client.client.show_subnet(subnet_id) prefixlen = netaddr.IPNetwork(subnet["subnet"]["cidr"]).prefixlen self._ip_cidr = "%s/%s" % (self._ip, prefixlen) # TODO(amuller): Support DHCP self.port.addr.add(self.ip_cidr) self.gateway_ip = subnet["subnet"]["gateway_ip"] if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def test_access_to_metadata_proxy(self): """Test access to the l3-agent metadata proxy. The test creates: * A l3-agent metadata service: * A router (which creates a metadata proxy in the router namespace), * A fake metadata server * A "client" namespace (simulating a vm) with a port on router internal subnet. The test queries from the "client" namespace the metadata proxy on http://169.254.169.254 and asserts that the metadata proxy added the X-Forwarded-For and X-Neutron-Router-Id headers to the request and forwarded the http request to the fake metadata server and the response to the "client" namespace. """ router_info = self.generate_router_info(enable_ha=False) router = self.manage_router(self.agent, router_info) self._create_metadata_fake_server(webob.exc.HTTPOk.code) # Create and configure client namespace client_ns = self._create_namespace() router_ip_cidr = self._port_first_ip_cidr(router.internal_ports[0]) ip_cidr = net_helpers.increment_ip_cidr(router_ip_cidr) br_int = get_ovs_bridge(self.agent.conf.ovs_integration_bridge) # FIXME(cbrandily): temporary, will be replaced by a fake machine port = self.useFixture( net_helpers.OVSPortFixture(br_int, client_ns.namespace)).port port.addr.add(ip_cidr) net_helpers.set_namespace_gateway(port, router_ip_cidr.partition('/')[0]) # Query metadata proxy url = 'http://%(host)s:%(port)s' % {'host': dhcp.METADATA_DEFAULT_IP, 'port': dhcp.METADATA_PORT} cmd = 'curl', '--max-time', METADATA_REQUEST_TIMEOUT, '-D-', url try: raw_headers = client_ns.netns.execute(cmd) except RuntimeError: self.fail('metadata proxy unreachable on %s before timeout' % url) # Check status code firstline = raw_headers.splitlines()[0] self.assertIn(str(webob.exc.HTTPOk.code), firstline.split())
def _configure_ipaddress(self, fixed_ip): if (netaddr.IPAddress(fixed_ip['ip_address']).version == constants.IP_VERSION_6): # v6Address/default_route is auto-configured. self._ipv6 = fixed_ip['ip_address'] else: self._ip = fixed_ip['ip_address'] subnet_id = fixed_ip['subnet_id'] subnet = self.safe_client.client.show_subnet(subnet_id) prefixlen = netaddr.IPNetwork(subnet['subnet']['cidr']).prefixlen self._ip_cidr = '%s/%s' % (self._ip, prefixlen) # TODO(amuller): Support DHCP self.port.addr.add(self.ip_cidr) self.gateway_ip = subnet['subnet']['gateway_ip'] if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def _configure_ipaddress(self, fixed_ip): if (netaddr.IPAddress( fixed_ip['ip_address']).version == constants.IP_VERSION_6): # v6Address/default_route is auto-configured. self._ipv6 = fixed_ip['ip_address'] else: self._ip = fixed_ip['ip_address'] subnet_id = fixed_ip['subnet_id'] subnet = self.safe_client.client.show_subnet(subnet_id) prefixlen = netaddr.IPNetwork(subnet['subnet']['cidr']).prefixlen self._ip_cidr = '%s/%s' % (self._ip, prefixlen) # TODO(amuller): Support DHCP self.port.addr.add(self.ip_cidr) self.gateway_ip = subnet['subnet']['gateway_ip'] if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def test_fip_connection_from_same_subnet(self): '''Test connection to floatingip which is associated with fixed_ip on the same subnet of the source fixed_ip. In other words it confirms that return packets surely go through the router. ''' router_info = self.generate_router_info(enable_ha=False) router = self.manage_router(self.agent, router_info) router_ip_cidr = self._port_first_ip_cidr(router.internal_ports[0]) router_ip = router_ip_cidr.partition('/')[0] src_ip_cidr = net_helpers.increment_ip_cidr(router_ip_cidr) dst_ip_cidr = net_helpers.increment_ip_cidr(src_ip_cidr) dst_ip = dst_ip_cidr.partition('/')[0] dst_fip = '19.4.4.10' router.router[l3_constants.FLOATINGIP_KEY] = [] self._add_fip(router, dst_fip, fixed_address=dst_ip) router.process(self.agent) br_int = get_ovs_bridge(self.agent.conf.ovs_integration_bridge) # FIXME(cbrandily): temporary, will be replaced by fake machines src_ns = self._create_namespace(prefix='test-src-') src_port = self.useFixture( net_helpers.OVSPortFixture(br_int, src_ns.namespace)).port src_port.addr.add(src_ip_cidr) net_helpers.set_namespace_gateway(src_port, router_ip) dst_ns = self._create_namespace(prefix='test-dst-') dst_port = self.useFixture( net_helpers.OVSPortFixture(br_int, dst_ns.namespace)).port dst_port.addr.add(dst_ip_cidr) net_helpers.set_namespace_gateway(dst_port, router_ip) protocol_port = helpers.get_free_namespace_port(dst_ns) # client sends to fip netcat = helpers.NetcatTester(src_ns, dst_ns, dst_ip, protocol_port, client_address=dst_fip, run_as_root=True, udp=False) self.addCleanup(netcat.stop_processes) self.assertTrue(netcat.test_connectivity())
def test_fip_connection_from_same_subnet(self): '''Test connection to floatingip which is associated with fixed_ip on the same subnet of the source fixed_ip. In other words it confirms that return packets surely go through the router. ''' router_info = self.generate_router_info(enable_ha=False) router = self.manage_router(self.agent, router_info) router_ip_cidr = self._port_first_ip_cidr(router.internal_ports[0]) router_ip = router_ip_cidr.partition('/')[0] src_ip_cidr = net_helpers.increment_ip_cidr(router_ip_cidr) dst_ip_cidr = net_helpers.increment_ip_cidr(src_ip_cidr) dst_ip = dst_ip_cidr.partition('/')[0] dst_fip = '19.4.4.10' router.router[l3_constants.FLOATINGIP_KEY] = [] self._add_fip(router, dst_fip, fixed_address=dst_ip) router.process(self.agent) br_int = get_ovs_bridge(self.agent.conf.ovs_integration_bridge) # FIXME(cbrandily): temporary, will be replaced by fake machines src_ns = self._create_namespace(prefix='test-src-') src_port = self.useFixture( net_helpers.OVSPortFixture(br_int, src_ns.namespace)).port src_port.addr.add(src_ip_cidr) net_helpers.set_namespace_gateway(src_port, router_ip) dst_ns = self._create_namespace(prefix='test-dst-') dst_port = self.useFixture( net_helpers.OVSPortFixture(br_int, dst_ns.namespace)).port dst_port.addr.add(dst_ip_cidr) net_helpers.set_namespace_gateway(dst_port, router_ip) protocol_port = helpers.get_free_namespace_port(dst_ns) # client sends to fip netcat = helpers.NetcatTester(src_ns, dst_ns, dst_ip, protocol_port, client_address=dst_fip, run_as_root=True, udp=False) self.addCleanup(netcat.stop_processes) self.assertTrue(netcat.test_connectivity())
def _configure_static_ipaddress(self): self.port.addr.add(self.ip_cidr) if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def _configure_static_ipaddress(self): self.port.addr.add(self.ip_cidr) if self.gateway_ip: net_helpers.set_namespace_gateway(self.port, self.gateway_ip)