Exemple #1
0
 def setUp(self):
     super(LVMHelperTestCase, self).setUp()
     self.share = fake_share()
     self.fake_conf = configuration.Configuration(None)
     self.fake_conf.container_volume_mount_path = "/tmp/shares"
     self.LVMHelper = storage_helper.LVMHelper(configuration=self.fake_conf)
     self.context = mock.Mock()
    def test_create_share_guest_not_ok(self):
        self.DockerCIFSHelper.conf = mock.Mock()
        self.DockerCIFSHelper.conf.container_cifs_guest_ok = False
        expected_arguments = [
            ("fakeserver", ["net", "conf", "addshare", "fakeshareid",
             "/shares/fakeshareid", "writeable=y", "guest_ok=n"]),
            ("fakeserver", ["net", "conf", "setparm", "fakeshareid",
             "browseable", "yes"]),
            ("fakeserver", ["net", "conf", "setparm", "fakeshareid",
             "hosts allow", "192.0.2.2"]),
            ("fakeserver", ["net", "conf", "setparm", "fakeshareid",
             "read only", "no"]),
            ("fakeserver", ["net", "conf", "setparm", "fakeshareid",
             "hosts deny", "0.0.0.0/0"]),
            ("fakeserver", ["net", "conf", "setparm", "fakeshareid",
             "create mask", "0755"])]
        actual_arguments = []
        self._helper.execute = functools.partial(
            self.fake_exec_sync, execute_arguments=actual_arguments,
            ret_val=" fake 192.0.2.2/24 more fake \n" * 20)
        self.DockerCIFSHelper.share = fake_share()

        self.DockerCIFSHelper.create_share("fakeserver")

        self.assertEqual(expected_arguments.sort(), actual_arguments.sort())
Exemple #3
0
    def test__get_helper_ok(self):
        share = cont_fakes.fake_share(share_proto='CIFS')
        expected = protocol_helper.DockerCIFSHelper(None)

        actual = self._driver._get_helper(share)

        self.assertEqual(type(expected), type(actual))
Exemple #4
0
    def test_extend_share(self):
        fake_new_size = 2
        fake_share_server = {'id': 'fake-server'}
        share = cont_fakes.fake_share()
        share_name = self._driver._get_share_name(share)
        actual_arguments = []
        expected_arguments = [('manila_fake_server',
                               ['umount', '/shares/%s' % share_name]),
                              ('manila_fake_server', [
                                  'mount',
                                  '/dev/manila_docker_volumes/%s' % share_name,
                                  '/shares/%s' % share_name
                              ])]
        mock_extend_share = self.mock_object(self._driver.storage,
                                             "extend_share")
        self._driver.container.execute = functools.partial(
            self.fake_exec_sync,
            execute_arguments=actual_arguments,
            ret_val='')

        self._driver.extend_share(share, fake_new_size, fake_share_server)

        self.assertEqual(expected_arguments, actual_arguments)
        mock_extend_share.assert_called_once_with(share_name, fake_new_size,
                                                  fake_share_server)
    def test_delete_share(self):
        self.DockerCIFSHelper.share = fake_share()

        self.DockerCIFSHelper.delete_share("fakeserver")

        self.DockerCIFSHelper.container.execute.assert_called_with(
            "fakeserver", ["net", "conf", "delshare", "fakeshareid"])
 def setUp(self):
     super(DockerCIFSHelperTestCase, self).setUp()
     self._helper = mock.Mock()
     self.fake_conf = mock.Mock()
     self.fake_conf.container_cifs_guest_ok = "yes"
     self.DockerCIFSHelper = protocol_helper.DockerCIFSHelper(
         self._helper, share=fake_share(), config=self.fake_conf)
    def test_create_share_guest_not_ok(self):
        self.DockerCIFSHelper.conf = mock.Mock()
        self.DockerCIFSHelper.conf.container_cifs_guest_ok = False
        expected_arguments = [
            ("fakeserver", ["net", "conf", "addshare", "fakeshareid",
             "/shares/fakeshareid", "writeable=y", "guest_ok=n"]),
            ("fakeserver", ["net", "conf", "setparm", "fakeshareid",
             "browseable", "yes"]),
            ("fakeserver", ["net", "conf", "setparm", "fakeshareid",
             "hosts allow", "192.0.2.2"]),
            ("fakeserver", ["net", "conf", "setparm", "fakeshareid",
             "read only", "no"]),
            ("fakeserver", ["net", "conf", "setparm", "fakeshareid",
             "hosts deny", "0.0.0.0/0"]),
            ("fakeserver", ["net", "conf", "setparm", "fakeshareid",
             "create mask", "0755"])]
        actual_arguments = []
        self._helper.execute = functools.partial(
            self.fake_exec_sync, execute_arguments=actual_arguments,
            ret_val=" fake 192.0.2.2/24 more fake \n" * 20)
        self.DockerCIFSHelper.share = fake_share()

        self.DockerCIFSHelper.create_share("fakeserver")

        self.assertEqual(expected_arguments.sort(), actual_arguments.sort())
 def setUp(self):
     super(DockerCIFSHelperTestCase, self).setUp()
     self._helper = mock.Mock()
     self.fake_conf = mock.Mock()
     self.fake_conf.container_cifs_guest_ok = "yes"
     self.DockerCIFSHelper = protocol_helper.DockerCIFSHelper(
         self._helper, share=fake_share(), config=self.fake_conf)
