Ejemplo n.º 1
0
def create_new_image(context, region_name, image_name, image_filename=None):
    """
    HELPER: Create new image using given params and step context.
    :param region_name (string): Name of the node where image will be created
    :param context (Behave Context): Behave context
    :param image_name (string): Name of the image
    :param image_file (string): Filename to be used as image.
    :return: None
    """

    __logger__.info(
        "Creating new image '%s' in region '%s'. Image filename: '%s'",
        image_name, region_name, image_filename)

    __dataset_utils__ = DatasetUtils()

    # Get Glance Manager for the given region
    glance_ops = context.glance_manager_list[region_name]
    properties = dict()
    if context.table is not None:
        for row in __dataset_utils__.prepare_data(context.table):
            if 'param_name' in row.headings:
                real_value = get_real_value_of_image_property(
                    glance_ops, row['param_value'])
                value = real_value if real_value is not None else row[
                    'param_value']
                properties.update({row['param_name']: value})

    # Create new image (pubic=True by default)
    is_public = True
    if "is_public" in properties:
        is_public = properties["is_public"]
        properties.pop("is_public")

    __logger__.debug("Is the image '%s' public?: '%s'", image_name, is_public)
    __logger__.debug("Image properties: '%s'", properties)

    # If filename is None, it will be the same as the image_name
    image_filename = image_name if image_filename is None else image_filename
    __logger__.debug("Image filename to use: '%s'", image_filename)

    glance_ops.create_image(image_name,
                            image_filename,
                            custom_properties=properties,
                            is_public=is_public)
    context.created_images_list.append(image_name)
def create_new_image(context, region_name, image_name, image_filename=None):
    """
    HELPER: Create new image using given params and step context.
    :param region_name (string): Name of the node where image will be created
    :param context (Behave Context): Behave context
    :param image_name (string): Name of the image
    :param image_file (string): Filename to be used as image.
    :return: None
    """

    __logger__.info("Creating new image '%s' in region '%s'. Image filename: '%s'",
                    image_name, region_name, image_filename)

    __dataset_utils__ = DatasetUtils()

    # Get Glance Manager for the given region
    glance_ops = context.glance_manager_list[region_name]
    properties = dict()
    if context.table is not None:
        for row in __dataset_utils__.prepare_data(context.table):
            if 'param_name' in row.headings:
                real_value = get_real_value_of_image_property(glance_ops, row['param_value'])
                value = real_value if real_value is not None else row['param_value']
                properties.update({row['param_name']: value})

    # Create new image (pubic=True by default)
    is_public = True
    if "is_public" in properties:
        is_public = properties["is_public"]
        properties.pop("is_public")

    __logger__.debug("Is the image '%s' public?: '%s'", image_name, is_public)
    __logger__.debug("Image properties: '%s'", properties)

    # If filename is None, it will be the same as the image_name
    image_filename = image_name if image_filename is None else image_filename
    __logger__.debug("Image filename to use: '%s'", image_filename)

    glance_ops.create_image(image_name, image_filename, custom_properties=properties, is_public=is_public)
    context.created_images_list.append(image_name)
Ejemplo n.º 3
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For those usages not covered by the Apache version 2.0 License please
# contact with [email protected]

__author__ = "@jframos"

from qautils.dataset.dataset_utils import DatasetUtils
import uuid

_dataset_utils = DatasetUtils()


def send_context_notification_step_helper(context, tenant_id, server_id):
    """
    STEP HELPER. This method sends a context notification to FACTS service using the given parameters.
       Behave's 'context' will have a table with the attribute values to be used in the notification.
       If they are not specified, default ones are used.
       Each row of the table is a single request (context notification) to be sent to FACTS service.
    :param context (Behave 'Context'): Behave step context
    :param tenant_id (String): TenantID
    :param server_id (String): ServierID
    :return: None
    """

    # Prepare table data and send the context notifications.
Ejemplo n.º 4
0
# For those usages not covered by the Apache version 2.0 License please
# contact with [email protected]

from behave import step
from hamcrest import assert_that, greater_than, is_
from qautils.dataset.dataset_utils import DatasetUtils
from datetime import datetime
import logging

__copyright__ = "Copyright 2015-2016"
__license__ = " Apache License, Version 2.0"

# Get logger for Behave steps
__logger__ = logger = logging.getLogger("order_steps")

__dataset_utils__ = DatasetUtils()


@step(
    u'the timestamp of image "(?P<image_name>[\w]*)" in "(?P<region1>[\w]*)" '
    u'is greater than the image in "(?P<region2>[\w]*)"')
def the_timestamp_of_image_is_greater_than(context, image_name, region1,
                                           region2):

    glance_ops_region1 = context.glance_manager_list[region1]
    image_region1 = glance_ops_region1.get_images(image_name)[
        0]  # Get the first image found with that name
    timestamp_image_region1 = getattr(image_region1, 'updated_at')
    __logger__.info(
        "'updated_at' attribute of image '%s' from region '%s': '%s'",
        image_name, region1, timestamp_image_region1)