Esempio n. 1
0
    def test_create_delete_share_snapshot(self):
        """Test share's snapshot can be created and deleted."""

        def _fake_create_snapshot(self, context, snapshot):
            snapshot['progress'] = '99%'
            return snapshot

        self.stubs.Set(FakeShareDriver, "create_snapshot",
                       _fake_create_snapshot)

        share = self._create_share()
        share_id = share['id']
        snapshot = self._create_snapshot(share_id=share_id)
        snapshot_id = snapshot['id']

        self.share.create_snapshot(self.context, share_id, snapshot_id)
        self.assertEqual(share_id,
                         db.share_snapshot_get(context.get_admin_context(),
                         snapshot_id).share_id)

        snap = db.share_snapshot_get(self.context, snapshot_id)
        self.assertEquals(snap['status'], 'available')

        self.share.delete_snapshot(self.context, snapshot_id)

        self.assertEquals('deleted', db.share_snapshot_get(
            context.get_admin_context(read_deleted='yes'), snapshot_id).status)
        self.assertRaises(exception.NotFound,
                          db.share_snapshot_get,
                          self.context,
                          snapshot_id)
Esempio n. 2
0
    def test_init_host_ensuring_shares(self):
        """Test init_host for ensuring shares and access rules."""

        share = self._create_share(status='available')
        share_id = share['id']

        another_share = self._create_share(status='error')

        access = self._create_access(share_id=share_id, state='active')

        self.mox.StubOutWithMock(context, 'get_admin_context')
        context.get_admin_context().AndReturn(self.context)

        self.mox.StubOutWithMock(db, 'share_get_all_by_host')
        db.share_get_all_by_host(self.context, mox.IgnoreArg())\
            .AndReturn([share, another_share])

        driver = self.mox.CreateMockAnything(FakeShareDriver)
        driver.do_setup(self.context)
        driver.check_for_setup_error()
        driver.ensure_share(self.context, share)
        driver.allow_access(self.context, share, mox.IgnoreArg())
        driver.get_share_stats(refresh=True)
        self.share.driver = driver

        self.mox.ReplayAll()

        self.share.init_host()
Esempio n. 3
0
 def test_service_disabled_on_create_based_on_flag(self):
     self.flags(enable_new_services=False)
     host = 'foo'
     binary = 'manila-fake'
     app = service.Service.create(host=host, binary=binary)
     app.start()
     app.stop()
     ref = db.service_get(context.get_admin_context(), app.service_id)
     db.service_destroy(context.get_admin_context(), app.service_id)
     self.assertTrue(ref['disabled'])
Esempio n. 4
0
 def test_service_enabled_on_create_based_on_flag(self):
     self.flags(enable_new_services=True)
     host = "foo"
     binary = "manila-fake"
     app = service.Service.create(host=host, binary=binary)
     app.start()
     app.stop()
     ref = db.service_get(context.get_admin_context(), app.service_id)
     db.service_destroy(context.get_admin_context(), app.service_id)
     self.assertFalse(ref["disabled"])
Esempio n. 5
0
 def _create_security_service(share_network_id=None):
     service = {}
     service['type'] = "FAKE"
     service['project_id'] = 'fake-project-id'
     service_ref = db.security_service_create(
         context.get_admin_context(), service)
     db.share_network_add_security_service(context.get_admin_context(),
                                           share_network_id,
                                           service_ref['id'])
     return service_ref
Esempio n. 6
0
 def _create_share_server(state='ACTIVE', share_network_id=None, host=None):
     """Create a share server object."""
     srv = {}
     srv['host'] = host
     srv['share_network_id'] = share_network_id
     srv['status'] = state
     share_srv = db.share_server_create(context.get_admin_context(), srv)
     backend_details = {'fake': 'fake'}
     db.share_server_backend_details_set(context.get_admin_context(),
                                         share_srv['id'],
                                         backend_details)
     return db.share_server_get(context.get_admin_context(),
                                share_srv['id'])
Esempio n. 7
0
def create_share_server(**kwargs):
    """Create a share server object."""
    backend_details = kwargs.pop('backend_details', {})
    srv = {
        'host': 'host1',
        'share_network_id': 'fake_srv_id',
        'status': constants.STATUS_ACTIVE
    }
    share_srv = _create_db_row(db.share_server_create, srv, kwargs)
    if backend_details:
        db.share_server_backend_details_set(
            context.get_admin_context(), share_srv['id'], backend_details)
    return db.share_server_get(context.get_admin_context(),
                               share_srv['id'])
    def setUp(self):
        super(GlusterfsDirectoryMappedLayoutTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self)
        self._execute = fake_utils.fake_execute
        self._context = context.get_admin_context()
        self.addCleanup(fake_utils.fake_execute_set_repliers, [])
        self.addCleanup(fake_utils.fake_execute_clear_log)

        CONF.set_default('glusterfs_target', '127.0.0.1:/testvol')
        CONF.set_default('glusterfs_mount_point_base', '/mnt/nfs')
        CONF.set_default('glusterfs_server_password',
                         fake_remote_server_password)
        CONF.set_default('glusterfs_path_to_private_key',
                         fake_path_to_private_key)

        self.fake_driver = mock.Mock()
        self.mock_object(self.fake_driver, '_execute',
                         self._execute)
        self.fake_driver.GLUSTERFS_VERSION_MIN = (3, 6)
        self.fake_conf = config.Configuration(None)
        self.mock_object(common.GlusterManager, 'make_gluster_call')
        self._layout = layout_directory.GlusterfsDirectoryMappedLayout(
            self.fake_driver, configuration=self.fake_conf)
        self._layout.gluster_manager = mock.Mock(**fake_gluster_manager_attrs)
        self.share = fake_share.fake_share(share_proto='NFS')
Esempio n. 9
0
    def __init__(self, share_driver=None, service_name=None, *args, **kwargs):
        """Load the driver from args, or from flags."""
        self.configuration = manila.share.configuration.Configuration(
            share_manager_opts,
            config_group=service_name)
        self._verify_unused_share_server_cleanup_interval()
        super(ShareManager, self).__init__(service_name='share',
                                           *args, **kwargs)

        if not share_driver:
            share_driver = self.configuration.share_driver
        if share_driver in MAPPING:
            msg_args = {'old': share_driver, 'new': MAPPING[share_driver]}
            LOG.warning(_LW("Driver path %(old)s is deprecated, update your "
                            "configuration to the new path %(new)s"),
                        msg_args)
            share_driver = MAPPING[share_driver]

        ctxt = context.get_admin_context()
        private_storage = drivers_private_data.DriverPrivateData(
            context=ctxt, backend_host=self.host,
            config_group=self.configuration.config_group
        )

        self.driver = importutils.import_object(
            share_driver, private_storage=private_storage,
            configuration=self.configuration
        )
