teemtee / tmt

Test Management Tool
MIT License
82 stars 122 forks source link

or/and will override other hardware constraints in Beaker job XML #3273

Open skycastlelily opened 2 hours ago

skycastlelily commented 2 hours ago

Here is the hardware part of a reproducer plan file:

    hardware:
        disk:
            - size: "> 32 GiB"
            - size: "> 16 GiB"
        memory: "> 6 GiB"
        or:
          - cpu:
               model: 65
          - cpu:
               model: 67

ie, a server with two disks, memory> 6GiB, cpu model is 65 or 67 And here is the hostRequires part of the beaker job xml

      <hostRequires>
        <and>
          <cpu>
            <model op="==" value="65"/>
          </cpu>
        </and>
        <system_type value="Machine"/>
      </hostRequires>

disk.size and memory requires are abandoned somehow

happz commented 2 hours ago

and/or shall not be mixed with other requirements in one block. tmt will indeed ignore requirements because of how this is parsed:

@ungroupify
def _parse_block(spec: Spec) -> BaseConstraint:
    ...

    if 'and' in spec:
        return _parse_and(spec['and'])

    if 'or' in spec:
        return _parse_or(spec['or'])

    return _parse_generic_spec(spec)

This is how it should be rewritten:

hardware:
  and:
    - disk:
        - size: "> 32 GiB"
        - size: "> 16 GiB"
    - memory: "> 6 GiB"
    - or:
      - cpu:
          model: 65
      - cpu:
          model: 67

The question is, did tmt complain about plan being incorrect? If it didn't that's the bug to fix. AFAICT, tmt should have complained because schema allows just one of the options:

  hardware:
    oneOf:
      - "$ref": "#/definitions/block"
      - "$ref": "#/definitions/and"
      - "$ref": "#/definitions/or"

So this seems like a question of better warning rather than and/or processing being broken.

skycastlelily commented 1 hour ago

Tmt doesn't complaint,and here is the merge request make it complaint: https://github.com/teemtee/tmt/pull/3275😁

On Thu, Oct 10, 2024 at 5:20 PM Miloš Prchlík @.***> wrote:

and/or shall not be mixed with other requirements in one block. tmt will indeed ignore requirements because of how this is parsed:

@ungroupifydef _parse_block(spec: Spec) -> BaseConstraint: ...

if 'and' in spec:
    return _parse_and(spec['and'])

if 'or' in spec:
    return _parse_or(spec['or'])

return _parse_generic_spec(spec)

This is how it should be rewritten:

hardware: and:

  • disk:
    • size: "> 32 GiB"
    • size: "> 16 GiB"
  • memory: "> 6 GiB"
  • or:
    • cpu: model: 65
    • cpu: model: 67

The question is, did tmt complain about plan being incorrect? If it didn't that's the bug to fix. AFAICT, tmt should have complained because schema allows just one of the options:

hardware: oneOf:

  • "$ref": "#/definitions/block"
  • "$ref": "#/definitions/and"
  • "$ref": "#/definitions/or"

So this seems like a question of better warning rather than and/or processing being broken.

— Reply to this email directly, view it on GitHub https://github.com/teemtee/tmt/issues/3273#issuecomment-2404558061, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKFR23GH6IGHNO2BPWLIFXDZ2ZBDXAVCNFSM6AAAAABPWJJN4KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBUGU2TQMBWGE . You are receiving this because you authored the thread.Message ID: @.***>

happz commented 29 minutes ago

But tmt does complain:

happz@multivac /tmp/foo $ cat plans.fmf 
discover:
  how: shell
  tests:
    - name: foo
      script: /bin/true

execute:
  how: tmt

provision:
    hardware:
        disk:
            - size: "> 32 GiB"
            - size: "> 16 GiB"
        memory: "> 6 GiB"
        or:
          - cpu:
               model: 65
          - cpu:
               model: 67
happz@multivac /tmp/foo $ tmt lint /plans
    warn: /plans:discover - {'how': 'shell', 'tests': [{'name': 'foo', 'script': '/bin/true'}]} is not valid under any of the given schemas
    warn: /plans:provision - {'hardware': {'disk': [{'size': '> 32 GiB'}, {'size': '> 16 GiB'}], 'memory': '> 6 GiB', 'or': [{'cpu': {'model': 65}}, {'cpu': {'model': 67}}]}, 'how': 'virtual'} is not valid under any of the given schemas
/plans
warn C000 key "tests" not recognized by schema /schemas/discover/fmf
warn C000 value of "how" is not "fmf"
warn C000 key "script" not recognized by schema, and does not match "^extra-" pattern
warn C000 value of "how" is not "artemis"
warn C000 value of "how" is not "beaker"
warn C000 key "hardware" not recognized by schema /schemas/provision/connect
warn C000 value of "how" is not "connect"
warn C000 key "hardware" not recognized by schema /schemas/provision/container
warn C000 value of "how" is not "container"
warn C000 key "hardware" not recognized by schema /schemas/provision/local
warn C000 value of "how" is not "local"
warn C000 key "hardware" not recognized by schema /schemas/provision/minute
warn C000 value of "how" is not "minute"
warn C000 key "hardware" not recognized by schema /schemas/provision/virtual
warn C000 fmf node failed schema validation
warn C001 summary key is missing

It reports plan fails the schema validation, and hardware key does not match the schema. So the problem is reported.

I wouldn't put a new extra special check into the code, we should instead try to focus on making the schema validation reporting better and easier to understand.

happz commented 26 minutes ago

I have some experiments with better JSON schema error rendering in my stash, I'll try to resurrect it & test it with the example above.