Ejemplo n.º 1
0
    def test_send_mixed_error(self):

        proxy = rest_proxy.JovianRESTProxy(CONFIG_MULTIHOST)

        json_data = {"data": None, "error": None}

        session_ret = mock.Mock()
        session_ret.text = json.dumps(json_data)
        session_ret.status_code = 200
        patches = [mock.patch.object(proxy.session, "send")]

        pr = 'prepared_request'

        self.start_patches(patches)

        side_effect = [requests.exceptions.ConnectionError()] * 4
        side_effect += [jexc.JDSSOSException()] * 4
        side_effect += [session_ret]

        proxy.session.send.side_effect = side_effect

        send_expected = [mock.call(pr)] * 7

        self.assertRaises(jexc.JDSSOSException, proxy._send, pr)

        proxy.session.send.assert_has_calls(send_expected)

        self.assertEqual(0, proxy.active_host)
Ejemplo n.º 2
0
    def __init__(self, config):

        self.pool = config.get('jovian_pool', 'Pool-0')
        self.rproxy = rest_proxy.JovianRESTProxy(config)

        self.resource_dne_msg = (
            re.compile(r'^Zfs resource: .* not found in this collection\.$'))
Ejemplo n.º 3
0
    def test_request_host_failure(self):

        proxy = rest_proxy.JovianRESTProxy(CONFIG_MULTIHOST)

        patches = [
            mock.patch.object(requests, "Request", return_value="request"),
            mock.patch.object(proxy.session,
                              "prepare_request",
                              return_value="out_data"),
            mock.patch.object(proxy, "_send", return_value="out_data")
        ]

        request_expected = [
            mock.call('GET', 'https://192.168.0.2:82/api/v3/pools/Pool-0'),
            mock.call('GET', 'https://192.168.0.3:82/api/v3/pools/Pool-0'),
            mock.call('GET', 'https://192.168.0.4:82/api/v3/pools/Pool-0')
        ]

        self.start_patches(patches)

        proxy._send.side_effect = [
            requests.exceptions.ConnectionError(),
            requests.exceptions.ConnectionError(), "out_data"
        ]

        proxy.request('GET', '/pools/Pool-0')
        self.assertEqual(2, proxy.active_host)
        requests.Request.assert_has_calls(request_expected)

        self.stop_patches(patches)
Ejemplo n.º 4
0
    def __init__(self, config):

        self.target_p = config.get('iscsi_target_prefix',
                                   'iqn.2020-04.com.open-e.cinder:')
        self.pool = config.safe_get('jovian_pool')
        self.rproxy = rest_proxy.JovianRESTProxy(config)

        self.resource_dne_msg = (
            re.compile(r'^Zfs resource: .* not found in this collection\.$'))
Ejemplo n.º 5
0
    def test_get_base_url(self):

        proxy = rest_proxy.JovianRESTProxy(CONFIG_OK)

        url = proxy._get_base_url()

        exp = '{proto}://{host}:{port}/api/v3'.format(proto='https',
                                                      host='192.168.0.2',
                                                      port='82')
        self.assertEqual(exp, url)
Ejemplo n.º 6
0
    def test_pool_request(self):

        proxy = rest_proxy.JovianRESTProxy(CONFIG_OK)

        patches = [mock.patch.object(proxy, "request")]

        req = '/pools/Pool-0/volumes'

        self.start_patches(patches)
        proxy.pool_request('GET', '/volumes')

        proxy.request.assert_called_once_with('GET', req, json_data=None)
        self.stop_patches(patches)
Ejemplo n.º 7
0
    def test_next_host(self):

        proxy = rest_proxy.JovianRESTProxy(CONFIG_MULTIHOST)

        self.assertEqual(0, proxy.active_host)
        proxy._next_host()

        self.assertEqual(1, proxy.active_host)
        proxy._next_host()

        self.assertEqual(2, proxy.active_host)
        proxy._next_host()

        self.assertEqual(0, proxy.active_host)
Ejemplo n.º 8
0
    def test_send(self):

        proxy = rest_proxy.JovianRESTProxy(CONFIG_MULTIHOST)

        json_data = {
            "data": [{
                "available": "949998694400",
                "status": 26,
                "name": "Pool-0",
                "scan": None,
                "encryption": {
                    "enabled": False
                },
                "iostats": {
                    "read": "0",
                    "write": "0",
                    "chksum": "0"
                },
                "vdevs": [{}],
                "health": "ONLINE",
                "operation": "none",
                "id": "12413634663904564349",
                "size": "996432412672"
            }],
            "error":
            None
        }
        session_ret = mock.Mock()
        session_ret.text = json.dumps(json_data)
        session_ret.status_code = 200
        patches = [
            mock.patch.object(proxy.session, "send", return_value=session_ret)
        ]

        pr = 'prepared_request'

        self.start_patches(patches)
        ret = proxy._send(pr)

        proxy.session.send.assert_called_once_with(pr)

        self.assertEqual(0, proxy.active_host)

        self.assertEqual(200, ret['code'])
        self.assertEqual(json_data['data'], ret['data'])
        self.assertEqual(json_data['error'], ret['error'])
        self.stop_patches(patches)
Ejemplo n.º 9
0
    def test_request(self):

        proxy = rest_proxy.JovianRESTProxy(CONFIG_MULTIHOST)

        patches = [
            mock.patch.object(requests, "Request", return_value="request"),
            mock.patch.object(proxy.session,
                              "prepare_request",
                              return_value="out_data"),
            mock.patch.object(proxy, "_send", return_value="out_data")
        ]

        addr = 'https://192.168.0.2:82/api/v3/pools/Pool-0'

        self.start_patches(patches)
        proxy.request('GET', '/pools/Pool-0')

        requests.Request.assert_called_once_with('GET', addr)
        self.stop_patches(patches)