Esempio n. 1
0
 def test_vlan_interface(self):  # pylint: disable=too-many-locals
     device_dict = DeviceDictionary.get('bbb-01')
     chk = {
         'hostname': 'bbb-01',
         'parameters': {
             'map': {'eth1': {'192.168.0.2': 7}, 'eth0': {'192.168.0.2': 5}},
             'interfaces': ['eth0', 'eth1'],
             'sysfs': {
                 'eth1': '/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/eth1',
                 'eth0': '/sys/devices/pci0000:00/0000:00:19.0/net/eth0'
             },
             'mac_addr': {'eth1': '00:24:d7:9b:c0:8c', 'eth0': 'f0:de:f1:46:8c:21'},
             'tags': {'eth1': ['1G'], 'eth0': ['1G', '10G']}}
     }
     self.assertEqual(chk, device_dict.to_dict())
     submission = yaml.load(open(self.filename, 'r'))
     self.assertIn('protocols', submission)
     self.assertIn('lava-vland', submission['protocols'])
     roles = [role for role, _ in submission['protocols']['lava-vland'].iteritems()]
     params = submission['protocols']['lava-vland']
     vlans = {}
     for role in roles:
         for name, tags in params[role].iteritems():
             vlans[name] = tags
     self.assertIn('vlan_one', vlans)
     self.assertIn('vlan_two', vlans)
     jobs = split_multinode_yaml(submission, 'abcdefghijkl')
     job_roles = {}
     for role in roles:
         self.assertEqual(len(jobs[role]), 1)
         job_roles[role] = jobs[role][0]
     for role in roles:
         self.assertIn('device_type', job_roles[role])
         self.assertIn('protocols', job_roles[role])
         self.assertIn('lava-vland', job_roles[role]['protocols'])
     client_job = job_roles['client']
     server_job = job_roles['server']
     self.assertIn('vlan_one', client_job['protocols']['lava-vland'])
     self.assertIn('10G', client_job['protocols']['lava-vland']['vlan_one']['tags'])
     self.assertIn('vlan_two', server_job['protocols']['lava-vland'])
     self.assertIn('1G', server_job['protocols']['lava-vland']['vlan_two']['tags'])
     client_tags = client_job['protocols']['lava-vland']['vlan_one']
     client_dict = DeviceDictionary.get('bbb-01').to_dict()
     for interface, tags in client_dict['parameters']['tags'].iteritems():
         if any(set(tags).intersection(client_tags)):
             self.assertEqual(interface, 'eth0')
             self.assertEqual(
                 client_dict['parameters']['map'][interface],
                 {'192.168.0.2': 5}
             )
     # find_device_for_job would have a call to match_vlan_interface(device, job.definition) added
     bbb1 = Device.objects.get(hostname='bbb-01')
     self.assertTrue(match_vlan_interface(bbb1, client_job))
     cubie1 = Device.objects.get(hostname='ct-01')
     self.assertTrue(match_vlan_interface(cubie1, server_job))