Exemple #9
0
    def test__get_helper_ok(self):
        share = cont_fakes.fake_share(share_proto='CIFS')
        expected = protocol_helper.DockerCIFSHelper(None)

        actual = self._driver._get_helper(share)

        self.assertEqual(type(expected), type(actual))
    def test_delete_share(self):
        self.DockerCIFSHelper.share = fake_share()

        self.DockerCIFSHelper.delete_share("fakeserver")

        self.DockerCIFSHelper.container.execute.assert_called_with(
            "fakeserver",
            ["net", "conf", "delshare", "fakeshareid"])
Exemple #11
0
    def test__get_helper_existing_ok(self):
        share = cont_fakes.fake_share(share_proto='CIFS')
        expected = protocol_helper.DockerCIFSHelper
        self._driver._helpers = {'CIFS': expected}

        actual = self._driver._get_helper(share)

        self.assertEqual(expected, type(actual))
Exemple #12
0
    def test__get_helper_existing_ok(self):
        share = cont_fakes.fake_share(share_proto='CIFS')
        expected = protocol_helper.DockerCIFSHelper
        self._driver._helpers = {'CIFS': expected}

        actual = self._driver._get_helper(share)

        self.assertEqual(expected, type(actual))
Exemple #13
0
    def test__get_share_name(self, has_export_location):

        if not has_export_location:
            fake_share = cont_fakes.fake_share_no_export_location()
            expected_result = fake_share.share_id
        else:
            fake_share = cont_fakes.fake_share()
            expected_result = fake_share['export_location'].split('/')[-1]

        result = self._driver._get_share_name(fake_share)
        self.assertEqual(expected_result, result)
Exemple #14
0
    def test__get_share_name(self, has_export_location):

        if not has_export_location:
            fake_share = cont_fakes.fake_share_no_export_location()
            expected_result = fake_share.share_id
        else:
            fake_share = cont_fakes.fake_share()
            expected_result = fake_share['export_location'].split('/')[-1]

        result = self._driver._get_share_name(fake_share)
        self.assertEqual(expected_result, result)
