예제 #1
0
class VolumesTest(unittest.TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._volumes = Volumes(self.connection)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._volumes.get_all(2, 500, filter, sort)

        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_called_once(self, mock_get_by):
        self._volumes.get_by('name', 'Test Volume')

        mock_get_by.assert_called_once_with('name', 'Test Volume')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_id_called_once(self, mock_get):
        self._volumes.get('3518be0e-17c1-4189-8f81-83f3724f6155')

        mock_get.assert_called_once_with(
            '3518be0e-17c1-4189-8f81-83f3724f6155')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_uri_called_once(self, mock_get):
        self._volumes.get(
            '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155')

        mock_get.assert_called_once_with(
            '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155')

    @mock.patch.object(ResourceClient, 'create')
    def test_create_called_once(self, mock_create):
        resource = {'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'}
        resource_rest_call = resource.copy()
        mock_create.return_value = {}

        self._volumes.create(resource)
        mock_create.assert_called_once_with(resource_rest_call, timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once(self, mock_update):
        resource = {
            'uri':
            '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155',
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()

        self._volumes.update(resource)

        mock_update.assert_called_once_with(resource_rest_call,
                                            timeout=-1,
                                            force=False)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once_with_force(self, mock_update):
        resource = {
            'uri':
            '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155',
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()

        self._volumes.update(resource, force=True)

        mock_update.assert_called_once_with(resource_rest_call,
                                            timeout=mock.ANY,
                                            force=True)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_by_id_called_once(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._volumes.delete(id, force=False, timeout=-1)

        expected_headers = {"exportOnly": False}
        mock_delete.assert_called_once_with(id,
                                            force=False,
                                            timeout=-1,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_with_force_called_once(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._volumes.delete(id, force=True)

        mock_delete.assert_called_once_with(mock.ANY,
                                            force=True,
                                            timeout=mock.ANY,
                                            custom_headers=mock.ANY)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_only_from_oneview_called_once(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._volumes.delete(id, export_only=True)

        expected_headers = {"exportOnly": True}
        mock_delete.assert_called_once_with(id,
                                            force=mock.ANY,
                                            timeout=mock.ANY,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_snapshots_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/'

        self._volumes.get_snapshots(volume_id, 2, 500, filter, sort)
        mock_get_all.assert_called_once_with(2,
                                             500,
                                             filter=filter,
                                             sort=sort,
                                             uri=uri)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_snapshots_called_once_with_default(self, mock_get_all):
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/'
        self._volumes.get_snapshots(volume_id)
        mock_get_all.assert_called_once_with(0,
                                             -1,
                                             filter='',
                                             sort='',
                                             uri=uri)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_snapshot_by_id_called_once(self, mock_get):
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        snapshot_id = '78216B75-3CC4-4444-BB5B-13C7504675'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/78216B75-3CC4-4444-BB5B-13C7504675'
        self._volumes.get_snapshot(snapshot_id, volume_id)
        mock_get.assert_called_once_with(uri)

    def test_get_snapshot_by_id_without_volume_id_should_fail(self):
        snapshot_id = '78216B75-3CC4-4444-BB5B-13C7504675'
        try:
            self._volumes.get_snapshot(snapshot_id)
        except ValueError as e:
            self.assertEqual(INVALID_VOLUME_URI, e.args[0])
        else:
            self.fail("Expected exception was not raised")

    @mock.patch.object(ResourceClient, 'get')
    def test_get_get_snapshot_by_uri_called_once(self, mock_get):
        snapshot_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        self._volumes.get_snapshot(snapshot_uri)
        mock_get.assert_called_once_with(snapshot_uri)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_get_snapshot_by_uri_and_volume_id_called_once(self, mock_get):
        snapshot_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        self._volumes.get_snapshot(snapshot_uri, volume_id)
        mock_get.assert_called_once_with(snapshot_uri)

    @mock.patch.object(ResourceClient, 'create')
    def test_create_snapshot_should_use_default_values(self, mock_create):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/'
        resource = {
            'name': 'OneViewSDK Test Snapshot',
        }
        resource_with_default_values = {
            'name': 'OneViewSDK Test Snapshot',
            'type': 'Snapshot',
        }

        self._volumes.create_snapshot(volume_id, resource)
        mock_create.assert_called_once_with(resource_with_default_values,
                                            uri=uri,
                                            timeout=-1)

    @mock.patch.object(ResourceClient, 'create')
    def test_create_snapshot_should_use_given_values(self, mock_create):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/'
        resource = {
            'name': 'OneViewSDK Test Snapshot',
            'type': 'SnapshotV3',
        }

        self._volumes.create_snapshot(volume_id, resource)
        mock_create.assert_called_once_with(resource, uri=uri, timeout=-1)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_snapshot_called_once(self, mock_delete):
        resource = {
            'name':
            'OneViewSDK Test Snapshot',
            'type':
            'SnapshotV3',
            'uri':
            '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        }
        self._volumes.delete_snapshot(resource, force=True, timeout=50)

        mock_delete.assert_called_once_with(resource, force=True, timeout=50)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_snapshot_called_once_with_defaults(self, mock_delete):
        resource = {
            'name':
            'OneViewSDK Test Snapshot',
            'type':
            'SnapshotV3',
            'uri':
            '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        }
        self._volumes.delete_snapshot(resource)

        mock_delete.assert_called_once_with(resource, force=False, timeout=-1)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_snapshot_by_called_once(self, mock_get_by):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        volume_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/'
        self._volumes.get_snapshot_by(volume_id, "name", "test name")

        mock_get_by.assert_called_once_with("name",
                                            "test name",
                                            uri=volume_uri)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_extra_managed_storage_volume_paths_called_once(
            self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._volumes.get_extra_managed_storage_volume_paths(
            2, 500, filter, sort)

        expected_uri = '/rest/storage-volumes/repair?alertFixType=ExtraManagedStorageVolumePaths'
        mock_get_all.assert_called_once_with(2,
                                             500,
                                             uri=expected_uri,
                                             filter=filter,
                                             sort=sort)

    @mock.patch.object(ResourceClient, 'create')
    def test_repair_by_id_called_once(self, mock_create):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        data = {
            'resourceUri':
            '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC',
            'type': 'ExtraManagedStorageVolumePaths'
        }
        self._volumes.repair(volume_id)

        custom_headers = {u'Accept-Language': u'en_US'}
        mock_create.assert_called_once_with(data,
                                            uri='/rest/storage-volumes/repair',
                                            timeout=-1,
                                            custom_headers=custom_headers)

    @mock.patch.object(ResourceClient, 'create')
    def test_repair_by_uri_called_once(self, mock_create):
        volume_id = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC'
        data = {
            'resourceUri':
            '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC',
            'type': 'ExtraManagedStorageVolumePaths'
        }
        self._volumes.repair(volume_id)

        custom_headers = {u'Accept-Language': u'en_US'}
        mock_create.assert_called_once_with(data,
                                            uri='/rest/storage-volumes/repair',
                                            timeout=-1,
                                            custom_headers=custom_headers)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_attachable_volumes_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'
        query = 'availableNetworks IN [/rest/fc-networks/123-45-67,/rest/fc-networks/111-222-333]'

        self._volumes.get_attachable_volumes(2, 500, filter, query, sort)

        expected_uri = '/rest/storage-volumes/attachable-volumes'
        mock_get_all.assert_called_once_with(2,
                                             500,
                                             uri=expected_uri,
                                             filter=filter,
                                             query=query,
                                             sort=sort)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_attachable_volumes_called_with_default_values(
            self, mock_get_all):
        self._volumes.get_attachable_volumes()

        expected_uri = '/rest/storage-volumes/attachable-volumes'
        mock_get_all.assert_called_once_with(0,
                                             -1,
                                             uri=expected_uri,
                                             filter='',
                                             query='',
                                             sort='')
class VolumesTest(unittest.TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._volumes = Volumes(self.connection)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._volumes.get_all(2, 500, filter, sort)

        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_called_once(self, mock_get_by):
        self._volumes.get_by('name', 'Test Volume')

        mock_get_by.assert_called_once_with('name', 'Test Volume')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_id_called_once(self, mock_get):
        self._volumes.get('3518be0e-17c1-4189-8f81-83f3724f6155')

        mock_get.assert_called_once_with('3518be0e-17c1-4189-8f81-83f3724f6155')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_uri_called_once(self, mock_get):
        self._volumes.get('/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155')

        mock_get.assert_called_once_with('/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155')

    @mock.patch.object(ResourceClient, 'create')
    def test_create_called_once(self, mock_create):
        resource = {
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()
        mock_create.return_value = {}

        self._volumes.create(resource)
        mock_create.assert_called_once_with(resource_rest_call, timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once(self, mock_update):
        resource = {
            'uri': '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155',
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()

        self._volumes.update(resource)

        mock_update.assert_called_once_with(resource_rest_call, timeout=-1, force=False)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once_with_force(self, mock_update):
        resource = {
            'uri': '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155',
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()

        self._volumes.update(resource, force=True)

        mock_update.assert_called_once_with(resource_rest_call, timeout=mock.ANY, force=True)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_by_id_called_once(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._volumes.delete(id, force=False, timeout=-1)

        expected_headers = {"exportOnly": False}
        mock_delete.assert_called_once_with(id, force=False, timeout=-1, custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_with_force_called_once(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._volumes.delete(id, force=True)

        mock_delete.assert_called_once_with(mock.ANY, force=True, timeout=mock.ANY, custom_headers=mock.ANY)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_only_from_oneview_called_once(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._volumes.delete(id, export_only=True)

        expected_headers = {"exportOnly": True}
        mock_delete.assert_called_once_with(id, force=mock.ANY, timeout=mock.ANY, custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_snapshots_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/'

        self._volumes.get_snapshots(volume_id, 2, 500, filter, sort)
        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort, uri=uri)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_snapshots_called_once_with_default(self, mock_get_all):
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/'
        self._volumes.get_snapshots(volume_id)
        mock_get_all.assert_called_once_with(0, -1, filter='', sort='', uri=uri)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_snapshot_by_id_called_once(self, mock_get):
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        snapshot_id = '78216B75-3CC4-4444-BB5B-13C7504675'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/78216B75-3CC4-4444-BB5B-13C7504675'
        self._volumes.get_snapshot(snapshot_id, volume_id)
        mock_get.assert_called_once_with(uri)

    def test_get_snapshot_by_id_without_volume_id_should_fail(self):
        snapshot_id = '78216B75-3CC4-4444-BB5B-13C7504675'
        try:
            self._volumes.get_snapshot(snapshot_id)
        except ValueError as e:
            self.assertEqual(INVALID_VOLUME_URI, e.args[0])
        else:
            self.fail("Expected exception was not raised")

    @mock.patch.object(ResourceClient, 'get')
    def test_get_get_snapshot_by_uri_called_once(self, mock_get):
        snapshot_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        self._volumes.get_snapshot(snapshot_uri)
        mock_get.assert_called_once_with(snapshot_uri)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_get_snapshot_by_uri_and_volume_id_called_once(self, mock_get):
        snapshot_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        self._volumes.get_snapshot(snapshot_uri, volume_id)
        mock_get.assert_called_once_with(snapshot_uri)

    @mock.patch.object(ResourceClient, 'create')
    def test_create_snapshot_should_be_called_once(self, mock_create):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/'
        resource = {
            'name': 'OneViewSDK Test Snapshot',
        }

        self._volumes.create_snapshot(volume_id, resource, 20)
        mock_create.assert_called_once_with(resource, uri=uri, timeout=20,
                                            default_values=self._volumes.DEFAULT_VALUES_SNAPSHOT)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_snapshot_called_once(self, mock_delete):
        resource = {
            'name': 'OneViewSDK Test Snapshot',
            'type': 'SnapshotV3',
            'uri': '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        }
        self._volumes.delete_snapshot(resource, force=True, timeout=50)

        mock_delete.assert_called_once_with(resource, force=True, timeout=50)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_snapshot_called_once_with_defaults(self, mock_delete):
        resource = {
            'name': 'OneViewSDK Test Snapshot',
            'type': 'SnapshotV3',
            'uri': '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        }
        self._volumes.delete_snapshot(resource)

        mock_delete.assert_called_once_with(resource, force=False, timeout=-1)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_snapshot_by_called_once(self, mock_get_by):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        volume_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/'
        self._volumes.get_snapshot_by(volume_id, "name", "test name")

        mock_get_by.assert_called_once_with("name", "test name", uri=volume_uri)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_extra_managed_storage_volume_paths_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._volumes.get_extra_managed_storage_volume_paths(2, 500, filter, sort)

        expected_uri = '/rest/storage-volumes/repair?alertFixType=ExtraManagedStorageVolumePaths'
        mock_get_all.assert_called_once_with(2, 500, uri=expected_uri, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'create')
    def test_repair_by_id_called_once(self, mock_create):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        data = {
            'resourceUri': '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC',
            'type': 'ExtraManagedStorageVolumePaths'
        }
        self._volumes.repair(volume_id)

        custom_headers = {u'Accept-Language': u'en_US'}
        mock_create.assert_called_once_with(data, uri='/rest/storage-volumes/repair', timeout=-1,
                                            custom_headers=custom_headers)

    @mock.patch.object(ResourceClient, 'create')
    def test_repair_by_uri_called_once(self, mock_create):
        volume_id = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC'
        data = {
            'resourceUri': '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC',
            'type': 'ExtraManagedStorageVolumePaths'
        }
        self._volumes.repair(volume_id)

        custom_headers = {u'Accept-Language': u'en_US'}
        mock_create.assert_called_once_with(data, uri='/rest/storage-volumes/repair', timeout=-1,
                                            custom_headers=custom_headers)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_attachable_volumes_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'
        query = 'availableNetworks IN [/rest/fc-networks/123-45-67,/rest/fc-networks/111-222-333]'

        self._volumes.get_attachable_volumes(2, 500, filter, query, sort)

        expected_uri = '/rest/storage-volumes/attachable-volumes'
        mock_get_all.assert_called_once_with(2, 500, uri=expected_uri, filter=filter, query=query, sort=sort)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_attachable_volumes_called_with_default_values(self, mock_get_all):
        self._volumes.get_attachable_volumes()

        expected_uri = '/rest/storage-volumes/attachable-volumes'
        mock_get_all.assert_called_once_with(0, -1, uri=expected_uri, filter='', query='', sort='')
예제 #3
0
class VolumesTest(unittest.TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._volumes = Volumes(self.connection)
        self.resource_uri = '/rest/storage-volumes/ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._volumes.data = {'uri': self.resource_uri}

    @mock.patch.object(ResourceHelper, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._volumes.get_all(2, 500, filter, sort)

        mock_get_all.assert_called_once_with(count=500,
                                             filter='name=TestName',
                                             sort='name:ascending',
                                             start=2)

    @mock.patch.object(Resource, 'get_by')
    def test_get_by_called_once(self, mock_get_by):
        self._volumes.get_by('name', 'Test Volume')

        mock_get_by.assert_called_once_with('name', 'Test Volume')

    @mock.patch.object(ResourceHelper, 'create')
    def test_create_called_once(self, mock_create):
        resource = {'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'}
        resource_rest_call = resource.copy()
        mock_create.return_value = {}

        self._volumes.create(resource)
        mock_create.assert_called_once_with(resource_rest_call, None, -1, None,
                                            False)

    @mock.patch.object(ResourceHelper, 'update')
    @mock.patch.object(ResourceHelper, 'do_get')
    def test_update_called_once(self, mock_get, mock_update):
        resource = {
            'uri':
            '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155',
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()

        self._volumes.update(resource)

        mock_update.assert_called_once_with(resource_rest_call,
                                            self.resource_uri, False, -1, None)

    @mock.patch.object(ResourceHelper, 'update')
    @mock.patch.object(ResourceHelper, 'do_get')
    def test_update_called_once_with_force(self, mock_get, mock_update):
        resource = {
            'uri':
            '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155',
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()

        self._volumes.update(resource, force=True)

        mock_update.assert_called_once_with(resource_rest_call,
                                            self.resource_uri, True, -1, None)

    @mock.patch.object(ResourceHelper, 'delete')
    def test_delete_by_id_called_once(self, mock_delete):
        self._volumes.delete(force=False, timeout=-1)

        expected_headers = {"If-Match": '*'}
        mock_delete.assert_called_once_with(self.resource_uri,
                                            force=False,
                                            timeout=-1,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceHelper, 'delete')
    def test_delete_by_resource_called_once(self, mock_delete):
        expected_headers = {"If-Match": '*'}
        self._volumes.delete()
        mock_delete.assert_called_once_with(self.resource_uri,
                                            force=False,
                                            timeout=-1,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceHelper, 'delete')
    def test_delete_with_force_called_once(self, mock_delete):
        self._volumes.delete(force=True)

        mock_delete.assert_called_once_with(mock.ANY,
                                            force=True,
                                            timeout=mock.ANY,
                                            custom_headers=mock.ANY)

    @mock.patch.object(ResourceHelper, 'delete')
    def test_delete_only_from_oneview_called_once_api300(self, mock_delete):
        self._volumes.delete(export_only=True)

        expected_headers = {'If-Match': '*', "exportOnly": True}
        mock_delete.assert_called_once_with(self.resource_uri,
                                            force=mock.ANY,
                                            timeout=mock.ANY,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceHelper, 'delete')
    def test_delete_only_from_oneview_called_once_api500(self, mock_delete):
        extended_uri = '{}?suppressDeviceUpdates=true'.format(
            self.resource_uri)
        self._volumes.delete(suppress_device_updates=True)

        expected_headers = {'If-Match': '*'}
        mock_delete.assert_called_once_with(extended_uri,
                                            force=mock.ANY,
                                            timeout=mock.ANY,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceHelper, 'get_all')
    def test_get_snapshots_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'
        self._volumes.get_snapshots(2, 500, filter, sort)
        mock_get_all.assert_called_once_with(count=500,
                                             filter='name=TestName',
                                             sort='name:ascending',
                                             start=2)

    @mock.patch.object(ResourceHelper, 'get_all')
    def test_get_snapshots_called_once_with_default(self, mock_get_all):
        self._volumes.get_snapshots()
        mock_get_all.assert_called_once_with(count=-1,
                                             filter=u'',
                                             sort=u'',
                                             start=0)

    @mock.patch.object(ResourceHelper, 'create')
    @mock.patch.object(ResourceHelper, 'get_all')
    def test_create_snapshot_should_be_called_once(self, mock_get,
                                                   mock_create):
        resource = {
            'name': 'OneViewSDK Test Snapshot',
        }

        self._volumes.create_snapshot(resource, 20)
        mock_create.assert_called_once_with(resource, None, 20, None, False)

    @mock.patch.object(Resource, 'get_by')
    def test_get_snapshot_by_called_once(self, mock_get_by):
        self._volumes.get_snapshot_by("name", "test name")

        mock_get_by.assert_called_once_with("name", "test name")

    @mock.patch.object(ResourceHelper, 'get_all')
    def test_get_extra_managed_storage_volume_paths_called_once(
            self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._volumes.get_extra_managed_storage_volume_paths(
            2, 500, filter, sort)

        expected_uri = '/rest/storage-volumes/repair?alertFixType=ExtraManagedStorageVolumePaths'
        mock_get_all.assert_called_once_with(2,
                                             500,
                                             uri=expected_uri,
                                             filter=filter,
                                             sort=sort)

    @mock.patch.object(ResourceHelper, 'create')
    def test_repair_called_once(self, mock_create):
        data = {
            'resourceUri': self.resource_uri,
            'type': 'ExtraManagedStorageVolumePaths'
        }
        self._volumes.repair()

        custom_headers = {u'Accept-Language': u'en_US'}
        mock_create.assert_called_once_with(data,
                                            uri='/rest/storage-volumes/repair',
                                            timeout=-1,
                                            custom_headers=custom_headers)

    @mock.patch.object(ResourceHelper, 'get_all')
    def test_get_attachable_volumes_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'
        query = 'availableNetworks IN [/rest/fc-networks/123-45-67,/rest/fc-networks/111-222-333]'
        scope_uris = [
            '/rest/scopes/e4a23533-9a72-4375-8cd3-a523016df852',
            '/rest/scopes/7799327d-6d79-4eb2-b969-a523016df869'
        ]
        connections = [{
            'networkUri':
            '/rest/fc-networks/90bd0f63-3aab-49e2-a45f-a52500b46616'
        }, {
            'networkUri':
            '/rest/fc-networks/8acd0f62-1aab-49e2-a45a-d22500b4acdb'
        }]

        self._volumes.get_attachable_volumes(2, 500, filter, query, sort,
                                             scope_uris, connections)

        expected_uri = "/rest/storage-volumes/attachable-volumes?connections=" \
                       "[{'networkUri': '/rest/fc-networks/90bd0f63-3aab-49e2-a45f-a52500b46616'}, " \
                       "{'networkUri': '/rest/fc-networks/8acd0f62-1aab-49e2-a45a-d22500b4acdb'}]"
        mock_get_all.assert_called_once_with(2,
                                             500,
                                             uri=expected_uri,
                                             filter=filter,
                                             query=query,
                                             sort=sort,
                                             scope_uris=scope_uris)

    @mock.patch.object(ResourceHelper, 'get_all')
    def test_get_attachable_volumes_called_with_default_values(
            self, mock_get_all):
        self._volumes.get_attachable_volumes()

        expected_uri = '/rest/storage-volumes/attachable-volumes'
        mock_get_all.assert_called_once_with(0,
                                             -1,
                                             uri=expected_uri,
                                             filter='',
                                             query='',
                                             sort='',
                                             scope_uris='')

    @mock.patch.object(ResourceHelper, 'create')
    def test_create_from_snapshot_called_once(self, mock_create):
        data = {'fake': 'data'}
        self._volumes.create_from_snapshot(data)
        mock_create.assert_called_once_with(
            data, uri='/rest/storage-volumes/from-snapshot', timeout=-1)

    @mock.patch.object(ResourceHelper, 'create')
    def test_add_from_existing_called_once(self, mock_create):
        data = {'fake': 'data'}
        self._volumes.add_from_existing(data)
        mock_create.assert_called_once_with(
            data, uri='/rest/storage-volumes/from-existing', timeout=-1)
class VolumesTest(unittest.TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._volumes = Volumes(self.connection)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._volumes.get_all(2, 500, filter, sort)

        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_called_once(self, mock_get_by):
        self._volumes.get_by('name', 'Test Volume')

        mock_get_by.assert_called_once_with('name', 'Test Volume')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_id_called_once(self, mock_get):
        self._volumes.get('3518be0e-17c1-4189-8f81-83f3724f6155')

        mock_get.assert_called_once_with('3518be0e-17c1-4189-8f81-83f3724f6155')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_uri_called_once(self, mock_get):
        self._volumes.get('/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155')

        mock_get.assert_called_once_with('/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155')

    @mock.patch.object(ResourceClient, 'create')
    def test_create_called_once(self, mock_create):
        resource = {
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()
        mock_create.return_value = {}

        self._volumes.create(resource)
        mock_create.assert_called_once_with(resource_rest_call, timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once(self, mock_update):
        resource = {
            'uri': '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155',
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()

        self._volumes.update(resource)

        mock_update.assert_called_once_with(resource_rest_call, timeout=-1, force=False)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once_with_force(self, mock_update):
        resource = {
            'uri': '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155',
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()

        self._volumes.update(resource, force=True)

        mock_update.assert_called_once_with(resource_rest_call, timeout=mock.ANY, force=True)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_by_id_called_once(self, mock_delete):
        id = 'fake'
        uri = '/rest/storage-volumes/fake'
        self._volumes.delete(id, force=False, timeout=-1)

        expected_headers = {"If-Match": '*'}
        mock_delete.assert_called_once_with(uri, force=False, timeout=-1, custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_by_resource_called_once(self, mock_delete):
        resource = {
            'uri': '/rest/storage-volumes/fake',
            'name': 'VOLUME_FAKE'
        }
        uri = '/rest/storage-volumes/fake'
        self._volumes.delete(resource, force=False, timeout=-1)

        expected_headers = {"If-Match": '*'}
        mock_delete.assert_called_once_with(uri, force=False, timeout=-1, custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_with_force_called_once(self, mock_delete):
        uri = '/rest/storage-volumes/fake'
        self._volumes.delete(uri, force=True)

        mock_delete.assert_called_once_with(mock.ANY, force=True, timeout=mock.ANY, custom_headers=mock.ANY)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_only_from_oneview_called_once_api300(self, mock_delete):
        uri = '/rest/storage-volumes/fake'
        self._volumes.delete(uri, export_only=True)

        expected_headers = {'If-Match': '*', "exportOnly": True}
        mock_delete.assert_called_once_with(uri, force=mock.ANY, timeout=mock.ANY, custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_only_from_oneview_called_once_api500(self, mock_delete):
        uri = '/rest/storage-volumes/fake'
        extended_uri = '/rest/storage-volumes/fake?suppressDeviceUpdates=true'
        self._volumes.delete(uri, suppress_device_updates=True)

        expected_headers = {'If-Match': '*'}
        mock_delete.assert_called_once_with(extended_uri, force=mock.ANY,
                                            timeout=mock.ANY, custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_snapshots_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/'

        self._volumes.get_snapshots(volume_id, 2, 500, filter, sort)
        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort, uri=uri)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_snapshots_called_once_with_default(self, mock_get_all):
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/'
        self._volumes.get_snapshots(volume_id)
        mock_get_all.assert_called_once_with(0, -1, filter='', sort='', uri=uri)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_snapshot_by_id_called_once(self, mock_get):
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        snapshot_id = '78216B75-3CC4-4444-BB5B-13C7504675'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/78216B75-3CC4-4444-BB5B-13C7504675'
        self._volumes.get_snapshot(snapshot_id, volume_id)
        mock_get.assert_called_once_with(uri)

    def test_get_snapshot_by_id_without_volume_id_should_fail(self):
        snapshot_id = '78216B75-3CC4-4444-BB5B-13C7504675'
        try:
            self._volumes.get_snapshot(snapshot_id)
        except ValueError as e:
            self.assertEqual(INVALID_VOLUME_URI, e.args[0])
        else:
            self.fail("Expected exception was not raised")

    @mock.patch.object(ResourceClient, 'get')
    def test_get_get_snapshot_by_uri_called_once(self, mock_get):
        snapshot_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        self._volumes.get_snapshot(snapshot_uri)
        mock_get.assert_called_once_with(snapshot_uri)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_get_snapshot_by_uri_and_volume_id_called_once(self, mock_get):
        snapshot_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        self._volumes.get_snapshot(snapshot_uri, volume_id)
        mock_get.assert_called_once_with(snapshot_uri)

    @mock.patch.object(ResourceClient, 'create')
    def test_create_snapshot_should_be_called_once(self, mock_create):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/'
        resource = {
            'name': 'OneViewSDK Test Snapshot',
        }

        self._volumes.create_snapshot(volume_id, resource, 20)
        mock_create.assert_called_once_with(resource, uri=uri, timeout=20,
                                            default_values=self._volumes.DEFAULT_VALUES_SNAPSHOT)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_snapshot_called_once(self, mock_delete):
        resource = {
            'name': 'OneViewSDK Test Snapshot',
            'type': 'SnapshotV3',
            'uri': '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        }
        expected_headers = {"If-Match": '*'}
        self._volumes.delete_snapshot(resource, force=True, timeout=50)

        mock_delete.assert_called_once_with(resource, force=True, timeout=50, custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_snapshot_called_once_with_defaults(self, mock_delete):
        resource = {
            'name': 'OneViewSDK Test Snapshot',
            'type': 'SnapshotV3',
            'uri': '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        }
        expected_headers = {"If-Match": '*'}

        self._volumes.delete_snapshot(resource)

        mock_delete.assert_called_once_with(resource, force=False, timeout=-1, custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_snapshot_by_called_once(self, mock_get_by):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        volume_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/'
        self._volumes.get_snapshot_by(volume_id, "name", "test name")

        mock_get_by.assert_called_once_with("name", "test name", uri=volume_uri)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_extra_managed_storage_volume_paths_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._volumes.get_extra_managed_storage_volume_paths(2, 500, filter, sort)

        expected_uri = '/rest/storage-volumes/repair?alertFixType=ExtraManagedStorageVolumePaths'
        mock_get_all.assert_called_once_with(2, 500, uri=expected_uri, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'create')
    def test_repair_by_id_called_once(self, mock_create):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        data = {
            'resourceUri': '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC',
            'type': 'ExtraManagedStorageVolumePaths'
        }
        self._volumes.repair(volume_id)

        custom_headers = {u'Accept-Language': u'en_US'}
        mock_create.assert_called_once_with(data, uri='/rest/storage-volumes/repair', timeout=-1,
                                            custom_headers=custom_headers)

    @mock.patch.object(ResourceClient, 'create')
    def test_repair_by_uri_called_once(self, mock_create):
        volume_id = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC'
        data = {
            'resourceUri': '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC',
            'type': 'ExtraManagedStorageVolumePaths'
        }
        self._volumes.repair(volume_id)

        custom_headers = {u'Accept-Language': u'en_US'}
        mock_create.assert_called_once_with(data, uri='/rest/storage-volumes/repair', timeout=-1,
                                            custom_headers=custom_headers)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_attachable_volumes_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'
        query = 'availableNetworks IN [/rest/fc-networks/123-45-67,/rest/fc-networks/111-222-333]'
        scope_uris = ['/rest/scopes/e4a23533-9a72-4375-8cd3-a523016df852',
                      '/rest/scopes/7799327d-6d79-4eb2-b969-a523016df869']
        connections = [{'networkUri': '/rest/fc-networks/90bd0f63-3aab-49e2-a45f-a52500b46616'},
                       {'networkUri': '/rest/fc-networks/8acd0f62-1aab-49e2-a45a-d22500b4acdb'}]

        self._volumes.get_attachable_volumes(2, 500, filter, query, sort, scope_uris, connections)

        expected_uri = "/rest/storage-volumes/attachable-volumes?connections=" \
                       "[{'networkUri': '/rest/fc-networks/90bd0f63-3aab-49e2-a45f-a52500b46616'}, " \
                       "{'networkUri': '/rest/fc-networks/8acd0f62-1aab-49e2-a45a-d22500b4acdb'}]"
        mock_get_all.assert_called_once_with(2, 500, uri=expected_uri, filter=filter, query=query, sort=sort,
                                             scope_uris=scope_uris)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_attachable_volumes_called_with_default_values(self, mock_get_all):
        self._volumes.get_attachable_volumes()

        expected_uri = '/rest/storage-volumes/attachable-volumes'
        mock_get_all.assert_called_once_with(0, -1, uri=expected_uri, filter='', query='', sort='', scope_uris='')

    @mock.patch.object(ResourceClient, 'create')
    def test_create_from_snapshot_called_once(self, mock_create):
        data = {
            'fake': 'data'
        }
        self._volumes.create_from_snapshot(data)
        mock_create.assert_called_once_with(data, uri='/rest/storage-volumes/from-snapshot', timeout=-1)

    @mock.patch.object(ResourceClient, 'create')
    def test_add_from_existing_called_once(self, mock_create):
        data = {
            'fake': 'data'
        }
        self._volumes.add_from_existing(data)
        mock_create.assert_called_once_with(data, uri='/rest/storage-volumes/from-existing', timeout=-1)
예제 #5
0
class VolumesTest(unittest.TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._volumes = Volumes(self.connection)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._volumes.get_all(2, 500, filter, sort)

        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_called_once(self, mock_get_by):
        self._volumes.get_by('name', 'Test Volume')

        mock_get_by.assert_called_once_with('name', 'Test Volume')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_id_called_once(self, mock_get):
        self._volumes.get('3518be0e-17c1-4189-8f81-83f3724f6155')

        mock_get.assert_called_once_with(
            '3518be0e-17c1-4189-8f81-83f3724f6155')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_uri_called_once(self, mock_get):
        self._volumes.get(
            '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155')

        mock_get.assert_called_once_with(
            '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155')

    @mock.patch.object(ResourceClient, 'create')
    def test_create_called_once(self, mock_create):
        resource = {'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'}
        resource_rest_call = resource.copy()
        mock_create.return_value = {}

        self._volumes.create(resource)
        mock_create.assert_called_once_with(resource_rest_call, timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once(self, mock_update):
        resource = {
            'uri':
            '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155',
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()

        self._volumes.update(resource)

        mock_update.assert_called_once_with(resource_rest_call,
                                            timeout=-1,
                                            force=False)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once_with_force(self, mock_update):
        resource = {
            'uri':
            '/rest/storage-volumes/3518be0e-17c1-4189-8f81-83f3724f6155',
            'name': 'ONEVIEW_SDK_TEST_VOLUME_TYPE_1'
        }
        resource_rest_call = resource.copy()

        self._volumes.update(resource, force=True)

        mock_update.assert_called_once_with(resource_rest_call,
                                            timeout=mock.ANY,
                                            force=True)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_by_id_called_once(self, mock_delete):
        id = 'fake'
        uri = '/rest/storage-volumes/fake'
        self._volumes.delete(id, force=False, timeout=-1)

        expected_headers = {"If-Match": '*'}
        mock_delete.assert_called_once_with(uri,
                                            force=False,
                                            timeout=-1,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_by_resource_called_once(self, mock_delete):
        resource = {'uri': '/rest/storage-volumes/fake', 'name': 'VOLUME_FAKE'}
        uri = '/rest/storage-volumes/fake'
        self._volumes.delete(resource, force=False, timeout=-1)

        expected_headers = {"If-Match": '*'}
        mock_delete.assert_called_once_with(uri,
                                            force=False,
                                            timeout=-1,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_with_force_called_once(self, mock_delete):
        uri = '/rest/storage-volumes/fake'
        self._volumes.delete(uri, force=True)

        mock_delete.assert_called_once_with(mock.ANY,
                                            force=True,
                                            timeout=mock.ANY,
                                            custom_headers=mock.ANY)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_only_from_oneview_called_once_api300(self, mock_delete):
        uri = '/rest/storage-volumes/fake'
        self._volumes.delete(uri, export_only=True)

        expected_headers = {'If-Match': '*', "exportOnly": True}
        mock_delete.assert_called_once_with(uri,
                                            force=mock.ANY,
                                            timeout=mock.ANY,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_only_from_oneview_called_once_api500(self, mock_delete):
        uri = '/rest/storage-volumes/fake'
        extended_uri = '/rest/storage-volumes/fake?suppressDeviceUpdates=true'
        self._volumes.delete(uri, suppress_device_updates=True)

        expected_headers = {'If-Match': '*'}
        mock_delete.assert_called_once_with(extended_uri,
                                            force=mock.ANY,
                                            timeout=mock.ANY,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_snapshots_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/'

        self._volumes.get_snapshots(volume_id, 2, 500, filter, sort)
        mock_get_all.assert_called_once_with(2,
                                             500,
                                             filter=filter,
                                             sort=sort,
                                             uri=uri)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_snapshots_called_once_with_default(self, mock_get_all):
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/'
        self._volumes.get_snapshots(volume_id)
        mock_get_all.assert_called_once_with(0,
                                             -1,
                                             filter='',
                                             sort='',
                                             uri=uri)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_snapshot_by_id_called_once(self, mock_get):
        volume_id = '280FF951-F007-478F-AC29-E4655FC76DDC'
        snapshot_id = '78216B75-3CC4-4444-BB5B-13C7504675'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC76DDC/snapshots/78216B75-3CC4-4444-BB5B-13C7504675'
        self._volumes.get_snapshot(snapshot_id, volume_id)
        mock_get.assert_called_once_with(uri)

    def test_get_snapshot_by_id_without_volume_id_should_fail(self):
        snapshot_id = '78216B75-3CC4-4444-BB5B-13C7504675'
        try:
            self._volumes.get_snapshot(snapshot_id)
        except ValueError as e:
            self.assertEqual(INVALID_VOLUME_URI, e.args[0])
        else:
            self.fail("Expected exception was not raised")

    @mock.patch.object(ResourceClient, 'get')
    def test_get_get_snapshot_by_uri_called_once(self, mock_get):
        snapshot_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        self._volumes.get_snapshot(snapshot_uri)
        mock_get.assert_called_once_with(snapshot_uri)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_get_snapshot_by_uri_and_volume_id_called_once(self, mock_get):
        snapshot_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        self._volumes.get_snapshot(snapshot_uri, volume_id)
        mock_get.assert_called_once_with(snapshot_uri)

    @mock.patch.object(ResourceClient, 'create')
    def test_create_snapshot_should_be_called_once(self, mock_create):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/'
        resource = {
            'name': 'OneViewSDK Test Snapshot',
        }

        self._volumes.create_snapshot(volume_id, resource, 20)
        mock_create.assert_called_once_with(
            resource,
            uri=uri,
            timeout=20,
            default_values=self._volumes.DEFAULT_VALUES_SNAPSHOT)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_snapshot_called_once(self, mock_delete):
        resource = {
            'name':
            'OneViewSDK Test Snapshot',
            'type':
            'SnapshotV3',
            'uri':
            '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        }
        expected_headers = {"If-Match": '*'}
        self._volumes.delete_snapshot(resource, force=True, timeout=50)

        mock_delete.assert_called_once_with(resource,
                                            force=True,
                                            timeout=50,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_snapshot_called_once_with_defaults(self, mock_delete):
        resource = {
            'name':
            'OneViewSDK Test Snapshot',
            'type':
            'SnapshotV3',
            'uri':
            '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/78216B75-3CC4-4444-B5B-13046'
        }
        expected_headers = {"If-Match": '*'}

        self._volumes.delete_snapshot(resource)

        mock_delete.assert_called_once_with(resource,
                                            force=False,
                                            timeout=-1,
                                            custom_headers=expected_headers)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_snapshot_by_called_once(self, mock_get_by):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        volume_uri = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC/snapshots/'
        self._volumes.get_snapshot_by(volume_id, "name", "test name")

        mock_get_by.assert_called_once_with("name",
                                            "test name",
                                            uri=volume_uri)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_extra_managed_storage_volume_paths_called_once(
            self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._volumes.get_extra_managed_storage_volume_paths(
            2, 500, filter, sort)

        expected_uri = '/rest/storage-volumes/repair?alertFixType=ExtraManagedStorageVolumePaths'
        mock_get_all.assert_called_once_with(2,
                                             500,
                                             uri=expected_uri,
                                             filter=filter,
                                             sort=sort)

    @mock.patch.object(ResourceClient, 'create')
    def test_repair_by_id_called_once(self, mock_create):
        volume_id = '280FF951-F007-478F-AC29-E4655FC'
        data = {
            'resourceUri':
            '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC',
            'type': 'ExtraManagedStorageVolumePaths'
        }
        self._volumes.repair(volume_id)

        custom_headers = {u'Accept-Language': u'en_US'}
        mock_create.assert_called_once_with(data,
                                            uri='/rest/storage-volumes/repair',
                                            timeout=-1,
                                            custom_headers=custom_headers)

    @mock.patch.object(ResourceClient, 'create')
    def test_repair_by_uri_called_once(self, mock_create):
        volume_id = '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC'
        data = {
            'resourceUri':
            '/rest/storage-volumes/280FF951-F007-478F-AC29-E4655FC',
            'type': 'ExtraManagedStorageVolumePaths'
        }
        self._volumes.repair(volume_id)

        custom_headers = {u'Accept-Language': u'en_US'}
        mock_create.assert_called_once_with(data,
                                            uri='/rest/storage-volumes/repair',
                                            timeout=-1,
                                            custom_headers=custom_headers)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_attachable_volumes_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'
        query = 'availableNetworks IN [/rest/fc-networks/123-45-67,/rest/fc-networks/111-222-333]'
        scope_uris = [
            '/rest/scopes/e4a23533-9a72-4375-8cd3-a523016df852',
            '/rest/scopes/7799327d-6d79-4eb2-b969-a523016df869'
        ]
        connections = [{
            'networkUri':
            '/rest/fc-networks/90bd0f63-3aab-49e2-a45f-a52500b46616'
        }, {
            'networkUri':
            '/rest/fc-networks/8acd0f62-1aab-49e2-a45a-d22500b4acdb'
        }]

        self._volumes.get_attachable_volumes(2, 500, filter, query, sort,
                                             scope_uris, connections)

        expected_uri = "/rest/storage-volumes/attachable-volumes?connections=" \
                       "[{'networkUri': '/rest/fc-networks/90bd0f63-3aab-49e2-a45f-a52500b46616'}, " \
                       "{'networkUri': '/rest/fc-networks/8acd0f62-1aab-49e2-a45a-d22500b4acdb'}]"
        mock_get_all.assert_called_once_with(2,
                                             500,
                                             uri=expected_uri,
                                             filter=filter,
                                             query=query,
                                             sort=sort,
                                             scope_uris=scope_uris)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_attachable_volumes_called_with_default_values(
            self, mock_get_all):
        self._volumes.get_attachable_volumes()

        expected_uri = '/rest/storage-volumes/attachable-volumes'
        mock_get_all.assert_called_once_with(0,
                                             -1,
                                             uri=expected_uri,
                                             filter='',
                                             query='',
                                             sort='',
                                             scope_uris='')

    @mock.patch.object(ResourceClient, 'create')
    def test_create_from_snapshot_called_once(self, mock_create):
        data = {'fake': 'data'}
        self._volumes.create_from_snapshot(data)
        mock_create.assert_called_once_with(
            data, uri='/rest/storage-volumes/from-snapshot', timeout=-1)

    @mock.patch.object(ResourceClient, 'create')
    def test_add_from_existing_called_once(self, mock_create):
        data = {'fake': 'data'}
        self._volumes.add_from_existing(data)
        mock_create.assert_called_once_with(
            data, uri='/rest/storage-volumes/from-existing', timeout=-1)