Ejemplo n.º 1
0
    def _invoke_join_request(self, docker_network_id,
                             docker_endpoint_id, container_id):
        data = {
            'NetworkID': docker_network_id,
            'EndpointID': docker_endpoint_id,
            'SandboxKey': utils.get_sandbox_key(container_id),
            'Options': {},
        }
        response = self.app.post('/NetworkDriver.Join',
                                 content_type='application/json',
                                 data=jsonutils.dumps(data))

        return response
Ejemplo n.º 2
0
    def _invoke_join_request(self, docker_network_id,
                             docker_endpoint_id, container_id):
        data = {
            'NetworkID': docker_network_id,
            'EndpointID': docker_endpoint_id,
            'SandboxKey': utils.get_sandbox_key(container_id),
            'Options': {},
        }
        response = self.app.post('/NetworkDriver.Join',
                                 content_type='application/json',
                                 data=jsonutils.dumps(data))

        return response
Ejemplo n.º 3
0
    def test_join_bad_request(self):
        fake_docker_network_id = hashlib.sha256(
            str(random.getrandbits(256))).hexdigest()
        invalid_docker_endpoint_id = 'id-should-be-hexdigits'
        fake_container_id = hashlib.sha256(
            str(random.getrandbits(256))).hexdigest()

        response = self._invoke_join_request(
            fake_docker_network_id, invalid_docker_endpoint_id,
            utils.get_sandbox_key(fake_container_id))

        self.assertEqual(400, response.status_code)
        decoded_json = jsonutils.loads(response.data)
        self.assertTrue('Err' in decoded_json)
        # TODO(tfukushima): Add the better error message validation.
        self.assertTrue(invalid_docker_endpoint_id in decoded_json['Err'])
        self.assertTrue('EndpointID' in decoded_json['Err'])
Ejemplo n.º 4
0
    def test_join_bad_request(self):
        fake_docker_network_id = hashlib.sha256(str(
            random.getrandbits(256))).hexdigest()
        invalid_docker_endpoint_id = 'id-should-be-hexdigits'
        fake_container_id = hashlib.sha256(str(
            random.getrandbits(256))).hexdigest()

        response = self._invoke_join_request(
            fake_docker_network_id, invalid_docker_endpoint_id,
            utils.get_sandbox_key(fake_container_id))

        self.assertEqual(400, response.status_code)
        decoded_json = jsonutils.loads(response.data)
        self.assertTrue('Err' in decoded_json)
        # TODO(tfukushima): Add the better error message validation.
        self.assertTrue(invalid_docker_endpoint_id in decoded_json['Err'])
        self.assertTrue('EndpointID' in decoded_json['Err'])
Ejemplo n.º 5
0
    def test_network_driver_join(self):
        fake_docker_network_id = hashlib.sha256(
            str(random.getrandbits(256))).hexdigest()
        fake_docker_endpoint_id = hashlib.sha256(
            str(random.getrandbits(256))).hexdigest()
        fake_container_id = hashlib.sha256(
            str(random.getrandbits(256))).hexdigest()

        data = {
            'NetworkID': fake_docker_network_id,
            'EndpointID': fake_docker_endpoint_id,
            'SandboxKey': utils.get_sandbox_key(fake_container_id),
            'Options': {},
        }
        response = self.app.post('/NetworkDriver.Join',
                                 content_type='application/json',
                                 data=jsonutils.dumps(data))

        self.assertEqual(200, response.status_code)
        decoded_json = jsonutils.loads(response.data)
        app.logger.info(decoded_json)
        self.assertEqual(constants.SCHEMA['JOIN'], decoded_json)
