コード例 #1
0
def test_functions_cortx_pillar_show_skeleton(
    run_script, mhost, mlocalhost,
    ssh_config, remote, component, project_path,
    install_provisioner
):
    h.install_provisioner_api(mhost)

    # 1. get pillar to compare
    # TODO python3.6 ???
    pillar_content = mhost.check_output(
        f"provisioner configure_cortx {component} --show"
    )

    # 2. call the script
    hostspec = mhost.hostname if remote else "''"
    ssh_config = ssh_config if remote else "''"
    with_sudo = 'false'  # TODO

    script = """
        cortx_pillar_show_skeleton {} {} {} {}
    """.format(component, hostspec, ssh_config, with_sudo)

    res = run_script(script, mhost=(mlocalhost if remote else mhost))

    # 3. verify
    assert res.rc == 0
    assert res.stdout.strip() == pillar_content
コード例 #2
0
def test_pyinstaller_approach(
    mhostsrvnode1, tmpdir_function, request
):
    # Note. python system libarary dir
    # python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'  # noqa: E501

    import inspect

    app_script = (
        """
            import importlib

            import provisioner
            import provisioner.freeze

            pillar = provisioner.pillar_get()
            print(pillar)

            try:
                importlib.import_module('salt')
            except ImportError:
                pass
            else:
                assert False, "salt is available"

            try:
                importlib.import_module('provisioner._api')
            except ImportError:
                pass
            else:
                assert False, "provisioner._api is available"
        """
    )
    app_script = inspect.cleandoc(app_script)

    app_path_local = tmpdir_function / 'myapp.py'
    app_path_local.write_text(app_script)
    app_path_remote = mhostsrvnode1.copy_to_host(app_path_local)

    install_provisioner_api(mhostsrvnode1)
    mhostsrvnode1.check_output("pip3 install pyinstaller")

    mhostsrvnode1.check_output(
        "cd {} && pyinstaller {}"
        .format(app_path_remote.parent, app_path_remote.name)
    )

    mhostsrvnode1.check_output(
        "{0}/dist/{1}/{1}"
        .format(app_path_remote.parent, app_path_remote.stem)
    )
コード例 #3
0
    def _f(test_mhost):
        _test_path = Path(str(test_path)).relative_to(project_path)
        inner_test_src = (_test_path.parent /
                          "{}_inner.py".format(_test_path.stem))

        # TODO limit to only necessary ones
        for mhost in hosts_meta.values():
            if mhost is test_mhost:
                h.install_provisioner_api(mhost)
                # TODO use requirements or setup.py
                mhost.check_output("pip3 install pytest==5.1.1")
                inner_tests_path = mhost.tmpdir / 'test.py'
                mhost.check_output("cp -f {} {}".format(
                    mhost.repo / inner_test_src, inner_tests_path))
                return inner_tests_path

        raise RuntimeError('no hosts matched')
コード例 #4
0
def test_configure_cortx_show(mhost, mlocalhost, ssh_config, remote,
                              install_provisioner, run_script):
    # Note. not parametrized per component since the test copies
    #       test_functions.sh:test_functions_cortx_pillar_show_skeleton a lot
    component = 'cluster'

    h.install_provisioner_api(mhost)

    # TODO python3.6 ???
    pillar_content = mhost.check_output(
        f"provisioner configure_cortx {component} --show")

    remote = '--remote {}'.format(mhost.hostname) if remote else ''
    ssh_config = '--ssh-config {}'.format(ssh_config) if remote else ''
    with_sudo = ''  # TODO

    res = run_script(
        f"{ssh_config} {with_sudo} {remote} --show-file-format {component}",
        mhost=(mlocalhost if remote else mhost))
    assert res.rc == 0
    assert res.stdout.strip() == pillar_content
コード例 #5
0
def test_configure_cortx_update_and_load_default(mhost, mlocalhost, ssh_config,
                                                 remote, install_provisioner,
                                                 run_script):
    # Note. not parametrized per component since the test copies
    #       test_functions.sh:test_functions_cortx_pillar_update_and_load_default
    #       a lot
    component = 'cluster'

    h.install_provisioner_api(mhost)

    # verify that the script accepts all pillar components
    for comp in h.PRVSNR_CORTX_COMPONENTS:
        run_script("--show-file-format {}".format(comp), mhost=mhost)

    # 1. prepare some valid pillar for the component
    res = run_script("--show-file-format {}".format(component), mhost=mhost)
    assert res.rc == 0

    pillar_new_key = 'test'

    new_pillar_content = res.stdout
    new_pillar_dict = yaml.safe_load(new_pillar_content.strip())
    new_pillar_dict.update({pillar_new_key: "temporary"})

    component_pillar = '{}.sls'.format(component)
    tmp_file = mlocalhost.tmpdir / component_pillar
    tmp_file.write_text(
        yaml.dump(new_pillar_dict, default_flow_style=False, canonical=False))
    if not remote:
        host_tmp_file = mhost.tmpdir / component_pillar
        mlocalhost.check_output("scp -F {0} {1} {2}:{3}".format(
            ssh_config, tmp_file, mhost.hostname, host_tmp_file))
        tmp_file = host_tmp_file

    # 2. call the script to update
    remote = '--remote {}'.format(mhost.hostname) if remote else ''
    ssh_config = '--ssh-config {}'.format(ssh_config) if remote else ''
    with_sudo = ''  # TODO

    res = run_script("{} {} {} --file {} {}".format(ssh_config, with_sudo,
                                                    remote, tmp_file,
                                                    component),
                     mhost=(mlocalhost if remote else mhost))

    # 3. verify
    assert res.rc == 0

    tmp_file_content = (mlocalhost if remote else mhost).check_output(
        'cat {}'.format(tmp_file))
    current_def_pillar = h.PRVSNR_PILLAR_DIR / 'components' / component_pillar
    current_user_pillar = h.PRVSNR_USER_PILLAR_ALL_HOSTS_DIR / component_pillar
    pillar_file_content = mhost.check_output(
        'cat {}'.format(current_user_pillar))

    tmp_file_dict = yaml.safe_load(tmp_file_content)
    pillar_file_dict = yaml.safe_load(pillar_file_content)
    assert tmp_file_dict == pillar_file_dict

    # 4. call the script to reset to defaults
    res = run_script("--load-default {} {} {} {}".format(
        ssh_config, with_sudo, remote, component),
                     mhost=(mlocalhost if remote else mhost))

    # 5. verify
    assert res.rc == 0

    pillar_file_content = mhost.check_output(
        'cat {}'.format(current_def_pillar))
    pillar_file_dict = yaml.safe_load(pillar_file_content)
    del new_pillar_dict[pillar_new_key]
    assert new_pillar_dict == pillar_file_dict
