Exemplo n.º 1
0
    def test_clone_failure(self):
        driver = self.volume.driver

        with mock.patch.object(driver, '_is_cloneable', lambda *args: False):
            image_loc = (mock.Mock(), mock.Mock())
            actual = driver.clone_image(mock.Mock(), image_loc, {})
            self.assertEqual(({}, False), actual)

        self.assertEqual(({}, False), driver.clone_image(object(), None, {}))
Exemplo n.º 2
0
    def test_clone_failure(self):
        driver = self.volume.driver

        with mock.patch.object(driver, "_is_cloneable", lambda *args: False):
            image_loc = (mock.Mock(), mock.Mock())
            actual = driver.clone_image(mock.Mock(), image_loc, mock.Mock(), {})
            self.assertEqual(({}, False), actual)

        self.assertEqual(({}, False), driver.clone_image(object(), None, None, {}))
Exemplo n.º 3
0
    def test_clone_multilocation_failure(self):
        expected = ({}, False)
        driver = self.volume.driver

        with mock.patch.object(driver, '_is_cloneable', return_value=False) \
            as mock_is_cloneable, \
            mock.patch.object(self.volume.driver, '_clone') as mock_clone, \
            mock.patch.object(self.volume.driver, '_resize') \
                as mock_resize:
                image_loc = ('rbd://bee/bi/bo/bum',
                             [{'url': 'rbd://bee/bi/bo/bum'},
                              {'url': 'rbd://fee/fi/fo/fum'}])

                volume = {'name': 'vol1'}
                image_meta = mock.sentinel.image_meta
                image_service = mock.sentinel.image_service
                actual = driver.clone_image(self.context,
                                            volume,
                                            image_loc,
                                            image_meta,
                                            image_service)

                self.assertEqual(expected, actual)
                self.assertEqual(2, mock_is_cloneable.call_count)
                mock_is_cloneable.assert_any_call('rbd://bee/bi/bo/bum',
                                                  image_meta)
                mock_is_cloneable.assert_any_call('rbd://fee/fi/fo/fum',
                                                  image_meta)
                self.assertFalse(mock_clone.called)
                self.assertFalse(mock_resize.called)
Exemplo n.º 4
0
    def test_clone_multilocation_success(self):
        expected = ({'provider_location': None}, True)
        driver = self.volume.driver

        def cloneable_side_effect(url_location, image_meta):
            return url_location == 'rbd://fee/fi/fo/fum'

        with mock.patch.object(self.volume.driver, '_is_cloneable') \
            as mock_is_cloneable, \
            mock.patch.object(self.volume.driver, '_clone') as mock_clone, \
            mock.patch.object(self.volume.driver, '_resize') \
                as mock_resize:
                mock_is_cloneable.side_effect = cloneable_side_effect
                image_loc = ('rbd://bee/bi/bo/bum',
                             [{'url': 'rbd://bee/bi/bo/bum'},
                              {'url': 'rbd://fee/fi/fo/fum'}])
                volume = {'name': 'vol1'}
                image_meta = mock.sentinel.image_meta
                image_service = mock.sentinel.image_service

                actual = driver.clone_image(self.context,
                                            volume,
                                            image_loc,
                                            image_meta,
                                            image_service)

                self.assertEqual(expected, actual)
                self.assertEqual(2, mock_is_cloneable.call_count)
                mock_clone.assert_called_once_with(volume,
                                                   'fi', 'fo', 'fum')
                mock_is_cloneable.assert_called_with('rbd://fee/fi/fo/fum',
                                                     image_meta)
                mock_resize.assert_called_once_with(volume)
