"Fossies" - the Fresh Open Source Software Archive

Member "octavia-8.0.0/octavia/tests/unit/amphorae/backends/agent/api_server/test_keepalivedlvs.py" (14 Apr 2021, 2399 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.

    1 # Copyright 2015 Hewlett Packard Enterprise Development Company LP
    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 from unittest import mock
   15 
   16 from oslo_utils import uuidutils
   17 
   18 from octavia.amphorae.backends.agent.api_server import keepalivedlvs
   19 from octavia.amphorae.backends.agent.api_server import util
   20 from octavia.tests.unit import base
   21 
   22 
   23 class KeepalivedLvsTestCase(base.TestCase):
   24     FAKE_ID = uuidutils.generate_uuid()
   25 
   26     def setUp(self):
   27         super().setUp()
   28         self.test_keepalivedlvs = keepalivedlvs.KeepalivedLvs()
   29 
   30     @mock.patch.object(keepalivedlvs, "webob")
   31     @mock.patch('os.path.exists')
   32     def test_delete_lvs_listener_not_exist(self, m_exist, m_webob):
   33         m_exist.return_value = False
   34         self.test_keepalivedlvs.delete_lvs_listener(self.FAKE_ID)
   35         calls = [
   36             mock.call(
   37                 json=dict(message='UDP Listener Not Found',
   38                           details="No UDP listener with UUID: "
   39                                   "{0}".format(self.FAKE_ID)), status=404),
   40             mock.call(json={'message': 'OK'})
   41         ]
   42         m_webob.Response.assert_has_calls(calls)
   43 
   44     @mock.patch('octavia.amphorae.backends.agent.api_server.util.'
   45                 'get_os_init_system')
   46     @mock.patch('octavia.amphorae.backends.agent.api_server.util.'
   47                 'get_keepalivedlvs_pid')
   48     @mock.patch('subprocess.check_output')
   49     @mock.patch('os.remove')
   50     @mock.patch('os.path.exists')
   51     def test_delete_lvs_listener_unsupported_sysinit(self, m_exist, m_remove,
   52                                                      m_check_output, mget_pid,
   53                                                      m_init_sys):
   54         m_exist.return_value = True
   55         mget_pid.return_value = '0'
   56         self.assertRaises(
   57             util.UnknownInitError,
   58             self.test_keepalivedlvs.delete_lvs_listener,
   59             self.FAKE_ID)