コード例 #6
0
def test_functions_cortx_pillar_update_and_load_default(
    run_script, mhost, mlocalhost, tmpdir_function,
    ssh_config, remote, component, project_path,
    install_provisioner, mock_hosts
):
    pillar_new_key = 'test'

    h.install_provisioner_api(mhost)
    # 1. prepare some valid pillar for the component
    # TODO python3.6 ???
    new_pillar_content = mhost.check_output(
        f"provisioner configure_cortx {component} --show"
    )
    new_pillar_dict = yaml.safe_load(new_pillar_content.strip())
    new_pillar_dict.update({pillar_new_key: "temporary"})

    component_pillar = '{}.sls'.format(component)
    tmp_file = tmpdir_function / component_pillar
    tmp_file.write_text(
        yaml.dump(new_pillar_dict, default_flow_style=False, canonical=False)
    )
    if not remote:
        host_tmp_file = mhost.tmpdir / component_pillar
        mlocalhost.check_output(
            "scp -F {0} {1} {2}:{3}".format(
                ssh_config,
                tmp_file,
                mhost.hostname,
                host_tmp_file
            )
        )
        tmp_file = host_tmp_file

    # 2. call the update script
    hostspec = mhost.hostname if remote else "''"
    ssh_config = ssh_config if remote else "''"
    with_sudo = 'false'  # TODO

    script = """
        cortx_pillar_update {} {} {} {} {}
    """.format(component, tmp_file, hostspec, ssh_config, with_sudo)

    res = run_script(script, mhost=(mlocalhost if remote else mhost))

    # 3. verify
    assert res.rc == 0

    tmp_file_content = (mlocalhost if remote else mhost).check_output(
        'cat {}'.format(tmp_file)
    )
    current_def_pillar = h.PRVSNR_PILLAR_DIR / 'components' / component_pillar
    current_user_pillar = h.PRVSNR_USER_PILLAR_ALL_HOSTS_DIR / component_pillar
    pillar_file_content = mhost.check_output(
        'cat {}'.format(current_user_pillar)
    )

    tmp_file_dict = yaml.safe_load(tmp_file_content)
    pillar_file_dict = yaml.safe_load(pillar_file_content)
    assert tmp_file_dict == pillar_file_dict

    # check that pillar has been refreshed on the minions
    expected_lines = [
        'SALT-ARGS: * saltutil.refresh_pillar'
    ]
    assert res.stdout.count('SALT-ARGS: ') == len(expected_lines)

    stdout_lines = res.stdout.split(os.linesep)
    ind = stdout_lines.index(expected_lines[0])
    assert stdout_lines[ind:(ind + len(expected_lines))] == expected_lines

    # 4. call the script to reset to defaults
    script = """
        cortx_pillar_load_default {} {} {} {}
    """.format(component, hostspec, ssh_config, with_sudo)

    res = run_script(script, mhost=(mlocalhost if remote else mhost))

    # 5. verify
    assert res.rc == 0

    pillar_file_content = mhost.check_output(
        'cat {}'.format(current_def_pillar)
    )
    pillar_file_dict = yaml.safe_load(pillar_file_content)
    del new_pillar_dict[pillar_new_key]
    assert new_pillar_dict == pillar_file_dict

    assert res.stdout.count('SALT-ARGS: ') == len(expected_lines)

    stdout_lines = res.stdout.split(os.linesep)
    ind = stdout_lines.index(expected_lines[0])
    assert stdout_lines[ind:(ind + len(expected_lines))] == expected_lines
コード例 #7
0
ファイル: test_rollback.py プロジェクト: ypise/cortx-prvsnr
def test_yum_rollback_manager(mhostsrvnode1, run_test, cortx_hosts):
    install_provisioner_api(mhostsrvnode1)
    run_test(mhostsrvnode1,
             env={'TEST_MINION_ID': cortx_hosts['srvnode1']['minion_id']})