Beispiel #1
0
def synthetic_host(address=None,
                   nids=list([]),
                   storage_resource=False,
                   fqdn=None,
                   nodename=None,
                   server_profile='test_profile'):
    """
    Create a ManagedHost + paraphernalia, with states set as if configuration happened successfully

    :param storage_resource: If true, create a PluginAgentResources (additional overhead, only sometimes required)
    """

    server_profile = ServerProfile.objects.get(name=server_profile)

    if address is None:
        address = random_str(postfix=".tld")

    if fqdn is None:
        fqdn = address
    if nodename is None:
        nodename = address

    host = ManagedHost.objects.create(
        address=address,
        fqdn=fqdn,
        nodename=nodename,
        state='managed',
        server_profile=server_profile,
        immutable_state=not server_profile.managed
        if server_profile else False)

    ObjectCache.add(ManagedHost, host)

    lnet_configuration = synthetic_lnet_configuration(host, nids)

    if server_profile.managed:
        synthetic_rsyslog_configuration(host)
        synthetic_ntp_configuration(host)
        synthetic_corosync_configuration(host)
        synthetic_pacemaker_configuration(host)

    log.debug("synthetic_host: %s %s" %
              (address, lnet_configuration.get_nids()))

    if storage_resource:
        from chroma_core.lib.storage_plugin.manager import storage_plugin_manager
        resource_class, resource_class_id = storage_plugin_manager.get_plugin_resource_class(
            'linux', 'PluginAgentResources')
        StorageResourceRecord.get_or_create_root(resource_class,
                                                 resource_class_id, {
                                                     'plugin_name': 'linux',
                                                     'host_id': host.id
                                                 })

    return host
    def obj_create(self, bundle, request=None, **kwargs):
        # Note: not importing this at module scope so that this module can
        # be imported without loading plugins (useful at installation)
        from chroma_core.lib.storage_plugin.manager import storage_plugin_manager
        resource_class, resource_class_id = storage_plugin_manager.get_plugin_resource_class(
            bundle.data['plugin_name'], bundle.data['class_name'])
        attrs = {}
        input_attrs = bundle.data['attrs']
        for name, property in resource_class.get_all_attribute_properties():
            if name in input_attrs:
                attrs[name] = property.encrypt(property.cast(
                    input_attrs[name]))
            elif property.default:
                attrs[name] = property.default
            elif not property.optional:
                # TODO: proper validation
                raise RuntimeError("%s not optional" % name)

        # Construct a record
        record, created = StorageResourceRecord.get_or_create_root(
            resource_class, resource_class_id, attrs)
        #record_dict = self.full_dehydrate(self.build_bundle(obj = record)).data
        bundle.obj = record

        return bundle
Beispiel #3
0
def synthetic_volume(serial=None, with_storage=True, usable_for_lustre=True):
    """
    Create a Volume and an underlying StorageResourceRecord
    """
    volume = Volume.objects.create()

    if not serial:
        serial = "foobar%d" % volume.id

    attrs = {'serial': serial, 'size': 8192000}

    if with_storage:
        from chroma_core.lib.storage_plugin.manager import storage_plugin_manager
        resource_class, resource_class_id = storage_plugin_manager.get_plugin_resource_class(
            'linux', 'ScsiDevice')

        storage_resource, created = StorageResourceRecord.get_or_create_root(
            resource_class, resource_class_id, attrs)

        volume.storage_resource = storage_resource

    volume.usable_for_lustre = usable_for_lustre

    volume.save()

    return volume
    def setUp(self):
        super(TestCallbacks, self).setUp()

        import chroma_core.lib.storage_plugin.manager

        self.orig_manager = chroma_core.lib.storage_plugin.manager.storage_plugin_manager
        chroma_core.lib.storage_plugin.manager.storage_plugin_manager = (
            chroma_core.lib.storage_plugin.manager.StoragePluginManager()
        )

        from chroma_core.lib.storage_plugin.manager import storage_plugin_manager

        storage_plugin_manager._load_plugin(sys.modules[__name__], "test_mod", TestPlugin)

        from chroma_core.models import StorageResourceRecord

        resource_class, resource_class_id = storage_plugin_manager.get_plugin_resource_class(
            "test_mod", "TestGlobalResource"
        )
        record, created = StorageResourceRecord.get_or_create_root(resource_class, resource_class_id, {"name": "test1"})

        from chroma_core.lib.storage_plugin.query import ResourceQuery

        scannable_record = StorageResourceRecord.objects.get()
        self.scannable_resource = ResourceQuery().get_resource(scannable_record)
        self.scannable_global_id = scannable_record.pk

        self.resource_manager = mock.Mock(_sessions={})
        self.plugin = TestPlugin(self.resource_manager, self.scannable_global_id)
        self.resource_manager._sessions[self.scannable_global_id] = PluginSession(
            self.plugin, self.scannable_global_id, 0
        )
