本文整理汇总了Python中lava_scheduler_app.models.DeviceDictionary.parameters方法的典型用法代码示例。如果您正苦于以下问题:Python DeviceDictionary.parameters方法的具体用法?Python DeviceDictionary.parameters怎么用?Python DeviceDictionary.parameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lava_scheduler_app.models.DeviceDictionary
的用法示例。
在下文中一共展示了DeviceDictionary.parameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_same_type_devices_with_map
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def test_same_type_devices_with_map(self):
device_dict = DeviceDictionary(hostname=self.factory.bbb1.hostname)
device_dict.parameters = { # client, RJ45 10M 100M
'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:22", 'eth1': "00:24:d7:9b:c0:8b"},
'tags': {'eth0': [], 'eth1': ['RJ45', '10M', '100M']},
'map': {'eth0': {'192.168.0.2': 5}, 'eth1': {'192.168.0.2': 7}}
}
device_dict.save()
bbb2 = self.factory.make_device(self.factory.bbb_type, hostname='bbb2')
device_dict = DeviceDictionary(hostname=bbb2.hostname)
device_dict.parameters = { # server, RJ45 10M 100M
'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', '100M']},
'map': {'eth0': {'192.168.0.2': 7}, 'eth1': {'192.168.0.2': 9}}
}
device_dict.save()
devices = list(Device.objects.filter(status=Device.IDLE).order_by('is_public'))
user = self.factory.make_user()
sample_job_file = os.path.join(os.path.dirname(__file__), 'bbb-bbb-vland-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
if device in devices:
devices.remove(device)
assign_jobs()
self.factory.bbb1.refresh_from_db()
bbb2.refresh_from_db()
self.assertIsNotNone(self.factory.bbb1.current_job)
self.assertIsNotNone(bbb2.current_job)
self.assertIsNotNone(self.factory.bbb1.current_job.actual_device)
self.assertIsNotNone(bbb2.current_job.actual_device)
self.assertNotEqual(self.factory.bbb1.current_job, bbb2.current_job)
self.assertNotEqual(self.factory.bbb1.current_job.actual_device, bbb2.current_job.actual_device)
示例2: test_pipeline_device
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def test_pipeline_device(self):
foo = DeviceDictionary(hostname='foo')
foo.parameters = {
'bootz': {
'kernel': '0x4700000',
'ramdisk': '0x4800000',
'dtb': '0x4300000'
},
'media': {
'usb': {
'UUID-required': True,
'SanDisk_Ultra': {
'uuid': 'usb-SanDisk_Ultra_20060775320F43006019-0:0',
'device_id': 0
},
'sata': {
'UUID-required': False
}
}
}
}
device = PipelineDevice(foo.parameters, 'foo')
self.assertEqual(device.target, 'foo')
self.assertIn('power_state', device)
self.assertEqual(device.power_state, '') # there is no power_on_command for this device, so the property is ''
self.assertTrue(hasattr(device, 'power_state'))
self.assertFalse(hasattr(device, 'hostname'))
self.assertIn('hostname', device)
示例3: test_select_device
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def test_select_device(self):
self.restart()
hostname = 'fakeqemu3'
device_dict = DeviceDictionary(hostname=hostname)
device_dict.parameters = self.conf
device_dict.save()
device = self.factory.make_device(self.device_type, hostname)
job = TestJob.from_yaml_and_user(
self.factory.make_job_yaml(),
self.factory.make_user())
# this uses the system jinja2 path - local changes to the qemu.jinja2
# will not be available.
selected = select_device(job, self.dispatchers)
self.assertIsNone(selected)
job.actual_device = device
selected = select_device(job, self.dispatchers)
self.assertIsNone(selected)
device.worker_host = self.worker
selected = select_device(job, self.dispatchers)
self.assertIsNone(selected)
# device needs to be in reserved state
# fake up the assignment which needs a separate test
job.actual_device = device
job.save()
device.current_job = job
device.status = Device.RESERVED
device.save()
selected = select_device(job, self.dispatchers)
self.assertEqual(selected, device)
示例4: test_menu_device
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def test_menu_device(self):
job_ctx = {}
hostname = 'mustang01'
device_dict = DeviceDictionary(hostname=hostname)
device_dict.parameters = self.conf
device_dict.save()
device = self.factory.make_device(self.device_type, hostname)
self.assertEqual(device.device_type.name, 'mustang-uefi')
device_data = devicedictionary_to_jinja2(
device_dict.parameters,
device_dict.parameters['extends']
)
template = prepare_jinja_template(hostname, device_data, system_path=False, path=self.jinja_path)
config_str = template.render(**job_ctx)
self.assertIsNotNone(config_str)
config = yaml.load(config_str)
self.assertIsNotNone(config)
self.assertEqual(config['device_type'], self.device_type.name)
self.assertIsNotNone(config['parameters'])
self.assertIsNotNone(config['actions']['boot']['methods']['uefi-menu']['nfs'])
menu_data = config['actions']['boot']['methods']['uefi-menu']['nfs']
tftp_menu = [item for item in menu_data if 'items' in item['select'] and 'TFTP' in item['select']['items'][0]][0]
tftp_mac = self.conf['tftp_mac']
# value from device dictionary correctly replaces device type default
self.assertIn(tftp_mac, tftp_menu['select']['items'][0])
示例5: test_job_protocols
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
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'])
示例6: test_make_device
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def test_make_device(self):
hostname = 'fakeqemu3'
device_dict = DeviceDictionary(hostname=hostname)
device_dict.parameters = self.conf
device_dict.save()
device = self.factory.make_device(self.device_type, hostname)
self.assertEqual(device.device_type.name, 'qemu')
job = self.factory.make_job_yaml()
self.assertIsNotNone(job)
示例7: test_vland_jinja2
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def test_vland_jinja2(self):
"""
Test complex device dictionary values
The reference data can cross lines but cannot be indented as the pprint
object in utils uses indent=0, width=80 for YAML compatibility.
The strings read in from config files can have indenting spaces, these
are removed in the pprint.
"""
data = """{% extends 'vland.jinja2' %}
{% set interfaces = ['eth0', 'eth1'] %}
{% set 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'} %}
{% set mac_addr = {'eth0': 'f0:de:f1:46:8c:21', 'eth1': '00:24:d7:9b:c0:8c'} %}
{% set tags = {'eth0': ['1G', '10G'], 'eth1': ['1G']} %}
{% set map = {'eth0': {'192.168.0.2': 5}, 'eth1': {'192.168.0.2': 7}} %}
"""
result = {
'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'
},
'extends': 'vland.jinja2',
'mac_addr': {
'eth1': '00:24:d7:9b:c0:8c',
'eth0': 'f0:de:f1:46:8c:21'
},
'tags': {
'eth1': ['1G'],
'eth0': ['1G', '10G']
},
'map': {
'eth0': {
'192.168.0.2': 5
},
'eth1': {
'192.168.0.2': 7
}
}
}
dictionary = jinja2_to_devicedictionary(data_dict=data)
self.assertEqual(result, dictionary)
jinja2_str = devicedictionary_to_jinja2(data_dict=dictionary, extends='vland.jinja2')
# ordering within the dict can change but each line needs to still appear
for line in str(data).split('\n'):
self.assertIn(line, str(jinja2_str))
# create a DeviceDictionary for this test
vlan = DeviceDictionary(hostname='vlanned1')
vlan.parameters = dictionary
vlan.save()
del vlan
vlan = DeviceDictionary.get('vlanned1')
cmp_str = str(devicedictionary_to_jinja2(vlan.parameters, 'vland.jinja2'))
for line in str(data).split('\n'):
self.assertIn(line, cmp_str)
示例8: test_match_devices_with_map
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
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)
示例9: test_jinja_postgres_loader
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def test_jinja_postgres_loader(self):
# path used for the device_type template
jinja2_path = os.path.realpath(os.path.join(__file__, '..', '..', '..', 'etc', 'dispatcher-config'))
self.assertTrue(os.path.exists(jinja2_path))
device_type = 'cubietruck'
# pretend this was already imported into the database and use for comparison later.
device_dictionary = {
'usb_label': 'SanDisk_Ultra',
'sata_label': 'ST160LM003',
'usb_uuid': "usb-SanDisk_Ultra_20060775320F43006019-0:0",
'sata_uuid': "ata-ST160LM003_HN-M160MBB_S2SYJ9KC102184",
'connection_command': 'telnet localhost 6002'
}
# create a DeviceDictionary for this test
cubie = DeviceDictionary(hostname='cubie')
cubie.parameters = device_dictionary
cubie.save()
dict_loader = jinja2.DictLoader(
{
'cubie.yaml':
devicedictionary_to_jinja2(cubie.parameters, '%s.yaml' % device_type)
}
)
type_loader = jinja2.FileSystemLoader([os.path.join(jinja2_path, 'device-types')])
env = jinja2.Environment(
loader=jinja2.ChoiceLoader([dict_loader, type_loader]),
trim_blocks=True)
template = env.get_template("%s.yaml" % 'cubie')
device_configuration = template.render()
yaml_data = yaml.load(device_configuration)
self.assertIn('timeouts', yaml_data)
self.assertIn('parameters', yaml_data)
self.assertIn('bootz', yaml_data['parameters'])
self.assertIn('media', yaml_data['parameters'])
self.assertIn('usb', yaml_data['parameters']['media'])
self.assertIn(device_dictionary['usb_label'], yaml_data['parameters']['media']['usb'])
self.assertIn('uuid', yaml_data['parameters']['media']['usb'][device_dictionary['usb_label']])
self.assertEqual(
yaml_data['parameters']['media']['usb'][device_dictionary['usb_label']]['uuid'],
device_dictionary['usb_uuid']
)
self.assertIn('commands', yaml_data)
self.assertIn('connect', yaml_data['commands'])
self.assertEqual(
device_dictionary['connection_command'],
yaml_data['commands']['connect'])
device = PipelineDevice(yaml_data, 'cubie')
self.assertIn('power_state', device)
# cubie1 has no power_on_command defined
self.assertEqual(device.power_state, '')
self.assertTrue(hasattr(device, 'power_state'))
self.assertFalse(hasattr(device, 'hostname'))
self.assertIn('hostname', device)
示例10: setUp
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def setUp(self):
super(VlanInterfaces, self).setUp()
# YAML, pipeline only
user = User.objects.create_user('test', '[email protected]', 'test')
user.user_permissions.add(
Permission.objects.get(codename='add_testjob'))
user.save()
bbb_type = self.factory.make_device_type('beaglebone-black')
bbb_1 = self.factory.make_device(hostname='bbb-01', device_type=bbb_type)
device_dict = DeviceDictionary.get(bbb_1.hostname)
self.assertIsNone(device_dict)
device_dict = DeviceDictionary(hostname=bbb_1.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()
ct_type = self.factory.make_device_type('cubietruck')
cubie = self.factory.make_device(hostname='ct-01', device_type=ct_type)
device_dict = DeviceDictionary.get(cubie.hostname)
self.assertIsNone(device_dict)
device_dict = DeviceDictionary(hostname=cubie.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()
self.filename = os.path.join(os.path.dirname(__file__), 'bbb-cubie-vlan-group.yaml')
示例11: test_host_role
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def test_host_role(self):
# need a full job to properly test the multinode YAML split
hostname = 'fakeqemu3'
self.factory.make_device(self.device_type, hostname)
device_dict = DeviceDictionary(hostname=hostname)
device_dict.parameters = self.conf
device_dict.save()
# create a new device to allow the submission to reach the multinode YAML test.
hostname = 'fakeqemu4'
self.factory.make_device(self.device_type, hostname)
data = yaml.load(self.factory.make_job_json())
data['protocols']['lava-multinode']['roles']['host']['count'] = 2
self.assertRaises(
SubmissionException, TestJob.from_yaml_and_user,
yaml.dump(data), self.factory.make_user())
示例12: handle
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def handle(self, *args, **options):
"""
Accept options via lava-server manage which provides access
to the database.
"""
hostname = options['hostname']
if hostname is None:
self.stderr.write("Please specify a hostname")
sys.exit(2)
if options['import'] is not None:
data = parse_template(options['import'])
element = DeviceDictionary.get(hostname)
if element is None:
self.stdout.write("Adding new device dictionary for %s" %
hostname)
element = DeviceDictionary(hostname=hostname)
element.hostname = hostname
element.parameters = data
element.save()
self.stdout.write("Device dictionary updated for %s" % hostname)
elif options['export'] is not None or options['review'] is not None:
element = DeviceDictionary.get(hostname)
data = None
if element is None:
self.stderr.write("Unable to export - no dictionary found for '%s'" %
hostname)
sys.exit(2)
else:
data = devicedictionary_to_jinja2(
element.parameters,
element.parameters['extends']
)
if options['review'] is None:
self.stdout.write(data)
else:
template = prepare_jinja_template(hostname, data, system_path=False, path=options['path'])
device_configuration = template.render()
# validate against the device schema
try:
validate_device(yaml.load(device_configuration))
except (yaml.YAMLError, SubmissionException) as exc:
self.stderr.write("Invalid template: %s" % exc)
self.stdout.write(device_configuration)
else:
self.stderr.write("Please specify one of --import, --export or --review")
sys.exit(1)
示例13: test_dictionary_remove
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def test_dictionary_remove(self):
foo = DeviceDictionary(hostname='foo')
foo.parameters = {
'bootz': {
'kernel': '0x4700000',
'ramdisk': '0x4800000',
'dtb': '0x4300000'
},
}
foo.save()
baz = DeviceDictionary.get('foo')
self.assertEqual(baz.parameters, foo.parameters)
baz.delete()
self.assertIsInstance(baz, DeviceDictionary)
baz = DeviceDictionary.get('foo')
self.assertIsNone(baz)
示例14: test_exclusivity
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def test_exclusivity(self):
device = Device.objects.get(hostname="fakeqemu1")
self.assertTrue(device.is_pipeline)
self.assertFalse(device.is_exclusive)
self.assertIsNotNone(DeviceDictionary.get(device.hostname))
device_dict = DeviceDictionary(hostname=device.hostname)
device_dict.save()
device_dict = DeviceDictionary.get(device.hostname)
self.assertTrue(device.is_pipeline)
self.assertFalse(device.is_exclusive)
update = device_dict.to_dict()
update.update({'exclusive': 'True'})
device_dict.parameters = update
device_dict.save()
self.assertTrue(device.is_pipeline)
self.assertTrue(device.is_exclusive)
示例15: handle
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import parameters [as 别名]
def handle(self, *args, **options):
"""
Accept options via lava-server manage which provides access
to the database.
"""
hostname = options['hostname']
if hostname is None:
self.stderr.write("Please specify a hostname")
sys.exit(2)
if options['import'] is not None:
data = parse_template(options['import'])
element = DeviceDictionary.get(hostname)
if element is None:
self.stdout.write("Adding new device dictionary for %s" %
hostname)
element = DeviceDictionary(hostname=hostname)
element.hostname = hostname
element.parameters = data
element.save()
self.stdout.write("Device dictionary updated for %s" % hostname)
elif options['export'] is not None or options['review'] is not None:
element = DeviceDictionary.get(hostname)
data = None
if element is None:
self.stderr.write("Unable to export - no dictionary found for '%s'" %
hostname)
sys.exit(2)
else:
data = devicedictionary_to_jinja2(
element.parameters,
element.parameters['extends']
)
if options['review'] is None:
self.stdout.write(data)
else:
string_loader = jinja2.DictLoader({'%s.yaml' % hostname: data})
type_loader = jinja2.FileSystemLoader([
os.path.join(options['path'], 'device-types')])
env = jinja2.Environment(
loader=jinja2.ChoiceLoader([string_loader, type_loader]),
trim_blocks=True)
template = env.get_template("%s.yaml" % hostname)
device_configuration = template.render()
self.stdout.write(device_configuration)
else:
self.stderr.write("Please specify one of --import, --export or --review")
sys.exit(1)