コード例 #1
0
def start_node(node_type):
    global conf
    global tmp_conf_file

    fake_config = fixtures.FakeConfig()
    conf = fake_config.get_node_info()
    conf["type"] = node_type
    # Speed up booting by going to hdd directly
    conf["compute"]["boot"]["boot_order"] = "c"
    conf["compute"]["storage_backend"] = [{
        "type": "ahci",
        "max_drive_per_controller": 6,
        "drives": [{"size": 8, "file": fixtures.image}]
    }]

    with open(tmp_conf_file, "w") as yaml_file:
        yaml.dump(conf, yaml_file, default_flow_style=False)

    node = model.CNode(conf)
    node.init()
    node.precheck()
    node.start()
    node.wait_node_up()
    helper.port_forward(node)

    global ssh
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600, paramiko.SSHClient.connect, ssh, "127.0.0.1",
                    port=2222, username="******", password="******", timeout=300)
    time.sleep(5)
コード例 #2
0
def start_node(node_type):
    global conf
    global tmp_conf_file

    fake_config = fixtures.FakeConfig()
    conf = fake_config.get_node_info()
    conf["type"] = node_type
    # Speed up booting by going to hdd directly
    conf["compute"]["boot"]["boot_order"] = "c"
    conf["compute"]["storage_backend"] = [{
        "type": "ahci",
        "max_drive_per_controller": 6,
        "drives": [{"size": 8, "file": fixtures.image}]
    }]

    with open(tmp_conf_file, "w") as yaml_file:
        yaml.dump(conf, yaml_file, default_flow_style=False)

    node = model.CNode(conf)
    node.init()
    node.precheck()
    node.start()
    node.wait_node_up()
    helper.port_forward(node)

    global ssh
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600, paramiko.SSHClient.connect, ssh, "127.0.0.1",
                    port=2222, username="******", password="******", timeout=300)
    time.sleep(5)
コード例 #3
0
    def test_qemu_boot_from_disk_img(self):

        self.conf["compute"]["storage_backend"] = [{
            "type":
            "ahci",
            "max_drive_per_controller":
            6,
            "drives": [{
                "size": 8,
                "file": fixtures.image
            }]
        }]
        # 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()

        # Port forward from guest 22 to host 2222
        path = os.path.join(node.workspace.get_workspace(), ".monitor")
        s = UnixSocket(path)
        s.connect()
        s.recv()

        payload_enable_qmp = {"execute": "qmp_capabilities"}

        s.send(json.dumps(payload_enable_qmp))
        s.recv()

        payload_port_forward = {
            "execute": "human-monitor-command",
            "arguments": {
                "command-line": "hostfwd_add ::2222-:22"
            }
        }
        s.send(json.dumps(payload_port_forward))
        s.recv()
        s.close()

        import paramiko
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        paramiko.util.log_to_file("filename.log")
        helper.try_func(600,
                        paramiko.SSHClient.connect,
                        ssh,
                        "127.0.0.1",
                        port=2222,
                        username="******",
                        password="******",
                        timeout=120)
        ssh.close()
コード例 #4
0
def run_cmd(cmd):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600, paramiko.SSHClient.connect, ssh, "127.0.0.1",
                    port=2222, username="******", password="******", timeout=120)

    stdin, stdout, stderr = ssh.exec_command(cmd)
    while not stdout.channel.exit_status_ready():
        pass
    lines = stdout.channel.recv(4096)
    ssh.close()
    return lines
コード例 #5
0
def run_cmd(cmd):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600, paramiko.SSHClient.connect, ssh, "127.0.0.1",
                    port=2222, username="******", password="******", timeout=120)

    stdin, stdout, stderr = ssh.exec_command(cmd)
    while not stdout.channel.exit_status_ready():
        pass
    lines = stdout.channel.recv(4096)
    ssh.close()
    return lines
