Exemplo n.º 1
0
class TestModuleConfiguration(unittest.TestCase):

    def setUp(self):
        self.client = XmlRpc(port=8888)
        self.client.call('authenticate', 'root', 'mandriva')

    def test_get_config_module_unavailable(self):
        result = self.client.call('get_config', ['foo'])
        self.assertEqual(result, [])

    def test_get_valid_config(self):
        result = self.client.call('get_config', ['module1'])
        self.assertEqual(len(result[0]["config"]), 2)
        #[{'config': [{u'default': u'foo', 'slug': u'module1', u'type': u'text', u'name': u'option1', u'label': u'option one'},
        #             {'slug': u'module1', u'type': u'check', u'name': u'option2', u'label': u'option two'}],
        #  'slug': u'module1'}]
        # Fill the configuration
        config = {"module1_option1": "bar", "module1_option2": "on"}
        # Validate the configuration
        (config_err, config_result) = self.client.call('valid_config', ['module1'], config)
        self.assertFalse(config_err)
        module1_config = config_result[0]
        self.assertEqual(module1_config[0]["default"], "bar")
        self.assertEqual(module1_config[1]["default"], "on")

    def test_required_field(self):
        config = {"module2_option2": "foo"}
        # Validate the configuration
        (config_err, config_result) = self.client.call('valid_config', ['module2'], config)
        self.assertTrue(config_err)
        module2_config = config_result[0]
        self.assertIn("error", module2_config[0])
        self.assertNotIn("error", module2_config[1])
Exemplo n.º 2
0
 def __init__(self, host="127.0.0.1", port="8001"):
     self.xmlrpc = XmlRpc(host=host, port=port)
Exemplo n.º 3
0
class Client:
    """ This class manages connections to a MSS agent. """
    def __init__(self, host="127.0.0.1", port="8001"):
        self.xmlrpc = XmlRpc(host=host, port=port)

    def debug(self):
        logger.setLevel(logging.DEBUG)

    def wait_for_task(self, task_type, module="agent"):
        """ Pool every second if 'type' thread is finished.
        Task_type are 'load_module','install','config', ...?"""
        while True:
            a = self.xmlrpc.call('get_state', task_type, module)
            code, output = a
            if code == 2000:
                pass
            else:
                break
            time.sleep(1)

    def call(self, method, *args):
        return self.xmlrpc.call(method, *args)

    def authenticate(self, login, passwd):
        logger.info('[Authentication] User: %s' % login)
        return self.xmlrpc.call("authenticate", login, passwd)

    def get_available_modules():
        pass

    def load_module(self, module_name):
        logger.info('Loading module %s...' % module_name)
        self.xmlrpc.call('load_modules', module_name)

    def install_module(self, module_name, sync=False):
        """ Load and Install module"""
        # self.load_module(module_name)

        logger.info('Installing module packages...')
        self.xmlrpc.call('install_modules', [module_name])
        if sync:
            self.wait_for_task('install')
            logger.info('Installing module package... done')

    def configure_module(self, module_name, config):
        """ Install module if needed. This method is synchone."""
        self.install_module(module_name, sync=True)

        # logger.info('Get configuration...')
        # module_config = self.xmlrpc.call('get_config', [module_name])
        logger.info('Configuring module...')
        config['continue'] = ''
        cfg = self.xmlrpc.call('valid_config', [module_name], config)
        logger.debug('Configuring module (run_config)...')
        self.xmlrpc.call('run_config', module_name)
        self.wait_for_task('config', module_name)
        logger.debug('Configuring module (end_config)...')
        self.xmlrpc.call('end_config', module_name, 0, "")
        logger.info('Configuring module... done')

    def get_configuration(self, module_name):
        """ Return module configuration """
        self.load_module(module_name)
        return self.xmlrpc.call('get_config', [module_name])[0]

    def get_require_fields(self, module_name):
        acc = []
        for r in self.get_configuration(module_name):
            if 'name' in r:
                if 'require' in r and r['require'] == 'yes':
                    acc.append(r)
        return acc
Exemplo n.º 4
0
"""
A MSS XML-RPC client example
"""

import logging
from mss.lib.xmlrpc import XmlRpc
client = XmlRpc()

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()

err, result = client.call("authenticate", "root", "mandriva")
if result:
    logger.debug("Getting mds_mmc module details")
    err, result = client.call("get_module_details", "mds_mmc")
    if not err:
        logger.debug(result)
    logger.debug("Getting mds_mmc module configuration description")
    err, result = client.call("get_config", ["mds_mmc"])
    if not err:
        logger.debug(result)
