Esempio n. 1
0
    def test_merge_templates_object_storage(self, mock_merge):
        # Setup
        overcloud_roles = {'controller': 1, 'overcloud-swift-storage': 12}

        # Test
        template_tools.merge_templates(overcloud_roles)

        # Verify
        mock_merge.assert_called_once_with(
            [
                '/etc/tuskar/tripleo-heat-templates/overcloud-source.yaml',
                '/etc/tuskar/tripleo-heat-templates/block-storage.yaml',
                '/etc/tuskar/tripleo-heat-templates/swift-source.yaml',
                '/etc/tuskar/tripleo-heat-templates/swift-storage-source.yaml',
                '/etc/tuskar/tripleo-heat-templates/ssl-source.yaml',
                '/etc/tuskar/tripleo-heat-templates/swift-deploy.yaml',
                '/etc/tuskar/tripleo-heat-templates/nova-compute-config.yaml'
            ],
            None,
            None,
            scaling={
                'NovaCompute0': (0, frozenset()),
                'SwiftStorage0': (12, frozenset()),
                'BlockStorage0': (0, frozenset()),
            },
            included_template_dir='/etc/tuskar/tripleo-heat-templates/')
Esempio n. 2
0
    def test_merge_templates_object_storage(self, mock_merge):
        # Setup
        overcloud_roles = {'controller': 1, 'overcloud-swift-storage': 12}

        # Test
        template_tools.merge_templates(overcloud_roles)

        # Verify
        mock_merge.assert_called_once_with(
            [
                '/etc/tuskar/tripleo-heat-templates/overcloud-source.yaml',
                '/etc/tuskar/tripleo-heat-templates/block-storage.yaml',
                '/etc/tuskar/tripleo-heat-templates/swift-source.yaml',
                '/etc/tuskar/tripleo-heat-templates/swift-storage-source.yaml',
                '/etc/tuskar/tripleo-heat-templates/ssl-source.yaml',
                '/etc/tuskar/tripleo-heat-templates/swift-deploy.yaml',
                '/etc/tuskar/tripleo-heat-templates/nova-compute-config.yaml'
            ],
            None,
            None,
            scaling={
                'NovaCompute0': (0, frozenset()),
                'SwiftStorage0': (12, frozenset()),
                'BlockStorage0': (0, frozenset()),
            },
            included_template_dir='/etc/tuskar/tripleo-heat-templates/'
        )
Esempio n. 3
0
    def template_parameters(self):
        # TODO(lsmola) returning all possible parameters now, later in J
        # user should pick what to build first and we should return
        # appropriate parameters.
        fixed_params = {template_tools.OVERCLOUD_COMPUTE_ROLE: 1,
                        template_tools.OVERCLOUD_VOLUME_ROLE: 1,
                        template_tools.OVERCLOUD_OBJECT_STORAGE_ROLE: 1}

        # We don't want user to fill flavor based parameters, cause
        # it is already stored in OvercloudRoles, also Image parameters
        # are expected to be default, otherwise our associations
        # will not work.
        except_parameters = ('OvercloudControlFlavor',
                             'OvercloudComputeFlavor',
                             'OvercloudBlockStorageFlavor',
                             'OvercloudSwiftStorageFlavor',
                             'NovaImage',
                             'notcomputeImage',
                             'BlockStorageImage',
                             'SwiftStorageImage',)

        overcloud = template_tools.merge_templates(fixed_params)

        heat_client = HeatClient()
        try:
            allowed_data = heat_client.validate_template(overcloud)
        except Exception as e:
            raise exception.HeatTemplateValidateFailed(unicode(e))

        # Send back only wanted parameters
        template_parameters = dict((key, value) for key, value
                                   in allowed_data['Parameters'].items()
                                   if key not in except_parameters)

        return template_parameters
