示例#1
0
    def testDescribeRegional(self):
        self.mock_client.regionInstanceGroups.Get.Expect(
            messages.ComputeRegionInstanceGroupsGetRequest(
                instanceGroup='group-1',
                project='fake-project',
                region='region-1'),
            test_resources.MakeInstanceGroups(messages,
                                              'alpha',
                                              scope_type='region',
                                              scope_name='region-1')[0])
        self.Run("""
        compute instance-groups describe group-1 --region region-1
        """)

        self.assertMultiLineEqual(
            encoding.Decode(self.stdout.getvalue()),
            textwrap.dedent("""\
            creationTimestamp: '2013-09-06T17:54:10.636-07:00'
            description: Test instance group
            fingerprint: MTIz
            name: group-1
            namedPorts:
            - name: serv-1
              port: 1111
            - name: serv-2
              port: 2222
            - name: serv-3
              port: 3333
            region: https://compute.googleapis.com/compute/alpha/projects/my-project/regions/region-1
            selfLink: https://compute.googleapis.com/compute/alpha/projects/my-project/regions/region-1/instanceGroups/group-1
            size: 0
            """))
示例#2
0
 def testScopePrompt(self):
     self.mock_client.instanceGroups.Get.Expect(
         messages.ComputeInstanceGroupsGetRequest(instanceGroup='group-1',
                                                  project='fake-project',
                                                  zone='zone-2'),
         test_resources.MakeInstanceGroups(messages, API_VERSION)[0])
     self.StartPatch('googlecloudsdk.core.console.console_io.CanPrompt',
                     return_value=True)
     self.StartPatch(
         'googlecloudsdk.api_lib.compute.zones.service.List',
         return_value=[
             messages.Zone(name='zone-1'),
             messages.Zone(name='zone-2')
         ],
     )
     self.StartPatch(
         'googlecloudsdk.api_lib.compute.regions.service.List',
         return_value=[messages.Region(name='region-1')],
     )
     self.WriteInput('3\n')
     self.Run("""
     compute instance-groups describe group-1
     """)
     self.AssertErrContains('group-1')
     self.AssertErrContains('zone-1')
     self.AssertErrContains('zone-2')
     self.AssertErrContains('region-1')
示例#3
0
    def testDescribeZonal(self):
        self.mock_client.instanceGroups.Get.Expect(
            messages.ComputeInstanceGroupsGetRequest(instanceGroup='group-1',
                                                     project='fake-project',
                                                     zone='zone-1'),
            test_resources.MakeInstanceGroups(messages, API_VERSION)[0])

        self.Run("""
        compute instance-groups describe group-1 --zone zone-1
        """)

        self.assertMultiLineEqual(
            encoding.Decode(self.stdout.getvalue()),
            textwrap.dedent("""\
            creationTimestamp: '2013-09-06T17:54:10.636-07:00'
            description: Test instance group
            fingerprint: MTIz
            name: group-1
            namedPorts:
            - name: serv-1
              port: 1111
            - name: serv-2
              port: 2222
            - name: serv-3
              port: 3333
            selfLink: https://compute.googleapis.com/compute/v1/projects/my-project/zones/zone-1/instanceGroups/group-1
            size: 0
            zone: https://compute.googleapis.com/compute/v1/projects/my-project/zones/zone-1
            """))
示例#4
0
 def testGetPortsScopePromptingZonalRegional(self):
    # ResourceArgument checks if this is true before attempting to prompt.
   self.StartPatch('googlecloudsdk.core.console.console_io.CanPrompt',
                   return_value=True)
   self.make_requests.side_effect = iter([
       [self.messages.Region(name='central2')],
       [self.messages.Zone(name='central2-a'),
        self.messages.Zone(name='central2-b')],
       [test_resources.MakeInstanceGroups(self.messages,
                                          self.api,
                                          scope_name='region-1',
                                          scope_type='region')[0]],
   ])
   self.WriteInput('1\n')
   self.Run("""
       compute instance-groups get-named-ports group-1
       """)
   self.CheckRequests(
       self.regions_list_request,
       self.zones_list_request,
       [(self.compute.regionInstanceGroups,
         'Get',
         self.messages.ComputeRegionInstanceGroupsGetRequest(
             instanceGroup='group-1',
             project='my-project',
             region='central2'))],
   )
   self.AssertOutputEquals(
       textwrap.dedent("""\
           NAME   PORT
           serv-1 1111
           serv-2 2222
           serv-3 3333
           """), normalize_space=True)
示例#5
0
 def _MockGetZonalResources(service, project, requested_zones,
                            filter_expr, http, batch_url, errors):
     _ = project, requested_zones, filter_expr, http, batch_url, errors
     if 'InstanceGroupsService' in str(type(service)):
         return test_resources.MakeInstanceGroups(
             self.messages, API_VERSION)
     return None
示例#6
0
 def _MockGetRegionalResources(service, project, requested_regions,
                               filter_expr, http, batch_url, errors):
     _ = project, requested_regions, filter_expr, http, batch_url, errors
     if 'RegionInstanceGroupsService' in str(type(service)):
         return test_resources.MakeInstanceGroups(msgs=self.messages,
                                                  api=API_VERSION,
                                                  scope_name='region-1',
                                                  scope_type='region')
     return None