Exemplo n.º 5
0
    def test_clone_success(self):
        expected = ({'provider_location': None}, True)
        driver = self.volume.driver

        with mock.patch.object(self.volume.driver, '_is_cloneable') as \
                mock_is_cloneable:
            mock_is_cloneable.return_value = True
            with mock.patch.object(self.volume.driver, '_clone') as \
                    mock_clone:
                with mock.patch.object(self.volume.driver, '_resize') as \
                        mock_resize:
                    image_loc = ('rbd://fee/fi/fo/fum', None)

                    volume = {'name': 'vol1'}
                    actual = driver.clone_image(mock.Mock(),
                                                volume,
                                                image_loc,
                                                {'disk_format': 'raw',
                                                 'id': 'id.foo'},
                                                mock.Mock())

                    self.assertEqual(expected, actual)
                    mock_clone.assert_called_once_with(volume,
                                                       'fi', 'fo', 'fum')
                    mock_resize.assert_called_once_with(volume)
Exemplo n.º 6
0
    def test_clone_success(self):
        expected = ({'provider_location': None}, True)
        driver = self.volume.driver

        with mock.patch.object(self.volume.driver, '_is_cloneable') as \
                mock_is_cloneable:
            mock_is_cloneable.return_value = True
            with mock.patch.object(self.volume.driver, '_clone') as \
                    mock_clone:
                with mock.patch.object(self.volume.driver, '_resize') as \
                        mock_resize:
                    image_loc = ('rbd://fee/fi/fo/fum', None)

                    volume = {'name': 'vol1'}
                    actual = driver.clone_image(mock.Mock(),
                                                volume,
                                                image_loc,
                                                {'disk_format': 'raw',
                                                 'id': 'id.foo'},
                                                mock.Mock())

                    self.assertEqual(expected, actual)
                    mock_clone.assert_called_once_with(volume,
                                                       'fi', 'fo', 'fum')
                    mock_resize.assert_called_once_with(volume)
Exemplo n.º 7
0
    def test_clone_multilocation_failure(self):
        expected = ({}, False)
        driver = self.volume.driver

        with mock.patch.object(driver, '_is_cloneable', return_value=False) \
            as mock_is_cloneable, \
            mock.patch.object(self.volume.driver, '_clone') as mock_clone, \
            mock.patch.object(self.volume.driver, '_resize') \
                as mock_resize:
            image_loc = ('rbd://bee/bi/bo/bum', [{
                'url': 'rbd://bee/bi/bo/bum'
            }, {
                'url': 'rbd://fee/fi/fo/fum'
            }])

            volume = {'name': 'vol1'}
            image_meta = mock.sentinel.image_meta
            image_service = mock.sentinel.image_service
            actual = driver.clone_image(self.context, volume, image_loc,
                                        image_meta, image_service)

            self.assertEqual(expected, actual)
            self.assertEqual(2, mock_is_cloneable.call_count)
            mock_is_cloneable.assert_any_call('rbd://bee/bi/bo/bum',
                                              image_meta)
            mock_is_cloneable.assert_any_call('rbd://fee/fi/fo/fum',
                                              image_meta)
            self.assertFalse(mock_clone.called)
            self.assertFalse(mock_resize.called)
Exemplo n.º 8
0
    def test_clone_multilocation_success(self):
        expected = ({'provider_location': None}, True)
        driver = self.volume.driver

        def cloneable_side_effect(url_location, image_meta):
            return url_location == 'rbd://fee/fi/fo/fum'

        with mock.patch.object(self.volume.driver, '_is_cloneable') \
            as mock_is_cloneable, \
            mock.patch.object(self.volume.driver, '_clone') as mock_clone, \
            mock.patch.object(self.volume.driver, '_resize') \
                as mock_resize:
            mock_is_cloneable.side_effect = cloneable_side_effect
            image_loc = ('rbd://bee/bi/bo/bum', [{
                'url': 'rbd://bee/bi/bo/bum'
            }, {
                'url': 'rbd://fee/fi/fo/fum'
            }])
            volume = {'name': 'vol1'}
            image_meta = mock.sentinel.image_meta
            image_service = mock.sentinel.image_service

            actual = driver.clone_image(self.context, volume, image_loc,
                                        image_meta, image_service)

            self.assertEqual(expected, actual)
            self.assertEqual(2, mock_is_cloneable.call_count)
            mock_clone.assert_called_once_with(volume, 'fi', 'fo', 'fum')
            mock_is_cloneable.assert_called_with('rbd://fee/fi/fo/fum',
                                                 image_meta)
            mock_resize.assert_called_once_with(volume)
