Commit b76875d6 by Jérome Perrin

testnode: fix Computer.updateConfiguration call

updateConfiguration is a method to set the list of partitions, not to
add partitions to an existing computer. The previous (slapos.core
<1.5.0) implementation of slap proxy was incorrect and was adding more
partitions each time it was called, but that was never the indented
behavior.

Prepare the list of partitions and call updateConfiguration only once to
set all partitions.

This should fix SLAPOS-SR-TEST that are still using erp5.util
parent 0e0e240f
......@@ -2,6 +2,7 @@ import unittest
from unittest import TestCase
from contextlib import contextmanager
from xml_marshaller import xml_marshaller
from erp5.util.testnode import logger
from erp5.util.testnode.testnode import TestNode, test_type_registry
from erp5.util.testnode.NodeTestSuite import SlapOSInstance, NodeTestSuite
......@@ -24,6 +25,11 @@ import tempfile
import json
import time
import re
try:
from unittest import mock
except ImportError:
# BBB python2
import mock
@contextmanager
def dummySuiteLog(_):
......@@ -69,6 +75,9 @@ class ERP5TestNode(TestCase):
# XXX how to get property the git path ?
config = {}
config["git_binary"] = "git"
config["master_url"] = 'http://example.org/'
config["proxy_host"] = ''
config["proxy_port"] = ''
config["slapos_directory"] = self.slapos_directory
config["working_directory"] = self.working_directory
config["software_directory"] = self.software_directory
......@@ -87,6 +96,9 @@ class ERP5TestNode(TestCase):
config["httpd_software_access_port"] = "9080"
config["frontend_url"] = "http://frontend/"
config["software_list"] = ["foo", "bar"]
config["partition_reference"] = "part"
config["ipv4_address"] = "1.2.3.4"
config["ipv6_address"] = "::1"
config["slapos_binary"] = "/opt/slapgrid/HASH/bin/slapos"
config["srv_directory"] = "srv_directory"
......@@ -1199,3 +1211,25 @@ shared = true
RunnerClass.updateDictionaryFile = original_updateDictionaryFile
RunnerClass._createInstance = original__createInstance
RunnerClass._waitInstanceCreation = original__waitInstanceCreation
def test_initializeSlapOSControler(self):
test_node = self.getTestNode()
test_node_slapos = SlapOSInstance(self.slapos_directory)
runner = test_type_registry['UnitTest'](test_node)
import slapos.slap
Computer = mock.create_autospec(slapos.slap.Computer)
with mock.patch(
'erp5.util.testnode.SlapOSControler.SlapOSControler.runSoftwareRelease',
return_value={"status_code": 0}
),\
mock.patch('erp5.util.testnode.SlapOSControler.slapos.slap.slap.registerComputer', return_value=Computer),\
mock.patch('erp5.util.testnode.SlapOSControler.slapos.slap.slap.initializeConnection'),\
mock.patch('erp5.util.testnode.SlapOSControler.slapos.slap.slap.registerSupply'),\
mock.patch('subprocess.Popen'):
runner.prepareSlapOSForTestNode(test_node_slapos)
# update configuration is called only once to set all partitions
self.assertEqual(1, Computer.updateConfiguration.call_count)
computer_config = xml_marshaller.loads(Computer.updateConfiguration.call_args[0][0])
self.assertEqual(10, len(computer_config['partition_list']))
......@@ -272,6 +272,7 @@ class SlapOSControler(object):
# MySQL DB content) from previous runs. To support changes of partition
# naming scheme (which already happened), do this at instance_root level.
createFolder(instance_root, True)
partition_list = []
for i in range(MAX_PARTITIONS):
# create partition and configure computer
# XXX: at the moment all partitions do share same virtual interface address
......@@ -281,18 +282,20 @@ class SlapOSControler(object):
if not(os.path.exists(partition_path)):
os.mkdir(partition_path)
os.chmod(partition_path, 0o750)
computer.updateConfiguration(xml_marshaller.xml_marshaller.dumps({
partition_list.append(
{'address_list': [{'addr': config['ipv4_address'],
'netmask': '255.255.255.255'},
{'addr': config['ipv6_address'],
'netmask': 'ffff:ffff:ffff::'},],
'path': partition_path,
'reference': partition_reference,
'tap': {'name': partition_reference},})
computer.updateConfiguration(xml_marshaller.xml_marshaller.dumps({
'address': config['ipv4_address'],
'instance_root': instance_root,
'netmask': '255.255.255.255',
'partition_list': [
{'address_list': [{'addr': config['ipv4_address'],
'netmask': '255.255.255.255'},
{'addr': config['ipv6_address'],
'netmask': 'ffff:ffff:ffff::'},],
'path': partition_path,
'reference': partition_reference,
'tap': {'name': partition_reference},}],
'partition_list': partition_list,
'reference': config['computer_id'],
'software_root': self.software_root}))
......
......@@ -83,6 +83,7 @@ setup(name=name,
'slapos.core',
'xml_marshaller',
'psutil >= 0.5.0',
'mock; python_version < "3"',
],
)
......
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 sign in to comment