Commit f3f91894 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 bc854f18
......@@ -45,4 +45,4 @@ md5sum = 1c0ee16966e1fcdb3fd11c09f12ee2b2
[template_instance_replicate]
_update_hash_filename_ = instance_replicate.cfg.in
md5sum = 7ff7e11d05145115f53564ec1af205ef
md5sum = d7071867625070c27dbd6456c761f9f0
......@@ -23,7 +23,7 @@ offline = true
# Macro section sharing request parameters
[instance-request-base]
<= slap-connection
recipe = slapos.cookbook:request
recipe = slapos.cookbook:request.serialised
# It is the same software as the current one
software-url = ${slap-connection:software-release-url}
# We want the default behaviour
......@@ -51,7 +51,7 @@ sla-computer_guid = {{ parameter_dict["sla-%s-computer-guid" % i] }}
# Publish information to connect to the two instances
[publish-connection-information]
recipe = slapos.cookbook:publish
recipe = slapos.cookbook:publish.serialised
{% for i in range(1, replicate_quantity + 1) %}
instance-{{ i }}-server_url = ${instance-{{ i }}:connection-server_url}
instance-{{ i }}-server-cdn-url = ${instance-{{ i }}:connection-server-cdn-url}
......
......@@ -25,12 +25,14 @@
#
##############################################################################
import json
import os
import requests
from urlparse import urlparse
from urllib.parse import urlparse
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(
os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'software.cfg')))
......@@ -43,8 +45,8 @@ class HTML5ASTestCase(SlapOSInstanceTestCase):
* Install the software release.
* Checks it compile without issue.
* Deploy the instance
* Check deployement works and promise pass
For testing the deployement a different testing class will need to be set up
* Check deployment works and promise pass
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.
"""
......@@ -63,11 +65,12 @@ class TestEmptyDeploy(HTML5ASTestCase):
"""
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)
result = response.text
self.assertFalse("<h1>" in result)
self.assertTrue("<p>Hello World</p>" in result)
self.assertNotIn("<h1>", result)
self.assertIn("<p>Hello World</p>", result)
class TestDeployWithTitle(HTML5ASTestCase):
"""
......@@ -81,13 +84,13 @@ class TestDeployWithTitle(HTML5ASTestCase):
}
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!")
url = connection_parameter_dict['server_url']
response = self.checkUrlAndGetResponse(url)
result = response.text
self.assertTrue("<h1>Test1</h1>" in result)
self.assertTrue("<p>Hello World</p>" in result)
self.assertIn("<h1>Test1</h1>", result)
self.assertIn("<p>Hello World</p>", result)
class TestGracefulWithPortChange(HTML5ASTestCase):
"""
......@@ -107,7 +110,7 @@ class TestGracefulWithPortChange(HTML5ASTestCase):
This test test port change and its application with graceful restart
"""
# 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)
# Check port is listening even thought it is duplicated with the promise:
# "port-listening-promise"
......@@ -122,8 +125,8 @@ class TestGracefulWithPortChange(HTML5ASTestCase):
self.requestDefaultInstance()
# Reprocess the instance to apply new port and run promises
self.slap.waitForInstance(self.instance_max_retry)
# Rerequest instance to get update connection parameter
url = self.requestDefaultInstance().getConnectionParameterDict()['server_url']
# Re-request instance to get update connection parameter
url = json.loads(self.requestDefaultInstance().getConnectionParameterDict()['_'])['server_url']
# Make sure the new port is the one being used
self.assertEqual(urlparse(url).port, 8086)
......@@ -151,16 +154,16 @@ class TestReplicateHTML5AS(HTML5ASTestCase):
return cls.instance_parameter_dict
def test_replicate_instance(self):
# Check First instance is deployed with proper parameters
connection_parameter_dict = self.computer_partition.getConnectionParameterDict()
# Check First instance is deployed with proper parameters
connection_parameter_dict = json.loads(self.computer_partition.getConnectionParameterDict()['_'])
url = connection_parameter_dict['instance-1-server_url']
self.assertEqual(urlparse(url).port, 8088)
response = self.checkUrlAndGetResponse(url)
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
self.assertTrue("instance-2-server_url" not in connection_parameter_dict)
self.assertNotIn("instance-2-server_url", connection_parameter_dict)
# Update replicate quantity parameter
self.instance_parameter_dict.update({
......@@ -174,9 +177,9 @@ class TestReplicateHTML5AS(HTML5ASTestCase):
self.slap.waitForInstance(self.instance_max_retry)
# 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']
self.assertEqual(urlparse(url).port, 8089)
response = self.checkUrlAndGetResponse(url)
result = response.text
self.assertTrue("<h1>Title 314</h1>" in result)
self.assertIn("<h1>Title 314</h1>", result)
......@@ -18,6 +18,7 @@ extra =
galene ${slapos.test.galene-setup:setup}
headless-chromium ${slapos.test.headless-chromium-setup:setup}
helloworld ${slapos.test.helloworld-setup:setup}
html5as ${slapos.test.html5as-setup:setup}
hugo ${slapos.test.hugo-setup:setup}
jupyter ${slapos.test.jupyter-setup:setup}
kvm ${slapos.test.kvm-setup:setup}
......
......@@ -373,7 +373,6 @@ extra =
dream ${slapos.test.dream-setup:setup}
gitlab ${slapos.test.gitlab-setup:setup}
grafana ${slapos.test.grafana-setup:setup}
html5as ${slapos.test.html5as-setup:setup}
html5as-base ${slapos.test.html5as-base-setup:setup}
htmlvalidatorserver ${slapos.test.htmlvalidatorserver-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