本文整理汇总了Python中lava_scheduler_app.models.DeviceDictionary.get方法的典型用法代码示例。如果您正苦于以下问题:Python DeviceDictionary.get方法的具体用法?Python DeviceDictionary.get怎么用?Python DeviceDictionary.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lava_scheduler_app.models.DeviceDictionary
的用法示例。
在下文中一共展示了DeviceDictionary.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_vlan_interface
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [as 别名]
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))
示例2: handle
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [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)
示例3: test_menu_context
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [as 别名]
def test_menu_context(self):
job_ctx = {
'menu_early_printk': '',
'menu_interrupt_prompt': 'Default boot will start in'
}
hostname = self.factory.make_fake_mustang_device()
device_dict = DeviceDictionary.get(hostname)
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['actions']['boot']['methods']['uefi-menu']['nfs'])
menu_data = config['actions']['boot']['methods']['uefi-menu']
# assert that menu_interrupt_prompt replaces the default 'The default boot selection will start in'
self.assertEqual(
menu_data['parameters']['interrupt_prompt'],
job_ctx['menu_interrupt_prompt']
)
# assert that menu_early_printk replaces the default earlyprintk default
self.assertEqual(
[e for e in menu_data['nfs'] if 'enter' in e['select'] and 'new Entry' in e['select']['wait']][0]['select']['enter'],
'console=ttyS0,115200 debug root=/dev/nfs rw nfsroot={NFS_SERVER_IP}:{NFSROOTFS},tcp,hard,intr ip=dhcp'
)
示例4: test_dictionary_remove
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [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)
示例5: match_vlan_interface
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [as 别名]
def match_vlan_interface(device, job_def):
if not isinstance(job_def, dict):
raise RuntimeError("Invalid vlan interface data")
if 'protocols' not in job_def or 'lava-vland' not in job_def['protocols']:
return False
interfaces = []
logger = logging.getLogger('dispatcher-master')
device_dict = DeviceDictionary.get(device.hostname).to_dict()
if 'tags' not in device_dict['parameters']:
logger.error("%s has no tags in the device dictionary parameters", device.hostname)
return False
for vlan_name in job_def['protocols']['lava-vland']:
tag_list = job_def['protocols']['lava-vland'][vlan_name]['tags']
for interface, tags in device_dict['parameters']['tags'].iteritems():
logger.info(
"Job requests %s for %s, device %s provides %s for %s",
tag_list, vlan_name, device.hostname, tags, interface)
# tags & job tags must equal job tags
# device therefore must support all job tags, not all job tags available on the device need to be specified
if set(tags) & set(tag_list) == set(tag_list) and interface not in interfaces:
logger.info("Matched vlan %s to interface %s on %s", vlan_name, interface, device)
interfaces.append(interface)
# matched, do not check any further interfaces of this device for this vlan
break
logger.info("Matched: %s" % (len(interfaces) == len(job_def['protocols']['lava-vland'].keys())))
return len(interfaces) == len(job_def['protocols']['lava-vland'].keys())
示例6: test_exclusivity
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [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)
示例7: handle
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [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)
示例8: test_vland_jinja2
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [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)
示例9: test_new_dictionary
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [as 别名]
def test_new_dictionary(self):
foo = JobPipeline.get('foo')
self.assertIsNone(foo)
foo = DeviceDictionary(hostname='foo')
foo.save()
self.assertEqual(foo.hostname, 'foo')
self.assertIsInstance(foo, DeviceDictionary)
foo = DeviceDictionary.get('foo')
self.assertIsNotNone(foo)
示例10: setUp
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [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: export_device_dictionary
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [as 别名]
def export_device_dictionary(self, hostname):
"""
Name
----
`export_device_dictionary` (`device_hostname`)
Description
-----------
[superuser only]
Export the device dictionary key value store for a
pipeline device.
See also get_pipeline_device_config
Arguments
---------
`device_hostname`: string
Device hostname to update.
Return value
------------
This function returns an XML-RPC binary data of output file.
"""
self._authenticate()
if not self.user.is_superuser:
raise xmlrpclib.Fault(
403, "User '%s' is not superuser." % self.user.username
)
try:
device = Device.objects.get(hostname=hostname)
except DeviceType.DoesNotExist:
raise xmlrpclib.Fault(
404, "Device '%s' was not found." % hostname
)
if not device.is_pipeline:
raise xmlrpclib.Fault(
400, "Device '%s' is not a pipeline device" % hostname
)
device_dict = DeviceDictionary.get(hostname)
if not device_dict:
raise xmlrpclib.Fault(
404, "Device '%s' does not have a device dictionary" % hostname
)
device_dict = device_dict.to_dict()
jinja_str = devicedictionary_to_jinja2(device_dict['parameters'], device_dict['parameters']['extends'])
return xmlrpclib.Binary(jinja_str.encode('UTF-8'))
示例12: test_from_json_rejects_exclusive
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [as 别名]
def test_from_json_rejects_exclusive(self):
panda_type = self.factory.ensure_device_type(name='panda')
panda_board = self.factory.make_device(device_type=panda_type, hostname='panda01')
self.assertFalse(panda_board.is_exclusive)
job = TestJob.from_json_and_user(
self.factory.make_job_json(device_type='panda'),
self.factory.make_user())
self.assertEqual(panda_type, job.requested_device_type)
device_dict = DeviceDictionary.get(panda_board.hostname)
self.assertIsNone(device_dict)
device_dict = DeviceDictionary(hostname=panda_board.hostname)
device_dict.parameters = {'exclusive': 'True'}
device_dict.save()
self.assertTrue(panda_board.is_exclusive)
self.assertRaises(
DevicesUnavailableException, _check_exclusivity, [panda_board], pipeline=False
)
示例13: match_vlan_interface
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [as 别名]
def match_vlan_interface(device, job_def):
if not isinstance(job_def, dict):
raise RuntimeError("Invalid vlan interface data")
if 'protocols' not in job_def or 'lava-vland' not in job_def['protocols']:
return False
interfaces = []
logger = logging.getLogger('lava_scheduler_app')
for vlan_name in job_def['protocols']['lava-vland']:
tag_list = job_def['protocols']['lava-vland'][vlan_name]['tags']
device_dict = DeviceDictionary.get(device.hostname).to_dict()
if 'tags' not in device_dict['parameters']:
return False
for interface, tags in device_dict['parameters']['tags'].iteritems():
if any(set(tags).intersection(tag_list)) and interface not in interfaces:
logger.debug("Matched vlan %s to interface %s on %s", vlan_name, interface, device)
interfaces.append(interface)
# matched, do not check any further interfaces of this device for this vlan
break
return len(interfaces) == len(job_def['protocols']['lava-vland'].keys())
示例14: get_pipeline_device_config
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [as 别名]
def get_pipeline_device_config(self, device_hostname):
"""
Name
----
`get_pipeline_device_config` (`device_hostname`)
Description
-----------
Get the pipeline device configuration for given device hostname.
Arguments
---------
`device_hostname`: string
Device hostname for which the configuration is required.
Return value
------------
This function returns an XML-RPC binary data of output file.
"""
if not device_hostname:
raise xmlrpclib.Fault(400, "Bad request: Device hostname was not "
"specified.")
element = DeviceDictionary.get(device_hostname)
if element is None:
raise xmlrpclib.Fault(404, "Specified device not found.")
data = devicedictionary_to_jinja2(element.parameters,
element.parameters['extends'])
string_loader = jinja2.DictLoader({'%s.yaml' % device_hostname: data})
type_loader = jinja2.FileSystemLoader(
[os.path.join(jinja_template_path(), 'device-types')])
env = jinja2.Environment(loader=jinja2.ChoiceLoader([string_loader,
type_loader]),
trim_blocks=True)
template = env.get_template("%s.yaml" % device_hostname)
device_configuration = template.render()
return xmlrpclib.Binary(device_configuration.encode('UTF-8'))
示例15: test_find_nonexclusive_device
# 需要导入模块: from lava_scheduler_app.models import DeviceDictionary [as 别名]
# 或者: from lava_scheduler_app.models.DeviceDictionary import get [as 别名]
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)