Esempio n. 10
0
 def list(self):
     """Show a list of all manila services."""
     ctxt = context.get_admin_context()
     services = db.service_get_all(ctxt)
     print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
     print(print_format % (
         _('Binary'),
         _('Host'),
         _('Zone'),
         _('Status'),
         _('State'),
         _('Updated At'))
     )
     for svc in services:
         alive = utils.service_is_up(svc)
         art = ":-)" if alive else "XXX"
         status = 'enabled'
         if svc['disabled']:
             status = 'disabled'
         print(print_format % (
             svc['binary'],
             svc['host'].partition('.')[0],
             svc['availability_zone']['name'],
             status,
             art,
             svc['updated_at'],
         ))
Esempio n. 11
0
 def __init__(self, db, _helpers, *args, **kwargs):
     """Do initialization."""
     super(ServiceInstanceManager, self).__init__(*args, **kwargs)
     if not CONF.service_instance_user:
         raise exception.ServiceInstanceException(_('Service instance user '
                                                    'is not specified'))
     self.admin_context = context.get_admin_context()
     self._execute = utils.execute
     self.compute_api = compute.API()
     self.neutron_api = neutron.API()
     self._helpers = _helpers
     self.db = db
     attempts = 5
     while attempts:
         try:
             self.service_tenant_id = self.neutron_api.admin_tenant_id
             break
         except exception.NetworkException:
             LOG.debug(_('Connection to neutron failed.'))
             attempts -= 1
             time.sleep(3)
     else:
         raise exception.ServiceInstanceException(_('Can not receive '
                                                    'service tenant id.'))
     self.share_networks_locks = {}
     self.share_networks_servers = {}
     self.service_network_id = self._get_service_network()
     self.vif_driver = importutils.import_class(CONF.interface_driver)()
     self._setup_connectivity_with_service_instances()
Esempio n. 12
0
    def setUp(self):
        super(ServiceInstanceManagerTestCase, self).setUp()
        self._context = context.get_admin_context()

        self._helper_cifs = mock.Mock()
        self._helper_nfs = mock.Mock()
        self._db = mock.Mock()
        self.stubs.Set(service_instance.neutron, 'API', fake_network.API)
        self.stubs.Set(service_instance.compute, 'API', fake_compute.API)
        with mock.patch.object(service_instance.ServiceInstanceManager,
                               '_setup_connectivity_with_service_instances',
                               mock.Mock()):
            self._manager = service_instance.ServiceInstanceManager(self._db,
                                                                    {})
        self._manager.service_tenant_id = 'service tenant id'
        self._manager.service_network_id = 'service network id'
        self._manager.admin_context = self._context
        self._manager._execute = mock.Mock(return_value=('', ''))
        self._manager.vif_driver = mock.Mock()
        self.stubs.Set(utils, 'synchronized',
                       mock.Mock(return_value=lambda f: f))
        self.stubs.Set(service_instance.os.path, 'exists',
                       mock.Mock(return_value=True))
        self._manager._helpers = {
            'CIFS': self._helper_cifs,
            'NFS': self._helper_nfs,
        }
        self.share = fake_share()
Esempio n. 13
0
 def __init__(self, db, *args, **kwargs):
     """Do initialization."""
     super(GenericShareDriver, self).__init__(*args, **kwargs)
     self.admin_context = context.get_admin_context()
     self.db = db
     self.configuration.append_config_values(share_opts)
     self._helpers = {}
Esempio n. 14
0
 def update(self, context, volume_id, fields):
     # Use Manila's context as far as Cinder's is restricted to update
     # volumes.
     manila_admin_context = ctxt.get_admin_context()
     client = cinderclient(manila_admin_context)
     item = client.volumes.get(volume_id)
     client.volumes.update(item, **fields)
Esempio n. 15
0
 def __init__(self, config_group_name=None):
     self.config_group_name = config_group_name or 'DEFAULT'
     CONF.register_opts(neutron_opts, group=self.config_group_name)
     self.configuration = getattr(CONF, self.config_group_name, CONF)
     self.last_neutron_extension_sync = None
     self.extensions = {}
     self.client = self.get_client(context.get_admin_context())
    def setUp(self):
        super(LVMShareDriverTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self)
        self._context = context.get_admin_context()

        CONF.set_default('lvm_share_volume_group', 'fakevg')
        CONF.set_default('lvm_share_export_ip', '10.0.0.1')
        CONF.set_default('driver_handles_share_servers', False)
        CONF.set_default('reserved_share_percentage', 50)

        self._helper_cifs = mock.Mock()
        self._helper_nfs = mock.Mock()
        self.fake_conf = configuration.Configuration(None)
        self._db = mock.Mock()
        self._os = lvm.os = mock.Mock()
        self._os.path.join = os.path.join
        self._driver = lvm.LVMShareDriver(self._db,
                                          configuration=self.fake_conf)
        self._driver._helpers = {
            'CIFS': self._helper_cifs,
            'NFS': self._helper_nfs,
        }

        self.share = fake_share()
        self.access = fake_access()
        self.snapshot = fake_snapshot()
        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"
Esempio n. 17
0
 def setUp(self):
     super(DataManagerTestCase, self).setUp()
     self.manager = manager.DataManager()
     self.context = context.get_admin_context()
     self.topic = 'fake_topic'
     self.share = db_utils.create_share()
     manager.CONF.set_default('migration_tmp_location', '/tmp/')
Esempio n. 18
0
    def setUp(self):
        def _safe_get(opt):
            return getattr(self.cfg, opt)
        self.cfg = conf.Configuration(None)
        self.cfg.nexenta_host = '1.1.1.1'
        super(self.__class__, self).setUp()
        self.ctx = context.get_admin_context()
        self.mock_object(
            self.cfg, 'safe_get', mock.Mock(side_effect=_safe_get))
        self.cfg.nexenta_rest_port = 8080
        self.cfg.nexenta_rest_protocol = 'auto'
        self.cfg.nexenta_pool = 'pool1'
        self.cfg.reserved_share_percentage = 0
        self.cfg.nexenta_nfs_share = 'nfs_share'
        self.cfg.nexenta_user = '******'
        self.cfg.share_backend_name = 'NexentaStor5'
        self.cfg.nexenta_password = '******'
        self.cfg.nexenta_thin_provisioning = False
        self.cfg.nexenta_mount_point_base = 'mnt'
        self.cfg.enabled_share_protocols = 'NFS'
        self.cfg.nexenta_mount_point_base = '$state_path/mnt'
        self.cfg.nexenta_dataset_compression = 'on'
        self.cfg.network_config_group = 'DEFAULT'
        self.cfg.admin_network_config_group = (
            'fake_admin_network_config_group')
        self.cfg.driver_handles_share_servers = False

        self.drv = nexenta_nas.NexentaNasDriver(configuration=self.cfg)
        self.drv.do_setup(self.ctx)
        self.mock_rpc = self.mock_class(PATH_TO_RPC)
        self.pool_name = self.cfg.nexenta_pool
        self.fs_prefix = self.cfg.nexenta_nfs_share
