def test_docker_template(self): data = "{% extends 'docker.jinja2' %}" self.assertTrue(self.validate_data('docker-01', data)) template_dict = prepare_jinja_template('docker-01', data, raw=False) self.assertEqual({'docker': None}, template_dict['actions']['deploy']['methods']) self.assertEqual({'docker': {'options': {'cpus': 0.0, 'memory': 0, 'devices': [], 'volumes': []}}}, template_dict['actions']['boot']['methods']) data = """{% extends 'docker.jinja2' %} {% set docker_cpus=2.1 %} {% set docker_memory="120M" %} {% set docker_volumes=["/home", "/tmp"] %}""" self.assertTrue(self.validate_data('docker-01', data)) template_dict = prepare_jinja_template('docker-01', data, raw=False) self.assertEqual({'docker': None}, template_dict['actions']['deploy']['methods']) self.assertEqual({'docker': {'options': {'cpus': 2.1, 'memory': "120M", 'devices': [], 'volumes': ["/home", "/tmp"]}}}, template_dict['actions']['boot']['methods']) data = """{% extends 'docker.jinja2' %} {% set docker_cpus=2.1 %} {% set docker_memory="120M" %} {% set docker_devices=["/dev/kvm"] %}""" self.assertTrue(self.validate_data('docker-01', data)) template_dict = prepare_jinja_template('docker-01', data, raw=False) self.assertEqual({'docker': None}, template_dict['actions']['deploy']['methods']) self.assertEqual({'docker': {'options': {'cpus': 2.1, 'memory': "120M", 'devices': ["/dev/kvm"], 'volumes': []}}}, template_dict['actions']['boot']['methods'])
def test_beaglebone_black_template(self): data = """{% extends 'beaglebone-black.jinja2' %} {% set map = {'eth0': {'lngswitch03': 19}, 'eth1': {'lngswitch03': 8}} %} {% set hard_reset_command = '/usr/bin/pduclient --daemon localhost --hostname lngpdu01 --command reboot --port 19' %} {% set tags = {'eth0': ['1G', '100M'], 'eth1': ['100M']} %} {% set interfaces = ['eth0', 'eth1'] %} {% set sysfs = {'eth0': '/sys/devices/platform/ocp/4a100000.ethernet/net/eth0', 'eth1': '/sys/devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.0/net/eth1'} %} {% set power_off_command = '/usr/bin/pduclient --daemon localhost --hostname lngpdu01 --command off --port 19' %} {% set mac_addr = {'eth0': '90:59:af:5e:69:fd', 'eth1': '00:e0:4c:53:44:58'} %} {% set power_on_command = '/usr/bin/pduclient --daemon localhost --hostname lngpdu01 --command on --port 19' %} {% set connection_command = 'telnet localhost 7333' %}""" self.assertTrue(self.validate_data("staging-bbb-01", data)) template_dict = prepare_jinja_template("staging-bbb-01", data, raw=False) self.assertIsNotNone( template_dict["actions"]["deploy"]["methods"]["ssh"]["host"]) self.assertEqual( "", template_dict["actions"]["deploy"]["methods"]["ssh"]["host"]) self.assertNotEqual( "None", template_dict["actions"]["deploy"]["methods"]["ssh"]["host"]) data += "{% set ssh_host = '192.168.0.10' %}" template_dict = prepare_jinja_template("staging-bbb-01", data, raw=False) self.assertIsNotNone( template_dict["actions"]["deploy"]["methods"]["ssh"]["host"]) self.assertEqual( "192.168.0.10", template_dict["actions"]["deploy"]["methods"]["ssh"]["host"])
def test_extra_nfs_opts(self): data = """{% extends 'panda.jinja2' %} {% set connection_command = 'telnet serial4 7012' %} {% set hard_reset_command = '/usr/bin/pduclient --daemon staging-master --hostname pdu15 --command reboot --port 05' %} {% set power_off_command = '/usr/bin/pduclient --daemon staging-master --hostname pdu15 --command off --port 05' %} {% set power_on_command = '/usr/bin/pduclient --daemon staging-master --hostname pdu15 --command on --port 05' %}""" job_ctx = {} template_dict = prepare_jinja_template("staging-panda-01", data, job_ctx=job_ctx, raw=False) for line in template_dict["actions"]["boot"]["methods"]["u-boot"][ "nfs"]["commands"]: if line.startswith("setenv nfsargs"): self.assertIn(",tcp,hard,intr ", line) self.assertNotIn("nfsvers", line) job_ctx = {"extra_nfsroot_args": ",nolock,nfsvers=3"} template_dict = prepare_jinja_template("staging-panda-01", data, job_ctx=job_ctx, raw=False) for line in template_dict["actions"]["boot"]["methods"]["u-boot"][ "nfs"]["commands"]: if line.startswith("setenv nfsargs"): self.assertIn(",tcp,hard,intr,nolock,nfsvers=3 ", line) commands = template_dict["actions"]["boot"]["methods"]["u-boot"][ "ramdisk"]["commands"] checked = False for line in commands: if "setenv initrd_high" in line: checked = True self.assertTrue(checked)
def test_extra_nfs_opts(self): data = """{% extends 'panda.jinja2' %} {% set connection_command = 'telnet serial4 7012' %} {% set hard_reset_command = '/usr/bin/pduclient --daemon staging-master --hostname pdu15 --command reboot --port 05' %} {% set power_off_command = '/usr/bin/pduclient --daemon staging-master --hostname pdu15 --command off --port 05' %} {% set power_on_command = '/usr/bin/pduclient --daemon staging-master --hostname pdu15 --command on --port 05' %}""" job_ctx = {} template_dict = prepare_jinja_template('staging-panda-01', data, job_ctx=job_ctx, raw=False) for line in template_dict['actions']['boot']['methods']['u-boot'][ 'nfs']['commands']: if line.startswith("setenv nfsargs"): self.assertIn(',tcp,hard,intr ', line) self.assertNotIn('nfsvers', line) job_ctx = {'extra_nfsroot_args': ',nolock,nfsvers=3'} template_dict = prepare_jinja_template('staging-panda-01', data, job_ctx=job_ctx, raw=False) for line in template_dict['actions']['boot']['methods']['u-boot'][ 'nfs']['commands']: if line.startswith("setenv nfsargs"): self.assertIn(',tcp,hard,intr,nolock,nfsvers=3 ', line) commands = template_dict['actions']['boot']['methods']['u-boot'][ 'ramdisk']['commands'] checked = False for line in commands: if 'setenv initrd_high' in line: checked = True self.assertTrue(checked)
def test_x86_interface_template(self): # test boot interface override data = """{% extends 'x86.jinja2' %} {% set power_off_command = '/usr/bin/pduclient --daemon localhost --port 02 --hostname lngpdu01 --command off' %} {% set hard_reset_command = '/usr/bin/pduclient --daemon localhost --port 02 --hostname lngpdu01 --command reboot' %} {% set power_on_command = '/usr/bin/pduclient --daemon localhost --port 02 --hostname lngpdu01 --command on' %} {% set connection_command = 'telnet localhost 7302' %}""" self.assertTrue(self.validate_data('staging-x86-01', data)) template_dict = prepare_jinja_template('staging-x86-01', data, raw=False) for _, value in template_dict['actions']['boot']['methods'][ 'ipxe'].items(): if 'commands' in value: self.assertIn('dhcp net0', value['commands']) self.assertNotIn('dhcp net1', value['commands']) # test boot interface override data = """{% extends 'x86.jinja2' %} {% set boot_interface = 'net1' %} {% set power_off_command = '/usr/bin/pduclient --daemon localhost --port 02 --hostname lngpdu01 --command off' %} {% set hard_reset_command = '/usr/bin/pduclient --daemon localhost --port 02 --hostname lngpdu01 --command reboot' %} {% set power_on_command = '/usr/bin/pduclient --daemon localhost --port 02 --hostname lngpdu01 --command on' %} {% set connection_command = 'telnet localhost 7302' %}""" self.assertTrue(self.validate_data('staging-x86-01', data)) template_dict = prepare_jinja_template('staging-x86-01', data, raw=False) for _, value in template_dict['actions']['boot']['methods'][ 'ipxe'].items(): if 'commands' in value: self.assertIn('dhcp net1', value['commands']) self.assertNotIn('dhcp net0', value['commands'])
def test_hikey960_grub(self): with open( os.path.join(os.path.dirname(__file__), "devices", "hi960-hikey-01.jinja2")) as hikey: data = hikey.read() self.assertIsNotNone(data) job_ctx = {"kernel": "Image", "devicetree": "hi960-hikey.dtb"} # self.assertTrue(self.validate_data('hi960-hikey-01', data)) template_dict = prepare_jinja_template("staging-hikey-01", data, job_ctx=job_ctx, raw=False) self.assertIsNotNone(template_dict) self.assertIsNotNone(template_dict["actions"]["boot"]["methods"]) self.assertNotIn("menu_options", template_dict["actions"]["boot"]["methods"]["grub"]) self.assertIn("grub", template_dict["actions"]["boot"]["methods"]) params = template_dict["actions"]["boot"]["methods"]["grub"] for command in params["installed"]["commands"]: self.assertEqual("boot", command) self.assertIn("ssh", template_dict["actions"]["deploy"]["methods"]) params = template_dict["actions"]["deploy"]["methods"]["ssh"] self.assertIsNotNone(params) self.assertIn("port", params) self.assertIn("user", params) self.assertIn("options", params) self.assertIn("identity_file", params) # test support for retreiving MAC from device using base-fastboot. data += "{% set device_mac = '00:E0:4C:53:44:58' %}" self.assertTrue(self.validate_data("hi6220-hikey-01", data)) template_dict = prepare_jinja_template("staging-hikey-01", data, job_ctx=None, raw=False) self.assertIn("parameters", template_dict) self.assertIn("interfaces", template_dict["parameters"]) self.assertIn("target", template_dict["parameters"]["interfaces"]) self.assertIn("mac", template_dict["parameters"]["interfaces"]["target"]) self.assertIn("ip", template_dict["parameters"]["interfaces"]["target"]) self.assertIsNotNone( template_dict["parameters"]["interfaces"]["target"]["mac"]) self.assertNotEqual( "", template_dict["parameters"]["interfaces"]["target"]["mac"]) self.assertEqual( "00:E0:4C:53:44:58", template_dict["parameters"]["interfaces"]["target"]["mac"], ) self.assertIsNone( template_dict["parameters"]["interfaces"]["target"]["ip"])
def test_hikey960_grub(self): with open( os.path.join(os.path.dirname(__file__), 'devices', 'hi960-hikey-01.jinja2')) as hikey: data = hikey.read() self.assertIsNotNone(data) job_ctx = {'kernel': 'Image', 'devicetree': 'hi960-hikey.dtb'} # self.assertTrue(self.validate_data('hi960-hikey-01', data)) template_dict = prepare_jinja_template('staging-hikey-01', data, job_ctx=job_ctx, raw=False) self.assertIsNotNone(template_dict) self.assertIsNotNone(template_dict['actions']['boot']['methods']) self.assertNotIn('menu_options', template_dict['actions']['boot']['methods']['grub']) self.assertIn('grub', template_dict['actions']['boot']['methods']) params = template_dict['actions']['boot']['methods']['grub'] for command in params['installed']['commands']: self.assertEqual('boot', command) self.assertIn('ssh', template_dict['actions']['deploy']['methods']) params = template_dict['actions']['deploy']['methods']['ssh'] self.assertIsNotNone(params) self.assertIn('port', params) self.assertIn('user', params) self.assertIn('options', params) self.assertIn('identity_file', params) # test support for retreiving MAC from device using base-fastboot. data += "{% set device_mac = '00:E0:4C:53:44:58' %}" self.assertTrue(self.validate_data('hi6220-hikey-01', data)) template_dict = prepare_jinja_template('staging-hikey-01', data, job_ctx=None, raw=False) self.assertIn('parameters', template_dict) self.assertIn('interfaces', template_dict['parameters']) self.assertIn('target', template_dict['parameters']['interfaces']) self.assertIn('mac', template_dict['parameters']['interfaces']['target']) self.assertIn('ip', template_dict['parameters']['interfaces']['target']) self.assertIsNotNone( template_dict['parameters']['interfaces']['target']['mac']) self.assertNotEqual( '', template_dict['parameters']['interfaces']['target']['mac']) self.assertEqual( '00:E0:4C:53:44:58', template_dict['parameters']['interfaces']['target']['mac']) self.assertIsNone( template_dict['parameters']['interfaces']['target']['ip'])
def test_qemu_cortex_a57_nfs(self): data = """{% extends 'qemu.jinja2' %} {% set memory = 2048 %} {% set mac_addr = '52:54:00:12:34:59' %} {% set arch = 'arm64' %} {% set base_guest_fs_size = 2048 %} """ job_ctx = { 'arch': 'amd64', 'qemu_method': 'qemu-nfs', 'netdevice': 'tap', 'extra_options': ['-smp', 1] } self.assertTrue(self.validate_data('staging-qemu-01', data)) template_dict = prepare_jinja_template('staging-juno-01', data, job_ctx=job_ctx, raw=False) self.assertIn('qemu-nfs', template_dict['actions']['boot']['methods']) params = template_dict['actions']['boot']['methods']['qemu-nfs']['parameters'] self.assertIn('command', params) self.assertEqual(params['command'], 'qemu-system-aarch64') self.assertIn('options', params) self.assertIn('-cpu cortex-a57', params['options']) self.assertEqual('qemu-system-aarch64', params['command']) self.assertIn('-smp', params['extra']) self.assertIn('append', params) self.assertIn('nfsrootargs', params['append']) self.assertEqual(params['append']['root'], '/dev/nfs') self.assertEqual(params['append']['console'], 'ttyAMA0')
def test_mustang_grub_efi_template(self): data = """{% extends 'mustang-grub-efi.jinja2' %} {% set grub_efi_method = 'grub' %} {% set hard_reset_command = '/usr/bin/pduclient --daemon services --hostname pdu09 --command reboot --port 05' %} {% set power_off_command = '/usr/bin/pduclient --daemon services --hostname pdu09 --command off --port 05' %} {% set power_on_command = '/usr/bin/pduclient --daemon services --hostname pdu09 --command on --port 05' %} {% set connection_command = 'telnet localhost 7012' %}""" self.assertTrue(self.validate_data("staging-mustang-01", data)) template_dict = prepare_jinja_template("staging-mustang-01", data, raw=False) self.assertIn("uefi-menu", template_dict["actions"]["boot"]["methods"]) self.assertNotIn( "pxe-grub", template_dict["actions"]["boot"]["methods"]["uefi-menu"] ) self.assertIn("grub", template_dict["actions"]["boot"]["methods"]["uefi-menu"]) self.assertEqual( template_dict["actions"]["boot"]["methods"]["grub-efi"]["menu_options"], "grub", ) self.assertIn( "ramdisk", template_dict["actions"]["boot"]["methods"]["grub-efi"] ) self.assertIn( "commands", template_dict["actions"]["boot"]["methods"]["grub-efi"]["ramdisk"], ) self.assertIn("nfs", template_dict["actions"]["boot"]["methods"]["grub-efi"]) self.assertIn( "commands", template_dict["actions"]["boot"]["methods"]["grub-efi"]["nfs"] ) nfs_commands = template_dict["actions"]["boot"]["methods"]["grub-efi"]["nfs"][ "commands" ] self.assertIn("insmod efinet", nfs_commands) self.assertIn("net_bootp", nfs_commands)
def test_recovery_mode(self): with open( os.path.join( os.path.dirname(__file__), "devices", "hi6220-hikey-bl-01.jinja2" ) ) as hikey: data = hikey.read() self.assertTrue(self.validate_data("hi620-bl-01", data)) template_dict = prepare_jinja_template("hi620-bl-01", data, raw=False) recovery = template_dict["actions"]["deploy"]["methods"] self.assertIsNotNone("recovery", recovery) self.assertIn("recovery", recovery) self.assertIn("commands", recovery["recovery"]) self.assertIsNotNone("recovery", recovery["recovery"]["commands"]) self.assertIn("recovery_mode", recovery["recovery"]["commands"]) self.assertEqual( [ "/home/neil/lava-lab/shared/lab-scripts/eth008_control -a 10.15.0.171 -r 1 -s off", "/home/neil/lava-lab/shared/lab-scripts/eth008_control -a 10.15.0.171 -r 2 -s on", ], recovery["recovery"]["commands"]["recovery_mode"], ) self.assertIn("recovery_exit", recovery["recovery"]["commands"]) self.assertEqual( [ "/home/neil/lava-lab/shared/lab-scripts/eth008_control -a 10.15.0.171 -r 1 -s on", "/home/neil/lava-lab/shared/lab-scripts/eth008_control -a 10.15.0.171 -r 2 -s off", ], recovery["recovery"]["commands"]["recovery_exit"], )
def test_b2260_template(self): data = """{% extends 'b2260.jinja2' %}""" self.assertTrue(self.validate_data("staging-b2260-01", data)) template_dict = prepare_jinja_template("staging-b2260-01", data, raw=False) self.assertEqual( {"seconds": 15}, template_dict["timeouts"]["actions"]["power-off"] )
def test_mustang_grub_efi_template(self): data = """{% extends 'mustang-grub-efi.jinja2' %} {% set grub_efi_method = 'grub' %} {% set hard_reset_command = '/usr/bin/pduclient --daemon services --hostname pdu09 --command reboot --port 05' %} {% set power_off_command = '/usr/bin/pduclient --daemon services --hostname pdu09 --command off --port 05' %} {% set power_on_command = '/usr/bin/pduclient --daemon services --hostname pdu09 --command on --port 05' %} {% set connection_command = 'telnet localhost 7012' %}""" self.assertTrue(self.validate_data('staging-mustang-01', data)) template_dict = prepare_jinja_template('staging-mustang-01', data, raw=False) self.assertIn('uefi-menu', template_dict['actions']['boot']['methods']) self.assertNotIn( 'pxe-grub', template_dict['actions']['boot']['methods']['uefi-menu']) self.assertIn('grub', template_dict['actions']['boot']['methods']['uefi-menu']) self.assertEqual( template_dict['actions']['boot']['methods']['grub-efi'] ['menu_options'], 'grub') self.assertIn('ramdisk', template_dict['actions']['boot']['methods']['grub-efi']) self.assertIn( 'commands', template_dict['actions']['boot']['methods']['grub-efi']['ramdisk']) self.assertIn('nfs', template_dict['actions']['boot']['methods']['grub-efi']) self.assertIn( 'commands', template_dict['actions']['boot']['methods']['grub-efi']['nfs']) nfs_commands = template_dict['actions']['boot']['methods']['grub-efi'][ 'nfs']['commands'] self.assertIn('insmod efinet', nfs_commands) self.assertIn('net_bootp', nfs_commands)
def test_xilinx_zcu102(self): with open( os.path.join(os.path.dirname(__file__), "devices", "zcu102.jinja2")) as zcu: data = zcu.read() self.assertTrue(self.validate_data("zcu-01", data)) template_dict = prepare_jinja_template("zcu-01", data, raw=False) self.assertIn("u-boot", template_dict["actions"]["boot"]["methods"]) self.assertIn("ramdisk", template_dict["actions"]["boot"]["methods"]["u-boot"]) commands = template_dict["actions"]["boot"]["methods"]["u-boot"][ "ramdisk"]["commands"] for command in commands: if not command.startswith("setenv loadkernel"): continue self.assertNotIn("tftp ", command) self.assertIn("tftpb", command) for command in commands: if not command.startswith("setenv bootargs"): continue self.assertNotIn("console=ttyS0,115200n8", command) self.assertNotIn("console=", command) self.assertNotIn("console=ttyO0", command) self.assertNotIn("115200n8", command) self.assertNotIn("n8", command)
def test_qemu_cortex_a57_nfs(self): data = """{% extends 'qemu.jinja2' %} {% set memory = 2048 %} {% set mac_addr = '52:54:00:12:34:59' %} {% set arch = 'arm64' %} {% set base_guest_fs_size = 2048 %} """ job_ctx = { "arch": "amd64", "qemu_method": "qemu-nfs", "netdevice": "tap", "extra_options": ["-smp", 1], } self.assertTrue(self.validate_data("staging-qemu-01", data)) template_dict = prepare_jinja_template("staging-juno-01", data, job_ctx=job_ctx, raw=False) self.assertIn("qemu-nfs", template_dict["actions"]["boot"]["methods"]) params = template_dict["actions"]["boot"]["methods"]["qemu-nfs"][ "parameters"] self.assertIn("command", params) self.assertEqual(params["command"], "qemu-system-aarch64") self.assertIn("options", params) self.assertIn("-cpu cortex-a57", params["options"]) self.assertEqual("qemu-system-aarch64", params["command"]) self.assertIn("-smp", params["extra"]) self.assertIn("append", params) self.assertIn("nfsrootargs", params["append"]) self.assertEqual(params["append"]["root"], "/dev/nfs") self.assertEqual(params["append"]["console"], "ttyAMA0")
def test_xilinx_zcu102(self): with open( os.path.join(os.path.dirname(__file__), 'devices', 'zcu102.jinja2')) as zcu: data = zcu.read() self.assertTrue(self.validate_data('zcu-01', data)) template_dict = prepare_jinja_template('zcu-01', data, raw=False) self.assertIn('u-boot', template_dict['actions']['boot']['methods']) self.assertIn('ramdisk', template_dict['actions']['boot']['methods']['u-boot']) commands = template_dict['actions']['boot']['methods']['u-boot'][ 'ramdisk']['commands'] for command in commands: if not command.startswith('setenv loadkernel'): continue self.assertNotIn('tftp ', command) self.assertIn('tftpb', command) for command in commands: if not command.startswith('setenv bootargs'): continue self.assertNotIn('console=ttyS0,115200n8', command) self.assertNotIn('console=', command) self.assertNotIn('console=ttyO0', command) self.assertNotIn('115200n8', command) self.assertNotIn('n8', command)
def test_armada375_template(self): """ Test the armada-375 template as if it was a device dictionary """ data = """ {% extends 'base-uboot.jinja2' %} {% set console_device = console_device|default('ttyS0') %} {% set baud_rate = baud_rate|default(115200) %} {% set bootloader_prompt = bootloader_prompt|default('Marvell>>') %} {% set bootm_kernel_addr = '0x02080000' %} {% set bootm_ramdisk_addr = '0x02880000' %} {% set bootm_dtb_addr = '0x02000000' %} {% set base_ip_args = 'ip=dhcp' %} {% set uboot_mkimage_arch = 'arm' %} {% set append_dtb = true %} {% set use_xip = true %} {% set uboot_bootx_cmd = "bootm {KERNEL_ADDR} {RAMDISK_ADDR}" %} """ self.assertTrue(self.validate_data('armada-375-01', data)) template_dict = prepare_jinja_template('armada-375-01', data, raw=False) params = template_dict['actions']['deploy']['parameters'] self.assertIsNotNone(params) self.assertIn('use_xip', params) self.assertIn('append_dtb', params) self.assertTrue(params['use_xip']) self.assertTrue(params['append_dtb']) params = template_dict['actions']['boot']['methods']['u-boot'][ 'ramdisk']['commands'] for line in params: if 'run loadkernel' in line: self.assertIn('bootm', line)
def test_armada375_template(self): """ Test the armada-375 template as if it was a device dictionary """ data = """ {% extends 'base-uboot.jinja2' %} {% set console_device = console_device|default('ttyS0') %} {% set baud_rate = baud_rate|default(115200) %} {% set bootloader_prompt = bootloader_prompt|default('Marvell>>') %} {% set bootm_kernel_addr = '0x02080000' %} {% set bootm_ramdisk_addr = '0x02880000' %} {% set bootm_dtb_addr = '0x02000000' %} {% set base_ip_args = 'ip=dhcp' %} {% set uboot_mkimage_arch = 'arm' %} {% set append_dtb = true %} {% set use_xip = true %} {% set uboot_bootx_cmd = "bootm {KERNEL_ADDR} {RAMDISK_ADDR}" %} """ self.assertTrue(self.validate_data("armada-375-01", data)) template_dict = prepare_jinja_template("armada-375-01", data, raw=False) params = template_dict["actions"]["deploy"]["parameters"] self.assertIsNotNone(params) self.assertIn("use_xip", params) self.assertIn("append_dtb", params) self.assertTrue(params["use_xip"]) self.assertTrue(params["append_dtb"]) params = template_dict["actions"]["boot"]["methods"]["u-boot"][ "ramdisk"]["commands"] for line in params: if "run loadkernel" in line: self.assertIn("bootm", line)
def test_panda_lxc_template(self): logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) logger = logging.getLogger("unittests") logger.disabled = True logger.propagate = False logger = logging.getLogger("dispatcher") logging.disable(logging.DEBUG) logger.disabled = True logger.propagate = False data = """{% extends 'panda.jinja2' %} {% set power_off_command = '/usr/local/lab-scripts/snmp_pdu_control --hostname pdu15 --command off --port 07' %} {% set hard_reset_command = '/usr/local/lab-scripts/snmp_pdu_control --hostname pdu15 --command reboot --port 07' %} {% set connection_command = 'telnet serial4 7010' %} {% set power_on_command = '/usr/local/lab-scripts/snmp_pdu_control --hostname pdu15 --command on --port 07' %}""" self.assertTrue(self.validate_data("staging-panda-01", data)) template_dict = prepare_jinja_template("staging-panda-01", data, raw=False) fdesc, device_yaml = tempfile.mkstemp() os.write(fdesc, yaml.dump(template_dict).encode()) panda = NewDevice(device_yaml) lxc_yaml = os.path.join( os.path.dirname(__file__), "sample_jobs", "panda-lxc-aep.yaml" ) with open(lxc_yaml) as sample_job_data: parser = JobParser() job = parser.parse(sample_job_data, panda, 4577, None, "") os.close(fdesc) job.logger = DummyLogger() job.logger.disabled = True job.logger.propagate = False job.validate()
def test_hikey620_uarts(self): with open( os.path.join(os.path.dirname(__file__), 'devices', 'hi6220-hikey-01.jinja2')) as hikey: data = hikey.read() self.assertIsNotNone(data) job_ctx = {} self.assertTrue(self.validate_data('hi6220-hikey-01', data)) template_dict = prepare_jinja_template('staging-hikey-01', data, job_ctx=job_ctx, raw=False) validate_device(template_dict) self.assertIsNotNone(template_dict) self.assertIn('commands', template_dict) self.assertNotIn('connect', template_dict['commands']) self.assertIn('connections', template_dict['commands']) self.assertIn('uart0', template_dict['commands']['connections']) self.assertIn('uart1', template_dict['commands']['connections']) self.assertIn('tags', template_dict['commands']['connections']['uart1']) self.assertIn( 'primary', template_dict['commands']['connections']['uart1']['tags']) self.assertNotIn('tags', template_dict['commands']['connections']['uart0']) self.assertEqual( template_dict['commands']['connections']['uart0']['connect'], 'telnet localhost 4002') self.assertEqual( template_dict['commands']['connections']['uart1']['connect'], 'telnet 192.168.1.200 8001')
def test_ethaddr(self): data = """{% extends 'b2260.jinja2' %} {% set hard_reset_command = '/usr/local/lab-scripts/snmp_pdu_control --port 14 --hostname pdu18 --command reboot' %} {% set power_off_command = '/usr/local/lab-scripts/snmp_pdu_control --port 14 --hostname pdu18 --command off' %} {% set connection_command = 'telnet localhost 7114' %} {% set power_on_command = '/usr/local/lab-scripts/snmp_pdu_control --port 14 --hostname pdu18 --command on' %} {% set uboot_mac_addr = '00:80:e1:12:81:30' %}""" self.assertTrue(self.validate_data("staging-b2260-01", data)) template_dict = prepare_jinja_template("staging-b2260-01", data, raw=False) ethaddr = False for command in template_dict["actions"]["boot"]["methods"]["u-boot"][ "ramdisk"]["commands"]: if command.startswith("setenv ethaddr"): self.assertEqual(command, "setenv ethaddr 00:80:e1:12:81:30") ethaddr = True self.assertTrue(ethaddr) ethaddr = False for command in template_dict["actions"]["boot"]["methods"]["u-boot"][ "nfs"]["commands"]: if command.startswith("setenv ethaddr"): self.assertEqual(command, "setenv ethaddr 00:80:e1:12:81:30") ethaddr = True self.assertTrue(ethaddr)
def test_juno_uboot_vland_template(self): data = """{% extends 'juno-uboot.jinja2' %} {% set map = {'iface0': {'lngswitch03': 19}, 'iface1': {'lngswitch03': 8}} %} {% set hard_reset_command = '/usr/local/lab-scripts/snmp_pdu_control --hostname lngpdu01 --command reboot --port 19' %} {% set tags = {'iface0': [], 'iface1': ['RJ45', '10M', '100M']} %} {% set interfaces = ['iface0', 'iface1'] %} {% set device_mac = '90:59:af:5e:69:fd' %} {% set sysfs = {'iface0': '/sys/devices/platform/ocp/4a100000.ethernet/net/', 'iface1': '/sys/devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.0/net/'} %} {% set power_off_command = '/usr/local/lab-scripts/snmp_pdu_control --hostname lngpdu01 --command off --port 19' %} {% set mac_addr = {'iface0': '90:59:af:5e:69:fd', 'iface1': '00:e0:4c:53:44:58'} %} {% set power_on_command = '/usr/local/lab-scripts/snmp_pdu_control --hostname lngpdu01 --command on --port 19' %} {% set connection_command = 'telnet localhost 7333' %}""" self.assertTrue(self.validate_data("staging-x86-01", data)) template_dict = prepare_jinja_template("staging-qemu-01", data, raw=False) self.assertIn("interfaces", template_dict["parameters"]) self.assertIn("iface0", template_dict["parameters"]["interfaces"]) self.assertIn("port", template_dict["parameters"]["interfaces"]["iface0"]) self.assertIn("target", template_dict["parameters"]["interfaces"]) self.assertIn("ip", template_dict["parameters"]["interfaces"]["target"]) self.assertIsNone( template_dict["parameters"]["interfaces"]["target"]["ip"]) self.assertIsNotNone( template_dict["parameters"]["interfaces"]["target"]["mac"])
def test_hikey620_uarts(self): with open( os.path.join(os.path.dirname(__file__), "devices", "hi6220-hikey-01.jinja2") ) as hikey: data = hikey.read() self.assertIsNotNone(data) job_ctx = {} self.assertTrue(self.validate_data("hi6220-hikey-01", data)) template_dict = prepare_jinja_template( "staging-hikey-01", data, job_ctx=job_ctx, raw=False ) validate_device(template_dict) self.assertIsNotNone(template_dict) self.assertIn("commands", template_dict) self.assertNotIn("connect", template_dict["commands"]) self.assertIn("connections", template_dict["commands"]) self.assertIn("uart0", template_dict["commands"]["connections"]) self.assertIn("uart1", template_dict["commands"]["connections"]) self.assertIn("tags", template_dict["commands"]["connections"]["uart1"]) self.assertIn( "primary", template_dict["commands"]["connections"]["uart1"]["tags"] ) self.assertNotIn("tags", template_dict["commands"]["connections"]["uart0"]) self.assertEqual( template_dict["commands"]["connections"]["uart0"]["connect"], "telnet localhost 4002", ) self.assertEqual( template_dict["commands"]["connections"]["uart1"]["connect"], "telnet 192.168.1.200 8001", )
def test_thunderx_template(self): data = """{% extends 'thunderx.jinja2' %} {% set map = {'iface0': {'lngswitch03': 13}, 'iface1': {'lngswitch03': 1}, 'iface2': {'lngswitch02': 9}, 'iface3': {'lngswitch02': 10}} %} {% set tags = {'iface0': [], 'iface1': ['RJ45', '1G', '10G'], 'iface2': ['SFP+', '1G', '10G'], 'iface3': ['SFP+', '1G', '10G']} %} {% set mac_addr = {'iface0': '00:00:1a:1b:8b:f6', 'iface1': '00:00:1a:1b:8b:f7', 'iface2': '00:11:0a:68:94:30', 'iface3': '00:11:0a:68:94:31'} %} {% set interfaces = ['iface0', 'iface1', 'iface2', 'iface3'] %} {% set sysfs = {'iface0': '/sys/devices/platform/AMDI8001:00/net/', 'iface1': '/sys/devices/platform/AMDI8001:01/net/', 'iface2': '/sys/devices/pci0000:00/0000:00:02.1/0000:01:00.0/net/', 'iface3': '/sys/devices/pci0000:00/0000:00:02.1/0000:01:00.1/net/'} %} {% set hard_reset_command = '/usr/bin/pduclient --daemon localhost --hostname lngpdu01 --command reboot --port 19' %} {% set power_off_command = '/usr/bin/pduclient --daemon localhost --hostname lngpdu01 --command off --port 19' %} {% set power_on_command = '/usr/bin/pduclient --daemon localhost --hostname lngpdu01 --command on --port 19' %} {% set connection_command = 'telnet localhost 7333' %}""" self.assertTrue(self.validate_data('staging-thunderx-01', data)) template_dict = prepare_jinja_template('staging-thunderx-01', data, raw=False) self.assertIn('character_delays', template_dict) self.assertIn('boot', template_dict['character_delays']) self.assertEqual(150, template_dict['character_delays']['boot']) self.assertIn('interfaces', template_dict['parameters']) self.assertIn('iface2', template_dict['parameters']['interfaces']) self.assertIn('iface1', template_dict['parameters']['interfaces']) self.assertIn('iface0', template_dict['parameters']['interfaces']) self.assertIn('sysfs', template_dict['parameters']['interfaces']['iface2'])
def test_panda_template(self): data = """{% extends 'panda.jinja2' %} {% set connection_command = 'telnet serial4 7012' %} {% set hard_reset_command = '/usr/bin/pduclient --daemon staging-master --hostname pdu15 --command reboot --port 05' %} {% set power_off_command = '/usr/bin/pduclient --daemon staging-master --hostname pdu15 --command off --port 05' %} {% set power_on_command = '/usr/bin/pduclient --daemon staging-master --hostname pdu15 --command on --port 05' %}""" self.assertTrue(self.validate_data("staging-panda-01", data)) context = {"extra_kernel_args": "intel_mmio=on mmio=on"} template_dict = prepare_jinja_template( "staging-panda-01", data, job_ctx=context, raw=False ) self.assertIn("bootloader-commands", template_dict["timeouts"]["actions"]) self.assertEqual( 180.0, Timeout.parse(template_dict["timeouts"]["actions"]["bootloader-commands"]), ) commands = template_dict["actions"]["boot"]["methods"]["u-boot"]["ramdisk"][ "commands" ] checked = False self.assertIsNotNone(commands) self.assertIsInstance(commands, list) self.assertIn("usb start", commands) for line in commands: if "setenv bootargs" in line: self.assertIn("console=ttyO2", line) self.assertIn(" " + context["extra_kernel_args"] + " ", line) checked = True self.assertTrue(checked) checked = False for line in commands: if "setenv initrd_high" in line: checked = True self.assertTrue(checked)
def test_b2260_template(self): data = """{% extends 'b2260.jinja2' %}""" self.assertTrue(self.validate_data('staging-b2260-01', data)) template_dict = prepare_jinja_template('staging-b2260-01', data, raw=False) self.assertEqual({'seconds': 15}, template_dict['timeouts']['actions']['power-off'])
def test_hikey_template(self): with open( os.path.join(os.path.dirname(__file__), "devices", "hi6220-hikey-01.jinja2")) as hikey: data = hikey.read() self.assertIsNotNone(data) self.assertTrue(self.validate_data("hi6220-hikey-01", data)) template_dict = prepare_jinja_template("staging-hikey-01", data, raw=False) self.assertIsNotNone(template_dict) self.assertIsInstance(template_dict["device_info"], list) self.assertIsInstance(template_dict["static_info"], list) self.assertEqual(template_dict["device_info"][0]["board_id"], "0123456789") self.assertEqual(template_dict["static_info"][0]["board_id"], "S_N0123456") self.assertIsInstance(template_dict["fastboot_options"], list) self.assertEqual(template_dict["fastboot_options"], ["-S", "256M"]) order = template_dict["flash_cmds_order"] self.assertEqual(0, order.index("ptable")) self.assertEqual(1, order.index("fastboot")) self.assertIn("cache", order) self.assertIn("system", order) self.assertIn("userdata", order) self.assertNotIn("xloader", order) # test support for retreiving MAC from device. data += "{% set device_mac = '00:E0:4C:53:44:58' %}" self.assertTrue(self.validate_data("hi6220-hikey-01", data)) template_dict = prepare_jinja_template("staging-hikey-01", data, raw=False) self.assertIn("parameters", template_dict) self.assertIn("interfaces", template_dict["parameters"]) self.assertIn("target", template_dict["parameters"]["interfaces"]) self.assertIn("mac", template_dict["parameters"]["interfaces"]["target"]) self.assertIn("ip", template_dict["parameters"]["interfaces"]["target"]) self.assertIsNotNone( template_dict["parameters"]["interfaces"]["target"]["mac"]) self.assertNotEqual( "", template_dict["parameters"]["interfaces"]["target"]["mac"]) self.assertIsNone( template_dict["parameters"]["interfaces"]["target"]["ip"])
def test_hikey_template(self): with open( os.path.join(os.path.dirname(__file__), 'devices', 'hi6220-hikey-01.jinja2')) as hikey: data = hikey.read() self.assertIsNotNone(data) self.assertTrue(self.validate_data('hi6220-hikey-01', data)) template_dict = prepare_jinja_template('staging-hikey-01', data, raw=False) self.assertIsNotNone(template_dict) self.assertIsInstance(template_dict['device_info'], list) self.assertIsInstance(template_dict['static_info'], list) self.assertEqual(template_dict['device_info'][0]['board_id'], '0123456789') self.assertEqual(template_dict['static_info'][0]['board_id'], 'S_N0123456') self.assertIsInstance(template_dict['fastboot_options'], list) self.assertEqual(template_dict['fastboot_options'], ['-S', '256M']) order = template_dict['flash_cmds_order'] self.assertEqual(0, order.index('ptable')) self.assertEqual(1, order.index('fastboot')) self.assertIn('cache', order) self.assertIn('system', order) self.assertIn('userdata', order) self.assertNotIn('xloader', order) # test support for retreiving MAC from device. data += "{% set device_mac = '00:E0:4C:53:44:58' %}" self.assertTrue(self.validate_data('hi6220-hikey-01', data)) template_dict = prepare_jinja_template('staging-hikey-01', data, raw=False) self.assertIn('parameters', template_dict) self.assertIn('interfaces', template_dict['parameters']) self.assertIn('target', template_dict['parameters']['interfaces']) self.assertIn('mac', template_dict['parameters']['interfaces']['target']) self.assertIn('ip', template_dict['parameters']['interfaces']['target']) self.assertIsNotNone( template_dict['parameters']['interfaces']['target']['mac']) self.assertNotEqual( '', template_dict['parameters']['interfaces']['target']['mac']) self.assertIsNone( template_dict['parameters']['interfaces']['target']['ip'])
def test_qemu_installer(self): data = """{% extends 'qemu.jinja2' %} {% set mac_addr = 'DE:AD:BE:EF:28:01' %} {% set memory = 512 %}""" job_ctx = {'arch': 'amd64'} template_dict = prepare_jinja_template('staging-qemu-01', data, job_ctx=job_ctx, raw=False) self.assertEqual( 'c', template_dict['actions']['boot']['methods']['qemu']['parameters']['boot_options']['boot_order'] )
def test_flasher(self): data = """{% extends 'b2260.jinja2' %} {% set flasher_deploy_commands = ['flashing', 'something --else'] %} """ self.assertTrue(self.validate_data("staging-b2260-01", data)) template_dict = prepare_jinja_template("staging-b2260-01", data, raw=False) self.assertEqual( ["flashing", "something --else"], template_dict["actions"]["deploy"]["methods"]["flasher"]["commands"], )
def test_db820c_template(self): data = """{% extends 'dragonboard-820c.jinja2' %} {% set adb_serial_number = '3083f595' %} {% set fastboot_serial_number = '3083f595' %} """ self.assertTrue(self.validate_data('db820c-01', data)) template_dict = prepare_jinja_template('db820c-01', data, raw=False) self.assertEqual('3083f595', template_dict['adb_serial_number']) self.assertEqual('3083f595', template_dict['fastboot_serial_number']) self.assertEqual([], template_dict['fastboot_options'])