Commit 1aef1c93 authored by Jérome Perrin's avatar Jérome Perrin

software/htm5as: port to python3 and serialize more in json-in-xml

This continues the changes from a576000f (software/html5as: serialize
as json-in-xml, 2022-08-19) to fix a test failure and serialize also
in json-in-xml for the replicate software type.

Minor changes to tests were made, to use assertIn for better messages
in case of assertion failures
parent 73f613d7
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
[template-cfg] [template-cfg]
filename = instance.cfg.in filename = instance.cfg.in
md5sum = ef264514b64a4b2c77c9965c587c6d34 md5sum = 23c15a579b66cef866b30a2f53b1b737
[instance_html5as] [instance_html5as]
_update_hash_filename_ = instance_html5as.cfg.in _update_hash_filename_ = instance_html5as.cfg.in
...@@ -45,4 +45,4 @@ md5sum = 1c0ee16966e1fcdb3fd11c09f12ee2b2 ...@@ -45,4 +45,4 @@ md5sum = 1c0ee16966e1fcdb3fd11c09f12ee2b2
[template_instance_replicate] [template_instance_replicate]
_update_hash_filename_ = instance_replicate.cfg.in _update_hash_filename_ = instance_replicate.cfg.in
md5sum = 7ff7e11d05145115f53564ec1af205ef md5sum = d7071867625070c27dbd6456c761f9f0
...@@ -61,7 +61,7 @@ default = instance-html5as:output ...@@ -61,7 +61,7 @@ default = instance-html5as:output
replicate = instance-replicate:output replicate = instance-replicate:output
[slap-configuration] [slap-configuration]
recipe = slapos.cookbook:slapconfiguration recipe = slapos.cookbook:slapconfiguration.serialised
computer = ${slap-connection:computer-id} computer = ${slap-connection:computer-id}
partition = ${slap-connection:partition-id} partition = ${slap-connection:partition-id}
url = ${slap-connection:server-url} url = ${slap-connection:server-url}
......
...@@ -23,7 +23,7 @@ offline = true ...@@ -23,7 +23,7 @@ offline = true
# Macro section sharing request parameters # Macro section sharing request parameters
[instance-request-base] [instance-request-base]
<= slap-connection <= slap-connection
recipe = slapos.cookbook:request recipe = slapos.cookbook:request.serialised
# It is the same software as the current one # It is the same software as the current one
software-url = ${slap-connection:software-release-url} software-url = ${slap-connection:software-release-url}
# We want the default behaviour # We want the default behaviour
...@@ -51,7 +51,7 @@ sla-computer_guid = {{ parameter_dict["sla-%s-computer-guid" % i] }} ...@@ -51,7 +51,7 @@ sla-computer_guid = {{ parameter_dict["sla-%s-computer-guid" % i] }}
# Publish information to connect to the two instances # Publish information to connect to the two instances
[publish-connection-information] [publish-connection-information]
recipe = slapos.cookbook:publish recipe = slapos.cookbook:publish.serialised
{% for i in range(1, replicate_quantity + 1) %} {% for i in range(1, replicate_quantity + 1) %}
instance-{{ i }}-server_url = ${instance-{{ i }}:connection-server_url} instance-{{ i }}-server_url = ${instance-{{ i }}:connection-server_url}
instance-{{ i }}-server-cdn-url = ${instance-{{ i }}:connection-server-cdn-url} instance-{{ i }}-server-cdn-url = ${instance-{{ i }}:connection-server-cdn-url}
......
...@@ -25,12 +25,14 @@ ...@@ -25,12 +25,14 @@
# #
############################################################################## ##############################################################################
import json
import os import os
import requests import requests
from urlparse import urlparse from urllib.parse import urlparse
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass( setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(
os.path.abspath( os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'software.cfg'))) os.path.join(os.path.dirname(__file__), '..', 'software.cfg')))
...@@ -43,8 +45,8 @@ class HTML5ASTestCase(SlapOSInstanceTestCase): ...@@ -43,8 +45,8 @@ class HTML5ASTestCase(SlapOSInstanceTestCase):
* Install the software release. * Install the software release.
* Checks it compile without issue. * Checks it compile without issue.
* Deploy the instance * Deploy the instance
* Check deployement works and promise pass * Check deployment works and promise pass
For testing the deployement a different testing class will need to be set up For testing the deployment a different testing class will need to be set up
per each variation of parameters the instance needs to be given. per each variation of parameters the instance needs to be given.
""" """
...@@ -63,11 +65,12 @@ class TestEmptyDeploy(HTML5ASTestCase): ...@@ -63,11 +65,12 @@ class TestEmptyDeploy(HTML5ASTestCase):
""" """
def test_deploy_with_no_paramater(self): def test_deploy_with_no_paramater(self):
url = self.requestDefaultInstance().getConnectionParameterDict()['server_url'] url = json.loads(self.computer_partition.getConnectionParameterDict()['_'])['server_url']
response = self.checkUrlAndGetResponse(url) response = self.checkUrlAndGetResponse(url)
result = response.text result = response.text
self.assertFalse("<h1>" in result) self.assertNotIn("<h1>", result)
self.assertTrue("<p>Hello World</p>" in result) self.assertIn("<p>Hello World</p>", result)
class TestDeployWithTitle(HTML5ASTestCase): class TestDeployWithTitle(HTML5ASTestCase):
""" """
...@@ -77,17 +80,21 @@ class TestDeployWithTitle(HTML5ASTestCase): ...@@ -77,17 +80,21 @@ class TestDeployWithTitle(HTML5ASTestCase):
@classmethod @classmethod
def getInstanceParameterDict(cls): def getInstanceParameterDict(cls):
return { return {
'_': json.dumps(
{
'title': 'Test1', 'title': 'Test1',
} }
)
}
def test_deploy_with_title_parameter(self): def test_deploy_with_title_parameter(self):
connection_parameter_dict = self.computer_partition.getConnectionParameterDict() connection_parameter_dict = json.loads(self.computer_partition.getConnectionParameterDict()['_'])
self.assertEqual(connection_parameter_dict["title"], "Title Test1!") self.assertEqual(connection_parameter_dict["title"], "Title Test1!")
url = connection_parameter_dict['server_url'] url = connection_parameter_dict['server_url']
response = self.checkUrlAndGetResponse(url) response = self.checkUrlAndGetResponse(url)
result = response.text result = response.text
self.assertTrue("<h1>Test1</h1>" in result) self.assertIn("<h1>Test1</h1>", result)
self.assertTrue("<p>Hello World</p>" in result) self.assertIn("<p>Hello World</p>", result)
class TestGracefulWithPortChange(HTML5ASTestCase): class TestGracefulWithPortChange(HTML5ASTestCase):
""" """
...@@ -95,7 +102,9 @@ class TestGracefulWithPortChange(HTML5ASTestCase): ...@@ -95,7 +102,9 @@ class TestGracefulWithPortChange(HTML5ASTestCase):
""" """
instance_parameter_dict = { instance_parameter_dict = {
'_': json.dumps({
'port': 8087 'port': 8087
})
} }
@classmethod @classmethod
...@@ -107,23 +116,23 @@ class TestGracefulWithPortChange(HTML5ASTestCase): ...@@ -107,23 +116,23 @@ class TestGracefulWithPortChange(HTML5ASTestCase):
This test test port change and its application with graceful restart This test test port change and its application with graceful restart
""" """
# Check initial connection parameter match expected port # Check initial connection parameter match expected port
url = self.computer_partition.getConnectionParameterDict()['server_url'] url = json.loads(self.computer_partition.getConnectionParameterDict()['_'])['server_url']
self.assertEqual(urlparse(url).port, 8087) self.assertEqual(urlparse(url).port, 8087)
# Check port is listening even thought it is duplicated with the promise: # Check port is listening even thought it is duplicated with the promise:
# "port-listening-promise" # "port-listening-promise"
self.checkUrlAndGetResponse(url) self.checkUrlAndGetResponse(url)
# Update port parameter # Update port parameter
self.instance_parameter_dict.update({ self.instance_parameter_dict['_'] = json.dumps({
'port': 8086, 'port': 8086
}) })
# Request instance with the new port parameter # Request instance with the new port parameter
self.requestDefaultInstance() self.requestDefaultInstance()
# Reprocess the instance to apply new port and run promises # Reprocess the instance to apply new port and run promises
self.slap.waitForInstance(self.instance_max_retry) self.slap.waitForInstance(self.instance_max_retry)
# Rerequest instance to get update connection parameter # Re-request instance to get update connection parameter
url = self.requestDefaultInstance().getConnectionParameterDict()['server_url'] url = json.loads(self.requestDefaultInstance().getConnectionParameterDict()['_'])['server_url']
# Make sure the new port is the one being used # Make sure the new port is the one being used
self.assertEqual(urlparse(url).port, 8086) self.assertEqual(urlparse(url).port, 8086)
...@@ -138,8 +147,10 @@ class TestReplicateHTML5AS(HTML5ASTestCase): ...@@ -138,8 +147,10 @@ class TestReplicateHTML5AS(HTML5ASTestCase):
""" """
instance_parameter_dict = { instance_parameter_dict = {
'_': json.dumps({
"port-1": 8088, "port-1": 8088,
"title-1": "Title 1", "title-1": "Title 1",
})
} }
@classmethod @classmethod
...@@ -152,31 +163,36 @@ class TestReplicateHTML5AS(HTML5ASTestCase): ...@@ -152,31 +163,36 @@ class TestReplicateHTML5AS(HTML5ASTestCase):
def test_replicate_instance(self): def test_replicate_instance(self):
# Check First instance is deployed with proper parameters # Check First instance is deployed with proper parameters
connection_parameter_dict = self.computer_partition.getConnectionParameterDict() connection_parameter_dict = json.loads(self.computer_partition.getConnectionParameterDict()['_'])
url = connection_parameter_dict['instance-1-server_url'] url = connection_parameter_dict['instance-1-server_url']
self.assertEqual(urlparse(url).port, 8088) self.assertEqual(urlparse(url).port, 8088)
response = self.checkUrlAndGetResponse(url) response = self.checkUrlAndGetResponse(url)
result = response.text result = response.text
self.assertTrue("<h1>Title 1</h1>" in result) self.assertIn("<h1>Title 1</h1>", result)
# Check only one instance is deployed by default # Check only one instance is deployed by default
self.assertTrue("instance-2-server_url" not in connection_parameter_dict) self.assertNotIn("instance-2-server_url", connection_parameter_dict)
# Update replicate quantity parameter # Update replicate quantity parameter
self.instance_parameter_dict.update({ self.instance_parameter_dict['_'] = json.dumps(
dict(
json.loads(self.instance_parameter_dict['_']),
**{
'replicate-quantity': 2, 'replicate-quantity': 2,
'port-2': 8089, 'port-2': 8089,
'sla-2-computer_guid': self.slap._computer_id, 'sla-2-computer_guid': self.slap._computer_id,
"title-2": "Title 314", "title-2": "Title 314",
}) }
)
)
# Request instance with the one more replicate # Request instance with the one more replicate
self.requestDefaultInstance() self.requestDefaultInstance()
self.slap.waitForInstance(self.instance_max_retry) self.slap.waitForInstance(self.instance_max_retry)
# Check the second replicate # Check the second replicate
connection_parameter_dict = self.requestDefaultInstance().getConnectionParameterDict() connection_parameter_dict = json.loads(self.requestDefaultInstance().getConnectionParameterDict()['_'])
url = connection_parameter_dict['instance-2-server_url'] url = connection_parameter_dict['instance-2-server_url']
self.assertEqual(urlparse(url).port, 8089) self.assertEqual(urlparse(url).port, 8089)
response = self.checkUrlAndGetResponse(url) response = self.checkUrlAndGetResponse(url)
result = response.text result = response.text
self.assertTrue("<h1>Title 314</h1>" in result) self.assertIn("<h1>Title 314</h1>", result)
...@@ -18,6 +18,7 @@ extra = ...@@ -18,6 +18,7 @@ extra =
galene ${slapos.test.galene-setup:setup} galene ${slapos.test.galene-setup:setup}
headless-chromium ${slapos.test.headless-chromium-setup:setup} headless-chromium ${slapos.test.headless-chromium-setup:setup}
helloworld ${slapos.test.helloworld-setup:setup} helloworld ${slapos.test.helloworld-setup:setup}
html5as ${slapos.test.html5as-setup:setup}
hugo ${slapos.test.hugo-setup:setup} hugo ${slapos.test.hugo-setup:setup}
jupyter ${slapos.test.jupyter-setup:setup} jupyter ${slapos.test.jupyter-setup:setup}
kvm ${slapos.test.kvm-setup:setup} kvm ${slapos.test.kvm-setup:setup}
......
...@@ -373,7 +373,6 @@ extra = ...@@ -373,7 +373,6 @@ extra =
dream ${slapos.test.dream-setup:setup} dream ${slapos.test.dream-setup:setup}
gitlab ${slapos.test.gitlab-setup:setup} gitlab ${slapos.test.gitlab-setup:setup}
grafana ${slapos.test.grafana-setup:setup} grafana ${slapos.test.grafana-setup:setup}
html5as ${slapos.test.html5as-setup:setup}
html5as-base ${slapos.test.html5as-base-setup:setup} html5as-base ${slapos.test.html5as-base-setup:setup}
htmlvalidatorserver ${slapos.test.htmlvalidatorserver-setup:setup} htmlvalidatorserver ${slapos.test.htmlvalidatorserver-setup:setup}
jscrawler ${slapos.test.jscrawler-setup:setup} jscrawler ${slapos.test.jscrawler-setup:setup}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment