Ejemplo n.º 1
0
    def testAddDuplicateAddress(self):
        mac1 = self.safe_interfaces[0]['MACAddress']

        tree = utils.callRpcCommand('netconf add %s %s %s %s' %
                                    (mac1, '192.168.42.1', '255.255.255.240',
                                     self.gw_set1), no_xml=True)

        result = utils.callRpcCommandError('netconf add %s %s %s %s' %
                                           (mac1, '192.168.42.1', '255.255.255.240',
                                            self.gw_set1))

        tree = utils.callRpcCommand('netconf add %s %s %s %s' %
                                    (mac1, '192.168.8.8', '255.255.255.0',
                                     self.gw_set2), no_xml=True)

        nics = getSafeInterfaces()
        expected = [
            {
                'MACAddress': nics[0]['MACAddress'],
                'IPAddress': ['192.168.42.1', '192.168.8.8'],
                'IPSubnet': ['255.255.255.240', '255.255.255.0'],
                'DefaultIPGateway': [self.gw_check2, self.gw_check2]
            },
            {
                'MACAddress': nics[1]['MACAddress'],
                'IPAddress': [],
                'IPSubnet': [],
                'DefaultIPGateway': []
            }
        ]
Ejemplo n.º 2
0
    def testRemoveModule(self):
        tree = utils.callRpcCommand('remove usermodule remove1', no_xml=True)

        tree = utils.callRpcCommand("modulemng list")

        self.assertNotIn('remove1',
                         [n.text for n in tree.findall('module/name')])
Ejemplo n.º 3
0
    def testAddDuplicateAddress(self):
        mac1 = self.safe_interfaces[0]['MACAddress']

        tree = utils.callRpcCommand(
            'netconf add %s %s %s %s' %
            (mac1, '192.168.42.1', '255.255.255.240', self.gw_set1),
            no_xml=True)

        result = utils.callRpcCommandError(
            'netconf add %s %s %s %s' %
            (mac1, '192.168.42.1', '255.255.255.240', self.gw_set1))

        tree = utils.callRpcCommand(
            'netconf add %s %s %s %s' %
            (mac1, '192.168.8.8', '255.255.255.0', self.gw_set2),
            no_xml=True)

        nics = getSafeInterfaces()
        expected = [{
            'MACAddress': nics[0]['MACAddress'],
            'IPAddress': ['192.168.42.1', '192.168.8.8'],
            'IPSubnet': ['255.255.255.240', '255.255.255.0'],
            'DefaultIPGateway': [self.gw_check2, self.gw_check2]
        }, {
            'MACAddress': nics[1]['MACAddress'],
            'IPAddress': [],
            'IPSubnet': [],
            'DefaultIPGateway': []
        }]
Ejemplo n.º 4
0
    def testAddRemoveSingle(self):
        mac1 = self.safe_interfaces[0]['MACAddress']
        mac2 = self.safe_interfaces[1]['MACAddress']

        tree = utils.callRpcCommand(
            'netconf add %s %s %s %s' %
            (mac1, '192.168.42.1', '255.255.255.240', self.gw_set1),
            no_xml=True)

        tree = utils.callRpcCommand('netconf add %s %s %s' %
                                    (mac2, '192.168.8.8', '255.255.255.0'),
                                    no_xml=True)

        nics = getSafeInterfaces()
        expected = [{
            'MACAddress': nics[0]['MACAddress'],
            'IPAddress': ['192.168.42.1'],
            'IPSubnet': ['255.255.255.240'],
            'DefaultIPGateway': [self.gw_check1]
        }, {
            'MACAddress': nics[1]['MACAddress'],
            'IPAddress': ['192.168.8.8'],
            'IPSubnet': ['255.255.255.0'],
            'DefaultIPGateway': [None]
        }]

        self.assertEquals(expected, nics)

        tree = utils.callRpcCommand('netconf remove %s %s' %
                                    (mac1, '192.168.42.1'),
                                    no_xml=True)

        nics = getSafeInterfaces()
        expected = [{
            'MACAddress': nics[0]['MACAddress'],
            'IPAddress': [],
            'DefaultIPGateway': [],
            'IPSubnet': []
        }, {
            'MACAddress': nics[1]['MACAddress'],
            'IPAddress': ['192.168.8.8'],
            'IPSubnet': ['255.255.255.0'],
            'DefaultIPGateway': [None]
        }]

        self.assertEquals(expected, nics)

        if isLinux() or isBsd():
            if isEndian():
                live_config = sortInterfaces(endianLiveConfig().values())
            else:
                live_config = sortInterfaces(callIfconfig().values())
            os_config = callNetconfList()

            for iface in os_config:
                if 'DefaultIPGateway' in iface:
                    del iface['DefaultIPGateway']

            self.assertEquals(os_config, live_config)