Ejemplo n.º 6
0
    def test_network_driver_join(self):
        fake_docker_network_id = hashlib.sha256(str(
            random.getrandbits(256))).hexdigest()
        fake_docker_endpoint_id = hashlib.sha256(str(
            random.getrandbits(256))).hexdigest()
        fake_container_id = hashlib.sha256(str(
            random.getrandbits(256))).hexdigest()

        data = {
            'NetworkID': fake_docker_network_id,
            'EndpointID': fake_docker_endpoint_id,
            'SandboxKey': utils.get_sandbox_key(fake_container_id),
            'Options': {},
        }
        response = self.app.post('/NetworkDriver.Join',
                                 content_type='application/json',
                                 data=jsonutils.dumps(data))

        self.assertEqual(200, response.status_code)
        decoded_json = jsonutils.loads(response.data)
        app.logger.info(decoded_json)
        self.assertEqual(constants.SCHEMA['JOIN'], decoded_json)
Ejemplo n.º 7
0
    def test_network_driver_join(self, vif_plug_is_fatal):
        if vif_plug_is_fatal:
            self.mox.StubOutWithMock(app, "vif_plug_is_fatal")
            app.vif_plug_is_fatal = True

        fake_docker_net_id = utils.get_hash()
        fake_docker_endpoint_id = utils.get_hash()
        fake_container_id = utils.get_hash()

        fake_neutron_net_id = str(uuid.uuid4())
        self._mock_out_network(fake_neutron_net_id, fake_docker_net_id)
        fake_neutron_port_id = str(uuid.uuid4())
        self.mox.StubOutWithMock(app.neutron, 'list_ports')
        neutron_port_name = utils.get_neutron_port_name(
            fake_docker_endpoint_id)
        fake_neutron_v4_subnet_id = str(uuid.uuid4())
        fake_neutron_v6_subnet_id = str(uuid.uuid4())
        fake_neutron_ports_response = self._get_fake_ports(
            fake_docker_endpoint_id, fake_neutron_net_id,
            fake_neutron_port_id, constants.PORT_STATUS_DOWN,
            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
        app.neutron.list_ports(name=neutron_port_name).AndReturn(
            fake_neutron_ports_response)

        self.mox.StubOutWithMock(app.neutron, 'list_subnets')
        fake_neutron_subnets_response = self._get_fake_subnets(
            fake_docker_endpoint_id, fake_neutron_net_id,
            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
        app.neutron.list_subnets(network_id=fake_neutron_net_id).AndReturn(
            fake_neutron_subnets_response)
        fake_neutron_port = fake_neutron_ports_response['ports'][0]
        fake_neutron_subnets = fake_neutron_subnets_response['subnets']
        _, fake_peer_name, _ = self._mock_out_binding(
            fake_docker_endpoint_id, fake_neutron_port, fake_neutron_subnets)

        if vif_plug_is_fatal:
            self.mox.StubOutWithMock(app.neutron, 'show_port')
            fake_neutron_ports_response_2 = self._get_fake_port(
                fake_docker_endpoint_id, fake_neutron_net_id,
                fake_neutron_port_id, constants.PORT_STATUS_ACTIVE,
                fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
            app.neutron.show_port(fake_neutron_port_id).AndReturn(
                fake_neutron_ports_response_2)

        self.mox.ReplayAll()

        fake_subnets_dict_by_id = {subnet['id']: subnet
                                   for subnet in fake_neutron_subnets}

        join_request = {
            'NetworkID': fake_docker_net_id,
            'EndpointID': fake_docker_endpoint_id,
            'SandboxKey': utils.get_sandbox_key(fake_container_id),
            'Options': {},
        }
        response = self.app.post('/NetworkDriver.Join',
                                 content_type='application/json',
                                 data=jsonutils.dumps(join_request))

        self.assertEqual(200, response.status_code)

        decoded_json = jsonutils.loads(response.data)
        fake_neutron_v4_subnet = fake_subnets_dict_by_id[
            fake_neutron_v4_subnet_id]
        fake_neutron_v6_subnet = fake_subnets_dict_by_id[
            fake_neutron_v6_subnet_id]
        expected_response = {
            'Gateway': fake_neutron_v4_subnet['gateway_ip'],
            'GatewayIPv6': fake_neutron_v6_subnet['gateway_ip'],
            'InterfaceName': {
                'DstPrefix': config.CONF.binding.veth_dst_prefix,
                'SrcName': fake_peer_name,
            },
            'StaticRoutes': []
        }
        self.assertEqual(expected_response, decoded_json)
Ejemplo n.º 8
0
 def test_get_sandbox_key(self, fake_container_id):
     sandbox_key = utils.get_sandbox_key(fake_container_id)
     expected = '/'.join([utils.DOCKER_NETNS_BASE, fake_container_id[:12]])
     self.assertEqual(expected, sandbox_key)
Ejemplo n.º 9
0
 def test_get_sandbox_key(self, fake_container_id):
     sandbox_key = utils.get_sandbox_key(fake_container_id)
     expected = '/'.join([utils.DOCKER_NETNS_BASE, fake_container_id[:12]])
     self.assertEqual(expected, sandbox_key)
Ejemplo n.º 10
0
    def test_network_driver_join(self):
        fake_docker_net_id = hashlib.sha256(utils.getrandbits(256)).hexdigest()
        fake_docker_endpoint_id = hashlib.sha256(
            utils.getrandbits(256)).hexdigest()
        fake_container_id = hashlib.sha256(utils.getrandbits(256)).hexdigest()

        fake_neutron_net_id = str(uuid.uuid4())
        self._mock_out_network(fake_neutron_net_id, fake_docker_net_id)
        fake_neutron_port_id = str(uuid.uuid4())
        self.mox.StubOutWithMock(app.neutron, 'list_ports')
        neutron_port_name = utils.get_neutron_port_name(
            fake_docker_endpoint_id)
        fake_neutron_v4_subnet_id = str(uuid.uuid4())
        fake_neutron_v6_subnet_id = str(uuid.uuid4())
        fake_neutron_ports_response = self._get_fake_ports(
            fake_docker_endpoint_id, fake_neutron_net_id, fake_neutron_port_id,
            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
        app.neutron.list_ports(
            name=neutron_port_name).AndReturn(fake_neutron_ports_response)

        self.mox.StubOutWithMock(app.neutron, 'list_subnets')
        fake_neutron_subnets_response = self._get_fake_subnets(
            fake_docker_endpoint_id, fake_neutron_net_id,
            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
        app.neutron.list_subnets(network_id=fake_neutron_net_id).AndReturn(
            fake_neutron_subnets_response)
        fake_neutron_port = fake_neutron_ports_response['ports'][0]
        fake_neutron_subnets = fake_neutron_subnets_response['subnets']
        _, fake_peer_name, _ = self._mock_out_binding(fake_docker_endpoint_id,
                                                      fake_neutron_port,
                                                      fake_neutron_subnets)
        self.mox.ReplayAll()

        fake_subnets_dict_by_id = {
            subnet['id']: subnet
            for subnet in fake_neutron_subnets
        }

        join_request = {
            'NetworkID': fake_docker_net_id,
            'EndpointID': fake_docker_endpoint_id,
            'SandboxKey': utils.get_sandbox_key(fake_container_id),
            'Options': {},
        }
        response = self.app.post('/NetworkDriver.Join',
                                 content_type='application/json',
                                 data=jsonutils.dumps(join_request))

        self.assertEqual(200, response.status_code)

        decoded_json = jsonutils.loads(response.data)
        fake_neutron_v4_subnet = fake_subnets_dict_by_id[
            fake_neutron_v4_subnet_id]
        fake_neutron_v6_subnet = fake_subnets_dict_by_id[
            fake_neutron_v6_subnet_id]
        expected_response = {
            'Gateway': fake_neutron_v4_subnet['gateway_ip'],
            'GatewayIPv6': fake_neutron_v6_subnet['gateway_ip'],
            'InterfaceName': {
                'DstPrefix': config.CONF.binding.veth_dst_prefix,
                'SrcName': fake_peer_name,
            },
            'StaticRoutes': []
        }
        self.assertEqual(expected_response, decoded_json)