Beispiel #1
0
def make_ng_dict(name,
                 flavor,
                 processes,
                 count,
                 instances=None,
                 volumes_size=None,
                 node_configs=None,
                 resource=False,
                 **kwargs):
    node_configs = node_configs or {}
    instances = instances or []
    dct = {
        'id': uuidutils.generate_uuid(),
        'name': name,
        'volumes_size': volumes_size,
        'flavor_id': flavor,
        'node_processes': processes,
        'count': count,
        'instances': instances,
        'node_configs': node_configs,
        'security_groups': None,
        'auto_security_group': False,
        'availability_zone': None,
        'volumes_availability_zone': None,
        'open_ports': [],
        'is_proxy_gateway': False,
        'volume_local_to_instance': False
    }
    dct.update(kwargs)
    if resource:
        return r.NodeGroupTemplateResource(dct)
    return dct
Beispiel #2
0
def start_patch(patch_templates=True):
    get_clusters_p = mock.patch("sahara.service.api.v10.get_clusters")
    get_cluster_p = mock.patch("sahara.service.api.v10.get_cluster")
    if patch_templates:
        get_ng_templates_p = mock.patch(
            "sahara.service.api.v10.get_node_group_templates")
        get_ng_template_p = mock.patch(
            "sahara.service.api.v10.get_node_group_template")
    if patch_templates:
        get_cl_templates_p = mock.patch(
            "sahara.service.api.v10.get_cluster_templates")
        get_cl_template_p = mock.patch(
            "sahara.service.api.v10.get_cluster_template")
    nova_p = mock.patch("sahara.utils.openstack.nova.client")
    heat_p = mock.patch("sahara.utils.openstack.heat.client")
    cinder_p = mock.patch("sahara.utils.openstack.cinder.client")
    cinder_exists_p = mock.patch(
        "sahara.utils.openstack.cinder.check_cinder_exists")
    get_image_p = mock.patch("sahara.service.api.v10.get_image")

    get_image = get_image_p.start()
    get_clusters = get_clusters_p.start()
    get_cluster = get_cluster_p.start()
    if patch_templates:
        get_ng_templates = get_ng_templates_p.start()
        get_ng_template = get_ng_template_p.start()
    if patch_templates:
        get_cl_templates = get_cl_templates_p.start()
        get_cl_template_p.start()

    nova = nova_p.start()

    if patch_templates:
        get_cl_templates.return_value = []

    nova().flavors.list.side_effect = _get_flavors_list
    nova().security_groups.list.side_effect = _get_security_groups_list
    nova().keypairs.get.side_effect = _get_keypair
    nova().networks.find.side_effect = _get_network
    nova().networks.find.__name__ = 'find'
    nova().floating_ip_pools.list.side_effect = _get_fl_ip_pool_list
    nova().availability_zones.list.side_effect = _get_availability_zone_list

    heat = heat_p.start()
    heat().stacks.list.side_effect = _get_heat_stack_list

    cinder = cinder_p.start()
    cinder().availability_zones.list.side_effect = _get_availability_zone_list

    cinder_exists = cinder_exists_p.start()
    cinder_exists.return_value = True

    class Image(object):
        def __init__(self, name='test'):
            self.name = name

        @property
        def id(self):
            if self.name == 'test':
                return '550e8400-e29b-41d4-a716-446655440000'
            else:
                return '813fe450-40d2-4acc-ade5-ea753a1bd5bc'

        @property
        def tags(self):
            if self.name == 'test':
                return ['fake', '0.1']
            else:
                return ['fake', 'wrong_tag']

    def _get_image(id):
        if id == '550e8400-e29b-41d4-a716-446655440000':
            return Image()
        else:
            return Image('wrong_test')

    get_image.side_effect = _get_image
    nova().images.list_registered.return_value = [
        Image(), Image(name='wrong_name')
    ]
    ng_dict = tu.make_ng_dict('ng', '42', ['namenode'], 1)
    cluster = tu.create_cluster('test',
                                't',
                                'fake',
                                '0.1', [ng_dict],
                                id=1,
                                status=c_u.CLUSTER_STATUS_ACTIVE)
    # stub clusters list
    get_clusters.return_value = [cluster]
    get_cluster.return_value = cluster

    # stub node templates
    if patch_templates:
        ngt_dict = {
            'name': 'test',
            'tenant_id': 't',
            'flavor_id': '42',
            'plugin_name': 'fake',
            'hadoop_version': '0.1',
            'id': '550e8400-e29b-41d4-a716-446655440000',
            'node_processes': ['namenode']
        }

        get_ng_templates.return_value = [r.NodeGroupTemplateResource(ngt_dict)]

        ct_dict = {
            'name': 'test',
            'tenant_id': 't',
            'plugin_name': 'fake',
            'hadoop_version': '0.1'
        }

        get_cl_templates.return_value = [r.ClusterTemplateResource(ct_dict)]

    def _get_ng_template(id):
        for template in get_ng_templates():
            if template.id == id:
                return template
        return None

    if patch_templates:
        get_ng_template.side_effect = _get_ng_template
    # request data to validate
    patchers = [
        get_clusters_p, get_cluster_p, nova_p, get_image_p, heat_p, cinder_p,
        cinder_exists_p
    ]
    if patch_templates:
        patchers.extend([
            get_ng_template_p, get_ng_templates_p, get_cl_template_p,
            get_cl_templates_p
        ])
    return patchers
