Пример #1
0
 def test_connect_volume_failed(self):
     fake_share = fake_object.FakeManilaShare(share_proto='NFS')
     self.connector._get_access_to = mock.MagicMock()
     self.connector._get_access_to.return_value = '192.168.0.2'
     with mock.patch(
             'fuxi.tests.unit.fake_client.FakeManilaClient'
             '.Shares.allow',
             side_effect=manila_exception.ClientException(500)):
         self.assertRaises(manila_exception.ClientException,
                           self.connector.connect_volume, fake_share)
Пример #2
0
    def test_monitor_manila_share_get_failed(self):
        fake_manila_client = fake_client.FakeManilaClient()
        fake_manila_share = fake_object.FakeManilaShare(status='creating')

        with mock.patch(
                'fuxi.tests.unit.fake_client'
                '.FakeManilaClient.Shares.get',
                side_effect=manila_exception.ClientException(404)):
            fake_state_monitor = state_monitor.StateMonitor(
                fake_manila_client, fake_manila_share, None, None, -1)
            self.assertRaises(exceptions.TimeoutException,
                              fake_state_monitor.monitor_manila_share)

        with mock.patch(
                'fuxi.tests.unit.fake_client'
                '.FakeManilaClient.Shares.get',
                side_effect=manila_exception.ClientException(404)):
            fake_state_monitor = state_monitor.StateMonitor(
                fake_manila_client, fake_manila_share, None, None)
            self.assertRaises(manila_exception.ClientException,
                              fake_state_monitor.monitor_manila_share)
Пример #3
0
    def test_monitor_share_access_list_failed(self):
        fake_manila_client = fake_client.FakeManilaClient()
        fake_manila_share = fake_object.FakeManilaShare()
        with mock.patch(
                'fuxi.tests.unit.fake_client.FakeManilaClient.Shares'
                '.access_list',
                side_effect=manila_exception.ClientException(404)):
            fake_state_monitor = state_monitor.StateMonitor(
                fake_manila_client, fake_manila_share, None, None, -1)
            self.assertRaises(exceptions.TimeoutException,
                              fake_state_monitor.monitor_share_access, 'ip',
                              '192.168.0.1')

        with mock.patch(
                'fuxi.tests.unit.fake_client.FakeManilaClient.Shares'
                '.access_list',
                side_effect=manila_exception.ClientException(404)):
            fake_state_monitor = state_monitor.StateMonitor(
                fake_manila_client, fake_manila_share, None, None)
            self.assertRaises(manila_exception.ClientException,
                              fake_state_monitor.monitor_share_access, 'ip',
                              '192.168.0.1')