Esempio n. 19
0
    def setUp(self):
        super(LVMShareDriverTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self.stubs)
        self._execute = fake_utils.fake_execute
        self._context = context.get_admin_context()

        CONF.set_default('share_volume_group', 'fakevg')
        CONF.set_default('share_export_ip', '10.0.0.1')

        self._helper_cifs = mock.Mock()
        self._helper_nfs = mock.Mock()
        self.fake_conf = Configuration(None)
        self._db = mock.Mock()
        self._os = lvm.os = mock.Mock()
        self._os.path.join = os.path.join
        self._driver = lvm.LVMShareDriver(self._db,
                                          execute=self._execute,
                                          configuration=self.fake_conf)
        self._driver._helpers = {
            'CIFS': self._helper_cifs,
            'NFS': self._helper_nfs,
        }

        self.share = fake_share()
        self.access = fake_access()
        self.snapshot = fake_snapshot()

        # Used only to test compatibility with share manager
        self.share_server = "fake_share_server"
Esempio n. 20
0
    def setUp(self, _factory_zfssa):
        super(ZFSSAShareDriverTestCase, self).setUp()
        self._create_fake_config()
        lcfg = self.configuration
        self.mountpoint = '/export/' + lcfg.zfssa_nas_mountpoint
        _factory_zfssa.return_value = fake_zfssa.FakeZFSSA()
        _factory_zfssa.set_host(lcfg.zfssa_host)
        _factory_zfssa.login(lcfg.zfssa_auth_user)
        self._context = context.get_admin_context()
        self._driver = zfssashare.ZFSSAShareDriver(False, configuration=lcfg)
        self._driver.do_setup(self._context)

        self.fake_proto_share = {
            'id': self.share['id'],
            'share_proto': 'fake_proto',
            'export_locations': [{'path': self.share['export_location']}],
        }

        self.test_share = {
            'id': self.share['id'],
            'share_proto': 'NFS',
            'export_locations': [{'path': self.share['export_location']}],
        }

        self.test_share2 = {
            'id': self.share2['id'],
            'share_proto': 'CIFS',
            'export_locations': [{'path': self.share2['export_location']}],
        }

        self.driver_options = {'zfssa_name': self.share['name']}
Esempio n. 21
0
    def init_host(self):
        """Initialization for a standalone service."""

        ctxt = context.get_admin_context()
        self.driver.do_setup(ctxt)
        self.driver.check_for_setup_error()

        shares = self.db.share_get_all_by_host(ctxt, self.host)
        LOG.debug(_("Re-exporting %s shares"), len(shares))
        for share in shares:
            if share['status'] in ['available', 'in-use']:
                self.driver.ensure_share(ctxt, share)
                rules = self.db.share_access_get_all_for_share(ctxt,
                                                               share['id'])
                for access_ref in rules:
                    if access_ref['state'] == access_ref.STATE_ACTIVE:
                        try:
                            self.driver.allow_access(ctxt, share,
                                                     access_ref)
                        except exception.ShareAccessExists:
                            pass
            else:
                LOG.info(_("share %s: skipping export"), share['name'])

        self.publish_service_capabilities(ctxt)
Esempio n. 22
0
    def setUp(self):
        super(HDFSNativeShareDriverTestCase, self).setUp()
        self._context = context.get_admin_context()
        self._hdfs_execute = mock.Mock(return_value=("", ""))
        self.local_ip = "192.168.1.1"

        CONF.set_default("driver_handles_share_servers", False)
        CONF.set_default("hdfs_namenode_ip", self.local_ip)
        CONF.set_default("hdfs_ssh_name", "fake_sshname")
        CONF.set_default("hdfs_ssh_pw", "fake_sshpw")
        CONF.set_default("hdfs_ssh_private_key", "fake_sshkey")

        self.fake_conf = config.Configuration(None)
        self._driver = hdfs_native.HDFSNativeShareDriver(execute=self._hdfs_execute, configuration=self.fake_conf)
        self.hdfs_bin = "hdfs"
        self._driver._hdfs_bin = "fake_hdfs_bin"
        self.share = fake_share.fake_share(share_proto="HDFS")
        self.snapshot = fake_share.fake_snapshot(share_proto="HDFS")
        self.access = fake_share.fake_access(access_type="user")
        self.fakesharepath = "hdfs://1.2.3.4:5/share-0"
        self.fakesnapshotpath = "/share-0/.snapshot/snapshot-0"

        socket.gethostname = mock.Mock(return_value="testserver")
        socket.gethostbyname_ex = mock.Mock(
            return_value=("localhost", ["localhost.localdomain", "testserver"], ["127.0.0.1", self.local_ip])
        )
Esempio n. 23
0
    def setUp(self):
        super(ShareGroupsAPITestCase, self).setUp()
        self.context = context.get_admin_context()
        self.scheduler_rpcapi = mock.Mock()
        self.share_rpcapi = mock.Mock()
        self.share_api = mock.Mock()
        self.api = share_group_api.API()
        self.mock_object(self.api, 'share_rpcapi', self.share_rpcapi)
        self.mock_object(self.api, 'share_api', self.share_api)
        self.mock_object(self.api, 'scheduler_rpcapi', self.scheduler_rpcapi)

        dt_utc = datetime.datetime.utcnow()
        self.mock_object(timeutils, 'utcnow', mock.Mock(return_value=dt_utc))
        self.fake_share_type = {
            'name': 'default',
            'extra_specs': {'driver_handles_share_servers': 'False'},
            'is_public': True,
            'id': 'c01990c1-448f-435a-9de6-c7c894bb6df9'
        }
        self.fake_share_type_2 = {
            'name': 'default2',
            'extra_specs': {'driver_handles_share_servers': 'False'},
            'is_public': True,
            'id': 'c01990c1-448f-435a-9de6-c7c894bb7dfd'
        }
        self.fake_share_group_type = {
            'share_types': [
                {'share_type_id': self.fake_share_type['id']},
                {'share_type_id': self.fake_share_type_2['id']},
            ]
        }
        self.mock_object(db_driver, 'share_group_type_get',
                         mock.Mock(return_value=self.fake_share_group_type))
Esempio n. 24
0
 def kill(self):
     """Destroy the service object in the datastore."""
     self.stop()
     try:
         db.service_destroy(context.get_admin_context(), self.service_id)
     except exception.NotFound:
         LOG.warn(_LW('Service killed that has no database entry'))
