Example #1
0
    def _f(mhost):
        test_pillar = {
            'test': {
                'simple': 1,
                'dict': {
                    "2": {
                        "3": 4
                    }
                },
                'list': [5, 6, 7]
            }
        }

        tmp_file = tmpdir_function / 'test.sls'
        dump_yaml(tmp_file, test_pillar)

        # Note. cluster.sls is used as one of listed in pillar/top.sls
        mhost.copy_to_host(
            tmp_file,
            host_path=Path(
                "{}/components/cluster.sls"
                .format(PRVSNR_PILLAR_DIR)
            )
        )

        mhost.check_output(
            "salt '{}' saltutil.refresh_pillar"
            .format(cortx_hosts['srvnode1']['minion_id'])
        )
Example #2
0
def test_dump_yaml_input_check(mocker):
    data_file = 'some-file'
    data_file_content = 'some-file-content'

    mocker.patch.object(utils, 'Path', autospec=True)

    run_m = mocker.patch.object(utils, 'dump_yaml_str', autospec=True)

    utils.dump_yaml(data_file, data_file_content)
    run_m.assert_called_once_with(data_file_content)
Example #3
0
    def run(self, **kwargs):

        node_id = local_minion_id()
        firewall_pillar_sls = Path(f"{PRVSNR_PILLAR_DIR}/components/firewall.sls")

        self.logger.debug(f"updating firewall config on {node_id}")

        try:
            self.logger.debug(f"loading firewall configuration")
            firewall_config_arg = kwargs.get('config')
            self.load_conf_store('index1', firewall_config_arg)
            firewall_conf = {'firewall': Conf.get('index1','firewall') }
            dump_yaml(firewall_pillar_sls, dict(firewall_conf))

            function_run('saltutil.refresh_pillar', targets=node_id)

            self.logger.debug(f"Applying 'components.system.firewall' on {node_id}")
            StatesApplier.apply(
                ["components.system.firewall"],
                local_minion_id()
            )
        except Exception as ex:
            raise ex
        self.logger.debug("Done")
def test_build_isos(mhost, rpm_prvsnr, rpm_prvsnr_api, tmpdir_function):
    res = []

    mhost.check_output("yum install -y createrepo genisoimage")
    single_repo = Path('/tmp/single')
    swupdate_repo = Path('/tmp/cortx')
    cortx_repo = single_repo / config.CORTX_ISO_DIR
    deps_repo = single_repo / config.CORTX_3RD_PARTY_ISO_DIR

    release_info = {
        'BUILD':
        '277',
        'DATETIME':
        '14-Oct-2020 11:21 UTC',
        'KERNEL':
        '3.10.0_1062.el7',
        'NAME':
        'CORTX',
        'OS':
        'Red Hat Enterprise Linux Server release 7.7 (Maipo)',
        'VERSION':
        '1.0.0',
        'COMPONENTS': [
            'cortx-csm_agent-1.0.0-25_9d988be.x86_64.rpm',
            'cortx-csm_web-1.0.0-58_65d6f8b.x86_64.rpm',
            'cortx-ha-1.0.0-34_eacae4e.x86_64.rpm',
            'cortx-hare-1.0.0-50_git584adaa.el7.x86_64.rpm',
            'cortx-libsspl_sec-1.0.0-33_gitf0c05e3.el7.x86_64.rpm',
            'cortx-libsspl_sec-devel-1.0.0-33_gitf0c05e3.el7.x86_64.rpm',
            'cortx-libsspl_sec-method_none-1.0.0-33_gitf0c05e3.el7.x86_64.rpm',
            'cortx-libsspl_sec-method_pki-1.0.0-33_gitf0c05e3.el7.x86_64.rpm',
            'cortx-motr-1.0.0-45_git7fc6c26_3.10.0_1062.el7.x86_64.rpm',
            'cortx-motr-devel-1.0.0-45_git7fc6c26_3.10.0_1062.el7.x86_64.rpm',
            'cortx-motr-tests-ut-1.0.0-45_git7fc6c26_3.10.0_1062.el7.x86_64.rpm',  # noqa: E501
            'cortx-prvsnr-1.0.0-75_gitb9b751c_el7.x86_64.rpm',
            'cortx-prvsnr-cli-1.0.0-75_gitb9b751c_el7.x86_64.rpm',
            'cortx-s3iamcli-1.0.0-75_git28a01f6.noarch.rpm',
            'cortx-s3iamcli-devel-1.0.0-75_git28a01f6.noarch.rpm',
            'cortx-s3server-1.0.0-75_git28a01f6_el7.x86_64.rpm',
            'cortx-sspl-1.0.0-33_gitf0c05e3.el7.noarch.rpm',
            'cortx-sspl-cli-1.0.0-33_gitf0c05e3.el7.noarch.rpm',
            'cortx-sspl-test-1.0.0-33_gitf0c05e3.el7.noarch.rpm',
            'python36-cortx-prvsnr-0.39.0-75_gitb9b751c.x86_64.rpm',
            'uds-pyi-1.1.1-1.r6.el7.x86_64.rpm',
            'udx-discovery-0.1.2-3.el7.x86_64.rpm'
        ]
    }

    for pkg, repo_dir in (('prvsnr', cortx_repo), ('prvsnr_api', deps_repo)):
        iso_path = Path(f'/tmp/{repo_dir.name}.iso')

        mhost.check_output(
            "mkdir -p {repo_dir} {swupdate_repo}"
            " && cp {rpm_path} {repo_dir}"
            " && cp {rpm_path} {swupdate_repo}"
            " && createrepo {repo_dir}"
            " && mkisofs -graft-points -r -l -iso-level 2 -J -o {iso_path} {repo_dir}"  # noqa: E501
            .format(repo_dir=repo_dir,
                    swupdate_repo=swupdate_repo,
                    rpm_path=getattr(mhost, f"rpm_{pkg}"),
                    iso_path=iso_path))
        res.append(mhost.copy_from_host(iso_path))

    # prepare single iso
    iso_path = Path(f'/tmp/{single_repo.name}.iso')
    mhost.check_output(
        "mkisofs -graft-points -r -l -iso-level 2 -J -o {iso_path} {repo_dir}"  # noqa: E501
        .format(repo_dir=single_repo, iso_path=iso_path))
    res.append(mhost.copy_from_host(iso_path))

    # prepare swupdate iso
    iso_path = Path(f'/tmp/{swupdate_repo.name}.iso')

    release_info_file = tmpdir_function / config.RELEASE_INFO_FILE
    dump_yaml(release_info_file, release_info)
    mhost.copy_to_host(release_info_file,
                       swupdate_repo / release_info_file.name)

    mhost.check_output((
        "createrepo {repo_dir}"
        " && mkisofs -graft-points -r -l -iso-level 2 -J -o {iso_path} {repo_dir}"  # noqa: E501
    ).format(repo_dir=swupdate_repo, iso_path=iso_path))
    res.append(mhost.copy_from_host(iso_path))

    for iso_path in res:
        dest = PROJECT_PATH / f"tmp/{iso_path.name}"
        dest.write_bytes(iso_path.read_bytes())