Esempio n. 2
0
 def test_job_protocols(self):
     self.factory.ensure_tag('usb-eth')
     self.factory.ensure_tag('sata')
     self.factory.bbb1.tags = Tag.objects.filter(name='usb-eth')
     self.factory.bbb1.save()
     self.factory.cubie1.tags = Tag.objects.filter(name='sata')
     self.factory.cubie1.save()
     device_dict = DeviceDictionary(hostname=self.factory.bbb1.hostname)
     device_dict.parameters = {
         'interfaces': ['eth0', 'eth1'],
         'sysfs': {
             'eth0': "/sys/devices/pci0000:00/0000:00:19.0/net/eth0",
             'eth1': "/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/eth1"},
         'mac_addr': {'eth0': "f0:de:f1:46:8c:21", 'eth1': "00:24:d7:9b:c0:8c"},
         'tags': {'eth0': ['1G', '10G'], 'eth1': ['1G']},
         'map': {'eth0': {'192.168.0.2': 5}, 'eth1': {'192.168.0.2': 7}}
     }
     device_dict.save()
     device_dict = DeviceDictionary(hostname=self.factory.cubie1.hostname)
     device_dict.parameters = {
         'interfaces': ['eth0', 'eth1'],
         'sysfs': {
             'eth0': "/sys/devices/pci0000:00/0000:00:19.0/net/eth0",
             'eth1': "/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/eth1"},
         'mac_addr': {'eth0': "f0:de:f1:46:8c:21", 'eth1': "00:24:d7:9b:c0:8c"},
         'tags': {'eth0': ['1G', '10G'], 'eth1': ['1G']},
         'map': {'eth0': {'192.168.0.2': 4}, 'eth1': {'192.168.0.2': 6}}
     }
     device_dict.save()
     target_group = "unit-test-only"
     job_dict = split_multinode_yaml(self.factory.make_vland_job(), target_group)
     client_job = job_dict['client'][0]
     client_handle, client_file_name = tempfile.mkstemp()
     yaml.dump(client_job, open(client_file_name, 'w'))
     # YAML device file, as required by lava-dispatch --target
     device_yaml_file = os.path.realpath(os.path.join(os.path.dirname(__file__), 'bbb-01.yaml'))
     print device_yaml_file
     self.assertTrue(os.path.exists(device_yaml_file))
     parser = JobParser()
     bbb_device = NewDevice(device_yaml_file)
     with open(client_file_name) as sample_job_data:
         bbb_job = parser.parse(sample_job_data, bbb_device, 4212, None, output_dir='/tmp/')
     os.close(client_handle)
     os.unlink(client_file_name)
     self.assertIn('protocols', bbb_job.parameters)
     self.assertIn(VlandProtocol.name, bbb_job.parameters['protocols'])
     self.assertIn(MultinodeProtocol.name, bbb_job.parameters['protocols'])
Esempio n. 3
0
 def test_split_vland(self):
     target_group = "unit-test-only"
     job_dict = split_multinode_yaml(self.factory.make_vland_job(), target_group)
     self.assertEqual(len(job_dict), 2)
     roles = job_dict.keys()
     self.assertEqual({'server', 'client'}, set(roles))
     for role in roles:
         self.assertEqual(len(job_dict[role]), 1)  # count = 1
     client_job = job_dict['client'][0]
     server_job = job_dict['server'][0]
     self.assertIn('lava-multinode', client_job['protocols'])
     self.assertIn('lava-multinode', server_job['protocols'])
     self.assertIn('lava-vland', client_job['protocols'])
     self.assertIn('lava-vland', server_job['protocols'])
     client_vlan = client_job['protocols']['lava-vland']
     server_vlan = server_job['protocols']['lava-vland']
     self.assertIn('vlan_one', client_vlan)
     self.assertIn('vlan_two', server_vlan)
     self.assertEqual(['10G'], client_vlan.values()[0]['tags'])
     self.assertEqual(['1G'], server_vlan.values()[0]['tags'])
Esempio n. 4
0
    def test_multinode_split(self):
        """
        Test just the split of pipeline YAML

        This function does not test the content of 'roles' as this needs information
        which is only available after the devices have been reserved.
        """
        server_check = os.path.join(os.path.dirname(__file__), 'kvm-multinode-server.yaml')
        client_check = os.path.join(os.path.dirname(__file__), 'kvm-multinode-client.yaml')
        submission = yaml.load(open(
            os.path.join(os.path.dirname(__file__), 'kvm-multinode.yaml'), 'r'))
        target_group = 'arbitrary-group-id'  # for unit tests only

        jobs = split_multinode_yaml(submission, target_group)
        self.assertEqual(len(jobs), 2)
        for role, job_list in jobs.items():
            for job in job_list:
                yaml.dump(job)  # ensure the jobs can be serialised as YAML
                role = job['protocols']['lava-multinode']['role']
                if role == 'client':
                    self.assertEqual(job, yaml.load(open(client_check, 'r')))
                if role == 'server':
                    self.assertEqual(job, yaml.load(open(server_check, 'r')))
