Ejemplo n.º 1
0
    def setUp(self):
        """Set an elastic search config var."""
        super(OtterHistoryTestCase, self).setUp()
        self.root = Otter(None, 'ord', es_host='http://dummy').app.resource()
        set_config_data({
            'limits': {'pagination': 20},
            'url_root': 'http://localhost'})

        self.addCleanup(set_config_data, {})

        self.log = patch(self, 'otter.rest.history.log', new=mock_log())
        self.make_auditlog_query = patch(
            self, 'otter.rest.history.make_auditlog_query',
            return_value={'tenant_id': 101010})

        self.treq = patch(self, 'otter.rest.history.treq', new=mock_treq(
            code=200, method='get', json_content={
                'hits': {
                    'hits': [{
                        '_source': {
                            'message': 'audit log event',
                            'event_type': 'event-abc',
                            '@timestamp': 1234567890,
                            'policy_id': 'policy-xyz',
                            'scaling_group_id': 'scaling-group-uvw',
                            'server_id': 'server-rst',
                            'throwaway_key': 'ignore me!!!!'
                        }
                    }]
                }
            }))
Ejemplo n.º 2
0
 def setUp(self):
     """
     Mock treq
     """
     self.log = mock_log()
     self.treq = patch(self, "otter.worker.validate_config.treq", new=mock_treq(code=200, method="get"))
     patch(self, "otter.util.http.treq", new=self.treq)
     self.headers = {"content-type": ["application/json"], "accept": ["application/json"]}
Ejemplo n.º 3
0
 def setUp(self):
     """
     Mock treq
     """
     self.log = mock_log()
     self.treq = patch(self, 'otter.worker.validate_config.treq',
                       new=mock_treq(code=200, method='get'))
     patch(self, 'otter.util.http.treq', new=self.treq)
     self.headers = {'content-type': ['application/json'],
                     'accept': ['application/json'],
                     'User-Agent': ['OtterScale/0.0']}
Ejemplo n.º 4
0
    def test_valid(self):
        """Result is successful when stack preview returns success."""
        self.patch_treq(
            mock_treq(code=200, json_content={'stack': {}}, method='post'))

        d = validate_launch_stack_config(self.log, 'dfw', 'catalog', 'token',
                                         self.launch_config)

        self.successResultOf(d)
        self.treq.post.assert_called_with('https://service/stacks/preview',
                                          json.dumps(self.expected_args),
                                          headers=headers('token'),
                                          log=self.log)
Ejemplo n.º 5
0
 def setUp(self):
     """
     Mock treq
     """
     self.log = mock_log()
     limits = {"limits": {"absolute": {"maxPersonality": 1, "maxPersonalitySize": 35}}}
     self.treq = patch(
         self, "otter.worker.validate_config.treq", new=mock_treq(code=200, method="get", json_content=limits)
     )
     patch(self, "otter.util.http.treq", new=self.treq)
     self.personality = [
         {"path": "/etc/banner.txt", "contents": base64.b64encode("This is a test of base64 encoding")}
     ]
     self.headers = {"content-type": ["application/json"], "accept": ["application/json"]}
Ejemplo n.º 6
0
 def setUp(self):
     """
     Mock treq
     """
     self.log = mock_log()
     limits = {'limits': {'absolute': {'maxPersonality': 1, 'maxPersonalitySize': 35}}}
     self.treq = patch(self, 'otter.worker.validate_config.treq',
                       new=mock_treq(code=200, method='get', json_content=limits))
     patch(self, 'otter.util.http.treq', new=self.treq)
     self.personality = [
         {'path': '/etc/banner.txt',
          'contents': base64.b64encode('This is a test of base64 encoding')}
     ]
     self.headers = {'content-type': ['application/json'],
                     'accept': ['application/json'],
                     'User-Agent': ['OtterScale/0.0']}
Ejemplo n.º 7
0
    def test_invalid(self):
        """
        Certain 40x responses should be handled and result in
        InvalidLaunchConfiguration.
        """
        for code in [400, 404, 409]:
            json_content = {"explanation": "some explanation %s" % code}

            self.patch_treq(mock_treq(code=code,
                                      json_content=json_content,
                                      content=json.dumps(json_content),
                                      method='post'))

            d = validate_launch_stack_config(self.log, 'dfw', 'catalog',
                                             'token', self.launch_config)

            f = self.failureResultOf(d, InvalidLaunchConfiguration)
            self.assertEqual(f.value.message, json.dumps(json_content))
Ejemplo n.º 8
0
 def _treq(self, **kwargs):
     treq = mock_treq(**kwargs)
     patch(self, 'otter.util.http.treq', new=treq)
     return treq