def test_controller_with_drive6(self): # Update ahci controller with six drives self.conf["compute"]["storage_backend"] = [{ "type": "ahci", "use_msi": "true", "max_cmds": 1024, "max_sge": 128, "max_drive_per_controller": 6, "drives": drive6 }] with open('/tmp/test.yml', 'w') as outfile: yaml.dump(self.conf, outfile, default_flow_style=False) os.system("infrasim config add test {}".format(tmp_conf_file)) node = model.CNode(self.conf) node.init() node.precheck() node.start() controller_type = run_command("infrasim node info {} | grep -c ahci". format(self.conf["name"])) self.assertEqual(int(controller_type[1]), 1) qemu_pid = get_qemu_pid(node) qemu_cmdline = open("/proc/{}/cmdline".format(qemu_pid)).read().replace("\x00", " ") qemu_cmdline = helper.get_full_qemu_cmd(qemu_cmdline) assert "qemu-system-x86_64" in qemu_cmdline assert "/tmp/sda.img" in qemu_cmdline assert "/tmp/sdb.img" in qemu_cmdline assert "/tmp/sdc.img" in qemu_cmdline assert "/tmp/sdd.img" in qemu_cmdline assert "/tmp/sde.img" in qemu_cmdline assert "/tmp/sdf.img" in qemu_cmdline assert "format=qcow2" in qemu_cmdline
def test_set_disk_drive(self): self.conf["compute"]["storage_backend"] = [{ "type": "ahci", "max_drive_per_controller": 6, "drives": [ {"size": 8, "file": "/tmp/sda.img"}, {"size": 8, "file": "/tmp/sdb.img"} ] }] # with open(TMP_CONF_FILE, "w") as yaml_file: # yaml.dump(self.conf, yaml_file, default_flow_style=False) node = model.CNode(self.conf) node.init() node.precheck() node.start() qemu_pid = get_qemu_pid(node) qemu_cmdline = open("/proc/{}/cmdline".format(qemu_pid)).read().replace("\x00", " ") qemu_cmdline = helper.get_full_qemu_cmd(qemu_cmdline) assert "qemu-system-x86_64" in qemu_cmdline assert "/tmp/sda.img" in qemu_cmdline assert "/tmp/sdb.img" in qemu_cmdline assert "format=qcow2" in qemu_cmdline
def test_set_disk_drive(self): self.conf["compute"]["storage_backend"] = [{ "type": "ahci", "max_drive_per_controller": 6, "drives": [{ "size": 8, "file": "/tmp/sda.img" }, { "size": 8, "file": "/tmp/sdb.img" }] }] # with open(TMP_CONF_FILE, "w") as yaml_file: # yaml.dump(self.conf, yaml_file, default_flow_style=False) node = model.CNode(self.conf) node.init() node.precheck() node.start() qemu_pid = get_qemu_pid(node) qemu_cmdline = open( "/proc/{}/cmdline".format(qemu_pid)).read().replace("\x00", " ") qemu_cmdline = helper.get_full_qemu_cmd(qemu_cmdline) assert "qemu-system-x86_64" in qemu_cmdline assert "/tmp/sda.img" in qemu_cmdline assert "/tmp/sdb.img" in qemu_cmdline assert "format=qcow2" in qemu_cmdline
def test_auto_add_nvme_serial(self): self.conf["compute"]["storage_backend"] = [{ "type": "nvme", "cmb_size": 256, "size": 8 }] node = model.CNode(self.conf) node.init() node.precheck() node.start() # Check process option has nvme serial str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) p = re.compile(r"-device nvme.*serial=(\w+)") m = p.search(str_result) assert m is not None # Check config in workspace has nvme serial node_info = workspace.Workspace.get_node_info_in_workspace( self.conf["name"]) serial = node_info["compute"]["storage_backend"][0]["serial"] assert m.group(1) == serial
def test_controller_with_drive6(self): # Update lsi controller with six drives self.conf["compute"]["storage_backend"] = [{ "type": "lsi", "use_msi": "true", "max_cmds": 1024, "max_sge": 128, "max_drive_per_controller": 6, "drives": drive6 }] self.conf['compute']['storage_backend'].insert( 0, { "type": "ahci", "max_drive_per_controller": 6, "drives": [{ 'file': fixtures.image, 'bootindex': 1, 'use_msi': 'true', 'size': 8 }] }) with open('/tmp/test.yml', 'w') as outfile: yaml.dump(self.conf, outfile, default_flow_style=False) os.system("infrasim config add test {}".format(tmp_conf_file)) node = model.CNode(self.conf) node.init() node.precheck() node.start() helper.port_forward(node) controller_type = run_command( "infrasim node info {} | grep -c lsi".format(self.conf["name"])) self.assertEqual(int(controller_type[1]), 1) qemu_pid = get_qemu_pid(node) qemu_cmdline = open( "/proc/{}/cmdline".format(qemu_pid)).read().replace("\x00", " ") qemu_cmdline = helper.get_full_qemu_cmd(qemu_cmdline) assert "qemu-system-x86_64" in qemu_cmdline assert "/tmp/sda.img" in qemu_cmdline assert "/tmp/sdb.img" in qemu_cmdline assert "/tmp/sdc.img" in qemu_cmdline assert "/tmp/sdd.img" in qemu_cmdline assert "/tmp/sde.img" in qemu_cmdline assert "/tmp/sdf.img" in qemu_cmdline assert "format=qcow2" in qemu_cmdline storage_list = get_storage_list() lsi_info = None for c_map in storage_list: if c_map.get('name') == 'sym53c8xx': lsi_info = c_map break assert lsi_info assert len(lsi_info.get('disks')) == 6
def test_controller_with_drive6(self): # Update ahci controller with six drives self.conf["compute"]["storage_backend"] = [{ "type": "ahci", "use_msi": "true", "max_cmds": 1024, "max_sge": 128, "max_drive_per_controller": 6, "drives": drive6 }] with open('/tmp/test.yml', 'w') as outfile: yaml.dump(self.conf, outfile, default_flow_style=False) os.system("infrasim config add test {}".format(tmp_conf_file)) node = model.CNode(self.conf) node.init() node.precheck() node.start() controller_type = run_command( "infrasim node info {} | grep -c ahci".format(self.conf["name"])) self.assertEqual(int(controller_type[1]), 1) qemu_pid = get_qemu_pid(node) qemu_cmdline = open( "/proc/{}/cmdline".format(qemu_pid)).read().replace("\x00", " ") qemu_cmdline = helper.get_full_qemu_cmd(qemu_cmdline) assert "qemu-system-x86_64" in qemu_cmdline assert "/tmp/sda.img" in qemu_cmdline assert "/tmp/sdb.img" in qemu_cmdline assert "/tmp/sdc.img" in qemu_cmdline assert "/tmp/sdd.img" in qemu_cmdline assert "/tmp/sde.img" in qemu_cmdline assert "/tmp/sdf.img" in qemu_cmdline assert "format=qcow2" in qemu_cmdline
def test_controller_with_drive6(self): # Update lsi controller with six drives self.conf["compute"]["storage_backend"] = [{ "type": "lsi", "use_msi": "true", "max_cmds": 1024, "max_sge": 128, "max_drive_per_controller": 6, "drives": drive6 }] self.conf['compute']['storage_backend'].insert(0, { "type": "ahci", "max_drive_per_controller": 6, "drives": [ { 'file': fixtures.image, 'bootindex': 1, 'use_msi': 'true', 'size': 8 } ] }) with open('/tmp/test.yml', 'w') as outfile: yaml.dump(self.conf, outfile, default_flow_style=False) os.system("infrasim config add test {}".format(tmp_conf_file)) node = model.CNode(self.conf) node.init() node.precheck() node.start() helper.port_forward(node) controller_type = run_command("infrasim node info {} | grep -c lsi". format(self.conf["name"])) self.assertEqual(int(controller_type[1]), 1) qemu_pid = get_qemu_pid(node) qemu_cmdline = open("/proc/{}/cmdline".format(qemu_pid)).read().replace("\x00", " ") qemu_cmdline = helper.get_full_qemu_cmd(qemu_cmdline) assert "qemu-system-x86_64" in qemu_cmdline assert "/tmp/sda.img" in qemu_cmdline assert "/tmp/sdb.img" in qemu_cmdline assert "/tmp/sdc.img" in qemu_cmdline assert "/tmp/sdd.img" in qemu_cmdline assert "/tmp/sde.img" in qemu_cmdline assert "/tmp/sdf.img" in qemu_cmdline assert "format=qcow2" in qemu_cmdline storage_list = get_storage_list() lsi_info = None for c_map in storage_list: if c_map.get('name') == 'sym53c8xx': lsi_info = c_map break assert lsi_info assert len(lsi_info.get('disks')) == 6
def test_qemu_mac_persist_across_power_cycle(self): """ Verify all network mac address persists across power cycle by ipmi command """ # Get qemu mac addresses qemu_rsp = run_command(cmd_ps_qemu)[1] qemu_rsp = helper.get_full_qemu_cmd(qemu_rsp) macs_former = r.findall(qemu_rsp) run_command(cmd_power_cycle) # sleep 2.5s to wait qemu up. time.sleep(2.5) # Get qemu mac addresses qemu_rsp = run_command(cmd_ps_qemu)[1] qemu_rsp = helper.get_full_qemu_cmd(qemu_rsp) macs_latter = r.findall(qemu_rsp) # Verify mac address list remains the same assert sorted(macs_former) == sorted(macs_latter)
def test_qemu_mac_persist_across_power_reset(self): """ Verify all network mac address persists across power reset by ipmi command """ # Get qemu mac addresses qemu_rsp = run_command(cmd_ps_qemu)[1] qemu_rsp = helper.get_full_qemu_cmd(qemu_rsp) macs_former = r.findall(qemu_rsp) run_command(cmd_power_reset) # Get qemu mac addresses qemu_rsp = run_command(cmd_ps_qemu)[1] qemu_rsp = helper.get_full_qemu_cmd(qemu_rsp) macs_latter = r.findall(qemu_rsp) # Verify mac address list remains the same assert sorted(macs_former) == sorted(macs_latter)
def test_peer_node_off_on(self): os.system(cmd_prefix1[4]) PS_QEMU = "ps ax | grep qemu" qemu_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] qemu_result = helper.get_full_qemu_cmd(qemu_result) self.assertNotIn("test1", qemu_result, "peer_bmc can not power off") """ test peer bmc on """ os.system(cmd_prefix1[5]) node1_ssh = self.client_ssh('192.168.188.92') status, result = node1_ssh.exec_command('ls') assert result
def test_peer_node_off_on(self): os.system(cmd_prefix1[4]) PS_QEMU = "ps ax | grep qemu" qemu_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] qemu_result = helper.get_full_qemu_cmd(qemu_result) self.assertNotIn("test1", qemu_result, "peer_bmc can not power off") """ test peer bmc on """ os.system(cmd_prefix1[5]) node1_ssh = self.client_ssh('192.168.188.92') status, result = node1_ssh.exec_command('ls') assert result
def test_set_memory_capacity(self): self.conf["compute"]["memory"]["size"] = 1536 with open(TMP_CONF_FILE, "w") as yaml_file: yaml.dump(self.conf, yaml_file, default_flow_style=False) node = model.CNode(self.conf) node.init() node.precheck() node.start() str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) assert "qemu-system-x86_64" in str_result assert "-m 1536" in str_result
def test_set_bmc_connection_port(self): self.conf["bmc_connection_port"] = 9102 node = model.CNode(self.conf) node.init() node.precheck() node.start() with open(self.bmc_conf, "r") as fp: bmc_conf = fp.read() assert 'serial kcs 0.0.0.0 9102 codec VM ipmb 0x20' in bmc_conf str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) assert "port=9102" in str_result
def test_set_cpu_family(self): self.conf["compute"]["cpu"]["type"] = "IvyBridge" # with open(TMP_CONF_FILE, "w") as yaml_file: # yaml.dump(self.conf, yaml_file, default_flow_style=False) node = model.CNode(self.conf) node.init() node.precheck() node.start() str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) assert "qemu-system-x86_64" in str_result assert "-cpu IvyBridge" in str_result
def test_set_memory_capacity(self): self.conf["compute"]["memory"]["size"] = 1536 with open(TMP_CONF_FILE, "w") as yaml_file: yaml.dump(self.conf, yaml_file, default_flow_style=False) node = model.CNode(self.conf) node.init() node.precheck() node.start() str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) assert "qemu-system-x86_64" in str_result assert "-m 1536" in str_result
def test_set_bmc_connection_port(self): self.conf["bmc_connection_port"] = 9102 node = model.CNode(self.conf) node.init() node.precheck() node.start() with open(self.bmc_conf, "r") as fp: bmc_conf = fp.read() assert 'serial kcs 0.0.0.0 9102 codec VM ipmb 0x20' in bmc_conf str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) assert "port=9102" in str_result
def test_set_vcpu(self): self.conf["compute"]["cpu"]["quantities"] = 8 # with open(TMP_CONF_FILE, "w") as yaml_file: # yaml.dump(self.conf, yaml_file, default_flow_style=False) node = model.CNode(self.conf) node.init() node.precheck() node.start() str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) assert "qemu-system-x86_64" in str_result assert "-smp 8" in str_result
def test_set_node_type(self): self.conf["type"] = "dell_c6320" node = model.CNode(self.conf) node.init() node.precheck() node.start() str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) assert "qemu-system-x86_64" in str_result assert "-smbios file={}/test/data/dell_c6320_smbios.bin".\ format(config.infrasim_home) in str_result str_result = run_command(PS_IPMI, True, subprocess.PIPE, subprocess.PIPE)[1] assert "-f {}/test/data/dell_c6320.emu".\ format(config.infrasim_home) in str_result
def test_set_node_type(self): self.conf["type"] = "dell_c6320" node = model.CNode(self.conf) node.init() node.precheck() node.start() str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) assert "qemu-system-x86_64" in str_result assert "-smbios file={}/test/data/dell_c6320_smbios.bin".\ format(config.infrasim_home) in str_result str_result = run_command(PS_IPMI, True, subprocess.PIPE, subprocess.PIPE)[1] assert "-f {}/test/data/dell_c6320.emu".\ format(config.infrasim_home) in str_result
def test_set_serial_socket(self): self.conf["sol_enable"] = True self.conf["serial_socket"] = "/tmp/test_infrasim_set_serial_socket" node = model.CNode(self.conf) node.init() node.precheck() node.start() str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) assert "-chardev socket,path=/tmp/test_infrasim_set_serial_socket," \ "id=serial0,nowait,reconnect=10" in str_result assert "-device isa-serial,chardev=serial0" in str_result str_result = run_command(PS_SOCAT, True, subprocess.PIPE, subprocess.PIPE)[1] assert "unix-listen:/tmp/test_infrasim_set_serial_socket," \ "fork" in str_result
def test_set_serial_socket(self): self.conf["sol_enable"] = True self.conf["serial_socket"] = "/tmp/test_infrasim_set_serial_socket" node = model.CNode(self.conf) node.init() node.precheck() node.start() str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) assert "-chardev socket,path=/tmp/test_infrasim_set_serial_socket," \ "id=serial0,nowait,reconnect=10" in str_result assert "-device isa-serial,chardev=serial0" in str_result str_result = run_command(PS_SOCAT, True, subprocess.PIPE, subprocess.PIPE)[1] assert "unix-listen:/tmp/test_infrasim_set_serial_socket," \ "fork" in str_result
def test_update_config_then_start_node(self): """ CLI test: node will apply updated config if there's no runtime workspace """ node_info = FakeConfig().get_node_info() node_info["type"] = "dell_r730xd" with open(self.test_config_path, "w") as fp: yaml.dump(node_info, fp, default_flow_style=False) output_update = run_command("infrasim config update {} {}".format( self.test_name, self.test_config_path)) self.assertEqual(output_update[0], 0) output_start = run_command("infrasim node start {}".format( self.test_name)) self.assertEqual(output_start[0], 0) output_ps_qemu = run_command("ps ax | grep qemu") self.assertEqual(output_ps_qemu[0], 0) assert "{}'s configuration mapping is updated".format( self.test_name) in output_update[1] assert "dell_r730xd" in helper.get_full_qemu_cmd(output_ps_qemu[1])
def test_start_node(self): """ Verify infrasim instance start with a netdev """ self.conf["compute"]["networks"].append({ "network_mode": "bridge", "network_name": FAKE_BRIDGE, "device": "vmxnet3", "mac": "00:11:22:33:44:55" }) node = model.CNode(self.conf) node.init() node.precheck() node.start() ret, rsp = run_command(PS_QEMU) rsp = helper.get_full_qemu_cmd(rsp) assert "qemu-system-x86_64" in rsp assert "-netdev bridge,id=netdev1,br={}," \ "helper=".format(FAKE_BRIDGE) in rsp assert "-device vmxnet3,netdev=netdev1," \ "mac=00:11:22:33:44:55" in rsp
def test_auto_add_nvme_serial(self): self.conf["compute"]["storage_backend"] = [{ "type": "nvme", "cmb_size": 256, "size": 8 }] node = model.CNode(self.conf) node.init() node.precheck() node.start() # Check process option has nvme serial str_result = run_command(PS_QEMU, True, subprocess.PIPE, subprocess.PIPE)[1] str_result = helper.get_full_qemu_cmd(str_result) p = re.compile(r"-device nvme.*serial=(\w+)") m = p.search(str_result) assert m is not None # Check config in workspace has nvme serial node_info = workspace.Workspace.get_node_info_in_workspace(self.conf["name"]) serial = node_info["compute"]["storage_backend"][0]["serial"] assert m.group(1) == serial
def test_controller_with_drive7_drive2_drive3(self): # Update ahci controller with seven drives self.conf["compute"]["storage_backend"] = [{ "type": "ahci", "use_msi": "true", "max_cmds": 1024, "max_sge": 128, "max_drive_per_controller": 6, "drives": self.drives7 }] controllers = [] controllers.append({ 'type': 'ahci', 'use_msi': 'true', 'max_cmds': 1024, 'max_sge': 128, 'drives': [], 'max_drive_per_controller': 6 }) controllers.append({ 'type': 'ahci', 'use_msi': 'true', 'max_cmds': 1024, 'max_sge': 128, 'drives': [], 'max_drive_per_controller': 6 }) self.conf['compute']['storage_backend'].extend(controllers) drives2 = [] drives2.append({'size': 8, 'file': "/tmp/sdh.img"}) drives2.append({'size': 16, 'file': "/tmp/sdi.img"}) self.conf['compute']['storage_backend'][1]['drives'].extend(drives2) drives3 = [] drives3.append({'size': 8, 'file': "/tmp/sdj.img"}) drives3.append({'size': 16, 'file': "/tmp/sdk.img"}) drives3.append({'size': 8, 'file': "/tmp/sdl.img"}) self.conf['compute']['storage_backend'][2]['drives'].extend(drives3) with open('/tmp/test.yml', 'w') as outfile: yaml.dump(self.conf, outfile, default_flow_style=False) node = model.CNode(self.conf) node.init() node.precheck() node.start() controller_type_ahci = run_command( "infrasim node info {} | grep -c ahci".format(self.conf["name"])) self.assertEqual(int(controller_type_ahci[1]), 4) qemu_pid = get_qemu_pid(node) qemu_cmdline = open( "/proc/{}/cmdline".format(qemu_pid)).read().replace("\x00", " ") qemu_cmdline = helper.get_full_qemu_cmd(qemu_cmdline) assert "qemu-system-x86_64" in qemu_cmdline assert "/tmp/sda.img" in qemu_cmdline assert "/tmp/sdb.img" in qemu_cmdline assert "/tmp/sdc.img" in qemu_cmdline assert "/tmp/sdd.img" in qemu_cmdline assert "/tmp/sde.img" in qemu_cmdline assert "/tmp/sdf.img" in qemu_cmdline assert "/tmp/sdg.img" in qemu_cmdline assert "/tmp/sdh.img" in qemu_cmdline assert "/tmp/sdi.img" in qemu_cmdline assert "/tmp/sdj.img" in qemu_cmdline assert "/tmp/sdk.img" in qemu_cmdline assert "/tmp/sdl.img" in qemu_cmdline assert "format=qcow2" in qemu_cmdline assert "-device ahci,id=sata0" in qemu_cmdline assert "-device ahci,id=sata1" in qemu_cmdline assert "-device ahci,id=sata2" in qemu_cmdline assert "-device ahci,id=sata3" in qemu_cmdline assert "drive=sata0-0-5-0" in qemu_cmdline assert "drive=sata1-0-0-0" in qemu_cmdline assert "drive=sata2-0-1-0" in qemu_cmdline assert "drive=sata3-0-2-0" in qemu_cmdline
def test_four_controllers_each_with_six_drives(self): image_path = "{}/{}".format(config.infrasim_home, self.conf["name"]) # Add several storage controllers/drives in node config file. drives = [] drives.append({'size': 16, 'file': "{}/sdb.img".format(image_path)}) drives.append({'size': 8, 'file': "{}/sdc.img".format(image_path)}) drives.append({'size': 16, 'file': "{}/sdd.img".format(image_path)}) drives.append({'size': 8, 'file': "{}/sde.img".format(image_path)}) drives.append({'size': 16, 'file': "{}/sdf.img".format(image_path)}) self.conf['compute']['storage_backend'][0]['drives'].extend(drives) self.conf['compute']['storage_backend'][0]['drives'][0][ 'file'] = fixtures.image controllers = [] controllers.append({ 'type': 'megasas', 'use_msi': 'true', 'max_cmds': 1024, 'max_sge': 128, 'drives': [], 'max_drive_per_controller': 6 }) controllers.append({ 'type': 'lsi', 'use_msi': 'true', 'max_cmds': 1024, 'max_sge': 128, 'drives': [], 'max_drive_per_controller': 6 }) controllers.append({ 'type': 'ahci', 'use_msi': 'true', 'max_cmds': 1024, 'max_sge': 128, 'drives': [], 'max_drive_per_controller': 6 }) self.conf['compute']['storage_backend'].extend(controllers) drives1 = [] drives1.append({'size': 8, 'file': "{}/sdg.img".format(image_path)}) drives1.append({'size': 16, 'file': "{}/sdh.img".format(image_path)}) drives1.append({'size': 8, 'file': "{}/sdi.img".format(image_path)}) drives1.append({'size': 16, 'file': "{}/sdj.img".format(image_path)}) drives1.append({'size': 8, 'file': "{}/sdk.img".format(image_path)}) drives1.append({'size': 16, 'file': "{}/sdl.img".format(image_path)}) self.conf['compute']['storage_backend'][1]['drives'].extend(drives1) drives2 = [] drives2.append({'size': 8, 'file': "{}/sdm.img".format(image_path)}) drives2.append({'size': 16, 'file': "{}/sdn.img".format(image_path)}) drives2.append({'size': 8, 'file': "{}/sdo.img".format(image_path)}) drives2.append({'size': 16, 'file': "{}/sdp.img".format(image_path)}) drives2.append({'size': 8, 'file': "{}/sdq.img".format(image_path)}) drives2.append({'size': 16, 'file': "{}/sdr.img".format(image_path)}) self.conf['compute']['storage_backend'][2]['drives'].extend(drives2) drives3 = [] drives3.append({'size': 8, 'file': "{}/sds.img".format(image_path)}) drives3.append({'size': 16, 'file': "{}/sdt.img".format(image_path)}) drives3.append({'size': 8, 'file': "{}/sdu.img".format(image_path)}) drives3.append({'size': 16, 'file': "{}/sdv.img".format(image_path)}) drives3.append({'size': 8, 'file': "{}/sdw.img".format(image_path)}) drives3.append({'size': 16, 'file': "{}/sdx.img".format(image_path)}) self.conf['compute']['storage_backend'][3]['drives'].extend(drives3) with open('/tmp/test.yml', 'w') as outfile: yaml.dump(self.conf, outfile, default_flow_style=False) os.system("infrasim config add {} {}".format(self.conf["name"], tmp_conf_file)) node = model.CNode(self.conf) node.init() node.precheck() node.start() helper.port_forward(node) controller_type_ahci = run_command( "infrasim node info {} | grep -c ahci".format(self.conf["name"])) controller_type_megasas = run_command( "infrasim node info {} | grep -c megasas".format( self.conf["name"])) controller_type_lsi = run_command( "infrasim node info {} | grep -c lsi".format(self.conf["name"])) self.assertEqual(int(controller_type_ahci[1]), 2) self.assertEqual(int(controller_type_megasas[1]), 1) self.assertEqual(int(controller_type_lsi[1]), 1) qemu_pid = get_qemu_pid(node) qemu_cmdline = open( "/proc/{}/cmdline".format(qemu_pid)).read().replace("\x00", " ") qemu_cmdline = helper.get_full_qemu_cmd(qemu_cmdline) assert "qemu-system-x86_64" in qemu_cmdline assert "format=qcow2" in qemu_cmdline storage_list = get_storage_list() # Only has three types of controller assert len(storage_list) == 3 for c_map in storage_list: if c_map.get('name') == 'ahci': assert len(c_map.get('buses') ) == 2 * 6 # 2 controllers * 6 ports per controller assert len(c_map.get('disks')) == 12 elif c_map.get('name') == 'megaraid_sas' or c_map.get( 'name') == 'sym53c8xx': assert len(c_map.get('buses')) == 1 assert len(c_map.get('disks')) == 6 else: assert False
def test_controller_with_drive7_drive2_drive3(self): # Update ahci controller with seven drives self.conf["compute"]["storage_backend"] = [{ "type": "ahci", "use_msi": "true", "max_cmds": 1024, "max_sge": 128, "max_drive_per_controller": 6, "drives": self.drives7 }] controllers = [] controllers.append({ 'type': 'ahci', 'use_msi': 'true', 'max_cmds': 1024, 'max_sge': 128, 'drives': [], 'max_drive_per_controller': 6 }) controllers.append({ 'type': 'ahci', 'use_msi': 'true', 'max_cmds': 1024, 'max_sge': 128, 'drives': [], 'max_drive_per_controller': 6 }) self.conf['compute']['storage_backend'].extend(controllers) drives2 = [] drives2.append({'size': 8, 'file': "/tmp/sdh.img"}) drives2.append({'size': 16, 'file': "/tmp/sdi.img"}) self.conf['compute']['storage_backend'][1]['drives'].extend(drives2) drives3 = [] drives3.append({'size': 8, 'file': "/tmp/sdj.img"}) drives3.append({'size': 16, 'file': "/tmp/sdk.img"}) drives3.append({'size': 8, 'file': "/tmp/sdl.img"}) self.conf['compute']['storage_backend'][2]['drives'].extend(drives3) with open('/tmp/test.yml', 'w') as outfile: yaml.dump(self.conf, outfile, default_flow_style=False) node = model.CNode(self.conf) node.init() node.precheck() node.start() controller_type_ahci = run_command("infrasim node info {} | grep -c ahci". format(self.conf["name"])) self.assertEqual(int(controller_type_ahci[1]), 4) qemu_pid = get_qemu_pid(node) qemu_cmdline = open("/proc/{}/cmdline".format(qemu_pid)).read().replace("\x00", " ") qemu_cmdline = helper.get_full_qemu_cmd(qemu_cmdline) assert "qemu-system-x86_64" in qemu_cmdline assert "/tmp/sda.img" in qemu_cmdline assert "/tmp/sdb.img" in qemu_cmdline assert "/tmp/sdc.img" in qemu_cmdline assert "/tmp/sdd.img" in qemu_cmdline assert "/tmp/sde.img" in qemu_cmdline assert "/tmp/sdf.img" in qemu_cmdline assert "/tmp/sdg.img" in qemu_cmdline assert "/tmp/sdh.img" in qemu_cmdline assert "/tmp/sdi.img" in qemu_cmdline assert "/tmp/sdj.img" in qemu_cmdline assert "/tmp/sdk.img" in qemu_cmdline assert "/tmp/sdl.img" in qemu_cmdline assert "format=qcow2" in qemu_cmdline assert "-device ahci,id=sata0" in qemu_cmdline assert "-device ahci,id=sata1" in qemu_cmdline assert "-device ahci,id=sata2" in qemu_cmdline assert "-device ahci,id=sata3" in qemu_cmdline assert "drive=sata0-0-5-0" in qemu_cmdline assert "drive=sata1-0-0-0" in qemu_cmdline assert "drive=sata2-0-1-0" in qemu_cmdline assert "drive=sata3-0-2-0" in qemu_cmdline
def test_four_controllers_each_with_six_drives(self): image_path = "{}/{}".format(config.infrasim_home, self.conf["name"]) # Add several storage controllers/drives in node config file. drives = [] drives.append({'size': 16, 'file': "{}/sdb.img".format(image_path)}) drives.append({'size': 8, 'file': "{}/sdc.img".format(image_path)}) drives.append({'size': 16, 'file': "{}/sdd.img".format(image_path)}) drives.append({'size': 8, 'file': "{}/sde.img".format(image_path)}) drives.append({'size': 16, 'file': "{}/sdf.img".format(image_path)}) self.conf['compute']['storage_backend'][0]['drives'].extend(drives) self.conf['compute']['storage_backend'][0]['drives'][0]['file'] = fixtures.image controllers = [] controllers.append({ 'type': 'megasas', 'use_msi': 'true', 'max_cmds': 1024, 'max_sge': 128, 'drives': [], 'max_drive_per_controller': 6 }) controllers.append({ 'type': 'lsi', 'use_msi': 'true', 'max_cmds': 1024, 'max_sge': 128, 'drives': [], 'max_drive_per_controller': 6 }) controllers.append({ 'type': 'ahci', 'use_msi': 'true', 'max_cmds': 1024, 'max_sge': 128, 'drives': [], 'max_drive_per_controller': 6 }) self.conf['compute']['storage_backend'].extend(controllers) drives1 = [] drives1.append({'size': 8, 'file': "{}/sdg.img".format(image_path)}) drives1.append({'size': 16, 'file': "{}/sdh.img".format(image_path)}) drives1.append({'size': 8, 'file': "{}/sdi.img".format(image_path)}) drives1.append({'size': 16, 'file': "{}/sdj.img".format(image_path)}) drives1.append({'size': 8, 'file': "{}/sdk.img".format(image_path)}) drives1.append({'size': 16, 'file': "{}/sdl.img".format(image_path)}) self.conf['compute']['storage_backend'][1]['drives'].extend(drives1) drives2 = [] drives2.append({'size': 8, 'file': "{}/sdm.img".format(image_path)}) drives2.append({'size': 16, 'file': "{}/sdn.img".format(image_path)}) drives2.append({'size': 8, 'file': "{}/sdo.img".format(image_path)}) drives2.append({'size': 16, 'file': "{}/sdp.img".format(image_path)}) drives2.append({'size': 8, 'file': "{}/sdq.img".format(image_path)}) drives2.append({'size': 16, 'file': "{}/sdr.img".format(image_path)}) self.conf['compute']['storage_backend'][2]['drives'].extend(drives2) drives3 = [] drives3.append({'size': 8, 'file': "{}/sds.img".format(image_path)}) drives3.append({'size': 16, 'file': "{}/sdt.img".format(image_path)}) drives3.append({'size': 8, 'file': "{}/sdu.img".format(image_path)}) drives3.append({'size': 16, 'file': "{}/sdv.img".format(image_path)}) drives3.append({'size': 8, 'file': "{}/sdw.img".format(image_path)}) drives3.append({'size': 16, 'file': "{}/sdx.img".format(image_path)}) self.conf['compute']['storage_backend'][3]['drives'].extend(drives3) with open('/tmp/test.yml', 'w') as outfile: yaml.dump(self.conf, outfile, default_flow_style=False) os.system("infrasim config add {} {}".format(self.conf["name"], tmp_conf_file)) node = model.CNode(self.conf) node.init() node.precheck() node.start() helper.port_forward(node) controller_type_ahci = run_command("infrasim node info {} | grep -c ahci". format(self.conf["name"])) controller_type_megasas = run_command("infrasim node info {} | grep -c megasas". format(self.conf["name"])) controller_type_lsi = run_command("infrasim node info {} | grep -c lsi". format(self.conf["name"])) self.assertEqual(int(controller_type_ahci[1]), 2) self.assertEqual(int(controller_type_megasas[1]), 1) self.assertEqual(int(controller_type_lsi[1]), 1) qemu_pid = get_qemu_pid(node) qemu_cmdline = open("/proc/{}/cmdline".format(qemu_pid)).read().replace("\x00", " ") qemu_cmdline = helper.get_full_qemu_cmd(qemu_cmdline) assert "qemu-system-x86_64" in qemu_cmdline assert "format=qcow2" in qemu_cmdline storage_list = get_storage_list() # Only has three types of controller assert len(storage_list) == 3 for c_map in storage_list: if c_map.get('name') == 'ahci': assert len(c_map.get('buses')) == 2 * 6 # 2 controllers * 6 ports per controller assert len(c_map.get('disks')) == 12 elif c_map.get('name') == 'megaraid_sas' or c_map.get('name') == 'sym53c8xx': assert len(c_map.get('buses')) == 1 assert len(c_map.get('disks')) == 6 else: assert False