コード例 #6
0
 def prepare_ssh(self):
     ssh = paramiko.SSHClient()
     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
     paramiko.util.log_to_file('filename.log')
     helper.try_func(
         600,
         paramiko.SSHClient.connect,
         ssh,
         '127.0.0.1',
         port=2222,
         username='******',
         password='******',
         timeout=120)
     time.sleep(2)
     return ssh
コード例 #7
0
    def get_drive(self, serial):
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        paramiko.util.log_to_file("filename.log")
        helper.try_func(600, paramiko.SSHClient.connect, ssh, "127.0.0.1",
                        port=2222, username="******", password="******", timeout=120)
        stdin, stdout, stderr = ssh.exec_command("ls /dev")
        drives = stdout.channel.recv(2048)
        drives = [e for e in filter(lambda x:"sd" in x, drives.split())]

        for drive in drives:
            stdin, stdout, stderr = ssh.exec_command('sg_inq /dev/'+drive)
            lines = stdout.channel.recv(2048)
            if serial in lines:
                return drive
コード例 #8
0
 def prepare_ssh(self):
     ssh = paramiko.SSHClient()
     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
     paramiko.util.log_to_file('filename.log')
     helper.try_func(
         600,
         paramiko.SSHClient.connect,
         ssh,
         '127.0.0.1',
         port=2222,
         username='******',
         password='******',
         timeout=120)
     time.sleep(2)
     return ssh
コード例 #9
0
    def get_port_status(self):
        # SSH ~ ipmi-console        default: 9300   tcp
        # ipmi-console ~ ipmi-sim   default: 9000   tcp
        # ipmi-sim ~ qemu           default: 9002   tcp
        # ipmitool ~ ipmi-sim       default: 623    udp
        # telnet client ~ qemu      default: 2345   tcp
        # VNC client ~ qemu         default: 5901   tcp
        # telnet client ~ racadm    default: 10022  tcp
        port_list = []
        task_pid = []
        base_path = os.path.join(infrasim_home, self.__node_name)
        task_name = ['socat', 'bmc', 'node', 'racadm', 'ipmi_console']
        for task in task_name:
            if task is 'ipmi_console':
                pid_file = os.path.join(base_path, '.ipmi_console.pid')
            else:
                pid_file = os.path.join(
                    base_path, ".{}-{}.pid".format(self.__node_name, task))
            if os.path.exists(pid_file):
                pid = get_task_pid(pid_file)
                if pid > 0 and os.path.exists("/proc/{}".format(pid)):
                    task_pid.append(pid)
        for pid in task_pid:
            cmd = "netstat -anp | grep {}".format(pid)

            res = helper.try_func(600, run_command, cmd)
            port = re.findall(r":(\d.+?) ", res[1])
            for p in port:
                if p not in port_list:
                    port_list.append(p)

        return port_list
コード例 #10
0
    def get_port_status(self):
        # SSH ~ ipmi-console        default: 9300   tcp
        # ipmi-console ~ ipmi-sim   default: 9000   tcp
        # ipmi-sim ~ qemu           default: 9002   tcp
        # ipmitool ~ ipmi-sim       default: 623    udp
        # telnet client ~ qemu      default: 2345   tcp
        # VNC client ~ qemu         default: 5901   tcp
        # telnet client ~ racadm    default: 10022  tcp
        port_list = []
        task_pid = []
        base_path = os.path.join(infrasim_home, self.__node_name)
        task_name = ['socat', 'bmc', 'node', 'racadm', 'ipmi_console']
        for task in task_name:
            if task is 'ipmi_console':
                pid_file = os.path.join(base_path, '.ipmi_console.pid')
            else:
                pid_file = os.path.join(base_path, ".{}-{}.pid".format(
                    self.__node_name, task))
            if os.path.exists(pid_file):
                pid = get_task_pid(pid_file)
                if pid > 0 and os.path.exists("/proc/{}".format(pid)):
                    task_pid.append(pid)
        for pid in task_pid:
            cmd = "netstat -anp | grep {}".format(pid)

            res = helper.try_func(600, run_command, cmd)
            port = re.findall(r":(\d.+?) ", res[1])
            for p in port:
                if p not in port_list:
                    port_list.append(p)

        return port_list