示例#7
0
 def _MockMakeRequests(requests, batch_url, *unused_args, **unused_kwargs):
   _ = batch_url, unused_args, unused_kwargs
   if len(requests) != 1:
     self.fail('expected to send single request, sent: ' + str(requests))
   service = requests[0][0]
   verb = requests[0][1]
   if verb != 'Get':
     self.fail('expected GET verb, sent: ' + str(verb))
   if service == self.compute.instanceGroups:
     return [test_resources.MakeInstanceGroups(self.messages,
                                               api_version)[0]]
   elif service == self.compute.regionInstanceGroups:
     return [test_resources.MakeInstanceGroups(self.messages,
                                               api_version,
                                               scope_name='region-1',
                                               scope_type='region')[0]]
   else:
     self.fail('expected IG request, sent: ' + str(service))
示例#8
0
 def _MockMakeRequests(requests, batch_url, *unused_args,
                       **unused_kwargs):
     _ = batch_url, unused_args, unused_kwargs
     if len(requests) != 1:
         self.fail('expected to send single request, sent: ' +
                   str(requests))
     service = requests[0][0]
     verb = requests[0][1]
     if verb == 'AggregatedList':
         if service == self.compute.instanceGroupManagers:
             return (
                 test_resources.MakeInstanceGroupManagers(api_version) +
                 test_resources.MakeInstanceGroupManagers(
                     api=api_version,
                     scope_name='region-1',
                     scope_type='region'))
         elif service == self.compute.instanceGroups:
             return (test_resources.MakeInstanceGroups(
                 self.messages, api_version) +
                     test_resources.MakeInstanceGroups(
                         self.messages,
                         api=api_version,
                         scope_name='region-1',
                         scope_type='region'))
     if verb == 'List':
         if service == self.compute.instanceGroups:
             return test_resources.MakeInstanceGroups(
                 self.messages, api_version)
         elif service == self.compute.regionInstanceGroups:
             return test_resources.MakeInstanceGroups(
                 self.messages,
                 api=api_version,
                 scope_name='region-1',
                 scope_type='region')
         elif service == self.compute.instanceGroupManagers:
             return test_resources.MakeInstanceGroupManagers(
                 api_version)
         elif service == self.compute.regionInstanceGroupManagers:
             return test_resources.MakeInstanceGroupManagers(
                 api=api_version,
                 scope_name='region-1',
                 scope_type='region')
     else:
         self.fail('unexpected request ' + str(requests[0]))
 def SetUp(self):
     self.SelectApi(API_VERSION)
     self.make_requests.side_effect = iter([
         [
             test_resources.MakeInstanceGroups(msgs=self.messages,
                                               api=API_VERSION,
                                               scope_type='region',
                                               scope_name='central2')[0]
         ],
     ])
示例#10
0
 def _SetUpZonal(self, api_version):
     self.SelectApi(api_version)
     self.zone = 'us-central2-a'
     self.scope_params = ('zone', self.zone)
     self.make_requests.side_effect = iter([
         [
             self.messages.Zone(name=self.zone),
         ],
         [
             test_resources.MakeInstanceGroupManagers(
                 api_version, scope_name=self.zone)[0],
         ],
         [
             test_resources.MakeInstanceGroups(self.messages,
                                               api_version,
                                               scope_name=self.zone)[0],
         ],
         [
             test_resources.MakeAutoscalers(api_version,
                                            scope_name=self.zone)[0],
         ],
     ])
     self.zone_1_get_request = [
         (self.compute.zones, 'Get',
          self.messages.ComputeZonesGetRequest(project='my-project',
                                               zone=self.zone))
     ]
     self.zone_ig_list_request = [
         (self.compute.instanceGroups, 'List',
          self.messages.ComputeInstanceGroupsListRequest(
              maxResults=500,
              project='my-project',
              zone=self.zone,
          ))
     ]
     self.zone_as_list_request = [
         (self.compute.autoscalers, 'List',
          self.messages.ComputeAutoscalersListRequest(maxResults=500,
                                                      project='my-project',
                                                      zone=self.zone))
     ]
     self.template_1_uri = (
         '{0}/projects/my-project/global/instanceTemplates/template-1'.
         format(self.compute_uri))
     self.http_health_check_uri = (
         '{0}/projects/my-project/global/httpHealthChecks/health-check-1'.
         format(self.compute_uri))
     self.https_health_check_uri = (
         '{0}/projects/my-project/global/httpsHealthChecks/health-check-2'.
         format(self.compute_uri))