Esempio n. 5
0
 def test_job_protocols(self):
     self.factory.ensure_tag('usb-eth')
     self.factory.ensure_tag('sata')
     self.factory.bbb1.tags = Tag.objects.filter(name='usb-eth')
     self.factory.bbb1.save()
     self.factory.cubie1.tags = Tag.objects.filter(name='sata')
     self.factory.cubie1.save()
     target_group = "unit-test-only"
     job_dict = split_multinode_yaml(self.factory.make_vland_job(), target_group)
     client_job = job_dict['client'][0]
     client_handle, client_file_name = tempfile.mkstemp()
     yaml.dump(client_job, open(client_file_name, 'w'))
     # YAML device file, as required by lava-dispatch --target
     device_yaml_file = os.path.realpath(os.path.join(os.path.dirname(__file__), 'devices', 'bbb-01.yaml'))
     self.assertTrue(os.path.exists(device_yaml_file))
     parser = JobParser()
     bbb_device = NewDevice(device_yaml_file)
     with open(client_file_name) as sample_job_data:
         bbb_job = parser.parse(sample_job_data, bbb_device, 4212, None, "")
     os.close(client_handle)
     os.unlink(client_file_name)
     self.assertIn('protocols', bbb_job.parameters)
     self.assertIn(VlandProtocol.name, bbb_job.parameters['protocols'])
     self.assertIn(MultinodeProtocol.name, bbb_job.parameters['protocols'])
Esempio n. 6
0
    def test_match_devices_with_map(self):
        devices = Device.objects.filter(status=Device.IDLE).order_by('is_public')
        device_dict = DeviceDictionary(hostname=self.factory.bbb1.hostname)
        device_dict.parameters = {  # client, RJ45 10M only
            'extends': 'beaglebone-black.jinja2',
            'interfaces': ['eth0', 'eth1'],
            'sysfs': {
                'eth0': "/sys/devices/pci0000:00/0000:00:19.0/net/eth0",
                'eth1': "/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/eth1"},
            'mac_addr': {'eth0': "f0:de:f1:46:8c:21", 'eth1': "00:24:d7:9b:c0:8c"},
            'tags': {'eth0': [], 'eth1': ['RJ45', '10M']},
            'map': {'eth0': {'192.168.0.2': 5}, 'eth1': {'192.168.0.2': 7}}
        }
        device_dict.save()
        device_dict = DeviceDictionary(hostname=self.factory.cubie1.hostname)
        device_dict.parameters = {  # server includes 100M
            'extends': 'cubietruck.jinja2',
            'interfaces': ['eth0', 'eth1'],
            'sysfs': {
                'eth0': "/sys/devices/pci0000:00/0000:00:19.0/net/eth0",
                'eth1': "/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/eth1"},
            'mac_addr': {'eth0': "f0:de:f1:46:8c:21", 'eth1': "00:24:d7:9b:c0:8c"},
            'tags': {'eth0': [], 'eth1': ['RJ45', '10M', '100M']},
            'map': {'eth0': {'192.168.0.2': 4}, 'eth1': {'192.168.0.2': 6}}
        }
        device_dict.save()
        user = self.factory.make_user()
        sample_job_file = os.path.join(os.path.dirname(__file__), 'bbb-cubie-vlan-group.yaml')
        with open(sample_job_file, 'r') as test_support:
            data = yaml.load(test_support)
        del(data['protocols']['lava-multinode']['roles']['client']['tags'])
        del(data['protocols']['lava-multinode']['roles']['server']['tags'])

        interfaces = []
        job_dict = split_multinode_yaml(data, 'abcdefg123456789')
        client_job = job_dict['client'][0]
        device_dict = DeviceDictionary.get(self.factory.bbb1.hostname).to_dict()
        self.assertIsNotNone(device_dict)
        tag_list = client_job['protocols']['lava-vland']['vlan_one']['tags']
        for interface, tags in device_dict['parameters']['tags'].iteritems():
            if set(tags) & set(tag_list) == set(tag_list) and interface not in interfaces:
                interfaces.append(interface)
                break
        self.assertEqual(['eth1'], interfaces)
        self.assertEqual(len(interfaces), len(client_job['protocols']['lava-vland'].keys()))

        interfaces = []
        server_job = job_dict['server'][0]
        device_dict = DeviceDictionary.get(self.factory.cubie1.hostname).to_dict()
        self.assertIsNotNone(device_dict)
        tag_list = server_job['protocols']['lava-vland']['vlan_two']['tags']
        for interface, tags in device_dict['parameters']['tags'].iteritems():
            if set(tags) & set(tag_list) == set(tag_list) and interface not in interfaces:
                interfaces.append(interface)
                break
        self.assertEqual(['eth1'], interfaces)
        self.assertEqual(len(interfaces), len(client_job['protocols']['lava-vland'].keys()))

        vlan_job = TestJob.from_yaml_and_user(yaml.dump(data), user)

        # vlan_one: client role. RJ45 10M. bbb device type
        # vlan_two: server role. RJ45 100M. cubie device type.

        assignments = {}
        for job in vlan_job:
            device = find_device_for_job(job, devices)
            self.assertEqual(device.device_type, job.requested_device_type)
            # map has been defined
            self.assertTrue(match_vlan_interface(device, yaml.load(job.definition)))
            assignments[job.device_role] = device
        self.assertEqual(assignments['client'].hostname, self.factory.bbb1.hostname)
        self.assertEqual(assignments['server'].hostname, self.factory.cubie1.hostname)