Exemplo n.º 9
0
 def test_clone_success(self):
     expected = ({"provider_location": None}, True)
     driver = self.volume.driver
     mpo = mock.patch.object
     with mpo(driver, "_is_cloneable", lambda *args: True):
         with mpo(driver, "_parse_location", lambda x: (1, 2, 3, 4)):
             with mpo(driver, "_clone") as mock_clone:
                 with mpo(driver, "_resize") as mock_resize:
                     image_loc = (mock.Mock(), mock.Mock())
                     actual = driver.clone_image(mock.Mock(), image_loc, mock.Mock(), {"disk_format": "raw"})
                     self.assertEqual(expected, actual)
                     mock_clone.assert_called()
                     mock_resize.assert_called()
Exemplo n.º 10
0
    def test_clone_success(self):
        expected = ({"provider_location": None}, True)
        driver = self.volume.driver

        with mock.patch.object(self.volume.driver, "_is_cloneable") as mock_is_cloneable:
            mock_is_cloneable.return_value = True
            with mock.patch.object(self.volume.driver, "_clone") as mock_clone:
                with mock.patch.object(self.volume.driver, "_resize") as mock_resize:
                    image_loc = ("rbd://fee/fi/fo/fum", None)

                    actual = driver.clone_image({"name": "vol1"}, image_loc, "id.foo", {"disk_format": "raw"})

                    self.assertEqual(expected, actual)
                    mock_clone.assert_called_once()
                    mock_resize.assert_called_once()
Exemplo n.º 11
0
 def test_clone_success(self):
     expected = ({'provider_location': None}, True)
     driver = self.volume.driver
     mpo = mock.patch.object
     with mpo(driver, '_is_cloneable', lambda *args: True):
         with mpo(driver, '_parse_location', lambda x: (1, 2, 3, 4)):
             with mpo(driver, '_clone') as mock_clone:
                 with mpo(driver, '_resize') as mock_resize:
                     image_loc = (mock.Mock(), mock.Mock())
                     actual = driver.clone_image(mock.Mock(),
                                                 image_loc,
                                                 mock.Mock(),
                                                 {'disk_format': 'raw'})
                     self.assertEqual(expected, actual)
                     mock_clone.assert_called()
                     mock_resize.assert_called()
Exemplo n.º 12
0
    def test_clone_success(self):
        expected = ({'provider_location': None}, True)
        driver = self.volume.driver

        self.volume.driver._is_cloneable = mock.Mock()
        self.volume.driver._is_cloneable.return_value = True
        self.volume.driver._clone = mock.Mock()
        self.volume.driver._resize = mock.Mock()

        image_loc = ('rbd://fee/fi/fo/fum', None)
        actual = driver.clone_image({'name': 'vol1'},
                                    image_loc,
                                    'id.foo',
                                    {'disk_format': 'raw'})

        self.assertEqual(expected, actual)
        self.volume.driver._clone.assert_called_once()
        self.volume.driver._resize.assert_called_once()
Exemplo n.º 13
0
    def test_clone_success(self):
        expected = ({'provider_location': None}, True)
        driver = self.volume.driver

        with mock.patch.object(self.volume.driver, '_is_cloneable') as \
                mock_is_cloneable:
            mock_is_cloneable.return_value = True
            with mock.patch.object(self.volume.driver, '_clone') as \
                    mock_clone:
                with mock.patch.object(self.volume.driver, '_resize') as \
                        mock_resize:
                    image_loc = ('rbd://fee/fi/fo/fum', None)

                    actual = driver.clone_image({'name': 'vol1'}, image_loc,
                                                'id.foo',
                                                {'disk_format': 'raw'})

                    self.assertEqual(actual, expected)
                    mock_clone.assert_called_once()
                    mock_resize.assert_called_once()