Beispiel #5
0
 def test_root_resource(self):
     """Test that the manager creates and returns a scannable resource"""
     from chroma_core.models import StorageResourceRecord
     resource_class, resource_class_id = self.manager.get_plugin_resource_class(
         'loadable_plugin', 'TestScannableResource')
     record, created = StorageResourceRecord.get_or_create_root(
         resource_class, resource_class_id, {'name': 'foobar'})
     self.assertEqual(
         self.manager.get_scannable_resource_ids('loadable_plugin'),
         [record.pk])
Beispiel #6
0
    def _create_plugin_instance(self, host):
        from chroma_core.lib.storage_plugin.manager import storage_plugin_manager

        resource_class, resource_class_id = storage_plugin_manager.get_plugin_resource_class(
            "linux", "PluginAgentResources")
        # FIXME: it is weird that the PluginAgentResources class lives in the linux plugin but is used by all of them
        record, created = StorageResourceRecord.get_or_create_root(
            resource_class, resource_class_id, {
                "plugin_name": self._plugin_name,
                "host_id": host.id
            })

        return self._plugin_klass(self._resource_manager, record.id)
Beispiel #7
0
    def setUp(self):
        super(TestReferenceAttribute, self).setUp()

        import chroma_core.lib.storage_plugin.manager
        self.original_mgr = chroma_core.lib.storage_plugin.manager.storage_plugin_manager

        mgr = load_plugins(['loadable_plugin'])
        chroma_core.lib.storage_plugin.manager.storage_plugin_manager = mgr

        from chroma_core.models import StorageResourceRecord
        resource_class, resource_class_id = mgr.get_plugin_resource_class('loadable_plugin', 'TestScannableResource')
        record, created = StorageResourceRecord.get_or_create_root(resource_class, resource_class_id, {'name': 'foobar'})
        self.record_pk = record.pk

        self.manager = mgr
Beispiel #8
0
    def setUp(self):
        super(TestAddRemove, self).setUp()

        import chroma_core.lib.storage_plugin.manager
        self.orig_manager = chroma_core.lib.storage_plugin.manager.storage_plugin_manager
        chroma_core.lib.storage_plugin.manager.storage_plugin_manager = chroma_core.lib.storage_plugin.manager.StoragePluginManager(
        )

        from chroma_core.lib.storage_plugin.manager import storage_plugin_manager
        storage_plugin_manager._load_plugin(sys.modules[__name__], 'test_mod',
                                            TestPlugin)

        from chroma_core.models import StorageResourceRecord
        resource_class, resource_class_id = storage_plugin_manager.get_plugin_resource_class(
            'test_mod', 'TestGlobalResource')
        record, created = StorageResourceRecord.get_or_create_root(
            resource_class, resource_class_id, {'name': 'test1'})

        from chroma_core.lib.storage_plugin.query import ResourceQuery

        scannable_record = StorageResourceRecord.objects.get()
        self.scannable_resource = ResourceQuery().get_resource(
            scannable_record)
        self.scannable_global_id = scannable_record.pk