50afa71853
1.Upgrade pylint to 2.4.4, add exclusions to the tests, and fix some lint errors in the code 2. Fix user creation with GRANT in MySQL 8.0(Ubuntu Focal) In Ubuntu Bionic (18.04) mysql 5.7 version used to create the user implicitly when using using the GRANT. Ubuntu Focal (20.04) has mysql 8.0 and with mysql 8.0 there is no implicit user creation with GRANT. We need to create the user first before using GRANT command. See also commit I97b0dcbb88c6ef7c22e3c55970211bed792bbd0d 3. Remove fwaas from the zuul.yaml 4. Remove DB migration test which is failing ue to FWaaS migration with py38 5. Fix cover tests python version in .tox 6. fix requirememnts Change-Id: I22654a5d5ccaad3185ae3365a90afba1ce870695
96 lines
3.7 KiB
Python
96 lines
3.7 KiB
Python
# Copyright 2014 VMware, Inc.
|
|
#
|
|
# All Rights Reserved
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# 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_lib.db import api as db_api
|
|
from oslo_db import exception as d_exc
|
|
from oslo_log import log as logging
|
|
from sqlalchemy import orm
|
|
|
|
from vmware_nsx._i18n import _
|
|
from vmware_nsx.common import exceptions as p_exc
|
|
from vmware_nsx.db import nsx_models
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
def lsn_add(context, network_id, lsn_id):
|
|
"""Add Logical Service Node information to persistent datastore."""
|
|
with db_api.CONTEXT_WRITER.using(context):
|
|
lsn = nsx_models.Lsn(network_id, lsn_id)
|
|
context.session.add(lsn)
|
|
|
|
|
|
def lsn_remove(context, lsn_id):
|
|
"""Remove Logical Service Node information from datastore given its id."""
|
|
with db_api.CONTEXT_WRITER.using(context):
|
|
context.session.query(nsx_models.Lsn).filter_by(lsn_id=lsn_id).delete()
|
|
|
|
|
|
def lsn_get_for_network(context, network_id, raise_on_err=True):
|
|
"""Retrieve LSN information given its network id."""
|
|
query = context.session.query(nsx_models.Lsn)
|
|
try:
|
|
return query.filter_by(net_id=network_id).one()
|
|
except (orm.exc.NoResultFound, d_exc.DBError):
|
|
msg = _('Unable to find Logical Service Node for network %s')
|
|
if raise_on_err:
|
|
LOG.error(msg, network_id)
|
|
raise p_exc.LsnNotFound(entity='network',
|
|
entity_id=network_id)
|
|
LOG.warning(msg, network_id)
|
|
|
|
|
|
def lsn_port_add_for_lsn(context, lsn_port_id, subnet_id, mac, lsn_id):
|
|
"""Add Logical Service Node Port information to persistent datastore."""
|
|
with db_api.CONTEXT_WRITER.using(context):
|
|
lsn_port = nsx_models.LsnPort(lsn_port_id, subnet_id, mac, lsn_id)
|
|
context.session.add(lsn_port)
|
|
|
|
|
|
def lsn_port_get_for_subnet(context, subnet_id, raise_on_err=True):
|
|
"""Return Logical Service Node Port information given its subnet id."""
|
|
with db_api.CONTEXT_READER.using(context):
|
|
try:
|
|
return (context.session.query(nsx_models.LsnPort).
|
|
filter_by(sub_id=subnet_id).one())
|
|
except (orm.exc.NoResultFound, d_exc.DBError):
|
|
if raise_on_err:
|
|
raise p_exc.LsnPortNotFound(lsn_id=None,
|
|
entity='subnet',
|
|
entity_id=subnet_id)
|
|
|
|
|
|
def lsn_port_get_for_mac(context, mac_address, raise_on_err=True):
|
|
"""Return Logical Service Node Port information given its mac address."""
|
|
with db_api.CONTEXT_READER.using(context):
|
|
try:
|
|
return (context.session.query(nsx_models.LsnPort).
|
|
filter_by(mac_addr=mac_address).one())
|
|
except (orm.exc.NoResultFound, d_exc.DBError):
|
|
if raise_on_err:
|
|
raise p_exc.LsnPortNotFound(lsn_id=None,
|
|
entity='mac',
|
|
entity_id=mac_address)
|
|
|
|
|
|
def lsn_port_remove(context, lsn_port_id):
|
|
"""Remove Logical Service Node port from the given Logical Service Node."""
|
|
with db_api.CONTEXT_WRITER.using(context):
|
|
(context.session.query(nsx_models.LsnPort).
|
|
filter_by(lsn_port_id=lsn_port_id).delete())
|