Esempio n. 1
0
    def test_create_snapshot_fail(self):
        mock_api = self.mock_object(
            self._driver, '_api',
            mock.Mock(side_effect=(exception.TegileAPIException(
                response="Fake Exception"))))

        self.assertRaises(exception.TegileAPIException,
                          self._driver.create_snapshot, self._ctxt,
                          test_snapshot)

        share = {
            'poolName': 'fake_pool',
            'projectName': 'fake_project',
            'name': test_share['name'],
            'availableSize': 0,
            'totalSize': 0,
            'datasetPath': '%s/%s/%s' % (
                'fake_pool',
                'Local',
                'fake_project',
            ),
            'mountpoint': test_share['name'],
            'local': 'true',
        }
        create_params = (share, test_snapshot['name'], False)
        mock_api.assert_called_once_with('createShareSnapshot', create_params)
Esempio n. 2
0
    def test_get_share_stats_fail(self):
        mock_api = self.mock_object(
            self._driver, '_api',
            mock.Mock(side_effect=(exception.TegileAPIException(
                response="Fake Exception"))))

        self.assertRaises(exception.TegileAPIException,
                          self._driver.get_share_stats, True)

        mock_api.assert_called_once_with(fine_logging=False,
                                         method='getArrayStats',
                                         request_type='get')
Esempio n. 3
0
    def test_shrink_share_fail(self):
        mock_api = self.mock_object(
            self._driver, '_api',
            mock.Mock(side_effect=(exception.TegileAPIException(
                response="Fake Exception"))))

        self.assertRaises(exception.TegileAPIException,
                          self._driver.shrink_share, test_share, 30)

        shrink_path = '%s/%s/%s/%s' % ('fake_pool', 'Local', 'fake_project',
                                       test_share['name'])
        shrink_params = (shrink_path, six.text_type(30), 'GB')
        mock_api.assert_called_once_with('resizeShare', shrink_params)
Esempio n. 4
0
    def test_delete_share_fail(self):
        mock_api = self.mock_object(
            self._driver, '_api',
            mock.Mock(side_effect=(exception.TegileAPIException(
                response="Fake Exception"))))

        self.assertRaises(exception.TegileAPIException,
                          self._driver.delete_share, self._ctxt, test_share)

        delete_path = '%s/%s/%s/%s' % ('fake_pool', 'Local', 'fake_project',
                                       test_share['name'])
        delete_params = (delete_path, True, False)
        mock_api.assert_called_once_with('deleteShare', delete_params)
Esempio n. 5
0
    def test_deny_access_fail(self, access_type, to, share, exception_type):
        self.mock_object(
            self._driver, '_api',
            mock.Mock(side_effect=exception.TegileAPIException(
                response="Fake Exception")))

        access = {
            'access_type': access_type,
            'access_level': const.ACCESS_LEVEL_RW,
            'access_to': to,
        }

        self.assertRaises(exception_type, self._driver._deny_access,
                          self._ctxt, share, access)
Esempio n. 6
0
    def test_ensure_share_fail(self):
        mock_api = self.mock_object(
            self._driver, '_api',
            mock.Mock(side_effect=(exception.TegileAPIException(
                response="Fake Exception"))))
        self.assertRaises(exception.TegileAPIException,
                          self._driver.ensure_share, self._ctxt, test_share)

        ensure_params = [
            '%s/%s/%s/%s' %
            ('fake_pool', 'Local', 'fake_project', test_share['name'])
        ]
        mock_api.assert_called_once_with('getShareIPAndMountPoint',
                                         ensure_params)
Esempio n. 7
0
    def test_create_share_fail(self):
        mock_api = self.mock_object(
            self._driver, '_api',
            mock.Mock(side_effect=(exception.TegileAPIException(
                response="Fake Exception"))))

        self.assertRaises(exception.TegileAPIException,
                          self._driver.create_share, self._ctxt, test_share)

        create_params = (
            'fake_pool',
            'fake_project',
            test_share['name'],
            test_share['share_proto'],
        )
        mock_api.assert_called_once_with('createShare', create_params)