コード例 #11
0
def start_node(node_type):
    global conf
    global tmp_conf_file

    fake_config = fixtures.FakeConfig()
    conf = fake_config.get_node_info()
    conf["type"] = node_type
    conf["compute"]["storage_backend"] = [{
        "type":
        "ahci",
        "max_drive_per_controller":
        6,
        "drives": [{
            "size": 8,
            "file": test_img_file
        }]
    }]

    with open(tmp_conf_file, "w") as yaml_file:
        yaml.dump(conf, yaml_file, default_flow_style=False)

    node = model.CNode(conf)
    node.init()
    node.precheck()
    node.start()

    time.sleep(3)
    import telnetlib
    tn = telnetlib.Telnet(host="127.0.0.1", port=2345)
    tn.read_until("(qemu)")
    tn.write("hostfwd_add ::2222-:22\n")
    tn.read_until("(qemu)")
    tn.close()

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600,
                    paramiko.SSHClient.connect,
                    ssh,
                    "127.0.0.1",
                    port=2222,
                    username="******",
                    password="******",
                    timeout=120)
    ssh.close()
    time.sleep(5)
コード例 #12
0
    def test_qemu_boot_from_disk_img(self):

        self.conf["compute"]["storage_backend"] = [{
            "type": "ahci",
            "max_drive_per_controller": 6,
            "drives": [{"size": 8, "file": fixtures.image}]
        }]
        # 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()

        # Port forward from guest 22 to host 2222
        path = os.path.join(node.workspace.get_workspace(), ".monitor")
        s = UnixSocket(path)
        s.connect()
        s.recv()

        payload_enable_qmp = {
            "execute": "qmp_capabilities"
        }

        s.send(json.dumps(payload_enable_qmp))
        s.recv()

        payload_port_forward = {
            "execute": "human-monitor-command",
            "arguments": {
                "command-line": "hostfwd_add ::2222-:22"
            }
        }
        s.send(json.dumps(payload_port_forward))
        s.recv()
        s.close()

        import paramiko
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        paramiko.util.log_to_file("filename.log")
        helper.try_func(600, paramiko.SSHClient.connect, ssh,
                        "127.0.0.1", port=2222, username="******",
                        password="******", timeout=120)
        ssh.close()
コード例 #13
0
    def set_port_forward(self):
        time.sleep(3)
        import telnetlib
        tn = telnetlib.Telnet(host="127.0.0.1", port=2345)
        tn.read_until("(qemu)")
        tn.write("hostfwd_add ::2222-:22\n")
        tn.read_until("(qemu)")
        tn.close()

        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        paramiko.util.log_to_file("filename.log")
        helper.try_func(600, paramiko.SSHClient.connect, ssh,
                        "127.0.0.1", port=2222, username="******",
                        password="******", timeout=120)
        ssh.close()

        time.sleep(5)
コード例 #14
0
def set_port_forward_try_ssh():
    import time
    import paramiko
    time.sleep(3)
    import telnetlib
    tn = telnetlib.Telnet(host="127.0.0.1", port=2345)
    tn.read_until("(qemu)")
    tn.write("hostfwd_add ::2222-:22\n")
    tn.read_until("(qemu)")
    tn.close()

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600, paramiko.SSHClient.connect, ssh,
                    "127.0.0.1", port=2222, username="******",
                    password="******", timeout=120)
    ssh.close()
    time.sleep(5)
