Ejemplo n.º 1
0
 def setUp(self):
     array_test, list_test = 'arrayParsing_test', 'listParsing_test'
     text_test, global_test = 'textParsing_test', 'global_test'
     array_error_test, array_error_test2 = 'arrayParsing_error_test', 'arrayParsing_error2_test'
     my_template = "{{hostname}}\n{{VLAN_error}}\n{{VLAN_error2}}\n{{VLAN}}\n{{VLAN!((VLAN!104:Name)):Gateway}}"
     self.workbook = dict()
     self.workbook['VLAN'] = ArrayParsing(
         get_sheet_test(array_test + '.xlsx'))
     self.workbook['VLAN_error'] = ArrayParsing(
         get_sheet_test(array_error_test + '.xlsx'))
     self.workbook['VLAN_error2'] = ArrayParsing(
         get_sheet_test(array_error_test2 + '.xlsx'))
     self.workbook[list_test] = ListParsing(
         get_sheet_test(list_test + '.xlsx'))
     self.workbook[text_test] = TextParsing(
         get_sheet_test(text_test + '.xlsx'))
     self.workbook['Global'] = ArrayParsing(
         get_sheet_test(global_test + '.xlsx'))
     self.equipment = Equipment('HOST1', my_template, self.workbook)
     self.equipment.unresolved = 1
     self.equipment.resolved = 2
Ejemplo n.º 2
0
def main(excel_file, template_file, directory):
    wb = get_excel_workbook(excel_file)
    sheet_names = wb.sheet_names()
    workbook = dict()
    template = open_file(template_file)

    for sheet in sheet_names:
        xl_sheet = wb.sheet_by_name(sheet)
        if (xl_sheet.cell(0, 0).value == 'Function' and
                xl_sheet.cell(0, 1).value == 'Variable' and
                xl_sheet.cell(0, 2).value == 'Value'):
            workbook[sheet] = ListParsing(xl_sheet)
        elif xl_sheet.cell(0, 0).value == 'Text':
            workbook[sheet] = TextParsing(xl_sheet)
        elif sheet == 'Interfaces':
            workbook[sheet] = Interface(xl_sheet)
        else:
            workbook[sheet] = ArrayParsing(xl_sheet)

    if not directory:
        directory = os.path.dirname(template_file)
    is_directory = False
    version_number = 1
    while is_directory is False:
        directory_name = ''.join(['scripts-', os.path.splitext(os.path.basename(excel_file))[0], '-v',
                                  str(version_number)])
        if os.path.isdir(os.path.join(directory, directory_name)) is False:
            directory = os.path.join(directory, directory_name)
            os.mkdir(directory)
            is_directory = True
        version_number += 1
    list_of_equipments = list()
    for hostname in workbook['Global'].get_all_indexes():
        equipment = Equipment(hostname, template, workbook)
        list_of_equipments.append(equipment)
        equipment.save_script_as(directory, hostname)
Ejemplo n.º 3
0
 def setUp(self):
     self.sheet = ArrayParsing(get_sheet_test('arrayParsing_test.xlsx'))
