Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS64 Validation Test and Tool #1521

Open
wants to merge 4 commits into
base: 5.2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pscheduler-test-dns64/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Makefile for Any Package
#

AUTO_TARBALL := 1

include unibuild/unibuild.make
1 change: 1 addition & 0 deletions pscheduler-test-dns64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Documentation on how to write a test for pScheduler can be found in the main directory of the PDK in the file test.md (https://github.com/perfsonar/pscheduler/blob/pdk-docs/scripts/PDK/test.md)
47 changes: 47 additions & 0 deletions pscheduler-test-dns64/dns64/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Makefile for any test class
#

NAME=dns64

# TODO: Everything below this should be made into a template that can
# be included.

FILES=\
cli-to-spec \
enumerate \
participants \
result-format \
spec-format \
spec-is-valid \
spec-to-cli

MODULES=\
validate \


PYS=$(MODULES:%=%.py)
PYCS=$(MODULES:%=__pycache__/%.pyc)

$(PYCS):
ifndef DESTDIR
@echo No PYTHON specified for build
@false
endif
$(PYTHON) -m compileall .
TO_CLEAN += $(PYCS)


install: $(FILES) $(PYS) $(PYCS)
ifndef DESTDIR
@echo No DESTDIR specified for installation
@false
endif
mkdir -p $(DESTDIR)
install -m 555 $(FILES) $(DESTDIR)
install -m 444 $(PYS) $(DESTDIR)
cp -r __pycache__ $(DESTDIR)


clean:
rm -f $(TO_CLEAN) *~
117 changes: 117 additions & 0 deletions pscheduler-test-dns64/dns64/cli-to-spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env python3

#
# Development Order #4:
#
# This file encodes CLI arguments as JSON data in a test spec,
# as defined by the datatypes in validate.py
#
# This can be tested directly using the following syntax:
# ./cli-to-spec --option argument
#

import re
import argparse
import pscheduler
import sys

if len(sys.argv) > 1:

# Args are on the command line
args = sys.argv[1:]

else:

# Args are in a JSON array on stdin
json_args = pscheduler.json_load(exit_on_error=True)
args = []

if not isinstance(json_args,list):
pscheduler.fail("Invalid JSON for this operation")
for arg in json_args:
if not ( isinstance(arg, str)
or isinstance(arg, int)
or isinstance(arg, float) ):
pscheduler.fail("Invalid JSON for this operation")
args = [ str(arg) for arg in json_args ]



# Gargle the arguments

arg_parser = argparse.ArgumentParser(epilog=
"""
This test validates DNS64 IPv4 and IPv6 conversion
"""
)

# Add all potential command line options here


arg_parser.add_argument("--query",
help="Hostname to look up.")

arg_parser.add_argument("--nameserver",
help="Nameserver to query.")

arg_parser.add_argument("--host",
help="Host to run the test.")

arg_parser.add_argument("--host-node",
help="Hostname to run the test.", dest="host_node")

arg_parser.add_argument("--translation-prefix",
help="Translation prefix to expect for converted results.",
dest="translation_prefix")

arg_parser.add_argument("--timeout",
help="Timeout for each query attempt",
dest="timeout")


arguments = arg_parser.parse_args(args)


# Call .set(n) on this object to indicate that a parameter requires
# schema level n or higher. The object will return the highest-set
# value when .value() is called.
#
# For example, if the 'foo' parameter was introduced in schema level 2:
#
# if options.foo is not None:
# result['foo'] = options.foo
# schema.set(2)
#
# If this is a brand-new test, you won't need to call .set() since the
# default is 1.

schema = pscheduler.HighInteger(1)


# Build the test specification. All we do here is build and set
# schema levels. Validation happens elsewhere.

result = { }

if arguments.query is not None:
result['query'] = arguments.query

if arguments.nameserver is not None:
result['nameserver'] = arguments.nameserver

if arguments.host is not None:
result['host'] = arguments.host

if arguments.host_node is not None:
result['host-node'] = arguments.host_node

if arguments.translation_prefix is not None:
result['translation-prefix'] = arguments.translation_prefix

if arguments.timeout is not None:
result['timeout'] = arguments.timeout

result['schema'] = schema.value()


pscheduler.succeed_json(result)
21 changes: 21 additions & 0 deletions pscheduler-test-dns64/dns64/enumerate
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sed -e 1d;/^#/d

#
# Development Order #2:
#
# This JSON data describes the test, and will be shown when 'pscheduler
# plugins tests' is run. This is the first file which should be edited.
#

{
"schema": 1,
"name": "dns64",
"description": "Test that checks for the correct functioning of a DNS64 server",
"version": "1.0",
"maintainer": {
"name": "perfSONAR Development Team",
"email": "[email protected]",
"href": "http://www.perfsonar.net"
},
"scheduling-class": "background"
}
13 changes: 13 additions & 0 deletions pscheduler-test-dns64/dns64/inputs/result-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"succeeded": true,
"result": {
"schema": 1,
"time": "PT0.071234S",
"succeeded": true,
"translated": true,
"ipv4": ["27.173.202.254", "190.173.250.206", "222.173.190.239"],
"ipv6": ["64:ff9b::1bad:cafe", "64:ff9b::bead:face", "64:ff9b::dead:beef"]
},
"error": "",
"diags": ""
}
7 changes: 7 additions & 0 deletions pscheduler-test-dns64/dns64/inputs/spec-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"query": "ipv4.me",
"nameserver": "2001:4860:4860::64",
"host": "foo.example.com",
"translation-prefix": "64:ff9b::/96",
"timeout": "PT15S"
}
53 changes: 53 additions & 0 deletions pscheduler-test-dns64/dns64/participants
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

