Ejemplo n.º 1
0
 def testPrompting(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.
             InstanceGroupManagersListManagedInstancesResponse(
                 managedInstances=(
                     test_resources.MakeInstancesInManagedInstanceGroup(
                         self.messages, self.API_VERSION)))
         ],
     ])
     self.WriteInput('2\n')
     self.Run("""
     compute instance-groups managed list-instances group-1
     """)
     self.AssertOutputEquals(textwrap.dedent("""\
         NAME   ZONE       STATUS  HEALTH_STATE ACTION     PRESERVED_STATE INSTANCE_TEMPLATE VERSION_NAME LAST_ERROR
         inst-1 central2-a RUNNING HEALTHY      NONE                       template-1        xxx
         inst-2 central2-a STOPPED UNHEALTHY    RECREATING                 template-1
         inst-3 central2-a RUNNING TIMEOUT      DELETING                   template-2        yyy
         inst-4 central2-a                      CREATING                   template-3                     Error CONDITION_NOT_MET: True is not False, Error QUOTA_EXCEEDED: Limit is 5
         """),
                             normalize_space=True)
Ejemplo n.º 2
0
 def SetUp(self):
     self.SelectApi(self.API_VERSION)
     self.make_requests.side_effect = iter([
         [
             self.messages.
             InstanceGroupManagersListManagedInstancesResponse(
                 managedInstances=(
                     test_resources.MakeInstancesInManagedInstanceGroup(
                         self.messages, self.API_VERSION))),
         ],
     ])
Ejemplo n.º 3
0
    def testZonePrompt(self):
        self.StartPatch('googlecloudsdk.core.console.console_io.CanPrompt',
                        return_value=True)
        self.make_requests.side_effect = iter(
            [[
                self.messages.Region(name='central1'),
                self.messages.Region(name='central2'),
            ],
             [
                 self.messages.Zone(name='central1-a'),
                 self.messages.Zone(name='central1-b'),
                 self.messages.Zone(name='central2-a'),
             ],
             [
                 self.messages.
                 InstanceGroupManagersListManagedInstancesResponse(
                     managedInstances=(
                         test_resources.MakeInstancesInManagedInstanceGroup(
                             self.messages, self.API_VERSION)))
             ], []])
        self.WriteInput('2\n')
        self.Run("""
        compute instance-groups managed update-instances group-1
            --instances inst-1
        """)

        instances = self.messages.RegionInstanceGroupManagersApplyUpdatesRequest(
            instances=['{0}/projects/my-project/zones/central2-a/instances/'
                       'inst-1'.format(self.compute_uri)],
            minimalAction=\
                self.messages.RegionInstanceGroupManagersApplyUpdatesRequest \
                .MinimalActionValueValuesEnum.NONE,
            mostDisruptiveAllowedAction= \
                self.messages.RegionInstanceGroupManagersApplyUpdatesRequest \
                .MostDisruptiveAllowedActionValueValuesEnum.REPLACE)
        update_request = (
            self.messages.
            ComputeRegionInstanceGroupManagersApplyUpdatesToInstancesRequest(
                instanceGroupManager='group-1',
                regionInstanceGroupManagersApplyUpdatesRequest=instances,
                project='my-project',
                region='central2'))
        self.CheckRequests(
            self.regions_list_request,
            self.zones_list_request,
            [(self.compute.regionInstanceGroupManagers, 'ListManagedInstances',
              self.list_instances_request)],
            [(self.compute.regionInstanceGroupManagers,
              'ApplyUpdatesToInstances', update_request)],
        )
    def testZonePrompt(self):
        self.StartPatch('googlecloudsdk.core.console.console_io.CanPrompt',
                        return_value=True)
        self.make_requests.side_effect = iter(
            [[
                self.messages.Region(name='central1'),
                self.messages.Region(name='central2'),
            ],
             [
                 self.messages.Zone(name='central1-a'),
                 self.messages.Zone(name='central1-b'),
                 self.messages.Zone(name='central2-a'),
             ],
             [
                 self.messages.
                 InstanceGroupManagersListManagedInstancesResponse(
                     managedInstances=(
                         test_resources.MakeInstancesInManagedInstanceGroup(
                             self.messages, API_VERSION)))
             ], []])
        self.WriteInput('2\n')
        self.Run("""
        compute instance-groups managed recreate-instances group-1
            --instances inst-1
        """)

        instances = self.messages.RegionInstanceGroupManagersRecreateRequest(
            instances=[
                '{0}/projects/my-project/zones/central2-a/instances/inst-1'.
                format(self.compute_uri)
            ])
        recreate_request = (
            self.messages.
            ComputeRegionInstanceGroupManagersRecreateInstancesRequest(
                instanceGroupManager='group-1',
                regionInstanceGroupManagersRecreateRequest=instances,
                project='my-project',
                region='central2'))
        self.CheckRequests(
            self.regions_list_request,
            self.zones_list_request,
            [(self.compute.regionInstanceGroupManagers, 'ListManagedInstances',
              self.list_instances_request)],
            [(self.compute.regionInstanceGroupManagers, 'RecreateInstances',
              recreate_request)],
        )