Esempio n. 8
0
    def test_delete_snapshot_fail(self):
        mock_api = self.mock_object(
            self._driver, '_api',
            mock.Mock(side_effect=(exception.TegileAPIException(
                response="Fake Exception"))))

        self.assertRaises(exception.TegileAPIException,
                          self._driver.delete_snapshot, self._ctxt,
                          test_snapshot)

        delete_snap_path = ('%s/%s/%s/%s@%s%s' % (
            'fake_pool',
            'Local',
            'fake_project',
            test_share['name'],
            'Manual-S-',
            test_snapshot['name'],
        ))
        delete_params = (delete_snap_path, False)
        mock_api.assert_called_once_with('deleteShareSnapshot', delete_params)
Esempio n. 9
0
    def test_create_share_from_snapshot_fail(self):
        mock_api = self.mock_object(
            self._driver, '_api',
            mock.Mock(side_effect=(exception.TegileAPIException(
                response="Fake Exception"))))

        self.assertRaises(exception.TegileAPIException,
                          self._driver.create_share_from_snapshot, self._ctxt,
                          test_share, test_snapshot)

        create_params = (
            '%s/%s/%s/%s@%s%s' % (
                'fake_pool',
                'Local',
                'fake_project',
                test_snapshot['share_name'],
                'Manual-S-',
                test_snapshot['name'],
            ),
            test_share['name'],
            True,
        )
        mock_api.assert_called_once_with('cloneShareSnapshot', create_params)
Esempio n. 10
0
    def _send_api_request(self,
                          method,
                          params=None,
                          request_type='post',
                          api_service=DEFAULT_API_SERVICE,
                          fine_logging=DEBUG_LOGGING):
        if params is not None:
            params = json.dumps(params)

        url = 'https://%s/%s/%s/%s' % (self._hostname, TEGILE_API_PATH,
                                       api_service, method)
        if fine_logging:
            LOG.debug(
                'TegileAPIExecutor(%(classname)s) method: %(method)s, '
                'url: %(url)s', {
                    'classname': self._classname,
                    'method': method,
                    'url': url,
                })
        if request_type == 'post':
            if fine_logging:
                LOG.debug(
                    'TegileAPIExecutor(%(classname)s) '
                    'method: %(method)s, payload: %(payload)s', {
                        'classname': self._classname,
                        'method': method,
                        'payload': params,
                    })
            req = requests.post(url,
                                data=params,
                                auth=(self._username, self._password),
                                verify=False)
        else:
            req = requests.get(url,
                               auth=(self._username, self._password),
                               verify=False)

        if fine_logging:
            LOG.debug(
                'TegileAPIExecutor(%(classname)s) method: %(method)s, '
                'return code: %(retcode)s', {
                    'classname': self._classname,
                    'method': method,
                    'retcode': req,
                })
        try:
            response = req.json()
            if fine_logging:
                LOG.debug(
                    'TegileAPIExecutor(%(classname)s) '
                    'method: %(method)s, response: %(response)s', {
                        'classname': self._classname,
                        'method': method,
                        'response': response,
                    })
        except ValueError:
            # Some APIs don't return output and that's fine
            response = ''
        req.close()

        if req.status_code != 200:
            raise exception.TegileAPIException(response=req.text)

        return response
Esempio n. 11
0
            'QoS_support': False,
            'free_capacity_gb': 2740.148867149747,
            'reserved_percentage': 0,
            'pool_name': 'cobalt',
        },
        {
            'total_capacity_gb': 913.5,
            'QoS_support': False,
            'free_capacity_gb': 913.4198722839355,
            'reserved_percentage': 0,
            'pool_name': 'test',
        },
    ],
}

fake_tegile_backend_fail = mock.Mock(side_effect=exception.TegileAPIException(
    response="Fake Exception"))


class FakeResponse(object):
    def __init__(self, status, json_output):
        self.status_code = status
        self.text = 'Random text'
        self._json = json_output

    def json(self):
        return self._json

    def close(self):
        pass