コード例 #15
0
def start_node(node_type):
    global conf
    global tmp_conf_file

    fake_config = fixtures.FakeConfig()
    conf = fake_config.get_node_info()
    conf["type"] = node_type
    conf["compute"]["storage_backend"] = [{
        "type": "ahci",
        "max_drive_per_controller": 6,
        "drives": [{"size": 8, "file": test_img_file}]
    }]

    with open(tmp_conf_file, "w") as yaml_file:
        yaml.dump(conf, yaml_file, default_flow_style=False)

    node = model.CNode(conf)
    node.init()
    node.precheck()
    node.start()

    time.sleep(3)
    import telnetlib
    tn = telnetlib.Telnet(host="127.0.0.1", port=2345)
    tn.read_until("(qemu)")
    tn.write("hostfwd_add ::2222-:22\n")
    tn.read_until("(qemu)")
    tn.close()

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600, paramiko.SSHClient.connect, ssh, "127.0.0.1",
                    port=2222, username="******", password="******", timeout=120)
    ssh.close()
    time.sleep(5)
コード例 #16
0
def start_node(node_type):
    """
    create two drive for comparasion.
    First drive has additional page, second doesn't
    """
    global conf
    global tmp_conf_file
    global ssh
    # create a empty image for test.
    os.system("touch {0}".format(test_drive_image))
    fake_config = fixtures.FakeConfig()
    conf = fake_config.get_node_info()
    conf["type"] = node_type

    conf["compute"]["storage_backend"] = [
        {
            "type": "ahci",
            "max_drive_per_controller": 6,
            "drives": [
                {
                    "size": 8,
                    "file": test_img_file
                }
            ]
        },
        {
            "type": "megasas",
            "max_drive_per_controller": 16,
            "drives": [
                {
                    "file": test_drive_image,
                    "format": "raw",
                    "vendor": "SEAGATE",
                    "product": "ST4000NM0005",
                    "serial": "01234567",
                    "version": "M001",
                    "wwn": "0x5000C500852E2971",
                    "share-rw": True,
                    "cache": "none",
                    "scsi-id": 0,
                    "slot_number": 0,
                    "page-file": page_file
                },
                {
                    "file": test_drive_image,
                    "format": "raw",
                    "vendor": "SEAGATE",
                    "product": "ST4000NM0005",
                    "serial": "12345678",
                    "version": "M001",
                    "wwn": "0x5000C500852E3141",
                    "share-rw": True,
                    "cache": "none",
                    "scsi-id": 1,
                    "slot_number": 1
                }
            ]
        }
    ]

    with open(tmp_conf_file, "w") as yaml_file:
        yaml.dump(conf, yaml_file, default_flow_style=False)

    node = model.CNode(conf)
    node.init()
    node.precheck()
    node.start()

    time.sleep(3)
    import telnetlib
    tn = telnetlib.Telnet(host="127.0.0.1", port=2345)
    tn.read_until("(qemu)")
    tn.write("hostfwd_add ::2222-:22\n")
    tn.read_until("(qemu)")
    tn.close()

    time.sleep(3)
# wait until system is ready for ssh.
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600, paramiko.SSHClient.connect, ssh, "127.0.0.1",
                    port=2222, username="******", password="******", timeout=120)
    ssh.close()
