Exemplo n.º 1
0
    def test_instances_have_networking(self):
        """Validate North/South and East/West networking."""
        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))

        instance_2 = self.nova_client.servers.find(
            name='{}-ins-2'.format(self.RESOURCE_PREFIX))

        def verify(stdin, stdout, stderr):
            """Validate that the SSH command exited 0."""
            self.assertEqual(stdout.channel.recv_exit_status(), 0)

        # Verify network from 1 to 2
        self.validate_instance_can_reach_other(instance_1, instance_2, verify)

        # Verify network from 2 to 1
        self.validate_instance_can_reach_other(instance_2, instance_1, verify)

        # Validate tenant to external network routing
        self.validate_instance_can_reach_router(instance_1, verify)
        self.validate_instance_can_reach_router(instance_2, verify)

        # If we get here, it means the tests passed
        self.run_tearDown = True
Exemplo n.º 2
0
 def launch_guests(self):
     """Launch two guests to use in tests."""
     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))
Exemplo n.º 3
0
    def launch_guest(self, guest_name, userdata=None):
        """Launch two guests to use in tests.

        Note that it is up to the caller to have set the RESOURCE_PREFIX class
        variable prior to calling this method.

        Also note that this method will remove any already existing instance
        with same name as what is requested.

        :param guest_name: Name of instance
        :type guest_name: str
        :param userdata: Userdata to attach to instance
        :type userdata: Optional[str]
        :returns: Nova instance objects
        :rtype: Server
        """
        instance_name = '{}-{}'.format(self.RESOURCE_PREFIX, guest_name)

        instance = self.retrieve_guest(instance_name)
        if instance:
            logging.info('Removing already existing instance ({}) with '
                         'requested name ({})'.format(instance.id,
                                                      instance_name))
            openstack_utils.delete_resource(self.nova_client.servers,
                                            instance.id,
                                            msg="server")

        return configure_guest.launch_instance(glance_setup.LTS_IMAGE_NAME,
                                               vm_name=instance_name,
                                               userdata=userdata)
Exemplo n.º 4
0
 def test_launch_vtpm_1_2_instance(self):
     """Launch an instance using TPM 1.2."""
     self.RESOURCE_PREFIX = 'zaza-nova'
     instance = guest.launch_instance(
         'focal', image_name='focal', flavor_name='vtpm-1.2',
         vm_name='zaza-nova-vtpm-1-2',
     )
     # Note: TPM 1.2 presents tpm0 as a device
     self._check_tpm_device(instance, '/dev/tpm0')
Exemplo n.º 5
0
 def test_launch_vtpm_2_instance(self):
     """Launch an instance using TPM 2.0."""
     self.RESOURCE_PREFIX = 'zaza-nova'
     instance = guest.launch_instance(
         'focal', image_name='focal', flavor_name='vtpm-2',
         vm_name='zaza-nova-vtpm-2',
     )
     # Note: TPM 1.2 and 2.0 both present tpm0 as a device. TPM 2.0
     # devices also include a tpmrm0 device.
     self._check_tpm_device(instance, '/dev/tpm0', '/dev/tpmrm0')
