Esempio n. 1
0
def is_content_ok(content: str, mocker, kv_adapter) -> bool:
    if len(content) < 4:
        # Some templates represent empty JSONs and should be skipped
        return True
    _, path = tempfile.mkstemp()
    try:
        with open(path, 'w') as f:
            f.write(content)

        store = ConfStoreProvider(f'json://{path}')
        mocker.patch.object(store, 'get_machine_id', return_value='machine-id')
        mocker.patch.object(store, 'get_machine_ids_for_service', return_value=['machine-id'])
        motr_store = ValueProvider()
        mocker.patch.object(motr_store, '_raw_get', return_value='/dev/dummy')
        #
        # the method will raise an exception if either
        # Dhall is unhappy or some values are not found in ConfStore
        generator = CdfGenerator(provider=store)
        generator.utils.kv = kv_adapter
        generator.generate()
        return True

    finally:
        if os.path.isfile(path):
            os.unlink(path)
Esempio n. 2
0
    def test_disk_refs_can_be_empty(self):
        store = ValueProvider()

        def ret_values(value: str) -> Any:
            data = {
                'server_node>MACH_ID>storage>cvg_count': 1,
                'cluster>CLUSTER_ID>site>storage_set_count': 1,
                'cluster>CLUSTER_ID>storage_set>server_node_count': 1,
                'cluster>CLUSTER_ID>storage_set[0]>name': 'StorageSet-1',
                'cluster>CLUSTER_ID>storage_set[0]>server_nodes': ['srvnode_1'],
                'cluster>CLUSTER_ID>storage_set[0]>durability>sns': {'stub': 1},
                'cluster>CLUSTER_ID>storage_set[0]>durability>sns>data': 1,
                'cluster>CLUSTER_ID>storage_set[0]>durability>sns>parity': 0,
                'cluster>CLUSTER_ID>storage_set[0]>durability>sns>spare': 0,
                'cluster>cluster_id':
                'CLUSTER_ID',
                'server_node': {
                    'srvnode_1': {
                        'cluster_id': 'CLUSTER_ID'
                    }
                },
                'server_node>srvnode_1>cluster_id':
                'CLUSTER_ID',
                'server_node>srvnode_1>name':
                'myhost',
                'server_node>srvnode_1>hostname':
                'myhost',
                'server_node>srvnode_1>network>data>interface_type':
                'o2ib',
                'server_node>srvnode_1>network>data>private_fqdn':
                    'srvnode-1.data.private',
                'server_node>srvnode_1>network>data>private_interfaces':
                ['eth1', 'eno2'],
                'cortx>software>s3>service>instances':
                1,
                'server_node>srvnode_1>storage>cvg_count':
                2,
                'cortx>software>motr>service>client_instances':
                2,
                'server_node>srvnode_1>storage>cvg':
                [{'data_devices': ['/dev/sdb', '/dev/sdc'], 'metadata_devices': ['/dev/meta', '/dev/meta1']}],
                'server_node>srvnode_1>storage>cvg[0]>data_devices':
                ['/dev/sdb'],
                'server_node>srvnode_1>storage>cvg[1]>data_devices':
                ['/dev/sdc'],
            }
            return data.get(value)

        store._raw_get = Mock(side_effect=ret_values)
        store.get_machine_id = Mock(return_value='MACH_ID')
        store.get_storage_set_nodes = Mock(return_value=['MACH_ID'])
        cdf = CdfGenerator(provider=store, motr_provider=Mock())
        cdf._get_m0d_per_cvg = Mock(return_value=1)
        cdf.generate()
Esempio n. 3
0
    def test_template_sane(self):
        _, path = tempfile.mkstemp()
        try:
            with open(path, 'w') as f:
                f.write(self._get_confstore_template())

            store = ConfStoreProvider(f'json://{path}')
            store.get_machine_id = Mock(return_value='1114a50a6bf6f9c93ebd3c49d07d3fd4')
            #
            # the method will raise an exception if either
            # Dhall is unhappy or some values are not found in ConfStore
            cdf = CdfGenerator(provider=store, motr_provider=Mock())
            cdf._get_m0d_per_cvg = Mock(return_value=1)
            cdf.generate()
        finally:
            os.unlink(path)
Esempio n. 4
0
def generate_cdf(url: str, motr_md_url: str) -> str:
    # ConfStoreProvider creates an empty file, if file does not exist.
    # So, we are validating the file is present or not.
    if not os.path.isfile(urlparse(motr_md_url).path):
        raise FileNotFoundError(f'config file: {motr_md_url} does not exist')
    motr_provider = ConfStoreProvider(motr_md_url, index='motr_md')
    generator = CdfGenerator(ConfStoreProvider(url), motr_provider)
    return generator.generate()
Esempio n. 5
0
def generate_cdf(url: str) -> str:
    generator = CdfGenerator(ConfStoreProvider(url))
    return generator.generate()