#
# Development Order #7:
#
# Participant list generator for 'dns64' task spec
#
# Input is an unvalidated dns64 test specification.
#

# Output is a JSON object:
#
# {
# "participants": [ "host-1", ..., "host-n" ]
# "null-reason": "Optional reason why participants[0] is null"
# }
#
# The first element of "participants" array may be null to
# signify that local host is the first participant.
#

import pscheduler
import sys

from validate import spec_is_valid

# Validate the input

json = pscheduler.json_load(exit_on_error=True)

valid, message = spec_is_valid(json)
if not valid:
pscheduler.fail(message)


# Determine the list of participants

# This test only has a single participant, which can be determined by
# looking up the 'host-node' or 'host' item in the specification.
host = json.get('host-node', json.get('host', None))

participants = [ host ]

result = { "participants": participants }


# Explain why the first participant is null

if host is None:
result["null-reason"] = "No host specified"


pscheduler.succeed_json(result)
64 changes: 64 additions & 0 deletions pscheduler-test-dns64/dns64/result-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3

#
# Development Order #8:
#
# This will format a test result into something that is human readable.
#
# To test this file, a spec is needed. You can generate one by pulling
# a result out of the pScheduler API or modifying inputs/result-format
# to suit your format.
#
# Invoke this program as follows:
#
#
# ./result-format text/plain < inputs/result-format
# ./result-format text/html < inputs/result-format
#

import pscheduler

from validate import result_is_valid
from validate import MAX_SCHEMA

# This is a Jinja2 template with the contents of the test
# specification provided as variables.
#
# Input provided to the template will be the original test spec in
# spec.* and the result to bef formatted in result.*.
#
# See the documentation for spec_result_method() in
# python-pscheduler/pscheduler/pscheduler/text.py for a list of
# variables and functions provided.

TEMPLATE = '''
{% if _mime_type == 'text/plain' %}

Elapsed Time ... {{ unspec(result.time) }}
{% for record in result.ipv4 -%}
IPv4 address ... {{ record }}
{% endfor -%}

{%- for record in result.ipv6 -%}
IPv6 address ... {{ record }}
{% endfor -%}

Translated ..... {{ result.translated }}

{% elif _mime_type == 'text/html' %}

<table>
<tr><td>Elapsed Time</td><td>{{ unspec(result.time) }}</td></tr>
<tr><td>IPv4</td><td><ul><li>{{ result.ipv4 | join('</li><li>') }}</li></ul></td></tr>
<tr><td>IPv6</td><td><ul><li>{{ result.ipv6 | join('</li><li>') }}</li></ul></td></tr>
<tr><td>Translated</td><td>{{ result.translated }}</td></tr>
</table>

{% else %}

{{ error('Unsupported MIME type "' + _mime_type + '"') }}

{% endif %}
'''

pscheduler.result_format_method(TEMPLATE, max_schema=MAX_SCHEMA, validator=result_is_valid)
Loading