Esempio n. 25
0
    def test_create_share_with_server_created(self):
        """Test share can be created and share server is created."""
        share_net = self._create_share_network()
        share = self._create_share(share_network_id=share_net['id'])
        self._create_share_server(
            share_network_id=share_net['id'], host=self.share_manager.host,
            state='ERROR')
        share_id = share['id']
        fake_server = {'id': 'fake_srv_id'}
        self.stubs.Set(db, 'share_server_create',
                       mock.Mock(return_value=fake_server))
        self.stubs.Set(self.share_manager, '_setup_server',
                       mock.Mock(return_value=fake_server))

        self.share_manager.create_share(self.context, share_id)

        self.assertEqual(share_id, db.share_get(context.get_admin_context(),
                         share_id).id)
        shr = db.share_get(self.context, share_id)
        self.assertEqual(shr['status'], 'available')
        self.assertEqual(shr['share_server_id'], 'fake_srv_id')
        db.share_server_create.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), mock.ANY)
        self.share_manager._setup_server.assert_called_once_with(
            utils.IsAMatcher(context.RequestContext), fake_server)
Esempio n. 26
0
    def test_share_access_mapping_state(self, expected_status):
        ctxt = context.get_admin_context()

        share = db_utils.create_share()
        share_instances = [
            share.instance,
            db_utils.create_share_instance(share_id=share['id']),
            db_utils.create_share_instance(share_id=share['id']),
            db_utils.create_share_instance(share_id=share['id']),
        ]
        access_rule = db_utils.create_access(share_id=share['id'])

        # Update the access mapping states
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[0]['id'],
            {'state': constants.ACCESS_STATE_ACTIVE})
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[1]['id'],
            {'state': expected_status})
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[2]['id'],
            {'state': constants.ACCESS_STATE_ACTIVE})
        db_api.share_instance_access_update(
            ctxt, access_rule['id'], share_instances[3]['id'],
            {'deleted': 'True', 'state': constants.STATUS_DELETED})

        access_rule = db_api.share_access_get(ctxt, access_rule['id'])

        self.assertEqual(expected_status, access_rule['state'])
Esempio n. 27
0
    def setUp(self):
        super(HDFSNativeShareDriverTestCase, self).setUp()
        self._context = context.get_admin_context()
        self._hdfs_execute = mock.Mock(return_value=('', ''))
        self.local_ip = '192.168.1.1'

        CONF.set_default('driver_handles_share_servers', False)
        CONF.set_default('hdfs_namenode_ip', self.local_ip)
        CONF.set_default('hdfs_ssh_name', 'fake_sshname')
        CONF.set_default('hdfs_ssh_pw', 'fake_sshpw')
        CONF.set_default('hdfs_ssh_private_key', 'fake_sshkey')

        self.fake_conf = config.Configuration(None)
        self._driver = hdfs_native.HDFSNativeShareDriver(
            execute=self._hdfs_execute,
            configuration=self.fake_conf)
        self.hdfs_bin = 'hdfs'
        self._driver._hdfs_bin = 'fake_hdfs_bin'
        self.share = fake_share.fake_share(share_proto='HDFS')
        self.snapshot = fake_share.fake_snapshot(share_proto='HDFS')
        self.access = fake_share.fake_access(access_type='user')
        self.fakesharepath = 'hdfs://1.2.3.4:5/share-0'
        self.fakesnapshotpath = '/share-0/.snapshot/snapshot-0'

        socket.gethostname = mock.Mock(return_value='testserver')
        socket.gethostbyname_ex = mock.Mock(return_value=(
            'localhost',
            ['localhost.localdomain', 'testserver'],
            ['127.0.0.1', self.local_ip]))
Esempio n. 28
0
    def report_state(self):
        """Update the state of this service in the datastore."""
        ctxt = context.get_admin_context()
        zone = CONF.storage_availability_zone
        state_catalog = {}
        try:
            try:
                service_ref = db.service_get(ctxt, self.service_id)
            except exception.NotFound:
                LOG.debug('The service database object disappeared, '
                          'Recreating it.')
                self._create_service_ref(ctxt)
                service_ref = db.service_get(ctxt, self.service_id)

            state_catalog['report_count'] = service_ref['report_count'] + 1
            if zone != service_ref['availability_zone']:
                state_catalog['availability_zone'] = zone

            db.service_update(ctxt,
                              self.service_id, state_catalog)

            # TODO(termie): make this pattern be more elegant.
            if getattr(self, 'model_disconnected', False):
                self.model_disconnected = False
                LOG.error(_LE('Recovered model server connection!'))

        # TODO(vish): this should probably only catch connection errors
        except Exception:  # pylint: disable=W0702
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('model server went away'))
Esempio n. 29
0
 def setUp(self):
     super(NeutronApiTest, self).setUp()
     self.context = context.get_admin_context()
     self.stubs.Set(base, 'Base', fakes.FakeModel)
     self.stubs.Set(
         clientv20, 'Client', mock.Mock(return_value=FakeNeutronClient()))
     self.neutron_api = neutron_api.API()
Esempio n. 30
0
def _create_db_row(method, default_values, custom_values):
    override_defaults = custom_values.pop('override_defaults', None)
    if override_defaults:
        default_values = custom_values
    else:
        default_values.update(copy.deepcopy(custom_values))
    return method(context.get_admin_context(), default_values)
Esempio n. 31
0
def setup_profiler(binary, host):
    if (osprofiler_initializer is None or profiler is None
            or profiler_opts is None):
        LOG.debug('osprofiler is not present')
        return

    if CONF.profiler.enabled:
        osprofiler_initializer.init_from_conf(
            conf=CONF,
            context=context.get_admin_context().to_dict(),
            project="manila",
            service=binary,
            host=host)
        LOG.warning("OSProfiler is enabled.")
Esempio n. 32
0
    def setUp(self):
        super(NativeProtocolHelperTestCase, self).setUp()
        self.fake_conf = configuration.Configuration(None)
        self._context = context.get_admin_context()
        self._share = fake_share.fake_share(share_proto='CEPHFS')

        self.fake_conf.set_default('driver_handles_share_servers', False)

        self.mock_object(driver, "cephfs_share_path")

        self._native_protocol_helper = driver.NativeProtocolHelper(
            None,
            self.fake_conf,
            ceph_vol_client=MockVolumeClientModule.CephFSVolumeClient())
