def test_hmp_access(self):
        # start service
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()
        node_name = node.get_node_name()
        port = self.conf["monitor"].get("port", 9005)

        if self.conf["monitor"].get("interface", None):
            interface = self.conf["monitor"].get("interface", None)
            ip = helper.get_interface_ip(interface)
        else:
            ip = "0.0.0.0"

        interface = self.conf["monitor"].get("interface", )
        payload = {
            "execute": "human-monitor-command",
            "arguments": {
                "command-line": "info chardev"
            }
        }
        url = "http://{}:{}/hmp/{}".format(ip, port, node_name)
        headers = {'content-type': 'application/json'}
        res = requests.post(url,
                            headers=headers,
                            data=json.dumps(payload),
                            timeout=1)
        # res = requests.post(url)
        if res.status_code == requests.codes.ok:
            return True
        else:
            return False
    def test_robust_error_hmp(self):
        # start service
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()
        node_name = node.get_node_name()
        port = self.conf["monitor"].get("port", 9005)

        if self.conf["monitor"].get("interface", None):
            interface = self.conf["monitor"].get("interface", None)
            ip = helper.get_interface_ip(interface)
        else:
            ip = "0.0.0.0"

        interface = self.conf["monitor"].get("interface", )
        # send the error command
        payload = {"error": "error"}
        url = "http://{}:{}/hmp/{}".format(ip, port, node_name)
        headers = {'content-type': 'application/json'}

        res = requests.post(url,
                            headers=headers,
                            data=json.dumps(payload),
                            timeout=1)
        if res.status_code == requests.codes.ok:
            return True
        else:
            return False
Exemplo n.º 3
0
    def setUpClass(self):
        test_img_file = "{}/kcs.img".\
            format(os.environ['HOME'])
        if os.path.exists(test_img_file) is False:
            os.system("wget -c \
                https://github.com/InfraSIM/test/raw/master/image/kcs.img \
                -O {}".format(test_img_file))

        if os.path.exists(test_img_file) is False:
            return

        os.system("touch test.yml")
        with open(VM_DEFAULT_CONFIG, 'r') as f_yml:
            self.conf = yaml.load(f_yml)
        self.conf["name"] = "test"
        self.conf["compute"]["storage_backend"] = [{
            "controller": {
                "type": "ahci",
                "max_drive_per_controller": 6,
                "drives": [{
                    "size": 8,
                    "file": test_img_file
                }]
            }
        }]
        with open("test.yml", "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()

        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")
        while True:
            try:
                ssh.connect("127.0.0.1",
                            port=2222,
                            username="******",
                            password="******",
                            timeout=120)
                ssh.close()
                break
            except paramiko.SSHException:
                time.sleep(1)
                continue
            except Exception as e:
                assert False

        time.sleep(3)
Exemplo n.º 4
0
 def tearDown(self):
     node = model.CNode(self.conf)
     node.init()
     node.stop()
     node.terminate_workspace()
     os.remove(self.sol_outfile)
     self.conf = None
Exemplo n.º 5
0
    def test_command_in_line(self):

        str_result = run_command("which sshpass", True,
                                 subprocess.PIPE, subprocess.PIPE)
        if str_result[0] != 0:
            self.skipTest("Need sshpass to test inline ssh command")

        # Start service
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()

        # Test help in iDrac console
        cmd_help = "sshpass -p 'admin' " \
                   "ssh [email protected] " \
                   "-p 10022 " \
                   "-o StrictHostKeyChecking=no " \
                   "help"
        child = subprocess.Popen(cmd_help, shell=True,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        cmd_result = child.communicate()
        assert "racadm" in cmd_result[0]

        # Test help in racadm console
        cmd_help = "sshpass -p 'admin' " \
                   "ssh [email protected] " \
                   "-p 10022 " \
                   "-o StrictHostKeyChecking=no " \
                   "racadm help"
        child = subprocess.Popen(cmd_help, shell=True,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        cmd_result = child.communicate()
        assert "hwinventory" in cmd_result[0]

        # Test wrong username fail
        cmd_help = "sshpass -p 'admin' " \
                   "ssh [email protected] " \
                   "-p 10022 " \
                   "-o StrictHostKeyChecking=no " \
                   "racadm help"
        child = subprocess.Popen(cmd_help, shell=True,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        cmd_result = child.communicate()
        assert "Permission denied" in cmd_result[1]

        # Test wrong password fail
        cmd_help = "sshpass -p 'fake' " \
                   "ssh [email protected] " \
                   "-p 10022 " \
                   "-o StrictHostKeyChecking=no " \
                   "racadm help"
        child = subprocess.Popen(cmd_help, shell=True,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        cmd_result = child.communicate()
        assert "Permission denied" in cmd_result[1]