Esempio n. 4
0
    def test_merge_templates(self, mock_merge):
        # Setup
        overcloud_roles = {'controller': 1, 'overcloud-compute': 12}

        # Test
        template_tools.merge_templates(overcloud_roles)

        # Verify
        mock_merge.assert_called_once_with([
            '/etc/tuskar/tripleo-heat-templates/overcloud-source.yaml',
            '/etc/tuskar/tripleo-heat-templates/ssl-source.yaml',
            '/etc/tuskar/tripleo-heat-templates/swift-source.yaml'],
            None,
            None,
            scaling={
                'NovaCompute0': 12
            },
            included_template_dir='/etc/tuskar/tripleo-heat-templates/'
        )
    def test_merge_templates_block_storage(self, mock_merge):
        # Setup
        overcloud_roles = {'controller': 1, 'overcloud-cinder-volume': 12}

        # Test
        template_tools.merge_templates(overcloud_roles)

        # Verify
        mock_merge.assert_called_once_with([
            '/etc/tuskar/tripleo-heat-templates/overcloud-source.yaml',
            '/etc/tuskar/tripleo-heat-templates/block-storage.yaml',
            '/etc/tuskar/tripleo-heat-templates/swift-source.yaml',
            '/etc/tuskar/tripleo-heat-templates/swift-storage-source.yaml',
            '/etc/tuskar/tripleo-heat-templates/ssl-source.yaml', ],
            None,
            None,
            scaling={
                'NovaCompute0': 0, 'SwiftStorage0': 0, 'BlockStorage0': 12,
            },
            included_template_dir='/etc/tuskar/tripleo-heat-templates/'
        )
Esempio n. 6
0
def process_stack(attributes, counts, create=False):
    """Helper function for processing the stack.

    Given a params dict containing the Overcloud Roles and initialization
    parameters create or update the stack.

    :param attributes: Dictionary of initialization params and overcloud roles
                       for heat template and initialization of stack
    :type  attributes: dict

    :param counts: Dictionary of counts of roles to be deployed
    :type  counts: dict

    :param create: A flag to designate if we are creating or updating the stack
    :type create: bool
    """

    overcloud = template_tools.merge_templates(parse_counts(counts))
    heat_client = HeatClient()

    stack_exists = heat_client.exists_stack()
    valid, allowed_data = heat_client.validate_template(overcloud)

    if not valid:
        raise exception.InvalidHeatTemplate()

    if stack_exists and create:
        raise exception.StackAlreadyCreated()

    elif not stack_exists and not create:
        raise exception.StackNotFound()

    if create:
        operation = heat_client.create_stack
    else:
        operation = heat_client.update_stack

    res = operation(overcloud, filter_template_attributes(allowed_data, attributes))

    if not res:
        if create:
            raise exception.HeatTemplateCreateFailed()

        raise exception.HeatTemplateUpdateFailed()
Esempio n. 7
0
    def template_parameters(self):
        # TODO(lsmola) returning all possible parameters now, later in J
        # user should pick what to build first and we should return
        # appropriate parameters.
        fixed_params = {
            template_tools.OVERCLOUD_COMPUTE_ROLE: 1,
            template_tools.OVERCLOUD_VOLUME_ROLE: 1,
            template_tools.OVERCLOUD_OBJECT_STORAGE_ROLE: 1
        }

        # We don't want user to fill flavor based parameters, cause
        # it is already stored in OvercloudRoles, also Image parameters
        # are expected to be default, otherwise our associations
        # will not work.
        except_parameters = (
            'OvercloudControlFlavor',
            'OvercloudComputeFlavor',
            'OvercloudBlockStorageFlavor',
            'OvercloudSwiftStorageFlavor',
            'NovaImage',
            'notcomputeImage',
            'BlockStorageImage',
            'SwiftStorageImage',
        )

        overcloud = template_tools.merge_templates(fixed_params)

        heat_client = HeatClient()
        try:
            allowed_data = heat_client.validate_template(overcloud)
        except Exception as e:
            raise exception.HeatTemplateValidateFailed(unicode(e))

        # Send back only wanted parameters
        template_parameters = dict(
            (key, value) for key, value in allowed_data['Parameters'].items()
            if key not in except_parameters)

        return template_parameters
Esempio n. 8
0
 def template_get(self):
     overcloud = template_tools.merge_templates(POC_PARAMS)
     return overcloud
