Ejemplo n.º 1
0
    def test_url_wait_for_no_work(self):
        def request_callback(request, uri, headers):
            return (400, headers, b"no worky")

        urls = ["http://www.yahoo.com", "http://www.google.com"]
        for url in urls:
            httpretty.register_uri(httpretty.GET, url, body=request_callback)

        self.assertIsNone(url_helper.wait_any_url(urls, max_wait=1))
Ejemplo n.º 2
0
    def test_url_wait_for_no_work(self):
        def request_callback(request, uri, headers):
            return (400, headers, b"no worky")

        urls = [
            "http://www.yahoo.com",
            "http://www.google.com",
        ]
        for url in urls:
            httpretty.register_uri(httpretty.GET, url, body=request_callback)

        self.assertIsNone(url_helper.wait_any_url(urls, max_wait=1))
Ejemplo n.º 3
0
    def _get_data(self, path):
        norm_path = self._path_join(self._config['metadata_url'], path)
        LOG.debug('Getting metadata from: %s', norm_path)
        response = url_helper.wait_any_url([norm_path],
                                           timeout=self._config['timeout'],
                                           max_wait=self._config['max_wait'])
        if response:
            _, request = response
            return base_source.APIResponse(request.contents,
                                           encoding=request.encoding)

        msg = "Metadata for url {0} was not accessible in due time"
        raise exceptions.CloudInitError(msg.format(norm_path))
Ejemplo n.º 4
0
    def _get_data(self, path):
        norm_path = self._path_join(self._config['metadata_url'], path)
        LOG.debug('Getting metadata from: %s', norm_path)
        response = url_helper.wait_any_url([norm_path],
                                           timeout=self._config['timeout'],
                                           max_wait=self._config['max_wait'])
        if response:
            _, request = response
            return base_source.APIResponse(request.contents,
                                           encoding=request.encoding)

        msg = "Metadata for url {0} was not accessible in due time"
        raise exceptions.CloudInitError(msg.format(norm_path))
Ejemplo n.º 5
0
    def test_url_wait_for(self):
        urls_actions = [
            ("http://www.yahoo.com", (False, False, True)),
            ("http://www.google.com", (False, False, False)),
        ]
        urls = []
        for (url, actions) in urls_actions:
            urls.append(url)
            for worked in actions:
                if worked:
                    httpretty.register_uri(httpretty.GET, url, body=b"it worked!")
                else:
                    httpretty.register_uri(httpretty.GET, url, body=b"no worky", status=400)

        url, response = url_helper.wait_any_url(urls)
        self.assertEqual("http://www.yahoo.com", url)
        self.assertIsInstance(response, url_helper.RequestsResponse)
        self.assertEqual(response.contents, b"it worked!")
Ejemplo n.º 6
0
    def test_url_wait_for(self):
        urls_actions = [
            ("http://www.yahoo.com", (False, False, True)),
            ("http://www.google.com", (False, False, False)),
        ]
        urls = []
        for (url, actions) in urls_actions:
            urls.append(url)
            for worked in actions:
                if worked:
                    httpretty.register_uri(httpretty.GET,
                                           url,
                                           body=b'it worked!')
                else:
                    httpretty.register_uri(httpretty.GET,
                                           url,
                                           body=b'no worky',
                                           status=400)

        url, response = url_helper.wait_any_url(urls)
        self.assertEqual("http://www.yahoo.com", url)
        self.assertIsInstance(response, url_helper.RequestsResponse)
        self.assertEqual(response.contents, b'it worked!')