Exemplo n.º 6
0
    def launch_guest(self,
                     guest_name,
                     userdata=None,
                     use_boot_volume=False,
                     instance_key=None):
        """Launch two guests to use in tests.

        Note that it is up to the caller to have set the RESOURCE_PREFIX class
        variable prior to calling this method.

        Also note that this method will remove any already existing instance
        with same name as what is requested.

        :param guest_name: Name of instance
        :type guest_name: str
        :param userdata: Userdata to attach to instance
        :type userdata: Optional[str]
        :param use_boot_volume: Whether to boot guest from a shared volume.
        :type use_boot_volume: boolean
        :param instance_key: Key to collect associated config data with.
        :type instance_key: Optional[str]
        :returns: Nova instance objects
        :rtype: Server
        """
        instance_key = instance_key or glance_setup.LTS_IMAGE_NAME
        instance_name = '{}-{}'.format(self.RESOURCE_PREFIX, guest_name)

        for attempt in tenacity.Retrying(stop=tenacity.stop_after_attempt(3),
                                         wait=tenacity.wait_exponential(
                                             multiplier=1, min=2, max=10)):
            with attempt:
                old_instance_with_same_name = self.retrieve_guest(
                    instance_name)
                if old_instance_with_same_name:
                    logging.info(
                        'Removing already existing instance ({}) with '
                        'requested name ({})'.format(
                            old_instance_with_same_name.id, instance_name))
                    openstack_utils.delete_resource(
                        self.nova_client.servers,
                        old_instance_with_same_name.id,
                        msg="server")

                return configure_guest.launch_instance(
                    instance_key,
                    vm_name=instance_name,
                    use_boot_volume=use_boot_volume,
                    userdata=userdata)
Exemplo n.º 7
0
    def test_snapshot_workload(self):
        """Ensure that a workload can be created and snapshot'ed."""
        # Setup volume and instance and attach one to the other
        volume = openstack_utils.create_volume(
            self.cinder_client,
            size="1",
            name="{}-100-vol".format(self.RESOURCE_PREFIX),
        )

        instance = guest_utils.launch_instance(
            glance_setup.CIRROS_IMAGE_NAME,
            vm_name="{}-server".format(self.RESOURCE_PREFIX),
        )

        # Trilio need direct access to ceph - OMG
        openstack_utils.attach_volume(self.nova_client, volume.id, instance.id)

        workloadmgrcli = WorkloadmgrCLIHelper(self.keystone_client)

        # Create workload using instance
        logging.info("Creating workload configuration")
        workload_id = workloadmgrcli.create_workload(instance.id)
        logging.info("Created workload: {}".format(workload_id))

        logging.info("Initiating snapshot")
        snapshot_id = workloadmgrcli.create_snapshot(workload_id)
        logging.info("Snapshot of workload {} created: {}".format(
            workload_id, snapshot_id))

        logging.info("Deleting server and volume ready for restore")
        openstack_utils.delete_resource(self.nova_client.servers, instance.id,
                                        "deleting instance")
        # NOTE: Trilio leaves a snapshot in place -
        #       drop before volume deletion.
        for (volume_snapshot) in self.cinder_client.volume_snapshots.list():
            openstack_utils.delete_resource(
                self.cinder_client.volume_snapshots,
                volume_snapshot.id,
                "deleting snapshot",
            )
        openstack_utils.delete_resource(self.cinder_client.volumes, volume.id,
                                        "deleting volume")

        logging.info("Initiating restore")
        workloadmgrcli.oneclick_restore(snapshot_id)
Exemplo n.º 8
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
        for attempt in Retrying(stop=stop_after_attempt(3),
                                wait=wait_exponential(multiplier=1,
                                                      min=2,
                                                      max=10)):
            with attempt:
                instance_1 = guest.launch_instance(
                    glance_setup.LTS_IMAGE_NAME,
                    vm_name='{}-ins-1'.format(self.RESOURCE_PREFIX),
                    userdata=self.INSTANCE_USERDATA.format(
                        _indent(conf, 8), _indent(keyring, 8)))

        for attempt in Retrying(stop=stop_after_attempt(3),
                                wait=wait_exponential(multiplier=1,
                                                      min=2,
                                                      max=10)):
            with attempt:
                instance_2 = guest.launch_instance(
                    glance_setup.LTS_IMAGE_NAME,
                    vm_name='{}-ins-2'.format(self.RESOURCE_PREFIX),
                    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)
Exemplo n.º 9
0
 def launch_instance(self, instance_key):
     """Deprecated: Use zaza.openstack.configure.guest.launch_instance."""
     logging.info('BaseGuestCreateTest.launch_instance is deprecated '
                  'please use '
                  'zaza.openstack.configure.guest.launch_instance')
     guest.launch_instance(instance_key)
Exemplo n.º 10
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)