示例#1
0
 def make_inactive(self, request, pk):
     """
     Remove this AppServer from the list of active app server for the instance.
     """
     app_server = self.get_object()
     make_appserver_active(app_server.pk, active=False)
     return Response({'status': 'App server deactivation initiated.'})
示例#2
0
 def test_disallow_deactivating_all(self, mock_make_active):
     """
     Disallow attempts to deactivate all appservers by passing in `active=False` and `deactivate_others=True`.
     """
     # Make an extra appserver to make sure it is not deactivated.
     appserver = make_test_appserver(self.appserver.instance)
     appserver.is_active = True
     appserver.save()
     tasks.make_appserver_active(self.appserver.id, active=False, deactivate_others=True)
     mock_make_active.assert_called_once_with(active=False)
示例#3
0
 def test_deactivate_others(self, mock_make_active):
     """
     When activating the appserver, optionally deactivate others.
     """
     for dummy in range(5):
         appserver = make_test_appserver(self.appserver.instance)
         appserver.is_active = True
         appserver.save()
     tasks.make_appserver_active(self.appserver.id, active=True, deactivate_others=True)
     mock_make_active.assert_has_calls(
         # Calls to make the appserver active.
         [call(active=True)] +
         # Calls to deactivate other appservers.
         [call(active=False) for dummy in range(5)]
     )
示例#4
0
 def test_make_appserver_active_server_unhealthy(self, health, mock_make_active, mock_update_status):
     """
     Test to activate the appserver where the associated server was unhealthy.
     The server is checked for being healthy twice. If it was unhealthy
     for both the calls, the appserver is not made active.
     """
     with patch('instance.models.server.OpenStackServer.Status.Ready.is_healthy_state',
                new_callable=PropertyMock) as mock_is_healthy_state:
         mock_is_healthy_state.side_effect = health
         tasks.make_appserver_active(self.appserver.id, active=True)
         mock_update_status.assert_called_once_with()
         if any(healthy for healthy in health):
             mock_make_active.assert_called_once_with(active=True)
         else:
             mock_make_active.assert_not_called()
示例#5
0
    def make_active(self, request, pk):
        """
        Add this AppServer to the list of active app server for the instance.
        """
        app_server = self.get_object()
        if not app_server.status.is_healthy_state or not make_appserver_active(app_server.pk):
            return Response(
                {"error": "Cannot make an unhealthy app server active."}, status=status.HTTP_400_BAD_REQUEST
            )

        return Response({'status': 'App server activation initiated.'})
示例#6
0
 def test_make_appserver_active(self, active, mock_make_active):
     """
     By default, we activate the appserver.
     """
     tasks.make_appserver_active(self.appserver.id, active=active)
     mock_make_active.assert_called_once_with(active=active)