else:
    logger.error("Authentication failed")
Exemplo n.º 5
0
import logging

from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _, ungettext

from mss.lib.xmlrpc import XmlRpc

xmlrpc = XmlRpc()
logger = logging.getLogger(__name__)


class Steps:
    PREINST = "preinst"
    DOWNLOAD = "download"
    MEDIAS_AUTH = "medias_auth"
    MEDIAS_ADD = "medias_add"
    INSTALL = "install"
    CONFIG = "config"
    END = "end"


class State:
    DISABLED = -1
    TODO = 0
    DONE = 1


class Transaction(object):
    def __init__(self, request, modules_list=None):
        if modules_list is not None:
            self.modules_list = modules_list
Exemplo n.º 6
0
"""
A MSS XML-RPC client example
"""

import logging
from mss.lib.xmlrpc import XmlRpc;
client = XmlRpc();

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()

err, result = client.call("authenticate", "root", "mandriva")
if result:
    logger.debug("Getting mds_mmc module details")
    err, result = client.call("get_module_details", "mds_mmc")
    if not err:
        logger.debug(result)
    logger.debug("Getting mds_mmc module configuration description")
    err, result = client.call("get_config", ["mds_mmc"])
    if not err:
        logger.debug(result)
else:
    logger.error("Authentication failed")
Exemplo n.º 7
0
class TestBasics(unittest.TestCase):
    def setUp(self):
        self.client = XmlRpc(port=8888)
        result = self.client.call('authenticate', 'root', 'mandriva')

    def test_get_modules(self):
        result = self.client.call('get_modules')
        self.assertEqual(len(result), 4)

    def test_get_module_details(self):
        result = self.client.call('get_module_details', 'module1')
        self.assertEqual(result["configured"], False)
        self.assertEqual(result["name"], "Module One")

    def test_get_module_details_notexists(self):
        result = self.client.call('get_module_details', 'foo')
        self.assertEqual(result, False)

    def test_get_modules_details(self):
        result = self.client.call('get_modules_details',
                                  ['module1', 'module2'])
        self.assertEqual(len(result), 2)

    def test_get_modules_details_notexists2(self):
        result = self.client.call('get_modules_details', ['module1', 'foo'])
        self.assertEqual(len(result), 1)

    def test_get_modules_details_notexists1(self):
        result = self.client.call('get_modules_details', ['foo'])
        self.assertEqual(len(result), 0)

    def test_get_module_packages(self):
        result = self.client.call('get_packages', 'module1')
        self.assertEqual(result,
                         ['package1', 'package2', 'package3', 'package4'])

    def test_get_module_packages_notexists(self):
        result = self.client.call('get_packages', 'foo')
        self.assertEqual(result, False)

    def test_get_module_packages_no_packages(self):
        result = self.client.call('get_packages', 'module2')
        self.assertEqual(result, [])

    def test_preinstall_modules(self):
        result = self.client.call('preinstall_modules', ['module1'])
        self.assertEqual(len(result), 2)
        self.assertEqual(result[0]["slug"], "module2")
        self.assertTrue(result[0]["dep"])
        self.assertEqual(result[1]["slug"], "module1")
        self.assertFalse(result[1]["dep"])

    def test_preinstall_modules_notexists1(self):
        result = self.client.call('preinstall_modules', ['module2', 'foo'])
        self.assertEqual(len(result), 1)

    def test_preinstall_modules_notexists2(self):
        result = self.client.call('preinstall_modules', ['foo'])
        self.assertEqual(len(result), 0)

    def test_get_repositories(self):
        result = self.client.call('get_repositories', ['module1', 'module2'])
        self.assertEqual(len(result), 2)
        self.assertEqual(result[0]["url"], "http://exemple.mandriva.com")

    def test_get_repositories_already_installed(self):
        result = self.client.call('get_repositories', ['module3'])
        self.assertEqual(len(result), 0)

    def test_get_sections(self):
        result = self.client.call('get_sections')
        self.assertEqual(result, [{'slug': 'test', 'name': 'Test'}])

    def test_get_section(self):
        result = self.client.call('get_section', 'test')
        self.assertEqual(len(result[0]["modules"]), 1)
        self.assertEqual(result[0]["modules"][0]["slug"], "module1")
        self.assertEqual(result[0]["slug"], "other")
Exemplo n.º 8
0
 def setUp(self):
     self.client = XmlRpc(port=8888)
     result = self.client.call('authenticate', 'root', 'mandriva')
Exemplo n.º 9
0
 def __init__(self, host="127.0.0.1", port="8001"):
     self.xmlrpc = XmlRpc(host=host, port=port)
