コード例 #1
0
 def testInstanceCompletion(self):
     instances_list = data.GetDatabaseInstancesListOfTwo(
     ) + data.GetDatabaseInstancesListOfOne()
     self.StartObjectPatch(instances._BaseInstances,
                           'GetDatabaseInstances',
                           return_value=instances_list)
     completer = self.Completer(flags.InstanceCompleter, cli=self.cli)
     self.assertCountEqual(
         ['backupless-instance1', 'backupless-instance2', 'testinstance'],
         completer.Complete('', self.parameter_info))
コード例 #2
0
    def testGetDatabaseInstancesWithBatchSize(self):
        self.mocked_client.instances.List.Expect(
            self.messages.SqlInstancesListRequest(
                maxResults=10,
                project=self.Project(),
            ),
            self.messages.InstancesListResponse(
                items=data.GetDatabaseInstancesListOfOne(),
                kind='sql#instancesList',
                nextPageToken='10',
            ))
        self.mocked_client.instances.List.Expect(
            self.messages.SqlInstancesListRequest(
                pageToken='10',
                project=self.Project(),
                maxResults=10,
            ),
            self.messages.InstancesListResponse(
                items=data.GetDatabaseInstancesListOfTwo(),
                kind='sql#instancesList',
                nextPageToken=None,
            ))

        instance_list = data.GetDatabaseInstancesListOfOne(
        ) + data.GetDatabaseInstancesListOfTwo()
        instance_list[
            0].state = self.messages.DatabaseInstance.StateValueValuesEnum.RUNNABLE
        instance_list[
            0].settings.activationPolicy = self.messages.Settings.ActivationPolicyValueValuesEnum.NEVER

        expected_instance_list = [
            instances_util.DatabaseInstancePresentation(instance)
            for instance in instance_list
        ]

        self.assertEqual(
            expected_instance_list,
            list(
                instances_util._BaseInstances.GetDatabaseInstances(
                    batch_size=10)))
コード例 #3
0
    def testInstancesListWithIpAddresses(self):
        instances_list = data.GetDatabaseInstancesListOfTwo()
        instances_list[0].ipAddresses = [
            self.messages.IpMapping(
                ipAddress='11.11.11.11',
                timeToRetire=None,
                type=self.messages.IpMapping.TypeValueValuesEnum.PRIVATE,
            ),
            self.messages.IpMapping(
                ipAddress='10.10.10.10',
                timeToRetire=None,
                type=self.messages.IpMapping.TypeValueValuesEnum.PRIMARY,
            ),
        ]
        instances_list[1].ipAddresses = [
            self.messages.IpMapping(
                ipAddress='20.20.20.20',
                timeToRetire=None,
                type=self.messages.IpMapping.TypeValueValuesEnum.PRIMARY,
            ),
            self.messages.IpMapping(
                ipAddress='23.23.23.23',
                timeToRetire=None,
                type=self.messages.IpMapping.TypeValueValuesEnum.OUTGOING,
            ),
            self.messages.IpMapping(
                ipAddress='21.21.21.21',
                timeToRetire=None,
                type=self.messages.IpMapping.TypeValueValuesEnum.PRIVATE,
            ),
        ]
        mocked_database_instances = self.StartObjectPatch(
            instances._BaseInstances, 'GetDatabaseInstances')
        mocked_database_instances.return_value = instances_list

        self.Run('sql instances list')

        mocked_database_instances.assert_called_once()

        # pylint:disable=line-too-long
        self.AssertOutputContains("""\
NAME                 DATABASE_VERSION LOCATION      TIER PRIMARY_ADDRESS PRIVATE_ADDRESS STATUS
testinstance         MYSQL_5_5        us-central    D0   10.10.10.10     11.11.11.11     RUNNABLE
backupless-instance1 MYSQL_5_5        us-central1-a D1   20.20.20.20     21.21.21.21     RUNNABLE
""",
                                  normalize_space=True)
コード例 #4
0
    def testInstancesListWithLimit(self):
        instances_list = data.GetDatabaseInstancesListOfTwo(
        ) + data.GetDatabaseInstancesListOfOne()
        mocked_database_instances = self.StartObjectPatch(
            instances._BaseInstances, 'GetDatabaseInstances')
        mocked_database_instances.return_value = instances_list

        self.Run('sql instances list --limit=2')

        mocked_database_instances.assert_called_once()
        mocked_database_instances.assert_called_with(limit=2, batch_size=None)

        # pylint:disable=line-too-long
        self.AssertOutputContains("""\
NAME                 DATABASE_VERSION LOCATION      TIER PRIMARY_ADDRESS PRIVATE_ADDRESS STATUS
testinstance         MYSQL_5_5        us-central    D0   -               -               RUNNABLE
backupless-instance1 MYSQL_5_5        us-central1-a D1   -               -               RUNNABLE
""",
                                  normalize_space=True)
        self.AssertOutputNotContains('backupless-instance2')
コード例 #5
0
    def testInstancesList(self):
        instances_list = [
            instances.DatabaseInstancePresentation(instance)
            for instance in data.GetDatabaseInstancesListOfTwo() +
            data.GetDatabaseInstancesListOfOne()
        ]
        mocked_database_instances = self.StartObjectPatch(
            instances._BaseInstances, 'GetDatabaseInstances')
        mocked_database_instances.return_value = instances_list

        self.Run('sql instances list')

        mocked_database_instances.assert_called_once()

        # pylint:disable=line-too-long
        self.AssertOutputContains("""\
NAME                 DATABASE_VERSION LOCATION      TIER PRIMARY_ADDRESS PRIVATE_ADDRESS STATUS
testinstance         MYSQL_5_5        us-central    D0   -               -               RUNNABLE
backupless-instance1 MYSQL_5_5        us-central1-a D1   -               -               RUNNABLE
backupless-instance2 MYSQL_5_5        us-central    D1   -               -               STOPPED
""",
                                  normalize_space=True)