Ejemplo n.º 4
0
class ArrayParsingTests(TestCase):
    def setUp(self):
        self.sheet = ArrayParsing(get_sheet_test('arrayParsing_test.xlsx'))

    def test_get_param_by_index(self):
        expected = '10.2.2.254'
        got = self.sheet.get_value_of_var_by_index_and_param('105', 'Gateway')
        self.assertEqual(expected, got)

    def test_get_param_by_index2(self):
        expected = '105'
        got = self.sheet.get_value_of_var_by_index_and_param('105', 'Vlans ID')
        self.assertEqual(expected, got)

    def test_get_param_by_index_failed(self):
        try:
            expected = KeyError
            got = self.sheet.get_value_of_var_by_index_and_param(
                '101', 'invalid_param')
            self.assertRaises(expected, got)
        except KeyError:
            pass

    def test_set_param_by_index(self):
        index_value, param_value, updated_value = '104', 'Gateway', '1.1.1.1'
        self.sheet.set_value_by_index_and_param(index_value, param_value,
                                                updated_value)
        got = self.sheet.get_value_of_var_by_index_and_param(
            index_value, param_value)
        self.assertEqual(updated_value, got)

    def test_set_param_by_index_failed(self):
        try:
            index_value, param_value, updated_value = '000', 'Gateway', '1.1.1.1'
            expected = KeyError
            got = self.sheet.set_value_by_index_and_param(
                index_value, param_value, updated_value)
            self.assertRaises(expected, got)
        except KeyError:
            pass

    def test_get_all_param_by_index(self):
        expected = {
            'Vlans ID': '105',
            'Name': 'VLAN-VOICE-02',
            'Subnet': '10.2.2.0',
            'Mask': '255.255.255.0',
            'Gateway': '10.2.2.254',
            'Description': '',
            'Subnet_arp': '10.2.2.224',
            'Wildcard_arp': '0.0.0.15',
            'Template Default': 'Default',
            'Template Snooping': 'Snooping',
            'Template Inspection': 'Inspection'
        }
        got = self.sheet.get_all_param_by_index('105')
        self.assertDictEqual(expected, got)

    def test_get_nbr_of_rows(self):
        expected = 23
        got = self.sheet.get_nbr_of_rows()
        self.assertEqual(expected, got)

    def test_get_nbr_of_cols(self):
        expected = 11
        got = self.sheet.get_nbr_of_cols()
        self.assertEqual(expected, got)

    def test_get_nbr_of_cols_in_row(self):
        expected = 11
        got = self.sheet.get_nbr_of_cols_in_row(0)
        self.assertEquals(expected, got)

    def test_get_all_headers(self):
        expected = [
            'Vlans ID', 'Name', 'Subnet', 'Mask', 'Gateway', 'Description',
            'Subnet_arp', 'Wildcard_arp', 'Template Default',
            'Template Snooping', 'Template Inspection'
        ]
        got = self.sheet.get_all_headers()
        self.assertListEqual(expected, got)

    def test_get_all_indexes(self):
        expected = [
            '21', '22', '23', '41', '42', '43', '101', 'test', '103', '104',
            '105', '106', '107', '108', '109'
        ]
        got = self.sheet.get_all_indexes()
        self.assertListEqual(expected, got)

    def test_is_duplication_False(self):
        expected = (False, [])
        got = self.sheet.is_duplication(self.sheet.get_all_headers())
        self.assertEqual(expected, got)

    def test_is_duplication_True(self):
        list_of_superheroes = [
            'Superman', 'Superman', 'Superman', 'Batman', 'Batman', 'Ironman',
            'Thor'
        ]
        expected = (True, ['Superman', 'Batman'])
        got = self.sheet.is_duplication(list_of_superheroes)
        self.assertEqual(expected, got)

    def test_get_row_where_value(self):
        expected = 11
        got = self.sheet.get_row_where_value(105)
        self.assertEqual(expected, got)

    def test_get_row_where_value_failed(self):
        expected = -1
        got = self.sheet.get_row_where_value(0000)
        self.assertEqual(expected, got)

    def test_delimitation_between_indexes_and_commands(self):
        expected = 17
        got = self.sheet.delimitation_between_indexes_and_commands()
        self.assertEqual(expected, got)

    def test_template_content_by_name1(self):
        expected = '{{Name}} and {{Subnet}} and\n{{Gateway}}'
        got = self.sheet.template_content_by_name('default')
        self.assertEqual(expected, got)

    def test_template_content_by_name2(self):
        expected = ''
        got = self.sheet.template_content_by_name('inspection')
        self.assertEqual(expected, got)
Ejemplo n.º 5
0
 def setUp(self):
     self.sheet = ArrayParsing(get_sheet_test('arrayParsing_test.xlsx'))