コード例 #17
0
def start_node(node_type):
    """
    create two drive for comparasion.
    First drive has additional page, second doesn't
    """
    global conf
    global tmp_conf_file
    global ssh
    # create a empty image for test.
    os.system("touch {0}".format(test_drive_image))
    fake_config = fixtures.FakeConfig()
    conf = fake_config.get_node_info()
    conf["type"] = node_type

    conf["compute"]["storage_backend"] = [
        {
            "type": "ahci",
            "max_drive_per_controller": 6,
            "drives": [
                {
                    "size": 8,
                    "file": test_img_file
                }
            ]
        },
        {
            "type": "megasas",
            "max_drive_per_controller": 16,
            "drives": [
                {
                    "file": test_drive_image,
                    "format": "raw",
                    "vendor": "SEAGATE",
                    "product": "ST4000NM0005",
                    "serial": "01234567",
                    "version": "M001",
                    "wwn": "0x5000C500852E2971",
                    "share-rw": "true",
                    "cache": "none",
                    "scsi-id": 0,
                    "slot_number": 0,
                    "page-file": page_file
                },
                {
                    "file": test_drive_image,
                    "format": "raw",
                    "vendor": "SEAGATE",
                    "product": "ST4000NM0005",
                    "serial": "12345678",
                    "version": "M001",
                    "wwn": "0x5000C500852E3141",
                    "share-rw": "true",
                    "cache": "none",
                    "scsi-id": 1,
                    "slot_number": 1
                }
            ]
        }
    ]

    with open(tmp_conf_file, "w") as yaml_file:
        yaml.dump(conf, yaml_file, default_flow_style=False)

    node = model.CNode(conf)
    node.init()
    node.precheck()
    node.start()

    time.sleep(3)

    # Port forward from guest 22 to host 2222
    path = os.path.join(node.workspace.get_workspace(), ".monitor")
    s = UnixSocket(path)
    s.connect()
    s.recv()

    payload_enable_qmp = {
        "execute": "qmp_capabilities"
    }

    s.send(json.dumps(payload_enable_qmp))
    s.recv()

    payload_port_forward = {
        "execute":"human-monitor-command",
        "arguments": {
            "command-line": "hostfwd_add ::2222-:22"
        }
    }
    s.send(json.dumps(payload_port_forward))
    s.recv()

    s.close()

    time.sleep(3)
# wait until system is ready for ssh.
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600, paramiko.SSHClient.connect, ssh, "127.0.0.1",
                    port=2222, username="******", password="******", timeout=120)
    ssh.close()
コード例 #18
0
class test_compute_configuration_change(unittest.TestCase):
    def setUp(self):
        fake_config = fixtures.FakeConfig()
        self.conf = fake_config.get_node_info()

    def tearDown(self):
        node = model.CNode(self.conf)
        node.init()
        node.stop()
        node.terminate_workspace()
        self.conf = None
        # if os.path.exists(TMP_CONF_FILE):
        #    os.unlink(TMP_CONF_FILE)
        drive_files = ["/tmp/sda.img", "/tmp/sdb.img"]
        for drive_file in drive_files:
            if os.path.exists(drive_file):
                os.unlink(drive_file)

    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]
        assert "qemu-system-x86_64" in str_result
        assert "-smp 8" 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]
        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]
        assert "qemu-system-x86_64" in str_result
        assert "-m 1536" in str_result

    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", " ")

        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_qemu_boot_from_disk_img(self):
        MD5_IMG = "986e5e63e8231a307babfbe9c81ca210"
        DOWNLOAD_URL = "https://github.com/InfraSIM/test/raw/master/image/kcs.img"
        test_img_file = "/tmp/kcs.img"
        try:
            helper.fetch_image(DOWNLOAD_URL, MD5_IMG, test_img_file)
        except InfraSimError, e:
            print e.value
            assert False

        self.conf["compute"]["storage_backend"] = [{
            "type":
            "ahci",
            "max_drive_per_controller":
            6,
            "drives": [{
                "size": 8,
                "file": test_img_file
            }]
        }]
        # 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()

        # Port forward from guest 22 to host 2222
        path = os.path.join(node.workspace.get_workspace(), ".monitor")
        s = UnixSocket(path)
        s.connect()
        s.recv()

        payload_enable_qmp = {"execute": "qmp_capabilities"}

        s.send(json.dumps(payload_enable_qmp))
        s.recv()

        payload_port_forward = {
            "execute": "human-monitor-command",
            "arguments": {
                "command-line": "hostfwd_add ::2222-:22"
            }
        }
        s.send(json.dumps(payload_port_forward))
        s.recv()
        s.close()

        import paramiko
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        paramiko.util.log_to_file("filename.log")
        helper.try_func(600,
                        paramiko.SSHClient.connect,
                        ssh,
                        "127.0.0.1",
                        port=2222,
                        username="******",
                        password="******",
                        timeout=120)
        ssh.close()
