예제 #1
0
    def setup_test_cinder_volume(self):
        """Set up the test Cinder volume into the Ceph RBD mirror environment.

        If the volume already exists, then it's returned.

        Also, if the Cinder RBD mirroring mode is 'image', the volume will
        use an explicit volume type with the appropriate replication flags.
        Otherwise, it is just a simple Cinder volume using the default backend.

        :returns: Cinder volume
        :rtype: :class:`Volume`.
        """
        session = openstack.get_overcloud_keystone_session()
        cinder = openstack.get_cinder_session_client(session, version=3)

        try:
            return cinder.volumes.find(name=self.test_cinder_volume_name)
        except cinder_exceptions.NotFound:
            logging.info("Test Cinder volume doesn't exist. Creating it")

        glance = openstack.get_glance_session_client(session)
        image = get_glance_image(glance)
        kwargs = {
            'cinder': cinder,
            'name': self.test_cinder_volume_name,
            'image_id': image.id,
        }
        if get_cinder_rbd_mirroring_mode(self.cinder_ceph_app_name) == 'image':
            volume_type = setup_cinder_repl_volume_type(
                cinder, backend_name=self.cinder_ceph_app_name)
            kwargs['type_id'] = volume_type.id

        return create_cinder_volume(**kwargs)
예제 #2
0
def add_image(image_url, glance_client=None, image_name=None, tags=[],
              properties=None):
    """Retrieve image from ``image_url`` and add it to glance.

    :param image_url: Retrievable URL with image data
    :type image_url: str
    :param glance: Authenticated glanceclient
    :type glance: glanceclient.Client
    :param image_name: Label for the image in glance
    :type image_name: str
    :param tags: List of tags to add to image
    :type tags: list of str
    :param properties: Properties to add to image
    :type properties: dict
    """
    if not glance_client:
        keystone_session = openstack_utils.get_overcloud_keystone_session()
        glance_client = openstack_utils.get_glance_session_client(
            keystone_session)
    if image_name:
        image = openstack_utils.get_images_by_name(
            glance_client, image_name)

    if image:
        logging.warning('Using existing glance image "{}" ({})'
                        .format(image_name, image[0].id))
    else:
        logging.info('Downloading image {}'.format(image_name or image_url))
        openstack_utils.create_image(
            glance_client,
            image_url,
            image_name,
            tags=tags,
            properties=properties)
예제 #3
0
 def setUpClass(cls):
     """Run class setup for running glance tests with cinder backend."""
     super(GlanceCinderBackendTest, cls).setUpClass()
     cls.glance_client = openstack_utils.get_glance_session_client(
         cls.keystone_session)
     cls.cinder_client = openstack_utils.get_cinder_session_client(
         cls.keystone_session)
예제 #4
0
 def setUpClass(cls):
     """Run class setup for running glance simple streams sync tests."""
     super(GlanceSimpleStreamsSyncTest, cls).setUpClass()
     # dict of OS_* env vars
     overcloud_auth = openstack_utils.get_overcloud_auth()
     cls.keystone_client = openstack_utils.get_keystone_client(
         overcloud_auth)
     cls.glance_client = openstack_utils.get_glance_session_client(
         cls.keystone_session)
예제 #5
0
    def setUpClass(cls):
        """Run class setup for running glance tests."""
        super(GlanceCephRGWBackendTest, cls).setUpClass()

        swift_session = openstack_utils.get_keystone_session_from_relation(
            'ceph-radosgw')
        cls.swift = openstack_utils.get_swift_session_client(swift_session)
        cls.glance_client = openstack_utils.get_glance_session_client(
            cls.keystone_session)
예제 #6
0
    def setUpClass(cls):
        """Run class setup for running tests."""
        super(SwiftImageCreateTest, cls).setUpClass()
        cls.image_name = 'zaza-swift-lts'
        swift_session = openstack_utils.get_keystone_session_from_relation(
            'swift-proxy')

        cls.swift = openstack_utils.get_swift_session_client(swift_session)
        cls.glance_client = openstack_utils.get_glance_session_client(
            cls.keystone_session)
예제 #7
0
 def setUpClass(cls):
     """Run class setup for running Heat tests."""
     super(HeatBasicDeployment, cls).setUpClass()
     cls.application = 'heat'
     cls.keystone_session = openstack_utils.get_overcloud_keystone_session()
     cls.heat_client = openstack_utils.get_heat_session_client(
         cls.keystone_session)
     cls.glance_client = openstack_utils.get_glance_session_client(
         cls.keystone_session)
     cls.nova_client = openstack_utils.get_nova_session_client(
         cls.keystone_session)
예제 #8
0
    def setUpClass(cls):
        """Run class setup for running glance tests with S3 backend."""
        super(GlanceExternalS3Test, cls).setUpClass()
        cls.glance_client = openstack_utils.get_glance_session_client(
            cls.keystone_session)

        configs = model.get_application_config("glance")
        cls.s3_store_host = configs["s3-store-host"]["value"]
        cls.s3_store_access_key = configs["s3-store-access-key"]["value"]
        cls.s3_store_secret_key = configs["s3-store-secret-key"]["value"]
        cls.s3_store_bucket = configs["s3-store-bucket"]["value"]