Ejemplo n.º 5
0
 def testCallService(self):
     # only tests we can reach the service and we get back a
     # well-formed response with success status
     try:
         tree = utils.callRpcCommand("modulemng list")
     except Exception as e:
         raise utils.FatalError(e)
Ejemplo n.º 6
0
    def testExecArgs(self):
        tree = utils.callRpcCommand("exec script %s arg1 arg2" % shellExt("xmlecho"))

        self.assertEquals('test', tree.tag)
        self.assertEquals(2, len(list(tree)))
        self.assertEquals(['arg1', 'arg2'],
                          [n.text for n in list(tree)])
Ejemplo n.º 7
0
    def testDetailedList(self):
        tree = utils.callRpcCommand("modulemng list -d")

        self.assertEquals('modules', tree.tag)
        self.assertGreater(len(tree.findall('module')), 1)

        for module in tree.findall('module'):
            checkModuleFormat(self, module)
Ejemplo n.º 8
0
    def testDetailedList(self):
        tree = utils.callRpcCommand("modulemng list -d")

        self.assertEquals('modules', tree.tag)
        self.assertGreater(len(tree.findall('module')), 1)

        for module in tree.findall('module'):
            checkModuleFormat(self, module)
Ejemplo n.º 9
0
    def _deconfigureInterfaces(self):
        need_check = False

        self.safe_interfaces = getSafeInterfaces()
        for nic in self.safe_interfaces:
            for ip in nic['IPAddress']:
                utils.callRpcCommand('netconf remove %s %s' %
                                     (nic['MACAddress'], ip), no_xml=True)
                need_check = True

        if not need_check:
            return

        self.safe_interfaces = getSafeInterfaces()
        for nic in self.safe_interfaces:
            if nic['IPAddress'] or nic['IPSubnet'] or \
                    nic['DefaultIPGateway']:
                raise Exception('Could not restore network interface to a clean configuration')
Ejemplo n.º 10
0
    def testUpdateLowerVersion(self):
        tree = utils.callRpcCommand('updateModule systemstatus 100',
                                    files.module('xmlecho'), no_xml=True)

        utils.checkModuleAndVersion('systemstatus', 100)

        result = utils.callRpcCommandError('updateModule systemstatus 9',
                                           files.executable(isWindows(), 'xmlecho'))

        utils.checkModuleAndVersion('systemstatus', 100)
Ejemplo n.º 11
0
    def testList(self):
        tree = utils.callRpcCommand("modulemng list")

        self.assertEquals('modules', tree.tag)

        for module in tree.findall('module'):
            self.assertHasChild(module, 'name')

        for builtin in INTERNAL + PLUGINS:
            self.assertIn(builtin,
                          [n.text for n in tree.findall('module/name')])
Ejemplo n.º 12
0
    def testList(self):
        tree = utils.callRpcCommand("modulemng list")

        self.assertEquals('modules', tree.tag)

        for module in tree.findall('module'):
            self.assertHasChild(module, 'name')

        for builtin in INTERNAL + PLUGINS:
            self.assertIn(builtin,
                          [n.text for n in tree.findall('module/name')])
Ejemplo n.º 13
0
    def testGet(self):
        for builtin in INTERNAL + PLUGINS:
            tree = utils.callRpcCommand("modulemng get %s" % builtin)

            modules = [n.text for n in tree.findall('module/name')]

            self.assertEquals('modules', tree.tag)
            self.assertEquals(1, len(tree.findall('module')))

            module = tree.find('module')
            self.assertChildText(module, 'name', builtin)
            checkModuleFormat(self, module)
Ejemplo n.º 14
0
    def _deconfigureInterfaces(self):
        need_check = False

        self.safe_interfaces = getSafeInterfaces()
        for nic in self.safe_interfaces:
            for ip in nic['IPAddress']:
                utils.callRpcCommand('netconf remove %s %s' %
                                     (nic['MACAddress'], ip),
                                     no_xml=True)
                need_check = True

        if not need_check:
            return

        self.safe_interfaces = getSafeInterfaces()
        for nic in self.safe_interfaces:
            if nic['IPAddress'] or nic['IPSubnet'] or \
                    nic['DefaultIPGateway']:
                raise Exception(
                    'Could not restore network interface to a clean configuration'
                )
Ejemplo n.º 15
0
    def testGet(self):
        for builtin in INTERNAL + PLUGINS:
            tree = utils.callRpcCommand("modulemng get %s" % builtin)

            modules = [n.text for n in tree.findall('module/name')]

            self.assertEquals('modules', tree.tag)
            self.assertEquals(1, len(tree.findall('module')))

            module = tree.find('module')
            self.assertChildText(module, 'name', builtin)
            checkModuleFormat(self, module)