コード例 #19
0
def start_node(node_type):
    """
    create two drive for comparasion.
    First drive has additional page, second doesn't
    """
    global conf
    global tmp_conf_file
    global ssh
    # create a empty image for test.
    os.system("touch {0}".format(test_drive_image))
    fake_config = fixtures.FakeConfig()
    conf = fake_config.get_node_info()
    conf["type"] = node_type

    conf["compute"]["storage_backend"] = [{
        "type":
        "ahci",
        "max_drive_per_controller":
        6,
        "drives": [{
            "size": 8,
            "file": test_img_file
        }]
    }, {
        "type":
        "megasas",
        "max_drive_per_controller":
        16,
        "drives": [{
            "file": test_drive_image,
            "format": "raw",
            "vendor": "SEAGATE",
            "product": "ST4000NM0005",
            "serial": "01234567",
            "version": "M001",
            "wwn": "0x5000C500852E2971",
            "share-rw": True,
            "cache": "none",
            "scsi-id": 0,
            "slot_number": 0,
            "page-file": page_file
        }, {
            "file": test_drive_image,
            "format": "raw",
            "vendor": "SEAGATE",
            "product": "ST4000NM0005",
            "serial": "12345678",
            "version": "M001",
            "wwn": "0x5000C500852E3141",
            "share-rw": True,
            "cache": "none",
            "scsi-id": 1,
            "slot_number": 1
        }]
    }]

    with open(tmp_conf_file, "w") as yaml_file:
        yaml.dump(conf, yaml_file, default_flow_style=False)

    node = model.CNode(conf)
    node.init()
    node.precheck()
    node.start()

    time.sleep(3)
    import telnetlib
    tn = telnetlib.Telnet(host="127.0.0.1", port=2345)
    tn.read_until("(qemu)")
    tn.write("hostfwd_add ::2222-:22\n")
    tn.read_until("(qemu)")
    tn.close()

    time.sleep(3)
    # wait until system is ready for ssh.
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600,
                    paramiko.SSHClient.connect,
                    ssh,
                    "127.0.0.1",
                    port=2222,
                    username="******",
                    password="******",
                    timeout=120)
    ssh.close()
コード例 #20
0
class test_compute_configuration_change(unittest.TestCase):
    def setUp(self):
        fake_config = fixtures.FakeConfig()
        self.conf = fake_config.get_node_info()

    def tearDown(self):
        node = model.CNode(self.conf)
        node.init()
        node.stop()
        node.terminate_workspace()
        self.conf = None
        # if os.path.exists(TMP_CONF_FILE):
        #    os.unlink(TMP_CONF_FILE)

    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]
        assert "qemu-system-x86_64" in str_result
        assert "-smp 8" 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]
        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]
        assert "qemu-system-x86_64" in str_result
        assert "-m 1536" in str_result

    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", " ")

        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_qemu_boot_from_disk_img(self):
        MD5_CIRROS_IMG = "ee1eca47dc88f4879d8a229cc70a07c6"
        DOWNLOAD_URL = "http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img"
        test_img_file = "/tmp/cirros-0.3.4-x86_64-disk.img"
        try:
            helper.fetch_image(DOWNLOAD_URL, MD5_CIRROS_IMG, test_img_file)
        except InfraSimError, e:
            print e.value
            assert False

        self.conf["compute"]["storage_backend"] = [{
            "type":
            "ahci",
            "max_drive_per_controller":
            6,
            "drives": [{
                "size": 8,
                "file": test_img_file
            }]
        }]
        # 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()

        import telnetlib
        import paramiko
        tn = telnetlib.Telnet(host="127.0.0.1", port=2345)
        tn.read_until("(qemu)")
        tn.write("hostfwd_add ::2222-:22\n")
        tn.read_until("(qemu)")
        tn.close()

        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        paramiko.util.log_to_file("filename.log")
        helper.try_func(600,
                        paramiko.SSHClient.connect,
                        ssh,
                        "127.0.0.1",
                        port=2222,
                        username="******",
                        password="******",
                        timeout=120)
        ssh.close()
