コード例 #1
0
ファイル: tests.py プロジェクト: wolsen/zaza-openstack-tests
    def _mount_share_on_instance(self, instance_ip, ssh_user_name,
                                 ssh_private_key, share_path):
        """Mount a share into a Nova instance.

        The mount command is executed via SSH.

        :param instance_ip: IP of the Nova instance.
        :type instance_ip: string
        :param ssh_user_name: SSH user name.
        :type ssh_user_name: string
        :param ssh_private_key: SSH private key.
        :type ssh_private_key: string
        :param share_path: Share network path.
        :type share_path: string
        """
        ssh_cmd = ('sudo mkdir -p {0} && '
                   'sudo mount -t {1} -o {2} {3} {0}'.format(
                       self.mount_dir, self.share_protocol,
                       self._get_mount_options(), share_path))

        for attempt in tenacity.Retrying(stop=tenacity.stop_after_attempt(5),
                                         wait=tenacity.wait_exponential(
                                             multiplier=3, min=2, max=10)):
            with attempt:
                openstack_utils.ssh_command(
                    vm_name="instance-{}".format(instance_ip),
                    ip=instance_ip,
                    username=ssh_user_name,
                    privkey=ssh_private_key,
                    command=ssh_cmd,
                    verify=verify_status)
コード例 #2
0
    def validate_instance_can_reach_router(self, instance, verify):
        """
        Validate that an instance can reach it's primary gateway.

        We make the assumption that the router's IP is 192.168.0.1
        as that's the network that is setup in
        neutron.setup.basic_overcloud_network which is used in all
        Zaza Neutron validations.

        :param instance: The instance to check networking from
        :type instance: nova_client.Server
        """
        address = floating_ips_from_instance(instance)[0]

        username = guest.boot_tests['bionic']['username']
        password = guest.boot_tests['bionic'].get('password')
        privkey = openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME)

        openstack_utils.ssh_command(username,
                                    address,
                                    'instance',
                                    'ping -c 1 192.168.0.1',
                                    password=password,
                                    privkey=privkey,
                                    verify=verify)
        pass
コード例 #3
0
    def validate_instance_can_reach_other(self,
                                          instance_1,
                                          instance_2,
                                          verify):
        """
        Validate that an instance can reach a fixed and floating of another.

        :param instance_1: The instance to check networking from
        :type instance_1: nova_client.Server

        :param instance_2: The instance to check networking from
        :type instance_2: nova_client.Server
        """
        floating_1 = floating_ips_from_instance(instance_1)[0]
        floating_2 = floating_ips_from_instance(instance_2)[0]
        address_2 = fixed_ips_from_instance(instance_2)[0]

        username = guest.boot_tests['bionic']['username']
        password = guest.boot_tests['bionic'].get('password')
        privkey = openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME)

        openstack_utils.ssh_command(
            username, floating_1, 'instance-1',
            'ping -c 1 {}'.format(address_2),
            password=password, privkey=privkey, verify=verify)

        openstack_utils.ssh_command(
            username, floating_1, 'instance-1',
            'ping -c 1 {}'.format(floating_2),
            password=password, privkey=privkey, verify=verify)
コード例 #4
0
    def _check_tpm_device(self, instance, *devices):
        """Check that the instance has TPM devices available.

        :param instance: the instance to determine if TPM devices are available
        :type instance: nova_client.Server instance
        :param devices: the devices to look for that are present in the guest
        :type devices: list of strings
        :return: True if the instance has TPM devices, False otherwise
        :rtype: bool
        """
        fip = neutron_tests.floating_ips_from_instance(instance)[0]
        username = guest.boot_tests['focal']['username']
        password = guest.boot_tests['focal'].get('password')
        privkey = openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME)

        def check_tpm(stdin, stdout, stderr):
            devs = [line.strip() for line in stdout.readlines()]
            for expected in devices:
                self.assertIn(expected, devs)

        logging.info('Validating TPM devices are present')
        openstack_utils.ssh_command(username, ip=fip, vm_name=instance.name,
                                    command='sudo ls -1 /dev/tpm*',
                                    password=password, privkey=privkey,
                                    verify=check_tpm)
