Ejemplo n.º 1
0
    def testPostCreate(self, _, create_from_file_patch):
        spec = self.create_container_engine_spec()
        with patch_critical_objects() as issue_command:
            cluster = google_container_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'])

            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)
Ejemplo n.º 2
0
    def testCreateDefaultVersion(self):
        spec = self.create_container_engine_spec()
        with patch_critical_objects() as issue_command:
            cluster = google_container_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)
Ejemplo n.º 3
0
    def testCreate(self):
        spec = self.create_container_engine_spec()
        with patch_critical_objects() as issue_command:
            cluster = google_container_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)
Ejemplo n.º 4
0
    def testDelete(self):
        spec = create_container_engine_spec()
        with patch_critical_objects() as issue_command:
            cluster = google_container_engine.GkeCluster(spec)
            cluster._Delete()
            command_string = ' '.join(issue_command.call_args[0][0])

            self.assertEqual(issue_command.call_count, 1)
            self.assertIn(
                'gcloud container clusters delete pkb-{0}'.format(_RUN_URI),
                command_string)
    def testCreateCustomVersion(self):
        spec = self.create_container_engine_spec()
        flags = mock_flags.MockFlags()
        flags.container_cluster_version = 'fake-version'
        with patch_critical_objects(flags=flags) as issue_command:
            cluster = google_container_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)
Ejemplo n.º 6
0
    def testPostCreate(self):
        spec = create_container_engine_spec()
        with patch_critical_objects() as issue_command:
            cluster = google_container_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 testCreateResourcesExhausted(self):
     spec = self.create_container_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_container_engine.GkeCluster(spec)
         with self.assertRaises(
                 errors.Benchmarks.InsufficientCapacityCloudFailure):
             cluster._Create()
         self.assertEqual(issue_command.call_count, 1)
  def testCreate(self):
    spec = self.create_container_engine_spec()
    with patch_critical_objects() as issue_command:
      cluster = google_container_engine.GkeCluster(spec)
      cluster._Create()
      command_string = ' '.join(issue_command.call_args[0][0])

      self.assertEqual(issue_command.call_count, 1)
      self.assertIn('gcloud beta 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 testPostCreate(self, create_from_file_patch):
    spec = self.create_container_engine_spec()
    with patch_critical_objects() as issue_command:
      cluster = google_container_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'])

      create_from_file_patch.assert_called_with(
          _NVIDIA_DRIVER_SETUP_DAEMON_SET_SCRIPT)
Ejemplo n.º 10
0
    def testGetInstanceGroups(self):
        path = os.path.join(os.path.dirname(__file__), _NODE_POOLS_LIST_OUTPUT)
        output = open(path).read()
        spec = self.create_container_engine_spec()
        with patch_critical_objects(stdout=output) as issue_command:
            cluster = google_container_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
Ejemplo n.º 11
0
    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_container_engine_spec()
        with patch_critical_objects(stdout=output) as issue_command:
            cluster = google_container_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