Esempio n. 1
0
    def testSetOverwritesExisting(self):
        config_name = 'projects/{0}/configs/foo'.format(self.Project())
        var_name = 'projects/{0}/configs/foo/variables/var1'.format(
            self.Project())

        # Short names due to the long class names hitting 80 characters
        cr_req = self.messages.RuntimeconfigProjectsConfigsVariablesCreateRequest(
            parent=config_name,
            variable=self.messages.Variable(
                name=var_name,
                value=b'value1',
            ),
        )
        cr_exception = base.MakeHttpError(409, 'ALREADY_EXISTS')

        upd_req = self.messages.Variable(
            name=var_name,
            value=b'value1',
        )
        upd_result = self.messages.Variable(
            name=var_name,
            state=self.messages.Variable.StateValueValuesEnum.UPDATED,
            updateTime='2016-04-16T00:00:00Z',
            value=b'value1',
        )

        self.variable_client.Create.Expect(cr_req, exception=cr_exception)
        self.variable_client.Update.Expect(upd_req, upd_result)
        got_result = self.RunRuntimeConfig(
            'variables set var1 "value1" --config-name foo')

        self.assertEqual(util.FormatVariable(upd_result), got_result)
Esempio n. 2
0
    def testDeleteNotFound(self):
        request = self.messages.RuntimeconfigProjectsConfigsWaitersDeleteRequest(
            name='projects/{0}/configs/foo/waiters/bar'.format(
                self.Project()), )
        exception = base.MakeHttpError(code=404, status='NOT_FOUND')

        self.waiter_client.Delete.Expect(request, exception=exception)
        with self.assertRaises(exceptions.HttpException):
            self.RunRuntimeConfig('waiters delete bar --config-name foo')
Esempio n. 3
0
    def testDeleteNotFound(self):
        config_name = 'projects/{0}/configs/foobar'.format(self.Project())
        expected_request = self.messages.RuntimeconfigProjectsConfigsDeleteRequest(
            name=config_name, )
        wanted_exception = base.MakeHttpError(code=404, status='NOT_FOUND')

        self.config_client.Delete.Expect(expected_request,
                                         exception=wanted_exception)
        with self.assertRaises(exceptions.HttpException):
            self.RunRuntimeConfig('delete foobar')
    def testGetValueNotFound(self):
        var_name = 'projects/{0}/configs/foo/variables/var1'.format(
            self.Project())
        request = self.messages.RuntimeconfigProjectsConfigsVariablesGetRequest(
            name=var_name, )
        exception = base.MakeHttpError(code=404, status='NOT_FOUND')

        self.variable_client.Get.Expect(request, exception=exception)
        with self.assertRaises(exceptions.HttpException):
            self.RunRuntimeConfig('variables get-value var1 --config-name foo',
                                  output_enabled=True)
Esempio n. 5
0
    def testUnsetIgnoresNotFound(self):
        request = self.messages.RuntimeconfigProjectsConfigsVariablesDeleteRequest(
            name='projects/{0}/configs/foo/variables/var1'.format(
                self.Project()),
            recursive=False,
        )
        exception = base.MakeHttpError(code=404, status='NOT_FOUND')

        self.variable_client.Delete.Expect(request, exception=exception)

        # Should run without raising.
        self.RunRuntimeConfig('variables unset var1 --config-name foo')
Esempio n. 6
0
    def testUnsetFailIfAbsentFails(self):
        request = self.messages.RuntimeconfigProjectsConfigsVariablesDeleteRequest(
            name='projects/{0}/configs/foo/variables/var1'.format(
                self.Project()),
            recursive=False,
        )
        exception = base.MakeHttpError(code=404, status='NOT_FOUND')

        self.variable_client.Delete.Expect(request, exception=exception)
        with self.assertRaises(exceptions.HttpException):
            self.RunRuntimeConfig('variables unset var1 --config-name foo '
                                  '--fail-if-absent')
Esempio n. 7
0
    def testUpdateNotFound(self):
        config_name = 'projects/{0}/configs/foobar'.format(self.Project())
        expected_request = self.messages.RuntimeConfig(
            name=config_name,
            description='abcd',
        )
        wanted_exception = base.MakeHttpError(code=404, status='NOT_FOUND')

        self.config_client.Update.Expect(expected_request,
                                         exception=wanted_exception)
        with self.assertRaises(exceptions.HttpException):
            self.RunRuntimeConfig('update foobar --description="abcd"')
Esempio n. 8
0
    def testListNotFound(self):
        config_name = 'projects/{0}/configs/foo'.format(self.Project())
        request = self.messages.RuntimeconfigProjectsConfigsWaitersListRequest(
            parent=config_name,
            pageSize=self.DEFAULT_PAGE_SIZE,
        )
        exception = base.MakeHttpError(code=404, status='NOT_FOUND')

        self.waiter_client.List.Expect(request, exception=exception)
        with self.assertRaises(exceptions.HttpException):
            result = self.RunRuntimeConfig('waiters list --config-name foo')
            # Evaluate the returned generator to generate the exception
            list(result)
Esempio n. 9
0
    def testUnsetNonRecursiveFailure(self):
        request = self.messages.RuntimeconfigProjectsConfigsVariablesDeleteRequest(
            name='projects/{0}/configs/foo/variables/var1'.format(
                self.Project()),
            recursive=False,
        )
        exception = base.MakeHttpError(code=400,
                                       status='FAILED_PRECONDITION',
                                       message='Contains children')

        self.variable_client.Delete.Expect(request, exception=exception)
        with self.assertRaises(exceptions.HttpException):
            self.RunRuntimeConfig('variables unset var1 --config-name foo')