Ejemplo n.º 6
0
class ArrayParsingTests(TestCase):

    def setUp(self):
        self.sheet = ArrayParsing(get_sheet_test('arrayParsing_test.xlsx'))

    def test_get_param_by_index(self):
        expected = '10.2.2.254'
        got = self.sheet.get_value_of_var_by_index_and_param('105', 'Gateway')
        self.assertEqual(expected, got)

    def test_get_param_by_index2(self):
        expected = '105'
        got = self.sheet.get_value_of_var_by_index_and_param('105', 'Vlans ID')
        self.assertEqual(expected, got)

    def test_get_param_by_index_failed(self):
        try:
            expected = KeyError
            got = self.sheet.get_value_of_var_by_index_and_param('101', 'invalid_param')
            self.assertRaises(expected, got)
        except KeyError:
            pass

    def test_set_param_by_index(self):
        index_value, param_value, updated_value = '104', 'Gateway', '1.1.1.1'
        self.sheet.set_value_by_index_and_param(index_value, param_value, updated_value)
        got = self.sheet.get_value_of_var_by_index_and_param(index_value, param_value)
        self.assertEqual(updated_value, got)

    def test_set_param_by_index_failed(self):
        try:
            index_value, param_value, updated_value = '000', 'Gateway', '1.1.1.1'
            expected = KeyError
            got = self.sheet.set_value_by_index_and_param(index_value, param_value, updated_value)
            self.assertRaises(expected, got)
        except KeyError:
            pass

    def test_get_all_param_by_index(self):
        expected = {'Vlans ID': '105',
                    'Name': 'VLAN-VOICE-02',
                    'Subnet': '10.2.2.0',
                    'Mask': '255.255.255.0',
                    'Gateway': '10.2.2.254',
                    'Description': '',
                    'Subnet_arp': '10.2.2.224',
                    'Wildcard_arp': '0.0.0.15',
                    'Template Default': 'Default',
                    'Template Snooping': 'Snooping',
                    'Template Inspection': 'Inspection'}
        got = self.sheet.get_all_param_by_index('105')
        self.assertDictEqual(expected, got)

    def test_get_nbr_of_rows(self):
        expected = 23
        got = self.sheet.get_nbr_of_rows()
        self.assertEqual(expected, got)

    def test_get_nbr_of_cols(self):
        expected = 11
        got = self.sheet.get_nbr_of_cols()
        self.assertEqual(expected, got)

    def test_get_nbr_of_cols_in_row(self):
        expected = 11
        got = self.sheet.get_nbr_of_cols_in_row(0)
        self.assertEquals(expected, got)

    def test_get_all_headers(self):
        expected = ['Vlans ID', 'Name', 'Subnet', 'Mask', 'Gateway', 'Description', 'Subnet_arp', 'Wildcard_arp',
                    'Template Default', 'Template Snooping', 'Template Inspection']
        got = self.sheet.get_all_headers()
        self.assertListEqual(expected, got)

    def test_get_all_indexes(self):
        expected = ['21', '22', '23', '41', '42', '43', '101', 'test', '103', '104', '105', '106', '107', '108', '109']
        got = self.sheet.get_all_indexes()
        self.assertListEqual(expected, got)

    def test_is_duplication_False(self):
        expected = (False, [])
        got = self.sheet.is_duplication(self.sheet.get_all_headers())
        self.assertEqual(expected, got)

    def test_is_duplication_True(self):
        list_of_superheroes = ['Superman', 'Superman', 'Superman', 'Batman', 'Batman', 'Ironman', 'Thor']
        expected = (True, ['Superman', 'Batman'])
        got = self.sheet.is_duplication(list_of_superheroes)
        self.assertEqual(expected, got)

    def test_get_row_where_value(self):
        expected = 11
        got = self.sheet.get_row_where_value(105)
        self.assertEqual(expected, got)

    def test_get_row_where_value_failed(self):
        expected = -1
        got = self.sheet.get_row_where_value(0000)
        self.assertEqual(expected, got)

    def test_delimitation_between_indexes_and_commands(self):
        expected = 17
        got = self.sheet.delimitation_between_indexes_and_commands()
        self.assertEqual(expected, got)

    def test_template_content_by_name1(self):
        expected = '{{Name}} and {{Subnet}} and\n{{Gateway}}'
        got = self.sheet.template_content_by_name('default')
        self.assertEqual(expected, got)

    def test_template_content_by_name2(self):
        expected = ''
        got = self.sheet.template_content_by_name('inspection')
        self.assertEqual(expected, got)
Ejemplo n.º 7
0
 def get_all_equipment_names(self):
     glob = self.wb.sheet_by_name('Global')
     glob = ArrayParsing(glob)
     return glob.get_all_indexes()