Esempio n. 33
0
    def setUp(self):
        super(MapRFSNativeShareDriverTestCase, self).setUp()
        self._context = context.get_admin_context()
        self._hdfs_execute = mock.Mock(return_value=('', ''))
        self.local_ip = '192.168.1.1'
        CONF.set_default('driver_handles_share_servers', False)
        CONF.set_default('maprfs_clinode_ip', [self.local_ip])
        CONF.set_default('maprfs_ssh_name', 'fake_sshname')
        CONF.set_default('maprfs_ssh_pw', 'fake_sshpw')
        CONF.set_default('maprfs_ssh_private_key', 'fake_sshkey')
        CONF.set_default('maprfs_rename_managed_volume', True)

        self.fake_conf = config.Configuration(None)
        self.cluster_name = 'fake'
        self._driver = maprfs.MapRFSNativeShareDriver(
            configuration=self.fake_conf)
        self._driver.do_setup(self._context)
        export_locations = {0: {'path': '/share-0'}}
        export_locations[0]['el_metadata'] = {
            'volume-name': 'share-0'}
        self.share = fake_share.fake_share(share_proto='MAPRFS',
                                           name='share-0', size=2, share_id=1,
                                           export_locations=export_locations,
                                           export_location='/share-0')
        self.snapshot = fake_share.fake_snapshot(share_proto='MAPRFS',
                                                 name='fake',
                                                 share_name=self.share['name'],
                                                 share_id=self.share['id'],
                                                 share=self.share,
                                                 share_instance=self.share,
                                                 provider_location='fake')
        self.access = fake_share.fake_access(access_type='user',
                                             access_to='fake',
                                             access_level='rw')

        self.snapshot = self.snapshot.values
        self.snapshot.update(share_instance=self.share)
        self.export_path = 'maprfs:///share-0 -C  -Z  -N fake'
        self.fakesnapshot_path = '/share-0/.snapshot/snapshot-0'
        self.hadoop_bin = '/usr/bin/hadoop'
        self.maprcli_bin = '/usr/bin/maprcli'

        self._driver.api.get_share_metadata = mock.Mock(return_value={})
        self._driver.api.update_share_metadata = mock.Mock()
        utils.execute = mock.Mock()
        socket.gethostname = mock.Mock(return_value='testserver')
        socket.gethostbyname_ex = mock.Mock(return_value=(
            'localhost',
            ['localhost.localdomain', 'testserver'],
            ['127.0.0.1', self.local_ip]))
Esempio n. 34
0
    def setUp(self):
        super(QuobyteShareDriverTestCase, self).setUp()

        self._context = context.get_admin_context()

        CONF.set_default('driver_handles_share_servers', False)

        self.fake_conf = config.Configuration(None)
        self._driver = quobyte.QuobyteShareDriver(configuration=self.fake_conf)
        self._driver.rpc = mock.Mock()
        self.share = fake_share.fake_share(
            share_proto='NFS',
            export_location='fake_location:/quobyte/fake_share')
        self.access = fake_share.fake_access()
Esempio n. 35
0
def create_share_replica(**kwargs):
    """Create a share replica object."""
    replica = {
        'host': 'fake',
        'status': constants.STATUS_CREATING,
    }
    replica.update(kwargs)

    if 'share_id' not in kwargs:
        share = create_share()
        kwargs['share_id'] = share['id']

    return db.share_instance_create(context.get_admin_context(),
                                    kwargs.pop('share_id'), kwargs)
Esempio n. 36
0
 def __init__(self, db, *args, **kwargs):
     """Do initialization."""
     super(GenericShareDriver, self).__init__(*args, **kwargs)
     self.admin_context = context.get_admin_context()
     self.db = db
     self.configuration.append_config_values(share_opts)
     self.configuration.append_config_values(service_instance.server_opts)
     self._helpers = {}
     self.backend_name = self.configuration.safe_get(
         'share_backend_name') or "Cinder_Volumes"
     self.ssh_connections = {}
     self.service_instance_manager = (
         service_instance.ServiceInstanceManager(
             self.db, driver_config=self.configuration))
Esempio n. 37
0
    def setUp(self):
        super(NetAppClusteredDrvTestCase, self).setUp()
        self._context = context.get_admin_context()
        self._db = mock.Mock()
        driver.driver.NetAppApiClient = mock.Mock()
        self.driver = driver.NetAppClusteredShareDriver(
            self._db, configuration=configuration.Configuration(None))
        self.driver._client = mock.Mock()
        self.driver._client.send_request = mock.Mock()
        self._vserver_client = mock.Mock()
        self._vserver_client.send_request = mock.Mock()
        driver.driver.NetAppApiClient = mock.Mock(
            return_value=self._vserver_client)

        self.share = {
            'id': 'fake_uuid',
            'project_id': 'fake_tenant_id',
            'name': 'fake_name',
            'size': 1,
            'share_proto': 'fake',
            'share_network_id': 'fake_net_id',
            'share_server_id': 'fake-share-srv-id',
            'network_info': {
                'network_allocations': [{
                    'ip_address': 'ip'
                }]
            }
        }
        self.snapshot = {
            'id': 'fake_snapshot_uuid',
            'project_id': 'fake_tenant_id',
            'share_id': 'fake_share_id',
            'share': self.share
        }
        self.security_service = {
            'id': 'fake_id',
            'domain': 'FAKE',
            'server': 'fake_server',
            'sid': 'fake_sid',
            'password': '******'
        }
        self.share_server = {
            'backend_details': {
                'vserver_name': 'fake_vserver'
            }
        }
        self.helper = mock.Mock()
        self.driver._helpers = {'FAKE': self.helper}
        self.driver._licenses = ['fake']
Esempio n. 38
0
    def setUp(self):
        super(GPFSShareDriverTestCase, self).setUp()
        self._context = context.get_admin_context()
        self._gpfs_execute = mock.Mock(return_value=('', ''))

        self._helper_fake = mock.Mock()
        CONF.set_default('driver_handles_share_servers', False)
        self.fake_conf = config.Configuration(None)
        self._driver = gpfs.GPFSShareDriver(execute=self._gpfs_execute,
                                            configuration=self.fake_conf)
        self._knfs_helper = gpfs.KNFSHelper(self._gpfs_execute, self.fake_conf)
        self._ces_helper = gpfs.CESHelper(self._gpfs_execute, self.fake_conf)
        self.fakedev = "/dev/gpfs0"
        self.fakefspath = "/gpfs0"
        self.fakesharepath = "/gpfs0/share-fakeid"
        self.fakesnapshotpath = "/gpfs0/.snapshots/snapshot-fakesnapshotid"
        self.mock_object(gpfs.os.path, 'exists', mock.Mock(return_value=True))
        self._driver._helpers = {'KNFS': self._helper_fake}
        self.share = fake_share.fake_share(share_proto='NFS')
        self.server = {
            'backend_details': {
                'ip': '1.2.3.4',
                'instance_id': 'fake'
            }
        }
        self.access = fake_share.fake_access()
        self.snapshot = fake_share.fake_snapshot()
        self.local_ip = "192.11.22.1"
        self.remote_ip = "192.11.22.2"
        gpfs_nfs_server_list = [self.local_ip, self.remote_ip]
        self._knfs_helper.configuration.gpfs_nfs_server_list = \
            gpfs_nfs_server_list
        self._ces_helper.configuration.gpfs_nfs_server_list = \
            gpfs_nfs_server_list
        self._ces_helper.configuration.ganesha_config_path = \
            "fake_ganesha_config_path"
        self.sshlogin = "******"
        self.sshkey = "fake_sshkey"
        self.gservice = "fake_ganesha_service"
        self._ces_helper.configuration.gpfs_ssh_login = self.sshlogin
        self._ces_helper.configuration.gpfs_ssh_private_key = self.sshkey
        self._ces_helper.configuration.ganesha_service_name = self.gservice
        self.mock_object(socket, 'gethostname',
                         mock.Mock(return_value="testserver"))
        self.mock_object(
            socket, 'gethostbyname_ex',
            mock.Mock(return_value=('localhost',
                                    ['localhost.localdomain', 'testserver'],
                                    ['127.0.0.1', self.local_ip])))
