summaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authortmartins <thigm85@gmail.com>2020-07-02 14:39:24 +0200
committertmartins <thigm85@gmail.com>2020-07-02 14:39:24 +0200
commitddd7cd7c804261993f04d8a4cabe5720f5cec605 (patch)
tree3796cdc4c3c9375c75bdd7acd367a6bd26624861 /python
parent49edbc6ebb6baac6eb1c402b6bcbec5136d95092 (diff)
add hosts and services template
Diffstat (limited to 'python')
-rw-r--r--python/vespa/vespa/package.py30
-rw-r--r--python/vespa/vespa/test_package.py33
2 files changed, 62 insertions, 1 deletions
diff --git a/python/vespa/vespa/package.py b/python/vespa/vespa/package.py
index b234ff1c077..9c66defd4d9 100644
--- a/python/vespa/vespa/package.py
+++ b/python/vespa/vespa/package.py
@@ -330,6 +330,36 @@ class ApplicationPackage(ToJson, FromJson["ApplicationPackage"]):
rank_profiles=self.schema.rank_profiles,
)
+ @property
+ def hosts_to_text(self):
+ env = Environment(
+ loader=PackageLoader("vespa", "templates"),
+ autoescape=select_autoescape(
+ disabled_extensions=("txt",), default_for_string=True, default=True,
+ ),
+ )
+ env.trim_blocks = True
+ env.lstrip_blocks = True
+ schema_template = env.get_template("hosts.xml")
+ return schema_template.render()
+
+ @property
+ def services_to_text(self):
+ env = Environment(
+ loader=PackageLoader("vespa", "templates"),
+ autoescape=select_autoescape(
+ disabled_extensions=("txt",), default_for_string=True, default=True,
+ ),
+ )
+ env.trim_blocks = True
+ env.lstrip_blocks = True
+ schema_template = env.get_template("services.xml")
+ return schema_template.render(
+ application_name=self.name,
+ document_name=self.schema.name,
+ )
+
+
@staticmethod
def from_dict(mapping: Mapping) -> "ApplicationPackage":
schema = mapping.get("schema", None)
diff --git a/python/vespa/vespa/test_package.py b/python/vespa/vespa/test_package.py
index 917d3470324..0650bcdf400 100644
--- a/python/vespa/vespa/test_package.py
+++ b/python/vespa/vespa/test_package.py
@@ -75,7 +75,7 @@ class TestDocument(unittest.TestCase):
name="body",
type="string",
indexing=["index", "summary"],
- index=["enable-bm25"],
+ index="enable-bm25",
)
document.add_fields(field_1, field_2)
self.assertEqual(document.fields, [field_1, field_2])
@@ -188,3 +188,34 @@ class TestApplicationPackage(unittest.TestCase):
"}"
self.assertEqual(self.app_package.schema_to_text, expected_result)
+ def test_hosts_to_text(self):
+ expected_result = '<?xml version="1.0" encoding="utf-8" ?>\n' \
+ '<!-- Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->\n' \
+ '<hosts>\n' \
+ ' <host name="localhost">\n' \
+ ' <alias>node1</alias>\n' \
+ ' </host>\n' \
+ '</hosts>'
+ self.assertEqual(self.app_package.hosts_to_text, expected_result)
+
+ def test_services_to_text(self):
+ expected_result = '<?xml version="1.0" encoding="UTF-8"?>\n' \
+ '<services version="1.0">\n' \
+ ' <container id="test_app" version="1.0">\n' \
+ ' <search></search>\n' \
+ ' <document-processing></document-processing>\n' \
+ ' <document-api></document-api>\n' \
+ ' </container>\n' \
+ ' <content id="test_app" version="1.0">\n' \
+ ' <redundancy reply-after="1">1</redundancy>\n' \
+ ' <documents>\n' \
+ ' <document type="msmarco" mode="index"></document>\n' \
+ ' <document-processing cluster="test_app"></document-processing>\n' \
+ ' </documents>\n' \
+ ' <nodes>\n' \
+ ' <node distribution-key="0" hostalias="node1"></node>\n' \
+ ' </nodes>\n' \
+ ' </content>\n' \
+ '</services>'
+
+ self.assertEqual(self.app_package.services_to_text, expected_result)