Beispiel #3
0
def start_patch(patch_templates=True):
    get_clusters_p = mock.patch("sahara.service.api.get_clusters")
    get_cluster_p = mock.patch("sahara.service.api.get_cluster")
    if patch_templates:
        get_ng_templates_p = \
            mock.patch("sahara.service.api.get_node_group_templates")
        get_ng_template_p = \
            mock.patch("sahara.service.api.get_node_group_template")
    get_plugins_p = mock.patch("sahara.service.api.get_plugins")
    get_plugin_p = \
        mock.patch("sahara.plugins.base.PluginManager.get_plugin")
    if patch_templates:
        get_cl_templates_p = \
            mock.patch("sahara.service.api.get_cluster_templates")
        get_cl_template_p = \
            mock.patch("sahara.service.api.get_cluster_template")
    nova_p = mock.patch("sahara.utils.openstack.nova.client")
    keystone_p = mock.patch("sahara.utils.openstack.keystone.client")
    heat_p = mock.patch("sahara.utils.openstack.heat.client")
    get_image_p = mock.patch("sahara.service.api.get_image")

    get_image = get_image_p.start()
    get_clusters = get_clusters_p.start()
    get_cluster = get_cluster_p.start()
    if patch_templates:
        get_ng_templates = get_ng_templates_p.start()
        get_ng_template = get_ng_template_p.start()
    get_plugins = get_plugins_p.start()
    get_plugin = get_plugin_p.start()
    if patch_templates:
        get_cl_templates = get_cl_templates_p.start()
        get_cl_template_p.start()

    nova = nova_p.start()
    keystone = keystone_p.start()

    if patch_templates:
        get_cl_templates.return_value = []

    nova().flavors.list.side_effect = _get_flavors_list
    nova().keypairs.get.side_effect = _get_keypair
    nova().networks.find.side_effect = _get_network
    nova().floating_ip_pools.list.side_effect = _get_fl_ip_pool_list

    heat = heat_p.start()
    heat().stacks.list.side_effect = _get_heat_stack_list

    class Service:
        @property
        def name(self):
            return 'cinder'

    def _services_list():
        return [Service()]

    keystone().services.list.side_effect = _services_list

    class Image:
        def __init__(self, name='test'):
            self.name = name

        @property
        def id(self):
            if self.name == 'test':
                return '550e8400-e29b-41d4-a716-446655440000'
            else:
                return '813fe450-40d2-4acc-ade5-ea753a1bd5bc'

        @property
        def tags(self):
            if self.name == 'test':
                return ['vanilla', '1.2.1']
            else:
                return ['wrong_tag']

    def _get_image(id):
        if id == '550e8400-e29b-41d4-a716-446655440000':
            return Image()
        else:
            return Image('wrong_test')

    get_image.side_effect = _get_image
    nova().images.list_registered.return_value = [
        Image(), Image(name='wrong_name')
    ]
    ng_dict = tu.make_ng_dict('ng', '42', ['namenode'], 1)
    cluster = tu.create_cluster('test',
                                't',
                                'vanilla',
                                '1.2.1', [ng_dict],
                                id=1,
                                status='Active')
    # stub clusters list
    get_clusters.return_value = [cluster]
    get_cluster.return_value = cluster

    # stub node templates
    if patch_templates:
        ngt_dict = {
            'name': 'test',
            'tenant_id': 't',
            'flavor_id': '42',
            'plugin_name': 'vanilla',
            'hadoop_version': '1.2.1',
            #'id': '1234321',
            'id': '550e8400-e29b-41d4-a716-446655440000',
            'node_processes': ['namenode']
        }

        get_ng_templates.return_value = [r.NodeGroupTemplateResource(ngt_dict)]

        ct_dict = {
            'name': 'test',
            'tenant_id': 't',
            'plugin_name': 'vanilla',
            'hadoop_version': '1.2.1'
        }

        get_cl_templates.return_value = [r.ClusterTemplateResource(ct_dict)]

    vanilla = plugin.VanillaProvider()
    vanilla.name = 'vanilla'
    get_plugins.return_value = [vanilla]

    def _get_ng_template(id):
        for template in get_ng_templates():
            if template.id == id:
                return template
        return None

    def _get_plugin(name):
        if name == 'vanilla':
            return vanilla
        return None

    get_plugin.side_effect = _get_plugin
    if patch_templates:
        get_ng_template.side_effect = _get_ng_template
    # request data to validate
    patchers = [
        get_clusters_p, get_cluster_p, get_plugins_p, get_plugin_p, nova_p,
        keystone_p, get_image_p, heat_p
    ]
    if patch_templates:
        patchers.extend([
            get_ng_template_p, get_ng_templates_p, get_cl_template_p,
            get_cl_templates_p
        ])
    return patchers