Esempio n. 39
0
 def setUp(self):
     super(NetAppCIFSHelperTestCase, self).setUp()
     self._context = context.get_admin_context()
     self.name = 'fake_share_name'
     self.share = {
         'id': 'fake_uuid',
         'tenant_id': 'fake_tenant_id',
         'name': self.name,
         'size': 1,
         'export_location': '//location/%s' % self.name,
         'share_proto': 'fake'
     }
     self.helper = driver.NetAppClusteredCIFSHelper()
     self.stubs.Set(self.helper, '_client', mock.Mock())
     self.stubs.Set(self.helper._client, 'send_request', mock.Mock())
Esempio n. 40
0
    def setUp(self):
        super(GlusterfsShareDriverTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self)
        self._execute = fake_utils.fake_execute
        self._context = context.get_admin_context()
        self.addCleanup(fake_utils.fake_execute_set_repliers, [])
        self.addCleanup(fake_utils.fake_execute_clear_log)

        CONF.set_default('reserved_share_percentage', 50)
        CONF.set_default('driver_handles_share_servers', False)

        self.fake_conf = config.Configuration(None)
        self._driver = glusterfs.GlusterfsShareDriver(
            execute=self._execute, configuration=self.fake_conf)
        self.share = fake_share.fake_share(share_proto='NFS')
Esempio n. 41
0
    def _weigh_object(self, host_state, weight_properties):
        """Pools with existing share server win."""
        pool_mapping = weight_properties.get('server_pools_mapping', {})
        if not pool_mapping:
            return 0

        ctx = context.get_admin_context()
        host = utils.extract_host(host_state.host, 'backend')
        servers = db_api.share_server_get_all_by_host(ctx, host)
        pool = utils.extract_host(host_state.host, 'pool')
        for server in servers:
            if any(pool == p['pool_name']
                   for p in pool_mapping.get(server['id'], [])):
                return 1
        return 0
Esempio n. 42
0
    def setUp(self):
        super(CephFSDriverAltConfigTestCase, self).setUp()
        self._execute = mock.Mock()
        self.fake_conf = configuration.Configuration(None)
        self._context = context.get_admin_context()
        self._share = fake_share.fake_share(share_proto='CEPHFS')

        self.fake_conf.set_default('driver_handles_share_servers', False)
        self.fake_conf.set_default('cephfs_auth_id', 'manila')

        self.mock_object(driver, "ceph_volume_client", MockVolumeClientModule)
        self.mock_object(driver, "ceph_module_found", True)
        self.mock_object(driver, "cephfs_share_path")
        self.mock_object(driver, 'NativeProtocolHelper')
        self.mock_object(driver, 'NFSProtocolHelper')
Esempio n. 43
0
def get_default(ctxt=None):
    """Get the default share group type."""
    name = CONF.default_share_group_type
    if name is None:
        return {}
    if ctxt is None:
        ctxt = context.get_admin_context()
    try:
        return get_by_name(ctxt, name)
    except exception.ShareGroupTypeNotFoundByName:
        LOG.exception(
            _LE("Default share group type '%s' is not found, "
                "please check 'default_share_group_type' config."),
            name,
        )
Esempio n. 44
0
 def _set_share_size(self, share, size):
     volume_name = self._get_volume_name(context.get_admin_context(), share)
     try:
         if share['size'] > size:
             info = self._maprfs_util.get_volume_info(volume_name)
             used = info['totalused']
             if int(used) >= int(size) * units.Ki:
                 raise exception.ShareShrinkingPossibleDataLoss(
                     share_id=share['id'])
         self._maprfs_util.set_volume_size(volume_name, size)
     except exception.ProcessExecutionError:
         msg = (_('Failed to set space quota for the share %(share_name)s.')
                % {'share_name': share['name']})
         LOG.exception(msg)
         raise exception.MapRFSException(msg=msg)
Esempio n. 45
0
    def setUp(self):
        super(GlusterfsNativeShareDriverTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self)
        self._execute = fake_utils.fake_execute
        self._context = context.get_admin_context()

        self.glusterfs_target1 = 'root@host1:/gv1'
        self.glusterfs_target2 = 'root@host2:/gv2'
        self.glusterfs_server1 = 'root@host1'
        self.glusterfs_server2 = 'root@host2'
        self.glusterfs_server1_volumes = 'manila-share-1-1G\nshare1'
        self.glusterfs_server2_volumes = 'manila-share-2-2G\nshare2'
        self.share1 = new_share(export_location=self.glusterfs_target1,
                                status=constants.STATUS_AVAILABLE)
        self.share2 = new_share(export_location=self.glusterfs_target2,
                                status=constants.STATUS_AVAILABLE)
        self.gmgr1 = common.GlusterManager(self.glusterfs_server1,
                                           self._execute,
                                           None,
                                           None,
                                           requires={'volume': False})
        self.gmgr2 = common.GlusterManager(self.glusterfs_server2,
                                           self._execute,
                                           None,
                                           None,
                                           requires={'volume': False})
        self.glusterfs_volumes_dict = ({
            'root@host1:/manila-share-1-1G': {
                'size': 1
            },
            'root@host2:/manila-share-2-2G': {
                'size': 2
            }
        })
        self.glusterfs_used_vols = set(
            ['root@host1:/manila-share-1-1G', 'root@host2:/manila-share-2-2G'])

        CONF.set_default('glusterfs_volume_pattern',
                         'manila-share-\d+-#{size}G$')
        CONF.set_default('driver_handles_share_servers', False)

        self.fake_conf = config.Configuration(None)
        self.mock_object(common.GlusterManager, 'make_gluster_call')

        self._driver = glusterfs_native.GlusterfsNativeShareDriver(
            execute=self._execute, configuration=self.fake_conf)
        self.addCleanup(fake_utils.fake_execute_set_repliers, [])
        self.addCleanup(fake_utils.fake_execute_clear_log)