Example #5
0
def test_pillar_updater_update_rollback_dump(targets, some_param_gr,
                                             some_param_di, pillar_dir,
                                             pillar_host_dir_tmpl):
    if targets != ALL_MINIONS:
        pillar_dir = Path(pillar_host_dir_tmpl.format(minion_id=targets))
        pillar_dir.mkdir(parents=True)

    input_param_group = some_param_gr('new-value1', 'new-value2')
    input_param_di = some_param_di('some_key', 'new-value3')

    attr1_param = some_param_gr.param_spec('attr1')
    attr2_param = some_param_gr.param_spec('attr2')
    attr3_param = input_param_di.param_spec()

    f1 = add_pillar_merge_prefix(pillar_dir / attr1_param.fpath.name)
    f2 = add_pillar_merge_prefix(pillar_dir / attr2_param.fpath.name)
    f3 = add_pillar_merge_prefix(pillar_dir / attr3_param.fpath.name)

    pillar_data = {'1': {'2': {'3': '4', '5': '6'}, 'di_parent': {}}}
    dump_yaml(f1, pillar_data)
    dump_yaml(f2, pillar_data)
    dump_yaml(f3, pillar_data)

    pu = PillarUpdater(targets=targets)

    # update (in memory only)
    pu.update(input_param_group, input_param_di)

    p1 = deepcopy(pillar_data)
    p1['1']['2']['3'] = input_param_group.attr1
    assert pu.pillar(f1.name) == p1
    assert load_yaml(f1) == pillar_data

    p2 = deepcopy(pillar_data)
    p2['1']['2']['5'] = input_param_group.attr2
    assert pu.pillar(f2.name) == p2
    assert load_yaml(f2) == pillar_data

    p3 = deepcopy(pillar_data)
    p3['1']['di_parent'] = {input_param_di.key_attr: input_param_di.value_attr}
    assert pu.pillar(f3.name) == p3
    assert load_yaml(f3) == pillar_data

    # update on disk
    pu.dump()
    assert load_yaml(f1) == p1
    assert load_yaml(f2) == p2
    assert load_yaml(f3) == p3

    # rolllback (in memory only)
    pu.rollback()
    assert pu.pillar(f1.name) == pillar_data
    assert load_yaml(f1) == p1

    assert pu.pillar(f2.name) == pillar_data
    assert load_yaml(f2) == p2

    assert pu.pillar(f3.name) == pillar_data
    assert load_yaml(f3) == p3

    # rollback on disk
    pu.dump()
    assert load_yaml(f1) == pillar_data
    assert load_yaml(f2) == pillar_data
    assert load_yaml(f3) == pillar_data