Commit fc7142e1 authored by Łukasz Nowak's avatar Łukasz Nowak

kvm: Switch default and kvm-cluster to json-in-xml

default and kvm-cluster software types are now json-in-xml, so they accept
and return json-in-xml.

Update tests to show that xml and json-in-xml serialization works.

Note: There was invective to publish with pure XML serialisation, but it is
wrong idea because:

 1) serialisation in the software.cfg.json is provided for both ways
 2) requesting instances with given serialisation by profiles expect same
    serialisation

Request resilient instances with serialised, as they reply with json-in-xml.
parent d0589a41
No related merge requests found
......@@ -19,15 +19,15 @@ md5sum = 7e90da1f6dac4233e1aa3248f48e357c
[template-kvm]
filename = instance-kvm.cfg.jinja2
md5sum = fb8f9a962cc1c0d986305c6a6ce59082
md5sum = 42fa6306968516fc9ea9b690ad3b645e
[template-kvm-cluster]
filename = instance-kvm-cluster.cfg.jinja2.in
md5sum = 8562882ac4a888d18db50e2a22e3ca86
md5sum = 406bf455afe1c71cb0e8cc04dd877f1d
[template-kvm-resilient]
filename = instance-kvm-resilient.cfg.jinja2
md5sum = a0fd4911401cbbda74323e8d1c7b18ad
md5sum = 839fc16c112d3b87e2dbd2e382e326de
[template-kvm-import]
filename = instance-kvm-import.cfg.jinja2.in
......
......@@ -32,7 +32,6 @@ global-ipv6 = {{ ipv6 }}
{% endfor -%}
[request-common]
recipe = slapos.cookbook:request
software-url = ${slap-connection:software-release-url}
server-url = ${slap-connection:server-url}
key-file = ${slap-connection:key-file}
......@@ -47,6 +46,7 @@ config-use-ipv6 = {{ dumps(slapparameter_dict.get('use-ipv6', False)) }}
{% set use_nat = kvm_parameter_dict.get('use-nat', True) -%}
[{{ section }}]
<= request-common
recipe = slapos.cookbook:request.serialised
software-type = kvm
name = {{ instance_name }}
{% if kvm_parameter_dict.get('sticky-computer', '') -%}
......@@ -319,7 +319,7 @@ private-path-list +=
[publish-connection-information]
<= monitor-publish
-extends = publish-early
recipe = slapos.cookbook:publish
recipe = slapos.cookbook:publish.serialised
{% for name, value in publish_dict.items() -%}
{{ name }} = {{ value }}
{% endfor %}
......
......@@ -61,6 +61,7 @@ etc = ${buildout:directory}/etc
# Bubble down the parameters of the requested instance to the user
[request-kvm]
recipe = slapos.cookbook:request.serialised
# Note: += doesn't work.
return =
# Resilient related parameters
......
......@@ -819,7 +819,7 @@ blank-line =
[publish-connection-information]
<= monitor-publish
recipe = slapos.cookbook:publish
recipe = slapos.cookbook:publish.serialised
ipv6 = ${slap-network-information:global-ipv6}
backend-url = https://[${novnc-instance:ip}]:${novnc-instance:port}/vnc.html?auto=1&encrypt=1&password=${kvm-controller-parameter-dict:vnc-passwd}
url = ${request-slave-frontend:connection-secure_access}/vnc.html?auto=1&encrypt=1&password=${kvm-controller-parameter-dict:vnc-passwd}
......
......@@ -5,6 +5,7 @@
"software-type": {
"default": {
"title": "Default",
"serialisation": "json-in-xml",
"description": "Standalone KVM",
"request": "instance-kvm-input-schema.json",
"response": "instance-kvm-output-schema.json",
......
......@@ -118,6 +118,10 @@ bootstrap_machine_param_dict = {
class KvmMixin(object):
def getConnectionParameterDictJson(self):
return json.loads(
self.computer_partition.getConnectionParameterDict()['_'])
def getProcessInfo(self):
hash_value = generateHashFromFiles([
os.path.join(self.computer_partition_root_path, hash_file)
......@@ -160,13 +164,25 @@ class KvmMixin(object):
state=state)
class KvmMixinJson(object):
@classmethod
def getInstanceParameterDict(cls):
return {
'_': json.dumps(super(KvmMixinJson, cls).getInstanceParameterDict())}
def rerequestInstance(self, parameter_dict, *args, **kwargs):
return super(KvmMixinJson, self).rerequestInstance(
parameter_dict={'_': json.dumps(parameter_dict)},
*args, **kwargs
)
@skipUnlessKvm
class TestInstance(InstanceTestCase, KvmMixin):
__partition_reference__ = 'i'
def test(self):
connection_parameter_dict = self\
.computer_partition.getConnectionParameterDict()
connection_parameter_dict = self.getConnectionParameterDictJson()
present_key_list = []
assert_key_list = [
'backend-url', 'url', 'monitor-setup-url', 'ipv6-network-info',
......@@ -307,7 +323,12 @@ class TestMemoryManagement(InstanceTestCase, KvmMixin):
)
class MonitorAccessMixin(object):
@skipUnlessKvm
class TestMemoryManagementJson(KvmMixinJson, TestMemoryManagement):
pass
class MonitorAccessMixin(KvmMixin):
def sqlite3_connect(self):
sqlitedb_file = os.path.join(
os.path.abspath(
......@@ -334,8 +355,7 @@ class MonitorAccessMixin(object):
db.close()
def test_access_monitor(self):
connection_parameter_dict = self.computer_partition\
.getConnectionParameterDict()
connection_parameter_dict = self.getConnectionParameterDictJson()
monitor_setup_url = connection_parameter_dict['monitor-setup-url']
monitor_url_with_auth = 'https' + monitor_setup_url.split('https')[2]
......@@ -348,8 +368,8 @@ class MonitorAccessMixin(object):
connection_xml = partition_information.get('connection_xml')
if not connection_xml:
continue
connection_dict = slapos.util.xml2dict(
connection_xml if six.PY3 else connection_xml.encode('utf-8'))
connection_dict = json.loads(slapos.util.xml2dict(
connection_xml if six.PY3 else connection_xml.encode('utf-8'))['_'])
monitor_base_url = connection_dict.get('monitor-base-url')
if not monitor_base_url:
continue
......@@ -376,8 +396,7 @@ class TestAccessDefault(MonitorAccessMixin, InstanceTestCase):
expected_partition_with_monitor_base_url_count = 1
def test(self):
connection_parameter_dict = self.computer_partition\
.getConnectionParameterDict()
connection_parameter_dict = self.getConnectionParameterDictJson()
result = requests.get(connection_parameter_dict['url'], verify=False)
self.assertEqual(
httplib.OK,
......@@ -387,6 +406,11 @@ class TestAccessDefault(MonitorAccessMixin, InstanceTestCase):
self.assertNotIn('url-additional', connection_parameter_dict)
@skipUnlessKvm
class TestAccessDefaultJson(KvmMixinJson, TestAccessDefault):
pass
@skipUnlessKvm
class TestAccessDefaultAdditional(MonitorAccessMixin, InstanceTestCase):
__partition_reference__ = 'ada'
......@@ -399,8 +423,7 @@ class TestAccessDefaultAdditional(MonitorAccessMixin, InstanceTestCase):
}
def test(self):
connection_parameter_dict = self.computer_partition\
.getConnectionParameterDict()
connection_parameter_dict = self.getConnectionParameterDictJson()
result = requests.get(connection_parameter_dict['url'], verify=False)
self.assertEqual(
......@@ -418,6 +441,12 @@ class TestAccessDefaultAdditional(MonitorAccessMixin, InstanceTestCase):
self.assertIn('<title>noVNC</title>', result.text)
@skipUnlessKvm
class TestAccessDefaultAdditionalJson(
KvmMixinJson, TestAccessDefaultAdditional):
pass
@skipUnlessKvm
class TestAccessDefaultBootstrap(MonitorAccessMixin, InstanceTestCase):
__partition_reference__ = 'adb'
......@@ -455,8 +484,7 @@ class TestAccessDefaultBootstrap(MonitorAccessMixin, InstanceTestCase):
self.slap.waitForInstance(max_retry=10)
# END: mock .slapos-resource with tap.ipv4_addr
cp = self.computer_partition
connection_parameter_dict = cp.getConnectionParameterDict()
connection_parameter_dict = self.getConnectionParameterDictJson()
result = requests.get(connection_parameter_dict['url'], verify=False)
self.assertEqual(
......@@ -492,8 +520,7 @@ class TestAccessKvmCluster(MonitorAccessMixin, InstanceTestCase):
})}
def test(self):
connection_parameter_dict = self.computer_partition\
.getConnectionParameterDict()
connection_parameter_dict = self.getConnectionParameterDictJson()
result = requests.get(connection_parameter_dict['KVM0-url'], verify=False)
self.assertEqual(
httplib.OK,
......@@ -526,8 +553,7 @@ class TestAccessKvmClusterAdditional(MonitorAccessMixin, InstanceTestCase):
})}
def test(self):
connection_parameter_dict = self.computer_partition\
.getConnectionParameterDict()
connection_parameter_dict = self.getConnectionParameterDictJson()
result = requests.get(connection_parameter_dict['KVM0-url'], verify=False)
self.assertEqual(
httplib.OK,
......@@ -570,8 +596,7 @@ class TestAccessKvmClusterBootstrap(MonitorAccessMixin, InstanceTestCase):
}))}
def test(self):
connection_parameter_dict = self.computer_partition\
.getConnectionParameterDict()
connection_parameter_dict = self.getConnectionParameterDictJson()
result = requests.get(
connection_parameter_dict['test-machine1-url'], verify=False)
self.assertEqual(
......@@ -696,6 +721,12 @@ ir3:sshd-on-watch RUNNING""",
)
@skipUnlessKvm
class TestInstanceResilientJson(
KvmMixinJson, TestInstanceResilient):
pass
@skipUnlessKvm
class TestInstanceResilientDiskTypeIde(InstanceTestCase, KvmMixin):
@classmethod
......@@ -705,6 +736,12 @@ class TestInstanceResilientDiskTypeIde(InstanceTestCase, KvmMixin):
}
@skipUnlessKvm
class TestInstanceResilientDiskTypeIdeJson(
KvmMixinJson, TestInstanceResilientDiskTypeIde):
pass
@skipUnlessKvm
class TestAccessResilientAdditional(InstanceTestCase):
__partition_reference__ = 'ara'
......@@ -740,6 +777,12 @@ class TestAccessResilientAdditional(InstanceTestCase):
self.assertIn('<title>noVNC</title>', result.text)
@skipUnlessKvm
class TestAccessResilientAdditionalJson(
KvmMixinJson, TestAccessResilientAdditional):
pass
class TestInstanceNbdServer(InstanceTestCase):
__partition_reference__ = 'ins'
instance_max_retry = 5
......@@ -768,6 +811,12 @@ class TestInstanceNbdServer(InstanceTestCase):
self.assertIn("WARNING", connection_parameter_dict['status_message'])
@skipUnlessKvm
class TestInstanceNbdServerJson(
KvmMixinJson, TestInstanceNbdServer):
pass
class FakeImageHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def log_message(self, *args):
if os.environ.get('SLAPOS_TEST_DEBUG'):
......@@ -1046,6 +1095,12 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin):
self.assertPromiseFails(self.config_state_promise)
@skipUnlessKvm
class TestBootImageUrlListJson(
KvmMixinJson, TestBootImageUrlList):
pass
@skipUnlessKvm
class TestBootImageUrlListResilient(TestBootImageUrlList):
kvm_instance_partition_reference = 'biul2'
......@@ -1055,6 +1110,12 @@ class TestBootImageUrlListResilient(TestBootImageUrlList):
return 'kvm-resilient'
@skipUnlessKvm
class TestBootImageUrlListResilientJson(
KvmMixinJson, TestBootImageUrlListResilient):
pass
@skipUnlessKvm
class TestBootImageUrlSelect(TestBootImageUrlList):
__partition_reference__ = 'bius'
......@@ -1157,6 +1218,12 @@ class TestBootImageUrlSelect(TestBootImageUrlList):
)
@skipUnlessKvm
class TestBootImageUrlSelectJson(
KvmMixinJson, TestBootImageUrlSelect):
pass
@skipUnlessKvm
class TestBootImageUrlSelectResilient(TestBootImageUrlSelect):
kvm_instance_partition_reference = 'bius2'
......@@ -1166,6 +1233,12 @@ class TestBootImageUrlSelectResilient(TestBootImageUrlSelect):
return 'kvm-resilient'
@skipUnlessKvm
class TestBootImageUrlSelectResilientJson(
KvmMixinJson, TestBootImageUrlSelectResilient):
pass
@skipUnlessKvm
class TestBootImageUrlListKvmCluster(InstanceTestCase, FakeImageServerMixin):
__partition_reference__ = 'biulkc'
......@@ -1245,7 +1318,7 @@ class TestBootImageUrlSelectKvmCluster(TestBootImageUrlListKvmCluster):
@skipUnlessKvm
class TestNatRules(InstanceTestCase):
class TestNatRules(KvmMixin, InstanceTestCase):
__partition_reference__ = 'nr'
@classmethod
......@@ -1255,8 +1328,7 @@ class TestNatRules(InstanceTestCase):
}
def test(self):
connection_parameter_dict = self.computer_partition\
.getConnectionParameterDict()
connection_parameter_dict = self.getConnectionParameterDictJson()
self.assertIn('nat-rule-port-tcp-100', connection_parameter_dict)
self.assertIn('nat-rule-port-tcp-200', connection_parameter_dict)
......@@ -1271,6 +1343,12 @@ class TestNatRules(InstanceTestCase):
)
@skipUnlessKvm
class TestNatRulesJson(
KvmMixinJson, TestNatRules):
pass
@skipUnlessKvm
class TestNatRulesKvmCluster(InstanceTestCase):
__partition_reference__ = 'nrkc'
......@@ -1350,6 +1428,12 @@ class TestWhitelistFirewall(InstanceTestCase):
self.assertGreater(len(self.content_json), len(resolv_conf_ip_list))
@skipUnlessKvm
class TestWhitelistFirewallJson(
KvmMixinJson, TestWhitelistFirewall):
pass
@skipUnlessKvm
class TestWhitelistFirewallRequest(TestWhitelistFirewall):
whitelist_domains = '2.2.2.2 3.3.3.3\n4.4.4.4'
......@@ -1367,6 +1451,12 @@ class TestWhitelistFirewallRequest(TestWhitelistFirewall):
self.assertIn('4.4.4.4', self.content_json)
@skipUnlessKvm
class TestWhitelistFirewallRequestJson(
KvmMixinJson, TestWhitelistFirewallRequest):
pass
@skipUnlessKvm
class TestWhitelistFirewallResilient(TestWhitelistFirewall):
kvm_instance_partition_reference = 'wf2'
......@@ -1376,6 +1466,12 @@ class TestWhitelistFirewallResilient(TestWhitelistFirewall):
return 'kvm-resilient'
@skipUnlessKvm
class TestWhitelistFirewallResilientJson(
KvmMixinJson, TestWhitelistFirewallResilient):
pass
@skipUnlessKvm
class TestWhitelistFirewallRequestResilient(TestWhitelistFirewallRequest):
kvm_instance_partition_reference = 'wf2'
......@@ -1385,6 +1481,12 @@ class TestWhitelistFirewallRequestResilient(TestWhitelistFirewallRequest):
return 'kvm-resilient'
@skipUnlessKvm
class TestWhitelistFirewallRequestResilientJson(
KvmMixinJson, TestWhitelistFirewallRequestResilient):
pass
@skipUnlessKvm
class TestWhitelistFirewallCluster(TestWhitelistFirewall):
kvm_instance_partition_reference = 'wf1'
......@@ -1453,6 +1555,12 @@ dd if=/dev/zero of=/dev/virt1 bs=4096 count=500k"""
self.assertTrue(os.access(slapos_wipe_device_disk, os.X_OK))
@skipUnlessKvm
class TestDiskDevicePathWipeDiskOndestroyJson(
KvmMixinJson, TestDiskDevicePathWipeDiskOndestroy):
pass
@skipUnlessKvm
class TestImageDownloadController(InstanceTestCase, FakeImageServerMixin):
__partition_reference__ = 'idc'
......@@ -1715,6 +1823,12 @@ class TestParameterDefault(InstanceTestCase, KvmMixin):
self._test({'ram-size': 2048}, "ram_max_size = '2560'")
@skipUnlessKvm
class TestParameterDefaultJson(
KvmMixinJson, TestParameterDefault):
pass
@skipUnlessKvm
class TestParameterResilient(TestParameterDefault):
__partition_reference__ = 'pr'
......@@ -1885,3 +1999,9 @@ class TestExternalDisk(InstanceTestCase, KvmMixin):
self.waitForInstance()
dropped_drive_list = self.getRunningDriveList(kvm_instance_partition)
self.assertEqual(drive_list, dropped_drive_list)
@skipUnlessKvm
class TestExternalDiskJson(
KvmMixinJson, TestExternalDisk):
pass
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