Exemplo n.º 10
0
class Client:
    """ This class manages connections to a MSS agent. """
    def __init__(self, host="127.0.0.1", port="8001"):
        self.xmlrpc = XmlRpc(host=host, port=port)

    def debug(self):
        logger.setLevel(logging.DEBUG)

    def wait_for_task(self, task_type, module="agent"):
        """ Pool every second if 'type' thread is finished.
        Task_type are 'load_module','install','config', ...?"""
        while True:
            a = self.xmlrpc.call('get_state', task_type, module)
            code, output = a
            if code == 2000:
                pass
            else:
                break
            time.sleep(1)

    def call(self, method, *args):
        return self.xmlrpc.call(method, *args)

    def authenticate(self, login, passwd):
        logger.info('[Authentication] User: %s' % login)
        return self.xmlrpc.call("authenticate", login, passwd)

    def get_available_modules():
        pass

    def load_module(self, module_name):
        logger.info('Loading module %s...' % module_name)
        self.xmlrpc.call('load_modules', module_name)

    def install_module(self, module_name, sync=False):
        """ Load and Install module"""
        # self.load_module(module_name)

        logger.info('Installing module packages...')
        self.xmlrpc.call('install_modules', [module_name])
        if sync:
            self.wait_for_task('install')
            logger.info('Installing module package... done')

    def configure_module(self, module_name, config):
        """ Install module if needed. This method is synchone."""
        self.install_module(module_name, sync=True)

        # logger.info('Get configuration...')
        # module_config = self.xmlrpc.call('get_config', [module_name])
        logger.info('Configuring module...')
        config['continue'] = ''
        cfg = self.xmlrpc.call('valid_config', [module_name], config)
        logger.debug('Configuring module (run_config)...')
        self.xmlrpc.call('run_config', module_name)
        self.wait_for_task('config', module_name)
        logger.debug('Configuring module (end_config)...')
        self.xmlrpc.call('end_config', module_name, 0, "")
        logger.info('Configuring module... done')

    def get_configuration(self, module_name):
        """ Return module configuration """
        self.load_module(module_name)
        return self.xmlrpc.call('get_config', [module_name])[0]

    def get_require_fields(self, module_name):
        acc = []
        for r in self.get_configuration(module_name):
            if 'name' in r:
                if 'require' in r and r['require'] == 'yes':
                    acc.append(r)
        return acc
Exemplo n.º 11
0
class TestBasics(unittest.TestCase):

    def setUp(self):
        self.client = XmlRpc(port=8888)
        result = self.client.call('authenticate', 'root', 'mandriva')

    def test_get_modules(self):
        result = self.client.call('get_modules')
        self.assertEqual(len(result), 4)

    def test_get_module_details(self):
        result = self.client.call('get_module_details', 'module1')
        self.assertEqual(result["configured"], False)
        self.assertEqual(result["name"], "Module One")

    def test_get_module_details_notexists(self):
        result = self.client.call('get_module_details', 'foo')
        self.assertEqual(result, False)

    def test_get_modules_details(self):
        result = self.client.call('get_modules_details', ['module1', 'module2'])
        self.assertEqual(len(result), 2)

    def test_get_modules_details_notexists2(self):
        result = self.client.call('get_modules_details', ['module1', 'foo'])
        self.assertEqual(len(result), 1)

    def test_get_modules_details_notexists1(self):
        result = self.client.call('get_modules_details', ['foo'])
        self.assertEqual(len(result), 0)

    def test_get_module_packages(self):
        result = self.client.call('get_packages', 'module1')
        self.assertEqual(result, ['package1', 'package2', 'package3', 'package4'])

    def test_get_module_packages_notexists(self):
        result = self.client.call('get_packages', 'foo')
        self.assertEqual(result, False)

    def test_get_module_packages_no_packages(self):
        result = self.client.call('get_packages', 'module2')
        self.assertEqual(result, [])

    def test_preinstall_modules(self):
        result = self.client.call('preinstall_modules', ['module1'])
        self.assertEqual(len(result), 2)
        self.assertEqual(result[0]["slug"], "module2")
        self.assertTrue(result[0]["dep"])
        self.assertEqual(result[1]["slug"], "module1")
        self.assertFalse(result[1]["dep"])

    def test_preinstall_modules_notexists1(self):
        result = self.client.call('preinstall_modules', ['module2', 'foo'])
        self.assertEqual(len(result), 1)

    def test_preinstall_modules_notexists2(self):
        result = self.client.call('preinstall_modules', ['foo'])
        self.assertEqual(len(result), 0)

    def test_get_repositories(self):
        result = self.client.call('get_repositories', ['module1', 'module2'])
        self.assertEqual(len(result), 2)
        self.assertEqual(result[0]["url"], "http://exemple.mandriva.com")

    def test_get_repositories_already_installed(self):
        result = self.client.call('get_repositories', ['module3'])
        self.assertEqual(len(result), 0)

    def test_get_sections(self):
        result = self.client.call('get_sections')
        self.assertEqual(result, [{'slug': 'test', 'name': 'Test'}])

    def test_get_section(self):
        result = self.client.call('get_section', 'test')
        self.assertEqual(len(result[0]["modules"]), 1)
        self.assertEqual(result[0]["modules"][0]["slug"], "module1")
        self.assertEqual(result[0]["slug"], "other")