Esempio n. 46
0
    def setUp(self):
        super(ZadaraVPSAShareDriverTestCase, self).setUp()

        def _safe_get(opt):
            return getattr(self.configuration, opt)

        self._context = context.get_admin_context()
        self.configuration = mock.Mock(spec=configuration.Configuration)
        self.configuration.safe_get = mock.Mock(side_effect=_safe_get)

        global RUNTIME_VARS
        RUNTIME_VARS = copy.deepcopy(DEFAULT_RUNTIME_VARS)

        self.configuration.driver_handles_share_servers = False
        self.configuration.network_config_group = ('fake_network_config_group')
        self.configuration.admin_network_config_group = (
            'fake_admin_network_config_group')
        self.configuration.reserved_percentage = 0
        self.configuration.reserved_snapshot_percentage = 0
        self.configuration.zadara_use_iser = True
        self.configuration.zadara_vpsa_host = '192.168.5.5'
        self.configuration.zadara_vpsa_port = '80'
        self.configuration.zadara_user = '******'
        self.configuration.zadara_password = '******'
        self.configuration.zadara_access_key = '0123456789ABCDEF'
        self.configuration.zadara_vpsa_poolname = 'pool-0001'
        self.configuration.zadara_vol_encrypt = False
        self.configuration.zadara_share_name_template = 'OS_share-%s'
        self.configuration.zadara_share_snap_name_template = (
            'OS_share-snapshot-%s')
        self.configuration.zadara_vpsa_use_ssl = False
        self.configuration.zadara_ssl_cert_verify = False
        self.configuration.zadara_default_snap_policy = False
        self.configuration.zadara_driver_ssl_cert_path = None
        self.configuration.zadara_gen3_vol_compress = True
        self.configuration.zadara_gen3_vol_dedupe = True
        self.configuration.share_backend_name = 'zadaravpsa'
        self.configuration.reserved_share_percentage = '0'
        self.configuration.reserved_share_from_snapshot_percentage = '0'
        self.configuration.replication_domain = None
        self.configuration.filter_function = None
        self.configuration.goodness_function = None
        self.configuration.goodness_function = None
        self.driver = (zadara.ZadaraVPSAShareDriver(
            configuration=self.configuration))
        self.driver.do_setup(None)
        self.driver.api.get_share_metadata = mock.Mock(return_value={})
        self.driver._get_share_export_location = mock.Mock()
Esempio n. 47
0
    def test_create_share_from_snapshot(self):
        """Test share can be created from snapshot."""
        share = self._create_share()
        share_id = share['id']
        snapshot = self._create_snapshot(share_id=share_id)
        snapshot_id = snapshot['id']

        self.share_manager.create_share(self.context,
                                        share_id,
                                        snapshot_id=snapshot_id)
        self.assertEqual(
            share_id,
            db.share_get(context.get_admin_context(), share_id).id)

        shr = db.share_get(self.context, share_id)
        self.assertEqual(shr['status'], 'available')
Esempio n. 48
0
    def setUp(self):
        super(NetAppCIFSHelperTestCase, self).setUp()
        self._context = context.get_admin_context()
        self._db = mock.Mock()

        self.share = {
            'id': 'fake_uuid',
            'tenant_id': 'fake_tenant_id',
            'name': 'fake_name',
            'size': 1,
            'export_location': 'location:/path',
            'share_proto': 'fake'
        }
        self.helper = driver.NetAppClusteredCIFSHelper()
        self.helper._client = mock.Mock()
        self.helper._client.send_request = mock.Mock()
Esempio n. 49
0
    def setUp(self):
        super(GlusterfsShareDriverTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self.stubs)
        self._execute = fake_utils.fake_execute
        self._context = context.get_admin_context()

        CONF.set_default('glusterfs_mount_point_base', '/mnt/nfs')
        CONF.set_default('reserved_share_percentage', 50)

        self.fake_conf = config.Configuration(None)
        self._db = Mock()
        self._driver = glusterfs.GlusterfsShareDriver(
                        self._db, execute=self._execute,
                        configuration=self.fake_conf)
        self._driver.gluster_address = Mock(**gluster_address_attrs)
        self.share = fake_share()
Esempio n. 50
0
def create_share_without_instance(**kwargs):
    share = {
        'share_proto': "NFS",
        'size': 0,
        'snapshot_id': None,
        'share_network_id': None,
        'share_server_id': None,
        'user_id': 'fake',
        'project_id': 'fake',
        'metadata': {},
        'availability_zone': 'fake_availability_zone',
        'status': constants.STATUS_CREATING,
        'host': 'fake_host'
    }
    share.update(copy.deepcopy(kwargs))
    return db.share_create(context.get_admin_context(), share, False)
Esempio n. 51
0
 def list(self):
     """Show a list of all manila services."""
     ctxt = context.get_admin_context()
     services = db.service_get_all(ctxt)
     print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
     print(print_format % (_('Binary'), _('Host'), _('Zone'), _('Status'),
                           _('State'), _('Updated At')))
     for svc in services:
         alive = utils.service_is_up(svc)
         art = ":-)" if alive else "XXX"
         status = 'enabled'
         if svc['disabled']:
             status = 'disabled'
         print(print_format %
               (svc['binary'], svc['host'].partition('.')[0],
                svc['availability_zone'], status, art, svc['updated_at']))
Esempio n. 52
0
def create_access(**kwargs):
    """Create an access rule object."""
    state = kwargs.pop('state', constants.ACCESS_STATE_QUEUED_TO_APPLY)
    access = {
        'access_type': 'fake_type',
        'access_to': 'fake_IP',
        'share_id': kwargs.pop('share_id', None) or create_share()['id'],
    }
    access.update(kwargs)
    share_access_rule = _create_db_row(db.share_access_create, access, kwargs)

    for mapping in share_access_rule.instance_mappings:
        db.share_instance_access_update(
            context.get_admin_context(), share_access_rule['id'],
            mapping.share_instance_id, {'state': state})

    return share_access_rule
Esempio n. 53
0
def get_default_volume_type():
    """Get the default volume type."""
    name = CONF.default_volume_type
    vol_type = {}

    if name is not None:
        ctxt = context.get_admin_context()
        try:
            vol_type = get_volume_type_by_name(ctxt, name)
        except exception.VolumeTypeNotFoundByName as e:
            # Couldn't find volume type with the name in default_volume_type
            # flag, record this issue and move on
            # TODO(zhiteng) consider add notification to warn admin
            LOG.exception(_('Default volume type is not found, '
                            'please check default_volume_type config: %s'), e)

    return vol_type