コード例 #5
0
    def test_cephfs_share(self):
        """Test that CephFS shares can be accessed on two instances.

        1. Spawn two servers
        2. mount it on both
        3. write a file on one
        4. read it on the other
        5. profit
        """
        keyring = model.run_on_leader(
            'ceph-mon', 'cat /etc/ceph/ceph.client.admin.keyring')['Stdout']
        conf = model.run_on_leader('ceph-mon',
                                   'cat /etc/ceph/ceph.conf')['Stdout']
        # Spawn Servers
        instance_1, instance_2 = self.launch_guests(
            userdata=self.INSTANCE_USERDATA.format(_indent(conf, 8),
                                                   _indent(keyring, 8)))

        # Write a file on instance_1
        def verify_setup(stdin, stdout, stderr):
            status = stdout.channel.recv_exit_status()
            self.assertEqual(status, 0)

        fip_1 = neutron_tests.floating_ips_from_instance(instance_1)[0]
        fip_2 = neutron_tests.floating_ips_from_instance(instance_2)[0]
        username = guest.boot_tests['bionic']['username']
        password = guest.boot_tests['bionic'].get('password')
        privkey = openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME)

        for attempt in Retrying(stop=stop_after_attempt(3),
                                wait=wait_exponential(multiplier=1,
                                                      min=2,
                                                      max=10)):
            with attempt:
                openstack_utils.ssh_command(
                    username,
                    fip_1,
                    'instance-1', 'sudo mount -a && '
                    'echo "test" | sudo tee /mnt/cephfs/test',
                    password=password,
                    privkey=privkey,
                    verify=verify_setup)

        def verify(stdin, stdout, stderr):
            status = stdout.channel.recv_exit_status()
            self.assertEqual(status, 0)
            out = ""
            for line in iter(stdout.readline, ""):
                out += line
            self.assertEqual(out, "test\n")

        openstack_utils.ssh_command(username,
                                    fip_2,
                                    'instance-2', 'sudo mount -a && '
                                    'sudo cat /mnt/cephfs/test',
                                    password=password,
                                    privkey=privkey,
                                    verify=verify)
コード例 #6
0
    def validate_instance_can_reach_other(self,
                                          instance_1,
                                          instance_2,
                                          verify,
                                          mtu=None):
        """
        Validate that an instance can reach a fixed and floating of another.

        :param instance_1: The instance to check networking from
        :type instance_1: nova_client.Server

        :param instance_2: The instance to check networking from
        :type instance_2: nova_client.Server

        :param verify: callback to verify result
        :type verify: callable

        :param mtu: Check that we can send non-fragmented packets of given size
        :type mtu: Optional[int]
        """
        floating_1 = floating_ips_from_instance(instance_1)[0]
        floating_2 = floating_ips_from_instance(instance_2)[0]
        address_2 = fixed_ips_from_instance(instance_2)[0]

        username = guest.boot_tests['bionic']['username']
        password = guest.boot_tests['bionic'].get('password')
        privkey = openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME)

        cmds = [
            'ping -c 1',
        ]
        if mtu:
            # the on-wire packet will be 28 bytes larger than the value
            # provided to ping(8) -s parameter
            packetsize = mtu - 28
            cmds.append('ping -M do -s {} -c 1'.format(packetsize))

        for cmd in cmds:
            openstack_utils.ssh_command(username,
                                        floating_1,
                                        'instance-1',
                                        '{} {}'.format(cmd, address_2),
                                        password=password,
                                        privkey=privkey,
                                        verify=verify)

            openstack_utils.ssh_command(username,
                                        floating_1,
                                        'instance-1',
                                        '{} {}'.format(cmd, floating_2),
                                        password=password,
                                        privkey=privkey,
                                        verify=verify)
コード例 #7
0
    def validate_instance_can_reach_router(self, instance, verify, mtu=None):
        """
        Validate that an instance can reach it's primary gateway.

        We make the assumption that the router's IP is 192.168.0.1
        as that's the network that is setup in
        neutron.setup.basic_overcloud_network which is used in all
        Zaza Neutron validations.

        :param instance: The instance to check networking from
        :type instance: nova_client.Server

        :param verify: callback to verify result
        :type verify: callable

        :param mtu: Check that we can send non-fragmented packets of given size
        :type mtu: Optional[int]
        """
        address = floating_ips_from_instance(instance)[0]

        username = guest.boot_tests['bionic']['username']
        password = guest.boot_tests['bionic'].get('password')
        privkey = openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME)

        cmds = [
            'ping -c 1',
        ]
        if mtu:
            # the on-wire packet will be 28 bytes larger than the value
            # provided to ping(8) -s parameter
            packetsize = mtu - 28
            cmds.append('ping -M do -s {} -c 1'.format(packetsize))

        for cmd in cmds:
            openstack_utils.ssh_command(username,
                                        address,
                                        'instance',
                                        '{} 192.168.0.1'.format(cmd),
                                        password=password,
                                        privkey=privkey,
                                        verify=verify)