Esempio n. 7
0
 def test_job_protocols(self):
     self.factory.ensure_tag('usb-eth')
     self.factory.ensure_tag('sata')
     self.factory.bbb1.tags = Tag.objects.filter(name='usb-eth')
     self.factory.bbb1.save()
     self.factory.cubie1.tags = Tag.objects.filter(name='sata')
     self.factory.cubie1.save()
     device_dict = DeviceDictionary(hostname=self.factory.bbb1.hostname)
     device_dict.parameters = {
         'interfaces': ['eth0', 'eth1'],
         'sysfs': {
             'eth0':
             "/sys/devices/pci0000:00/0000:00:19.0/net/eth0",
             'eth1':
             "/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/eth1"
         },
         'mac_addr': {
             'eth0': "f0:de:f1:46:8c:21",
             'eth1': "00:24:d7:9b:c0:8c"
         },
         'tags': {
             'eth0': ['1G', '10G'],
             'eth1': ['1G']
         },
         'map': {
             'eth0': {
                 '192.168.0.2': 5
             },
             'eth1': {
                 '192.168.0.2': 7
             }
         }
     }
     device_dict.save()
     device_dict = DeviceDictionary(hostname=self.factory.cubie1.hostname)
     device_dict.parameters = {
         'interfaces': ['eth0', 'eth1'],
         'sysfs': {
             'eth0':
             "/sys/devices/pci0000:00/0000:00:19.0/net/eth0",
             'eth1':
             "/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/eth1"
         },
         'mac_addr': {
             'eth0': "f0:de:f1:46:8c:21",
             'eth1': "00:24:d7:9b:c0:8c"
         },
         'tags': {
             'eth0': ['1G', '10G'],
             'eth1': ['1G']
         },
         'map': {
             'eth0': {
                 '192.168.0.2': 4
             },
             'eth1': {
                 '192.168.0.2': 6
             }
         }
     }
     device_dict.save()
     target_group = "unit-test-only"
     job_dict = split_multinode_yaml(self.factory.make_vland_job(),
                                     target_group)
     client_job = job_dict['client'][0]
     client_handle, client_file_name = tempfile.mkstemp()
     yaml.dump(client_job, open(client_file_name, 'w'))
     # YAML device file, as required by lava-dispatch --target
     device_yaml_file = os.path.realpath(
         os.path.join(os.path.dirname(__file__), 'devices', 'bbb-01.yaml'))
     self.assertTrue(os.path.exists(device_yaml_file))
     parser = JobParser()
     bbb_device = NewDevice(device_yaml_file)
     with open(client_file_name) as sample_job_data:
         bbb_job = parser.parse(sample_job_data,
                                bbb_device,
                                4212,
                                None,
                                "",
                                output_dir='/tmp/')
     os.close(client_handle)
     os.unlink(client_file_name)
     self.assertIn('protocols', bbb_job.parameters)
     self.assertIn(VlandProtocol.name, bbb_job.parameters['protocols'])
     self.assertIn(MultinodeProtocol.name, bbb_job.parameters['protocols'])