Пример #4
0
class TestManila(base.TestCase):
    def setUp(self):
        super(TestManila, self).setUp()
        self._set_up_provider()

    @mock.patch.object(utils,
                       'get_manilaclient',
                       return_value=fake_client.FakeManilaClient())
    def _set_up_provider(self, mock_client):
        self.provider = manila.Manila()
        self.provider.manilaclient = fake_client.FakeManilaClient()
        self.provider.connector = FakeManilaConnector()

    def test_create_exist(self):
        fake_share = fake_object.FakeManilaShare(name='fake-vol',
                                                 id='fake-id',
                                                 export_location='fake-el')

        for status in [consts.NOT_ATTACH, consts.ATTACH_TO_THIS]:
            with mock.patch.object(manila.Manila,
                                   '_get_docker_volume',
                                   return_value=(fake_share, status)):
                self.assertEqual('fake-el',
                                 self.provider.create('fake-vol', {})['path'])

    @mock.patch('fuxi.volumeprovider.manila.Manila._get_docker_volume',
                side_effect=exceptions.NotFound())
    def test_create_from_id(self, mock_docker_volume):
        fake_vol_opts = {'volume_id': 'fake-id'}
        fake_share = fake_object.FakeManilaShare(name='fake-vol',
                                                 id='fake-id',
                                                 export_location='fake-el',
                                                 status='available',
                                                 metadata={})
        with mock.patch.object(fake_client.FakeManilaClient.Shares,
                               'get',
                               return_value=fake_share):
            self.assertEqual(
                'fake-el',
                self.provider.create('fake-vol', fake_vol_opts)['path'])

    @mock.patch('fuxi.volumeprovider.manila.Manila._get_docker_volume',
                side_effect=exceptions.NotFound())
    def test_create_not_exist(self, mock_docker_volume):
        fake_vol_opts = {'share_network': 'fake-share-network'}
        fake_share = fake_object.FakeManilaShare(name='fake-vol',
                                                 id='fake-id',
                                                 export_location='fake-el',
                                                 status='creating')
        with mock.patch.object(fake_client.FakeManilaClient.Shares,
                               'create',
                               return_value=fake_share):
            fake_share.status = 'available'
            with mock.patch.object(state_monitor.StateMonitor,
                                   'monitor_manila_share',
                                   return_value=fake_share):
                self.assertEqual(
                    'fake-el',
                    self.provider.create('fake-vol', fake_vol_opts)['path'])

    @mock.patch.object(utils, 'execute')
    @mock.patch.object(mount.Mounter, 'get_mps_by_device', return_value=[])
    def test_delete(self, mock_execute, mock_mps):
        fake_share = fake_object.FakeManilaShare(name='fake-vol',
                                                 id='fake-id',
                                                 export_location='fake-el')

        with mock.patch.object(manila.Manila,
                               '_get_docker_volume',
                               return_value=(fake_share,
                                             consts.ATTACH_TO_THIS)):
            with mock.patch.object(manila.Manila, '_delete_share'):
                self.assertTrue(self.provider.delete('fake-vol'))

    def test_mount(self):
        fake_share = fake_object.FakeManilaShare(name='fake-vol',
                                                 id='fake-id',
                                                 export_location='fake-el',
                                                 share_proto='nfs')

        with mock.patch.object(manila.Manila,
                               '_get_docker_volume',
                               return_value=(fake_share,
                                             consts.ATTACH_TO_THIS)):
            self.assertEqual('fake-vol', self.provider.mount('fake-vol'))

    def test_unmount(self):
        self.assertIsNone(self.provider.unmount('fake-vol'))

    def test_show(self):
        fake_vol = fake_object.DEFAULT_VOLUME_NAME
        with mock.patch.object(manila.Manila,
                               '_get_docker_volume',
                               return_value=(fake_object.FakeManilaShare(),
                                             consts.ATTACH_TO_THIS)):
            self.assertEqual({
                'Name': fake_vol,
                'Mountpoint': fake_vol
            }, self.provider.show(fake_vol))

    @mock.patch('fuxi.tests.unit.fake_client.FakeManilaClient.Shares.list',
                side_effect=manila_exception.ClientException(500))
    def test_show_list_failed(self, mock_list):
        self.assertRaises(manila_exception.ClientException, self.provider.show,
                          'fake-vol')

    @mock.patch.object(fake_client.FakeManilaClient.Shares,
                       'list',
                       return_value=[])
    def test_show_no_share(self, mock_list):
        self.assertRaises(exceptions.NotFound, self.provider.show, 'fake-vol')

    @mock.patch.object(fake_client.FakeManilaClient.Shares,
                       'list',
                       return_value=[
                           fake_object.FakeManilaShare(id='1'),
                           fake_object.FakeManilaShare(id='2')
                       ])
    def test_show_too_many_shares(self, mock_list):
        self.assertRaises(exceptions.TooManyResources, self.provider.show,
                          'fake-vol')

    @mock.patch.object(manila.Manila,
                       '_get_docker_volume',
                       return_value=(fake_object.FakeManilaShare(),
                                     consts.NOT_ATTACH))
    def test_show_not_attach(self, mock_docker_volume):
        fake_vol = fake_object.DEFAULT_VOLUME_NAME
        self.assertEqual({
            'Name': fake_vol,
            'Mountpoint': fake_vol
        }, self.provider.show(fake_vol))

    @mock.patch.object(manila.Manila,
                       '_get_docker_volume',
                       return_value=(fake_object.FakeManilaShare(),
                                     consts.ATTACH_TO_THIS))
    def test_show_not_mount(self, mock_dokcer_volume):
        fake_vol = fake_object.DEFAULT_VOLUME_NAME
        self.assertEqual({
            'Name': fake_vol,
            'Mountpoint': fake_vol
        }, self.provider.show(fake_vol))

    def test_list(self):
        share_dict = [{
            'id': 'fake-id1',
            'name': 'fake-name1',
            'export_location': 'fake-el1'
        }, {
            'id': 'fake-id2',
            'name': 'fake-name2',
            'export_location': 'fake-el2'
        }]
        fake_shares = [fake_object.FakeManilaShare(**s) for s in share_dict]
        fake_volumes = [{
            'Name': 'fake-name1',
            'Mountpoint': 'fake-name1'
        }, {
            'Name': 'fake-name2',
            'Mountpoint': 'fake-name2'
        }]
        with mock.patch.object(fake_client.FakeManilaClient.Shares,
                               'list',
                               return_value=fake_shares):
            with mock.patch.object(mount.Mounter,
                                   'get_mps_by_device',
                                   return_value=[]):
                self.assertEqual(fake_volumes, self.provider.list())

    def test_list_failed(self):
        with mock.patch(
                'fuxi.tests.unit.fake_client.FakeManilaClient'
                '.Shares.list',
                side_effect=manila_exception.ClientException):
            self.assertRaises(manila_exception.ClientException,
                              self.provider.list)

    def test_check_exist(self):
        with mock.patch('fuxi.volumeprovider.manila.Manila._get_docker_volume',
                        side_effect=exceptions.NotFound()):
            self.assertFalse(self.provider.check_exist('fake-vol'))

        with mock.patch.object(manila.Manila,
                               '_get_docker_volume',
                               return_value=(fake_object.FakeManilaShare(),
                                             consts.ATTACH_TO_THIS)):
            self.assertTrue(self.provider.check_exist('fake-vol'))