コード例 #1
0
ファイル: test_share.py プロジェクト: aostapenko/manila
    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)
コード例 #2
0
ファイル: test_share.py プロジェクト: aostapenko/manila
    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()
コード例 #3
0
ファイル: test_service.py プロジェクト: mbr4v0v/manila
 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'])
コード例 #4
0
ファイル: test_service.py プロジェクト: sajuptpm/manila
 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"])
コード例 #5
0
ファイル: test_share.py プロジェクト: grafuls/manila
 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
コード例 #6
0
ファイル: test_share.py プロジェクト: grafuls/manila
 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'])
コード例 #7
0
ファイル: db_utils.py プロジェクト: vponomaryov/manila
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'])
コード例 #8
0
    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')
コード例 #9
0
ファイル: manager.py プロジェクト: aawm/manila
    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
        )
コード例 #10
0
ファイル: manage.py プロジェクト: openstack/manila
 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'],
         ))
コード例 #11
0
ファイル: service_instance.py プロジェクト: resker/manila
 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()
コード例 #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()
コード例 #13
0
ファイル: generic.py プロジェクト: kleopatra999/manila
 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 = {}
コード例 #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)
コード例 #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())
コード例 #16
0
    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"
コード例 #17
0
ファイル: test_manager.py プロジェクト: ISCAS-VDI/manila-base
 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/')
コード例 #18
0
ファイル: test_nexenta_nas.py プロジェクト: NetApp/manila
    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
コード例 #19
0
ファイル: test_share_lvm.py プロジェクト: mbr4v0v/manila
    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"
コード例 #20
0
ファイル: test_zfssashare.py プロジェクト: NetApp/manila
    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']}
コード例 #21
0
ファイル: manager.py プロジェクト: kleopatra999/manila
    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)
コード例 #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])
        )
コード例 #23
0
ファイル: test_api.py プロジェクト: vponomaryov/manila
    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))
コード例 #24
0
ファイル: service.py プロジェクト: weiting-chen/manila
 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'))
コード例 #25
0
ファイル: test_share.py プロジェクト: grafuls/manila
    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)
コード例 #26
0
ファイル: test_models.py プロジェクト: vponomaryov/manila
    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'])
コード例 #27
0
ファイル: test_hdfs_native.py プロジェクト: jcsp/manila
    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]))
コード例 #28
0
ファイル: service.py プロジェクト: weiting-chen/manila
    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'))
コード例 #29
0
ファイル: test_neutron_api.py プロジェクト: Hussnain1/manila
 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()
コード例 #30
0
ファイル: db_utils.py プロジェクト: vponomaryov/manila
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)
コード例 #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.")
コード例 #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())
コード例 #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]))
コード例 #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()
コード例 #35
0
ファイル: db_utils.py プロジェクト: vkmc/manila
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)
コード例 #36
0
ファイル: generic.py プロジェクト: ddiss/manila
 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))
コード例 #37
0
ファイル: test_cmode_drv.py プロジェクト: mbr4v0v/manila
    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']
コード例 #38
0
ファイル: test_gpfs.py プロジェクト: vkmc/manila
    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])))
コード例 #39
0
ファイル: test_cluster_mode.py プロジェクト: Hussnain1/manila
 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())
コード例 #40
0
ファイル: test_glusterfs.py プロジェクト: vast-data/manila
    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')
コード例 #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
コード例 #42
0
ファイル: test_driver.py プロジェクト: vast-data/manila
    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')
コード例 #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,
        )
コード例 #44
0
ファイル: maprfs_native.py プロジェクト: dinghb/manila
 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)
コード例 #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)
コード例 #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()
コード例 #47
0
ファイル: test_share.py プロジェクト: mbr4v0v/manila
    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')
コード例 #48
0
ファイル: test_cmode_drv.py プロジェクト: mbr4v0v/manila
    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()
コード例 #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()
コード例 #50
0
ファイル: db_utils.py プロジェクト: openstack/manila
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)
コード例 #51
0
ファイル: manage.py プロジェクト: yuyuyu101/manila
 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']))
コード例 #52
0
ファイル: db_utils.py プロジェクト: openstack/manila
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
コード例 #53
0
ファイル: volume_types.py プロジェクト: mbr4v0v/manila
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
コード例 #54
0
ファイル: manage.py プロジェクト: yuyuyu101/manila
    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']))
コード例 #55
0
ファイル: manage.py プロジェクト: gmelikov/manila
    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
              })
コード例 #56
0
ファイル: test_cephfs_native.py プロジェクト: mkoderer/manila
    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={}))
コード例 #57
0
ファイル: hook.py プロジェクト: openstack/manila
 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
コード例 #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()
コード例 #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)
コード例 #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