コード例 #21
0
def start_node():
    """
    create two drive for comparasion.
    First drive has additional page, second doesn't
    """
    global conf
    global tmp_conf_file
    global ssh

    fake_config = fixtures.FakeConfig()
    conf = fake_config.get_node_info()
    conf["compute"]["networks"][0]["port_forward"] = [{
        "protocal": "tcp",
        "inside": 22,
        "outside": 2222
    }]

    conf["compute"]["storage_backend"] = [{
        "type":
        "ahci",
        "max_drive_per_controller":
        6,
        "drives": [{
            "size": 8,
            "file": fixtures.image
        }]
    }, {
        "type":
        "lsi",
        "max_drive_per_controller":
        16,
        "drives": [{
            "format": "raw",
            "size": 1,
            "vendor": "SEAGATE",
            "product": "ST4000NM0005",
            "serial": "01234567",
            "version": "M001",
            "wwn": "0x5000C500852E2971",
            "share-rw": "true",
            "cache": "none",
            "scsi-id": 0,
            "slot_number": 0,
            "sector_size": 520
        }, {
            "format": "raw",
            "size": 1,
            "vendor": "HITACH",
            "product": "ST4000NM0006",
            "serial": "12345678",
            "version": "M001",
            "wwn": "0x5000C500852E3141",
            "share-rw": "true",
            "cache": "none",
            "scsi-id": 1,
            "slot_number": 1
        }]
    }]

    node = model.CNode(conf)
    node.init()
    node.precheck()
    node.start()

    # wait until system is ready for ssh.
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600,
                    paramiko.SSHClient.connect,
                    ssh,
                    "127.0.0.1",
                    port=2222,
                    username="******",
                    password="******",
                    timeout=120)
コード例 #22
0
def start_node(node_type):
    """
    create two drive for comparasion.
    First drive has additional page, second doesn't
    """
    global conf
    global tmp_conf_file
    global ssh
    # create a empty image for test.
    os.system("touch {0}".format(test_drive_image))
    fake_config = fixtures.FakeConfig()
    conf = fake_config.get_node_info()
    conf["type"] = node_type

    conf["compute"]["storage_backend"] = [{
        "type":
        "ahci",
        "max_drive_per_controller":
        6,
        "drives": [{
            "size": 8,
            "file": fixtures.image
        }]
    }, {
        "type":
        "megasas",
        "max_drive_per_controller":
        16,
        "drives": [{
            "file": test_drive_image,
            "format": "raw",
            "vendor": "SEAGATE",
            "product": "ST4000NM0005",
            "serial": "01234567",
            "version": "M001",
            "wwn": "0x5000C500852E2971",
            "share-rw": "true",
            "cache": "none",
            "scsi-id": 0,
            "slot_number": 0,
            "page-file": page_file
        }, {
            "file": test_drive_image,
            "format": "raw",
            "vendor": "SEAGATE",
            "product": "ST4000NM0005",
            "serial": "12345678",
            "version": "M001",
            "wwn": "0x5000C500852E3141",
            "share-rw": "true",
            "cache": "none",
            "scsi-id": 1,
            "slot_number": 1
        }]
    }]

    with open(tmp_conf_file, "w") as yaml_file:
        yaml.dump(conf, yaml_file, default_flow_style=False)

    node = model.CNode(conf)
    node.init()
    node.precheck()
    node.start()

    time.sleep(3)

    # Port forward from guest 22 to host 2222
    path = os.path.join(node.workspace.get_workspace(), ".monitor")
    s = UnixSocket(path)
    s.connect()
    s.recv()

    payload_enable_qmp = {"execute": "qmp_capabilities"}

    s.send(json.dumps(payload_enable_qmp))
    s.recv()

    payload_port_forward = {
        "execute": "human-monitor-command",
        "arguments": {
            "command-line": "hostfwd_add ::2222-:22"
        }
    }
    s.send(json.dumps(payload_port_forward))
    s.recv()

    s.close()

    time.sleep(3)
    # wait until system is ready for ssh.
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600,
                    paramiko.SSHClient.connect,
                    ssh,
                    "127.0.0.1",
                    port=2222,
                    username="******",
                    password="******",
                    timeout=120)
    ssh.close()