コード例 #8
0
ファイル: tests.py プロジェクト: wolsen/zaza-openstack-tests
    def _validate_testing_file_from_instance(self, instance_ip, ssh_user_name,
                                             ssh_private_key):
        """Validate a file from the Manila share mounted into a Nova instance.

        This is meant to run after the testing file was already written into
        another Nova instance. It validates the written file. The commands are
        executed via SSH.

        :param instance_ip: IP of the Nova instance.
        :type instance_ip: string
        :param ssh_user_name: SSH user name.
        :type ssh_user_name: string
        :param ssh_private_key: SSH private key.
        :type ssh_private_key: string
        """
        openstack_utils.ssh_command(vm_name="instance-{}".format(instance_ip),
                                    ip=instance_ip,
                                    username=ssh_user_name,
                                    privkey=ssh_private_key,
                                    command='sudo cat {}/test'.format(
                                        self.mount_dir),
                                    verify=verify_manila_testing_file)
コード例 #9
0
ファイル: tests.py プロジェクト: wolsen/zaza-openstack-tests
    def _clear_testing_file_on_instance(self, instance_ip, ssh_user_name,
                                        ssh_private_key):
        """Clear a file on a Manila share mounted into a Nova instance.

        Remove a testing file into the already mounted Manila share from the
        given Nova instance (which is meant to be validated from another
        instance). These commands are executed via SSH.

        :param instance_ip: IP of the Nova instance.
        :type instance_ip: string
        :param ssh_user_name: SSH user name.
        :type ssh_user_name: string
        :param ssh_private_key: SSH private key.
        :type ssh_private_key: string
        """
        openstack_utils.ssh_command(vm_name="instance-{}".format(instance_ip),
                                    ip=instance_ip,
                                    username=ssh_user_name,
                                    privkey=ssh_private_key,
                                    command='sudo rm {}/test'.format(
                                        self.mount_dir),
                                    verify=verify_status)
コード例 #10
0
    def test_ssh_command(self):
        paramiko_mock = mock.MagicMock()
        self.patch_object(openstack_utils.paramiko,
                          'SSHClient',
                          return_value=paramiko_mock)
        self.patch_object(openstack_utils.paramiko,
                          'AutoAddPolicy',
                          return_value='some_policy')
        stdout = io.StringIO("myvm")

        paramiko_mock.exec_command.return_value = ('stdin', stdout, 'stderr')

        def verifier(_stdin, stdout, _stderr):
            self.assertEqual('myvm', stdout.readlines()[0].strip())

        openstack_utils.ssh_command('bob',
                                    '10.0.0.10',
                                    'myvm',
                                    'uname -n',
                                    password='******',
                                    verify=verifier)
        paramiko_mock.connect.assert_called_once_with(
            '10.0.0.10', password='******', username='******')
コード例 #11
0
    def test_manila_share(self):
        """Test that Manila + Ganesha shares can be accessed on two instances.

        1. create a share
        2. Spawn two servers
        3. mount it on both
        4. write a file on one
        5. read it on the other
        6. profit
        """
        # Create a share
        share = self.manila_client.shares.create(
            share_type='cephfsnfstype', name='cephnfsshare1',
            share_proto="nfs", size=1)

        # Spawn Servers
        instance_1 = guest.launch_instance(
            glance_setup.LTS_IMAGE_NAME,
            vm_name='{}-ins-1'.format(self.RESOURCE_PREFIX),
            userdata=self.INSTANCE_USERDATA)
        instance_2 = guest.launch_instance(
            glance_setup.LTS_IMAGE_NAME,
            vm_name='{}-ins-2'.format(self.RESOURCE_PREFIX),
            userdata=self.INSTANCE_USERDATA)

        fip_1 = neutron_tests.floating_ips_from_instance(instance_1)[0]
        fip_2 = neutron_tests.floating_ips_from_instance(instance_2)[0]

        # Wait for the created share to become available before it gets used.
        openstack_utils.resource_reaches_status(
            self.manila_client.shares,
            share.id,
            wait_iteration_max_time=120,
            stop_after_attempt=2,
            expected_status="available",
            msg="Waiting for a share to become available")

        share.allow(access_type='ip', access=fip_1, access_level='rw')
        share.allow(access_type='ip', access=fip_2, access_level='rw')

        # Mount Share
        username = guest.boot_tests['bionic']['username']
        password = guest.boot_tests['bionic'].get('password')
        privkey = openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME)

        # Write a file on instance_1
        def verify_setup(stdin, stdout, stderr):
            status = stdout.channel.recv_exit_status()
            self.assertEqual(status, 0)

        mount_path = share.export_locations[0]

        for attempt in Retrying(
                stop=stop_after_attempt(3),
                wait=wait_exponential(multiplier=1, min=2, max=10)):
            with attempt:
                openstack_utils.ssh_command(
                    username, fip_1, 'instance-1',
                    'sudo mkdir -p /mnt/ceph && '
                    'sudo mount -t nfs -o nfsvers=4.1,proto=tcp '
                    '{} /mnt/ceph && '
                    'echo "test" | sudo tee /mnt/ceph/test'.format(
                        mount_path),
                    password=password, privkey=privkey, verify=verify_setup)

        for attempt in Retrying(
                stop=stop_after_attempt(3),
                wait=wait_exponential(multiplier=1, min=2, max=10)):
            with attempt:
                # Setup that file on instance_2
                openstack_utils.ssh_command(
                    username, fip_2, 'instance-2',
                    'sudo mkdir -p /mnt/ceph && '
                    'sudo /bin/mount -t nfs -o nfsvers=4.1,proto=tcp '
                    '{} /mnt/ceph'
                    .format(mount_path),
                    password=password, privkey=privkey, verify=verify_setup)

        def verify(stdin, stdout, stderr):
            status = stdout.channel.recv_exit_status()
            self.assertEqual(status, 0)
            out = ""
            for line in iter(stdout.readline, ""):
                out += line
            self.assertEqual(out, "test\n")

        openstack_utils.ssh_command(
            username, fip_2, 'instance-2',
            'sudo cat /mnt/ceph/test',
            password=password, privkey=privkey, verify=verify)