示例#11
0
 def _SetUpRegional(self, api_version):
     self.SelectApi(api_version)
     self.region = 'us-central2'
     self.scope_params = ('region', self.region)
     self.make_requests.side_effect = iter([
         [
             test_resources.MakeInstanceGroupManagers(
                 api_version, scope_name=self.region,
                 scope_type='region')[0],
         ],
         [
             test_resources.MakeInstanceGroups(self.messages,
                                               api_version,
                                               scope_name=self.region,
                                               scope_type='region')[0],
         ],
         [
             test_resources.MakeAutoscalers(api_version,
                                            scope_name=self.region,
                                            scope_type='region')[0],
         ],
     ])
     self.region_ig_list_request = [
         (self.compute.regionInstanceGroups, 'List',
          self.messages.ComputeRegionInstanceGroupsListRequest(
              maxResults=500,
              project='my-project',
              region=self.region,
          ))
     ]
     self.region_as_list_request = [
         (self.compute.regionAutoscalers, 'List',
          self.messages.ComputeRegionAutoscalersListRequest(
              maxResults=500, project='my-project', region=self.region))
     ]
     self.template_1_uri = (
         '{0}/projects/my-project/global/instanceTemplates/template-1'.
         format(self.compute_uri))
     self.http_health_check_uri = (
         '{0}/projects/my-project/global/httpHealthChecks/health-check-1'.
         format(self.compute_uri))
     self.https_health_check_uri = (
         '{0}/projects/my-project/global/httpsHealthChecks/health-check-2'.
         format(self.compute_uri))
     self.region_uri = ('{0}/projects/my-project/regions/{1}'.format(
         self.compute_uri, self.region))
 def testGetPortsSingleRow(self):
     self.make_requests.side_effect = iter([
         [test_resources.MakeInstanceGroups(self.messages, API_VERSION)[1]],
     ])
     self.Run("""
     compute instance-groups managed get-named-ports group-1
       --zone central2-a
     """)
     self.CheckRequests([(self.compute.instanceGroups, 'Get',
                          self.messages.ComputeInstanceGroupsGetRequest(
                              instanceGroup='group-1',
                              project='my-project',
                              zone='central2-a'))], )
     self.AssertOutputEquals(textwrap.dedent("""\
         NAME   PORT
         serv-1 1111
         """),
                             normalize_space=True)
示例#13
0
 def _MockGetZonalResources(service, project, requested_zones,
                            filter_expr, http, batch_url, errors):
     _ = project, requested_zones, filter_expr, http, batch_url, errors
     if service == self.compute.instanceGroupManagers:
         return test_resources.MakeInstanceGroupManagers(API_VERSION)
     if service == self.compute.instanceGroups:
         non_zonal_group = (self.messages.InstanceGroup(
             name='regional-group',
             selfLink=('https://compute.googleapis.com/compute/{0}/'
                       'projects/my-project/regions/region-1/'
                       'instanceGroups/group-1'.format(API_VERSION)),
             creationTimestamp='2013-09-06T17:54:10.636-07:00',
             description='Test regional instance group',
             fingerprint=b'123',
             namedPorts=[],
             size=0,
         ))
         return (test_resources.MakeInstanceGroups(
             self.messages, API_VERSION) + [non_zonal_group])
     return None
示例#14
0
    def testShowNotManaged(self):
        self.make_requests.side_effect = iter([
            [test_resources.MakeInstanceGroups(self.messages, API_VERSION)[0]],
            [],
        ])
        self.Run("""
        compute instance-groups unmanaged describe group-1
          --zone zone-1
        """)

        self.CheckRequests(
            [(self.compute.instanceGroups, 'Get',
              self.messages.ComputeInstanceGroupsGetRequest(
                  instanceGroup='group-1', project='my-project',
                  zone='zone-1'))],
            [(self.compute.instanceGroupManagers, 'List',
              self.messages.ComputeInstanceGroupManagersListRequest(
                  maxResults=500, project='my-project', zone='zone-1'))],
        )
        self.assertMultiLineEqual(
            self.GetOutput(),
            textwrap.dedent("""\
            creationTimestamp: '2013-09-06T17:54:10.636-07:00'
            description: Test instance group
            fingerprint: MTIz
            isManaged: No
            name: group-1
            namedPorts:
            - name: serv-1
              port: 1111
            - name: serv-2
              port: 2222
            - name: serv-3
              port: 3333
            selfLink: https://compute.googleapis.com/compute/{0}/projects/my-project/zones/zone-1/instanceGroups/group-1
            size: 0
            zone: https://compute.googleapis.com/compute/{0}/projects/my-project/zones/zone-1
            """.format(API_VERSION)))
 def testGetPortsSingleRow(self):
     self.make_requests.side_effect = iter([
         [
             test_resources.MakeInstanceGroups(msgs=self.messages,
                                               api=API_VERSION,
                                               scope_type='region',
                                               scope_name='central2')[1]
         ],
     ])
     self.Run("""
     compute instance-groups managed get-named-ports group-1
       --region central2
     """)
     self.CheckRequests(
         [(self.compute.regionInstanceGroups, 'Get',
           self.messages.ComputeRegionInstanceGroupsGetRequest(
               instanceGroup='group-1',
               project='my-project',
               region='central2'))], )
     self.AssertOutputEquals(textwrap.dedent("""\
         NAME   PORT
         serv-1 1111
         """),
                             normalize_space=True)
 def SetUp(self):
     self.SelectApi(API_VERSION)
     self.make_requests.side_effect = iter([
         [test_resources.MakeInstanceGroups(self.messages, API_VERSION)[0]],
     ])