Skip to content

Commit

Permalink
[PyOutline] Add spec_version (#919)
Browse files Browse the repository at this point in the history
* Add spec_version to outline.cfg

* Add spec_version unittest
  • Loading branch information
splhack committed Feb 16, 2021
1 parent 97a72a0 commit 15ff97e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyoutline/etc/outline.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ wrapper_dir = %(home)s/wrappers
user_dir =
bin_dir = %(home)s/bin
backend = cue
spec_version = 1.11
facility = local
domain = example.com
maxretries = 2
Expand Down
24 changes: 20 additions & 4 deletions pyoutline/outline/backend/cue.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from xml.dom.minidom import parseString
from xml.etree import ElementTree as Et

from packaging.version import Version
import six

import FileSequence
Expand Down Expand Up @@ -216,6 +217,10 @@ def serialize_simple(launcher):
return _serialize(launcher, use_pycuerun=False)


def _warning_spec_version(spec_version, feature):
logger.warning("spec_version=%s doesn't support %s", spec_version, feature)


def _serialize(launcher, use_pycuerun):
"""
Serialize the outline part of the given L{OutlineLauncher} into a
Expand All @@ -229,6 +234,8 @@ def _serialize(launcher, use_pycuerun):
"""
ol = launcher.get_outline()

spec_version = Version(outline.config.get("outline", "spec_version"))

root = Et.Element("spec")
depends = Et.Element("depends")

Expand All @@ -246,7 +253,10 @@ def _serialize(launcher, use_pycuerun):

j = Et.SubElement(root, "job", {"name": ol.get_name()})
sub_element(j, "paused", str(launcher.get("pause")))
sub_element(j, "priority", str(launcher.get("priority")))
if spec_version >= Version("1.11"):
sub_element(j, "priority", str(launcher.get("priority")))
elif launcher.get("priority"):
_warning_spec_version(spec_version, "priority")
sub_element(j, "maxretries", str(launcher.get("maxretries")))
sub_element(j, "autoeat", str(launcher.get("autoeat")))

Expand Down Expand Up @@ -309,10 +319,16 @@ def _serialize(launcher, use_pycuerun):
sub_element(spec_layer, "memory", "%s" % (layer.get_arg("memory")))

if layer.get_arg("timeout"):
sub_element(spec_layer, "timeout", "%s" % (layer.get_arg("timeout")))
if spec_version >= Version("1.10"):
sub_element(spec_layer, "timeout", "%s" % (layer.get_arg("timeout")))
else:
_warning_spec_version(spec_version, "timeout")

if layer.get_arg("timeout_llu"):
sub_element(spec_layer, "timeout_llu", "%s" % (layer.get_arg("timeout_llu")))
if spec_version >= Version("1.10"):
sub_element(spec_layer, "timeout_llu", "%s" % (layer.get_arg("timeout_llu")))
else:
_warning_spec_version(spec_version, "timeout_llu")

if os.environ.get("OL_TAG_OVERRIDE", False):
sub_element(spec_layer, "tags",
Expand Down Expand Up @@ -352,7 +368,7 @@ def _serialize(launcher, use_pycuerun):
xml = [
'<?xml version="1.0"?>',
'<!DOCTYPE spec PUBLIC "SPI Cue Specification Language" '
'"http://localhost:8080/spcue/dtd/cjsl-1.11.dtd">',
'"http://localhost:8080/spcue/dtd/cjsl-%s.dtd">' % spec_version,
Et.tostring(root).decode()
]

Expand Down
63 changes: 63 additions & 0 deletions pyoutline/tests/specver_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python

# Copyright Contributors to the OpenCue Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Tests for the outline.cfg spec_version
"""

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division

import unittest

from xml.etree import ElementTree as Et

import outline
import outline.modules.shell


class SpecVersiondTest(unittest.TestCase):
def _makeSpec(self):
ol = outline.Outline(name="spec_version_test")
layer = outline.modules.shell.Shell("test_layer", command=["/bin/ls"])
layer.set_arg("timeout", 420)
layer.set_arg("timeout_llu", 4200)
ol.add_layer(layer)
l = outline.cuerun.OutlineLauncher(ol)
l.set_flag("priority", 42)
return Et.fromstring(l.serialize())

def test_1_9(self):
outline.config.set("outline", "spec_version", "1.9")
root = self._makeSpec()
self.assertIsNone(root.find("job/layers/layer/timeout"))
self.assertIsNone(root.find("job/layers/layer/timeout_llu"))
self.assertIsNone(root.find("job/priority"))

def test_1_10(self):
outline.config.set("outline", "spec_version", "1.10")
root = self._makeSpec()
self.assertEqual(root.find("job/layers/layer/timeout").text, "420")
self.assertEqual(root.find("job/layers/layer/timeout_llu").text, "4200")
self.assertIsNone(root.find("job/priority"))

def test_1_11(self):
outline.config.set("outline", "spec_version", "1.11")
root = self._makeSpec()
self.assertEqual(root.find("job/layers/layer/timeout").text, "420")
self.assertEqual(root.find("job/layers/layer/timeout_llu").text, "4200")
self.assertEqual(root.find("job/priority").text, "42")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ futures==3.2.0;python_version<"3.0"
grpcio==1.16.0
grpcio-tools==1.16.0
mock==2.0.0
packaging==20.9
pathlib==1.0.1;python_version<"3.4"
psutil==5.6.6
pyfakefs==3.6
Expand Down

0 comments on commit 15ff97e

Please sign in to comment.