Esempio n. 9
0
def process_stack(attributes, counts, overcloud_roles, create=False):
    """Helper function for processing the stack.

    Given a params dict containing the Overcloud Roles and initialization
    parameters create or update the stack.

    :param attributes: Dictionary of initialization params and overcloud roles
                       for heat template and initialization of stack
    :type  attributes: dict

    :param counts: Dictionary of counts of roles to be deployed
    :type  counts: dict

    :param overcloud_roles: Dict of (overcloud_role_id, overcloud_role) so
                            we can access image_name and flavor_id of roles
    :type  overcloud_roles: dict

    :param create: A flag to designate if we are creating or updating the stack
    :type create: bool
    """
    heat_client = HeatClient()

    try:
        # Get how many of each role we want and what flavor each role uses.
        parsed_counts, parsed_flavors = parse_counts_and_flavors(
            counts, overcloud_roles)
    except Exception as e:
        raise exception.ParseCountsAndFlavorsFailed(six.text_type(e))

    try:
        # Build the template
        overcloud = template_tools.merge_templates(parsed_counts)
    except Exception as e:
        raise exception.HeatTemplateCreateFailed(six.text_type(e))

    try:
        # Get the parameters that the template accepts and validate
        allowed_data = heat_client.validate_template(overcloud)
    except Exception as e:
        raise exception.HeatTemplateValidateFailed(six.text_type(e))

    stack_exists = heat_client.exists_stack()
    if stack_exists and create:
        raise exception.StackAlreadyCreated()

    elif not stack_exists and not create:
        raise exception.StackNotFound()

    try:
        # Put flavors from OverloudRoles into attributes
        attributes.update(get_flavor_attributes(parsed_flavors))

        # Filter the attributes to allowed only
        filtered_attributes = filter_template_attributes(allowed_data,
                                                         attributes)
    except Exception as e:
        raise exception.HeatStackProcessingAttributesFailed(six.text_type(e))

    if create:
        operation = heat_client.create_stack
    else:
        operation = heat_client.update_stack

    try:
        result = operation(overcloud, filtered_attributes)
    except Exception as e:
        if create:
            raise exception.HeatStackCreateFailed(six.text_type(e))
        else:
            raise exception.HeatStackUpdateFailed(six.text_type(e))

    return result
Esempio n. 10
0
def process_stack(attributes, counts, overcloud_roles, create=False):
    """Helper function for processing the stack.

    Given a params dict containing the Overcloud Roles and initialization
    parameters create or update the stack.

    :param attributes: Dictionary of initialization params and overcloud roles
                       for heat template and initialization of stack
    :type  attributes: dict

    :param counts: Dictionary of counts of roles to be deployed
    :type  counts: dict

    :param overcloud_roles: Dict of (overcloud_role_id, overcloud_role) so
                            we can access image_name and flavor_id of roles
    :type  overcloud_roles: dict

    :param create: A flag to designate if we are creating or updating the stack
    :type create: bool
    """
    heat_client = HeatClient()

    try:
        # Get how many of each role we want and what flavor each role uses.
        parsed_counts, parsed_flavors = parse_counts_and_flavors(
            counts, overcloud_roles)
    except Exception as e:
        raise exception.ParseCountsAndFlavorsFailed(six.text_type(e))

    try:
        # Build the template
        overcloud = template_tools.merge_templates(parsed_counts)
    except Exception as e:
        raise exception.HeatTemplateCreateFailed(six.text_type(e))

    try:
        # Get the parameters that the template accepts and validate
        allowed_data = heat_client.validate_template(overcloud)
    except Exception as e:
        raise exception.HeatTemplateValidateFailed(six.text_type(e))

    stack_exists = heat_client.exists_stack()
    if stack_exists and create:
        raise exception.StackAlreadyCreated()

    elif not stack_exists and not create:
        raise exception.StackNotFound()

    try:
        # Put flavors from OverloudRoles into attributes
        attributes.update(get_flavor_attributes(parsed_flavors))

        # Filter the attributes to allowed only
        filtered_attributes = filter_template_attributes(
            allowed_data, attributes)
    except Exception as e:
        raise exception.HeatStackProcessingAttributesFailed(six.text_type(e))

    if create:
        operation = heat_client.create_stack
    else:
        operation = heat_client.update_stack

    try:
        result = operation(overcloud, filtered_attributes)
    except Exception as e:
        if create:
            raise exception.HeatStackCreateFailed(six.text_type(e))
        else:
            raise exception.HeatStackUpdateFailed(six.text_type(e))

    return result