Пример #1
0
 def test__update_leader_with_retry(self, mock_patch):
     mock_patch.side_effect = k8s_client.rest.ApiException(502, '')
     self.assertFalse(self.k.update_leader('123'))
     mock_patch.side_effect = RetryFailedError('')
     self.assertFalse(self.k.update_leader('123'))
     mock_patch.side_effect = k8s_client.rest.ApiException(409, '')
     with patch('time.time', Mock(side_effect=[0, 100, 200])):
         self.assertFalse(self.k.update_leader('123'))
     with patch('time.sleep', Mock()):
         self.assertFalse(self.k.update_leader('123'))
         mock_patch.side_effect = [k8s_client.rest.ApiException(409, ''), mock_namespaced_kind()]
         self.k._kinds._object_cache['test'].metadata.resource_version = '2'
         self.assertIsNotNone(self.k._update_leader_with_retry({}, '1', []))
Пример #2
0
 def test__update_leader_with_retry(self, mock_patch, mock_read):
     mock_read.return_value = mock_read_namespaced_endpoints()
     mock_patch.side_effect = k8s_client.rest.ApiException(502, '')
     self.assertFalse(self.k.update_leader('123'))
     mock_patch.side_effect = RetryFailedError('')
     self.assertFalse(self.k.update_leader('123'))
     mock_patch.side_effect = k8s_client.rest.ApiException(409, '')
     with patch('time.time', Mock(side_effect=[0, 100, 200, 0, 0, 0, 0, 100, 200])):
         self.assertFalse(self.k.update_leader('123'))
         self.assertFalse(self.k.update_leader('123'))
     self.assertFalse(self.k.update_leader('123'))
     mock_patch.side_effect = [k8s_client.rest.ApiException(409, ''), mock_namespaced_kind()]
     mock_read.return_value.metadata.resource_version = '2'
     self.assertIsNotNone(self.k._update_leader_with_retry({}, '1', []))
     mock_patch.side_effect = k8s_client.rest.ApiException(409, '')
     mock_read.side_effect = Exception
     self.assertFalse(self.k.update_leader('123'))
Пример #3
0
 def test_manual_failover(self):
     with patch.object(k8s_client.CoreV1Api, 'patch_namespaced_config_map',
                       Mock(side_effect=RetryFailedError(''))):
         self.k.manual_failover('foo', 'bar')