Esempio n. 54
0
    def list(self, zone=None):
        """Show a list of all physical hosts. Filter by zone.

        args: [zone]
        """
        print("%-25s\t%-15s" % (_('host'), _('zone')))
        ctxt = context.get_admin_context()
        services = db.service_get_all(ctxt)
        if zone:
            services = [s for s in services if s['availability_zone'] == zone]
        hosts = []
        for srv in services:
            if not [h for h in hosts if h['host'] == srv['host']]:
                hosts.append(srv)

        for h in hosts:
            print("%-25s\t%-15s" % (h['host'], h['availability_zone']))
Esempio n. 55
0
    def update_host(self, current_host, new_host, force=False):
        """Modify the host name associated with a share.

           Particularly to recover from cases where one has moved
           their Manila Share node, or modified their 'host' opt
           or their backend section name in the manila configuration file.
        """
        if not force:
            self._validate_hosts(current_host, new_host)
        ctxt = context.get_admin_context()
        updated = db.share_instances_host_update(ctxt, current_host, new_host)
        print("Updated host of %(count)s share instances on %(chost)s "
              "to %(nhost)s." % {
                  'count': updated,
                  'chost': current_host,
                  'nhost': new_host
              })
Esempio n. 56
0
    def setUp(self):
        super(CephFSNativeDriverTestCase, self).setUp()
        self.fake_conf = configuration.Configuration(None)
        self._context = context.get_admin_context()
        self._share = fake_share.fake_share(share_proto='CEPHFS')

        self.fake_conf.set_default('driver_handles_share_servers', False)

        self.mock_object(cephfs_native, "ceph_volume_client",
                         MockVolumeClientModule)
        self.mock_object(cephfs_native, "ceph_module_found", True)

        self._driver = (cephfs_native.CephFSNativeDriver(
            configuration=self.fake_conf))

        self.mock_object(share_types, 'get_share_type_extra_specs',
                         mock.Mock(return_value={}))
Esempio n. 57
0
 def execute_pre_hook(self, context=None, func_name=None, *args, **kwargs):
     """Hook called before driver's action."""
     if not self.pre_hooks_enabled:
         return
     LOG.debug("Running 'pre hook'.")
     context = context or ctxt.get_admin_context()
     try:
         pre_data = self._execute_pre_hook(context=context,
                                           func_name=func_name,
                                           *args,
                                           **kwargs)
     except Exception as e:
         if self.suppress_pre_hooks_errors:
             LOG.warning("\nSuppressed exception in pre hook. %s\n", e)
             pre_data = e
         else:
             raise
     return pre_data
Esempio n. 58
0
    def setUp(self):
        super(GlusterfsShareDriverTestCase, self).setUp()
        fake_utils.stub_out_utils_execute(self.stubs)
        self._execute = fake_utils.fake_execute
        self._context = context.get_admin_context()

        CONF.set_default('glusterfs_target', '127.0.0.1:/testvol')
        CONF.set_default('glusterfs_mount_point_base', '/mnt/nfs')
        CONF.set_default('reserved_share_percentage', 50)

        self.fake_conf = config.Configuration(None)
        self._db = mock.Mock()
        self._driver = glusterfs.GlusterfsShareDriver(
            self._db, execute=self._execute, configuration=self.fake_conf)
        self._driver.gluster_address = (mock.Mock(
            make_gluster_args=mock.Mock(return_value=(('true', ), {})),
            **gluster_address_attrs))
        self.share = fake_share()
Esempio n. 59
0
    def start(self):
        version_string = version.version_string()
        LOG.info('Starting %(topic)s node (version %(version_string)s)', {
            'topic': self.topic,
            'version_string': version_string
        })
        self.model_disconnected = False
        ctxt = context.get_admin_context()

        if self.coordinator:
            coordination.LOCK_COORDINATOR.start()

        try:
            service_ref = db.service_get_by_args(ctxt, self.host, self.binary)
            self.service_id = service_ref['id']
        except exception.NotFound:
            self._create_service_ref(ctxt)

        LOG.debug("Creating RPC server for service %s.", self.topic)

        target = messaging.Target(topic=self.topic, server=self.host)
        endpoints = [self.manager]
        endpoints.extend(self.manager.additional_endpoints)
        self.rpcserver = rpc.get_server(target, endpoints)
        self.rpcserver.start()

        self.manager.init_host()
        if self.report_interval:
            pulse = loopingcall.FixedIntervalLoopingCall(self.report_state)
            pulse.start(interval=self.report_interval,
                        initial_delay=self.report_interval)
            self.timers.append(pulse)

        if self.periodic_interval:
            if self.periodic_fuzzy_delay:
                initial_delay = random.randint(0, self.periodic_fuzzy_delay)
            else:
                initial_delay = None

            periodic = loopingcall.FixedIntervalLoopingCall(
                self.periodic_tasks)
            periodic.start(interval=self.periodic_interval,
                           initial_delay=initial_delay)
            self.timers.append(periodic)
Esempio n. 60
0
    def setUp(self):
        def _safe_get(opt):
            return getattr(self.cfg, opt)

        self.cfg = mock.Mock(spec=conf.Configuration)
        self.cfg.nexenta_nas_host = '1.1.1.1'
        super(TestNexentaNasDriver, self).setUp()

        self.ctx = context.get_admin_context()
        self.cfg.safe_get = mock.Mock(side_effect=_safe_get)
        self.cfg.nexenta_rest_port = 1000
        self.cfg.reserved_share_percentage = 0
        self.cfg.reserved_share_from_snapshot_percentage = 0
        self.cfg.max_over_subscription_ratio = 0
        self.cfg.nexenta_rest_protocol = 'auto'
        self.cfg.nexenta_volume = 'volume'
        self.cfg.nexenta_nfs_share = 'nfs_share'
        self.cfg.nexenta_user = '******'
        self.cfg.nexenta_password = '******'
        self.cfg.nexenta_thin_provisioning = False
        self.cfg.enabled_share_protocols = 'NFS'
        self.cfg.nexenta_mount_point_base = '$state_path/mnt'
        self.cfg.share_backend_name = 'NexentaStor'
        self.cfg.nexenta_dataset_compression = 'on'
        self.cfg.nexenta_smb = 'on'
        self.cfg.nexenta_nfs = 'on'
        self.cfg.nexenta_dataset_dedupe = 'on'

        self.cfg.network_config_group = 'DEFAULT'
        self.cfg.admin_network_config_group = (
            'fake_admin_network_config_group')
        self.cfg.driver_handles_share_servers = False

        self.request_params = RequestParams('http', self.cfg.nexenta_nas_host,
                                            self.cfg.nexenta_rest_port,
                                            '/rest/nms/',
                                            self.cfg.nexenta_user,
                                            self.cfg.nexenta_password)

        self.drv = nexenta_nas.NexentaNasDriver(configuration=self.cfg)
        self.drv.do_setup(self.ctx)

        self.volume = self.cfg.nexenta_volume
        self.share = self.cfg.nexenta_nfs_share