コード例 #12
0
    def test_manila_share(self):
        """Test that Manila + Ganesha shares can be accessed on two instances.

        1. create a share
        2. Spawn two servers
        3. mount it on both
        4. write a file on one
        5. read it on the other
        6. profit
        """

        # Create Share
        share = self.manila_client.shares.create(share_type='cephfsnfstype',
                                                 name='cephnfsshare1',
                                                 share_proto="nfs",
                                                 size=1)

        # Spawn Servers
        guest.launch_instance(glance_setup.LTS_IMAGE_NAME,
                              vm_name='{}-ins-1'.format(self.RESOURCE_PREFIX))
        guest.launch_instance(glance_setup.LTS_IMAGE_NAME,
                              vm_name='{}-ins-2'.format(self.RESOURCE_PREFIX))

        instance_1 = self.nova_client.servers.find(
            name='{}-ins-1'.format(self.RESOURCE_PREFIX))
        fip_1 = neutron_tests.floating_ips_from_instance(instance_1)[0]
        instance_2 = self.nova_client.servers.find(
            name='{}-ins-2'.format(self.RESOURCE_PREFIX))
        fip_2 = neutron_tests.floating_ips_from_instance(instance_2)[0]

        share.allow(access_type='ip', access=fip_1, access_level='rw')
        share.allow(access_type='ip', access=fip_2, access_level='rw')

        # Mount Share

        username = guest.boot_tests['bionic']['username']
        password = guest.boot_tests['bionic'].get('password')
        privkey = openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME)
        mount_path = share.export_locations[0]

        # Write a file on instance_1

        def verify_setup(stdin, stdout, stderr):
            status = stdout.channel.recv_exit_status()
            self.assertEqual(status, 0)

        openstack_utils.ssh_command(
            username,
            fip_1,
            'instance-1',
            'sudo apt install -yq nfs-common && '
            'sudo mkdir -p /mnt/ceph && '
            'sudo mount -t nfs -o nfsvers=4.1,proto=tcp {} /mnt/ceph && '
            'echo "test" | sudo tee /mnt/ceph/test'.format(mount_path),
            password=password,
            privkey=privkey,
            verify=verify_setup)

        openstack_utils.ssh_command(
            username,
            fip_2,
            'instance-2',
            'sudo apt install -yq nfs-common && '
            'sudo /bin/mkdir -p /mnt/ceph && '
            'sudo /bin/mount -t nfs -o nfsvers=4.1,proto=tcp {} /mnt/ceph'.
            format(mount_path),
            password=password,
            privkey=privkey,
            verify=verify_setup)

        def verify(stdin, stdout, stderr):
            status = stdout.channel.recv_exit_status()
            out = ""
            print("[{}] Stdout:".format(status))
            for line in iter(stdout.readline, ""):
                out += line
            self.assertEqual(out, "test\n")

        # Read that file on instance_2

        openstack_utils.ssh_command(
            username,
            fip_2,
            'instance-2',
            'sudo cat /mnt/ceph/test'.format(mount_path),
            password=password,
            privkey=privkey,
            verify=verify)