Exemplo n.º 12
0
 def setUp(self):
     self.client = XmlRpc(port=8888)
     result = self.client.call('authenticate', 'root', 'mandriva')
Exemplo n.º 13
0
def is_first_time():
    xmlrpc = XmlRpc()
    return not xmlrpc.call('get_option', 'first-time')
Exemplo n.º 14
0
class TestConfigValidation(unittest.TestCase):

    def setUp(self):
        self.client = XmlRpc(port=8888)
        self.client.call('authenticate', 'root', 'mandriva')

    def test_fqdn_validation(self):
        config_result = self.client.call('valid_config', ['module1'], {"module1_fqdn": "foo"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertIn("error", module1_config[0])
        config_result = self.client.call('valid_config', ['module1'], {"module1_fqdn": "foo.a"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertIn("error", module1_config[0])
        config_result = self.client.call('valid_config', ['module1'], {"module1_fqdn": "foo.local"})
        self.assertFalse(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertNotIn("error", module1_config[0])

    def test_network_validation(self):
        config_result = self.client.call('valid_config', ['module1'], {"module1_network_text": "foo"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertIn("error", module1_config[1])
        config_result = self.client.call('valid_config', ['module1'], {"module1_network_text": [("192.168.0.0", "255.255.255.0")]})
        self.assertFalse(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertNotIn("error", module1_config[1])
        config_result = self.client.call('valid_config', ['module1'], {"module1_network_0_ip": "foo"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertIn("error", module1_config[2])
        config_result = self.client.call('valid_config', ['module1'], {"module1_network_0_ip": "192.168.0.45"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertIn("error", module1_config[2])
        config_result = self.client.call('valid_config', ['module1'], {"module1_network_0_ip": "340.45.30", "module1_network_0_mask": "255.0.0.0"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertIn("error", module1_config[2])
        config_result = self.client.call('valid_config', ['module1'], {"module1_network_0_mask": "255.0.0.0"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertIn("error", module1_config[2])
        config_result = self.client.call('valid_config', ['module1'], {"module1_network_0_mask": "400.500.0.0"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertIn("error", module1_config[2])
        config_result = self.client.call('valid_config', ['module1'], {"module1_network_0_ip": "192.168.0.0", "module1_network_0_mask": "255.255.255.0"})
        self.assertFalse(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertNotIn("error", module1_config[2])

    def test_ip_validation(self):
        config_result = self.client.call('valid_config', ['module1'], {"module1_ip": "foo"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertIn("error", module1_config[3])
        config_result = self.client.call('valid_config', ['module1'], {"module1_ip": "300.400.0.0"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertIn("error", module1_config[3])
        config_result = self.client.call('valid_config', ['module1'], {"module1_ip": "192.168.30.34"})
        self.assertFalse(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertNotIn("error", module1_config[3])

    def test_custom_validation(self):
        config_result = self.client.call('valid_config', ['module1'], {"module1_custom": "bar"})
        self.assertTrue(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertEqual(module1_config[4]["error"], "Value is not foo")
        config_result = self.client.call('valid_config', ['module1'], {"module1_custom": "foo"})
        self.assertFalse(config_result[0]["errors"])
        module1_config = config_result[0]["config"]
        self.assertNotIn("error", module1_config[4])

    def test_multi_required(self):
        config_result = self.client.call('valid_config', ['module2'], {"module2_field1_0_field": ""})
        self.assertTrue(config_result[0]["errors"])
        module2_config = config_result[0]["config"]
        self.assertEqual(module2_config[0]["error"], "This field can't be empty.")
        config_result = self.client.call('valid_config', ['module2'], {"module2_field1_0_field": "foo"})
        self.assertFalse(config_result[0]["errors"])
        module2_config = config_result[0]["config"]
        self.assertNotIn("error", module2_config[0])