def test_cloudinit_login_with_publickey(self):
     """
     :avocado: tags=tier1,cloudinit
     RHEL7-103831 - CLOUDINIT-TC: VM can successfully login
     after provisioning(with public key authentication)
     1. Create a VM with only public key authentication
     2. Login with publickey, should have sudo privilege
     """
     self.log.info(
         "RHEL7-103831 - CLOUDINIT-TC: VM can successfully login after provisioning(with public key authentication)"
     )
     self.session.connect(authentication="publickey")
     self.assertEqual(self.vm.vm_username,
                      self.session.cmd_output("whoami"),
                      "Fail to login with publickey")
     self.assertIn(
         "%s ALL=(ALL) NOPASSWD:ALL" % self.vm.vm_username,
         self.session.cmd_output(
             "sudo cat /etc/sudoers.d/90-cloud-init-users"),
         "No sudo privilege")
     # Collect /var/log/cloud-init.log and /var/log/messages
     try:
         self.session.cmd_output("mkdir -p /tmp/logs")
         self.session.cmd_output(
             "sudo cp /var/log/cloud-init.log /tmp/logs/")
         self.session.cmd_output("sudo cp /var/log/messages /tmp/logs/")
         self.session.cmd_output("sudo chmod 644 /tmp/logs/*")
         host_logpath = os.path.dirname(self.job.logfile) + "/logs"
         command("mkdir -p {}".format(host_logpath))
         self.session.copy_files_from("/tmp/logs/*", host_logpath)
     except:
         pass
Пример #2
0
 def delete(self, wait=True):
     name = self.id if self.id is not None else self.vm_name
     cmd = self.basecli + '-delete "{}"'.format(name)
     try:
         command(cmd)
     except:
         return False
     # Sometimes VM still exists for a while after cli finished
     time.sleep(30)
     if wait:
         error_message = "Timed out waiting for server to get deleted."
         for count in utils_misc.iterate_timeout(100,
                                                 error_message,
                                                 wait=10):
             if not self.exists():
                 time.sleep(
                     60)  # waiting for other resource (network) release
                 break
Пример #3
0
 def show(self):
     cmd = self.basecli + ' {} '.format(self.name)
     try:
         ret = command(cmd)
     except:
         return False
     if len(ret.stdout):
         info = json.loads(ret.stdout)
         self.id = info["id"]
         self.properties = info
         return True
Пример #4
0
 def stop(self, wait=True):
     cmd = self.basecli + '-stop "{}"'.format(self.vm_name)
     ret = command(cmd)
     # waiting for VM is stopped
     if wait:
         error_message = "Timed out waiting for server to be stopped."
         for count in utils_misc.iterate_timeout(100,
                                                 error_message,
                                                 wait=10):
             self.show()
             if self.is_stopped():
                 return True
     # not active or not wait, just return the VM info
     if len(ret.stdout):
         return self.show()
Пример #5
0
    def create(self, wait=True):
        cmd = self.basecli + '-create  "{}"  --image "{}" --json'\
            .format(self.vm_name, self.image)
        if self.memory:
            cmd += ' --memory {}'.format(self.memory)
        if self.network:
            cmd += ' --network {}'.format(self.network)
        if self.ssh_key_name:
            cmd += ' --key-name {}'.format(self.ssh_key_name)
        # if self.processors:
        #     cmd += ' --processors "{}"'.format(self.processors)
        if self.processor_type:
            cmd += ' --processor-type "{}"'.format(self.processor_type)
        # if self.volumes:
        #     cmd += ' --volumes {}'.format(self.volumes)
        # if self.sys_type:
        #     cmd += ' --sys-type "{}"'.format(self.sys_type)
        # if self.storage_type:
        #     cmd += ' --storage-type {}'.format(self.storage_type)

        try:
            ret = command(cmd)
        except:
            return False
        # waiting for VM is active

        if len(ret.stdout):
            info = json.loads(ret.stdout)
            self.properties = info[0]
            self.id = self.properties.get("pvmInstanceID")
            if wait:
                error_message = "Timed out waiting for server to be active."
                time.sleep(60)
                for count in utils_misc.iterate_timeout(100,
                                                        error_message,
                                                        wait=10):
                    if self.show():
                        if self.is_started():
                            return True
            else:
                return self.show()
        # not active or not wait, just return the VM info
        return False
Пример #6
0
    def capture(self, wait=True):
        capture_image_name = self.vm_name + "_capture_image"
        cmd = self.basecli + '-capture "{}" --destination image-catalog --name "{}" --json'\
            .format(self.vm_name, capture_image_name)
        # if self.volumes:
        #     cmd += ' --volumes {}'.format(self.volumes)
        ret = command(cmd)
        capture_image = BootImage(self.params, name=capture_image_name)
        # waiting for captured image is active
        if wait:
            error_message = "Timed out waiting for image to be active."
            for count in utils_misc.iterate_timeout(100,
                                                    error_message,
                                                    wait=10):

                capture_image.show()
                if capture_image.is_active():
                    return True
        # not active or not wait, just return the captured image info
        if len(ret.stdout):
            return capture_image.show()
Пример #7
0
 def show(self):
     name = self.id if self.id is not None else self.vm_name
     cmd = self.basecli + ' "{}" --json'.format(name)
     try:
         ret = command(cmd)
     except:
         return False  # when no vm exists
     if len(ret.stdout):
         info = json.loads(ret.stdout)
         self.properties = info
         if self.id is None:
             self.id = self.properties.get("pvmInstanceID")
         status = self.properties.get("status")
         if status == "ACTIVE":
             network_list = self.properties.get("networks")
             for network in network_list:
                 if network.get("networkName") == self.network:
                     self.public_network = network
                     return True
         return True
     return False
Пример #8
0
 def delete(self):
     cmd = self.basecli + '-delete {} '.format(self.name)
     command(cmd)
     return True
Пример #9
0
 def imageimport(self):
     cmd = self.basecli + '-import {}  --image-path {}  --os-type {}  --access-key {}  --secret-key {} --json'.format(
         self.name, self.path, self.ostype, self.accesskey, self.secretkey)
     command(cmd)
     return True
Пример #10
0
 def list():
     cmd = "ibmcloud account list"
     command(cmd)
Пример #11
0
 def show():
     cmd = "ibmcloud account show"
     ret = command(cmd)
     return json.loads(ret.stdout)
Пример #12
0
 def logout(self):
     cmd = "ibmcloud logout"
     command(cmd)
Пример #13
0
 def listnetworks(self):
     cmd = self.basecli + "s --json"
     ret = command(cmd)
     return json.loads(ret.stdout)
Пример #14
0
 def list(self):
     cmd = self.basecli + "-list --json"
     ret = command(cmd)
     return json.loads(ret.stdout)
Пример #15
0
 def target(self):
     cmd = self.basecli + '-target {} '.format(self.name)
     command(cmd)
     return True
Пример #16
0
 def login(self):
     cmd = 'ibmcloud login -a "{}" -u "{}" -p "{}" --no-region'.format(
         self.api_endpoint, self.username, self.password)
     command(cmd)
Пример #17
0
 def create(self):
     cmd = self.basecli + '-create {}  --json'.format(self.name)
     command(cmd)
     return self.show()