Exemple #1
0
    def update_subnet_postcommit(self, context):
        new_subnet = context.current
        old_subnet = context.original
        network = context.network.current
        plugin_context = context._plugin_context
        dhcp_ip = None
        dhcp_port = None

        try:
            dhcp_ip, dhcp_port = self._handle_update_subnet_dhcp(
                plugin_context, old_subnet, new_subnet)
        except Exception:
            LOG.exception("Failed to create dhcp port for subnet %s",
                          new_subnet['id'])
            return None

        lswitch = self.nb_api.get(
            l2.LogicalSwitch(id=new_subnet['network_id'],
                             topic=network['tenant_id']))
        lswitch.version = network['revision_number']
        subnet = lswitch.find_subnet(new_subnet['id'])
        subnet.update(neutron_l2.subnet_from_neutron_subnet(new_subnet))
        subnet.dhcp_ip = dhcp_ip
        self.nb_api.update(lswitch)

        LOG.info("DFMechDriver: update subnet %s", new_subnet['id'])
        return new_subnet
Exemple #2
0
    def create_subnet_postcommit(self, context):
        subnet = context.current
        network = context.network.current
        net_id = subnet['network_id']
        plugin_context = context._plugin_context
        dhcp_ip = None
        dhcp_port = None

        try:
            dhcp_ip, dhcp_port = self._handle_create_subnet_dhcp(
                plugin_context, subnet)
        except Exception:
            LOG.exception("Failed to create dhcp port for subnet %s",
                          subnet['id'])
            return None

        lswitch = self.nb_api.get(
            l2.LogicalSwitch(id=net_id, topic=network['tenant_id']))
        lswitch.version = network['revision_number']
        df_subnet = neutron_l2.subnet_from_neutron_subnet(subnet)
        df_subnet.dhcp_ip = dhcp_ip
        lswitch.add_subnet(df_subnet)
        self.nb_api.update(lswitch)

        LOG.info("DFMechDriver: create subnet %s", subnet['id'])
        return subnet
Exemple #3
0
    def update_subnet_postcommit(self, context):
        new_subnet = context.current
        subnet = neutron_l2.subnet_from_neutron_subnet(new_subnet)
        self.nb_api.update(subnet)
        network = context.network.current
        topic = df_utils.get_obj_topic(network)
        self.nb_api.update(l2.LogicalSwitch(
            id=network['id'], topic=topic,
            version=network['revision_number']))

        LOG.info("DFMechDriver: update subnet %s", new_subnet['id'])
        return new_subnet
Exemple #4
0
    def create_subnet_postcommit(self, context):
        subnet = context.current
        network = context.network.current
        net_id = subnet['network_id']
        df_subnet = neutron_l2.subnet_from_neutron_subnet(subnet)
        self.nb_api.create(df_subnet)
        topic = df_utils.get_obj_topic(network)
        self.nb_api.update(l2.LogicalSwitch(
            id=net_id, topic=topic,
            version=network['revision_number']))

        LOG.info("DFMechDriver: create subnet %s", subnet['id'])
        return subnet
Exemple #5
0
    def test_create_update_delete_subnet_network_revision(self):
        network, lswitch = self._test_create_network_revision()
        self.nb_api.update.assert_not_called()
        self.nb_api.get.side_effect = nb_api_get_func(lswitch)
        with self.subnet(network={'network': network}, set_context=True) as s:
            subnet_id = s['subnet']['id']
        new_network = self.driver.get_network(self.context, network['id'])
        self.assertGreater(new_network['revision_number'],
                           network['revision_number'])
        lswitch.version = new_network['revision_number']
        # Once for lswitch, once for DHCP lport
        self.assertEqual(2, self.nb_api.update.call_count)
        self.nb_api.update.assert_called_with(lswitch)
        self.nb_api.update.reset_mock()

        data = {'subnet': {'name': 'updated'}}
        req = self.new_update_request('subnets', data, subnet_id)
        req.get_response(self.api)
        network = new_network
        new_network = self.driver.get_network(self.context, network['id'])
        new_lswitch = neutron_l2.logical_switch_from_neutron_network(
            new_network)
        updated_subnet = self.driver.get_subnet(self.context,
                                                subnet_id)
        new_lswitch.subnets = [neutron_l2.subnet_from_neutron_subnet(
            updated_subnet)]
        self.assertGreater(new_network['revision_number'],
                           network['revision_number'])
        self.nb_api.update.called_once_with(new_lswitch)
        self.nb_api.update.reset_mock()
        self.nb_api.get.side_effect = nb_api_get_func(lswitch)
        self.assertEqual(new_network['revision_number'],
                         lswitch.version)

        network = new_network
        req = self.new_delete_request('subnets', subnet_id)
        req.get_response(self.api)
        new_network = self.driver.get_network(self.context, network['id'])
        new_lswitch = neutron_l2.logical_switch_from_neutron_network(
            new_network)
        self.assertGreater(new_network['revision_number'],
                           network['revision_number'])
        self.nb_api.update.called_once_with(new_lswitch)
        self.assertEqual(new_network['revision_number'],
                         new_lswitch.version)