예제 #9
0
    def test_retrofit_image_source_image(self):
        """Run ``retrofit-image`` action specifying source image."""
        session = openstack.get_overcloud_keystone_session()
        glance = openstack.get_glance_session_client(session)

        for image in glance.images.list(filters={
                'os_distro': 'ubuntu',
                'os_version': '18.04'
        }):
            action = zaza.model.run_action(
                'octavia-diskimage-retrofit/0',
                'retrofit-image',
                action_params={'source-image': image.id})
            self.assertEqual(action.status, 'completed')
            break
예제 #10
0
def add_glance_config(ctxt, keystone_session):
    """Add glance config to context.

    :param ctxt: Context dictionary
    :type ctxt: dict
    :param keystone_session: keystoneauth1.session.Session object
    :type: keystoneauth1.session.Session
    :returns: None
    :rtype: None
    """
    glance_client = openstack_utils.get_glance_session_client(keystone_session)
    image = openstack_utils.get_images_by_name(glance_client,
                                               glance_setup.CIRROS_IMAGE_NAME)
    image_alt = openstack_utils.get_images_by_name(
        glance_client, glance_setup.CIRROS_ALT_IMAGE_NAME)
    if image:
        ctxt['image_id'] = image[0].id
    if image_alt:
        ctxt['image_alt_id'] = image_alt[0].id
예제 #11
0
    def get_client_and_attempt_operation(self, ip):
        """Attempt to list the images as a policyd override.

        This operation should pass normally for the demo_user, and fail when
        the rule has been overriden (see the `rule` class variable.

        :param ip: the IP address to get the session against.
        :type ip: str
        :raises: PolicydOperationFailedException if operation fails.
        """
        glance_client = openstack_utils.get_glance_session_client(
            self.get_keystone_session_demo_user(ip))
        try:
            # NOTE(ajkavanagh) - it turns out that the list() is very important
            # as it forces the generator to iterate which only then checkes if
            # the api call is authorized.  Just getting the generator (from
            # .list()) doesn't perform the API call.
            images = list(glance_client.images.list())
            logging.debug("images is: {}".format(images))
        except glanceclient.common.exceptions.HTTPForbidden:
            raise PolicydOperationFailedException()
예제 #12
0
def _get_default_glance_client():
    """Create default Glance client using overcloud credentials."""
    keystone_session = openstack_utils.get_overcloud_keystone_session()
    glance_client = openstack_utils.get_glance_session_client(keystone_session)
    return glance_client
예제 #13
0
 def setUpClass(cls):
     """Run class setup for running glance tests."""
     super(GlanceTest, cls).setUpClass()
     cls.glance_client = openstack_utils.get_glance_session_client(
         cls.keystone_session)
예제 #14
0
    def test_cinder_volume_mirrored(self):
        """Validate that a volume created through Cinder is mirrored.

        For RBD Mirroring to work clients must enable the correct set of
        features when creating images.

        The RBD image feature settings are announced by the ``ceph-mon`` charm
        over the client relation when it has units related on its
        ``rbd-mirror`` endpoint.

        By creating a volume through cinder on site A, checking for presence on
        site B and subsequently comparing the contents we get a full end to end
        test.
        """
        session = openstack.get_overcloud_keystone_session()
        glance = openstack.get_glance_session_client(session)
        cinder = openstack.get_cinder_session_client(session)

        image = next(glance.images.list(name=LTS_IMAGE_NAME))

        # NOTE(fnordahl): for some reason create volume from image often fails
        # when run just after deployment is finished.  We should figure out
        # why, resolve the underlying issue and then remove this.
        #
        # We do not use tenacity here as it will interfere with tenacity used
        # in ``resource_reaches_status``
        def create_volume_from_image(cinder, image, retry=20):
            if retry < 1:
                return
            volume = cinder.volumes.create(8, name='zaza', imageRef=image.id)
            try:
                # Note(coreycb): stop_after_attempt is increased because using
                # juju storage for ceph-osd backed by cinder on undercloud
                # takes longer than the prior method of directory-backed OSD
                # devices.
                openstack.resource_reaches_status(cinder.volumes,
                                                  volume.id,
                                                  msg='volume',
                                                  stop_after_attempt=20)
                return volume
            except AssertionError:
                logging.info('retrying')
                volume.delete()
                return create_volume_from_image(cinder, image, retry=retry - 1)

        volume = create_volume_from_image(cinder, image)

        site_a_hash = zaza.openstack.utilities.ceph.get_rbd_hash(
            zaza.model.get_lead_unit_name('ceph-mon',
                                          model_name=self.site_a_model),
            'cinder-ceph',
            'volume-{}'.format(volume.id),
            model_name=self.site_a_model)
        self.wait_for_mirror_state('up+replaying',
                                   check_entries_behind_master=True,
                                   application_name=self.application_name +
                                   self.site_b_app_suffix,
                                   model_name=self.site_b_model)
        site_b_hash = zaza.openstack.utilities.ceph.get_rbd_hash(
            zaza.model.get_lead_unit_name('ceph-mon' + self.site_b_app_suffix,
                                          model_name=self.site_b_model),
            'cinder-ceph',
            'volume-{}'.format(volume.id),
            model_name=self.site_b_model)
        logging.info(site_a_hash)
        logging.info(site_b_hash)
        self.assertEqual(site_a_hash, site_b_hash)