Exemple #15
0
    def test_manage_existing(self):

        fake_container_name = "manila_fake_container"
        fake_export_location = 'export_location'
        expected_result = {
            'size': 1,
            'export_locations': [fake_export_location]
        }
        fake_share_server = cont_fakes.fake_share()
        fake_share_name = self._driver._get_share_name(self.share)
        mock_get_container_name = self.mock_object(
            self._driver, '_get_container_name',
            mock.Mock(return_value=fake_container_name))
        mock_get_share_name = self.mock_object(
            self._driver, '_get_share_name',
            mock.Mock(return_value=fake_share_name))
        mock_rename_storage = self.mock_object(
            self._driver.storage, 'rename_storage')
        mock_get_size = self.mock_object(
            self._driver.storage, 'get_size', mock.Mock(return_value=1))
        mock_delete_and_umount = self.mock_object(
            self._driver, '_delete_export_and_umount_storage')
        mock_create_and_mount = self.mock_object(
            self._driver, '_create_export_and_mount_storage',
            mock.Mock(return_value=fake_export_location)
        )

        result = self._driver.manage_existing_with_server(
            self.share, {}, fake_share_server)

        mock_rename_storage.assert_called_once_with(
            fake_share_name, self.share.share_id
        )
        mock_get_size.assert_called_once_with(
            fake_share_name
        )
        mock_delete_and_umount.assert_called_once_with(
            self.share, fake_container_name, fake_share_name
        )
        mock_create_and_mount.assert_called_once_with(
            self.share, fake_container_name, self.share.share_id
        )
        mock_get_container_name.assert_called_once_with(
            fake_share_server['id']
        )
        mock_get_share_name.assert_called_with(
            self.share
        )
        self.assertEqual(expected_result, result)
Exemple #16
0
    def test_manage_existing(self):

        fake_container_name = "manila_fake_container"
        fake_export_location = 'export_location'
        expected_result = {
            'size': 1,
            'export_locations': [fake_export_location]
        }
        fake_share_server = cont_fakes.fake_share()
        fake_share_name = self._driver._get_share_name(self.share)
        mock_get_container_name = self.mock_object(
            self._driver, '_get_container_name',
            mock.Mock(return_value=fake_container_name))
        mock_get_share_name = self.mock_object(
            self._driver, '_get_share_name',
            mock.Mock(return_value=fake_share_name))
        mock_rename_storage = self.mock_object(
            self._driver.storage, 'rename_storage')
        mock_get_size = self.mock_object(
            self._driver.storage, 'get_size', mock.Mock(return_value=1))
        mock_delete_and_umount = self.mock_object(
            self._driver, '_delete_export_and_umount_storage')
        mock_create_and_mount = self.mock_object(
            self._driver, '_create_export_and_mount_storage',
            mock.Mock(return_value=fake_export_location)
        )

        result = self._driver.manage_existing_with_server(
            self.share, {}, fake_share_server)

        mock_rename_storage.assert_called_once_with(
            fake_share_name, self.share.share_id
        )
        mock_get_size.assert_called_once_with(
            fake_share_name
        )
        mock_delete_and_umount.assert_called_once_with(
            self.share, fake_container_name, fake_share_name
        )
        mock_create_and_mount.assert_called_once_with(
            self.share, fake_container_name, self.share.share_id
        )
        mock_get_container_name.assert_called_once_with(
            fake_share_server['id']
        )
        mock_get_share_name.assert_called_with(
            self.share
        )
        self.assertEqual(expected_result, result)
Exemple #17
0
    def test_extend_share(self):
        share = cont_fakes.fake_share()
        actual_arguments = []
        expected_arguments = [
            ('manila_fake_server', ['umount', '/shares/fakeshareid']),
            ('manila_fake_server',
             ['mount', '/dev/manila_docker_volumes/fakeshareid',
              '/shares/fakeshareid'])
        ]
        self.mock_object(self._driver.storage, "extend_share")
        self._driver.container.execute = functools.partial(
            self.fake_exec_sync, execute_arguments=actual_arguments,
            ret_val='')

        self._driver.extend_share(share, 2, {'id': 'fake-server'})

        self.assertEqual(expected_arguments, actual_arguments)