Ejemplo n.º 16
0
    def testCustomModuleLifeCycle(self):
        name = shellExt("thisisatestmodule")

        tree = utils.callRpcCommand("upload usermodule %s" % name,
                                    files.executable(isWindows(),
                                                     'thisisatest'),
                                    no_xml=True)

        # check upload worked
        tree = utils.callRpcCommand("modulemng list")

        self.assertIn(name, [n.text for n in tree.findall('module/name')])

        tree = utils.callRpcCommand("modulemng get %s" % name)

        module = tree.find('module')
        self.assertEquals('modules', tree.tag)
        self.assertChildText(module, 'name', name)
        self.assertChildText(module, 'version', '0')
        self.assertChildText(module, 'type', 'Custom')
        self.assertChildText(module, 'upgradable', 'true')

        # try calling the command
        tree = utils.callRpcCommand("exec script %s" % name)

        self.assertEquals('test', tree.tag)
        self.assertEquals('this is a test', tree.text)

        # remove module
        tree = utils.callRpcCommand("remove usermodule %s" % name, no_xml=True)

        # check module not in the list after remove
        tree = utils.callRpcCommand("modulemng list")

        self.assertNotIn(name, [n.text for n in tree.findall('module/name')])
Ejemplo n.º 17
0
    def testUploadModule(self):
        utils.uploadUserModule('upload1', 'dummy content')

        # Check module info
        tree = utils.callRpcCommand('modulemng get upload1')

        self.assertEquals('modules', tree.tag)
        self.assertEquals(1, len(tree))

        module = tree[0]
        self.assertEquals('module', module.tag)
        self.assertChildText(module, 'name', 'upload1')
        self.assertChildText(module, 'version', '0')
        self.assertChildText(module, 'type', 'Custom')
        self.assertChildText(module, 'upgradable', 'true')
Ejemplo n.º 18
0
def callSystemStatus():
    tree = utils.callRpcCommand('systemstatus')
    res = {
        'cpu': [],
        'disk': [],
    }

    date = tree.find('datetime')
    ram = tree.find('ram')

    for cpu in tree.findall('cpu'):
        index = int(cpu.attrib['value'])

        while index >= len(res['cpu']):
            res['cpu'].append(None)

        res['cpu'][index] = item = {
            'used': float(cpu.attrib['used']),
            'core': [],
        }

        for core in cpu.findall('cores/core'):
            index = int(core.attrib['value'])

            while index >= len(item['core']):
                item['core'].append(None)

            item['core'][index] = float(core.attrib['used'])

    disks = []

    for disk in tree.findall('disks/disk'):
        disks.append({
            'name': disk.attrib['value'],
            'used': int(disk.attrib['used']),
            'total': int(disk.attrib['total']),
            'available': int(disk.attrib['available']),
        })

    res['disk'] = sorted(disks, key=lambda d: d['name'].lower())
    res['date'] = int(date.attrib['value'])
    res['ram'] = {
        'used': float(ram.attrib['used']),
        'total': float(ram.attrib['total']),
        'available': float(ram.attrib['available']),
    }

    return res
Ejemplo n.º 19
0
def callSystemStatus():
    tree = utils.callRpcCommand('systemstatus')
    res = {
        'cpu': [],
        'disk': [],
    }

    date = tree.find('datetime')
    ram = tree.find('ram')

    for cpu in tree.findall('cpu'):
        index = int(cpu.attrib['value'])

        while index >= len(res['cpu']):
            res['cpu'].append(None)

        res['cpu'][index] = item = {
            'used': float(cpu.attrib['used']),
            'core': [],
        }

        for core in cpu.findall('cores/core'):
            index = int(core.attrib['value'])

            while index >= len(item['core']):
                item['core'].append(None)

            item['core'][index] = float(core.attrib['used'])

    disks = []

    for disk in tree.findall('disks/disk'):
        disks.append({
                'name': disk.attrib['value'],
                'used': int(disk.attrib['used']),
                'total': int(disk.attrib['total']),
                'available': int(disk.attrib['available']),
        })

    res['disk'] = sorted(disks, key=lambda d: d['name'].lower())
    res['date'] = int(date.attrib['value'])
    res['ram'] = {
        'used': float(ram.attrib['used']),
        'total': float(ram.attrib['total']),
        'available': float(ram.attrib['available']),
    }

    return res
