def testPostCreate(self, create_from_file_patch): spec = self.create_kubernetes_engine_spec() with patch_critical_objects() as issue_command, mock.patch.object( container_service, 'RunKubectlCommand') as mock_kubectl_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._PostCreate() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn( 'gcloud container clusters get-credentials pkb-{0}'.format(_RUN_URI), command_string) self.assertIn('KUBECONFIG', issue_command.call_args[1]['env']) self.assertEqual(mock_kubectl_command.call_count, 1) expected_args_to_create_from_file = ( _NVIDIA_DRIVER_SETUP_DAEMON_SET_SCRIPT, data.ResourcePath( _NVIDIA_UNRESTRICTED_PERMISSIONS_DAEMON_SET) ) expected_calls = [mock.call(arg) for arg in expected_args_to_create_from_file] # Assert that create_from_file was called twice, # and that the args were as expected (should be the NVIDIA # driver setup daemon set, followed by the # NVIDIA unrestricted permissions daemon set. create_from_file_patch.assert_has_calls(expected_calls)
def testCreateRegionalClusterZonalNodepool(self): spec = self.create_kubernetes_engine_spec(use_zonal_nodepools=True) with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._Create() create_cluster, create_nodepool1, create_nodepool2 = ( call[0][0] for call in issue_command.call_args_list) self.assertNotIn('--zone', create_cluster) self.assertContainsSubsequence(create_cluster, ['--region', 'us-west1']) self.assertContainsSubsequence(create_cluster, ['--machine-type', 'fake-machine-type']) self.assertContainsSubsequence( create_nodepool1, ['gcloud', 'container', 'node-pools', 'create', 'nodepool1']) self.assertContainsSubsequence(create_nodepool1, ['--cluster', 'pkb-fake-urn-uri']) self.assertContainsSubsequence( create_nodepool1, ['--node-labels', 'pkb_nodepool=nodepool1']) self.assertContainsSubsequence( create_nodepool1, ['--node-locations', 'us-west1-a,us-west1-b']) self.assertContainsSubsequence(create_nodepool1, ['--region', 'us-west1']) self.assertContainsSubsequence( create_nodepool2, ['gcloud', 'container', 'node-pools', 'create', 'nodepool2']) self.assertContainsSubsequence(create_nodepool2, ['--node-locations', 'us-west1-c'])
def testCreateDefaultVersion(self): spec = self.create_kubernetes_engine_spec() with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._Create() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn('--cluster-version latest', command_string)
def testCreateRapidChannel(self): spec = self.create_kubernetes_engine_spec() FLAGS.container_cluster_version = 'rapid' with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._Create() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn('--release-channel rapid', command_string)
def testCreateDisableGvnic(self): spec = self.create_kubernetes_engine_spec() FLAGS.gke_enable_gvnic = False with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._Create() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn('--no-enable-gvnic', command_string)
def testCreate(self): spec = self.create_kubernetes_engine_spec() with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._Create() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn('gcloud container clusters create', command_string) self.assertIn('--machine-type custom-4-1024', command_string)
def testCreateCustomVersion(self): spec = self.create_kubernetes_engine_spec() FLAGS.container_cluster_version = 'fake-version' with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._Create() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn('--cluster-version fake-version', command_string)
def testExists(self): spec = self.create_kubernetes_engine_spec() with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._Exists() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn( 'gcloud container clusters describe pkb-{0}'.format(_RUN_URI), command_string)
def testCreateQuotaExceeded(self): spec = self.create_kubernetes_engine_spec() with patch_critical_objects( stderr=""" message=Insufficient regional quota to satisfy request: resource "CPUS": request requires '6400.0' and is short '5820.0'""", return_code=1) as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) with self.assertRaises( errors.Benchmarks.QuotaFailure): cluster._Create() self.assertEqual(issue_command.call_count, 1)
def testPostCreate(self, _): spec = self.create_kubernetes_engine_spec() with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._PostCreate() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn( 'gcloud container clusters get-credentials pkb-{0}'.format(_RUN_URI), command_string) self.assertIn('KUBECONFIG', issue_command.call_args[1]['env'])
def testCreate(self): spec = self.create_kubernetes_engine_spec() with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._Create() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn('gcloud container clusters create', command_string) self.assertIn('--enable-autoscaling', command_string) self.assertIn('--min-nodes 1', command_string) self.assertIn('--num-nodes 2', command_string) self.assertIn('--max-nodes 3', command_string)
def testCreate(self): spec = self.create_kubernetes_engine_spec() with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._Create() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn('gcloud container clusters create', command_string) self.assertIn('--num-nodes 2', command_string) self.assertIn('--machine-type fake-machine-type', command_string) self.assertIn('--accelerator type=nvidia-tesla-k80,count=2', command_string)
def testCreateResourcesExhausted(self): spec = self.create_kubernetes_engine_spec() with patch_critical_objects(stderr=""" [ZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILS]: Instance 'test' creation failed: The zone 'projects/artemis-prod/zones/us-central1-a' does not have enough resources available to fulfill the request.""", return_code=1) as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) with self.assertRaises( errors.Benchmarks.InsufficientCapacityCloudFailure): cluster._Create() self.assertEqual(issue_command.call_count, 1)
def testGetResourceMetadata(self): spec = self.create_kubernetes_engine_spec() with patch_critical_objects(stdout=_KUBECTL_VERSION) as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) metadata = cluster.GetResourceMetadata() self.assertEqual(issue_command.call_count, 1) self.assertContainsSubset( { 'project': 'fakeproject', 'cloud': 'GCP', 'cluster_type': 'Kubernetes', 'min_size': 1, 'size': 2, 'max_size': 3 }, metadata)
def testCreate(self): spec = self.create_kubernetes_engine_spec() with patch_critical_objects() as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) cluster._Create() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn('gcloud container clusters create', command_string) self.assertIn('--num-nodes 2', command_string) self.assertIn('--machine-type fake-machine-type', command_string) self.assertIn('--zone us-central1-a', command_string) self.assertIn('--min-cpu-platform skylake', command_string) self.assertIn('--disk-size 200', command_string) self.assertIn('--disk-type foo', command_string) self.assertIn('--local-ssd-count 2', command_string)
def testGetInstanceGroups(self): path = os.path.join(os.path.dirname(__file__), _NODE_POOLS_LIST_OUTPUT) output = open(path).read() spec = self.create_kubernetes_engine_spec() with patch_critical_objects(stdout=output) as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) instance_groups = cluster._GetInstanceGroups() command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn('gcloud container node-pools list', command_string) self.assertIn('--cluster', command_string) expected = set([ 'gke-pkb-0c47e6fa-default-pool-167d73ee-grp', 'gke-pkb-0c47e6fa-test-efea7796-grp' ]) self.assertEqual(expected, set(instance_groups)) # order doesn't matter
def testGetResourceMetadata(self): spec = self.create_kubernetes_engine_spec() with patch_critical_objects(stdout=_KUBECTL_VERSION) as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) metadata = cluster.GetResourceMetadata() self.assertEqual(issue_command.call_count, 1) self.assertContainsSubset( { 'project': 'fakeproject', 'gce_local_ssd_count': 2, 'gce_local_ssd_interface': 'SCSI', 'machine_type': 'fake-machine-type', 'boot_disk_type': 'foo', 'boot_disk_size': 200, 'cloud': 'GCP', 'cluster_type': 'Kubernetes', 'zone': 'us-central1-a', 'size': 2, 'container_cluster_version': 'v1.2.3', }, metadata)
def testGetInstancesFromInstanceGroups(self): instance_group_name = 'gke-pkb-0c47e6fa-default-pool-167d73ee-grp' path = os.path.join(os.path.dirname(__file__), _INSTANCE_GROUPS_LIST_OUTPUT) output = open(path).read() spec = self.create_kubernetes_engine_spec() with patch_critical_objects(stdout=output) as issue_command: cluster = google_kubernetes_engine.GkeCluster(spec) instances = cluster._GetInstancesFromInstanceGroup(instance_group_name) command_string = ' '.join(issue_command.call_args[0][0]) self.assertEqual(issue_command.call_count, 1) self.assertIn( 'gcloud compute instance-groups list-instances ' 'gke-pkb-0c47e6fa-default-pool-167d73ee-grp', command_string) expected = set([ 'gke-pkb-0c47e6fa-default-pool-167d73ee-hmwk', 'gke-pkb-0c47e6fa-default-pool-167d73ee-t854' ]) self.assertEqual(expected, set(instances)) # order doesn't matter