Ejemplo n.º 5
0
 def SetUp(self):
     self.SelectApi(API_VERSION)
     self.make_requests.side_effect = iter([
         [
             self.messages.
             InstanceGroupManagersListManagedInstancesResponse(
                 managedInstances=(
                     test_resources.MakeInstancesInManagedInstanceGroup(
                         self.messages, API_VERSION)))
         ],
         [],
     ])
     self.list_instances_request = (
         self.messages.
         ComputeRegionInstanceGroupManagersListManagedInstancesRequest(
             instanceGroupManager='group-1',
             region='central2',
             project='my-project'))
Ejemplo n.º 6
0
 def SetUp(self):
   self.SelectApi(API_VERSION)
   self.make_requests.side_effect = iter([
       [self.messages.InstanceGroupManagersListManagedInstancesResponse(
           managedInstances=(
               test_resources.MakeInstancesInManagedInstanceGroup(
                   self.messages, API_VERSION)))],
       [],
   ])
   self.template_1_uri = (
       '{0}/projects/my-project/global/instanceTemplates/template-1'.format(
           self.compute_uri))
   self.list_instances_request = (
       self.messages.
       ComputeRegionInstanceGroupManagersListManagedInstancesRequest(
           instanceGroupManager='group-1',
           region='central2',
           project='my-project'))
Ejemplo n.º 7
0
    def SetUp(self):
        self.SelectApi(self.API_VERSION)
        self.endpoint_uri = (
            'https://compute.googleapis.com/compute/{api_version}/'.format(
                api_version=self.API_VERSION))
        self.project_uri = '{endpoint_uri}projects/fake-project'.format(
            endpoint_uri=self.endpoint_uri)

        managed_instances = test_resources.MakeInstancesInManagedInstanceGroup(
            self.messages, self.API_VERSION)

        # Add stateful policy to all 4 managed instances
        for i in range(len(managed_instances)):
            managed_instances[i].preservedStateFromPolicy = (
                policy_utils.MakePreservedState(self.messages, [
                    policy_utils.MakePreservedStateDisksMapEntry(
                        self.messages, {
                            'device_name': 'disk-a',
                            'auto_delete': 'never'
                        }),
                ]))

        # Add PICs to the last two managed instances
        source = self.project_uri + '/zones/central2-a/disks/baz'
        for managed_instance in managed_instances[2:]:
            managed_instance.preservedStateFromConfig = (
                config_utils.MakePreservedState(self.messages, [
                    config_utils.MakePreservedStateDiskMapEntry(
                        self.messages, 'disk-a', source, 'ro'),
                ]))

        self.make_requests.side_effect = iter([
            [
                self.messages.
                InstanceGroupManagersListManagedInstancesResponse(
                    managedInstances=managed_instances),
            ],
        ])