Ejemplo n.º 20
0
    def testCustomModuleLifeCycle(self):
        name = shellExt("thisisatestmodule")

        tree = utils.callRpcCommand("upload usermodule %s" % name,
                                    files.executable(isWindows(), 'thisisatest'),
                                    no_xml=True)

        # check upload worked
        tree = utils.callRpcCommand("modulemng list")

        self.assertIn(name,
                      [n.text for n in tree.findall('module/name')])

        tree = utils.callRpcCommand("modulemng get %s" % name)

        module = tree.find('module')
        self.assertEquals('modules', tree.tag)
        self.assertChildText(module, 'name', name)
        self.assertChildText(module, 'version', '0')
        self.assertChildText(module, 'type', 'Custom')
        self.assertChildText(module, 'upgradable', 'true')

        # try calling the command
        tree = utils.callRpcCommand("exec script %s" % name)

        self.assertEquals('test', tree.tag)
        self.assertEquals('this is a test', tree.text)

        # remove module
        tree = utils.callRpcCommand("remove usermodule %s" % name, no_xml=True)

        # check module not in the list after remove
        tree = utils.callRpcCommand("modulemng list")

        self.assertNotIn(name,
                         [n.text for n in tree.findall('module/name')])
Ejemplo n.º 21
0
def callNetconfList():
    return _parseInterfaceList(utils.callRpcCommand('netconf list'))
Ejemplo n.º 22
0
    def testExecNoArgs(self):
        tree = utils.callRpcCommand("exec script %s" % shellExt("xmlecho"))

        self.assertEquals('test', tree.tag)
        self.assertEquals(0, len(list(tree)))
Ejemplo n.º 23
0
    def testAddRemoveMultiple(self):
        mac1 = self.safe_interfaces[0]['MACAddress']

        tree = utils.callRpcCommand('netconf add %s %s %s %s' %
                                    (mac1, '192.168.42.1', '255.255.255.240',
                                     self.gw_set1), no_xml=True)

        tree = utils.callRpcCommand('netconf add %s %s %s' %
                                    (mac1, '192.168.8.8', '255.255.255.0'),
                                    no_xml=True)

        tree = utils.callRpcCommand('netconf add %s %s %s' %
                                    (mac1, '192.168.8.9', '255.255.255.0'),
                                    no_xml=True)

        nics = getSafeInterfaces()
        expected = [
            {
                'MACAddress': nics[0]['MACAddress'],
                'IPAddress': ['192.168.42.1', '192.168.8.8', '192.168.8.9'],
                'IPSubnet': ['255.255.255.240', '255.255.255.0', '255.255.255.0'],
                'DefaultIPGateway': [self.gw_check1, None, None]
            },
            {
                'MACAddress': nics[1]['MACAddress'],
                'IPAddress': [],
                'IPSubnet': [],
                'DefaultIPGateway': []
            }
        ]

        self.assertEquals(expected, nics)

        tree = utils.callRpcCommand('netconf remove %s %s' %
                                    (mac1, '192.168.42.1'), no_xml=True)
        tree = utils.callRpcCommand('netconf remove %s %s' %
                                    (mac1, '192.168.8.9'), no_xml=True)

        nics = getSafeInterfaces()
        expected = [
            {
                'MACAddress': nics[0]['MACAddress'],
                'IPAddress': ['192.168.8.8'],
                'IPSubnet': ['255.255.255.0'],
                'DefaultIPGateway': [self.gw_check1]
            },
            {
                'MACAddress': nics[1]['MACAddress'],
                'IPAddress': [],
                'DefaultIPGateway': [],
                'IPSubnet': []
            }
        ]

        self.assertEquals(expected, nics)

        if isLinux() or isBsd():
            if isEndian():
                live_config = sortInterfaces(endianLiveConfig().values())
            else:
                live_config = sortInterfaces(callIfconfig().values())
            os_config = callNetconfList()

            for iface in os_config:
                if 'DefaultIPGateway' in iface:
                    del iface['DefaultIPGateway']

            self.assertEquals(os_config, live_config)
Ejemplo n.º 24
0
def callOsInfo():
    tree = utils.callRpcCommand('osinfo')

    return tree.findtext('name'), tree.findtext('version')
Ejemplo n.º 25
0
    def testUpdate(self):
        tree = utils.callRpcCommand('updateModule systemstatus 100',
                                    files.module('xmlecho'), no_xml=True)

        utils.checkModuleAndVersion('systemstatus', 100)
Ejemplo n.º 26
0
def callNetconfGet(mac):
    return _parseInterfaceList(utils.callRpcCommand('netconf get %s' % mac))
Ejemplo n.º 27
0
def callNetconfList():
    return _parseInterfaceList(utils.callRpcCommand('netconf list'))
Ejemplo n.º 28
0
    def testRemoveModule(self):
        tree = utils.callRpcCommand('remove usermodule remove1', no_xml=True)

        tree = utils.callRpcCommand("modulemng list")

        self.assertNotIn('remove1', [n.text for n in tree.findall('module/name')])
Ejemplo n.º 29
0
def callOsInfo():
    tree = utils.callRpcCommand('osinfo')

    return tree.findtext('name'), tree.findtext('version')
Ejemplo n.º 30
0
def callNetconfGet(mac):
    return _parseInterfaceList(utils.callRpcCommand('netconf get %s' % mac))