def testGetMetadata(self): spec = self.create_virtual_machine_spec() with patch_critical_objects(): kub_vm = kubernetes_virtual_machine.KubernetesVirtualMachine(spec) subset_of_expected_metadata = { 'pod_cpu_limit': 2, 'pod_memory_limit_mb': 5120, 'pod_cpu_request': 1.5, 'pod_memory_request_mb': 4096, } actual = kub_vm.GetResourceMetadata() self.assertDictContainsSubset(subset_of_expected_metadata, actual)
def testCreate(self): spec = self.create_virtual_machine_spec() with patch_critical_objects() as (issue_command, _): kub_vm = kubernetes_virtual_machine.KubernetesVirtualMachine(spec) kub_vm._WaitForPodBootCompletion = lambda: None kub_vm._Create() command = issue_command.call_args[0][0] command_string = ' '.join(command[:4]) self.assertEqual(issue_command.call_count, 1) self.assertIn('{0} --kubeconfig={1} create -f'.format( _KUBECTL, _KUBECONFIG), command_string)
def testCreatePodBodyWrittenCorrectly(self): spec = self.create_virtual_machine_spec() with patch_critical_objects() as (_, temp_file): kub_vm = kubernetes_virtual_machine.KubernetesVirtualMachine(spec) # Need to set the name explicitly on the instance because the test # running is currently using a single PKB instance, so the BaseVm # instance counter is at an unpredictable number at this stage, and it is # used to set the name. kub_vm.name = _NAME kub_vm._WaitForPodBootCompletion = lambda: None kub_vm._Create() write_mock = get_write_mock_from_temp_file_mock(temp_file) self.assertJsonEqual(write_mock.call_args[0][0], _EXPECTED_CALL_BODY_WITH_2_GPUS)
def testCreatePodResourceBody(self): spec = self.create_virtual_machine_spec() with patch_critical_objects(): kub_vm = kubernetes_virtual_machine.KubernetesVirtualMachine(spec) expected = { 'limits': { 'cpu': '2', 'memory': '5120Mi', 'nvidia.com/gpu': '2' }, 'requests': { 'cpu': '1.5', 'memory': '4096Mi', 'nvidia.com/gpu': '2' } } actual = kub_vm._BuildResourceBody() self.assertDictEqual(expected, actual)