"Fossies" - the Fresh Open Source Software Archive

Member "neutron-14.0.3/neutron/tests/functional/db/migrations/test_b12a3ef66e62_add_standardattr_to_qos_policies.py" (22 Oct 2019, 2346 Bytes) of package /linux/misc/openstack/neutron-14.0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #
    2 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    3 #    not use this file except in compliance with the License. You may obtain
    4 #    a copy of the License at
    5 #
    6 #         http://www.apache.org/licenses/LICENSE-2.0
    7 #
    8 #    Unless required by applicable law or agreed to in writing, software
    9 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   10 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   11 #    License for the specific language governing permissions and limitations
   12 #    under the License.
   13 #
   14 
   15 
   16 from oslo_db.sqlalchemy import utils as db_utils
   17 from oslo_utils import uuidutils
   18 
   19 from neutron.tests.functional.db import test_migrations
   20 
   21 
   22 class QosStandardAttrMixin(object):
   23     """Validates qos standard attr migration."""
   24 
   25     def _create_qos_pol(self, pol_id, description):
   26         otable = db_utils.get_table(self.engine, 'qos_policies')
   27         values = {'id': pol_id, 'description': description}
   28         self.engine.execute(otable.insert().values(values))
   29 
   30     def _create_policies_with_descriptions(self, engine):
   31         for i in range(10):
   32             pol_id = uuidutils.generate_uuid()
   33             self._create_qos_pol(pol_id, 'description-%s' % pol_id)
   34 
   35     def _pre_upgrade_b12a3ef66e62(self, engine):
   36         self._create_policies_with_descriptions(engine)
   37         return True  # return True so check function is invoked after migrate
   38 
   39     def _check_b12a3ef66e62(self, engine, data):
   40         qp = db_utils.get_table(engine, 'qos_policies')
   41         sa = db_utils.get_table(engine, 'standardattributes')
   42         for qos_pol in engine.execute(qp.select()).fetchall():
   43             # ensure standard attributes model was created
   44             standard_id = qos_pol.standard_attr_id
   45             rows = engine.execute(
   46                 sa.select().where(sa.c.id == standard_id)).fetchall()
   47             self.assertEqual(1, len(rows))
   48             # ensure description got moved over
   49             self.assertEqual('description-%s' % qos_pol.id,
   50                              rows[0].description)
   51 
   52 
   53 class TestQosStandardAttrMysql(QosStandardAttrMixin,
   54                                test_migrations.TestWalkMigrationsMysql):
   55     pass
   56 
   57 
   58 class TestQosStandardAttrPsql(QosStandardAttrMixin,
   59                               test_migrations.TestWalkMigrationsPsql):
   60     pass