Esempio n. 1
0
    def test_create_stack(self):
        """
        create_stack POSTs data to the stack creation endpoint and returns
        the parsed JSON result.
        """
        log = mock_log()
        treq = self._treq(code=201, method='post',
                          json_content={'hello': 'world'})
        client = HeatClient('my-auth-token', log, treq)
        result = client.create_stack(
            'http://heat-url/', 'my-stack-name', {'p1': 'v1'}, 60,
            'my template')
        treq.post.assert_called_once_with(
            'http://heat-url/stacks',
            headers={'x-auth-token': ['my-auth-token'],
                     'content-type': ['application/json'],
                     'accept': ['application/json'],
                     'User-Agent': ['OtterScale/0.0']},
            data=json.dumps({'stack_name': 'my-stack-name',
                             'parameters': {'p1': 'v1'},
                             'timeout_mins': 60,
                             'template': 'my template'}),
            log=mock.ANY)

        self.assertEqual(self.successResultOf(result), {'hello': 'world'})
        self._assert_bound(log, treq.post.mock_calls[-1][2]['log'],
                           system='heatclient', event='create-stack',
                           stack_name='my-stack-name')
Esempio n. 2
0
 def test_create_stack_error(self):
     """
     On any result other than 201, create_stack raises an exception.
     """
     log = mock_log()
     treq = self._treq(code=404, method='post',
                       json_content={'hello': 'world'})
     client = HeatClient('my-auth-token', log, treq)
     result = client.create_stack(
         'http://heat-url/', 'my-stack-name', {'p1': 'v1'}, 60,
         'my template')
     failure = self.failureResultOf(result)
     failure.trap(APIError)