Пример #1
0
    def test_manila_share(self):
        """Test that a Manila share 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=self.share_type_name,
            name=self.share_name,
            share_proto=self.share_protocol,
            share_network=self.share_network,
            size=1)

        # Spawn Servers
        instance_1 = self.launch_guest(
            guest_name='ins-1',
            userdata=self.INSTANCE_USERDATA,
            instance_key=self.INSTANCE_KEY)
        instance_2 = self.launch_guest(
            guest_name='ins-2',
            userdata=self.INSTANCE_USERDATA,
            instance_key=self.INSTANCE_KEY)

        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")

        # Grant access to the Manila share for both Nova instances.
        share.allow(access_type='ip', access=fip_1, access_level='rw')
        share.allow(access_type='ip', access=fip_2, access_level='rw')

        ssh_user_name = guest.boot_tests[self.INSTANCE_KEY]['username']
        privkey = openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME)
        share_path = share.export_locations[0]

        # Write a testing file on instance #1
        self._mount_share_on_instance(
            fip_1, ssh_user_name, privkey, share_path)
        self._write_testing_file_on_instance(
            fip_1, ssh_user_name, privkey)

        # Validate the testing file from instance #2
        self._mount_share_on_instance(
            fip_2, ssh_user_name, privkey, share_path)
        self._validate_testing_file_from_instance(
            fip_2, ssh_user_name, privkey)
Пример #2
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)
Пример #3
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)
Пример #4
0
    def tearDownClass(cls):
        """Run class teardown after tests finished."""
        # Cleanup Nova servers
        logging.info('Cleaning up test Nova servers')
        fips_reservations = []
        for vm in cls.nova_client.servers.list():
            fips_reservations += neutron_tests.floating_ips_from_instance(vm)
            vm.delete()
            openstack_utils.resource_removed(
                cls.nova_client.servers,
                vm.id,
                msg="Waiting for the Nova VM {} to be deleted".format(vm.name))

        # Delete FiPs reservations
        logging.info('Cleaning up test FiPs reservations')
        neutron = openstack_utils.get_neutron_session_client(
            session=cls.keystone_session)
        for fip in neutron.list_floatingips()['floatingips']:
            if fip['floating_ip_address'] in fips_reservations:
                neutron.delete_floatingip(fip['id'])

        # Cleanup Manila shares
        logging.info('Cleaning up test shares')
        for share in cls.manila_client.shares.list():
            share.delete()
            openstack_utils.resource_removed(
                cls.manila_client.shares,
                share.id,
                msg="Waiting for the Manila share {} to be deleted".format(
                    share.name))

        # Cleanup test Manila share servers (spawned by the driver when DHSS
        # is enabled).
        logging.info('Cleaning up test shares servers (if found)')
        for server in cls.manila_client.share_servers.list():
            server.delete()
            openstack_utils.resource_removed(
                cls.manila_client.share_servers,
                server.id,
                msg="Waiting for the share server {} to be deleted".format(
                    server.id))
Пример #5
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)
    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)