Example #1
0
class OpenStackBaseConnectionTest(unittest.TestCase):
    def setUp(self):
        self.timeout = 10
        OpenStackBaseConnection.conn_class = Mock()
        self.connection = OpenStackBaseConnection(
            'foo',
            'bar',
            timeout=self.timeout,
            ex_force_auth_url='https://127.0.0.1')
        self.connection.driver = Mock()
        self.connection.driver.name = 'OpenStackDriver'

    def tearDown(self):
        OpenStackBaseConnection.conn_class = LibcloudConnection

    def test_base_connection_timeout(self):
        self.connection.connect()
        self.assertEqual(self.connection.timeout, self.timeout)
        if PY25:
            self.connection.conn_class.assert_called_with(host='127.0.0.1',
                                                          port=443)
        else:
            self.connection.conn_class.assert_called_with(host='127.0.0.1',
                                                          secure=1,
                                                          port=443,
                                                          timeout=10)
 def setUp(self):
     self.timeout = 10
     OpenStackBaseConnection.conn_class = Mock()
     self.connection = OpenStackBaseConnection('foo', 'bar',
                                               timeout=self.timeout,
                                               ex_force_auth_url='https://127.0.0.1')
     self.connection.driver = Mock()
     self.connection.driver.name = 'OpenStackDriver'
Example #3
0
 def setUp(self):
     self.timeout = 10
     OpenStackBaseConnection.conn_class = Mock()
     self.connection = OpenStackBaseConnection(
         "foo",
         "bar",
         timeout=self.timeout,
         ex_force_auth_url="https://127.0.0.1")
     self.connection.driver = Mock()
     self.connection.driver.name = "OpenStackDriver"
Example #4
0
    def _get_mock_connection(self, mock_http_class, auth_url=None):
        OpenStackBaseConnection.conn_class = mock_http_class

        if auth_url is None:
            auth_url = "https://auth.api.example.com"

        OpenStackBaseConnection.auth_url = auth_url
        connection = OpenStackBaseConnection(*OPENSTACK_PARAMS)

        connection._ex_force_base_url = "https://www.foo.com"
        connection.driver = OpenStack_1_0_NodeDriver(*OPENSTACK_PARAMS)

        return connection
    def _get_mock_connection(self, mock_http_class, auth_url=None):
        OpenStackBaseConnection.conn_class = mock_http_class

        if auth_url is None:
            auth_url = "https://auth.api.example.com"

        OpenStackBaseConnection.auth_url = auth_url
        connection = OpenStackBaseConnection(*OPENSTACK_PARAMS)

        connection._ex_force_base_url = "https://www.foo.com"
        connection.driver = OpenStack_1_0_NodeDriver(*OPENSTACK_PARAMS)

        return connection
Example #6
0
class OpenStackBaseConnectionTest(unittest.TestCase):
    def setUp(self):
        self.timeout = 10
        OpenStackBaseConnection.conn_class = Mock()
        self.connection = OpenStackBaseConnection(
            "foo",
            "bar",
            timeout=self.timeout,
            ex_force_auth_url="https://127.0.0.1")
        self.connection.driver = Mock()
        self.connection.driver.name = "OpenStackDriver"

    def tearDown(self):
        OpenStackBaseConnection.conn_class = LibcloudConnection

    def test_base_connection_timeout(self):
        self.connection.connect()
        self.assertEqual(self.connection.timeout, self.timeout)
        self.connection.conn_class.assert_called_with(host="127.0.0.1",
                                                      secure=1,
                                                      port=443,
                                                      timeout=10)

    def test_set_microversion(self):
        self.connection._ex_force_microversion = "2.67"
        headers = self.connection.add_default_headers({})
        self.assertEqual(headers["OpenStack-API-Version"], "compute 2.67")

    @patch("libcloud.common.base.ConnectionUserAndKey.request")
    def test_request(self, mock_request):
        OpenStackBaseConnection.conn_class._raw_data = ""
        OpenStackBaseConnection.default_content_type = "application/json"
        expected_response = Mock()
        mock_request.return_value = expected_response
        response = self.connection.request("/path",
                                           data="somedata",
                                           headers={"h1": "v1"},
                                           method="POST")
        self.assertEqual(response, expected_response)
        mock_request.assert_called_with(
            action="/path",
            params={},
            data="somedata",
            method="POST",
            headers={
                "h1": "v1",
                "Content-Type": "application/json"
            },
            raw=False,
        )
 def setUp(self):
     self.timeout = 10
     OpenStackBaseConnection.conn_class = Mock()
     self.connection = OpenStackBaseConnection('foo', 'bar',
                                               timeout=self.timeout,
                                               ex_force_auth_url='https://127.0.0.1')
     self.connection.driver = Mock()
     self.connection.driver.name = 'OpenStackDriver'
Example #8
0
class OpenStackBaseConnectionTest(unittest.TestCase):
    def setUp(self):
        self.timeout = 10
        OpenStackBaseConnection.conn_classes = (None, Mock())
        self.connection = OpenStackBaseConnection('foo', 'bar',
                                                  timeout=self.timeout,
                                                  ex_force_auth_url='https://127.0.0.1')
        self.connection.driver = Mock()
        self.connection.driver.name = 'OpenStackDriver'

    def test_base_connection_timeout(self):
        self.connection.connect()
        self.assertEqual(self.connection.timeout, self.timeout)
        if PY25:
            self.connection.conn_classes[1].assert_called_with(host='127.0.0.1',
                                                               port=443)
        else:
            self.connection.conn_classes[1].assert_called_with(host='127.0.0.1',
                                                               port=443,
                                                               timeout=10)