def test_exception_detail_logging(self):

        e3e = Etcd3Exception(detail_text='from test_exception_detail_logging')

        def fn(self, *args, **kwargs):
            raise e3e

        wrapped = etcdv3.logging_exceptions(fn)

        with mock.patch.object(log.getLogger('networking_calico.etcdv3'),
                               'warning') as mock_lw:
            try:
                wrapped(None)
            except Exception:
                pass
            mock_lw.assert_called_with("Etcd3Exception, re-raising: %r:\n%s",
                                       e3e,
                                       'from test_exception_detail_logging')
Ejemplo n.º 2
0
    def test_exception_detail_logging(self):
        LOG.debug("test_exception_detail_logging")

        with mock.patch.object(
                log.getLogger(
                    'networking_calico.plugins.ml2.drivers.calico.election'),
                'warning') as mock_lw:
            etcdv3._client = client = stub_etcd.Client()
            exc = e3e.Etcd3Exception(detail_text="Unauthorised user")
            client.add_read_exception(exc)
            elector = election.Elector("test_basic",
                                       "/bloop",
                                       interval=5,
                                       ttl=15)
            self._wait_and_stop(client, elector)

            # Check that Etcd3Exception detail was logged.
            mock_lw.assert_called_with('Failed to %s - key %s: %r:\n%s',
                                       'read current master', '/bloop', exc,
                                       'Unauthorised user')
Ejemplo n.º 3
0
# 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 json
import netaddr

from networking_calico.common import config as calico_config
from networking_calico.compat import log
from networking_calico import datamodel_v1
from networking_calico import datamodel_v2
from networking_calico import etcdv3
from networking_calico.plugins.ml2.drivers.calico.syncer import ResourceGone
from networking_calico.plugins.ml2.drivers.calico.syncer import ResourceSyncer

LOG = log.getLogger(__name__)


class SubnetSyncer(ResourceSyncer):
    """Logic for syncing Subnets.

    For Subnet resources, the name is the full etcd key, and the data is the
    etcd value as a string, i.e. not JSON-decoded into a dict.
    """
    def __init__(self, db, txn_from_context):
        super(SubnetSyncer, self).__init__(db, txn_from_context, "Subnet")
        self.region_string = calico_config.get_region_string()

    def delete_legacy_etcd_data(self):
        etcdv3.delete_prefix(datamodel_v1.SUBNET_DIR)
Ejemplo n.º 4
0
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, 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 neutron.db import l3_db
from neutron.plugins.ml2.plugin import Ml2Plugin

from networking_calico.compat import cfg
from networking_calico.compat import log


LOG = log.getLogger(__name__)


class CalicoPlugin(Ml2Plugin, l3_db.L3_NAT_db_mixin):
    def __init__(self):
        # Add the ability to handle floating IPs.
        self._supported_extension_aliases.extend(["router"])

        # Set ML2 options so the user doesn't have to.
        LOG.info("Forcing ML2 mechanism_drivers to 'calico'")
        cfg.CONF.set_override('mechanism_drivers', ['calico'], group='ml2')
        LOG.info("Forcing ML2 type_drivers to 'local, flat'")
        cfg.CONF.set_override('type_drivers', ['local', 'flat'], group='ml2')
        LOG.info("Forcing ML2 tenant_network_types to 'local'")
        cfg.CONF.set_override('tenant_network_types', ['local'], group='ml2')