Esempio n. 8
0
    def test_match_devices_with_map(self):
        devices = Device.objects.filter(
            status=Device.IDLE).order_by('is_public')
        device_dict = DeviceDictionary(hostname=self.factory.bbb1.hostname)
        device_dict.parameters = {  # client, RJ45 10M only
            'extends': 'beaglebone-black.jinja2',
            'interfaces': ['eth0', 'eth1'],
            'sysfs': {
                'eth0':
                "/sys/devices/pci0000:00/0000:00:19.0/net/eth0",
                'eth1':
                "/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/eth1"
            },
            'mac_addr': {
                'eth0': "f0:de:f1:46:8c:21",
                'eth1': "00:24:d7:9b:c0:8c"
            },
            'tags': {
                'eth0': [],
                'eth1': ['RJ45', '10M']
            },
            'map': {
                'eth0': {
                    '192.168.0.2': 5
                },
                'eth1': {
                    '192.168.0.2': 7
                }
            }
        }
        device_dict.save()
        device_dict = DeviceDictionary(hostname=self.factory.cubie1.hostname)
        device_dict.parameters = {  # server includes 100M
            'extends': 'cubietruck.jinja2',
            'interfaces': ['eth0', 'eth1'],
            'sysfs': {
                'eth0':
                "/sys/devices/pci0000:00/0000:00:19.0/net/eth0",
                'eth1':
                "/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/eth1"
            },
            'mac_addr': {
                'eth0': "f0:de:f1:46:8c:21",
                'eth1': "00:24:d7:9b:c0:8c"
            },
            'tags': {
                'eth0': [],
                'eth1': ['RJ45', '10M', '100M']
            },
            'map': {
                'eth0': {
                    '192.168.0.2': 4
                },
                'eth1': {
                    '192.168.0.2': 6
                }
            }
        }
        device_dict.save()
        user = self.factory.make_user()
        sample_job_file = os.path.join(os.path.dirname(__file__),
                                       'sample_jobs',
                                       'bbb-cubie-vlan-group.yaml')
        with open(sample_job_file, 'r') as test_support:
            data = yaml.load(test_support)
        del (data['protocols']['lava-multinode']['roles']['client']['tags'])
        del (data['protocols']['lava-multinode']['roles']['server']['tags'])

        interfaces = []
        job_dict = split_multinode_yaml(data, 'abcdefg123456789')
        client_job = job_dict['client'][0]
        device_dict = DeviceDictionary.get(
            self.factory.bbb1.hostname).to_dict()
        self.assertIsNotNone(device_dict)
        tag_list = client_job['protocols']['lava-vland']['vlan_one']['tags']
        for interface, tags in device_dict['parameters']['tags'].iteritems():
            if set(tags) & set(tag_list) == set(
                    tag_list) and interface not in interfaces:
                interfaces.append(interface)
                break
        self.assertEqual(['eth1'], interfaces)
        self.assertEqual(len(interfaces),
                         len(client_job['protocols']['lava-vland'].keys()))

        interfaces = []
        server_job = job_dict['server'][0]
        device_dict = DeviceDictionary.get(
            self.factory.cubie1.hostname).to_dict()
        self.assertIsNotNone(device_dict)
        tag_list = server_job['protocols']['lava-vland']['vlan_two']['tags']
        for interface, tags in device_dict['parameters']['tags'].iteritems():
            if set(tags) & set(tag_list) == set(
                    tag_list) and interface not in interfaces:
                interfaces.append(interface)
                break
        self.assertEqual(['eth1'], interfaces)
        self.assertEqual(len(interfaces),
                         len(client_job['protocols']['lava-vland'].keys()))

        vlan_job = TestJob.from_yaml_and_user(yaml.dump(data), user)

        # vlan_one: client role. RJ45 10M. bbb device type
        # vlan_two: server role. RJ45 100M. cubie device type.

        assignments = {}
        for job in vlan_job:
            device = find_device_for_job(job, devices)
            self.assertEqual(device.device_type, job.requested_device_type)
            # map has been defined
            self.assertTrue(
                match_vlan_interface(device, yaml.load(job.definition)))
            assignments[job.device_role] = device
        self.assertEqual(assignments['client'].hostname,
                         self.factory.bbb1.hostname)
        self.assertEqual(assignments['server'].hostname,
                         self.factory.cubie1.hostname)