Exemplo n.º 1
0
 def start_vm(cls, vmid, hostid):
     """Start the instance"""
     cmd = startVirtualMachine.startVirtualMachineCmd()
     cmd.id = vmid
     if hostid:
         cmd.hostid = hostid
     return (cls.testClass.apiclient.startVirtualMachine(cmd))
Exemplo n.º 2
0
    def test_02_revert_vm_snapshots(self):
        """Test to revert VM snapshots
        """

        try:
            ssh_client = self.virtual_machine.get_ssh_client()

            cmds = [
                "rm -rf %s/%s" % (self.test_dir, self.random_data),
                "ls %s/%s" % (self.test_dir, self.random_data)
            ]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        if str(result[0]).index("No such file or directory") == -1:
            self.fail("Check the random data has be delete from temp file!")

        time.sleep(self.services["sleep"])

        list_snapshot_response = VmSnapshot.list(self.apiclient,
                                                 vmid=self.virtual_machine.id,
                                                 listall=True)

        self.assertEqual(isinstance(list_snapshot_response, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(list_snapshot_response, None,
                            "Check if snapshot exists in ListSnapshot")

        self.assertEqual(list_snapshot_response[0].state, "Ready",
                         "Check the snapshot of vm is ready!")

        VmSnapshot.revertToSnapshot(self.apiclient,
                                    list_snapshot_response[0].id)

        list_vm_response = list_virtual_machines(self.apiclient,
                                                 id=self.virtual_machine.id)

        self.assertEqual(list_vm_response[0].state, "Stopped",
                         "Check the state of vm is Stopped!")

        cmd = startVirtualMachine.startVirtualMachineCmd()
        cmd.id = list_vm_response[0].id
        self.apiclient.startVirtualMachine(cmd)

        time.sleep(self.services["sleep"])

        try:
            ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)

            cmds = ["cat %s/%s" % (self.test_dir, self.random_data)]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        self.assertEqual(
            self.random_data_0, result[0],
            "Check the random data is equal with the ramdom file!")
    def test_02_revert_vm_snapshots(self):
        """Test to revert VM snapshots
        """

        try:
            ssh_client = self.virtual_machine.get_ssh_client()

            cmds = [
                "rm -rf %s/%s" % (self.test_dir, self.random_data),
                "ls %s/%s" % (self.test_dir, self.random_data)
            ]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        if str(result[0]).index("No such file or directory") == -1:
            self.fail("Check the random data has be delete from temp file!")

        time.sleep(self.services["sleep"])

        list_snapshot_response = VmSnapshot.list(self.apiclient, vmid=self.virtual_machine.id, listall=True)

        self.assertEqual(
            isinstance(list_snapshot_response, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            list_snapshot_response,
            None,
            "Check if snapshot exists in ListSnapshot"
        )

        self.assertEqual(
            list_snapshot_response[0].state,
            "Ready",
            "Check the snapshot of vm is ready!"
        )

        VmSnapshot.revertToSnapshot(self.apiclient, list_snapshot_response[0].id)

        list_vm_response = list_virtual_machines(
            self.apiclient,
            id=self.virtual_machine.id
        )

        self.assertEqual(
            list_vm_response[0].state,
            "Stopped",
            "Check the state of vm is Stopped!"
        )

        cmd = startVirtualMachine.startVirtualMachineCmd()
        cmd.id = list_vm_response[0].id
        self.apiclient.startVirtualMachine(cmd)

        time.sleep(self.services["sleep"])

        try:
            ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)

            cmds = [
                "cat %s/%s" % (self.test_dir, self.random_data)
            ]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        self.assertEqual(
            self.random_data_0,
            result[0],
            "Check the random data is equal with the ramdom file!"
        )
Exemplo n.º 4
0
    def test_01_UserDataPasswordReset(self):
        self.debug("START USER DATA PASSWORD RESET ON VM")
        """
         Validate the following:
         1) user data
         2) reset vm password.

         Steps:
         1.  Set password enabled to false in the template.
         2.  Create an Isolated network - Test Network (10.1.1.1/24).
         3.  Deploy VM1 in Test Network
         4.  Verify domain,zone subnet, vm.
         5.  create public ip , Create Static Nat rule firewall rule and verify
         6.  SSH to VM should be successful
         7.  verify userdata
         8.  check cloud-set-guest-password exist.
         9.  if cloud-set-guest-password exist.
          9.1    change template password enabled to true
          9.2   verify that template is password enbalded
          9.3   SSH with new password should be successful
         10. else cloud-set-guest-password does not exist.
          10.1  get the cloud-set-guest-password file
          10.2  stop vm
          10.3  create a new template with password enabled. Verify that template is password enabled.
          10.4  create vm 2 with new template in Test Network
          10.5  Verify vm.
          10.6  create public ip , Create Static Nat rule firewall rule and verify
          10.7  SSH to VM 2 should be successful
         11. Reset VM password (VM_1 if guest password file exist.  else it is VM2)
         12  Starting VM and SSH to VM to verify new password
        """

        self.defaultTemplateVal = self.template.passwordenabled
        if self.template.passwordenabled:
            self.updateTemplate(False)

        self.debug("CREATE AN ISOLATED NETWORK")
        self.network_1 = self.create_Network(self.test_data["network_offering_pr"])
        self.cleanup.append(self.network_1)
        expUserData = "hello world vm1"
        userdata = base64.b64encode(expUserData)
        self.test_data["virtual_machine_pr"]["userdata"] = userdata
        self.debug("DEPLOY VM 1 IN TEST NETWORK")
        # Pass the network and name of the vm type from the testdata with the configuration for the vm
        self.vm_1 = self.create_VM_in_Network(self.network_1, "virtual_machine_pr")

        self.vm_1.password = self.test_data["virtual_machine_pr"]["password"]
        user_data_cmd = self.get_userdata_url(self.vm_1)

        # VSD verification
        self.debug("VERIFY DOMAIN, ZONE, NETWORK , and VM 1")
        self.verify_vsp_network(self.domain.id, self.network_1)
        self.verify_vsp_vm(self.vm_1)

        self.debug("CREATE PUBLIC IP, STATIC NAT RULE, FLOATING IP, FIREWALL AND VERIFY")
        public_ip_1 = self.acquire_Public_IP(self.network_1)
        self.create_and_verify_fw(self.vm_1, public_ip_1, self.network_1)

        self.debug("SSH TO VM")
        ssh = self.ssh_into_vm(self.vm_1, public_ip_1)

        self.debug("VERIFY USER DATA")
        self.debug("Get User Data with command: " + user_data_cmd)
        adata = self.execute_cmd(ssh, user_data_cmd)
        actUserData = base64.b64decode(adata)
        self.debug("Response User Data=" + actUserData + ", Expected=" + expUserData)
        self.assertEqual(actUserData, expUserData, "User Data Did Not Match ")

        # check /etc/init.d/cloud-set-quest-password
        ls_cmd = "ls /etc/init.d/cloud-set-guest-password"
        ls_result = self.execute_cmd(ssh, ls_cmd)
        ls_result = ls_result.lower()
        self.debug("reponse from ls_cmd: " + ls_result)
        if "no such file" in ls_result:
            self.debug("NO CLOUD-SET_GUEST_PASSWORD FILE.  NEED TO GET ONE")
            self.install_cloud_set_guest_password_script(ssh)
            self.stop_vm(self.vm_1)
            self.create_template(self.vm_1)
            self.debug("DEPLOY VM 2 IN TEST NETWORK WITH NEW TEMPLATE")
            self.vm_2 = self.create_VM_in_Network(self.network_1, "virtual_machine_pr")
            self.remove_vm2 = True
            self.debug("STARTING VM_2 ")
            startCmd = startVirtualMachine.startVirtualMachineCmd()
            startCmd.id = self.vm_2.id
            vm_2a = self.apiclient.startVirtualMachine(startCmd)
            self.vm_2.password = vm_2a.password.strip()
            self.vm_2.nic = vm_2a.nic
            self.debug("VM - %s password %s !" % (self.vm_2.name, self.vm_2.password))
            self.assertNotEqual(self.vm_2.password,
                                self.test_data["virtual_machine_pr"]["password"],
                                "Password enabled not working. Password same as virtual_machine password "
                                )
            self.verify_vsp_vm(vm_2a)
            self.debug("GET PUBLIC IP.  CREATE AND VERIFIED FIREWALL RULES")
            public_ip_2 = self.acquire_Public_IP(self.network_1)
            self.create_and_verify_fw(self.vm_2, public_ip_2, self.network_1)

            ssh = self.ssh_into_vm(self.vm_2, public_ip_2)
            vm_test = self.vm_2
            vm_test_public_ip = public_ip_2

        else:
            self.debug("UPDATE TEMPLATE TO PASSWORD ENABLED")
            self.updateTemplate(True)
            self.assertEqual(self.template.passwordenabled, True, "Template is not password enabled")
            vm_test = self.vm_1
            vm_test_public_ip = public_ip_1

        self.debug("RESETTING VM PASSWORD for VM: %s" % vm_test.name)
        vm_test.password = vm_test.resetPassword(self.apiclient)
        self.debug("Password reset to: %s" % vm_test.password)
        self.debug("STARTING VM AND SSH TO VM TO VERIFY NEW PASSWORD")
        vm_test.start(self.apiclient)
        self.debug("VM - %s started!" % vm_test.name)
        self.ssh_into_vm(vm_test, vm_test_public_ip)
Exemplo n.º 5
0
 def start(cls, apiclient, vmid, hostid):
     """Start the instance"""
     cmd = startVirtualMachine.startVirtualMachineCmd()
     cmd.id = vmid
     cmd.hostid = hostid
     return (apiclient.startVirtualMachine(cmd))
Exemplo n.º 6
0
    def test_01_UserDataPasswordReset(self):
        self.debug("START USER DATA PASSWORD RESET ON VM")
        """
         Validate the following:
         1) user data
         2) reset vm password.

         Steps:
         1.  Set password enabled to false in the template.
         2.  Create an Isolated network - Test Network (10.1.1.1/24).
         3.  Deploy VM1 in Test Network
         4.  Verify domain,zone subnet, vm.
         5.  create public ip , Create Static Nat rule firewall rule and verify
         6.  SSH to VM should be successful
         7.  verify userdata
         8.  check cloud-set-guest-password exist.
         9.  if cloud-set-guest-password exist.
          9.1    change template password enabled to true
          9.2   verify that template is password enbalded
          9.3   SSH with new password should be successful
         10. else cloud-set-guest-password does not exist.
          10.1  get the cloud-set-guest-password file
          10.2  stop vm
          10.3  create a new template with password enabled. Verify that template is password enabled.
          10.4  create vm 2 with new template in Test Network
          10.5  Verify vm.
          10.6  create public ip , Create Static Nat rule firewall rule and verify
          10.7  SSH to VM 2 should be successful
         11. Reset VM password (VM_1 if guest password file exist.  else it is VM2)
         12  Starting VM and SSH to VM to verify new password
        """

        self.defaultTemplateVal = self.template.passwordenabled
        if self.template.passwordenabled:
            self.updateTemplate(False)

        self.debug("CREATE AN ISOLATED NETWORK")
        self.network_1 = self.create_Network(
            self.test_data["network_offering_pr"])
        self.cleanup.append(self.network_1)
        expUserData = "hello world vm1"
        userdata = base64.b64encode(expUserData)
        self.test_data["virtual_machine_pr"]["userdata"] = userdata
        self.debug("DEPLOY VM 1 IN TEST NETWORK")
        # Pass the network and name of the vm type from the testdata with the configuration for the vm
        self.vm_1 = self.create_VM_in_Network(self.network_1,
                                              "virtual_machine_pr")

        self.vm_1.password = self.test_data["virtual_machine_pr"]["password"]
        user_data_cmd = self.get_userdata_url(self.vm_1)

        # VSD verification
        self.debug("VERIFY DOMAIN, ZONE, NETWORK , and VM 1")
        self.verify_vsp_network(self.domain.id, self.network_1)
        self.verify_vsp_vm(self.vm_1)

        self.debug(
            "CREATE PUBLIC IP, STATIC NAT RULE, FLOATING IP, FIREWALL AND VERIFY"
        )
        public_ip_1 = self.acquire_Public_IP(self.network_1)
        self.create_and_verify_fw(self.vm_1, public_ip_1, self.network_1)

        self.debug("SSH TO VM")
        ssh = self.ssh_into_vm(self.vm_1, public_ip_1)

        self.debug("VERIFY USER DATA")
        self.debug("Get User Data with command: " + user_data_cmd)
        adata = self.execute_cmd(ssh, user_data_cmd)
        actUserData = base64.b64decode(adata)
        self.debug("Response User Data=" + actUserData + ", Expected=" +
                   expUserData)
        self.assertEqual(actUserData, expUserData, "User Data Did Not Match ")

        # check /etc/init.d/cloud-set-quest-password
        ls_cmd = "ls /etc/init.d/cloud-set-guest-password"
        ls_result = self.execute_cmd(ssh, ls_cmd)
        ls_result = ls_result.lower()
        self.debug("reponse from ls_cmd: " + ls_result)
        if "no such file" in ls_result:
            self.debug("NO CLOUD-SET_GUEST_PASSWORD FILE.  NEED TO GET ONE")
            self.install_cloud_set_guest_password_script(ssh)
            self.stop_vm(self.vm_1)
            self.create_template(self.vm_1)
            self.debug("DEPLOY VM 2 IN TEST NETWORK WITH NEW TEMPLATE")
            self.vm_2 = self.create_VM_in_Network(self.network_1,
                                                  "virtual_machine_pr")
            self.remove_vm2 = True
            self.debug("STARTING VM_2 ")
            startCmd = startVirtualMachine.startVirtualMachineCmd()
            startCmd.id = self.vm_2.id
            vm_2a = self.apiclient.startVirtualMachine(startCmd)
            self.vm_2.password = vm_2a.password.strip()
            self.vm_2.nic = vm_2a.nic
            self.debug("VM - %s password %s !" %
                       (self.vm_2.name, self.vm_2.password))
            self.assertNotEqual(
                self.vm_2.password,
                self.test_data["virtual_machine_pr"]["password"],
                "Password enabled not working. Password same as virtual_machine password "
            )
            self.verify_vsp_vm(vm_2a)
            self.debug("GET PUBLIC IP.  CREATE AND VERIFIED FIREWALL RULES")
            public_ip_2 = self.acquire_Public_IP(self.network_1)
            self.create_and_verify_fw(self.vm_2, public_ip_2, self.network_1)

            ssh = self.ssh_into_vm(self.vm_2, public_ip_2)
            vm_test = self.vm_2
            vm_test_public_ip = public_ip_2

        else:
            self.debug("UPDATE TEMPLATE TO PASSWORD ENABLED")
            self.updateTemplate(True)
            self.assertEqual(self.template.passwordenabled, True,
                             "Template is not password enabled")
            vm_test = self.vm_1
            vm_test_public_ip = public_ip_1

        self.debug("RESETTING VM PASSWORD for VM: %s" % vm_test.name)
        vm_test.password = vm_test.resetPassword(self.apiclient)
        self.debug("Password reset to: %s" % vm_test.password)
        self.debug("STARTING VM AND SSH TO VM TO VERIFY NEW PASSWORD")
        vm_test.start(self.apiclient)
        self.debug("VM - %s started!" % vm_test.name)
        self.ssh_into_vm(vm_test, vm_test_public_ip)
 def start_vm(self, id):
     cmd = startVirtualMachine.startVirtualMachineCmd()
     cmd.id = id
     return self.apiclient.startVirtualMachine(cmd)