Exemple #18
0
    def test_extend_share(self):
        share = cont_fakes.fake_share()
        actual_arguments = []
        expected_arguments = [
            ('manila_fake_server', ['umount', '/shares/fakeshareid']),
            ('manila_fake_server', [
                'mount', '/dev/manila_docker_volumes/fakeshareid',
                '/shares/fakeshareid'
            ])
        ]
        self.mock_object(self._driver.storage, "extend_share")
        self._driver.container.execute = functools.partial(
            self.fake_exec_sync,
            execute_arguments=actual_arguments,
            ret_val='')

        self._driver.extend_share(share, 2, {'id': 'fake-server'})

        self.assertEqual(expected_arguments, actual_arguments)
Exemple #19
0
    def setUp(self):
        super(ContainerShareDriverTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self)
        self._context = context.get_admin_context()
        self._db = mock.Mock()
        self.fake_conf = configuration.Configuration(None)

        CONF.set_default('driver_handles_share_servers', True)

        self._driver = driver.ContainerShareDriver(
            configuration=self.fake_conf)

        self.share = cont_fakes.fake_share()
        self.access = cont_fakes.fake_access()
        self.server = {
            'public_address': self.fake_conf.lvm_share_export_ip,
            'instance_id': 'LVM',
        }

        # Used only to test compatibility with share manager
        self.share_server = "fake_share_server"
Exemple #20
0
    def setUp(self):
        super(ContainerShareDriverTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self)
        self._context = context.get_admin_context()
        self._db = mock.Mock()
        self.fake_conf = configuration.Configuration(None)

        CONF.set_default('driver_handles_share_servers', True)

        self._driver = driver.ContainerShareDriver(
            configuration=self.fake_conf)

        self.share = cont_fakes.fake_share()
        self.access = cont_fakes.fake_access()
        self.server = {
            'public_address': self.fake_conf.lvm_share_export_ip,
            'instance_id': 'LVM',
        }

        # Used only to test compatibility with share manager
        self.share_server = "fake_share_server"
Exemple #21
0
    def test_extend_share(self):
        fake_new_size = 2
        fake_share_server = {'id': 'fake-server'}
        share = cont_fakes.fake_share()
        share_name = self._driver._get_share_name(share)
        actual_arguments = []
        expected_arguments = [
            ('manila_fake_server', ['umount', '/shares/%s' % share_name]),
            ('manila_fake_server',
             ['mount', '/dev/manila_docker_volumes/%s' % share_name,
              '/shares/%s' % share_name])
        ]
        mock_extend_share = self.mock_object(self._driver.storage,
                                             "extend_share")
        self._driver.container.execute = functools.partial(
            self.fake_exec_sync, execute_arguments=actual_arguments,
            ret_val='')

        self._driver.extend_share(share, fake_new_size, fake_share_server)

        self.assertEqual(expected_arguments, actual_arguments)
        mock_extend_share.assert_called_once_with(share_name, fake_new_size,
                                                  fake_share_server)
Exemple #22
0
    def test_extend_share(self):
        share = cont_fakes.fake_share()
        self.mock_object(self._driver.storage, "extend_share")

        self._driver.extend_share(share, 2, 'fake-server')
Exemple #23
0
 def setUp(self):
     super(LVMHelperTestCase, self).setUp()
     self.share = fake_share()
     self.fake_conf = configuration.Configuration(None)
     self.LVMHelper = storage_helper.LVMHelper(configuration=self.fake_conf)
Exemple #24
0
    def test__get_helper_not_ok(self):
        share = cont_fakes.fake_share()

        self.assertRaises(exception.InvalidShare, self._driver._get_helper,
                          share)
Exemple #25
0
    def test__get_helper_not_ok(self):
        share = cont_fakes.fake_share()

        self.assertRaises(exception.InvalidShare, self._driver._get_helper,
                          share)
Exemple #26
0
 def setUp(self):
     super(LVMHelperTestCase, self).setUp()
     self.share = fake_share()
     self.fake_conf = configuration.Configuration(None)
     self.LVMHelper = storage_helper.LVMHelper(configuration=self.fake_conf)