Esempio n. 10
0
    def testListNotFound(self):
        expected_request = self.messages.RuntimeconfigProjectsConfigsListRequest(
            parent='projects/{0}'.format(self.Project()),
            pageSize=self.DEFAULT_PAGE_SIZE,
        )
        wanted_exception = base.MakeHttpError(code=404, status='NOT_FOUND')

        self.config_client.List.Expect(expected_request,
                                       exception=wanted_exception)
        with self.assertRaises(exceptions.HttpException):
            result = self.RunRuntimeConfig('list')
            # Evaluate the returned generator to generate the exception
            list(result)
Esempio n. 11
0
    def testSetFailIfAbsentFails(self):
        # Tests that --fail-if-absent causees an error if the named
        # variable does not already exist.
        var_name = 'projects/{0}/configs/foo/variables/var1'.format(
            self.Project())
        request = self.messages.Variable(
            name=var_name,
            value=b'value1',
        )
        exception = base.MakeHttpError(404, 'NOT_FOUND')

        self.variable_client.Update.Expect(request, exception=exception)
        with self.assertRaises(exceptions.HttpException):
            self.RunRuntimeConfig(
                'variables set var1 "value1" --config-name foo '
                '--fail-if-absent')
Esempio n. 12
0
    def testWatchServerTimeout(self):
        var_name = 'projects/{0}/configs/foo/variables/var1'.format(
            self.Project())
        request = self.messages.RuntimeconfigProjectsConfigsVariablesWatchRequest(
            name=var_name,
            watchVariableRequest=self.messages.WatchVariableRequest(
                newerThan=None, ))
        exception = base.MakeHttpError(code=504, status='DEADLINE_EXCEEDED')

        self.variable_client.Watch.Expect(request, exception=exception)
        try:
            self.RunRuntimeConfig('variables watch var1 --config-name foo')
        except exceptions.OperationTimeoutError as e:
            self.assertEqual(e.exit_code, 2)  # 2 means we timed out
        else:
            self.fail('No exceptions.OperationTimeoutError raised')
Esempio n. 13
0
    def testCreateAlreadyExists(self):
        project_name = 'projects/{0}'.format(self.Project())
        config_name = 'projects/{0}/configs/foobar'.format(self.Project())
        expected_request = self.messages.RuntimeconfigProjectsConfigsCreateRequest(
            parent=project_name,
            runtimeConfig=self.messages.RuntimeConfig(
                name=config_name,
                description='baz baz',
            ),
        )
        wanted_exception = base.MakeHttpError(code=409,
                                              status='ALREADY_EXISTS')

        self.config_client.Create.Expect(expected_request,
                                         exception=wanted_exception)
        with self.assertRaises(exceptions.HttpException):
            self.RunRuntimeConfig('create foobar --description "baz baz"')
Esempio n. 14
0
    def testWatchNotFound(self):
        var_name = 'projects/{0}/configs/foo/variables/var1'.format(
            self.Project())
        request = self.messages.RuntimeconfigProjectsConfigsVariablesWatchRequest(
            name=var_name,
            watchVariableRequest=self.messages.WatchVariableRequest(
                newerThan=None, ))
        exception = base.MakeHttpError(code=404, status='NOT_FOUND')

        self.variable_client.Watch.Expect(request, exception=exception)
        try:
            self.RunRuntimeConfig('variables watch var1 --config-name foo')
        except api_exceptions.HttpException as e:
            self.assertEqual(e.exit_code,
                             1)  # 1 means something other than timeout
        else:
            self.fail('No HttpException raised')
Esempio n. 15
0
    def testSetFailIfPresentFails(self):
        # Tests that --fail-if-present causees an error if the named
        # variable already exists.
        config_name = 'projects/{0}/configs/foo'.format(self.Project())
        var_name = 'projects/{0}/configs/foo/variables/var1'.format(
            self.Project())
        request = self.messages.RuntimeconfigProjectsConfigsVariablesCreateRequest(
            parent=config_name,
            variable=self.messages.Variable(
                name=var_name,
                value=b'value1',
            ),
        )
        exception = base.MakeHttpError(409, 'ALREADY_EXISTS')

        self.variable_client.Create.Expect(request, exception=exception)
        with self.assertRaises(exceptions.HttpException):
            self.RunRuntimeConfig(
                'variables set var1 "value1" --config-name foo '
                '--fail-if-present')
Esempio n. 16
0
    def testCreateAlreadyExists(self):
        config_name = 'projects/{0}/configs/foo'.format(self.Project())
        waiter_name = 'projects/{0}/configs/foo/waiters/bar'.format(
            self.Project())
        request = self.messages.RuntimeconfigProjectsConfigsWaitersCreateRequest(
            parent=config_name,
            waiter=self.messages.Waiter(
                name=waiter_name,
                timeout='60s',
                success=self.messages.EndCondition(
                    cardinality=self.messages.Cardinality(
                        path='/success',
                        number=1,
                    ))),
        )
        exception = base.MakeHttpError(code=409, status='ALREADY_EXISTS')

        self.waiter_client.Create.Expect(request, exception=exception)
        with self.assertRaises(sdk_exceptions.HttpException):
            self.RunRuntimeConfig(
                'waiters create bar --config-name foo --timeout 1m '
                '--success-cardinality-path /success')