Commit 3a98bda4 authored by Romain Courteaud's avatar Romain Courteaud 🐸

client: revert everything!!!

parent 447d3da4
......@@ -111,11 +111,11 @@ class SlapOSHelpAction(argparse.Action):
try:
factory = ep.load()
except Exception as err:
raise
return 'Could not load %r\n' % ep
try:
cmd = factory(self, None)
except Exception as err:
raise
return 'Could not instantiate %r: %s\n' % (ep, err)
one_liner = cmd.get_description().split('\n')[0]
group = getattr(factory, 'command_group', 'other')
return group, ' %-13s %s\n' % (name, one_liner)
......
......@@ -59,8 +59,6 @@ class RegisterCommand(Command):
ap = super(RegisterCommand, self).get_parser(prog_name)
ap.add_argument('node_name',
default='',
nargs='?',
help='Chosen title for the node')
ap.add_argument('--interface-name',
......@@ -150,23 +148,10 @@ def get_certificate_key_pair(logger, master_url_web, node_name, token=None, logi
"""Download certificates from SlapOS Master"""
if token:
if token.startswith("V2/"):
_, compute_node_id, token = token.split("/")
data = {}
if node_name:
data = {'title': node_name}
req = requests.post('/'.join([
master_url_web.strip("/"),
'compute_node_module/%s/ComputeNode_approveComputer' % compute_node_id
]),
data=data,
headers={'X-Access-Token': token},
verify=False)
else:
req = requests.post('/'.join([master_url_web, 'Person_requestComputer']),
data={'title': node_name},
headers={'X-Access-Token': token},
verify=False)
req = requests.post('/'.join([master_url_web, 'Person_requestComputer']),
data={'title': node_name},
headers={'X-Access-Token': token},
verify=False)
else:
register_server_url = '/'.join([master_url_web, ("Person_requestComputer?title={}".format(node_name))])
req = requests.get(register_server_url, auth=(login, password), verify=False)
......@@ -349,7 +334,7 @@ def gen_auth(conf):
def do_register(conf):
"""Register new computer on SlapOS Master and generate slapos.cfg"""
if conf.login or conf.login_auth and conf.node_name:
if conf.login or conf.login_auth:
for login, password in gen_auth(conf):
if check_credentials(conf.master_url_web, login, password):
break
......@@ -365,9 +350,7 @@ def do_register(conf):
else:
while not conf.token:
conf.token = input('Computer security token: ').strip()
if not conf.token.startswith("V2/") and not conf.node_name:
while not conf.node_name:
conf.node_name = input('Computer Name: ').strip()
certificate, key = get_certificate_key_pair(conf.logger,
conf.master_url_web,
conf.node_name,
......
......@@ -161,44 +161,16 @@ def do_request(logger, conf, local):
else:
parameters = conf.parameters
try:
if local['slap'].jio_api_connector:
request_dict = {
"title": conf.reference,
"portal_type": "Software Instance",
"software_release_uri": conf.software_url,
}
if conf.state:
request_dict['state'] = conf.state
if conf.slave:
request_dict["shared"] = True
if conf.node:
request_dict["sla_parameters"] = conf.node
if conf.parameters:
request_dict["parameters"] = json.dumps(conf.parameters)
if conf.type:
request_dict["software_type"] = conf.type
partition_dict = local['slap'].jio_api_connector.post(request_dict)
if "$schema" in partition_dict and "error-response-schema.json" in partition_dict["$schema"]:
logger.warning('Server Response: %s' % json.dumps(partition_dict, indent=2))
logger.warning('Instance requested. Master is provisioning it. Please rerun in a '
'couple of minutes to get connection information.')
exit(2)
instance_state = partition_dict["state"]
connection_parameter_dict = partition_dict["connection_parameters"]
else:
partition = local['slap'].registerOpenOrder().request(
software_release=conf.software_url,
partition_reference=conf.reference,
partition_parameter_kw=parameters,
software_type=conf.type,
filter_kw=conf.node,
state=conf.state,
shared=conf.slave
)
instance_state = partition.getState()
connection_parameter_dict = partition.getConnectionParameterDict()
logger.info('Instance requested.\nState is : %s.', instance_state)
partition = local['slap'].registerOpenOrder().request(
software_release=conf.software_url,
partition_reference=conf.reference,
partition_parameter_kw=parameters,
software_type=conf.type,
filter_kw=conf.node,
state=conf.state,
shared=conf.slave
)
logger.info('Instance requested.\nState is : %s.', partition.getState())
logger.info('Connection parameters of instance are:')
connection_parameter_dict = partition.getConnectionParameterDict()
if software_schema.getSerialisation() == SoftwareReleaseSerialisation.JsonInXml:
......
......@@ -27,8 +27,6 @@
#
##############################################################################
import json
from slapos.cli.config import ClientConfigCommand
from slapos.client import init, ClientConfig, _getSoftwareReleaseFromSoftwareString
......@@ -65,21 +63,10 @@ def do_supply(logger, software_release, computer_id, local):
software_release = _getSoftwareReleaseFromSoftwareString(
logger, software_release, local['product'])
if local['slap'].jio_api_connector:
software_installation = local['slap'].jio_api_connector.post({
"portal_type": "Software Installation",
"software_release_uri": software_release,
"compute_node_id": computer_id,
"state": 'available'
})
if "$schema" in software_installation and "error-response-schema.json" in software_installation["$schema"]:
logger.warning('Issue during the request. Server Response: %s' % json.dumps(software_installation, indent=2))
logger.warning('Message: %s' % software_installation.get("message", ""))
exit(2)
else:
local['supply'](
software_release=software_release,
computer_guid=computer_id,
state='available'
)
local['supply'](
software_release=software_release,
computer_guid=computer_id,
state='available'
)
logger.info('Done.')
......@@ -366,48 +366,17 @@ class Computer(object):
connection_dict['cert_file'] = conf.cert_file
slap_instance.initializeConnection(conf.master_url,
**connection_dict)
if slap_instance.jio_api_connector:
partition_list = []
for partition in self.partition_list:
ip_list = []
network_interface = partition.tap.name if partition.tap else partition.reference
for address in partition.address_list:
ip_list.append({
"ip-address": address["addr"],
"network-interface": network_interface,
})
if partition.tap and partition.tap.ipv4_addr:
ip_list.append({
"ip-address": partition.tap.ipv4_addr,
"network-interface": partition.tap.name,
"gateway-ip-address": partition.tap.ipv4_gateway,
"netmask": partition.tap.netmask,
"network-address": partition.tap.ipv4_network
})
partition_list.append({
"partition_id": partition.reference,
"ip_list": ip_list
})
if conf.dry_run:
return
slap_instance.jio_api_connector.put({
"compute_node_id": self.reference,
"compute_partition_list": partition_list,
"portal_type": "Compute Node",
})
else:
slap_computer = slap_instance.registerComputer(self.reference)
slap_computer = slap_instance.registerComputer(self.reference)
if conf.dry_run:
return
try:
slap_computer.updateConfiguration(dumps(_getDict(self)))
except slap.NotFoundError as error:
raise slap.NotFoundError("%s\nERROR: This SlapOS node is not recognised by "
"SlapOS Master and/or computer_id and certificates don't match. "
"Please make sure computer_id of slapos.cfg looks "
"like 'COMP-123' and is correct.\nError is : 404 Not Found." % error)
if conf.dry_run:
return
try:
slap_computer.updateConfiguration(dumps(_getDict(self)))
except slap.NotFoundError as error:
raise slap.NotFoundError("%s\nERROR: This SlapOS node is not recognised by "
"SlapOS Master and/or computer_id and certificates don't match. "
"Please make sure computer_id of slapos.cfg looks "
"like 'COMP-123' and is correct.\nError is : 404 Not Found." % error)
def dump(self, path_to_xml, path_to_json, logger):
"""
......@@ -1697,15 +1666,7 @@ def do_format(conf):
conf.logger.exception('slapos failed to prepare the computer.')
return FormatReturn.FAILURE
computer.update()
# Dumping and sending to the erp5 the current configuration
if not conf.dry_run:
computer.dump(path_to_xml=conf.computer_xml,
path_to_json=conf.computer_json,
logger=conf.logger)
conf.logger.info('Posting information to %r' % conf.master_url)
computer.send(conf)
conf.logger.info('slapos successfully prepared the computer.')
class FormatConfig(object):
"""This class represents the options for slapos node format
......
......@@ -30,7 +30,6 @@
import datetime
import errno
import json
import os
import pkg_resources
import pwd
......@@ -57,7 +56,6 @@ from slapos.grid.svcbackend import getSupervisorRPC
from slapos.grid.exception import (BuildoutFailedError, WrongPermissionError,
PathDoesNotExistError, DiskSpaceError)
from slapos.grid.networkcache import download_network_cached, upload_network_cached
from slapos.grid.utils import md5digest
from slapos.human import bytes2human
from slapos.util import bytes2str, rmtree
......@@ -77,8 +75,6 @@ GROUP_PARTITION_TEMPLATE = bytes2str(
pkg_resources.resource_string(
__name__, 'templates/group_partition_supervisord.conf.in'))
SOFTWARE_INSTANCE_JSON_FILENAME = '.software-instance.json'
def free_space(path, fn):
while True:
......@@ -519,15 +515,21 @@ class Partition(object):
available=bytes2human(available),
required=bytes2human(required)))
def _updateCertificate(self, partition_certificates):
def _updateCertificate(self):
if not self.key_file or not self.cert_file:
# Certificate files are unset, skip.
return
try:
partition_certificate = self.computer_partition.getCertificate()
except NotFoundError:
raise NotFoundError('Partition %s is not known by SlapOS Master.' %
self.partition_id)
uid, gid = self.getUserGroupId()
for name, path in [('certificate', self.cert_file), ('key', self.key_file)]:
new_content = partition_certificates[name]
new_content = partition_certificate[name]
old_content = None
if os.path.exists(path):
with open(path) as f:
......@@ -583,7 +585,7 @@ class Partition(object):
installs the software partition with the help of buildout
"""
self.logger.info("Installing Computer Partition %s..."
% self.computer_partition.get("compute_partition_id"))
% self.partition_id)
self.check_free_space()
......@@ -604,20 +606,6 @@ class Partition(object):
(self.instance_path, permission,
REQUIRED_COMPUTER_PARTITION_PERMISSION))
uid, gid = self.getUserGroupId()
# Store software instance json
instance_json_location = os.path.join(
self.instance_path,
SOFTWARE_INSTANCE_JSON_FILENAME
)
partiton_dict = self.computer_partition.copy()
partiton_dict.pop("slap_partition", None)
# XXX Check if we want them or not
partiton_dict.pop("access_status_message", None)
with open(instance_json_location, 'w') as f:
json.dump(partiton_dict, f, indent=2)
os.chown(instance_json_location, uid, gid)
# Check that Software Release directory is present
if not os.path.exists(self.software_path):
# XXX What should it raise?
......@@ -635,7 +623,6 @@ class Partition(object):
# XXX What should it raise?
raise IOError('Software Release %s is not correctly installed.\nMissing file: %s' % (
self.software_release_url, template_location))
config_location = os.path.join(self.instance_path, 'buildout.cfg')
self.logger.debug("Copying %r to %r" % (template_location, config_location))
shutil.copy(template_location, config_location)
......@@ -647,27 +634,13 @@ class Partition(object):
'templates/buildout-tail.cfg.in')) % {
'computer_id': self.computer_id,
'partition_id': self.partition_id,
'software_instance_reference': self.computer_partition.get("reference"),
'server_url': self.server_url,
'software_release_url': self.software_release_url,
'key_file': self.key_file,
'cert_file': self.cert_file,
'storage_home': self.instance_storage_home,
'global_ipv4_network_prefix': self.ipv4_global_network,
'shared_part_list': ' '.join(self.shared_part_list.strip().splitlines(True)),
'parameters_md5sum': md5digest(
json.dumps(
self.computer_partition.get("parameters", {}), sort_keys=True
)
),
'connection_parameters_md5sum': md5digest(
json.dumps(
self.computer_partition.get("connection_parameters", {}), sort_keys=True
)
),
'instance_state': self.computer_partition.get("state"),
'instance_software_type': self.computer_partition.get("software_type"),
'instance_processing_timestamp': self.computer_partition.get("processing_timestamp")
'shared_part_list': ' '.join(self.shared_part_list.strip().splitlines(True))
}
with open(config_location, 'w') as f:
f.write(buildout_text)
......@@ -683,6 +656,7 @@ class Partition(object):
if q.startswith('bootstrap')]
else:
bootstrap_candidate_list = []
uid, gid = self.getUserGroupId()
os.chown(config_location, -1, int(gid))
if len(bootstrap_candidate_list) == 0:
buildout_binary = os.path.join(self.software_path, 'bin', 'buildout')
......@@ -758,14 +732,6 @@ class Partition(object):
self.logger.warning('No runners nor services found for partition %r' %
self.partition_id)
else:
partition_id = self.computer_partition.get("compute_partition_id")
group_partition_template = bytes2str(pkg_resources.resource_string(__name__,
'templates/group_partition_supervisord.conf.in'))
self.supervisor_configuration_group = group_partition_template % {
'instance_id': partition_id,
'program_list': ','.join(['_'.join([partition_id, runner])
for runner in runner_list + service_list])
}
# Same method to add to service and run
self.addServicesToGroup(runner_list, self.run_path)
self.addServicesToGroup(
......@@ -838,22 +804,22 @@ class Partition(object):
"""Asks supervisord to start the instance. If this instance is not
installed, we install it.
"""
partition_id = self.computer_partition.get("compute_partition_id")
self.updateSupervisorConfiguration()
partition_id = self.partition_id
try:
with self.getSupervisorRPC() as supervisor:
supervisor.startProcessGroup(partition_id, False)
except xmlrpclib.Fault as exc:
if exc.faultString.startswith('BAD_NAME:'):
self.logger.info("Nothing to start on %s..." %
self.computer_partition.get("compute_partition_id"))
self.logger.info("Nothing to start on %s..." % partition_id)
else:
raise
else:
self.logger.info("Requested start of %s..." % self.computer_partition.get("compute_partition_id"))
self.logger.info("Requested start of %s..." % partition_id)
def stop(self):
"""Asks supervisord to stop the instance."""
partition_id = self.computer_partition.get("compute_partition_id")
partition_id = self.partition_id
filename = partition_id + '.conf'
filepath = os.path.join(
self.supervisord_partition_configuration_dir, filename)
......@@ -864,13 +830,13 @@ class Partition(object):
raise
else:
self.updateSupervisor()
self.logger.info("Requested stop of %s..." % self.computer_partition.get("compute_partition_id"))
self.logger.info("Requested stop of %s..." % partition_id)
def destroy(self):
"""Destroys the partition and makes it available for subsequent use."
"""
self.logger.info("Destroying Computer Partition %s..."
% self.computer_partition.get("compute_partition_id"))
% self.partition_id)
self.createRetentionLockDate()
if not self.checkRetentionIsAuthorized():
......
This diff is collapsed.
......@@ -15,7 +15,6 @@ key-file = %(key_file)s
cert-file = %(cert_file)s
shared-part-list =
%(shared_part_list)s
software-instance-reference = %(software_instance_reference)s
[slap_connection]
# Kept for backward compatiblity
......@@ -32,11 +31,3 @@ storage-home = %(storage_home)s
[network-information]
global-ipv4-network = %(global_ipv4_network_prefix)s
# This is end of zc.buildout profile's tail added by slapgrid
[software-instance-data]
state = %(instance_state)s
software-type = %(instance_software_type)s
reference = %(software_instance_reference)s
processing-timestamp = %(instance_processing_timestamp)s
connection-parameters-md5sum = %(connection_parameters_md5sum)s
parameters-md5sum = %(parameters_md5sum)s
......@@ -187,32 +187,12 @@ class Watchdog(object):
def handle_process_state_change_event(self, headers, payload_dict):
partition_id = payload_dict['groupname']
self.initialize_connection(partition_id)
if self.slap.jio_api_connector:
instance_list = self.slap.jio_api_connector.allDocs({
"portal_type": "Software Instance",
"compute_node_id": self.computer_id,
"compute_partition_id": partition_id,
}).get("result_list", [])
if len(instance_list) != 1:
raise ValueError("No instance found for %s %s %s" % (
self.computer_id,
partition_id,
instance_list,
))
self.slap.jio_api_connector.put({
"portal_type": "Software Instance",
"reported_state": "bang",
"status_message": "%s process in partition %s encountered a problem"
% (payload_dict['processname'], partition_id),
"reference": instance_list[0]["reference"]
})
else:
partition = slapos.slap.ComputerPartition(
computer_id=self.computer_id,
connection_helper=self.slap._connection_helper,
partition_id=partition_id)
partition.bang("%s process in partition %s encountered a problem"
% (payload_dict['processname'], partition_id))
partition = slapos.slap.ComputerPartition(
computer_id=self.computer_id,
connection_helper=self.slap._connection_helper,
partition_id=partition_id)
partition.bang("%s process in partition %s encountered a problem"
% (payload_dict['processname'], partition_id))
self.create_partition_bang_timestamp_file(payload_dict['groupname'])
......
......@@ -82,8 +82,9 @@ class Manager(object):
# Get partitions IPv6 address
computer_partition = partition.computer_partition
parameter_dict = computer_partition.getInstanceParameterDict()
partition_ip_list = computer_partition['ip_list'] + computer_partition.get(
partition_ip_list = parameter_dict['ip_list'] + parameter_dict.get(
'full_ip_list', [])
partition_ip_list = [tup[1] for tup in partition_ip_list]
......
......@@ -60,42 +60,6 @@ ALLOWED_JIO_FIELD_LIST = [
"FloatField",
"TextAreaField"]
# https://stackoverflow.com/a/33571117
def _byteify(data, ignore_dicts = False):
if isinstance(data, str):
return data
# if this is a list of values, return list of byteified values
if isinstance(data, list):
return [ _byteify(item, ignore_dicts=True) for item in data ]
# if this is a dictionary, return dictionary of byteified keys and values
# but only if we haven't already byteified it
if isinstance(data, dict) and not ignore_dicts:
return {
_byteify(key, ignore_dicts=True): _byteify(value, ignore_dicts=True)
for key, value in data.items() # changed to .items() for python 2.7/3
}
# python 3 compatible duck-typing
# if this is a unicode string, return its string representation
if str(type(data)) == "<type 'unicode'>":
return data.encode('utf-8')
# if it's anything else, return it in its original form
return data
def json_loads_byteified(json_text):
"""
Encode string when loading JSON
"""
return _byteify(
json.loads(json_text, object_hook=_byteify),
ignore_dicts=True
)
class TempDocument(object):
def __init__(self, **kw):
"""
......@@ -122,8 +86,7 @@ class ConnectionHelper:
self.session = CacheControl(self.uncached_session,
cache=FileCache(os.path.expanduser("~/.slapos_cached_get")))
def do_request(self, method, path, params=None, data=None, headers=None,
expect_json_error=False, cert_key=None):
def do_request(self, method, path, params=None, data=None, headers=None):
url = parse.urljoin(self.slapgrid_uri, path)
if headers is None:
headers = {}
......@@ -133,22 +96,24 @@ class ConnectionHelper:
# raise ValueError('method path should be relative: %s' % path)
try:
if url.startswith('https') and cert_key is None:
cert_key = (self.cert_file, self.key_file)
if url.startswith('https'):
cert = (self.cert_file, self.key_file)
else:
cert = None
# XXX TODO: handle host cert verify
# Old behavior was to pass empty parameters as "None" value.
# Behavior kept for compatibility with old slapproxies (< v1.3.3).
# Can be removed when old slapproxies are no longer in use.
if data and isinstance(data, dict):
if data:
for k, v in six.iteritems(data):
if v is None:
data[k] = 'None'
req = method(url=url,
params=params,
cert=cert_key,
cert=cert,
verify=False,
data=data,
headers=headers,
......@@ -166,8 +131,6 @@ class ConnectionHelper:
"enabled on your machine and that the server is available. The "
"original error was:\n%s" % exc)
except requests.HTTPError as exc:
if expect_json_error and not int(exc.response.status_code) >= 500:
return req
if exc.response.status_code == requests.status_codes.codes.not_found:
msg = url
if params:
......@@ -193,15 +156,21 @@ class ConnectionHelper:
return req
def callJsonRpcAPI(self, path, data, cert_key=None):
req = self.do_request(requests.post,
def GET(self, path, params=None, headers=None):
req = self.do_request(self.session.get,
path=path,
data=json.dumps(data),
headers={'Content-type': 'application/json'},
expect_json_error=True,
cert_key=cert_key)
return json_loads_byteified(req.text)
params=params,
headers=headers)
return req.text.encode('utf-8')
def POST(self, path, params=None, data=None,
content_type='application/x-www-form-urlencoded'):
req = self.do_request(requests.post,
path=path,
params=params,
data=data,
headers={'Content-type': content_type})
return req.text.encode('utf-8')
class HateoasNavigator(object):
"""
......
......@@ -52,7 +52,7 @@ except ImportError: # XXX to be removed once we depend on typing
from .exception import ResourceNotReady, ServerError, NotFoundError, \
ConnectionError
from .hateoas import SlapHateoasNavigator, ConnectionHelper, json_loads_byteified
from .hateoas import SlapHateoasNavigator, ConnectionHelper
from slapos.util import (SoftwareReleaseSchema, SoftwareReleaseSchemaValidationError,
bytes2str, calculate_dict_hash, dict2xml, dumps, loads,
unicode2str, xml2dict)
......@@ -762,9 +762,7 @@ class SlapConnectionHelper(ConnectionHelper):
return loads(xml)
getHateoasUrl_cache = {}
getjIOAPI_cache = {}
@implementer(interface.slap)
class slap:
......@@ -775,6 +773,7 @@ class slap:
slapgrid_rest_uri=None):
if master_ca_file:
raise NotImplementedError('Master certificate not verified in this version: %s' % master_ca_file)
self._connection_helper = SlapConnectionHelper(
slapgrid_uri, key_file, cert_file, master_ca_file, timeout)
......
......@@ -89,7 +89,6 @@ class CliMixin(unittest.TestCase):
def setUp(self):
slap = slapos.slap.slap()
self.logger = create_autospec(logging.Logger)
slap.initializeConnection("http://127.0.0.1:80/")
self.local = {'slap': slap, 'product': SoftwareProductCollection(self.logger, slap)}
self.conf = create_autospec(ClientConfig)
self.sign_cert_list = signature_certificate_list
......
......@@ -149,6 +149,7 @@ class MasterMixin(BasicMixin, unittest.TestCase):
self,
software_release_url,
partition_id=None,
slap_computer_partition=None,
retention_delay=None,
partition_timeout=None,
shared_part_list='',
......@@ -166,18 +167,10 @@ class MasterMixin(BasicMixin, unittest.TestCase):
if partition_id is None:
partition_id = 'mypartition'
software_instance = {
"reference": partition_id,
"compute_node_id": 'bidon',
"portal_type": "Software Instance",
"compute_partition_id": partition_id,
"state": "stopped",
"software_type": None,
"parameters": {},
"processing_timestamp": 0,
"ip_list": [],
"full_ip_list": [],
}
if slap_computer_partition is None:
slap_computer_partition = SlapComputerPartition(
computer_id='bidon',
partition_id=partition_id)
instance_path = os.path.join(self.instance_root, partition_id)
os.mkdir(instance_path)
......@@ -193,7 +186,7 @@ class MasterMixin(BasicMixin, unittest.TestCase):
supervisord_partition_configuration_dir=supervisor_configuration_path,
supervisord_socket=svcbackend._getSupervisordSocketPath(
self.instance_root, logging.getLogger(self.id())),
computer_partition=software_instance,
computer_partition=slap_computer_partition,
computer_id='bidon',
partition_id=partition_id,
server_url='bidon',
......
......@@ -29,7 +29,6 @@
from __future__ import print_function
import glob
import json
import logging
import os
import shutil
......@@ -52,8 +51,6 @@ import os
import pwd
import time
import mock
import httmock
from six.moves.urllib import parse
from .test_slapgrid import DummyManager
......@@ -687,81 +684,6 @@ class TestFormatDump(SlapformatMixin):
shutil.rmtree(self._tempdir, True)
super(TestFormatDump, self).tearDown()
class TestConfForAPI():
def __init__(self):
self.master_url = "https://127.0.0.1"
self.key_file = None
self.cert_file = None
self.dry_run = False
class TestFormatSendToMaster(SlapformatMixin):
def setUp(self):
super(TestFormatSendToMaster, self).setUp()
self.restoreOs()
self._tempdir = tempfile.mkdtemp()
self.sequence = []
self.body_sequence = []
def jio_api_request_handler(self, url, req):
self.sequence.append(url.path)
if req.method == 'GET':
qs = parse.parse_qs(url.query)
else:
qs = parse.parse_qs(req.body)
if url.path.startswith('/api/'):
content = json.loads(req.body)
self.body_sequence.append(content)
return json.dumps({})
def test(self):
computer = slapos.format.Computer('computer',
instance_root=os.path.join(self._tempdir, 'instance_root'),
software_root=os.path.join(self._tempdir, 'software_root'),
tap_ipv6=True,
interface=slapos.format.Interface(
logger=self.logger, name='myinterface', ipv4_local_network='127.0.0.1/16'),
partition_list=[
slapos.format.Partition(
'partition', 'part_path', slapos.format.User('testuser'), [], tap=slapos.format.Tap('tap')),
])
global USER_LIST
USER_LIST = ['testuser']
global INTERFACE_DICT
INTERFACE_DICT['myinterface'] = {
socket.AF_INET: [{'addr': '192.168.242.77', 'broadcast': '127.0.0.1',
'netmask': '255.255.255.0'}],
socket.AF_INET6: [{'addr': '2a01:e35:2e27::e59c', 'netmask': 'ffff:ffff:ffff:ffff::'}]
}
computer.format(alter_user=False, alter_network=False, create_tap=False)
test_configuration = TestConfForAPI()
with httmock.HTTMock(self.jio_api_request_handler):
computer.send(test_configuration)
self.assertEqual(self.sequence, ['/getHateoasUrl', '/api/put/'])
self.assertEqual(
self.body_sequence,
[
{
'portal_type': 'Compute Node',
'compute_node_id': 'computer',
'compute_partition_list': [
{
'ip_list': [
{'ip-address': computer.partition_list[0].address_list[0]["addr"], 'network-interface': 'tap'},
{'ip-address': computer.partition_list[0].address_list[1]["addr"], 'network-interface': 'tap'}
],
'partition_id': 'partition'
}
]
}
]
)
def tearDown(self):
shutil.rmtree(self._tempdir, True)
super(TestFormatSendToMaster, self).tearDown()
class SlapGridPartitionMock:
......
This diff is collapsed.
This diff is collapsed.
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