예제 #1
0
    def testReplicaCounts(self, spec_replicas, status_replicas,
                          available_replicas, updated_replicas,
                          done_and_succeeded):
        d = kube_util.DeploymentPodsAvailableOperation('namespace', 'test',
                                                       'testImage',
                                                       self.mock_client)
        self.mock_client.GetResourceField.side_effect = [
            ('testImage', None),
            (spec_replicas, None),
            (status_replicas, None),
            (available_replicas, None),
            (updated_replicas, None),
        ]

        d.Update()
        self.mock_client.GetResourceField.assert_has_calls([
            mock.call('namespace', 'deployment/test',
                      '.spec.template.spec.containers[0].image'),
            mock.call('namespace', 'deployment/test', '.spec.replicas'),
            mock.call('namespace', 'deployment/test', '.status.replicas'),
            mock.call('namespace', 'deployment/test',
                      '.status.availableReplicas'),
            mock.call('namespace', 'deployment/test',
                      '.status.updatedReplicas')
        ])

        self.assertEqual(d.done, done_and_succeeded)
        self.assertEqual(d.succeeded, done_and_succeeded)
        self.assertFalse(d.error)
예제 #2
0
    def testDifferentImage(self):
        d = kube_util.DeploymentPodsAvailableOperation('namespace', 'test',
                                                       'testImage',
                                                       self.mock_client)
        self.mock_client.GetResourceField.return_value = ('differentImage',
                                                          None)

        d.Update()

        self.assertFalse(d.done)
        self.assertFalse(d.succeeded)
        self.assertFalse(d.error)
예제 #3
0
    def testError(self):
        d = kube_util.DeploymentPodsAvailableOperation('namespace', 'test',
                                                       'testImage',
                                                       self.mock_client)
        self.mock_client.GetResourceField.return_value = (
            None, 'Error from server (SomethingIsWrong): something is wrong')

        d.Update()

        self.assertTrue(d.done)
        self.assertFalse(d.succeeded)
        self.assertTrue(d.error)
예제 #4
0
    def testNotFoundError(self):
        d = kube_util.DeploymentPodsAvailableOperation('namespace', 'test',
                                                       'testImage',
                                                       self.mock_client)
        self.mock_client.GetResourceField.return_value = (
            None,
            'Error from server (NotFound): deployments.extensions "foo" not found'
        )

        d.Update()

        self.assertFalse(d.done)
        self.assertFalse(d.succeeded)
        self.assertFalse(d.error)
예제 #5
0
    def testInit(self):
        d = kube_util.DeploymentPodsAvailableOperation('namespace', 'test',
                                                       'testImage',
                                                       self.mock_client)
        self.assertEqual(d.namespace, 'namespace')
        self.assertEqual(d.deployment_name, 'test')
        self.assertEqual(d.image, 'testImage')
        self.assertEqual(d.kube_client, self.mock_client)

        self.mock_client.GetResourceField.assert_not_called()

        self.assertFalse(d.done)
        self.assertFalse(d.succeeded)
        self.assertFalse(d.error)