Ejemplo n.º 1
0
 def get_ssh_to_vm(self,
                   ip,
                   username=None,
                   password=None,
                   private_keys=None,
                   **kwargs):
     return SSHClient(host=ip,
                      username=username,
                      password=password,
                      private_keys=private_keys,
                      **kwargs)
Ejemplo n.º 2
0
    def ssh_to_instance(self,
                        env,
                        vm,
                        vm_keypair=None,
                        username='******',
                        password=None,
                        proxy_node=None):
        """Returns direct ssh client to instance via proxy"""
        # Update vm data
        vm.get()
        logger.debug('Try to connect to vm {0}'.format(vm.name))
        net_name = [x for x in vm.addresses if len(vm.addresses[x]) > 0][0]
        vm_ip = vm.addresses[net_name][0]['addr']
        vm_mac = vm.addresses[net_name][0]['OS-EXT-IPS-MAC:mac_addr']
        net_id = self.neutron.list_ports(
            mac_address=vm_mac)['ports'][0]['network_id']
        dhcp_namespace = "qdhcp-{0}".format(net_id)
        if proxy_node is None:
            proxy_nodes = self.get_node_with_dhcp_for_network(net_id)
            if not proxy_nodes:
                raise Exception("Nodes with dhcp for network with id:{}"
                                " not found.".format(net_id))
        else:
            proxy_nodes = [proxy_node]

        proxy_commands = []
        for node in proxy_nodes:
            ip = env.find_node_by_fqdn(node).data['ip']
            key_paths = env.admin_ssh_keys_paths
            proxy_command = ("ssh {keys} -o 'StrictHostKeyChecking no' "
                             "root@{node_ip} 'ip netns exec {ns} "
                             "nc {vm_ip} 22'".format(keys=' '.join(
                                 '-i {}'.format(k) for k in key_paths),
                                                     ns=dhcp_namespace,
                                                     node_ip=ip,
                                                     vm_ip=vm_ip))
            proxy_commands.append(proxy_command)
        instance_keys = []
        if vm_keypair is not None:
            instance_keys.append(
                paramiko.RSAKey.from_private_key(
                    six.StringIO(vm_keypair.private_key)))
        return SSHClient(vm_ip,
                         port=22,
                         username=username,
                         password=password,
                         private_keys=instance_keys,
                         proxy_commands=proxy_commands)
Ejemplo n.º 3
0
 def ssh(self):
     return SSHClient(host=self.data['ip'],
                      username='******',
                      private_keys=self._env.admin_ssh_keys)
Ejemplo n.º 4
0
 def ssh_admin(self):
     return SSHClient(host=self.admin_ip,
                      username=self.ssh_login,
                      password=self.ssh_password)
Ejemplo n.º 5
0
 def get_ssh_to_node(self, ip):
     return SSHClient(host=ip,
                      username='******',
                      private_keys=self.admin_ssh_keys)
Ejemplo n.º 6
0
    def test_live_migration_of_v_ms_with_data_on_root_and_ephemeral_disk(self):
        """This test checks Live Migration of VMs with data on root and
        ephemeral disk

            Steps:
             1. Create flavor with ephemeral disk
             2. Create a floating ip
             3. Create an instance from an image with 'm1.ephemeral' flavor
             4. Add the floating ip to the instance
             5. Ssh to instance and create timestamp on root and ephemeral
                disks
             6. Ping the instance by the floating ip
             7. Execute live migration
             8. Check current hypervisor and status of instance
             9. Check that packets loss was minimal
             10. Ssh to instance and check timestamp on root and ephemeral
                 disks
        """
        networks = self.neutron.list_networks()['networks']
        net = [net['id'] for net in networks if not net['router:external']][0]
        image_id = [
            image.id for image in self.nova.images.list()
            if image.name == 'TestVM'
        ][0]
        flavor = self.nova.flavors.create("m1.ephemeral",
                                          64,
                                          1,
                                          1,
                                          ephemeral=1,
                                          is_public=True)
        self.flavors.append(flavor)
        floating_ip = self.nova.floating_ips.create()
        self.floating_ips.append(floating_ip)
        self.assertIn(
            floating_ip.ip,
            [fip_info.ip for fip_info in self.nova.floating_ips.list()])
        keys = self.nova.keypairs.create('key_2238776')
        self.keys.append(keys)
        private_key = paramiko.RSAKey.from_private_key(
            six.StringIO(str(keys.private_key)))
        inst = common_functions.create_instance(self.nova,
                                                "inst_2238776_{}".format(
                                                    flavor.name),
                                                flavor.id,
                                                net, [self.sec_group.name],
                                                image_id=image_id,
                                                key_name='key_2238776',
                                                inst_list=self.instances)
        self.instances.append(inst.id)
        inst.add_floating_ip(floating_ip.ip)
        ping = common_functions.ping_command(floating_ip.ip, i=10)
        self.assertTrue(ping, "Instance is not reachable")
        out = []
        with SSHClient(host=floating_ip.ip,
                       username="******",
                       password=None,
                       private_keys=[private_key]) as vm_r:
            out.append(vm_r.execute("sudo sh -c 'date > /timestamp.txt'"))
            out.append(vm_r.execute("sudo sh -c 'date > /mnt/timestamp.txt'"))
            out.append(vm_r.execute("sudo -i cat /timestamp.txt"))
            out.append(vm_r.execute("sudo -i cat /mnt/timestamp.txt"))

        for i in out:
            if i.get('stderr'):
                raise Exception("ssh commands were executed with errors")

        root_data = out[-2]['stdout'][0]
        ephem_data = out[-1]['stdout'][0]

        self.live_migration(inst, floating_ip.ip)

        out = []
        with SSHClient(host=floating_ip.ip,
                       username="******",
                       password=None,
                       private_keys=[private_key]) as vm_r:
            out.append(vm_r.execute("sudo -i cat /timestamp.txt"))
            out.append(vm_r.execute("sudo -i cat /mnt/timestamp.txt"))

        for i in out:
            if i.get('stderr'):
                raise Exception("ssh commands were executed with errors")

        r_data = out[0]['stdout'][0]
        ep_data = out[1]['stdout'][0]
        self.assertEqual(root_data, r_data, "Data on root disk is changed")
        self.assertEqual(ephem_data, ep_data, "Data on ephemeral disk is "
                         "changed")