def test_find_device_for_job_with_multiple_tags(self): """ test that tags are used to set which device is selected choose black02 and never black01 due to the presence of both the common tag and the unique tag only with black02. """ job = self.submit_job(device_type='beaglebone', tags=[ self.common_tag.name, self.unique_tag.name ]) devices = [self.panda01, self.black01, self.black02, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black02, chosen_device) try: job = self.submit_job(device_type='panda', tags=[ self.common_tag.name, self.unique_tag.name ]) except DevicesUnavailableException: pass else: self.fail("Offered a panda when no pandas support the requested tags") devices = [self.black01, self.black02, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black02, chosen_device) devices = [self.arndale02, self.panda02, self.black02, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black02, chosen_device)
def test_find_device_for_job_with_multiple_tags(self): """ test that tags are used to set which device is selected choose black02 and never black01 due to the presence of both the common tag and the unique tag only with black02. """ job = self.submit_job( device_type='beaglebone', tags=[self.common_tag.name, self.unique_tag.name]) devices = [self.panda01, self.black01, self.black02, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black02, chosen_device) try: job = self.submit_job( device_type='panda', tags=[self.common_tag.name, self.unique_tag.name]) except DevicesUnavailableException: pass else: self.fail( "Offered a panda when no pandas support the requested tags") devices = [self.black01, self.black02, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black02, chosen_device) devices = [self.arndale02, self.panda02, self.black02, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black02, chosen_device)
def test_find_device_with_single_job_tag(self): """ tests handling of jobs with less tags than supported but still choosing one tag which only applies to one device in the set. """ job = self.submit_job(device_type='beaglebone', tags=[self.unique_tag.name]) devices = [self.panda02, self.black02, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black02, chosen_device) job = self.submit_job(device_type='beaglebone', tags=[self.exclusion_tag.name]) devices = [self.panda02, self.black02, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black03, chosen_device)
def test_find_device_for_job(self): """ tests that find_device_for_job gives preference to matching by requested _device_ over matching by requested device _type_. """ job = self.submit_job(target='panda01', device_type='panda') devices = [self.panda02, self.panda01] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.panda01, chosen_device)
def test_find_device_with_single_job_tag(self): """ tests handling of jobs with less tags than supported but still choosing one tag which only applies to one device in the set. """ job = self.submit_job(device_type='beaglebone', tags=[ self.unique_tag.name ]) devices = [self.panda02, self.black02, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black02, chosen_device) job = self.submit_job(device_type='beaglebone', tags=[ self.exclusion_tag.name ]) devices = [self.panda02, self.black02, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black03, chosen_device)
def test_find_device_for_job_with_tag(self): """ test that tags are used to set which device is selected panda should be excluded by device_type black03 should be excluded as it does not have the common tag black02 would also match but is not included in the device check """ job = self.submit_job(device_type='beaglebone', tags=[self.common_tag.name]) devices = [self.panda01, self.arndale02, self.black01, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black01, chosen_device)
def test_find_device_for_job_with_tag(self): """ test that tags are used to set which device is selected panda should be excluded by device_type black03 should be excluded as it does not have the common tag black02 would also match but is not included in the device check """ job = self.submit_job(device_type='beaglebone', tags=[ self.common_tag.name ]) devices = [self.panda01, self.arndale02, self.black01, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.black01, chosen_device)
def test_find_device_for_devices_without_tags(self): """ ensure that tags do not interfere with finding devices of unrelated types """ job = self.submit_job(device_type='arndale', tags=[]) devices = [self.panda01, self.arndale02, self.black01, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.arndale02, chosen_device) try: self.submit_job(device_type='arndale', tags=[self.common_tag.name]) except DevicesUnavailableException: pass else: self.fail( "Offered an arndale when no arndale support the requested tags" )
def test_find_device_for_devices_without_tags(self): """ ensure that tags do not interfere with finding devices of unrelated types """ job = self.submit_job(device_type='arndale', tags=[]) devices = [self.panda01, self.arndale02, self.black01, self.black03] chosen_device = find_device_for_job(job, devices) self.assertEqual(self.arndale02, chosen_device) try: job = self.submit_job(device_type='arndale', tags=[ self.common_tag.name ]) except DevicesUnavailableException: pass else: self.fail("Offered an arndale when no arndale support the requested tags")
def test_match_devices_with_map(self): devices = Device.objects.filter(status=Device.IDLE).order_by('is_public') 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() 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) vlan_job = TestJob.from_yaml_and_user(yaml.dump(data), user) 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)
def test_find_nonexclusive_device(self): """ test that exclusive devices are not assigned JSON jobs """ self.assertFalse(self.panda01.is_exclusive) device_dict = DeviceDictionary.get(self.panda01.hostname) self.assertIsNone(device_dict) device_dict = DeviceDictionary(hostname=self.panda01.hostname) device_dict.parameters = {'exclusive': 'True'} device_dict.save() self.assertTrue(self.panda01.is_exclusive) self.assertRaises(DevicesUnavailableException, self.submit_job, target='panda01', device_type='panda') job = self.submit_job(device_type='panda') devices = [self.panda02, self.panda01] self.assertEqual(find_device_for_job(job, devices), self.panda02) device_dict.delete() self.assertFalse(self.panda01.is_exclusive)
def test_match_devices_without_map(self): devices = Device.objects.filter(status=Device.IDLE).order_by('is_public') 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() 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) vlan_job = TestJob.from_yaml_and_user(yaml.dump(data), user) assignments = {} for job in vlan_job: device = find_device_for_job(job, devices) self.assertEqual(device.device_type, job.requested_device_type) # no map defined self.assertFalse(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)
def test_find_nonexclusive_device(self): """ test that exclusive devices are not assigned JSON jobs """ self.assertFalse(self.panda01.is_exclusive) device_dict = DeviceDictionary.get(self.panda01.hostname) self.assertIsNone(device_dict) device_dict = DeviceDictionary(hostname=self.panda01.hostname) device_dict.parameters = {'exclusive': 'True'} device_dict.save() self.assertTrue(self.panda01.is_exclusive) self.assertRaises( DevicesUnavailableException, self.submit_job, target='panda01', device_type='panda') job = self.submit_job(device_type='panda') devices = [self.panda02, self.panda01] self.assertEqual( find_device_for_job(job, devices), self.panda02 ) device_dict.delete() self.assertFalse(self.panda01.is_exclusive)