Commit a6cc5765 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Empty partition are now empty in getFullComputerInformation

parent 74a0cedd
...@@ -31,7 +31,7 @@ from flask import g, Flask, request, abort ...@@ -31,7 +31,7 @@ from flask import g, Flask, request, abort
import xml_marshaller import xml_marshaller
from lxml import etree from lxml import etree
from slapos.slap.slap import Computer, ComputerPartition, \ from slapos.slap.slap import Computer, ComputerPartition, \
SoftwareRelease, SoftwareInstance SoftwareRelease, SoftwareInstance, NotFoundError
import sqlite3 import sqlite3
app = Flask(__name__) app = Flask(__name__)
...@@ -72,27 +72,30 @@ def dict2xml(dictionnary): ...@@ -72,27 +72,30 @@ def dict2xml(dictionnary):
def partitiondict2partition(partition): def partitiondict2partition(partition):
slap_partition = ComputerPartition(app.config['computer_id'], slap_partition = ComputerPartition(app.config['computer_id'],
partition['reference']) partition['reference'])
slap_partition._requested_state = 'started' slap_partition._software_release_document = None
slap_partition._requested_state = 'destroyed'
slap_partition._need_modification = 0
if partition['software_release']: if partition['software_release']:
slap_partition._need_modification = 1 slap_partition._need_modification = 1
else: slap_partition._requested_state = 'started'
slap_partition._need_modification = 0
slap_partition._parameter_dict = xml2dict(partition['xml']) slap_partition._parameter_dict = xml2dict(partition['xml'])
address_list = [] address_list = []
for address in execute_db('partition_network', for address in execute_db('partition_network',
'SELECT * FROM %s WHERE partition_reference=?', 'SELECT * FROM %s WHERE partition_reference=?',
[partition['reference']]): [partition['reference']]):
address_list.append((address['reference'], address['address'])) address_list.append((address['reference'], address['address']))
if not partition['slave_instance_list'] == None:
slap_partition._parameter_dict['slave_instance_list'] = \
xml_marshaller.xml_marshaller.loads(partition['slave_instance_list'])
slap_partition._parameter_dict['ip_list'] = address_list slap_partition._parameter_dict['ip_list'] = address_list
slap_partition._parameter_dict['slap_software_type'] = \ slap_partition._parameter_dict['slap_software_type'] = \
partition['software_type'] partition['software_type']
if not partition['slave_instance_list'] == None:
slap_partition._parameter_dict['slave_instance_list'] = \
xml_marshaller.xml_marshaller.loads(partition['slave_instance_list'])
slap_partition._connection_dict = xml2dict(partition['connection_xml']) slap_partition._connection_dict = xml2dict(partition['connection_xml'])
slap_partition._software_release_document = SoftwareRelease( slap_partition._software_release_document = SoftwareRelease(
software_release=partition['software_release'], software_release=partition['software_release'],
computer_guid=app.config['computer_id']) computer_guid=app.config['computer_id'])
return slap_partition return slap_partition
......
...@@ -96,6 +96,27 @@ database_uri = %(tempdir)s/lib/proxy.db ...@@ -96,6 +96,27 @@ database_uri = %(tempdir)s/lib/proxy.db
views.app.config['port'] = config.port views.app.config['port'] = config.port
self.app = views.app.test_client() self.app = views.app.test_client()
def add_free_partition (self, partition_amount):
"""
Will simulate a slapformat first run
and create "partition_amount" partitions
"""
computer_dict = {'reference':self.computer_id,
'address':'123.456.789',
'netmask':'fffffffff',
'partition_list':[]}
for i in range(0, partition_amount):
partition_example = {'reference':'slappart%s' %i,
'address_list':[]}
computer_dict['partition_list'].append(partition_example)
request_dict = { 'computer_id': self.computer_id,
'xml': xml_marshaller.xml_marshaller.dumps(computer_dict),
}
self.app.post('/loadComputerConfigurationFromXML',
data = request_dict)
def tearDown(self): def tearDown(self):
""" """
Remove files generated for test Remove files generated for test
...@@ -137,35 +158,29 @@ class TestInformation(BasicMixin, unittest.TestCase): ...@@ -137,35 +158,29 @@ class TestInformation(BasicMixin, unittest.TestCase):
Test that computer information won't be given to a requester different Test that computer information won't be given to a requester different
from the one specified from the one specified
""" """
with self.assertRaises(views.UnauthorizedError): with self.assertRaises(slapos.slap.NotFoundError):
self.app.get('/getComputerInformation?computer_id=' self.app.get('/getComputerInformation?computer_id='
+ self.computer_id + '42') + self.computer_id + '42')
def test_partition_are_empty (self):
class MasterMixin(BasicMixin):
""" """
Define advanced tool for test proxy simulating behavior slap library tools Test that empty partition are empty :)
""" """
self.add_free_partition(10)
rv = self.app.get('/getFullComputerInformation?computer_id='
+ self.computer_id)
computer = xml_marshaller.xml_marshaller.loads(rv.data)
for slap_partition in computer._computer_partition_list:
self.assertIsNone(slap_partition._software_release_document)
self.assertEqual(slap_partition._requested_state, 'destroyed')
self.assertEqual(slap_partition._need_modification, 0)
def add_free_partition (self, partition_amount):
class MasterMixin(BasicMixin):
""" """
Will simulate a slapformat first run Define advanced tool for test proxy simulating behavior slap library tools
and create "partition_amount" partitions
""" """
computer_dict = {'reference':self.computer_id,
'address':'123.456.789',
'netmask':'fffffffff',
'partition_list':[]}
for i in range(0, partition_amount):
partition_example = {'reference':'slappart%s' %i,
'address_list':[]}
computer_dict['partition_list'].append(partition_example)
request_dict = { 'computer_id': self.computer_id,
'xml': xml_marshaller.xml_marshaller.dumps(computer_dict),
}
self.app.post('/loadComputerConfigurationFromXML',
data = request_dict)
def request(self, software_release, software_type, partition_reference, def request(self, software_release, software_type, partition_reference,
partition_id, partition_id,
...@@ -239,7 +254,6 @@ class TestRequest (MasterMixin, unittest.TestCase): ...@@ -239,7 +254,6 @@ class TestRequest (MasterMixin, unittest.TestCase):
""" """
Set of tests for requests Set of tests for requests
""" """
def test_two_request_one_partition_free (self): def test_two_request_one_partition_free (self):
""" """
If only one partition is available and two different request are made If only one partition is available and two different request are made
......
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