Пример #1
0
def test_install_monitor_save_local(install_mockery_mutable_config, mock_fetch,
                                    tmpdir_factory):
    """
    Mock installing and saving monitor results to file.
    """
    reports_dir = tmpdir_factory.mktemp('reports')
    spack.config.set('config:monitor_dir', str(reports_dir))
    out = install('--monitor', '--monitor-save-local', 'dttop')
    assert "Successfully installed dttop" in out

    # The reports directory should not be empty (timestamped folders)
    assert os.listdir(str(reports_dir))

    # Get the spec name
    spec = spack.spec.Spec("dttop")
    spec.concretize()
    full_hash = spec.full_hash()

    # Ensure we have monitor results saved
    for dirname in os.listdir(str(reports_dir)):
        dated_dir = os.path.join(str(reports_dir), dirname)
        build_metadata = "build-metadata-%s.json" % full_hash
        assert build_metadata in os.listdir(dated_dir)
        spec_file = "spec-dttop-%s-config.json" % spec.version
        assert spec_file in os.listdir(dated_dir)

    spack.config.set('config:monitor_dir', "~/.spack/reports/monitor")
Пример #2
0
def test_ordered_read_not_required_for_consistent_dag_hash(
        hash_type, config, mock_packages):
    """Make sure ordered serialization isn't required to preserve hashes.

    For consistent hashes, we require that YAML and json documents
    have their keys serialized in a deterministic order. However, we
    don't want to require them to be serialized in order. This
    ensures that is not required.
    """
    specs = ['mpileaks ^zmpi', 'dttop', 'dtuse']
    for spec in specs:
        spec = Spec(spec)
        spec.concretize()

        #
        # Dict & corresponding YAML & JSON from the original spec.
        #
        spec_dict = spec.to_dict(hash=hash_type)
        spec_yaml = spec.to_yaml(hash=hash_type)
        spec_json = spec.to_json(hash=hash_type)

        #
        # Make a spec with reversed OrderedDicts for every
        # OrderedDict in the original.
        #
        reversed_spec_dict = reverse_all_dicts(spec.to_dict(hash=hash_type))

        #
        # Dump to YAML and JSON
        #
        yaml_string = syaml.dump(spec_dict, default_flow_style=False)
        reversed_yaml_string = syaml.dump(reversed_spec_dict,
                                          default_flow_style=False)
        json_string = sjson.dump(spec_dict)
        reversed_json_string = sjson.dump(reversed_spec_dict)

        #
        # Do many consistency checks
        #

        # spec yaml is ordered like the spec dict
        assert yaml_string == spec_yaml
        assert json_string == spec_json

        # reversed string is different from the original, so it
        # *would* generate a different hash
        assert yaml_string != reversed_yaml_string
        assert json_string != reversed_json_string

        # build specs from the "wrongly" ordered data
        round_trip_yaml_spec = Spec.from_yaml(yaml_string)
        round_trip_json_spec = Spec.from_json(json_string)
        round_trip_reversed_yaml_spec = Spec.from_yaml(reversed_yaml_string)
        round_trip_reversed_json_spec = Spec.from_yaml(reversed_json_string)

        # Strip spec if we stripped the yaml
        spec = spec.copy(deps=hash_type.deptype)

        # specs are equal to the original
        assert spec == round_trip_yaml_spec
        assert spec == round_trip_json_spec

        assert spec == round_trip_reversed_yaml_spec
        assert spec == round_trip_reversed_json_spec
        assert round_trip_yaml_spec == round_trip_reversed_yaml_spec
        assert round_trip_json_spec == round_trip_reversed_json_spec
        # dag_hashes are equal
        assert spec.dag_hash() == round_trip_yaml_spec.dag_hash()
        assert spec.dag_hash() == round_trip_json_spec.dag_hash()
        assert spec.dag_hash() == round_trip_reversed_yaml_spec.dag_hash()
        assert spec.dag_hash() == round_trip_reversed_json_spec.dag_hash()

        # full_hashes are equal if we round-tripped by build_hash or full_hash
        if hash_type in (ht.build_hash, ht.full_hash):
            spec.concretize()
            round_trip_yaml_spec.concretize()
            round_trip_json_spec.concretize()
            round_trip_reversed_yaml_spec.concretize()
            round_trip_reversed_json_spec.concretize()
            assert spec.full_hash() == round_trip_yaml_spec.full_hash()
            assert spec.full_hash() == round_trip_json_spec.full_hash()
            assert spec.full_hash() == round_trip_reversed_yaml_spec.full_hash(
            )
            assert spec.full_hash() == round_trip_reversed_json_spec.full_hash(
            )