"Fossies" - the Fresh Open Source Software Archive

Member "octavia-8.0.0/octavia/cmd/status.py" (14 Apr 2021, 5631 Bytes) of package /linux/misc/openstack/octavia-8.0.0.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. For more information about "status.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 7.1.1_vs_8.0.0.

    1 # Copyright (c) 2018 NEC, Corp.
    2 #
    3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 #    not use this file except in compliance with the License. You may obtain
    5 #    a copy of the License at
    6 #
    7 #         http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 #    Unless required by applicable law or agreed to in writing, software
   10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 #    License for the specific language governing permissions and limitations
   13 #    under the License.
   14 
   15 import sys
   16 
   17 from oslo_config import cfg
   18 from oslo_upgradecheck import common_checks
   19 from oslo_upgradecheck import upgradecheck
   20 from stevedore import driver as stevedore_driver
   21 
   22 # Need to import to load config
   23 from octavia.common import config  # noqa: F401 pylint: disable=unused-import
   24 from octavia.common import constants
   25 from octavia.common import policy
   26 from octavia.controller.worker.v2 import taskflow_jobboard_driver as tsk_driver
   27 from octavia.i18n import _
   28 
   29 CONF = cfg.CONF
   30 
   31 
   32 class Checks(upgradecheck.UpgradeCommands):
   33 
   34     """Contains upgrade checks
   35 
   36     Various upgrade checks should be added as separate methods in this class
   37     and added to _upgrade_checks tuple.
   38     """
   39 
   40     def _check_persistence(self):
   41         try:
   42             pers_driver = tsk_driver.MysqlPersistenceDriver()
   43             with pers_driver.get_persistence() as pers:
   44                 if pers.engine.dialect.name == 'sqlite':
   45                     return upgradecheck.Result(
   46                         upgradecheck.Code.WARNING,
   47                         _('Persistence database is using sqlite backend. '
   48                           'Verification required if persistence_connecton URL '
   49                           'has been set properly.'))
   50                 return pers
   51         except Exception:
   52             return upgradecheck.Result(upgradecheck.Code.FAILURE,
   53                                        _('Failed to connect to persistence '
   54                                          'backend for AmphoraV2 provider.'))
   55 
   56     def _check_jobboard(self, persistence):
   57         try:
   58             jobboard_driver = stevedore_driver.DriverManager(
   59                 namespace='octavia.worker.jobboard_driver',
   60                 name=CONF.task_flow.jobboard_backend_driver,
   61                 invoke_args=(persistence,),
   62                 invoke_on_load=True).driver
   63             with jobboard_driver.job_board(persistence) as jb:
   64                 if jb.connected:
   65                     return upgradecheck.Result(
   66                         upgradecheck.Code.SUCCESS,
   67                         _('Persistence database and Jobboard backend for '
   68                           'AmphoraV2 provider configured.'))
   69         except Exception:
   70             # Return FAILURE later
   71             pass
   72 
   73         return upgradecheck.Result(
   74             upgradecheck.Code.FAILURE,
   75             _('Failed to connect to jobboard backend for AmphoraV2 provider. '
   76               'Check jobboard configuration options in task_flow config '
   77               'section.'))
   78 
   79     def _check_amphorav2(self):
   80         default_provider_driver = CONF.api_settings.default_provider_driver
   81         enabled_provider_drivers = CONF.api_settings.enabled_provider_drivers
   82         if (default_provider_driver == constants.AMPHORAV2 or
   83                 constants.AMPHORAV2 in enabled_provider_drivers):
   84             persistence = self._check_persistence()
   85             if isinstance(persistence, upgradecheck.Result):
   86                 return persistence
   87             return self._check_jobboard(persistence)
   88         return upgradecheck.Result(upgradecheck.Code.SUCCESS,
   89                                    _('AmphoraV2 provider is not enabled.'))
   90 
   91     def _check_yaml_policy(self):
   92         if CONF.oslo_policy.policy_file.lower().endswith('yaml'):
   93             return upgradecheck.Result(upgradecheck.Code.SUCCESS,
   94                                        _('The [oslo_policy] policy_file '
   95                                          'setting is configured for YAML '
   96                                          'policy file format.'))
   97         if CONF.oslo_policy.policy_file.lower().endswith('json'):
   98             return upgradecheck.Result(
   99                 upgradecheck.Code.WARNING,
  100                 _('The [oslo_policy] policy_file setting is configured for '
  101                   'JSON policy file format. JSON format policy files have '
  102                   'been deprecated by oslo policy. Please use the oslo policy '
  103                   'tool to convert your policy file to YAML format. See this '
  104                   'patch for more information: '
  105                   'https://review.opendev.org/733650'))
  106         return upgradecheck.Result(upgradecheck.Code.FAILURE,
  107                                    _('Unable to determine the [oslo_policy] '
  108                                      'policy_file setting file format. '
  109                                      'Please make sure your policy file is '
  110                                      'in YAML format and has the suffix of '
  111                                      '.yaml for the filename. Oslo policy '
  112                                      'has deprecated the JSON file format.'))
  113 
  114     _upgrade_checks = (
  115         (_('AmphoraV2 Check'), _check_amphorav2),
  116         (_('YAML Policy File'), _check_yaml_policy),
  117         (_('Policy File JSON to YAML Migration'),
  118          (common_checks.check_policy_json, {'conf': CONF})),
  119     )
  120 
  121 
  122 def main():
  123     policy.Policy()
  124     return upgradecheck.main(
  125         CONF, project='octavia', upgrade_command=Checks())
  126 
  127 
  128 if __name__ == '__main__':
  129     sys.exit(main())