"Fossies" - the Fresh Open Source Software Archive

Member "magnum-8.1.0/magnum/tests/unit/servicegroup/test_magnum_service.py" (1 Oct 2019, 3076 Bytes) of package /linux/misc/openstack/magnum-8.1.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 - Yahoo! Inc.
    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 mock
   16 
   17 from magnum.common.rpc_service import CONF
   18 from magnum import objects
   19 from magnum.servicegroup import magnum_service_periodic as periodic
   20 from magnum.tests import base
   21 
   22 
   23 class MagnumServicePeriodicTestCase(base.TestCase):
   24 
   25     def setUp(self):
   26         super(MagnumServicePeriodicTestCase, self).setUp()
   27         mock_magnum_service_refresh = mock.Mock()
   28 
   29         class FakeMS(object):
   30             report_state_up = mock_magnum_service_refresh
   31 
   32         self.fake_ms = FakeMS()
   33         self.fake_ms_refresh = mock_magnum_service_refresh
   34 
   35     @mock.patch.object(objects.MagnumService, 'get_by_host_and_binary')
   36     @mock.patch.object(objects.MagnumService, 'create')
   37     @mock.patch.object(objects.MagnumService, 'report_state_up')
   38     def test_update_magnum_service_firsttime(self,
   39                                              mock_ms_refresh,
   40                                              mock_ms_create,
   41                                              mock_ms_get
   42                                              ):
   43         p_task = periodic.MagnumServicePeriodicTasks(CONF,
   44                                                      'fake-conductor')
   45         mock_ms_get.return_value = None
   46 
   47         p_task.update_magnum_service(None)
   48 
   49         mock_ms_get.assert_called_once_with(mock.ANY, p_task.host,
   50                                             p_task.binary)
   51         mock_ms_create.assert_called_once_with()
   52         mock_ms_refresh.assert_called_once_with()
   53 
   54     @mock.patch.object(objects.MagnumService, 'get_by_host_and_binary')
   55     @mock.patch.object(objects.MagnumService, 'create')
   56     def test_update_magnum_service_on_restart(self,
   57                                               mock_ms_create,
   58                                               mock_ms_get):
   59         p_task = periodic.MagnumServicePeriodicTasks(CONF,
   60                                                      'fake-conductor')
   61         mock_ms_get.return_value = self.fake_ms
   62 
   63         p_task.update_magnum_service(None)
   64 
   65         mock_ms_get.assert_called_once_with(mock.ANY, p_task.host,
   66                                             p_task.binary)
   67         self.fake_ms_refresh.assert_called_once_with()
   68 
   69     def test_update_magnum_service_regular(self):
   70         p_task = periodic.MagnumServicePeriodicTasks(CONF,
   71                                                      'fake-conductor')
   72         p_task.magnum_service_ref = self.fake_ms
   73 
   74         p_task.update_magnum_service(None)
   75 
   76         self.fake_ms_refresh.assert_called_once_with()