コード例 #23
0
def start_node(node_type):
    """
    create pcie_topo
    """
    global conf
    global tmp_conf_file
    global ssh
    fake_config = fixtures.FakeConfig()
    conf = fake_config.get_node_info()
    conf["compute"]["boot"] = {
        "boot_order": "c"
        }
    conf["compute"]["storage_backend"] = [{
            "type": "ahci",
            "max_drive_per_controller": 6,
            "drives": [
                {
                    "size": 8,
                    "file": fixtures.image
                }
            ]}, {
            "bus": "downstream4",
            "type": "nvme",
            "cmb_size": 256,
            "drives": [{"size": 8}]
        }]

    conf["compute"]["networks"] = [{
        "bus": "downstream1",
        "device": "e1000",
        "mac": "52:54:be:b9:77:dd",
        "network_mode": "nat",
        "network_name": "dummy0"
    }]
    conf["compute"]["pcie_topology"] = {
      "root_port": [
        {
          "addr": "7.0",
          "bus": "pcie.0",
          "chassis": 1,
          "device": "ioh3420",
          "id": "root_port1",
          "pri_bus": 0,
          "sec_bus": 40,
          "slot": 2
        },
        {
          "addr": "8.0",
          "bus": "pcie.0",
          "chassis": 1,
          "device": "ioh3420",
          "id": "root_port2",
          "pri_bus": 0,
          "sec_bus": 60,
          "slot": 3
        }
      ],
      "switch": [
        {
          "downstream": [
            {
              "addr": "2.0",
              "bus": "upstream1",
              "chassis": 1,
              "device": "xio3130-downstream",
              "id": "downstream1",
              "slot": 190,
              "pri_bus": 41,
              "sec_bus": 42
            },
            {
              "addr": "3.0",
              "bus": "upstream1",
              "chassis": 1,
              "device": "xio3130-downstream",
              "id": "downstream2",
              "slot": 160,
              "pri_bus": 41,
              "sec_bus": 43
            }
          ],
          "upstream": [
            {
              "bus": "root_port1",
              "device": "x3130-upstream",
              "id": "upstream1"
            }
          ]
        },
        {
          "downstream": [
            {
              "addr": "2.0",
              "bus": "upstream2",
              "chassis": 1,
              "device": "xio3130-downstream",
              "id": "downstream3",
              "slot": 193,
              "pri_bus": 61,
              "sec_bus": 62
            },
            {
              "addr": "3.0",
              "bus": "upstream2",
              "chassis": 1,
              "device": "xio3130-downstream",
              "id": "downstream4",
              "slot": 164,
              "pri_bus": 61,
              "sec_bus": 63
            }
          ],
          "upstream": [
            {
              "bus": "root_port2",
              "device": "x3130-upstream",
              "id": "upstream2"
            }
          ]
        }
      ]
    }

    node = model.CNode(conf)
    node.init()
    node.precheck()
    node.start()
    time.sleep(3)
    port_forward(node)
    time.sleep(3)

    # wait until system is ready for ssh.
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    paramiko.util.log_to_file("filename.log")
    helper.try_func(600, paramiko.SSHClient.connect, ssh, "127.0.0.1",
                    port=2222, username="******", password="******", timeout=120)
    ssh.close()